// Version 0.3.2 // AngularJS simple file upload directive // this directive uses an iframe as a target // to enable the uploading of files without // losing focus in the ng-app. // //
//
//
// // //
//
//
// // angular.module('app', ['ngUpload']) // .controller('mainCtrl', function($scope) { // $scope.submited = function(content, completed) { // if (completed) { // console.log(content); // } // } // }); // angular.module('ngUpload', []) .directive('uploadSubmit', ['$parse', function($parse) { return { restrict: 'AC', link: function(scope, element, attrs) { // Options (just 1 for now) // Each option should be prefixed with 'upload-options-' or 'uploadOptions' // { // // specify whether to enable the submit button when uploading forms // enableControls: bool // } var options = {}; options.enableControls = attrs.uploadOptionsEnableControls; // submit the form - requires jQuery var form = element.parents('form[ng-upload]') || element.parents('form.ng-upload'); // Retrieve the callback function var fn = $parse(attrs.uploadSubmit); if (!angular.isFunction(fn)) { var message = "The expression on the ngUpload directive does not point to a valid function."; throw message + "\n"; } element.bind('click', function($event) { // prevent default behavior of click $event.preventDefault = true; // create a new iframe var iframe = angular.element("