Skip to content

Instantly share code, notes, and snippets.

@joshperry
Created May 16, 2014 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshperry/cabaefc1685dbb88b808 to your computer and use it in GitHub Desktop.
Save joshperry/cabaefc1685dbb88b808 to your computer and use it in GitHub Desktop.
'use strict';
angular.module('sawebApp')
.directive('pdkFilesSelected', function($parse) {
return {
restrict: 'A',
link: function(scope, elm, attrs) {
var onSelected = $parse(attrs.pdkFilesSelected);
elm.on('change', function() {
scope.$apply(function() {
//attr.multiple ?
onSelected(scope, { $files: elm[0].files });
});
});
}
};
})
.directive('pdkUploadImage', function($parse) {
return {
restrict: 'E',
scope: {
imageSrc: '=',
imageSelected: '&'
},
link: function(scope, element, attrs) {
scope.chooseNewImage = function() {
element.find('input').trigger('click');
};
scope.filesSelected = function(files) {
imageSelected({ $image: files[0] });
};
},
template: '<img ng-src="{{imageSrc}}" style="max-width: 100%;" '
+ 'ng-dblclick="chooseNewImage()" '
+ 'hm-hold="chooseNewImage()" />'
+ '<input type="file" style="width: 0px; height: 0px;" '
+ 'accept="image/png,image/jpg,image/jpeg" '
+ 'pdk-files-selected="filesSelected($files)"/>'
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment