From 1e798c97fa9ad987086cccceead5f10bac755172 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 1 Feb 2015 14:21:03 +0100 Subject: [PATCH] Upgraded to Redactor 10.0.7 --- .../3rdParty/redactor/plugins/wmonkeypatch.js | 24 +- .../files/js/3rdParty/redactor/redactor.js | 527 ++++++++++-------- .../js/3rdParty/redactor/redactor.min.js | 6 +- 3 files changed, 325 insertions(+), 232 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index fa32860867..746c82006d 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -296,9 +296,9 @@ RedactorPlugins.wmonkeypatch = function() { if (orgn.tagName == 'BR' && this.opts.linebreaks === false) { - var par = $(this.opts.emptyHtml)[0]; - $(orgn).replaceWith(par); - orgn = par; + var parent = $(this.opts.emptyHtml)[0]; + $(orgn).replaceWith(parent); + orgn = parent; focn = orgn; } @@ -484,6 +484,8 @@ RedactorPlugins.wmonkeypatch = function() { var $item = $('' + btnObject.title + ''); $item.on('click', $.proxy(function(e) { + e.preventDefault(); + var type = 'func'; var callback = btnObject.func; if (btnObject.command) { @@ -496,7 +498,7 @@ RedactorPlugins.wmonkeypatch = function() { } this.button.onClick(e, btnName, type, callback); - + this.dropdown.hideAll(); }, this)); $item.appendTo($listItem); @@ -646,12 +648,12 @@ RedactorPlugins.wmonkeypatch = function() { }).bind(this); // inline.formatRemoveSameChildren; - var $mpFormatRemoveSameChildren = this.inline.formatRemoveSameChildren; + /*var $mpFormatRemoveSameChildren = this.inline.formatRemoveSameChildren; this.inline.formatRemoveSameChildren = (function($el, tag) { // check if this represents a style - if (tag === 'span' && this.inline.type === 'style') { - var $newProperty = this.inline.value.replace(/^([^:]+?):.*/, '$1'); - + if (tag === 'span' && this.inline.type === 'style') {*/ + //var $newProperty = this.inline.value.replace(/^([^:]+?):.*/, '$1'); + /* $el.children(tag).each((function(index, child) { var $child = $(child); if (!$child.hasClass('redactor-selection-marker')) { @@ -669,7 +671,7 @@ RedactorPlugins.wmonkeypatch = function() { else { $mpFormatRemoveSameChildren.call(this, $el, tag); } - }).bind(this); + }).bind(this);*/ // inline.removeStyleRule var $mpRemoveStyleRule = this.inline.removeStyleRule; @@ -863,7 +865,7 @@ RedactorPlugins.wmonkeypatch = function() { }).bind(this); // link.set - var $mpSet = this.link.set; + /*var $mpSet = this.link.set; this.link.set = (function(text, link, target) { $mpSet.call(this, text, link, target); @@ -879,7 +881,7 @@ RedactorPlugins.wmonkeypatch = function() { $($current).text(text); } } - }).bind(this); + }).bind(this);*/ }, /** diff --git a/wcfsetup/install/files/js/3rdParty/redactor/redactor.js b/wcfsetup/install/files/js/3rdParty/redactor/redactor.js index 2ac60a7445..23baa5c45b 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/redactor.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/redactor.js @@ -1,6 +1,6 @@ /* - Redactor v10.0.6 - Updated: January 7, 2015 + Redactor v10.0.7 + Updated: January 31, 2015 http://imperavi.com/redactor/ @@ -94,7 +94,7 @@ // Functionality $.Redactor = Redactor; - $.Redactor.VERSION = '10.0.6'; + $.Redactor.VERSION = '10.0.7'; $.Redactor.modules = ['alignment', 'autosave', 'block', 'buffer', 'build', 'button', 'caret', 'clean', 'code', 'core', 'dropdown', 'file', 'focus', 'image', 'indent', 'inline', 'insert', 'keydown', 'keyup', @@ -147,14 +147,14 @@ imageFloatMargin: '10px', imageResizable: true, - imageUpload: false, + imageUpload: null, imageUploadParam: 'file', uploadImageField: false, dragImageUpload: true, - fileUpload: false, + fileUpload: null, fileUploadParam: 'file', dragFileUpload: true, @@ -179,7 +179,7 @@ toolbarExternal: false, // ID selector toolbarOverflow: false, - buttonSource: false, + source: true, buttons: ['html', 'formatting', 'bold', 'italic', 'deleted', 'unorderedlist', 'orderedlist', 'outdent', 'indent', 'image', 'file', 'link', 'alignment', 'horizontalrule'], // + 'underline' @@ -447,50 +447,69 @@ }, set: function(type) { + // focus if (!this.utils.browser('msie')) this.$editor.focus(); this.buffer.set(); this.selection.save(); + // get blocks this.alignment.blocks = this.selection.getBlocks(); - if (this.opts.linebreaks && this.alignment.blocks[0] === false) + this.alignment.type = type; + + // set alignment + if (this.alignment.isLinebreaksOrNoBlocks()) { - this.alignment.setText(type); + this.alignment.setText(); } else { - this.alignment.setBlocks(type); + this.alignment.setBlocks(); } + // sync this.selection.restore(); this.code.sync(); }, - setText: function(type) + setText: function() { var wrapper = this.selection.wrap('div'); - $(wrapper).attr('data-tagblock', 'redactor'); - $(wrapper).css('text-align', type); + $(wrapper).attr('data-tagblock', 'redactor').css('text-align', this.alignment.type); }, - setBlocks: function(type) + setBlocks: function() { $.each(this.alignment.blocks, $.proxy(function(i, el) { var $el = this.utils.getAlignmentElement(el); - if (!$el) return; - if (type === '' && typeof($el.data('tagblock')) !== 'undefined') + if (this.alignment.isNeedReplaceElement($el)) { - $el.replaceWith($el.html()); + this.alignment.replaceElement($el); } else { - $el.css('text-align', type); - this.utils.removeEmptyAttr($el, 'style'); + 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'); } }; }, @@ -504,35 +523,36 @@ this.autosave.html = false; this.autosave.name = (this.opts.autosaveName) ? this.opts.autosaveName : this.$textarea.attr('name'); - if (!this.opts.autosaveOnChange) - { - this.autosaveInterval = setInterval($.proxy(this.autosave.load, this), this.opts.autosaveInterval * 1000); - } + 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() { - var html = this.code.get(); - if (this.autosave.html === html) return; - if (this.utils.isEmpty(html)) return; + this.autosave.source = this.code.get(); - $.ajax({ + if (this.autosave.html === this.autosave.source) return; + if (this.utils.isEmpty(this.autosave.source)) return; + + // data + var data = {}; + data['name'] = this.autosave.name; + data[this.autosave.name] = escape(encodeURIComponent(this.autosave.source)); + + // ajax + var jsxhr = $.ajax({ url: this.opts.autosave, type: 'post', - data: 'name=' + this.autosave.name + '&' + this.autosave.name + '=' + escape(encodeURIComponent(html)), - success: $.proxy(function(data) - { - this.autosave.success(data, html); - - }, this) + data: data }); + + jsxhr.done(this.autosave.success); }, - success: function(data, html) + success: function(data) { var json; try @@ -548,7 +568,7 @@ var callbackName = (typeof json.error == 'undefined') ? 'autosave' : 'autosaveError'; this.core.setCallback(callbackName, this.autosave.name, json); - this.autosave.html = html; + this.autosave.html = this.autosave.source; }, disable: function() { @@ -741,6 +761,7 @@ } else { + if (this.opts.linebreaks || tag != 'p') { if (tag == 'blockquote') @@ -773,6 +794,7 @@ } + this.block.formatWrap(tag); } else @@ -782,7 +804,7 @@ if (this.block.type == 'class') { toggleType = 'toggle'; - classSize = $(this.block.blocks).filter('.' + this.block.value).size(); + classSize = $(this.block.blocks).filter('.' + this.block.value).length; if (this.block.blocksSize == classSize) toggleType = 'toggle'; else if (this.block.blocksSize > classSize) toggleType = 'set'; @@ -964,10 +986,10 @@ }, formatTableWrapping: function($formatted) { - if ($formatted.closest('table').size() === 0) return; + if ($formatted.closest('table').length === 0) return; - if ($formatted.closest('tr').size() === 0) $formatted.wrap(''); - if ($formatted.closest('td').size() === 0 && $formatted.closest('th').size() === 0) + if ($formatted.closest('tr').length === 0) $formatted.wrap(''); + if ($formatted.closest('td').length === 0 && $formatted.closest('th').length === 0) { $formatted.wrap(''); } @@ -1122,13 +1144,11 @@ return { run: function() { - this.build.createContainerBox(); this.build.loadContent(); this.build.loadEditor(); this.build.enableEditor(); this.build.setCodeAndCall(); - }, isTextarea: function() { @@ -1144,13 +1164,7 @@ }, getTextareaName: function() { - var name = this.$element.attr('id'); - if (typeof(name) == 'undefined') - { - name = 'content-' + this.uuid; - } - - return name; + return ((typeof(name) == 'undefined')) ? 'content-' + this.uuid : this.$element.attr('id'); }, loadContent: function() { @@ -1193,10 +1207,8 @@ this.build.callEditor(); // code mode - if (!this.opts.visual) - { - setTimeout($.proxy(this.code.showCode, this), 200); - } + if (this.opts.visual) return; + setTimeout($.proxy(this.code.showCode, this), 200); }, callEditor: function() { @@ -1236,6 +1248,21 @@ if (this.opts.maxHeight) this.$editor.css('maxHeight', this.opts.maxHeight); }, + setEventDropUpload: function(e) + { + e.preventDefault(); + + if (!this.opts.dragImageUpload || !this.opts.dragFileUpload) return; + + var files = e.dataTransfer.files; + this.upload.directUpload(files[0], e); + }, + setEventDrop: function(e) + { + this.code.sync(); + setTimeout(this.clean.clearUnverified, 1); + this.core.setCallback('drop', e); + }, setEvents: function() { // drop @@ -1245,28 +1272,16 @@ if (window.FormData === undefined || !e.dataTransfer) return true; - var length = e.dataTransfer.files.length; - if (length === 0) + if (e.dataTransfer.files.length === 0) { - this.code.sync(); - setTimeout($.proxy(this.clean.clearUnverified, this), 1); - this.core.setCallback('drop', e); - - return true; + return this.build.setEventDrop(e); } else { - e.preventDefault(); - - if (this.opts.dragImageUpload || this.opts.dragFileUpload) - { - var files = e.dataTransfer.files; - this.upload.directUpload(files[0], e); - } + this.build.setEventDropUpload(e); } - setTimeout($.proxy(this.clean.clearUnverified, this), 1); - + setTimeout(this.clean.clearUnverified, 1); this.core.setCallback('drop', e); }, this)); @@ -1275,11 +1290,8 @@ // click this.$editor.on('click.redactor', $.proxy(function(e) { - var type = 'click'; - if ((this.core.getEvent() == 'click' || this.core.getEvent() == 'arrow')) - { - type = false; - } + var event = this.core.getEvent(); + var type = (event == 'click' || event == 'arrow') ? false : 'click'; this.core.addEvent(type); this.utils.disableSelectAll(); @@ -1315,23 +1327,25 @@ } var clickedElement; - $(document).on('mousedown', function(e) { - clickedElement = $(e.target); - }); + $(document).on('mousedown', function(e) { clickedElement = e.target; }); // blur this.$editor.on('blur.redactor', $.proxy(function(e) { if (this.rtePaste) return; + if (!this.build.isBlured(clickedElement)) return; + + this.utils.disableSelectAll(); + if ($.isFunction(this.opts.blurCallback)) this.core.setCallback('blur', e); - var $el = $(clickedElement); - if (!$el.hasClass('redactor-toolbar, redactor-dropdown') && !$el.is('#redactor-modal') && $el.parents('.redactor-toolbar, .redactor-dropdown, #redactor-modal').size() === 0) - { - this.utils.disableSelectAll(); - if ($.isFunction(this.opts.blurCallback)) this.core.setCallback('blur', e); - } }, this)); }, + isBlured: function(clickedElement) + { + var $el = $(clickedElement); + + return (!$el.hasClass('redactor-toolbar, redactor-dropdown') && !$el.is('#redactor-modal') && $el.parents('.redactor-toolbar, .redactor-dropdown, #redactor-modal').length === 0); + }, setHelpers: function() { // autosave @@ -1341,8 +1355,8 @@ this.placeholder.enable(); // focus - if (this.opts.focus) setTimeout($.proxy(this.focus.setStart, this), 100); - if (this.opts.focusEnd) setTimeout($.proxy(this.focus.setEnd, this), 100); + if (this.opts.focus) setTimeout(this.focus.setStart, 100); + if (this.opts.focusEnd) setTimeout(this.focus.setEnd, 100); }, plugins: function() @@ -1364,6 +1378,7 @@ this[s] = RedactorPlugins[s](); + // get methods var methods = this.getModuleMethods(this[s]); var len = methods.length; @@ -1378,7 +1393,6 @@ }, this)); - }, disableMozillaEditing: function() { @@ -1399,28 +1413,10 @@ { var $button = $('').attr('tabindex', '-1'); + // click if (btnObject.func || btnObject.command || btnObject.dropdown) { - $button.on('touchstart click', $.proxy(function(e) - { - if ($button.hasClass('redactor-button-disabled')) return false; - - var type = 'func'; - var callback = btnObject.func; - if (btnObject.command) - { - type = 'command'; - callback = btnObject.command; - } - else if (btnObject.dropdown) - { - type = 'dropdown'; - callback = false; - } - - this.button.onClick(e, btnName, type, callback); - - }, this)); + this.button.setEvent($button, btnName, btnObject); } // dropdown @@ -1439,6 +1435,30 @@ return $button; }, + setEvent: function($button, btnName, btnObject) + { + $button.on('touchstart click', $.proxy(function(e) + { + if ($button.hasClass('redactor-button-disabled')) return false; + + var type = 'func'; + var callback = btnObject.func; + + if (btnObject.command) + { + type = 'command'; + callback = btnObject.command; + } + else if (btnObject.dropdown) + { + type = 'dropdown'; + callback = false; + } + + this.button.onClick(e, btnName, type, callback); + + }, this)); + }, createTooltip: function($button, name, title) { var $tooltip = $('').addClass('redactor-toolbar-tooltip redactor-toolbar-tooltip-' + name).hide().html(title); @@ -1449,13 +1469,11 @@ if ($(this).hasClass('redactor-button-disabled')) return; var pos = $button.offset(); - var height = $button.innerHeight(); - var width = $button.innerWidth(); $tooltip.show(); $tooltip.css({ - top: (pos.top + height) + 'px', - left: (pos.left + width/2 - $tooltip.innerWidth()/2) + 'px' + top: (pos.top + $button.innerHeight()) + 'px', + left: (pos.left + $button.innerWidth()/2 - $tooltip.innerWidth()/2) + 'px' }); }); @@ -1473,38 +1491,25 @@ if (this.utils.browser('msie')) e.returnValue = false; - if (type == 'command') - { - this.inline.format(callback); - } - else if (type == 'dropdown') - { - this.dropdown.show(e, btnName); - } - else + if (type == 'command') this.inline.format(callback); + else if (type == 'dropdown') this.dropdown.show(e, btnName); + else this.button.onClickCallback(e, callback, btnName); + }, + onClickCallback: function(e, callback, btnName) + { + var func; + + if ($.isFunction(callback)) callback.call(this, btnName); + else if (callback.search(/\./) != '-1') { - var func; + func = callback.split('.'); + if (typeof this[func[0]] == 'undefined') return; - if ($.isFunction(callback)) - { - callback.call(this, btnName); - this.observe.buttons(e, btnName); - } - else if (callback.search(/\./) != '-1') - { - func = callback.split('.'); - if (typeof this[func[0]] != 'undefined') - { - this[func[0]][func[1]](btnName); - this.observe.buttons(e, btnName); - } - } - else - { - this[callback](btnName); - this.observe.buttons(e, btnName); - } + this[func[0]][func[1]](btnName); } + else this[callback](btnName); + + this.observe.buttons(e, btnName); }, get: function(key) { @@ -1570,10 +1575,8 @@ var $dropdown = $('