From bffa6d6801062bbf30f9813a0626b5afa540fa0b Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 13 Feb 2017 11:38:19 +0100 Subject: [PATCH] Upgraded to Redactor II 2.1 --- .../files/js/3rdParty/redactor2/redactor.js | 174 +++++++++++------- .../js/3rdParty/redactor2/redactor.min.js | 10 +- 2 files changed, 109 insertions(+), 75 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js index 4cf1f81202..1c4a5cdffb 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.0 - Updated: February 5, 2017 + Version 2.1 + Updated: February 13, 2017 http://imperavi.com/redactor/ @@ -101,7 +101,7 @@ // Options $.Redactor = Redactor; - $.Redactor.VERSION = '2.0'; + $.Redactor.VERSION = '2.1'; $.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', @@ -506,12 +506,13 @@ this.opts = $.extend( {}, - $.extend(true, {}, $.Redactor.opts), - $.extend(true, {}, settings), + $.Redactor.opts, this.$element.data(), options ); + this.opts = $.extend(true, this.opts, settings); + }, getModuleMethods: function(object) { @@ -613,9 +614,9 @@ }, show: function (e) { - this.marker.remove(); - this.selection.save(); - this.selection.restore(false); + //this.marker.remove(); + this.selection.saveInstant(); + //this.selection.restore(false); $('.redactor-air').hide(); @@ -661,19 +662,19 @@ if (key === this.keyCode.ESC) { this.selection.get().collapseToStart(); - this.marker.remove(); + //this.marker.remove(); } else if (key === this.keyCode.BACKSPACE || key === this.keyCode.DELETE) { var sel = this.selection.get(); var range = this.selection.range(sel); range.deleteContents(); - this.marker.remove(); + //this.marker.remove(); } else if (key === this.keyCode.ENTER) { this.selection.get().collapseToEnd(); - this.marker.remove(); + //this.marker.remove(); } if (this.air.enabled) @@ -683,7 +684,7 @@ else { this.selection.get().collapseToStart(); - this.marker.remove(); + //this.marker.remove(); } @@ -783,7 +784,7 @@ var json; try { - json = $.parseJSON(data); + json = JSON.parse(data); } catch(e) { @@ -1114,26 +1115,28 @@ }, setUndo: function() { - var saved = this.selection.saveInstant(); + var saved = this.selection.saveInstant(); var last = this.opts.buffer[this.opts.buffer.length-1]; var current = this.core.editor().html(); - if (last !== current) - { + + var save = (typeof last !== 'undefined' && (last[0] === current)) ? false : true; + if (save) + { this.opts.buffer.push([current, saved]); } - this.selection.restoreInstant(); + //this.selection.restoreInstant(); }, setRedo: function() { var saved = this.selection.saveInstant(); this.opts.rebuffer.push([this.core.editor().html(), saved]); - this.selection.restoreInstant(); + //this.selection.restoreInstant(); }, add: function() { - this.opts.buffer.push(this.core.editor().html()); + this.opts.buffer.push([this.core.editor().html(), 0]); }, undo: function() { @@ -2216,7 +2219,6 @@ }, start: function(node) { - var sel, range; node = this.caret.prepare(node); @@ -2230,45 +2232,56 @@ return this.caret.before(node); } + var $first = $(node).children().first(); + // empty or inline tag var inline = this.utils.isInlineTag(node.tagName); if (node.innerHTML === '' || inline) { - sel = window.getSelection(); - range = document.createRange(); - var textNode = document.createTextNode('\u200B'); - - range.setStart(node, 0); - range.insertNode(textNode); - range.setStartAfter(textNode); - range.collapse(true); - - sel.removeAllRanges(); - sel.addRange(range); - - // remove invisible text node - if (!inline) - { - this.core.editor().on('keydown.redactor-remove-textnode', function() - { - $(textNode).remove(); - $(this).off('keydown.redactor-remove-textnode'); - }); - } + this.caret.setStartEmptyOrInline(node, inline); } - // block tag + // empty inline inside + else if ($first && $first.length !== 0 && this.utils.isInlineTag($first[0].tagName) && $first.text() === '') + { + this.caret.setStartEmptyOrInline($first[0], true); + } + // block tag else { - sel = window.getSelection(); - sel.removeAllRanges(); + sel = window.getSelection(); + sel.removeAllRanges(); - range = document.createRange(); - range.selectNodeContents(node); - range.collapse(true); - sel.addRange(range); + range = document.createRange(); + range.selectNodeContents(node); + range.collapse(true); + sel.addRange(range); } + }, + setStartEmptyOrInline: function(node, inline) + { + var sel = window.getSelection(); + var range = document.createRange(); + var textNode = document.createTextNode('\u200B'); + + range.setStart(node, 0); + range.insertNode(textNode); + range.setStartAfter(textNode); + range.collapse(true); + + sel.removeAllRanges(); + sel.addRange(range); + + // remove invisible text node + if (!inline) + { + this.core.editor().on('keydown.redactor-remove-textnode', function() + { + $(textNode).remove(); + $(this).off('keydown.redactor-remove-textnode'); + }); + } }, end: function(node) { @@ -2573,7 +2586,7 @@ $div.find('*[rel=""]').removeAttr('rel'); // remove markers - $div.find('.redactor-invisible-space').each(function() + $div.find('.redactor-invisible-space, .redactor-unlink').each(function() { $(this).contents().unwrap(); }); @@ -2967,7 +2980,7 @@ $links.attr('target', this.opts.pasteLinkTarget); } - // links & images + // links if (data.links && this.opts.pasteLinks) { $div.find('a').each(function(i, link) @@ -2992,6 +3005,7 @@ html = $div.html(); + // images if (data.images && this.opts.pasteImages) { html = html.replace(/])>/gi, '##%img$1src="$2"$3%##'); @@ -5011,14 +5025,23 @@ var $figure = $image.closest(this.opts.imageTag, this.core.editor()[0]); var $parent = $image.parent(); + // callback + var imageDeleteStop = this.core.callback('imageDelete', e, $image[0]); + if (imageDeleteStop === false) + { + e.preventDefault(); + return false; + } + if ($('#redactor-image-box').length !== 0) { $parent = $('#redactor-image-box').parent(); } - var $next; + var $next, $prev; if ($figure.length !== 0) { + $prev = $figure.prev(); $next = $figure.next(); $figure.remove(); } @@ -5036,19 +5059,18 @@ if (e !== false) { - if ($figure.length !== 0 && $next.length !== 0) + if ($next && $next.length !== 0) { this.caret.start($next); } - else if ($parent.length !== 0) + else if ($prev && $prev.length !== 0) { - this.caret.start($parent); + this.caret.end($prev); } } if (typeof e !== 'boolean') { - this.modal.close(); } @@ -5436,7 +5458,7 @@ { for (var key in attr) { - self.inline.setAttr($inside, key, attr[key], 'remove'); + self.inline.removeSpecificAttr($inside, key, attr[key]); } } @@ -5446,7 +5468,7 @@ { for (var key in attr) { - self.inline.setAttr($parent, key, attr[key], 'remove'); + self.inline.removeSpecificAttr($parent, key, attr[key]); } } }); @@ -5639,6 +5661,20 @@ { return $(this.inline.getInlines(inline)).attr(attr, value)[0]; }, + removeSpecificAttr: function(inline, key, value) + { + if (key === 'style') + { + var arr = value.split(':'); + var name = arr[0].trim(); + $(inline).css(name, ''); + this.utils.removeEmptyAttr(inline, 'style'); + } + else + { + $(inline).removeAttr(key)[0]; + } + }, removeAttr: function(attr, inline) { return $(this.inline.getInlines(inline)).removeAttr(attr)[0]; @@ -6318,7 +6354,6 @@ // backspace if (key === this.keyCode.BACKSPACE) { - if (this.detect.isFirefox()) { this.line.removeOnBackspace(e); @@ -6459,6 +6494,7 @@ return; } + // remove inline tags in new-empty paragraph setTimeout($.proxy(function() { @@ -6483,8 +6519,8 @@ sel.addRange(range); } - }, this), 1); + }, this), 1); }, checkEvents: function(arrow, key) { @@ -9423,7 +9459,6 @@ return node.nextSibling; } }, - saved: {}, save: function() { this.marker.insert(); @@ -9477,11 +9512,13 @@ var start = selectionRange.toString().length; - return this.saved = { + this.saved = { start: start, end: start + range.toString().length, node: range.startContainer }; + + return this.saved; }, restoreInstant: function(saved) { @@ -9508,7 +9545,6 @@ return; } - var el = this.core.editor()[0]; var doc = el.ownerDocument, win = doc.defaultView; var charIndex = 0, range = doc.createRange(); @@ -10181,7 +10217,7 @@ var json; try { - json = (typeof data === 'string' ? $.parseJSON(data) : data); + json = (typeof data === 'string' ? JSON.parse(data) : data); } catch(err) { @@ -10822,14 +10858,12 @@ }, rgb2hex: function(rgb) { - rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); - - function hex(x) - { - return ("0" + parseInt(x).toString(16)).slice(-2); - } + rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i); - return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); + return (rgb && rgb.length === 4) ? "#" + + ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) + + ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) + + ("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : ''; }, // #backward diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.min.js b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.min.js index bbb166bee6..ac6c005d65 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.min.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.min.js @@ -1,5 +1,5 @@ -!function(t){"use strict";function e(t,i){return new e.prototype.init(t,i)}Function.prototype.bind||(Function.prototype.bind=function(t){var e=this;return function(){return e.apply(t)}});var i=0;t.fn.redactor=function(i){var o=[],r=Array.prototype.slice.call(arguments,1);return"string"==typeof i?this.each(function(){var e,s=t.data(this,"redactor");if("-1"!==i.search(/\./)?(e=i.split("."),"undefined"!=typeof s[e[0]]&&(e=s[e[0]][e[1]])):e=s[i],"undefined"!=typeof s&&t.isFunction(e)){var n=e.apply(s,r);void 0!==n&&n!==s&&o.push(n)}else t.error('No such method "'+i+'" for Redactor')}):this.each(function(){t.data(this,"redactor",{}),t.data(this,"redactor",e(this,i))}),0===o.length?this:1===o.length?o[0]:o},t.Redactor=e,t.Redactor.VERSION="2.0",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,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"],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:"​",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}},e.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,o){return this.$element=t(e),this.uuid=i++,this.loadOptions(o),this.loadModules(),this.opts.clickToEdit&&!this.$element.hasClass("redactor-click-to-edit")?this.loadToEdit(o):(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.extend(!0,{},t.Redactor.opts),t.extend(!0,{},i),this.$element.data(),e)},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,o=0;i>o;o++)this[t][e[o]]=this[t][e[o]].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("