diff --git a/app/assets/javascripts/comfy/vendor/redactor.js b/app/assets/javascripts/comfy/vendor/redactor.js index 89174d00..955dc1a5 100755 --- a/app/assets/javascripts/comfy/vendor/redactor.js +++ b/app/assets/javascripts/comfy/vendor/redactor.js @@ -13,9195 +13,9001 @@ fixes and tweaks annotated with "COMFY FIX" */ -import jQuery from "jquery"; - -(function ($) { - "use strict"; - - if (!Function.prototype.bind) { - Function.prototype.bind = function (scope) { - var fn = this; - return function () { - return fn.apply(scope); - }; - }; - } - - var uuid = 0; - - // Plugin - $.fn.redactor = function (options) { - var val = []; - var args = Array.prototype.slice.call(arguments, 1); - - if (typeof options === "string") { - this.each(function () { - var instance = $.data(this, "redactor"); - var func; - - if (options.search(/\./) != "-1") { - func = options.split("."); - if (typeof instance[func[0]] != "undefined") { - func = instance[func[0]][func[1]]; - } - } else { - func = instance[options]; - } - - if (typeof instance !== "undefined" && $.isFunction(func)) { - var methodVal = func.apply(instance, args); - if (methodVal !== undefined && methodVal !== instance) { - val.push(methodVal); - } - } else { - $.error('No such method "' + options + '" for Redactor'); - } - }); - } else { - this.each(function () { - $.data(this, "redactor", {}); - $.data(this, "redactor", Redactor(this, options)); - }); - } - - if (val.length === 0) return this; - else if (val.length === 1) return val[0]; - else return val; - }; - - // Initialization - function Redactor(el, options) { - return new Redactor.prototype.init(el, options); - } - - // Functionality - $.Redactor = Redactor; - $.Redactor.VERSION = "10.2.5"; - $.Redactor.modules = [ - "alignment", - "autosave", - "block", - "buffer", - "build", - "button", - "caret", - "clean", - "code", - "core", - "dropdown", - "file", - "focus", - "image", - "indent", - "inline", - "insert", - "keydown", - "keyup", - "lang", - "line", - "link", - "linkify", - "list", - "modal", - "observe", - "paragraphize", - "paste", - "placeholder", - "progress", - "selection", - "shortcuts", - "tabifier", - "tidy", - "toolbar", - "upload", - "utils", - ]; - - $.Redactor.opts = { - // settings - lang: "en", - direction: "ltr", // ltr or rtl - - plugins: false, // array - - focus: false, - focusEnd: false, - - placeholder: false, - - visual: true, - tabindex: false, - - minHeight: false, - maxHeight: false, - - linebreaks: false, - replaceDivs: true, - paragraphize: true, - cleanStyleOnEnter: false, - enterKey: true, - - cleanOnPaste: true, - cleanSpaces: true, - pastePlainText: false, - - autosave: false, // false or url - autosaveName: false, - autosaveInterval: 60, // seconds - autosaveOnChange: false, - autosaveFields: false, - - linkTooltip: true, - linkProtocol: "http", - linkNofollow: false, - linkSize: 50, - - imageEditable: true, - imageLink: true, - imagePosition: true, - imageFloatMargin: "10px", - imageResizable: true, - - imageUpload: null, - imageUploadParam: "file", - - uploadImageField: false, - - dragImageUpload: true, - - fileUpload: null, - fileUploadParam: "file", - - dragFileUpload: true, - - s3: false, - - convertLinks: true, - convertUrlLinks: true, - convertImageLinks: true, - convertVideoLinks: true, - - preSpaces: 4, // or false - tabAsSpaces: false, // true or number of spaces - tabKey: true, - - scrollTarget: false, - - toolbar: true, - toolbarFixed: true, - toolbarFixedTarget: document, - toolbarFixedTopOffset: 0, // pixels - toolbarExternal: false, // ID selector - toolbarOverflow: false, - - source: true, - buttons: [ - "html", - "formatting", - "bold", - "italic", - "deleted", - "unorderedlist", - "orderedlist", - "outdent", - "indent", - "image", - "file", - "link", - "alignment", - "horizontalrule", - ], // + 'underline' - - buttonsHide: [], - buttonsHideOnMobile: [], - - formatting: ["p", "blockquote", "pre", "h1", "h2", "h3", "h4", "h5", "h6"], - formattingAdd: false, - - tabifier: true, - - deniedTags: ["script", "style"], - allowedTags: false, // or array - - paragraphizeBlocks: [ - "table", - "div", - "pre", - "form", - "ul", - "ol", - "h1", - "h2", - "h3", - "h4", - "h5", - "h6", - "dl", - "blockquote", - "figcaption", - "address", - "section", - "header", - "footer", - "aside", - "article", - "object", - "style", - "script", - "iframe", - "select", - "input", - "textarea", - "button", - "option", - "map", - "area", - "math", - "hr", - "fieldset", - "legend", - "hgroup", - "nav", - "figure", - "details", - "menu", - "summary", - "p", - ], - - removeComments: false, - replaceTags: [ - ["strike", "del"], - ["b", "strong"], - ], - replaceStyles: [ - ["font-weight:\\s?bold", "strong"], - ["font-style:\\s?italic", "em"], - ["text-decoration:\\s?underline", "u"], - ["text-decoration:\\s?line-through", "del"], - ], - removeDataAttr: false, - - removeAttr: false, // or multi array - allowedAttr: false, // or multi array - - removeWithoutAttr: ["span"], // or false - removeEmpty: ["p"], // or false; - - activeButtons: [ - "deleted", - "italic", - "bold", - "underline", - "unorderedlist", - "orderedlist", - "alignleft", - "aligncenter", - "alignright", - "justify", - ], - activeButtonsStates: { - b: "bold", - strong: "bold", - i: "italic", - em: "italic", - del: "deleted", - strike: "deleted", - ul: "unorderedlist", - ol: "orderedlist", - u: "underline", - }, - - shortcuts: { - "ctrl+shift+m, meta+shift+m": { func: "inline.removeFormat" }, - "ctrl+b, meta+b": { func: "inline.format", params: ["bold"] }, - "ctrl+i, meta+i": { func: "inline.format", params: ["italic"] }, - "ctrl+h, meta+h": { func: "inline.format", params: ["superscript"] }, - "ctrl+l, meta+l": { func: "inline.format", params: ["subscript"] }, - "ctrl+k, meta+k": { func: "link.show" }, - "ctrl+shift+7": { func: "list.toggle", params: ["orderedlist"] }, - "ctrl+shift+8": { func: "list.toggle", params: ["unorderedlist"] }, - }, - shortcutsAdd: false, - - // private - buffer: [], - rebuffer: [], - emptyHtml: "

", - invisibleSpace: "​", - imageTypes: ["image/png", "image/jpeg", "image/gif"], - indentValue: 20, - verifiedTags: [ - "a", - "img", - "b", - "strong", - "sub", - "sup", - "i", - "em", - "u", - "small", - "strike", - "del", - "cite", - "ul", - "ol", - "li", - ], // and for span tag special rule - inlineTags: [ - "strong", - "b", - "u", - "em", - "i", - "code", - "del", - "ins", - "samp", - "kbd", - "sup", - "sub", - "mark", - "var", - "cite", - "small", - ], - alignmentTags: [ - "P", - "H1", - "H2", - "H3", - "H4", - "H5", - "H6", - "DL", - "DT", - "DD", - "DIV", - "TD", - "BLOCKQUOTE", - "OUTPUT", - "FIGCAPTION", - "ADDRESS", - "SECTION", - "HEADER", - "FOOTER", - "ASIDE", - "ARTICLE", - ], - blockLevelElements: ["PRE", "UL", "OL", "LI"], - highContrast: false, - observe: { - dropdowns: [], - }, - - // lang - langs: { - en: { - html: "HTML", - video: "Insert Video", - image: "Insert Image", - table: "Table", - link: "Link", - link_insert: "Insert link", - link_edit: "Edit link", - unlink: "Unlink", - formatting: "Formatting", - paragraph: "Normal text", - quote: "Quote", - code: "Code", - header1: "Header 1", - header2: "Header 2", - header3: "Header 3", - header4: "Header 4", - header5: "Header 5", - bold: "Bold", - italic: "Italic", - fontcolor: "Font Color", - backcolor: "Back Color", - unorderedlist: "Unordered List", - orderedlist: "Ordered List", - outdent: "Outdent", - indent: "Indent", - cancel: "Cancel", - insert: "Insert", - save: "Save", - _delete: "Delete", - insert_table: "Insert Table", - insert_row_above: "Add Row Above", - insert_row_below: "Add Row Below", - insert_column_left: "Add Column Left", - insert_column_right: "Add Column Right", - delete_column: "Delete Column", - delete_row: "Delete Row", - delete_table: "Delete Table", - rows: "Rows", - columns: "Columns", - add_head: "Add Head", - delete_head: "Delete Head", - title: "Title", - image_position: "Position", - none: "None", - left: "Left", - right: "Right", - center: "Center", - image_web_link: "Image Web Link", - text: "Text", - mailto: "Email", - web: "URL", - video_html_code: "Video Embed Code or Youtube/Vimeo Link", - file: "Insert File", - upload: "Upload", - download: "Download", - choose: "Choose", - or_choose: "Or choose", - drop_file_here: "Drop file here", - align_left: "Align text to the left", - align_center: "Center text", - align_right: "Align text to the right", - align_justify: "Justify text", - horizontalrule: "Insert Horizontal Rule", - deleted: "Deleted", - anchor: "Anchor", - link_new_tab: "Open link in new tab", - underline: "Underline", - alignment: "Alignment", - filename: "Name (optional)", - edit: "Edit", - upload_label: "Drop file here or ", - }, - }, - - linkify: { - regexps: { - youtube: - /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w.\-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/gi, - vimeo: /https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/, - image: /((https?|www)[^\s]+\.)(jpe?g|png|gif)(\?[^\s-]+)?/gi, - url: /(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/gi, - }, - }, - - codemirror: false, - }; - - // Functionality - Redactor.fn = $.Redactor.prototype = { - keyCode: { - BACKSPACE: 8, - DELETE: 46, - UP: 38, - DOWN: 40, - ENTER: 13, - SPACE: 32, - ESC: 27, - TAB: 9, - CTRL: 17, - META: 91, - SHIFT: 16, - ALT: 18, - RIGHT: 39, - LEFT: 37, - LEFT_WIN: 91, - }, - - // Initialization - init: function (el, options) { - this.$element = $(el); - this.uuid = uuid++; - - // if paste event detected = true - this.rtePaste = false; - this.$pasteBox = false; - - this.loadOptions(options); - this.loadModules(); - - // formatting storage - this.formatting = {}; - - // block level tags - $.merge(this.opts.blockLevelElements, this.opts.alignmentTags); - this.reIsBlock = new RegExp( - "^(" + this.opts.blockLevelElements.join("|") + ")$", - "i" - ); - - // setup allowed and denied tags - this.tidy.setupAllowed(); - - // setup denied tags - if (this.opts.deniedTags !== false) { - var tags = ["html", "head", "link", "body", "meta", "applet"]; - for (var i = 0; i < tags.length; i++) { - this.opts.deniedTags.push(tags[i]); - } - } - - // load lang - this.lang.load(); - - // extend shortcuts - $.extend(this.opts.shortcuts, this.opts.shortcutsAdd); - - // start callback - this.core.setCallback("start"); - - // build - this.start = true; - this.build.run(); - }, - - loadOptions: function (options) { - this.opts = $.extend( - {}, - $.extend(true, {}, $.Redactor.opts), - this.$element.data(), - options - ); - }, - getModuleMethods: function (object) { - return Object.getOwnPropertyNames(object).filter(function (property) { - return typeof object[property] == "function"; - }); - }, - loadModules: function () { - var len = $.Redactor.modules.length; - for (var i = 0; i < len; i++) { - this.bindModuleMethods($.Redactor.modules[i]); - } - }, - bindModuleMethods: function (module) { - if (typeof this[module] == "undefined") return; - - // init module - this[module] = this[module](); - - var methods = this.getModuleMethods(this[module]); - var len = methods.length; - - // bind methods - for (var z = 0; z < len; z++) { - this[module][methods[z]] = this[module][methods[z]].bind(this); - } - }, - alignment: function () { - return { - left: function () { - this.alignment.set(""); - }, - right: function () { - this.alignment.set("right"); - }, - center: function () { - this.alignment.set("center"); - }, - justify: function () { - this.alignment.set("justify"); - }, - set: function (type) { - // focus - if (!this.utils.browser("msie") && !this.opts.linebreaks) { - this.$editor.focus(); - } - - // get blocks - this.alignment.blocks = this.selection.getBlocks(); - this.alignment.type = type; - - this.buffer.set(); - this.selection.save(); - - // set alignment - if (this.alignment.isLinebreaksOrNoBlocks()) { - this.alignment.setText(); - } else { - this.alignment.setBlocks(); - } - - // sync - this.selection.restore(); - this.code.sync(); - }, - setText: function () { - var wrapper = this.selection.wrap("div"); - $(wrapper) - .attr("data-tagblock", "redactor") - .css("text-align", this.alignment.type); - }, - setBlocks: function () { - $.each( - this.alignment.blocks, - $.proxy(function (i, el) { - var $el = this.utils.getAlignmentElement(el); - if (!$el) return; - - if (this.alignment.isNeedReplaceElement($el)) { - this.alignment.replaceElement($el); - } else { - this.alignment.alignElement($el); - } - }, this) - ); - }, - isLinebreaksOrNoBlocks: function () { - return this.opts.linebreaks && this.alignment.blocks[0] === false; - }, - isNeedReplaceElement: function ($el) { - return ( - this.alignment.type === "" && - typeof $el.data("tagblock") !== "undefined" - ); - }, - replaceElement: function ($el) { - $el.replaceWith($el.html()); - }, - alignElement: function ($el) { - $el.css("text-align", this.alignment.type); - this.utils.removeEmptyAttr($el, "style"); - }, - }; - }, - autosave: function () { - return { - html: false, - enable: function () { - if (!this.opts.autosave) return; - - this.autosave.name = this.opts.autosaveName - ? this.opts.autosaveName - : this.$textarea.attr("name"); - - if (this.opts.autosaveOnChange) return; - this.autosaveInterval = setInterval( - this.autosave.load, - this.opts.autosaveInterval * 1000 - ); - }, - onChange: function () { - if (!this.opts.autosaveOnChange) return; - this.autosave.load(); - }, - load: function () { - if (!this.opts.autosave) return; - - this.autosave.source = this.code.get(); - - if (this.autosave.html === this.autosave.source) return; - - // data - var data = {}; - data["name"] = this.autosave.name; - data[this.autosave.name] = this.autosave.source; - data = this.autosave.getHiddenFields(data); - - // ajax - var jsxhr = $.ajax({ - url: this.opts.autosave, - type: "post", - data: data, - }); - - jsxhr.done(this.autosave.success); - }, - getHiddenFields: function (data) { - if ( - this.opts.autosaveFields === false || - typeof this.opts.autosaveFields !== "object" - ) { - return data; - } - - $.each( - this.opts.autosaveFields, - $.proxy(function (k, v) { - if (v !== null && v.toString().indexOf("#") === 0) v = $(v).val(); - data[k] = v; - }, this) - ); - - return data; - }, - success: function (data) { - var json; - try { - json = $.parseJSON(data); - } catch (e) { - //data has already been parsed - json = data; - } - - var callbackName = - typeof json.error == "undefined" ? "autosave" : "autosaveError"; - - this.core.setCallback(callbackName, this.autosave.name, json); - this.autosave.html = this.autosave.source; - }, - disable: function () { - clearInterval(this.autosaveInterval); - }, - }; - }, - block: function () { - return { - formatting: function (name) { - this.block.clearStyle = false; - var type, value; - - if (typeof this.formatting[name].data != "undefined") type = "data"; - else if (typeof this.formatting[name].attr != "undefined") - type = "attr"; - else if (typeof this.formatting[name]["class"] != "undefined") - type = "class"; - - if (typeof this.formatting[name].clear != "undefined") { - this.block.clearStyle = true; - } - - if (type) value = this.formatting[name][type]; - - this.block.format(this.formatting[name].tag, type, value); - }, - format: function (tag, type, value) { - if (tag == "quote") tag = "blockquote"; - - var formatTags = [ - "p", - "pre", - "blockquote", - "h1", - "h2", - "h3", - "h4", - "h5", - "h6", - ]; - if ($.inArray(tag, formatTags) == -1) return; - - this.block.isRemoveInline = - tag == "pre" || tag.search(/h[1-6]/i) != -1; - - // focus - if (!this.utils.browser("msie")) this.$editor.focus(); - - var html = $.trim(this.$editor.html()); - this.block.isEmpty = this.utils.isEmpty(html); - - // FF focus - if (this.utils.browser("mozilla") && !this.focus.isFocused()) { - if (this.block.isEmpty) { - var $first; - if (!this.opts.linebreaks) { - $first = this.$editor.children().first(); - this.caret.setEnd($first); - } - } - } - - this.block.blocks = this.selection.getBlocks(); - - this.block.blocksSize = this.block.blocks.length; - this.block.type = type; - this.block.value = value; - - this.buffer.set(); - this.selection.save(); - - this.block.set(tag); - - this.selection.restore(); - this.code.sync(); - this.observe.load(); - }, - set: function (tag) { - this.selection.get(); - this.block.containerTag = this.range.commonAncestorContainer.tagName; - - if (this.range.collapsed) { - this.block.setCollapsed(tag); - } else { - this.block.setMultiple(tag); - } - }, - setCollapsed: function (tag) { - if (this.opts.linebreaks && this.block.isEmpty && tag != "p") { - var node = document.createElement(tag); - this.$editor.html(node); - this.caret.setEnd(node); - - return; - } - - var block = this.block.blocks[0]; - if (block === false) return; - - if (block.tagName == "LI") { - if (tag != "blockquote") return; - - this.block.formatListToBlockquote(); - return; - } - - var isContainerTable = - this.block.containerTag == "TD" || this.block.containerTag == "TH"; - if (isContainerTable && !this.opts.linebreaks) { - document.execCommand("formatblock", false, "<" + tag + ">"); - - block = this.selection.getBlock(); - this.block.toggle($(block)); - } else if (block.tagName.toLowerCase() != tag) { - if (this.opts.linebreaks && tag == "p") { - $(block).append("
"); - this.utils.replaceWithContents(block); - } else { - var $formatted = this.utils.replaceToTag(block, tag); - - this.block.toggle($formatted); - - if (tag != "p" && tag != "blockquote") - $formatted.find("img").remove(); - if (this.block.isRemoveInline) - this.utils.removeInlineTags($formatted); - if (tag == "p" || this.block.headTag) - $formatted.find("p").contents().unwrap(); - - this.block.formatTableWrapping($formatted); - } - } else if ( - tag == "blockquote" && - block.tagName.toLowerCase() == tag - ) { - // blockquote off - if (this.opts.linebreaks) { - $(block).append("
"); - this.utils.replaceWithContents(block); - } else { - var $el = this.utils.replaceToTag(block, "p"); - this.block.toggle($el); - } - } else if (block.tagName.toLowerCase() == tag) { - this.block.toggle($(block)); - } - - if ( - typeof this.block.type == "undefined" && - typeof this.block.value == "undefined" - ) { - $(block).removeAttr("class").removeAttr("style"); - } - }, - setMultiple: function (tag) { - var block = this.block.blocks[0]; - - var isContainerTable = - this.block.containerTag == "TD" || this.block.containerTag == "TH"; - - if (block !== false && this.block.blocksSize === 1) { - if (block.tagName.toLowerCase() == tag && tag == "blockquote") { - // blockquote off - if (this.opts.linebreaks) { - $(block).append("
"); - this.utils.replaceWithContents(block); - } else { - var $el = this.utils.replaceToTag(block, "p"); - this.block.toggle($el); - } - } else if (block.tagName == "LI") { - if (tag != "blockquote") return; - - this.block.formatListToBlockquote(); - } else if (this.block.containerTag == "BLOCKQUOTE") { - this.block.formatBlockquote(tag); - } else if ( - this.opts.linebreaks && - (isContainerTable || this.range.commonAncestorContainer != block) - ) { - this.block.formatWrap(tag); - } else { - if (this.opts.linebreaks && tag == "p") { - $(block).prepend("
").append("
"); - this.utils.replaceWithContents(block); - } else if (block.tagName === "TD") { - this.block.formatWrap(tag); - } else { - var $formatted = this.utils.replaceToTag(block, tag); - - this.block.toggle($formatted); - - if (this.block.isRemoveInline) - this.utils.removeInlineTags($formatted); - if (tag == "p" || this.block.headTag) - $formatted.find("p").contents().unwrap(); - } - } - } else { - if (this.opts.linebreaks || tag != "p") { - if (tag == "blockquote") { - var count = 0; - for (var i = 0; i < this.block.blocksSize; i++) { - if (this.block.blocks[i].tagName == "BLOCKQUOTE") count++; - } - - // only blockquote selected - if (count == this.block.blocksSize) { - $.each( - this.block.blocks, - $.proxy(function (i, s) { - var $formatted = false; - if (this.opts.linebreaks) { - $(s).prepend("
").append("
"); - $formatted = this.utils.replaceWithContents(s); - } else { - $formatted = this.utils.replaceToTag(s, "p"); - } - - if ( - $formatted && - typeof this.block.type == "undefined" && - typeof this.block.value == "undefined" - ) { - $formatted.removeAttr("class").removeAttr("style"); - } - }, this) - ); - - return; - } - } - - this.block.formatWrap(tag); - } else { - var classSize = 0; - var toggleType = false; - if (this.block.type == "class") { - toggleType = "toggle"; - classSize = $(this.block.blocks).filter( - "." + this.block.value - ).length; - - if (this.block.blocksSize == classSize) toggleType = "toggle"; - else if (this.block.blocksSize > classSize) toggleType = "set"; - else if (classSize === 0) toggleType = "set"; - } - - var exceptTags = ["ul", "ol", "li", "td", "th", "dl", "dt", "dd"]; - $.each( - this.block.blocks, - $.proxy(function (i, s) { - if ($.inArray(s.tagName.toLowerCase(), exceptTags) != -1) - return; - - var $formatted = this.utils.replaceToTag(s, tag); - - if (toggleType) { - if (toggleType == "toggle") this.block.toggle($formatted); - else if (toggleType == "remove") - this.block.remove($formatted); - else if (toggleType == "set") - this.block.setForce($formatted); - } else this.block.toggle($formatted); - - if (tag != "p" && tag != "blockquote") - $formatted.find("img").remove(); - if (this.block.isRemoveInline) - this.utils.removeInlineTags($formatted); - if (tag == "p" || this.block.headTag) - $formatted.find("p").contents().unwrap(); - - if ( - typeof this.block.type == "undefined" && - typeof this.block.value == "undefined" - ) { - $formatted.removeAttr("class").removeAttr("style"); - } - }, this) - ); - } - } - }, - setForce: function ($el) { - // remove style and class if the specified setting - if (this.block.clearStyle) { - $el.removeAttr("class").removeAttr("style"); - } - - if (this.block.type == "class") { - $el.addClass(this.block.value); - return; - } else if (this.block.type == "attr" || this.block.type == "data") { - $el.attr(this.block.value.name, this.block.value.value); - return; - } - }, - toggle: function ($el) { - // remove style and class if the specified setting - if (this.block.clearStyle) { - $el.removeAttr("class").removeAttr("style"); - } - - if (this.block.type == "class") { - $el.toggleClass(this.block.value); - return; - } else if (this.block.type == "attr" || this.block.type == "data") { - if ($el.attr(this.block.value.name) == this.block.value.value) { - $el.removeAttr(this.block.value.name); - } else { - $el.attr(this.block.value.name, this.block.value.value); - } - - return; - } else { - $el.removeAttr("style class"); - return; - } - }, - remove: function ($el) { - $el.removeClass(this.block.value); - }, - formatListToBlockquote: function () { - var block = $(this.block.blocks[0]).closest( - "ul, ol", - this.$editor[0] - ); - - $(block).find("ul, ol").contents().unwrap(); - $(block).find("li").append($("
")).contents().unwrap(); - - var $el = this.utils.replaceToTag(block, "blockquote"); - this.block.toggle($el); - }, - formatBlockquote: function (tag) { - document.execCommand("outdent"); - document.execCommand("formatblock", false, tag); - - this.clean.clearUnverified(); - this.$editor.find("p:empty").remove(); - - var formatted = this.selection.getBlock(); - - if (tag != "p") { - $(formatted).find("img").remove(); - } - - if (!this.opts.linebreaks) { - this.block.toggle($(formatted)); - } - - this.$editor - .find("ul, ol, tr, blockquote, p") - .each($.proxy(this.utils.removeEmpty, this)); - - if (this.opts.linebreaks && tag == "p") { - this.utils.replaceWithContents(formatted); - } - }, - formatWrap: function (tag) { - if ( - this.block.containerTag == "UL" || - this.block.containerTag == "OL" - ) { - if (tag == "blockquote") { - this.block.formatListToBlockquote(); - } else { - return; - } - } - - var formatted = this.selection.wrap(tag); - if (formatted === false) return; - - var $formatted = $(formatted); - - this.block.formatTableWrapping($formatted); - - var $elements = $formatted.find( - this.opts.blockLevelElements.join(",") + - ", td, table, thead, tbody, tfoot, th, tr" - ); - - $elements.contents().unwrap(); - - if (tag != "p" && tag != "blockquote") - $formatted.find("img").remove(); - - $.each(this.block.blocks, $.proxy(this.utils.removeEmpty, this)); - - $formatted.append(this.selection.getMarker(2)); - - if (!this.opts.linebreaks) { - this.block.toggle($formatted); - } - - this.$editor - .find("ul, ol, tr, blockquote, p") - .each($.proxy(this.utils.removeEmpty, this)); - $formatted.find("blockquote:empty").remove(); - - if (this.block.isRemoveInline) { - this.utils.removeInlineTags($formatted); - } - - if (this.opts.linebreaks && tag == "p") { - this.utils.replaceWithContents($formatted); - } - - if (this.opts.linebreaks) { - var $next = $formatted.next().next(); - if ($next.size() != 0 && $next[0].tagName === "BR") { - $next.remove(); - } - } - }, - formatTableWrapping: function ($formatted) { - if ($formatted.closest("table", this.$editor[0]).length === 0) return; - - if ($formatted.closest("tr", this.$editor[0]).length === 0) - $formatted.wrap(""); - if ( - $formatted.closest("td", this.$editor[0]).length === 0 && - $formatted.closest("th").length === 0 - ) { - $formatted.wrap(""); - } - }, - removeData: function (name, value) { - var blocks = this.selection.getBlocks(); - $(blocks).removeAttr("data-" + name); - - this.code.sync(); - }, - setData: function (name, value) { - var blocks = this.selection.getBlocks(); - $(blocks).attr("data-" + name, value); - - this.code.sync(); - }, - toggleData: function (name, value) { - var blocks = this.selection.getBlocks(); - $.each(blocks, function () { - if ($(this).attr("data-" + name)) { - $(this).removeAttr("data-" + name); - } else { - $(this).attr("data-" + name, value); - } - }); - }, - removeAttr: function (attr, value) { - var blocks = this.selection.getBlocks(); - $(blocks).removeAttr(attr); - - this.code.sync(); - }, - setAttr: function (attr, value) { - var blocks = this.selection.getBlocks(); - $(blocks).attr(attr, value); - - this.code.sync(); - }, - toggleAttr: function (attr, value) { - var blocks = this.selection.getBlocks(); - $.each(blocks, function () { - if ($(this).attr(name)) { - $(this).removeAttr(name); - } else { - $(this).attr(name, value); - } - }); - }, - removeClass: function (className) { - var blocks = this.selection.getBlocks(); - $(blocks).removeClass(className); - - this.utils.removeEmptyAttr(blocks, "class"); - - this.code.sync(); - }, - setClass: function (className) { - var blocks = this.selection.getBlocks(); - $(blocks).addClass(className); - - this.code.sync(); - }, - toggleClass: function (className) { - var blocks = this.selection.getBlocks(); - $(blocks).toggleClass(className); - - this.code.sync(); - }, - }; - }, - buffer: function () { - return { - set: function (type) { - if (typeof type == "undefined" || type == "undo") { - this.buffer.setUndo(); - } else { - this.buffer.setRedo(); - } - }, - setUndo: function () { - this.selection.save(); - this.opts.buffer.push(this.$editor.html()); - this.selection.restore(); - }, - setRedo: function () { - this.selection.save(); - this.opts.rebuffer.push(this.$editor.html()); - this.selection.restore(); - }, - getUndo: function () { - this.$editor.html(this.opts.buffer.pop()); - }, - getRedo: function () { - this.$editor.html(this.opts.rebuffer.pop()); - }, - add: function () { - this.opts.buffer.push(this.$editor.html()); - }, - undo: function () { - if (this.opts.buffer.length === 0) return; - - this.buffer.set("redo"); - this.buffer.getUndo(); - - this.selection.restore(); - - setTimeout($.proxy(this.observe.load, this), 50); - }, - redo: function () { - if (this.opts.rebuffer.length === 0) return; - - this.buffer.set("undo"); - this.buffer.getRedo(); - - this.selection.restore(); - - setTimeout($.proxy(this.observe.load, this), 50); - }, - }; - }, - build: function () { - return { - focused: false, - blured: true, - run: function () { - this.build.createContainerBox(); - this.build.loadContent(); - this.build.loadEditor(); - this.build.enableEditor(); - this.build.setCodeAndCall(); - }, - isTextarea: function () { - return this.$element[0].tagName === "TEXTAREA"; - }, - createContainerBox: function () { - this.$box = $('
'); - }, - createTextarea: function () { - this.$textarea = $("