|
1 |
| -var fileuploadOptions = {}; |
2 |
| -var wysihtml5Overrides = { |
3 |
| - initInsertImage: function(toolbar) { |
4 |
| - var self = this; |
5 |
| - var insertImageModal = toolbar.find('.bootstrap-wysihtml5-insert-image-modal'); |
6 |
| - var urlInput = insertImageModal.find('.bootstrap-wysihtml5-insert-image-url'); |
7 |
| - var insertButton = insertImageModal.find('a.btn-primary'); |
8 |
| - var initialValue = urlInput.val(); |
| 1 | +!function($) { |
9 | 2 |
|
10 |
| - var insertImage = function(imgData) { |
11 |
| - if (!imgData.src) throw 'Image src is not specified'; |
12 |
| - self.editor.currentView.element.focus(); |
13 |
| - self.editor.composer.commands.exec("insertImage", imgData); |
14 |
| - }; |
| 3 | + var fileuploadOptions = {}; |
| 4 | + var wysihtml5Overrides = { |
| 5 | + initInsertImage: function(toolbar) { |
| 6 | + var self = this; |
| 7 | + var insertImageModal = toolbar.find('.bootstrap-wysihtml5-insert-image-modal'); |
| 8 | + var urlInput = insertImageModal.find('.bootstrap-wysihtml5-insert-image-url'); |
| 9 | + var insertButton = insertImageModal.find('a.btn-primary'); |
| 10 | + var initialValue = urlInput.val(); |
15 | 11 |
|
16 |
| - insertImageModal.on('hide', function() { |
17 |
| - self.editor.currentView.element.focus(); |
18 |
| - }); |
| 12 | + var insertImage = function(imgData) { |
| 13 | + if (!imgData.src) throw 'Image src is not specified'; |
| 14 | + self.editor.currentView.element.focus(); |
| 15 | + self.editor.composer.commands.exec("insertImage", imgData); |
| 16 | + }; |
19 | 17 |
|
20 |
| - toolbar.find('a[data-wysihtml5-command=insertImage]').click(function() { |
21 |
| - var activeButton = $(this).hasClass("wysihtml5-command-active"); |
22 |
| - var done; |
| 18 | + insertImageModal.on('hide', function() { |
| 19 | + self.editor.currentView.element.focus(); |
| 20 | + }); |
23 | 21 |
|
24 |
| - if (!activeButton) { |
25 |
| - insertImageModal.modal('show'); |
| 22 | + toolbar.find('a[data-wysihtml5-command=insertImage]').click(function() { |
| 23 | + var activeButton = $(this).hasClass("wysihtml5-command-active"); |
| 24 | + var done; |
26 | 25 |
|
27 |
| - done = function(e, data) { |
28 |
| - var imgs; |
29 |
| - imgs = fileuploadOptions.done(e, data); |
30 |
| - insertImageModal.modal('hide'); |
| 26 | + if (!activeButton) { |
| 27 | + insertImageModal.modal('show'); |
31 | 28 |
|
32 |
| - if (!$.isArray(imgs)) imgs = [imgs]; |
| 29 | + done = function(e, data) { |
| 30 | + var imgs; |
| 31 | + imgs = fileuploadOptions.done(e, data); |
| 32 | + insertImageModal.modal('hide'); |
33 | 33 |
|
34 |
| - $.each(imgs, function(index, img) { |
35 |
| - insertImage(img); |
| 34 | + if (!$.isArray(imgs)) imgs = [imgs]; |
| 35 | + |
| 36 | + $.each(imgs, function(index, img) { |
| 37 | + insertImage(img); |
| 38 | + }); |
| 39 | + }; |
| 40 | + |
| 41 | + insertImageModal.find('.file').fileupload($.extend({}, fileuploadOptions, { |
| 42 | + done: done |
| 43 | + })); |
| 44 | + |
| 45 | + insertImageModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) { |
| 46 | + e.stopPropagation(); |
36 | 47 | });
|
37 |
| - }; |
| 48 | + return false; |
| 49 | + } |
| 50 | + else { |
| 51 | + return true; |
| 52 | + } |
| 53 | + }); |
| 54 | + } |
| 55 | + }; |
38 | 56 |
|
39 |
| - insertImageModal.find('#file').fileupload($.extend({}, fileuploadOptions, { |
40 |
| - done: done |
41 |
| - })); |
| 57 | + $.extend($.fn.wysihtml5.Constructor.prototype, wysihtml5Overrides); |
42 | 58 |
|
43 |
| - insertImageModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) { |
44 |
| - e.stopPropagation(); |
45 |
| - }); |
46 |
| - return false; |
| 59 | + // Override options. |
| 60 | + var wysihtml5Options = { |
| 61 | + customTemplates: { |
| 62 | + /* This is the template for the image button in the toolbar. */ |
| 63 | + image: function(locale) { |
| 64 | + return '<li>' + |
| 65 | + '<div class="bootstrap-wysihtml5-insert-image-modal modal hide">' + |
| 66 | + '<div class="modal-header">' + |
| 67 | + '<a class="close" data-dismiss="modal">×</a>' + |
| 68 | + '<h3>' + locale.image.insert + '</h3>' + |
| 69 | + '</div>' + |
| 70 | + '<div class="modal-body">' + |
| 71 | + '<input name="file" class="file" type="file" multiple>' + |
| 72 | + '</div>' + |
| 73 | + '<div class="modal-footer">' + |
| 74 | + '<a href="#" class="btn" data-dismiss="modal">' + locale.image.cancel + '</a>' + |
| 75 | + '</div>' + |
| 76 | + '</div>' + |
| 77 | + '<a class="btn" data-wysihtml5-command="insertImage" title="' + locale.image.insert + '"><i class="icon-picture"></i></a>' + |
| 78 | + '</li>'; |
47 | 79 | }
|
48 |
| - else { |
49 |
| - return true; |
50 |
| - } |
51 |
| - }); |
52 |
| - } |
53 |
| -}; |
54 |
| - |
55 |
| -$.extend($.fn.wysihtml5.Constructor.prototype, wysihtml5Overrides); |
| 80 | + }, |
| 81 | + }; |
56 | 82 |
|
57 |
| -// Override options. |
58 |
| -var wysihtml5Options = { |
59 |
| - customTemplates: { |
60 |
| - /* This is the template for the image button in the toolbar. */ |
61 |
| - image: function(locale) { |
62 |
| - return '<li>' + |
63 |
| - '<div class="bootstrap-wysihtml5-insert-image-modal modal hide">' + |
64 |
| - '<div class="modal-header">' + |
65 |
| - '<a class="close" data-dismiss="modal">×</a>' + |
66 |
| - '<h3>' + locale.image.insert + '</h3>' + |
67 |
| - '</div>' + |
68 |
| - '<div class="modal-body">' + |
69 |
| - '<input name="file" id="file" type="file" multiple>' + |
70 |
| - '</div>' + |
71 |
| - '<div class="modal-footer">' + |
72 |
| - '<a href="#" class="btn" data-dismiss="modal">' + locale.image.cancel + '</a>' + |
73 |
| - '</div>' + |
74 |
| - '</div>' + |
75 |
| - '<a class="btn" data-wysihtml5-command="insertImage" title="' + locale.image.insert + '"><i class="icon-picture"></i></a>' + |
76 |
| - '</li>'; |
77 |
| - } |
78 |
| - }, |
79 |
| -}; |
| 83 | + $.fn.bootstrapEditor = function(options) { |
| 84 | + if (options.fileupload) fileuploadOptions = options.fileupload; |
| 85 | + $(this).wysihtml5($.extend(wysihtml5Options, options)); |
| 86 | + }; |
80 | 87 |
|
81 |
| -$.fn.bootstrapEditor = function(options) { |
82 |
| - if (options.fileupload) fileuploadOptions = options.fileupload; |
83 |
| - $(this).wysihtml5($.extend(wysihtml5Options, options)); |
84 |
| -}; |
| 88 | +}(window.jQuery); |
0 commit comments