Skip to content

Commit

Permalink
Bug fixes and addition of NodeJS demo url
Browse files Browse the repository at this point in the history
* Bug fixes for Google Chrome
* Addition of NodeJS demo url to the Readme document. (Hosted on AppFog)
  • Loading branch information
adebisi-fa committed Mar 7, 2013
1 parent 0fabbea commit ed43daa
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ _ReSharper*/
[Tt]est[Rr]esult*
packages
PublishProfiles
ngUpload.sln
43 changes: 21 additions & 22 deletions examples/aspnet.mvc/Content/libs/js/ng-upload.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Version 0.1.0
// AngularJS simple file upload directive
// this directive uses an iframe as a target
// to enable the uploading of files without
Expand All @@ -12,7 +13,7 @@
// </div>
// </div>
//
// angular.module('app', ['ng-upload'])
// angular.module('app', ['ngUpload'])
// .controller('mainCtrl', function($scope) {
// $scope.results = function(content) {
// console.log(content);
Expand All @@ -28,7 +29,7 @@ angular.module('ngUpload', [])
// Options (just 1 for now)
// Each option should be prefixed with 'upload-Options-' or 'uploadOptions'
// {
// // specify whether to disable the submit button when uploading forms
// // specify whether to enable the submit button when uploading forms
// enableControls: bool
// }
var options = {};
Expand All @@ -54,47 +55,45 @@ angular.module('ngUpload', [])
// attach function to load event of the iframe
iframe.bind('load', function () {

//remove listener
iframe.unbind('load');
// get content - requires jQuery
var content = iframe.contents().find('body').text();

// get content - requires jQuery
var content = iframe.contents().find('body').text();
// execute the upload response function in the active scope
scope.$apply(function () { callbackFn(content); });

// execute the upload response function in the active scope
scope.$apply(function () { callbackFn(content); });
// remove iframe
if (content != "") // Fixes a bug in Google Chrome that dispose the iframe before content is ready.
setTimeout(function () { iframe.remove(); }, 250);

// remove iframe
setTimeout(function () { iframe.remove() }, 250);

//if (options.enableControls == null || !(options.enableControls.length >= 0))
submitControl.attr('disabled', null);
submitControl.attr('title', 'Click to start upload.');
});
//if (options.enableControls == null || !(options.enableControls.length >= 0))
submitControl.attr('disabled', null);
submitControl.attr('title', 'Click to start upload.');
});

// add the new iframe to application
element.parent().append(iframe);
}
};

// 1) get the upload submit control(s) on the form (submitters must be decorated with the 'ng-upload-submit' class)
// 2) attach a handler to the controls' click event
$('.upload-submit', element).click(
function () {

scope.$apply(function () { callbackFn('Please wait...'); });
addNewDisposableIframe($(this) /* pass the submit control */);

scope.$apply(function () { callbackFn("Please wait..."); });

console.log(angular.toJson(options));
//console.log(angular.toJson(options));

var enabled = true;
if (options.enableControls == null || !(options.enableControls.length >= 0)) {
if (options.enableControls === null || options.enableControls === undefined || options.enableControls.length >= 0) {
// disable the submit control on click
$(this).attr('disabled', 'disabled');
enabled = false;
}

$(this).attr('title', (enabled ? '[ENABLED]: ' : '[DISABLED]: ') + 'Uploading, please wait...');

addNewDisposableIframe($(this) /* pass the submit control */);

// submit the form
$(element).submit();
}
Expand All @@ -103,5 +102,5 @@ angular.module('ngUpload', [])
else
console.log("No callback function found on the ngUpload directive.");
}
}
};
});
43 changes: 21 additions & 22 deletions examples/nodejs/libs/js/ng-upload.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Version 0.1.0
// AngularJS simple file upload directive
// this directive uses an iframe as a target
// to enable the uploading of files without
Expand All @@ -12,7 +13,7 @@
// </div>
// </div>
//
// angular.module('app', ['ng-upload'])
// angular.module('app', ['ngUpload'])
// .controller('mainCtrl', function($scope) {
// $scope.results = function(content) {
// console.log(content);
Expand All @@ -28,7 +29,7 @@ angular.module('ngUpload', [])
// Options (just 1 for now)
// Each option should be prefixed with 'upload-Options-' or 'uploadOptions'
// {
// // specify whether to disable the submit button when uploading forms
// // specify whether to enable the submit button when uploading forms
// enableControls: bool
// }
var options = {};
Expand All @@ -54,47 +55,45 @@ angular.module('ngUpload', [])
// attach function to load event of the iframe
iframe.bind('load', function () {

//remove listener
iframe.unbind('load');
// get content - requires jQuery
var content = iframe.contents().find('body').text();

// get content - requires jQuery
var content = iframe.contents().find('body').text();
// execute the upload response function in the active scope
scope.$apply(function () { callbackFn(content); });

// execute the upload response function in the active scope
scope.$apply(function () { callbackFn(content); });
// remove iframe
if (content != "") // Fixes a bug in Google Chrome that dispose the iframe before content is ready.
setTimeout(function () { iframe.remove(); }, 250);

// remove iframe
setTimeout(function () { iframe.remove() }, 250);

//if (options.enableControls == null || !(options.enableControls.length >= 0))
submitControl.attr('disabled', null);
submitControl.attr('title', 'Click to start upload.');
});
//if (options.enableControls == null || !(options.enableControls.length >= 0))
submitControl.attr('disabled', null);
submitControl.attr('title', 'Click to start upload.');
});

