-
Notifications
You must be signed in to change notification settings - Fork 9
/
summernote-image-shapes.js
executable file
·66 lines (66 loc) · 2.18 KB
/
summernote-image-shapes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* https://github.com/DiemenDesign/summernote-image-shapes */
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'],factory)
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('jquery'));
} else {
factory(window.jQuery)
}
}
(function ($) {
$.extend(true,$.summernote.lang, {
'en-US': {
imageShapes: {
tooltip: 'Image Shapes',
tooltipShapeOptions: ['Responsive', 'Rounded', 'Circle', 'Thumbnail', 'None']
}
},
});
$.extend($.summernote.options, {
imageShapes: {
icon: '<i class="note-icon-picture"/>',
/* Must keep the same order as in lang.imageAttributes.tooltipShapeOptions */
shapes: ['img-responsive', 'img-rounded', 'img-circle', 'img-thumbnail', '']
}
});
$.extend($.summernote.plugins, {
'imageShapes': function(context) {
var ui = $.summernote.ui,
$editable = context.layoutInfo.editable,
options = context.options,
lang = options.langInfo;
context.memo('button.imageShapes', function() {
var button = ui.buttonGroup([
ui.button({
className: 'dropdown-toggle',
contents: options.imageShapes.icon + ' <span class="caret"></span>',
tooltip: lang.imageShapes.tooltip,
data: {
toggle: 'dropdown'
}
}),
ui.dropdown({
className: 'dropdown-shape',
items: lang.imageShapes.tooltipShapeOptions,
click: function (e) {
e.preventDefault();
var $button = $(e.target);
var $img = $($editable.data('target'));
var index = $.inArray(
$button.data('value'),
lang.imageShapes.tooltipShapeOptions
);
$.each(options.imageShapes.shapes, function (index,value) {
$img.removeClass(value);
});
$img.addClass(options.imageShapes.shapes[index]);
context.invoke('editor.afterCommand');
}
})
]);
return button.render();
});
}
});
}));