Skip to content

Commit

Permalink
added the ability to append onto the model, as opposed to completely …
Browse files Browse the repository at this point in the history
…overwriting the model.
  • Loading branch information
boxxxie committed Apr 8, 2014
1 parent fee67a7 commit ee6abd3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
2 changes: 2 additions & 0 deletions demo/front-end/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ <h2>Multi image drag and drop</h2>

<div
images-drop
append
resize
resize-max-height="300"
resize-max-width="250"
Expand Down Expand Up @@ -153,6 +154,7 @@ <h2>Multiple images</h2>

<button
input-images
append
id="inputImage3"
append-data-uri
ng-model="images">
Expand Down
35 changes: 22 additions & 13 deletions src/imageupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,24 @@
};
})

.directive("inputImages", function(generic_image_processing_functions) {
.factory("multi_image_model_updater", function(){
return function update_model(ngModel, options){
return function(model){
var old_model = ngModel.$modelValue;
var model_to_update;
if(angular.isDefined(options.append) && angular.isArray(old_model)){
model_to_update = old_model.concat(model);
}
else{
model_to_update = model;
}
ngModel.$setViewValue(model_to_update);

}
};
})
.directive("inputImages", function(generic_image_processing_functions,
multi_image_model_updater) {

return {
require: "ngModel",
Expand All @@ -243,13 +260,8 @@
var files = evt.target.files;

generic_image_processing_functions(files, attrs)
.then(update_model);
.then(multi_image_model_updater(ngModel, attrs));
});

function update_model(model){
ngModel.$setViewValue(model);
}

}
};
})
Expand Down Expand Up @@ -367,23 +379,20 @@
.directive("imagesDrop", function (
find_data_transfer,
image_drop_linker_common,
generic_image_processing_functions){
generic_image_processing_functions,
multi_image_model_updater){
return {
restrict: "EA",
require: "ngModel",
link: function (scope, element, attrs, ngModel) {

image_drop_linker_common(scope, element, attrs, ngModel);

function update_model(model){
ngModel.$setViewValue(model);
}

element.bind("drop", function (e) {
var files = find_data_transfer(e).files;

generic_image_processing_functions(files, attrs)
.then(update_model);
.then(multi_image_model_updater(ngModel, attrs));
});
}
};
Expand Down

0 comments on commit ee6abd3

Please sign in to comment.