vendor: 4,821 bytes, lines 1-162
1/* jshint expr: true */ 2!(function($, wysi) { 3 'use strict'; 4 5 var templates = function(key, locale, options) { 6 return wysi.tpl[key]({locale: locale, options: options}); 7 }; 8 9 var Wysihtml5 = function(el, options) { 10 this.el = el; 11 var toolbarOpts = options || defaultOptions; 12 for(var t in toolbarOpts.customTemplates) { 13 wysi.tpl[t] = toolbarOpts.customTemplates[t]; 14 } 15 this.toolbar = this.createToolbar(el, toolbarOpts); 16 this.editor = this.createEditor(options); 17 18 window.editor = this.editor; 19 20 $('iframe.wysihtml5-sandbox').each(function(i, el){ 21 $(el.contentWindow).off('focus.wysihtml5').on({ 22 'focus.wysihtml5' : function(){ 23 $('li.dropdown').removeClass('open'); 24 } 25 }); 26 }); 27 }; 28 29 Wysihtml5.prototype = { 30 31 constructor: Wysihtml5, 32 33 createEditor: function(options) { 34 options = options || {}; 35 36 // Add the toolbar to a clone of the options object so multiple instances 37 // of the WYISYWG don't break because 'toolbar' is already defined 38 options = $.extend(true, {}, options); 39 options.toolbar = this.toolbar[0]; 40 41 var editor = new wysi.Editor(this.el[0], options); 42 43 if(options && options.events) { 44 for(var eventName in options.events) { 45 editor.on(eventName, options.events[eventName]); 46 } 47 } 48 return editor; 49 }, 50 51 createToolbar: function(el, options) { 52 var self = this; 53 var toolbar = $('<ul/>', { 54 'class' : 'wysihtml5-toolbar', 55 'style': 'display:none' 56 }); 57 var culture = options.locale || defaultOptions.locale || 'en'; 58 for(var key in defaultOptions) { 59 var value = false; 60 61 if(options[key] !== undefined) { 62 if(options[key] === true) { 63 value = true; 64 } 65 } else { 66 value = defaultOptions[key]; 67 } 68 69 if(value === true) { 70 toolbar.append(templates(key, locale[culture], options)); 71 72 if(key === 'html') { 73 this.initHtml(toolbar); 74 } 75 76 if(key === 'link') { 77 this.initInsertLink(toolbar); 78 } 79 80 if(key === 'image') { 81 this.initInsertImage(toolbar); 82 } 83 } 84 } 85 86 if(options.toolbar) { 87 for(key in options.toolbar) { 88 toolbar.append(options.toolbar[key]); 89 } 90 } 91 92 toolbar.find('a[data-wysihtml5-command="formatBlock"]').click(function(e) { 93 var target = e.target || e.srcElement; 94 var el = $(target); 95 self.toolbar.find('.current-font').text(el.html()); 96 }); 97 98 toolbar.find('a[data-wysihtml5-command="foreColor"]').click(function(e) { 99 var target = e.target || e.srcElement; 100 var el = $(target); 101 self.toolbar.find('.current-color').text(el.html()); 102 }); 103 104 this.el.before(toolbar); 105 106 return toolbar; 107 }, 108 109 initHtml: function(toolbar) { 110 var changeViewSelector = 'a[data-wysihtml5-action="change_view"]'; 111 toolbar.find(changeViewSelector).click(function(e) { 112 toolbar.find('a.btn').not(changeViewSelector).toggleClass('disabled'); 113 }); 114 }, 115 116 initInsertImage: function(toolbar) { 117 var self = this; 118 var insertImageModal = toolbar.find('.bootstrap-wysihtml5-insert-image-modal'); 119 var urlInput = insertImageModal.find('.bootstrap-wysihtml5-insert-image-url'); 120 var insertButton = insertImageModal.find('a.btn-primary'); 121 var initialValue = urlInput.val(); 122 var caretBookmark; 123 124 var insertImage = function() { 125 var url = urlInput.val(); 126 urlInput.val(initialValue); 127 self.editor.currentView.element.focus(); 128 if (caretBookmark) { 129 self.editor.composer.selection.setBookmark(caretBookmark); 130 caretBookmark = null; 131 } 132 self.editor.composer.commands.exec('insertImage', url); 133 }; 134 135 urlInput.keypress(function(e) { 136 if(e.which == 13) { 137 insertImage(); 138 insertImageModal.modal('hide'); 139 } 140 }); 141 142 insertButton.click(insertImage); 143 144 insertImageModal.on('shown', function() { 145 urlInput.focus(); 146 }); 147 148 insertImageModal.on('hide', function() { 149 self.editor.currentView.element.focus(); 150 }); 151 152 toolbar.find('a[data-wysihtml5-command=insertImage]').click(function() { 153 var activeButton = $(this).hasClass('wysihtml5-command-active'); 154 155 if (!activeButton) { 156 self.editor.currentView.element.focus(false); 157 caretBookmark = self.editor.composer.selection.getBookmark(); 158 insertImageModal.appendTo('body').modal('show'); 159 insertImageModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) { 160 e.stopPropagation(); 161 }); 162 return false;
163 } 164 else { 165 return true; 166 } 167 }); 168 }, 169 170 initInsertLink: function(toolbar) { 171 var self = this; 172 var insertLinkModal = toolbar.find('.bootstrap-wysihtml5-insert-link-modal'); 173 var urlInput = insertLinkModal.find('.bootstrap-wysihtml5-insert-link-url'); 174 var targetInput = insertLinkModal.find('.bootstrap-wysihtml5-insert-link-target'); 175 var insertButton = insertLinkModal.find('a.btn-primary'); 176 var initialValue = urlInput.val(); 177 var caretBookmark; 178 179 var insertLink = function() { 180 var url = urlInput.val(); 181 urlInput.val(initialValue); 182 self.editor.currentView.element.focus(); 183 if (caretBookmark) { 184 self.editor.composer.selection.setBookmark(caretBookmark); 185 caretBookmark = null; 186 } 187 188 var newWindow = targetInput.prop('checked'); 189 self.editor.composer.commands.exec('createLink', { 190 'href' : url, 191 'target' : (newWindow ? '_blank' : '_self'), 192 'rel' : (newWindow ? 'nofollow' : '') 193 }); 194 }; 195 var pressedEnter = false; 196 197 urlInput.keypress(function(e) { 198 if(e.which == 13) { 199 insertLink(); 200 insertLinkModal.modal('hide'); 201 } 202 }); 203 204 insertButton.click(insertLink); 205 206 insertLinkModal.on('shown', function() { 207 urlInput.focus(); 208 }); 209 210 insertLinkModal.on('hide', function() { 211 self.editor.currentView.element.focus(); 212 }); 213 214 toolbar.find('a[data-wysihtml5-command=createLink]').click(function() { 215 var activeButton = $(this).hasClass('wysihtml5-command-active'); 216 217 if (!activeButton) { 218 self.editor.currentView.element.focus(false); 219 caretBookmark = self.editor.composer.selection.getBookmark(); 220 insertLinkModal.appendTo('body').modal('show'); 221 insertLinkModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) { 222 e.stopPropagation(); 223 }); 224 return false; 225 } 226 else { 227 return true; 228 } 229 }); 230 } 231 }; 232 233 // these define our public api 234 var methods = { 235 resetDefaults: function() { 236 $.fn.wysihtml5.defaultOptions = $.extend(true, {}, $.fn.wysihtml5.defaultOptionsCache); 237 }, 238 bypassDefaults: function(options) { 239 return this.each(function () { 240 var $this = $(this); 241 $this.data('wysihtml5', new Wysihtml5($this, options)); 242 }); 243 }, 244 shallowExtend: function (options) { 245 var settings = $.extend({}, $.fn.wysihtml5.defaultOptions, options || {}, $(this).data()); 246 var that = this; 247 return methods.bypassDefaults.apply(that, [settings]); 248 }, 249 deepExtend: function(options) { 250 var settings = $.extend(true, {}, $.fn.wysihtml5.defaultOptions, options || {}); 251 var that = this; 252 return methods.bypassDefaults.apply(that, [settings]); 253 }, 254 init: function(options) { 255 var that = this; 256 return methods.shallowExtend.apply(that, [options]); 257 } 258 }; 259 260 $.fn.wysihtml5 = function ( method ) { 261 if ( methods[method] ) { 262 return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); 263 } else if ( typeof method === 'object' || ! method ) { 264 return methods.init.apply( this, arguments ); 265 } else { 266 $.error( 'Method ' + method + ' does not exist on jQuery.wysihtml5' ); 267 } 268 }; 269 270 $.fn.wysihtml5.Constructor = Wysihtml5; 271 272 var defaultOptions = $.fn.wysihtml5.defaultOptions = { 273 'font-styles': true, 274 'color': false, 275 'emphasis': true, 276 'lists': true, 277 'html': false, 278 'link': true, 279 'image': true, 280 events: {}, 281 parserRules: { 282 classes: { 283 'wysiwyg-color-silver' : 1, 284 'wysiwyg-color-gray' : 1, 285 'wysiwyg-color-white' : 1, 286 'wysiwyg-color-maroon' : 1, 287 'wysiwyg-color-red' : 1, 288 'wysiwyg-color-purple' : 1, 289 'wysiwyg-color-fuchsia' : 1, 290 'wysiwyg-color-green' : 1, 291 'wysiwyg-color-lime' : 1, 292 'wysiwyg-color-olive' : 1, 293 'wysiwyg-color-yellow' : 1, 294 'wysiwyg-color-navy' : 1, 295 'wysiwyg-color-blue' : 1, 296 'wysiwyg-color-teal' : 1, 297 'wysiwyg-color-aqua' : 1, 298 'wysiwyg-color-orange' : 1 299 }, 300 tags: { 301 'b': {}, 302 'i': {}, 303 'strong': {}, 304 'em': {}, 305 'p': {}, 306 'br': {}, 307 'ol': {}, 308 'ul': {}, 309 'li': {}, 310 'h1': {}, 311 'h2': {}, 312 'h3': {}, 313 'h4': {}, 314 'h5': {}, 315 'h6': {}, 316 'blockquote': {}, 317 'u': 1, 318 'img': { 319 'check_attributes': { 320 'width': 'numbers', 321 'alt': 'alt', 322 'src': 'url', 323 'height': 'numbers' 324 } 325 }, 326 'a': { 327 check_attributes: { 328 'href': 'url' // important to avoid XSS 329 }, 330 'set_attributes': { 331 'target': '_blank', 332 'rel': 'nofollow' 333 } 334 }, 335 'span': 1, 336 'div': 1, 337 // to allow save and edit files with code tag hacks 338 'code': 1, 339 'pre': 1 340 } 341 }, 342 locale: 'en' 343 }; 344 345 if (typeof $.fn.wysihtml5.defaultOptionsCache === 'undefined') { 346 $.fn.wysihtml5.defaultOptionsCache = $.extend(true, {}, $.fn.wysihtml5.defaultOptions); 347 } 348 349 var locale = $.fn.wysihtml5.locale = {}; 350})(window.jQuery, window.wysihtml5);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.