From 272df353a5a9b547351aa7aafeca5bdba6474b7d Mon Sep 17 00:00:00 2001 From: Stefan Neculai Date: Sun, 24 Aug 2014 15:27:45 +0300 Subject: [PATCH] Fixing on paste. --- js/froala_editor.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/froala_editor.min.js b/js/froala_editor.min.js index 48b5fdb5a..d6537da75 100644 --- a/js/froala_editor.min.js +++ b/js/froala_editor.min.js @@ -2,7 +2,7 @@ * froala_editor v1.1.9 (http://editor.froala.com) * Copyright 2014-2014 Froala */ -if("undefined"==typeof jQuery)throw new Error("Froala requires jQuery");!function(a){"use strict";var b=function(c,d){this.options=a.extend({},b.DEFAULTS,a(c).data(),"object"==typeof d&&d),this.browser=b.browser(),this.disabledList=[],this._id=++b.count,this.blurred=!0,this.init(c)};b.count=0,b.VALID_NODES=["P","PRE","BLOCKQUOTE","H1","H2","H3","H4","H5","H6","DIV","LI","TD"],b.LANGS=[],b.DEFAULTS={allowedImageTypes:["jpeg","jpg","png","gif"],alwaysBlank:!1,alwaysVisible:!1,autosave:!1,autosaveInterval:1e4,blockTags:["n","p","blockquote","pre","h1","h2","h3","h4","h5","h6"],borderColor:"#252528",buttons:["bold","italic","underline","strikeThrough","fontSize","fontFamily","color","sep","formatBlock","blockStyle","align","insertOrderedList","insertUnorderedList","outdent","indent","sep","createLink","insertImage","insertVideo","insertHorizontalRule","undo","redo","html"],crossDomain:!0,customButtons:{},customDropdowns:{},customText:!1,defaultImageWidth:300,direction:"ltr",disableRightClick:!1,editorClass:"",headers:{},height:"auto",icons:{},inlineMode:!0,initOnClick:!1,language:"en_us",linkList:[],linkText:!0,linkClasses:{},maxHeight:"auto",minHeight:"auto",noFollow:!0,paragraphy:!0,placeholder:"Type something",plainPaste:!1,preloaderSrc:"",saveURL:null,saveParams:{},saveRequestType:"POST",simpleAmpersand:!1,shortcuts:!0,spellcheck:!1,theme:null,toolbarFixed:!0,trackScroll:!1,unlinkButton:!0,typingTimer:200,width:"auto",withCredentials:!1,zIndex:1e3},b.prototype.destroy=function(){this.sync(),this.hide(),this.isHTML&&this.html(),this.focus(),this.clearSelection(),this.$element.blur(),this.$bttn_wrapper&&this.$bttn_wrapper.html("").removeData().remove(),this.$editor&&this.$editor.html("").removeData().remove(),this.$image_editor&&this.$image_editor.html("").removeData().remove(),this.$image_wrapper&&this.$image_wrapper.html("").removeData().remove(),this.$link_wrapper&&this.$link_wrapper.html("").removeData().remove(),this.$video_wrapper&&this.$video_wrapper.html("").removeData().remove(),this.$popup_editor&&this.$popup_editor.html("").removeData().remove(),this.$overlay&&this.$overlay.html("").removeData().remove(),this.$image_modal&&(this.hideMediaManager(),this.$image_modal.html("").removeData().remove()),this.isLink?this.$element.removeData("fa.editable"):(this.$element.replaceWith(this.getHTML()),this.$box&&!this.editableDisabled&&(this.$box.removeClass("froala-box"),this.$box.find(".html-switch").remove(),this.$box.removeData("fa.editable"),clearTimeout(this.typingTimer))),clearTimeout(this.ajaxInterval),clearTimeout(this.typingTimer),this.$element.off("mousedown mouseup click keydown keyup focus keypress touchstart touchend touch drop"),this.$element.off("mousedown mouseup click keydown keyup focus keypress touchstart touchend touch drop","**"),a(window).off("mouseup."+this._id),a(window).off("keydown."+this._id),a(window).off("keyup."+this._id),a(window).off("hide."+this._id),a(window).off("scroll."+this._id),a(document).off("selectionchange."+this._id),void 0!==this.$upload_frame&&this.$upload_frame.remove(),this.$textarea&&(this.$box.remove(),this.$textarea.removeData("fa.editable"),this.$textarea.show())},b.prototype.callback=function(b,c,d){void 0===d&&(d=!0);var e=!0,f=b+"Callback";return this.options[f]&&a.isFunction(this.options[f])&&(e=c?this.options[f].apply(this,c):this.options[f].call(this)),e=c?this.$box.trigger("editable."+b,c):this.$box.trigger("editable."+b),d===!0&&this.sync(),void 0===e?!0:e},b.prototype.syncCleanHTML=function(a,b){var c;if(b)for(c=a.replace(/])*?><\/span>/gi,"");a!=c;)a=c,c=a.replace(/])*?><\/span>/gi,"");else for(c=a.replace(/]*?><\/span>/g,"");a!=c;)a=c,c=a.replace(/]*?><\/span>/g,"");return a},b.prototype.syncClean=function(b,c){var d="span:empty";c&&(d="span:empty:not(.f-marker)");for(var e=!1,f=function(b,c){0===c.attributes.length&&(a(c).remove(),e=!1)},g=b.find(d);g.length&&e===!1;)e=!0,g.each(f),g=b.find(d)},b.prototype.sync=function(){if(!this.isHTML){this.raiseEvent("sync"),this.disableImageResize(),this.isLink||this.isImage||this.$element.trigger("placeholderCheck"),this.isResizing()||this.isLink||this.isImage||this.options.editInPopup||this.android()||this.imageMode||this.cleanify();var a=this.getHTML();this.isHTML||(this.trackHTML!==a&&null!=this.trackHTML?(this.callback("contentChanged",[],!1),this.refreshImageList(),this.refreshButtons(),this.trackHTML=a):null==this.trackHTML&&(this.trackHTML=a)),this.$textarea&&this.$textarea.val(a)}},b.prototype.emptyElement=function(b){if("IMG"==b.tagName||a(b).find("img").length>0)return!1;if(a(b).find("input, iframe").length>0)return!1;for(var c=a(b).text(),d=0;d").html(this.$textarea.val()),this.$textarea.before(this.$element).hide(),this.$textarea.parents("form").bind("submit",a.proxy(function(){this.isHTML?this.html():this.sync()},this));else if("A"==b.tagName)this.isLink=!0,this.selectionDisabled=!0,this.editableDisabled=!0,this.options.buttons=[],this.$element=a(b),this.options.paragraphy=!1,this.$box=this.$element;else if("IMG"==b.tagName){var c=a(b).css("float");"A"==a(b).parent().get(0).tagName&&(b=a(b).parent()),this.isImage=!0,this.editableDisabled=!0,this.imageList=[],this.options.buttons=[],this.options.paragraphy=!1,this.options.imageMargin="auto",a(b).wrap("
"),this.$element=a(b).parent(),this.$element.css("display","inline-block"),this.$element.css("max-width","100%"),this.$element.css("margin-left","auto"),this.$element.css("margin-right","auto"),this.$element.css("float",c),this.$element.addClass("f-image"),this.$box=a(b)}else this.options.editInPopup?(this.$element=a(b),this.$box=this.$element,this.editableDisabled=!0,this.options.buttons=[],this.$element.on("click",a.proxy(function(a){a.preventDefault()},this))):("DIV"!=b.tagName&&this.options.buttons.indexOf("formatBlock")>=0&&this.disabledList.push("formatBlock"),this.$element=a(b));this.isImage||this.isLink||this.options.editInPopup||(this.$box=this.$element,this.$element=a("
"),this.setHTML(this.$box.html(),!1),this.$box.html(this.$element).addClass("froala-box"),this.$element.on("keyup",a.proxy(function(a){var b=a.which;13==b&&this.webkitParagraphy()},this))),this.$element.on("drop",a.proxy(function(){setTimeout(a.proxy(function(){a("html").click(),this.$element.find(".f-img-wrap").each(function(b,c){0===a(c).find("img").length&&a(c).remove()})},this),1)},this)),this.sync()},b.prototype.webkitParagraphy=function(){this.$element.find("*").each(a.proxy(function(b,c){if(this.emptyElement(c)&&"DIV"==c.tagName&&this.options.paragraphy===!0){var d=a("


");a(c).replaceWith(d),this.setSelection(d.get(0))}},this))},b.prototype.trim=function(a){return String(a).replace(/^\s+|\s+$/g,"")},b.prototype.unwrapText=function(){this.options.paragraphy||this.$element.find("div").each(function(b,c){void 0===a(c).attr("style")&&a(c).replaceWith(a(c).html()+"
")})},b.prototype.wrapText=function(){if(this.isImage||this.isLink)return!1;this.webkitParagraphy();var b=[],c=["SPAN","A","B","I","EM","U","S","STRONG","STRIKE","FONT","IMG"],d=this,e=function(){if(0!==b.length){var c;c=a(d.options.paragraphy===!0?"

":"

");var e=a(b[0]);if(1==b.length&&"f-marker"==e.attr("class"))return void(b=[]);for(var f=0;f0||c.indexOf(this.tagName)>=0?b.push(this):this.nodeType==Node.TEXT_NODE&&0===d.text().trim().length?d.remove():e()}),e(),this.$element.find("> p, > div").each(function(b,c){0===a(c).text().trim().length&&0===a(c).find("img").length&&0===a(c).find("br").length&&a(c).append("
")}),this.$element.find("div:empty, > br").remove()},b.prototype.setHTML=function(a,b){this.no_verify=!0,void 0===b&&(b=!0),a=this.clean(a,!0,!1),a=a.replace(/>\s+<"),this.$element.html(a),this.imageList=[],this.refreshImageList(),this.options.paragraphy&&this.wrapText(),b===!0&&(this.restoreSelectionByMarkers(),this.sync()),this.no_verify=!1,this.$element.find("span").data("fr-verified",!0)},b.prototype.registerPaste=function(){var b=this;this.$element.get(0).onpaste=function(){if(!b.isHTML){if(!b.callback("beforePaste",[],!1))return!1;b.pasting=!0,b.saveSelection();var c=a(window).scrollTop(),d=a('
').appendTo("body");d.focus(),window.setTimeout(function(){var e=d.html();d.remove(),a(window).scrollTop(c),b.restoreSelection(),b.insertHTML(b.options.plainPaste?e.replace(/<(?!br\s*\/?)[^>]+>/g,""):e.match(/(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/gi)?b.wordClean(e):b.clean(e,!1,!0)),b.sync(),b.cleanify(),b.$element.trigger("placeholderCheck"),b.pasting=!1,b.callback("afterPaste")},1)}}},b.prototype._extractContent=function(a){for(var b,c=document.createDocumentFragment();b=a.firstChild;)c.appendChild(b);return c},b.prototype.wordClean=function(a){console.log("da"),a=a.replace(/([\s\S]*?)<\/p>/gi,"
  • $3

"),a=a.replace(/([\s\S]*?)<\/p>/gi,"
  • $3

  • "),a=a.replace(/([\s\S]*?)<\/p>/gi,"
  • $3

  • "),a=a.replace(/([\s\S]*?)<\/p>/gi,"
  • $3

"),a=a.replace(/([\s\S]*?)([\s\S]*?)/gi,""),a=a.replace(/(\n|\r| class=(")?Mso[a-zA-Z]+(")?)/gi," "),a=a.replace(//gi,""),a=a.replace(/<(\/)*(meta|link|span|\\?xml:|st1:|o:|font)(.*?)>/gi,"");for(var b=["style","script","applet","embed","noframes","noscript"],c=0;c","gi");a=a.replace(d,"")}a=a.replace(/([\w\-]*)=("[^<>"]*"|'[^<>']*'|\w+)/gi,""),a=a.replace(/ /gi,"");var e;do e=a,a=a.replace(/<[^\/>][^>]*><\/[^>]+>/gi,"");while(a!=e);return a},b.prototype.isClosingTag=function(a){return null!==a.match(/^<\/([a-zA-Z0-9]+)([^<]+)*>$/gi)},b.prototype.tagName=function(a){return a.replace(/^<\/?([a-zA-Z0-9]+)([^<]+)*>$/gi,"$1").toLowerCase()},b.prototype.isSelfClosingTag=function(a){var b=["br","button","input","img"],c=this.tagName(a);return b.indexOf(c)>=0},b.prototype.tabs=function(a){for(var b="",c=0;a>c;c++)b+=" ";return b},b.prototype.cleanTags=function(a){var b,c,d,e,f=["P","PRE","BLOCKQUOTE","H1","H2","H3","H4","H5","H6","DIV","UL","OL","LI","TABLE","TBODY","THEAD","TFOOT","TR","TH","TD"],g=[],h=[];for(a=a.replace(/\n/gi,""),c=0;c",c+1);if(-1!==i){var j=a.substring(c,i+1),k=this.tagName(j),l=this.isClosingTag(j);if(this.isSelfClosingTag(j))h.push(j);else if(l)for(d=!1,e=!0;d===!1&&void 0!==e;)e=g.pop(),void 0!==e&&e.tag_name!==k?h.splice(e.i,1):(d=!0,void 0!==e&&h.push(j));else h.push(j),g.push({tag_name:k,i:h.length-1});c=i}}else h.push(b);for(;g.length>0;)e=g.pop(),h.splice(e.i,1);for(a="",g=0,c=0;c0&&"\n"==a[a.length-1]&&(a+=this.tabs(g)),a+=h[c]+"\n"):(a+="\n"+this.tabs(g)+h[c],g+=1);return"\n"==a[0]&&(a=a.substring(1,a.length)),"\n"==a[a.length-1]&&(a=a.substring(0,a.length-1)),a},b.prototype.clean=function(b,c,d,e,f){f||(f=["title","href","alt","src","style","width","height","target","rel","name","value","type","colspan","rowspan","size","color","cellpadding","cellspacing","valign","align","autocomplete","background","bgcolor","contenteditable","tabindex","data-.*"]),e||(e=["div","p","h1","h2","h3","h4","h5","h6","pre","blockquote","table","thead","tbody","tfoot","tr","th","td","span","b","u","i","strong","em","strike","img","ul","ol","li","iframe","a"]),c===!0&&(f.push("id"),f.push("class")),b=b.replace(/)<[^<]*)*<\/script>/gi,"");var g=new RegExp("<\\/?((?!(?:"+e.join("|")+"))\\w+)[^>]*?>","gi");b=b.replace(g,"");var h=new RegExp("<([^>]*)( (?!(?:"+f.join("|")+'))\\[a-zA-Z0-9-]+)=(?:\'[^\']*\'|""[^""]*""|[^\\s>]+)([^>]*)>',"gi");b=b.replace(h,"<$1$3>");var i=new RegExp('<([^>]*)(src|href)=(\'[^\']*\'|""[^""]*""|[^\\s>]+)([^>]*)>',"gi");if(b=b.replace(i,a.proxy(function(a,b,c,d,e){return"<"+b+c+'="'+this.sanitizeURL(d.replace(/^["'](.*)["']\/?$/gi,"$1"))+'"'+e+">"},this)),d){var j=new RegExp('<([^>]*)(style)=(\'[^\']*\'|""[^""]*""|[^\\s>]+)([^>]*)>',"gi");b=b.replace(j,"<$1$2$4>")}return b=this.cleanTags(b)},b.prototype.cleanNewLine=function(a){var b=new RegExp("\\n","g");return a.replace(b,"")},b.prototype.initElementStyle=function(){this.editableDisabled||this.$element.attr("contenteditable",!0);var a="froala-element "+this.options.editorClass;this.browser.msie&&b.getIEversion()<9&&(a+=" ie8"),this.$element.css("outline",0),this.browser.msie||(a+=" not-msie"),this.$element.addClass(a)},b.prototype.initUndoRedo=function(){(this.isEnabled("undo")||this.isEnabled("redo"))&&(this.undoStack=[],this.undoIndex=0,this.saveUndoStep()),this.disableBrowserUndo()},b.prototype.enableTyping=function(){this.typingTimer=null,this.$element.on("keydown",a.proxy(function(){clearTimeout(this.typingTimer),this.ajaxSave=!1,this.oldHTML=this.getHTML(),this.typingTimer=setTimeout(a.proxy(function(){this.getHTML().replace(/[\u3041-\u3096]|[\u30A0-\u30FF]|[\u4E00-\u9FFF]/gi,"")!=this.oldHTML.replace(/[\u3041-\u3096]|[\u30A0-\u30FF]|[\u4E00-\u9FFF]/gi,"")&&(this.saveUndoStep(),this.sync())},this),Math.max(this.options.typingTimer,200))},this))},b.prototype.removeMarkersByRegex=function(a){return a.replace(/]*? class\s*=\s*["']?f-marker["']?[^>]+>([\S\s][^\/])*<\/span>/gi,"")},b.prototype.getImageHTML=function(){return JSON.stringify({src:this.$element.find("img").attr("src"),style:this.$element.find("img").attr("style"),alt:this.$element.find("img").attr("alt"),width:this.$element.find("img").attr("width"),link:this.$element.find("a").attr("href"),link_title:this.$element.find("a").attr("title"),link_target:this.$element.find("a").attr("target")})},b.prototype.getLinkHTML=function(){return JSON.stringify({body:this.$element.html(),href:this.$element.attr("href"),title:this.$element.attr("title"),popout:this.$element.hasClass("popout"),nofollow:"nofollow"==this.$element.attr("ref"),blank:"_blank"==this.$element.attr("target"),left:this.$element.parents(".navbar-left").length>0,"class":this.$element.attr("class").replace(/froala-element/,"").replace(/not-msie/,"").replace(/ +(?= )/g,"").split(" ").sort().join(" ")})},b.prototype.getHTML=function(b,c){if(void 0===c&&(c=!1),void 0===b&&(b=!1),this.isHTML)return this.$html_area.val();if(this.isImage)return this.getImageHTML();if(this.isLink)return this.getLinkHTML();this.$element.find("a").data("fr-link",!0),c&&this.$element.find("p, h1, h2, h3, h4, h5, h6, pre, blockquote, table, ul, ol, img").addClass("fr-tag"),this.$element.find(".f-img-editor > img").each(a.proxy(function(b,c){this.addImageClass(a(c),this.getImageClass(a(c).parent().attr("class")))},this));var d=this.$element.html();return this.$element.find(".f-img-editor > img").removeClass("fr-fin fr-fil fr-fir"),this.$element.find("p, h1, h2, h3, h4, h5, h6, pre, blockquote, table, ul, ol, img").removeClass("fr-tag"),d=this.syncCleanHTML(d,b),d=d.replace(/\s*contenteditable="[^"]*"/gi,""),d=d.replace(/]*?><\/a>/g,""),b||(d=this.removeMarkersByRegex(d)),d=d.replace(/]*? class\s*=\s*["']?f-img-handle[^>]+><\/span>/gi,""),d=d.replace(/^([\S\s]*)]*? class\s*=\s*["']?f-img-editor[^>]+>([\S\s]*)<\/span>([\S\s]*)$/gi,"$1$2$3"),d=d.replace(/^([\S\s]*)]*? class\s*=\s*["']?f-img-wrap[^>]+>([\S\s]*)<\/span>([\S\s]*)$/gi,"$1$2$3"),d=d.replace(/^([\S\s]*)]*? class\s*=\s*["']?f-video-editor[^>]+>([\S\s]*)<\/span>([\S\s]*)$/gi,"$1$2$3"),d=d.replace(/\&/gi,"&"),this.options.simpleAmpersand&&(d=d.replace(/\&/gi,"&")),d=d.replace(/ data-fr-verified="true"/gi,""),d=d.replace(/\n/gi,""),d=d.replace(/\u200B/gi,"")},b.prototype.getText=function(){return this.$element.text()},b.prototype.initAjaxSaver=function(){this.ajaxHTML=this.getHTML(),this.ajaxSave=!0,this.ajaxInterval=setInterval(a.proxy(function(){var a=this.getHTML();this.ajaxHTML!=a&&this.ajaxSave&&(this.options.autosave&&this.save(),this.ajaxHTML=a),this.ajaxSave=!0},this),Math.max(this.options.autosaveInterval,100))},b.prototype.disableBrowserUndo=function(){a("body").keydown(function(a){var b=a.which,c=(a.ctrlKey||a.metaKey)&&!a.altKey;if(!this.isHTML&&c){if(75==b)return a.preventDefault(),!1;if(90==b&&a.shiftKey)return a.preventDefault(),!1;if(90==b)return a.preventDefault(),!1}})},b.prototype.saveUndoStep=function(){if(this.isEnabled("undo")||this.isEnabled("redo")){for(;this.undoStack.length>this.undoIndex;)this.undoStack.pop();var a=this.getHTML(!0);if(this.undoStack[this.undoIndex-1]&&this.removeMarkersByRegex(this.undoStack[this.undoIndex-1])==a)return!1;this.selectionInEditor()&&this.$element.is(":focus")&&this.saveSelectionByMarkers(),this.undoStack.push(this.getHTML(!0)),this.undoIndex++,this.selectionInEditor()&&this.$element.is(":focus")&&this.restoreSelectionByMarkers(),this.refreshUndoRedo()}},b.prototype.initShortcuts=function(){this.options.shortcuts&&this.$element.on("keydown",a.proxy(function(a){var b=a.which,c=(a.ctrlKey||a.metaKey)&&!a.altKey;if(!this.isHTML&&c){if(70==b)return this.show(null),!1;if(66==b)return this.execDefaultShortcut("bold");if(73==b)return this.execDefaultShortcut("italic");if(85==b)return this.execDefaultShortcut("underline");if(75==b)return this.execDefaultShortcut("createLink");if(80==b)return this.repositionEditor(),this.execDefaultShortcut("insertImage");if(65==b)return this.execDefaultShortcut("selectAll");if(221==b)return this.execDefaultShortcut("indent");if(219==b)return this.execDefaultShortcut("outdent");if(72==b)return this.execDefaultShortcut("html");if(48==b)return this.execDefaultShortcut("formatBlock","n");if(49==b)return this.execDefaultShortcut("formatBlock","h1");if(50==b)return this.execDefaultShortcut("formatBlock","h2");if(51==b)return this.execDefaultShortcut("formatBlock","h3");if(52==b)return this.execDefaultShortcut("formatBlock","h4");if(53==b)return this.execDefaultShortcut("formatBlock","h5");if(54==b)return this.execDefaultShortcut("formatBlock","h6");if(222==b)return this.execDefaultShortcut("formatBlock","blockquote");if(220==b)return this.execDefaultShortcut("formatBlock","pre");if(83==b)return this.execDefaultShortcut("strikeThrough");if(90==b&&a.shiftKey)return this.redo(),a.stopPropagation(),!1;if(90==b)return this.undo(),a.stopPropagation(),!1}9!=b||a.shiftKey?9==b&&a.shiftKey&&a.preventDefault():(a.preventDefault(),this.insertHTML("    ",!1))},this))},b.prototype.textEmpty=function(b){var c=a(b).text().replace(/(\r\n|\n|\r|\t)/gm,"");return(""===c||b===this.$element.get(0))&&0===a(b).find("br").length},b.prototype.focus=function(a){if(void 0===a&&(a=!0),""!==this.text())return void this.$element.focus();if(!this.isHTML){a&&!this.pasting&&(this.browser.webkit||this.$element.blur(),this.$element.focus()),this.pasting&&!this.$element.is(":focus")&&this.$element.focus();var c=this.getRange();if(""===this.text()&&c&&(0===c.startOffset||c.startContainer===this.$element.get(0))){var d,e,f=this.getSelectionElements();if(f.length>=1&&f[0]!==this.$element.get(0))for(d=0;d