// add the new iframe to application
element.parent().append(iframe);
}
};

// 1) get the upload submit control(s) on the form (submitters must be decorated with the 'ng-upload-submit' class)
// 2) attach a handler to the controls' click event
$('.upload-submit', element).click(
function () {

scope.$apply(function () { callbackFn('Please wait...'); });
addNewDisposableIframe($(this) /* pass the submit control */);

scope.$apply(function () { callbackFn("Please wait..."); });

console.log(angular.toJson(options));
//console.log(angular.toJson(options));

var enabled = true;
if (options.enableControls == null || !(options.enableControls.length >= 0)) {
if (options.enableControls === null || options.enableControls === undefined || options.enableControls.length >= 0) {
// disable the submit control on click
$(this).attr('disabled', 'disabled');
enabled = false;
}

$(this).attr('title', (enabled ? '[ENABLED]: ' : '[DISABLED]: ') + 'Uploading, please wait...');

addNewDisposableIframe($(this) /* pass the submit control */);

// submit the form
$(element).submit();
}
Expand All @@ -103,5 +102,5 @@ angular.module('ngUpload', [])
else
console.log("No callback function found on the ngUpload directive.");
}
}
};
});
34 changes: 16 additions & 18 deletions ng-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ angular.module('ngUpload', [])
// Options (just 1 for now)
// Each option should be prefixed with 'upload-Options-' or 'uploadOptions'
// {
// // specify whether to disable the submit button when uploading forms
// // specify whether to enable the submit button when uploading forms
// enableControls: bool
// }
var options = {};
Expand All @@ -55,22 +55,20 @@ angular.module('ngUpload', [])
// attach function to load event of the iframe
iframe.bind('load', function () {

//remove listener
iframe.unbind('load');
// get content - requires jQuery
var content = iframe.contents().find('body').text();

// get content - requires jQuery
var content = iframe.contents().find('body').text();
// execute the upload response function in the active scope
scope.$apply(function () { callbackFn(content); });

// execute the upload response function in the active scope
scope.$apply(function () { callbackFn(content); });
// remove iframe
if (content != "") // Fixes a bug in Google Chrome that dispose the iframe before content is ready.
setTimeout(function () { iframe.remove(); }, 250);

// remove iframe
setTimeout(function () { iframe.remove(); }, 250);

//if (options.enableControls == null || !(options.enableControls.length >= 0))
submitControl.attr('disabled', null);
submitControl.attr('title', 'Click to start upload.');
});
//if (options.enableControls == null || !(options.enableControls.length >= 0))
submitControl.attr('disabled', null);
submitControl.attr('title', 'Click to start upload.');
});

// add the new iframe to application
element.parent().append(iframe);
Expand All @@ -81,21 +79,21 @@ angular.module('ngUpload', [])
$('.upload-submit', element).click(
function () {

scope.$apply(function () { callbackFn('Please wait...'); });
addNewDisposableIframe($(this) /* pass the submit control */);

scope.$apply(function () { callbackFn("Please wait..."); });

//console.log(angular.toJson(options));

var enabled = true;
if (options.enableControls === null || options.enableControls.length === 0) {
if (options.enableControls === null || options.enableControls === undefined || options.enableControls.length >= 0) {
// disable the submit control on click
$(this).attr('disabled', 'disabled');
enabled = false;
}

$(this).attr('title', (enabled ? '[ENABLED]: ' : '[DISABLED]: ') + 'Uploading, please wait...');

addNewDisposableIframe($(this) /* pass the submit control */);

// submit the form
$(element).submit();
}
Expand Down
3 changes: 2 additions & 1 deletion ng-upload.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions ng-upload.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ angular.module('app', ['ngUpload'])

Example of forms that posts to ASP.Net MVC or NodeJS server are now included under the [/examples](https://github.com/adebisi-fa/ngUpload/tree/master/examples) folder.

Live examples of the ASP.Net MVC sample can be found at http://ng-upload.azurewebsites.net
Live demo of the ASP.Net MVC example can be found at http://ng-upload.azurewebsites.net

Live demo of the NodeJS example can be found at http://ng-upload.eu01.aws.af.cm

## License

Expand Down

0 comments on commit ed43daa

Please sign in to comment.