Skip to content

Commit

Permalink
add the on-media-delete callback
Browse files Browse the repository at this point in the history
related with #92
  • Loading branch information
outsideris committed Jan 6, 2016
1 parent b8266e5 commit bb4e990
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,39 @@ summernote's options can be specified as attributes.
<summernote airMode></summernote>
```

If you use the `removeMedia` button in popover, like below:

```
<summernote airMode config="options" on-media-delete="mediaDelete(target)"></summernote>
```

```
function DemoController($scope) {
$scope.options = {
popover: {
image: [['remove', ['removeMedia']] ],
air: [['insert', ['picture']]]
}
};
$scope.mediaDelete = function(target) {
console.log('media is delted:', target);
}
}
```

You can use the 'onMediaDelete` callback. The `target` object has information of the DOM that is removed like:

```
{
tagName: "IMG",
attrs: {
data-filename: "image-name.jpg",
src: "http://path/to/image",
style: "width: 100px;"
}
}
```

#### options object

You can specify all options using ngModel in `config` attribute.
Expand Down
24 changes: 23 additions & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h4>lang</h4>
<div ng-controller="AirmodeCtrl">
<h4>airmode</h4>
<div class="example">
<summernote airMode ng-model="text"></summernote>
<summernote airMode ng-model="text" config="options" on-media-delete="mediaDelete(target)"></summernote>
</div>
</div>

Expand Down Expand Up @@ -130,6 +130,28 @@ <h4>use callbacks</h4>
})
.controller('AirmodeCtrl', function($scope) {
$scope.text = "<h3>This is an Air-mode editable area.</h3>";
$scope.options = {
popover: {
image: [
['imagesize', ['imageSize100', 'imageSize50', 'imageSize25']],
['float', ['floatLeft', 'floatRight', 'floatNone']],
['remove', ['removeMedia']]
],
link: [
['link', ['linkDialogShow', 'unlink']]
],
air: [
['color', ['color']],
['font', ['bold', 'underline', 'clear']],
['para', ['ul', 'paragraph']],
['table', ['table']],
['insert', ['link', 'picture']]
]
}
};
$scope.mediaDelete = function(target) {
console.log('media is delted:', target);
}
})
.controller('CodeCtrl', function($scope) {
$scope.text = "Hello World";
Expand Down
14 changes: 13 additions & 1 deletion src/angular-summernote.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ angular.module('summernote', [])
$scope.imageUpload({files:files, editable: $scope.editable});
};
}
if (angular.isDefined($attrs.onMediaDelete)) {
callbacks.onMediaDelete = function(target) {
// make new object that has information of target to avoid error:isecdom
var removedMedia = {attrs: {}};
removedMedia.tagName = target[0].tagName;
angular.forEach(target[0].attributes, function(attr) {
removedMedia.attrs[attr.name] = attr.value;
});
$scope.mediaDelete({target: removedMedia});
}
}

this.activate = function(scope, element, ngModel) {
var updateNgModel = function() {
Expand Down Expand Up @@ -127,7 +138,8 @@ angular.module('summernote', [])
keyup: '&onKeyup',
keydown: '&onKeydown',
change: '&onChange',
imageUpload: '&onImageUpload'
imageUpload: '&onImageUpload',
mediaDelete: '&onMediaDelete'
},
template: '<div class="summernote"></div>',
link: function(scope, element, attrs, ctrls, transclude) {
Expand Down

0 comments on commit bb4e990

Please sign in to comment.