mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
8 lines
221 KiB
JavaScript
8 lines
221 KiB
JavaScript
|
!function(factory){"function"==typeof define&&define.amd?define(["jquery"],factory):"object"==typeof module&&module.exports?module.exports=function(root,jQuery){return void 0===jQuery&&(jQuery="undefined"!=typeof window?require("jquery"):require("jquery")(root)),factory(jQuery),jQuery}:factory(jQuery)}(function($){"use strict";var FroalaEditor=function(element,options){this.opts=$.extend({},FroalaEditor.DEFAULTS,$(element).data(),"object"==typeof options&&options),this.$original_element=$(element),this.$original_element.data("froala.editor",this),this.id=++$.FroalaEditor.ID,this.original_document=element.ownerDocument,this.original_window="defaultView"in this.original_document?this.original_document.defaultView:this.original_document.parentWindow;var c_scroll=$(this.original_window).scrollTop();this.$original_element.on("froala.doInit",$.proxy(function(){this.$original_element.off("froala.doInit"),this.document=this.$el.get(0).ownerDocument,this.window="defaultView"in this.document?this.document.defaultView:this.document.parentWindow,this.$document=$(this.document),this.$window=$(this.window),this.opts.initOnClick?(this.load($.FroalaEditor.MODULES),this.$el.on("mousedown.init dragenter.init focus.init",$.proxy(function(e){if(1===e.which){this.$el.off("mousedown.init dragenter.init focus.init"),this.load($.FroalaEditor.MODULES),this.load($.FroalaEditor.PLUGINS);var target=e.originalEvent&&e.originalEvent.originalTarget;target&&"IMG"==target.tagName&&$(target).trigger("mousedown"),"undefined"==typeof this.ul&&this.destroy(),this.events.trigger("initialized")}},this))):(this.load($.FroalaEditor.MODULES),this.load($.FroalaEditor.PLUGINS),$(this.original_window).scrollTop(c_scroll),"undefined"==typeof this.ul&&this.destroy(),this.events.trigger("initialized"))},this)),this._init()};FroalaEditor.DEFAULTS={initOnClick:!1},FroalaEditor.MODULES={},FroalaEditor.PLUGINS={},FroalaEditor.VERSION="2.0.5",FroalaEditor.INSTANCES=[],FroalaEditor.ID=0,FroalaEditor.prototype._init=function(){var tag_name=this.$original_element.prop("tagName"),initOnDefault=$.proxy(function(){this._original_html=this._original_html||this.$original_element.html(),this.$box=this.$box||this.$original_element,this.opts.fullPage&&(this.opts.iframe=!0),this.opts.iframe?(this.$iframe=$('<iframe src="about:blank" frameBorder="0">'),this.$wp=$("<div></div>"),this.$box.html(this.$wp),this.$wp.append(this.$iframe),this.$iframe.get(0).contentWindow.document.open(),this.$iframe.get(0).contentWindow.document.write("<!DOCTYPE html>"),this.$iframe.get(0).contentWindow.document.write("<html><head></head><body></body></html>"),this.$iframe.get(0).contentWindow.document.close(),this.$el=this.$iframe.contents().find("body"),this.$head=this.$iframe.contents().find("head"),this.$html=this.$iframe.contents().find("html"),this.iframe_document=this.$iframe.get(0).contentWindow.document,this.$original_element.trigger("froala.doInit")):(this.$el=$("<div></div>"),this.$wp=$("<div></div>").append(this.$el),this.$box.html(this.$wp),this.$original_element.trigger("froala.doInit"))},this),initOnTextarea=$.proxy(function(){this.$box=$("<div>"),this.$original_element.before(this.$box).hide(),this._original_html=this.$original_element.val(),this.$original_element.parents("form").on("submit."+this.id,$.proxy(function(){this.events.trigger("form.submit")},this)),initOnDefault()},this),initOnA=$.proxy(function(){this.$el=this.$original_element,this.$el.attr("contenteditable",!0).css("outline","none"),this.opts.multiLine=!1,this.$original_element.trigger("froala.doInit")},this),initOnImg=$.proxy(function(){this.$el=this.$original_element,this.$original_element.trigger("froala.doInit")},this),editInPopup=$.proxy(function(){this.$el=this.$original_element,this.$original_element.trigger("froala.doInit")},this);this.opts.editInPopup?editInPopup():"TEXTAREA"==tag_name?initOnTextarea():"A"==tag_name?initOnA():"IMG"==tag_name?initOnImg():"BUTTON"==tag_name?(this.opts.editInPopup=!0,editInPopup()):("DIV"!==tag_name&&(this.opts.enter=$.FroalaEditor.ENTER_BR),initOnDefault())},FroalaEditor.prototype.load
|
||
|
}function place(range,marker,id){try{var boundary=range.cloneRange();if(boundary.collapse(marker),boundary.insertNode(_build(marker,id)),marker===!0&&range.collapsed)for(var sibling=editor.$el.find('span.fr-marker[data-type="true"][data-id="'+id+'"]').get(0).nextSibling;sibling&&sibling.nodeType===Node.TEXT_NODE&&0===sibling.textContent.length;)$(sibling).remove(),sibling=editor.$el.find('span.fr-marker[data-type="true"][data-id="'+id+'"]').get(0).nextSibling;if(marker===!0&&!range.collapsed){var marker=editor.$el.find('span.fr-marker[data-type="true"][data-id="'+id+'"]').get(0),sibling=marker.nextSibling;if(sibling&&sibling.nodeType===Node.ELEMENT_NODE&&editor.node.isBlock(sibling)){var contents=[sibling];do sibling=contents[0],contents=editor.node.contents(sibling);while(contents[0]&&editor.node.isBlock(contents[0]));$(sibling).prepend($(marker))}}if(marker===!1&&!range.collapsed){var marker=editor.$el.find('span.fr-marker[data-type="false"][data-id="'+id+'"]').get(0),sibling=marker.previousSibling;if(sibling&&sibling.nodeType===Node.ELEMENT_NODE&&editor.node.isBlock(sibling)){var contents=[sibling];do sibling=contents[contents.length-1],contents=editor.node.contents(sibling);while(contents[contents.length-1]&&editor.node.isBlock(contents[contents.length-1]));$(sibling).append($(marker))}marker.parentNode&&["TD","TH"].indexOf(marker.parentNode.tagName)>=0&&marker.parentNode.previousSibling&&!marker.previousSibling&&$(marker.parentNode.previousSibling).append(marker)}return marker}catch(ex){return null}}function insert(){if(!editor.$wp)return null;try{var range=editor.selection.ranges(0),containter=range.commonAncestorContainer;if(containter!=editor.$el.get(0)&&0==editor.$el.find(containter).length)return null;var boundary=range.cloneRange(),original_range=range.cloneRange();boundary.collapse(!0);var mk=$('<span class="fr-marker" style="display: none; line-height: 0;">'+$.FroalaEditor.INVISIBLE_SPACE+"</span>",editor.document)[0];if(boundary.insertNode(mk),mk=editor.$el.find("span.fr-marker").get(0)){for(var sibling=mk.nextSibling;sibling&&sibling.nodeType===Node.TEXT_NODE&&0===sibling.textContent.length;)$(sibling).remove(),sibling=editor.$el.find("span.fr-marker").get(0).nextSibling;return editor.selection.clear(),editor.selection.get().addRange(original_range),mk}return null}catch(ex){console.warn("MARKER",ex)}}function insertAtPoint(e){var x=e.clientX,y=e.clientY;remove();var start,range=null;if("undefined"!=typeof editor.document.caretPositionFromPoint?(start=editor.document.caretPositionFromPoint(x,y),range=editor.document.createRange(),range.setStart(start.offsetNode,start.offset),range.setEnd(start.offsetNode,start.offset)):"undefined"!=typeof editor.document.caretRangeFromPoint&&(start=editor.document.caretRangeFromPoint(x,y),range=editor.document.createRange(),range.setStart(start.startContainer,start.startOffset),range.setEnd(start.startContainer,start.startOffset)),null!==range&&"undefined"!=typeof editor.window.getSelection){var sel=editor.window.getSelection();sel.removeAllRanges(),sel.addRange(range)}else if("undefined"!=typeof editor.document.body.createTextRange)try{range=editor.document.body.createTextRange(),range.moveToPoint(x,y);var end_range=range.duplicate();end_range.moveToPoint(x,y),range.setEndPoint("EndToEnd",end_range),range.select()}catch(ex){}insert()}function remove(){editor.$el.find(".fr-marker").remove()}return{place:place,insert:insert,insertAtPoint:insertAtPoint,remove:remove}},$.FroalaEditor.MODULES.selection=function(editor){function text(){var text="";return editor.window.getSelection?text=editor.window.getSelection():editor.document.getSelection?text=editor.document.getSelection():editor.document.selection&&(text=editor.document.selection.createRange().text),text.toString()}function get(){var selection="";return selection=editor.window.getSelection?editor.window.getSelection():editor.document.getSelection?editor.document.getSelection():editor.document.selection.createRange()}function ranges(index){var sel=get(),ranges=[];if(sel&&sel.getRangeAt&&sel.rangeCount)for(var ranges=[],i=0
|
||
|
editor.opts.fullPage?(html=getDoctype(editor.iframe_document),html+="<html"+editor.node.attributes(editor.$html.get(0))+">"+editor.$html.html()+"</html>"):html=editor.$el.html()),!editor.opts.useClasses&&!keep_classes)for(i=0;i<updated_elms.length;i++)updated_elms[i].getAttribute("fr-original-class")&&(updated_elms[i].setAttribute("class",updated_elms[i].getAttribute("fr-original-class")),updated_elms[i].removeAttribute("fr-original-class")),updated_elms[i].setAttribute("style",updated_elms[i].getAttribute("fr-original-style")),updated_elms[i].removeAttribute("fr-original-style");html=html.replace(/<pre(?:[\w\W]*?)>(?:[\w\W]*?)<\/pre>/g,function(str){return str.replace(/<br>/g,"\n")}),editor.opts.fullPage&&(html=html.replace(/<style data-fr-style="true">(?:[\w\W]*?)<\/style>/g,""),html=html.replace(/<style(?:[\w\W]*?)class="firebugResetStyles"(?:[\w\W]*?)>(?:[\w\W]*?)<\/style>/g,""),html=html.replace(/<body((?:[\w\W]*?)) spellcheck="true"((?:[\w\W]*?))>((?:[\w\W]*?))<\/body>/g,"<body$1$2>$3</body>"),html=html.replace(/<body((?:[\w\W]*?)) contenteditable="(true|false)"((?:[\w\W]*?))>((?:[\w\W]*?))<\/body>/g,"<body$1$3>$4</body>"),html=html.replace(/<body((?:[\w\W]*?)) dir="([\w]*)"((?:[\w\W]*?))>((?:[\w\W]*?))<\/body>/g,"<body$1$3>$4</body>"),html=html.replace(/<body((?:[\w\W]*?))class="([\w\W]*?)(fr-rtl|fr-ltr)([\w\W]*?)"((?:[\w\W]*?))>((?:[\w\W]*?))<\/body>/g,'<body$1class="$2$4"$5>$6</body>'),html=html.replace(/<body((?:[\w\W]*?)) class=""((?:[\w\W]*?))>((?:[\w\W]*?))<\/body>/g,"<body$1$2>$3</body>")),editor.opts.htmlSimpleAmpersand&&(html=html.replace(/\&/gi,"&")),editor.events.trigger("html.afterGet"),keep_markers||(html=html.replace(/<span[^>]*? class\s*=\s*["']?fr-marker["']?[^>]+>\u200b<\/span>/gi,"")),html=editor.clean.invisibleSpaces(html);var new_html=editor.events.chainTrigger("html.get",html);return"string"==typeof new_html&&(html=new_html),html}function getSelected(){var wrapSelection=function(container,node){for(;node&&(node.nodeType==Node.TEXT_NODE||!editor.node.isBlock(node));)node&&node.nodeType!=Node.TEXT_NODE&&$(container).wrapInner(editor.node.openTagString(node)+editor.node.closeTagString(node)),node=node.parentNode;node&&container.innerHTML==node.innerHTML&&(container.innerHTML=node.outerHTML)},selectionParent=function(){var sel,parent=null;return editor.window.getSelection?(sel=editor.window.getSelection(),sel&&sel.rangeCount&&(parent=sel.getRangeAt(0).commonAncestorContainer,parent.nodeType!=Node.ELEMENT_NODE&&(parent=parent.parentNode))):(sel=editor.document.selection)&&"Control"!=sel.type&&(parent=sel.createRange().parentElement()),null!=parent&&($.inArray(editor.$el.get(0),$(parent).parents())>=0||parent==editor.$el.get(0))?parent:null},html="";if("undefined"!=typeof editor.window.getSelection){editor.browser.mozilla&&(editor.selection.save(),editor.$el.find('.fr-marker[data-type="false"]').length>1&&(editor.$el.find('.fr-marker[data-type="false"][data-id="0"]').remove(),editor.$el.find('.fr-marker[data-type="false"]:last').attr("data-id","0"),editor.$el.find(".fr-marker").not('[data-id="0"]').remove()),editor.selection.restore());for(var ranges=editor.selection.ranges(),i=0;i<ranges.length;i++){var container=document.createElement("div");container.appendChild(ranges[i].cloneContents()),wrapSelection(container,selectionParent()),html+=container.innerHTML}}else"undefined"!=typeof editor.document.selection&&"Text"==editor.document.selection.type&&(html=editor.document.selection.createRange().htmlText);return html}function _hasBlockTags(html){var $tmp=$("<div>").html(html);return $tmp.find(blockTagsQuery()).length>0}function _setCursorAtEnd(html){var tmp=editor.document.createElement("div");return tmp.innerHTML=html,editor.selection.setAtEnd(tmp),tmp.innerHTML}function escapeEntities(str){return str.replace(/</gi,"<").replace(/>/gi,">").replace(/"/gi,""").replace(/'/gi,"'")}function insert(dirty_html,clean){""!==editor.selection.text()&&editor.selection.remove();var clean_html;if(clean_html=clean?dirty_html:editor.clean.html(dirty_html),dirty_html.indexOf('class="fr-marker"')<
|
||
|
prev_node.textContent.length&&55357==prev_node.textContent.charCodeAt(prev_node.textContent.length-1)&&(prev_node.textContent=prev_node.textContent.substr(0,prev_node.textContent.length-1))))}return _atEnd(marker)?do_default=_middleBackspace(marker):_atStart(marker)?_inLi(marker)&&_isAtStart(marker,$(marker).parents("li:first").get(0))?editor.cursorLists._backspace(marker):_startBackspace(marker):do_default=_middleBackspace(marker),$(marker).remove(),editor.$el.find("blockquote:empty").remove(),editor.html.fillEmptyBlocks(!0),editor.html.cleanEmptyTags(!0),editor.clean.quotes(),editor.clean.lists(),editor.html.normalizeSpaces(),editor.selection.restore(),do_default}function _endDel(marker){var quote=$(marker).parentsUntil(editor.$el,"BLOCKQUOTE").length>0,deep_parent=editor.node.deepestParent(marker,[],!quote);if(deep_parent&&"BLOCKQUOTE"==deep_parent.tagName){var m_parent=editor.node.deepestParent(marker,[$(marker).parentsUntil(editor.$el,"BLOCKQUOTE").get(0)]);m_parent&&m_parent.nextSibling&&(deep_parent=m_parent)}if(null!==deep_parent){var contents,next_node=deep_parent.nextSibling;if(editor.node.isBlock(deep_parent)&&editor.node.isEditable(deep_parent)&&next_node&&$.FroalaEditor.NO_DELETE_TAGS.indexOf(next_node.tagName)<0)if(editor.node.isBlock(next_node)&&editor.node.isEditable(next_node))if(editor.node.isList(next_node))if(editor.node.isEmpty(deep_parent,!0))$(deep_parent).remove(),$(next_node).find("li:first").prepend($.FroalaEditor.MARKERS);else{var $li=$(next_node).find("li:first");"BLOCKQUOTE"==deep_parent.tagName&&(contents=editor.node.contents(deep_parent),contents.length&&editor.node.isBlock(contents[contents.length-1])&&(deep_parent=contents[contents.length-1])),0===$li.find("ul, ol").length&&($(marker).replaceWith($.FroalaEditor.MARKERS),$li.find(editor.html.blockTagsQuery()).not("ol, ul, table").each(function(){this.parentNode==$li.get(0)&&$(this).replaceWith($(this).html()+(editor.node.isEmpty(this)?"":"<br>"))}),$(deep_parent).append(editor.node.contents($li.get(0))),$li.remove(),0===$(next_node).find("li").length&&$(next_node).remove())}else{if(contents=editor.node.contents(next_node),contents.length&&"BR"==contents[0].tagName&&$(contents[0]).remove(),"BLOCKQUOTE"!=next_node.tagName&&"BLOCKQUOTE"==deep_parent.tagName)for(contents=editor.node.contents(deep_parent);contents.length&&editor.node.isBlock(contents[contents.length-1]);)deep_parent=contents[contents.length-1],contents=editor.node.contents(deep_parent);else if("BLOCKQUOTE"==next_node.tagName&&"BLOCKQUOTE"!=deep_parent.tagName)for(contents=editor.node.contents(next_node);contents.length&&editor.node.isBlock(contents[0]);)next_node=contents[0],contents=editor.node.contents(next_node);$(marker).replaceWith($.FroalaEditor.MARKERS),$(deep_parent).append(next_node.innerHTML),$(next_node).remove()}else{for($(marker).replaceWith($.FroalaEditor.MARKERS);next_node&&"BR"!==next_node.tagName&&!editor.node.isBlock(next_node)&&editor.node.isEditable(next_node);){var copy_node=next_node;next_node=next_node.nextSibling,$(deep_parent).append(copy_node)}next_node&&"BR"==next_node.tagName&&editor.node.isEditable(next_node)&&$(next_node).remove()}}}function _middleDel(marker){for(var next_node=marker;!next_node.nextSibling;)next_node=next_node.parentNode;if(next_node=next_node.nextSibling,"BR"==next_node.tagName&&editor.node.isEditable(next_node))if(next_node.nextSibling){if(editor.node.isBlock(next_node.nextSibling)&&editor.node.isEditable(next_node.nextSibling)){if(!($.FroalaEditor.NO_DELETE_TAGS.indexOf(next_node.nextSibling.tagName)<0))return;next_node=next_node.nextSibling,$(next_node.previousSibling).remove()}}else if(_atEnd(next_node)){if(_inLi(marker))editor.cursorLists._del(marker);else{var deep_parent=editor.node.deepestParent(next_node);deep_parent&&($(next_node).remove(),_endDel(marker))}return}var contents;if(!editor.node.isBlock(next_node)&&editor.node.isEditable(next_node)){for(contents=editor.node.contents(next_node);next_node.nodeType!=Node.TEXT_NODE&&contents.length&&editor.node.isEditable(next_node);)next_node=contents[0],contents=editor.node.c
|
||
|
!$el.data("title"))return!1;$el.removeAttr("title"),editor.$tooltip.text($el.data("title")),editor.$tooltip.addClass("fr-visible");var left=$el.offset().left+($el.outerWidth()-editor.$tooltip.outerWidth())/2;0>left&&(left=0),left+editor.$tooltip.outerWidth()>$(editor.original_window).width()&&(left=$(editor.original_window).width()-editor.$tooltip.outerWidth()),editor.$tooltip.css("left",left),"undefined"==typeof above&&(above=editor.opts.toolbarBottom),editor.$tooltip.css("top",above?$el.offset().top-editor.$tooltip.height():$el.offset().top+$el.outerHeight())}function bind($el,selector,above){editor.helpers.isMobile()||($el.on("mouseenter",selector,function(e){$(e.currentTarget).hasClass("fr-disabled")||to($(e.currentTarget),above)}),$el.on("mouseleave "+editor._mousedown+" "+editor._mouseup,selector,function(e){hide()})),editor.events.on("destroy",function(){$el.off("mouseleave "+editor._mousedown+" "+editor._mouseup,selector),$el.off("mouseenter",selector)},!0)}function _init(){editor.helpers.isMobile()||(editor.$tooltip=$('<div class="fr-tooltip"></div>'),editor.opts.theme&&editor.$tooltip.addClass(editor.opts.theme+"-theme"),$(editor.original_document).find("body").append(editor.$tooltip),editor.events.on("destroy",function(){editor.$tooltip.html("").removeData().remove()},!0))}return{_init:_init,hide:hide,to:to,bind:bind}},$.FroalaEditor.ICON_DEFAULT_TEMPLATE="font_awesome",$.FroalaEditor.ICON_TEMPLATES={font_awesome:'<i class="fa fa-[NAME]"></i>',text:'<span style="text-align: center;">[NAME]</span>',image:"<img src=[SRC] alt=[ALT] />"},$.FroalaEditor.ICONS={bold:{NAME:"bold"},italic:{NAME:"italic"},underline:{NAME:"underline"},strikeThrough:{NAME:"strikethrough"},subscript:{NAME:"subscript"},superscript:{NAME:"superscript"},color:{NAME:"tint"},outdent:{NAME:"outdent"},indent:{NAME:"indent"},undo:{NAME:"rotate-left"},redo:{NAME:"rotate-right"},insertHR:{NAME:"minus"},clearFormatting:{NAME:"eraser"},selectAll:{NAME:"mouse-pointer"}},$.FroalaEditor.DefineIconTemplate=function(name,options){$.FroalaEditor.ICON_TEMPLATES[name]=options},$.FroalaEditor.DefineIcon=function(name,options){$.FroalaEditor.ICONS[name]=options},$.FroalaEditor.MODULES.icon=function(editor){function create(command){var icon=null,info=$.FroalaEditor.ICONS[command];if("undefined"!=typeof info){var template=info.template||$.FroalaEditor.ICON_DEFAULT_TEMPLATE;template&&(template=$.FroalaEditor.ICON_TEMPLATES[template])&&(icon=template.replace(/\[([a-zA-Z]*)\]/g,function(str,a1){return"NAME"==a1?info[a1]||command:info[a1]}))}return icon||command}return{create:create}},$.FroalaEditor.MODULES.button=function(editor){function _dropdownButtonClick(e){var $btn=$(e.currentTarget),$dropdown=$btn.next(),active=$btn.hasClass("fr-active"),$active_dropdowns=(editor.helpers.isMobile(),$(".fr-dropdown.fr-active").not($btn));if(editor.helpers.isIOS()&&0==editor.$el.find(".fr-marker").length&&(editor.selection.save(),editor.selection.clear(),editor.selection.restore()),!active){var cmd=$btn.data("cmd");$dropdown.find(".fr-command").removeClass("fr-active"),$.FroalaEditor.COMMANDS[cmd]&&$.FroalaEditor.COMMANDS[cmd].refreshOnShow&&$.FroalaEditor.COMMANDS[cmd].refreshOnShow.apply(editor,[$btn,$dropdown]),$dropdown.css("left",$btn.offset().left-$btn.parent().offset().left-("rtl"==editor.opts.direction?$dropdown.width()-$btn.outerWidth():0)),editor.opts.toolbarBottom?$dropdown.css("bottom",editor.$tb.height()-$btn.position().top):$dropdown.css("top",$btn.position().top+$btn.outerHeight())}$btn.addClass("fr-blink").toggleClass("fr-active"),setTimeout(function(){$btn.removeClass("fr-blink")},300),$dropdown.offset().left+$dropdown.outerWidth()>$(editor.opts.scrollableContainer).offset().left+$(editor.opts.scrollableContainer).outerWidth()&&$dropdown.css("margin-left",-($dropdown.offset().left+$dropdown.outerWidth()-$(editor.opts.scrollableContainer).offset().left-$(editor.opts.scrollableContainer).outerWidth())),$active_dropdowns.removeClass("fr-active")}function exec($btn){$btn.addClass("fr-blink"),setTimeout(function(){$btn.removeClass("fr-blink")},500);for(var cmd=$bt
|
||
|
left&&(left=editor.$tb.offset().left+editor.$tb.width()/2),editor.$tb.hasClass("fr-above")&&(top+=editor.$tb.outerHeight()),obj_height=0),$container=popups[id].data("container"),!editor.opts.iframe||obj_height||is_visible||(left&&(left-=editor.$iframe.offset().left),top&&(top-=editor.$iframe.offset().top)),left&&(left-=width/2),editor.opts.toolbarBottom&&$container&&editor.$tb&&$container.get(0)==editor.$tb.get(0)&&(popups[id].addClass("fr-above"),top-=popups[id].outerHeight()),editor.position.at(left,top,popups[id],obj_height||0);var active_popup=popups[id].find("input:visible, textarea:visible").get(0);active_popup&&(0==editor.$el.find(".fr-marker").length&&editor.core.hasFocus()&&editor.selection.save(),editor.events.disableBlur(),$(active_popup).select().focus()),editor.opts.toolbarInline&&!editor.helpers.isMobile()&&editor.toolbar.hide(),editor.events.trigger("popups.show."+id)}function onShow(id,callback){editor.events.on("popups.show."+id,callback)}function isVisible(id){return popups[id]&&popups[id].hasClass("fr-active")||!1}function areVisible(){for(var id in popups)if(isVisible(id))return!0;return!1}function hide(id){popups[id]&&popups[id].hasClass("fr-active")&&(popups[id].removeClass("fr-active fr-above"),editor.events.trigger("popups.hide."+id),editor.events.disableBlur(),popups[id].find("input, textarea, button").filter(":focus").blur(),popups[id].find("input, textarea").attr("disabled","disabled"))}function onHide(id,callback){editor.events.on("popups.hide."+id,callback)}function get(id){return popups[id]}function onRefresh(id,callback){editor.events.on("popups.refresh."+id,callback)}function refresh(id){editor.events.trigger("popups.refresh."+id);for(var btns=popups[id].find(".fr-command"),i=0;i<btns.length;i++){var $btn=$(btns[i]);0==$btn.parents(".fr-dropdown-menu").length&&editor.button.refresh($btn)}}function hideAll(except){"undefined"==typeof except&&(except=[]);for(var id in popups)except.indexOf(id)<0&&hide(id)}function _markExit(){exit_flag=!0}function _unmarkExit(){exit_flag=!1}function _buildTemplate(id,template){var html=$.FroalaEditor.POPUP_TEMPLATES[id];"function"==typeof html&&(html=html.apply(editor));for(var nm in template)html=html.replace("[_"+nm.toUpperCase()+"_]",template[nm]);return html}function create(id,template){var html=_buildTemplate(id,template),$popup=$('<div class="fr-popup'+(editor.helpers.isMobile()?" fr-mobile":" fr-desktop")+(editor.opts.toolbarInline?" fr-inline":"")+'"><span class="fr-arrow"></span>'+html+"</div>");editor.opts.theme&&$popup.addClass(editor.opts.theme+"-theme"),editor.opts.zIndex>1&&editor.$tb.css("z-index",editor.opts.zIndex+2),"auto"!=editor.opts.direction&&$popup.removeClass("fr-ltr fr-rtl").addClass("fr-"+editor.opts.direction),$popup.find("input, textarea").attr("dir",editor.opts.direction).attr("disabled","disabled");var $container=$("body");return $container.append($popup),$popup.data("container",$container),popups[id]=$popup,editor.button.bindCommands($popup,!1),$(editor.original_window).on("resize.popups"+editor.id,function(){editor.helpers.isMobile()||(editor.events.disableBlur(),hide(id),editor.events.enableBlur())}),$popup.on(editor._mousedown+" "+editor._mouseup,function(e){var originalTarget=e.originalEvent?e.originalEvent.target||e.originalEvent.originalTarget:null;return originalTarget&&"INPUT"!=originalTarget.tagName?(e.preventDefault(),e.stopPropagation(),!1):void e.stopPropagation()}),$popup.on("focus","input, textarea, button, select",function(e){if(e.preventDefault(),e.stopPropagation(),setTimeout(function(){editor.events.enableBlur()},0),editor.helpers.isMobile()){var t=$(editor.original_window).scrollTop();setTimeout(function(){$(editor.original_window).scrollTop(t)},0)}}),$popup.on("keydown","input, textarea, button, select",function(e){var key_code=e.which;if($.FroalaEditor.KEYCODE.TAB==key_code){e.preventDefault();var inputs=$popup.find("input, textarea, button, select").filter(":visible").not(":disabled").toArray();inputs.sort(function(a,b){return e.shiftKey?$(a).attr("tabIndex")<$(b).attr("tabIndex"):$(a).attr("tabIndex")>$(
|
||
|
for(var $td=$(td),cspan=parseInt($td.attr("colspan"),10)||1,rspan=parseInt($td.attr("rowspan"),10)||1,i=row;row+rspan>i;i++)for(var j=c_index;c_index+cspan>j;j++)map[i]||(map[i]=[]),map[i][j]?c_index++:map[i][j]=td;c_index+=cspan})}),map}}function _cellOrigin(td,map){for(var i=0;i<map.length;i++)for(var j=0;j<map[i].length;j++)if(map[i][j]==td)return{row:i,col:j}}function _cellEnds(origin_i,origin_j,map){for(var max_i=origin_i+1,max_j=origin_j+1;max_i<map.length;){if(map[max_i][origin_j]!=map[origin_i][origin_j]){max_i--;break}max_i++}for(max_i==map.length&&max_i--;max_j<map[origin_i].length;){if(map[origin_i][max_j]!=map[origin_i][origin_j]){max_j--;break}max_j++}return max_j==map[origin_i].length&&max_j--,{row:max_i,col:max_j}}function _removeSelection(){var cells=editor.$el.find(".fr-selected-cell");cells.length>0&&cells.each(function(){var $cell=$(this);$cell.removeClass("fr-selected-cell"),""===$cell.attr("class")&&$cell.removeAttr("class")})}function _clearSelection(){setTimeout(function(){editor.selection.clear(),editor.$el.addClass("fr-no-selection"),editor.edit.off(),editor.$el.blur()},0)}function _currentSelection(map){var i,min_i=map.length,max_i=0,min_j=map[0].length,max_j=0,cells=editor.$el.find(".fr-selected-cell");for(i=0;i<cells.length;i++){var cellOrigin=_cellOrigin(cells[i],map),cellEnd=_cellEnds(cellOrigin.row,cellOrigin.col,map);min_i=Math.min(cellOrigin.row,min_i),max_i=Math.max(cellEnd.row,max_i),min_j=Math.min(cellOrigin.col,min_j),max_j=Math.max(cellEnd.col,max_j)}return{min_i:min_i,max_i:max_i,min_j:min_j,max_j:max_j}}function _selectionLimits(min_i,max_i,min_j,max_j,map){var i,j,cellOrigin,cellEnd,first_i=min_i,last_i=max_i,first_j=min_j,last_j=max_j;for(i=first_i;last_i>=i;i++)((parseInt($(map[i][first_j]).attr("rowspan"),10)||1)>1||(parseInt($(map[i][first_j]).attr("colspan"),10)||1)>1)&&(cellOrigin=_cellOrigin(map[i][first_j],map),cellEnd=_cellEnds(cellOrigin.row,cellOrigin.col,map),first_i=Math.min(cellOrigin.row,first_i),last_i=Math.max(cellEnd.row,last_i),first_j=Math.min(cellOrigin.col,first_j),last_j=Math.max(cellEnd.col,last_j)),((parseInt($(map[i][last_j]).attr("rowspan"),10)||1)>1||(parseInt($(map[i][last_j]).attr("colspan"),10)||1)>1)&&(cellOrigin=_cellOrigin(map[i][last_j],map),cellEnd=_cellEnds(cellOrigin.row,cellOrigin.col,map),first_i=Math.min(cellOrigin.row,first_i),last_i=Math.max(cellEnd.row,last_i),first_j=Math.min(cellOrigin.col,first_j),last_j=Math.max(cellEnd.col,last_j));for(j=first_j;last_j>=j;j++)((parseInt($(map[first_i][j]).attr("rowspan"),10)||1)>1||(parseInt($(map[first_i][j]).attr("colspan"),10)||1)>1)&&(cellOrigin=_cellOrigin(map[first_i][j],map),cellEnd=_cellEnds(cellOrigin.row,cellOrigin.col,map),first_i=Math.min(cellOrigin.row,first_i),last_i=Math.max(cellEnd.row,last_i),first_j=Math.min(cellOrigin.col,first_j),last_j=Math.max(cellEnd.col,last_j)),((parseInt($(map[last_i][j]).attr("rowspan"),10)||1)>1||(parseInt($(map[last_i][j]).attr("colspan"),10)||1)>1)&&(cellOrigin=_cellOrigin(map[last_i][j],map),cellEnd=_cellEnds(cellOrigin.row,cellOrigin.col,map),first_i=Math.min(cellOrigin.row,first_i),last_i=Math.max(cellEnd.row,last_i),first_j=Math.min(cellOrigin.col,first_j),last_j=Math.max(cellEnd.col,last_j));return first_i==min_i&&last_i==max_i&&first_j==min_j&&last_j==max_j?{min_i:min_i,max_i:max_i,min_j:min_j,max_j:max_j}:_selectionLimits(first_i,last_i,first_j,last_j,map)}function _selectionOffset(map){var selection=_currentSelection(map),$tl=$(map[selection.min_i][selection.min_j]),$tr=$(map[selection.min_i][selection.max_j]),$bl=$(map[selection.max_i][selection.min_j]),left=$tl.offset().left,right=$tr.offset().left+$tr.outerWidth(),top=$tl.offset().top,bottom=$bl.offset().top+$bl.outerHeight();return{left:left,right:right,top:top,bottom:bottom}}function _selectCells(firstCell,lastCell){if($(firstCell).is(lastCell))_removeSelection(),$(firstCell).addClass("fr-selected-cell");else{_clearSelection();var map=_tableMap(),firstCellOrigin=_cellOrigin(firstCell,map),lastCellOrigin=_cellOrigin(lastCell,map),limits=_selectionLimits(Math.min(firstCellOrigin.row,lastCell
|
||
|
editor.selection.save(),editor.$el.find("span").each(function(index,span){var $span=$(span),color=$span.css("background-color");("#123456"===color||"#123456"===editor.helpers.RGBToHex(color))&&$span.replaceWith($span.html())}),editor.selection.restore()),_hideColorsPopup()}function text(val){"REMOVE"!=val?editor.commands.applyProperty("color",editor.helpers.HEXtoRGB(val)):(editor.commands.applyProperty("color","#123456"),editor.selection.save(),editor.$el.find("span").each(function(index,span){var $span=$(span),color=$span.css("color");("#123456"===color||"#123456"===editor.helpers.RGBToHex(color))&&$span.replaceWith($span.html())}),editor.selection.restore()),_hideColorsPopup()}function back(){editor.popups.hide("colors.picker"),editor.toolbar.showInline()}function _init(){}return{_init:_init,showColorsPopup:_showColorsPopup,hideColorsPopup:_hideColorsPopup,changeSet:_changeSet,background:background,text:text,back:back}},$.FroalaEditor.DefineIcon("colors",{NAME:"format_color_text"}),$.FroalaEditor.RegisterCommand("color",{title:"Colors",undo:!1,focus:!0,refreshOnCallback:!1,popup:!0,callback:function(){this.popups.isVisible("colors.picker")?(this.$el.find(".fr-marker")&&(this.events.disableBlur(),this.selection.restore()),this.popups.hide("colors.picker")):this.colors.showColorsPopup()}}),$.FroalaEditor.RegisterCommand("textColor",{undo:!0,callback:function(cmd,val){this.colors.text(val)}}),$.FroalaEditor.RegisterCommand("backgroundColor",{undo:!0,callback:function(cmd,val){this.colors.background(val)}}),$.FroalaEditor.RegisterCommand("colorChangeSet",{undo:!1,focus:!1,callback:function(cmd,val){var $tab=this.popups.get("colors.picker").find('.fr-command[data-cmd="'+cmd+'"][data-param1="'+val+'"]');this.colors.changeSet($tab,val)}}),$.FroalaEditor.DefineIcon("colorsBack",{NAME:"arrow_back"}),$.FroalaEditor.RegisterCommand("colorsBack",{title:"Back",undo:!1,focus:!1,back:!0,refreshAfterCallback:!1,callback:function(){this.colors.back()}})});
|