From c9caf311f374f8440657b5ce8270676249f3530c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 20 May 2017 14:14:07 +0200 Subject: [PATCH] Upgraded to Redactor II 2.6 --- .../files/js/3rdParty/redactor2/redactor.js | 112 ++++++++++++------ .../js/3rdParty/redactor2/redactor.min.js | 12 +- 2 files changed, 82 insertions(+), 42 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js index 8ecf818cf5..caea5a1bfc 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js @@ -1,7 +1,7 @@ /* Redactor II - Version 2.5 - Updated: May 1, 2017 + Version 2.6 + Updated: May 17, 2017 http://imperavi.com/redactor/ @@ -101,7 +101,7 @@ // Options $.Redactor = Redactor; - $.Redactor.VERSION = '2.5'; + $.Redactor.VERSION = '2.6'; $.Redactor.modules = ['air', 'autosave', 'block', 'buffer', 'build', 'button', 'caret', 'clean', 'code', 'core', 'detect', 'dropdown', 'events', 'file', 'focus', 'image', 'indent', 'inline', 'insert', 'keydown', 'keyup', 'lang', 'line', 'link', 'linkify', 'list', 'marker', 'modal', 'observe', 'offset', 'paragraphize', 'paste', 'placeholder', @@ -202,7 +202,7 @@ formatting: ['p', 'blockquote', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'], formattingAdd: false, - buttons: ['format', 'bold', 'italic', 'deleted', 'lists', 'image', 'file', 'link'], // + 'horizontalrule', 'underline', 'ol', 'ul', 'indent', 'outdent' + buttons: ['format', 'bold', 'italic', 'deleted', 'lists', 'image', 'file', 'link', 'horizontalrule'], // + 'horizontalrule', 'underline', 'ol', 'ul', 'indent', 'outdent' buttonsTextLabeled: false, buttonsHide: [], buttonsHideOnMobile: [], @@ -216,6 +216,8 @@ 'strike': 'del' }, + keepStyleAttr: [], // tag name array + // shortcuts shortcuts: { 'ctrl+shift+m, meta+shift+m': { func: 'inline.removeFormat' }, @@ -1709,7 +1711,7 @@ observe: { element: 'a', 'in': { - title: this.lang.get('link-edit'), + title: this.lang.get('link-edit') }, out: { title: this.lang.get('link-insert') @@ -2353,10 +2355,13 @@ sel = window.getSelection(); sel.removeAllRanges(); - range = document.createRange(); - range.selectNodeContents(node); - range.collapse(false); - sel.addRange(range); + try { + range = document.createRange(); + range.selectNodeContents(node); + range.collapse(false); + sel.addRange(range); + } + catch(e) {} }, after: function(node) { @@ -2717,6 +2722,10 @@ html = html.replace(/]*font-weight: bold[^>]*>([\w\W]*?)<\/span>/gi, '$1'); html = html.replace(/]*font-weight: 700[^>]*>([\w\W]*?)<\/span>/gi, '$1'); + // op tag + html = html.replace(/]*>/gi, ''); + html = html.replace(/<\/o:p>/gi, ''); + var msword = this.clean.isHtmlMsWord(html); if (msword) { @@ -2735,6 +2744,7 @@ } else { + html = this.clean.replaceBrToNl(html); html = this.clean.removeTagsInsidePre(html); } @@ -2772,8 +2782,14 @@ if (data.paragraphize) { + // ff bugfix + html = html.replace(/ \n/g, ' '); + html = html.replace(/\n /g, ' '); html = this.paragraphize.load(html); + + // remove empty p + html = html.replace(/

<\/p>/g, ''); } return html; @@ -3188,7 +3204,9 @@ { html = html.replace(//gi, ''); html = html.replace(//gi, ''); - html = html.replace(/<\/p>|<\/div>|<\/li>|<\/td>/gi, '\n'); + html = html.replace(/

<\/p>/g, ''); + html = html.replace(/<\/div>|<\/li>|<\/td>/gi, '\n'); + html = html.replace(/<\/p>/gi, '\n\n'); html = html.replace(/<\/H[1-6]>/gi, '\n\n'); var tmp = document.createElement('div'); @@ -4830,6 +4848,11 @@ }, loadEditableControls: function($image) { + if ($('#redactor-image-box').length !== 0) + { + return; + } + var imageBox = $(''); imageBox.css('float', $image.css('float')).attr('contenteditable', false); @@ -5376,7 +5399,8 @@ } else { - this.caret.start(inline); + var $first = this.inline.insertBreakpoint($parent[0], currentTag); + this.caret.after($first); } } else @@ -5846,6 +5870,10 @@ { var $el = $(el); $el.removeAttr('style').css(params); + + var style = $el.attr('style'); + if (style) $el.attr('style', style.replace(/"/g, '\'')); + $el = self.inline.addParentStyle($el); return $el; @@ -5865,8 +5893,8 @@ var newVal = params[key]; var oldVal = $el.css(key); - oldVal = (self.utils.isRgb(oldVal)) ? self.utils.rgb2hex(oldVal) : oldVal; - newVal = (self.utils.isRgb(newVal)) ? self.utils.rgb2hex(newVal) : newVal; + oldVal = (self.utils.isRgb(oldVal)) ? self.utils.rgb2hex(oldVal) : oldVal.replace(/"/g, ''); + newVal = (self.utils.isRgb(newVal)) ? self.utils.rgb2hex(newVal) : newVal.replace(/"/g, ''); if (oldVal === newVal) { @@ -5878,6 +5906,9 @@ } } + var style = $el.attr('style'); + if (style) $el.attr('style', style.replace(/"/g, '\'')); + if (!self.utils.removeEmptyAttr(el, 'style')) { $el = self.inline.addParentStyle($el); @@ -5887,6 +5918,7 @@ $el.removeAttr('data-redactor-style-cache'); } + return $el; }); }, @@ -5900,6 +5932,10 @@ var $el = $(el); $el.css(params); + + var style = $el.attr('style'); + if (style) $el.attr('style', style.replace(/"/g, '\'')); + $el = self.inline.addParentStyle($el); return $el; @@ -6051,6 +6087,9 @@ html = $.parseHTML(html); + // end node + var endNode = $(html).last(); + // delete selected content var sel = this.selection.get(); var range = this.selection.range(sel); @@ -6137,15 +6176,13 @@ } } - this.utils.disableSelectAll(); this.linkify.format(); - if (data.pre) - { - this.clean.cleanPre(); - } + if (data.pre) this.clean.cleanPre(); + // end focus + this.caret.end(endNode); }, text: function(text) { @@ -6701,7 +6738,14 @@ this.code.syncFire = false; this.keydown.removeEmptyLists(); - this.core.editor().find('*[style]').not('img, figure, iframe, #redactor-image-box, #redactor-image-editter, [data-redactor-style-cache], [data-redactor-span]').removeAttr('style'); + var filter = ''; + if (this.opts.keepStyleAttr.length !== 0) + { + filter = ',' + this.opts.keepStyleAttr.join(','); + } + + var $styleTags = this.core.editor().find('*[style]'); + $styleTags.not('img, figure, iframe, #redactor-image-box, #redactor-image-editter, [data-redactor-style-cache], [data-redactor-span]' + filter).removeAttr('style'); this.keydown.formatEmpty(e); this.code.syncFire = true; @@ -8604,13 +8648,10 @@ } // disable line - if (this.utils.isCurrentOrParentHeader() || this.utils.isCurrentOrParent(['table', 'pre', 'blockquote', 'li'])) + if (this.core.editor().css('display') !== 'none') { - this.button.disable('horizontalrule'); - } - else - { - this.button.enable('horizontalrule'); + if (this.utils.isCurrentOrParentHeader() || this.utils.isCurrentOrParent(['table', 'pre', 'blockquote', 'li'])) this.button.disable('horizontalrule'); + else this.button.enable('horizontalrule'); } $.each(this.opts.activeButtonsStates, $.proxy(function(key, value) @@ -9068,6 +9109,7 @@ // clipboard event if (this.detect.isDesktop()) { + if (!this.paste.pre && this.opts.clipboardImageUpload && this.opts.imageUpload && this.paste.detectClipboardUpload(e)) { if (this.detect.isIe()) @@ -9163,13 +9205,7 @@ e = e.originalEvent || e; var clipboard = e.clipboardData; - - if (this.detect.isIe()) - { - return true; - } - - if (this.detect.isFirefox()) + if (this.detect.isIe() || this.detect.isFirefox()) { return false; } @@ -9182,7 +9218,6 @@ return false; } - if (!clipboard.items || !clipboard.items.length) { return; @@ -10384,7 +10419,7 @@ this.upload.$droparea = $('

'); this.upload.$placeholdler = $('
').text(this.lang.get('upload-label')); - this.upload.$input = $(''); + this.upload.$input = $(''); this.upload.$placeholdler.append(this.upload.$input); this.upload.$droparea.append(this.upload.$placeholdler); @@ -10399,8 +10434,13 @@ // change this.upload.$input.on('change.redactor.upload', $.proxy(function(e) { - e = e.originalEvent || e; - this.upload.traverseFile(this.upload.$input[0].files[0], e); + e = e.originalEvent || e; + var len = this.upload.$input[0].files.length; + + for (var i = 0; i < len; i++) + { + this.upload.traverseFile(this.upload.$input[0].files[i], e); + } }, this)); // drop diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.min.js b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.min.js index ca132f6951..4f81a47e73 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.min.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.min.js @@ -1,6 +1,6 @@ -!function(t){"use strict";function i(t,e){return new i.prototype.init(t,e)}Function.prototype.bind||(Function.prototype.bind=function(t){var e=this;return function(){return e.apply(t)}});var r=0;t.fn.redactor=function(e){var r=[],o=Array.prototype.slice.call(arguments,1);return"string"==typeof e?this.each(function(){var i,s=t.data(this,"redactor");if("-1"!==e.search(/\./)?(i=e.split("."),"undefined"!=typeof s[i[0]]&&(i=s[i[0]][i[1]])):i=s[e],"undefined"!=typeof s&&t.isFunction(i)){var n=i.apply(s,o);void 0!==n&&n!==s&&r.push(n)}else t.error('No such method "'+e+'" for Redactor')}):this.each(function(){t.data(this,"redactor",{}),t.data(this,"redactor",i(this,e))}),0===r.length?this:1===r.length?r[0]:r},t.Redactor=i,t.Redactor.VERSION="2.5",t.Redactor.modules=["air","autosave","block","buffer","build","button","caret","clean","code","core","detect","dropdown","events","file","focus","image","indent","inline","insert","keydown","keyup","lang","line","link","linkify","list","marker","modal","observe","offset","paragraphize","paste","placeholder","progress","selection","shortcuts","storage","toolbar","upload","uploads3","utils","browser"],t.Redactor.settings={},t.Redactor.opts={animation:!1,lang:"en",direction:"ltr",spellcheck:!0,overrideStyles:!0,scrollTarget:document,focus:!1,focusEnd:!1,clickToEdit:!1,structure:!1,tabindex:!1,minHeight:!1,maxHeight:!1,maxWidth:!1,plugins:!1,callbacks:{},placeholder:!1,linkify:!0,enterKey:!0,pastePlainText:!1,pasteImages:!0,pasteLinks:!0,pasteBlockTags:["pre","h1","h2","h3","h4","h5","h6","table","tbody","thead","tfoot","th","tr","td","ul","ol","li","blockquote","p","figure","figcaption"],pasteInlineTags:["br","strong","ins","code","del","span","samp","kbd","sup","sub","mark","var","cite","small","b","u","em","i"],preClass:!1,preSpaces:4,tabAsSpaces:!1,tabKey:!0,autosave:!1,autosaveName:!1,autosaveFields:!1,imageUpload:null,imageUploadParam:"file",imageUploadFields:!1,imageUploadForms:!1,imageTag:"figure",imageEditable:!0,imageCaption:!0,imagePosition:!1,imageResizable:!1,imageFloatMargin:"10px",dragImageUpload:!0,multipleImageUpload:!0,clipboardImageUpload:!0,fileUpload:null,fileUploadParam:"file",fileUploadFields:!1,fileUploadForms:!1,dragFileUpload:!0,s3:!1,linkNewTab:!1,linkTooltip:!0,linkNofollow:!1,linkSize:30,pasteLinkTarget:!1,videoContainerClass:"video-container",toolbar:!0,toolbarFixed:!0,toolbarFixedTarget:document,toolbarFixedTopOffset:0,toolbarExternal:!1,toolbarOverflow:!1,air:!1,airWidth:!1,formatting:["p","blockquote","pre","h1","h2","h3","h4","h5","h6"],formattingAdd:!1,buttons:["format","bold","italic","deleted","lists","image","file","link"],buttonsTextLabeled:!1,buttonsHide:[],buttonsHideOnMobile:[],script:!0,removeNewlines:!1,removeComments:!0,replaceTags:{b:"strong",i:"em",strike:"del"},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:!1,activeButtons:["deleted","italic","bold"],activeButtonsStates:{b:"bold",strong:"bold",i:"italic",em:"italic",del:"deleted",strike:"deleted"},langs:{en:{format:"Format",image:"Image",file:"File",link:"Link",bold:"Bold",italic:"Italic",deleted:"Strikethrough",underline:"Underline","bold-abbr":"B","italic-abbr":"I","deleted-abbr":"S","underline-abbr":"U",lists:"Lists","link-insert":"Insert link","link-edit":"Edit link","link-in-new-tab":"Open link in new tab",unlink:"Unlink",cancel:"Cancel",close:"Close",insert:"Insert",save:"Save","delete":"Delete",text:"Text",edit:"Edit",title:"Title",paragraph:"Normal text",quote:"Quote",code:"Code",heading1:"Heading 1",heading2:"Heading 2",heading3:"Heading 3",heading4:"Heading 4",heading5:"Heading 5",heading6:"Heading 6",filename:"Name",optional:"optional",unorderedlist:"Unordered List",orderedlist:"Ordered List",outdent:"Outdent",indent:"Indent",horizontalrule:"Line","upload-label":"Drop file here or ",caption:"Caption",bulletslist:"Bullets",numberslist:"Numbers","image-position":"Position",none:"None",left:"Left",right:"Right",center:"Center","accessibility-help-label":"Rich text editor"}},type:"textarea",inline:!1,buffer:[],rebuffer:[],inlineTags:["a","span","strong","strike","b","u","em","i","code","del","ins","samp","kbd","sup","sub","mark","var","cite","small"],blockTags:["pre","ul","ol","li","p","h1","h2","h3","h4","h5","h6","dl","dt","dd","div","td","blockquote","output","figcaption","figure","address","section","header","footer","aside","article","iframe"],paragraphize:!0,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"],emptyHtml:"

",invisibleSpace:"​",emptyHtmlRendered:t("").html("​").html(),imageTypes:["image/png","image/jpeg","image/gif"],userAgent:navigator.userAgent.toLowerCase(),observe:{dropdowns:[]},regexps:{linkyoutube:/https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w.\-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/gi,linkvimeo:/https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/,linkimage:/((https?|www)[^\s]+\.)(jpe?g|png|gif)(\?[^\s-]+)?/gi,url:/(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/gi}},i.fn=t.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},init:function(e,i){return this.$element=t(e),this.uuid=r++,this.loadOptions(i),this.loadModules(),this.opts.clickToEdit&&!this.$element.hasClass("redactor-click-to-edit")?this.loadToEdit(i):(this.$element.hasClass("redactor-click-to-edit")&&this.$element.removeClass("redactor-click-to-edit"),this.reIsBlock=new RegExp("^("+this.opts.blockTags.join("|").toUpperCase()+")$","i"),this.reIsInline=new RegExp("^("+this.opts.inlineTags.join("|").toUpperCase()+")$","i"),this.opts.dragImageUpload=null===this.opts.imageUpload?!1:this.opts.dragImageUpload,this.opts.dragFileUpload=null===this.opts.fileUpload?!1:this.opts.dragFileUpload,this.formatting={},this.lang.load(),t.extend(this.opts.shortcuts,this.opts.shortcutsAdd),this.$editor=this.$element,this.detectType(),this.core.callback("start"),this.core.callback("startToEdit"),this.start=!0,void this.build.start())},detectType:function(){this.build.isInline()||this.opts.inline?this.opts.type="inline":this.build.isTag("DIV")?this.opts.type="div":this.build.isTag("PRE")&&(this.opts.type="pre")},loadToEdit:function(e){this.$element.on("click.redactor-click-to-edit",t.proxy(function(){this.initToEdit(e)},this)),this.$element.addClass("redactor-click-to-edit")},initToEdit:function(e){t.extend(e.callbacks,{startToEdit:function(){this.insert.node(this.marker.get(),!1)},initToEdit:function(){this.selection.restore(),this.clickToCancelStorage=this.code.get(),t(this.opts.clickToCancel).off(".redactor-click-to-edit"),t(this.opts.clickToCancel).show().on("click.redactor-click-to-edit",t.proxy(function(i){i.preventDefault(),this.core.destroy(),this.events.syncFire=!1,this.$element.html(this.clickToCancelStorage),this.core.callback("cancel",this.clickToCancelStorage),this.events.syncFire=!0,this.clickToCancelStorage="",t(this.opts.clickToCancel).hide(),t(this.opts.clickToSave).hide(),this.$element.on("click.redactor-click-to-edit",t.proxy(function(){this.initToEdit(e)},this)),this.$element.addClass("redactor-click-to-edit")},this)),t(this.opts.clickToSave).off(".redactor-click-to-edit"),t(this.opts.clickToSave).show().on("click.redactor-click-to-edit",t.proxy(function(i){i.preventDefault(),this.core.destroy(),this.core.callback("save",this.code.get()),t(this.opts.clickToCancel).hide(),t(this.opts.clickToSave).hide(),this.$element.on("click.redactor-click-to-edit",t.proxy(function(){this.initToEdit(e)},this)),this.$element.addClass("redactor-click-to-edit")},this))}}),this.$element.redactor(e),this.$element.off(".redactor-click-to-edit")},loadOptions:function(e){var i={};"undefined"!=typeof t.Redactor.settings.namespace?this.$element.hasClass(t.Redactor.settings.namespace)&&(i=t.Redactor.settings):i=t.Redactor.settings,this.opts=t.extend({},t.Redactor.opts,this.$element.data(),e),this.opts=t.extend(!0,this.opts,i)},getModuleMethods:function(t){return Object.getOwnPropertyNames(t).filter(function(e){return"function"==typeof t[e]})},loadModules:function(){for(var e=t.Redactor.modules.length,i=0;e>i;i++)this.bindModuleMethods(t.Redactor.modules[i])},bindModuleMethods:function(t){if("undefined"!=typeof this[t]){this[t]=this[t]();for(var e=this.getModuleMethods(this[t]),i=e.length,r=0;i>r;r++)this[t][e[r]]=this[t][e[r]].bind(this)}},air:function(){return{enabled:!1,collapsed:function(){this.opts.air&&this.selection.get().collapseToStart()},collapsedEnd:function(){this.opts.air&&this.selection.get().collapseToEnd()},build:function(){this.detect.isMobile()||(this.button.hideButtons(),this.button.hideButtonsOnMobile(),0!==this.opts.buttons.length&&(this.$air=this.air.createContainer(),this.opts.airWidth!==!1&&this.$air.css("width",this.opts.airWidth),this.air.append(),this.button.$toolbar=this.$air,this.button.setFormatting(),this.button.load(this.$air),this.core.editor().on("mouseup.redactor",this,t.proxy(function(t){""!==this.selection.text()&&this.air.show(t)},this))))},append:function(){this.$air.appendTo("body")},createContainer:function(){return t("