From: Alexander Ebert Date: Sat, 4 Oct 2014 13:49:34 +0000 (+0200) Subject: Updated Redactor 9.2 -> 10.0 X-Git-Tag: 2.1.0_Alpha_1~278 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=aaec55d900bb8ce0425dd6d36e9915f141cf0319;p=GitHub%2FWoltLab%2FWCF.git Updated Redactor 9.2 -> 10.0 There are still some small glitches and I have not yet overhauled the API access from our own scripts (e.g. mentions). If something related to the editor is now broken, blame me. --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/table.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/table.js new file mode 100644 index 0000000000..dfc483197f --- /dev/null +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/table.js @@ -0,0 +1,330 @@ +if (!RedactorPlugins) var RedactorPlugins = {}; + +RedactorPlugins.table = function() +{ + return { + getTemplate: function() + { + return String() + + '
' + + '' + + '' + + '' + + '' + + '
'; + }, + init: function() + { + + var dropdown = {}; + + dropdown.insert_table = { title: this.lang.get('insert_table'), func: this.table.show }; + dropdown.insert_row_above = { title: this.lang.get('insert_row_above'), func: this.table.addRowAbove }; + dropdown.insert_row_below = { title: this.lang.get('insert_row_below'), func: this.table.addRowBelow }; + dropdown.insert_column_left = { title: this.lang.get('insert_column_left'), func: this.table.addColumnLeft }; + dropdown.insert_column_right = { title: this.lang.get('insert_column_right'), func: this.table.addColumnRight }; + dropdown.add_head = { title: this.lang.get('add_head'), func: this.table.addHead }; + dropdown.delete_head = { title: this.lang.get('delete_head'), func: this.table.deleteHead }; + dropdown.delete_column = { title: this.lang.get('delete_column'), func: this.table.deleteColumn }; + dropdown.delete_row = { title: this.lang.get('delete_row'), func: this.table.deleteRow }; + dropdown.delete_table = { title: this.lang.get('delete_table'), func: this.table.deleteTable }; + + this.observe.addButton('td', 'table'); + this.observe.addButton('th', 'table'); + + var button = this.button.addBefore('link', 'table', this.lang.get('table')); + this.button.addDropdown(button, dropdown); + }, + show: function() + { + this.modal.addTemplate('table', this.table.getTemplate()); + + this.modal.load('table', this.lang.get('insert_table'), 300); + this.modal.createCancelButton(); + + var button = this.modal.createActionButton(this.lang.get('insert')); + button.on('click', this.table.insert); + + this.selection.save(); + this.modal.show(); + + $('#redactor-table-rows').focus(); + + }, + insert: function() + { + + var rows = $('#redactor-table-rows').val(), + columns = $('#redactor-table-columns').val(), + $tableBox = $('
'), + tableId = Math.floor(Math.random() * 99999), + $table = $('
'), + i, $row, z, $column; + + for (i = 0; i < rows; i++) + { + $row = $(''); + + for (z = 0; z < columns; z++) + { + $column = $('' + this.opts.invisibleSpace + ''); + + // set the focus to the first td + if (i === 0 && z === 0) + { + $column.append(this.selection.getMarker()); + } + + $($row).append($column); + } + + $table.append($row); + } + + $tableBox.append($table); + var html = $tableBox.html(); + + + this.modal.close(); + this.selection.restore(); + + if (this.table.getTable()) return; + + this.buffer.set(); + + var current = this.selection.getBlock() || this.selection.getCurrent(); + if (current && current.tagName != 'BODY') + { + if (current.tagName == 'LI') current = $(current).closest('ul, ol'); + $(current).after(html); + } + else + { + this.insert.html(html); + } + + this.selection.restore(); + + var table = this.$editor.find('#table' + tableId); + + if (!this.opts.linebreaks && (this.utils.browser('mozilla') || this.utils.browser('msie'))) + { + var $next = table.next(); + if ($next.length === 0) + { + table.after(this.opts.emptyHtml); + } + } + + this.observe.buttons(); + + table.find('span.redactor-selection-marker').remove(); + table.removeAttr('id'); + + this.code.sync(); + this.core.setCallback('insertedTable', table); + }, + getTable: function() + { + var $table = $(this.selection.getParent()).closest('table'); + + if (!this.utils.isRedactorParent($table)) return false; + if ($table.size() === 0) return false; + + return $table; + }, + restoreAfterDelete: function($table) + { + this.selection.restore(); + $table.find('span.redactor-selection-marker').remove(); + this.code.sync(); + }, + deleteTable: function() + { + var $table = this.table.getTable(); + if (!$table) return; + + this.buffer.set(); + + + var $next = $table.next(); + if (!this.opts.linebreaks && $next.length !== 0) + { + this.caret.setStart($next); + } + else + { + this.caret.setAfter($table); + } + + + $table.remove(); + + this.code.sync(); + }, + deleteRow: function() + { + var $table = this.table.getTable(); + if (!$table) return; + + var $current = $(this.selection.getCurrent()); + + this.buffer.set(); + + var $current_tr = $current.closest('tr'); + var $focus_tr = $current_tr.prev().length ? $current_tr.prev() : $current_tr.next(); + if ($focus_tr.length) + { + var $focus_td = $focus_tr.children('td, th').first(); + if ($focus_td.length) $focus_td.prepend(this.selection.getMarker()); + } + + $current_tr.remove(); + this.table.restoreAfterDelete($table); + }, + deleteColumn: function() + { + var $table = this.table.getTable(); + if (!$table) return; + + this.buffer.set(); + + var $current = $(this.selection.getCurrent()); + var $current_td = $current.closest('td, th'); + var index = $current_td[0].cellIndex; + + $table.find('tr').each($.proxy(function(i, elem) + { + var $elem = $(elem); + var focusIndex = index - 1 < 0 ? index + 1 : index - 1; + if (i === 0) $elem.find('td, th').eq(focusIndex).prepend(this.selection.getMarker()); + + $elem.find('td, th').eq(index).remove(); + + }, this)); + + this.table.restoreAfterDelete($table); + }, + addHead: function() + { + var $table = this.table.getTable(); + if (!$table) return; + + this.buffer.set(); + + if ($table.find('thead').size() !== 0) + { + this.table.deleteHead(); + return; + } + + var tr = $table.find('tr').first().clone(); + tr.find('td').html(this.opts.invisibleSpace); + $thead = $('').append(tr); + $table.prepend($thead); + + this.code.sync(); + + }, + deleteHead: function() + { + var $table = this.table.getTable(); + if (!$table) return; + + var $thead = $table.find('thead'); + if ($thead.size() === 0) return; + + this.buffer.set(); + + $thead.remove(); + this.code.sync(); + }, + addRowAbove: function() + { + this.table.addRow('before'); + }, + addRowBelow: function() + { + this.table.addRow('after'); + }, + addColumnLeft: function() + { + this.table.addColumn('before'); + }, + addColumnRight: function() + { + this.table.addColumn('after'); + }, + addRow: function(type) + { + var $table = this.table.getTable(); + if (!$table) return; + + this.buffer.set(); + + var $current = $(this.selection.getCurrent()); + var $current_tr = $current.closest('tr'); + var new_tr = $current_tr.clone(); + + new_tr.find('th').replaceWith(function() + { + var $td = $(''); + $td[0].attributes = this.attributes; + + return $td.append($(this).contents()); + }); + + new_tr.find('td').html(this.opts.invisibleSpace); + + if (type == 'after') + { + $current_tr.after(new_tr); + } + else + { + $current_tr.before(new_tr); + } + + this.code.sync(); + }, + addColumn: function (type) + { + var $table = this.table.getTable(); + if (!$table) return; + + var index = 0; + var current = $(this.selection.getCurrent()); + + this.buffer.set(); + + var $current_tr = current.closest('tr'); + var $current_td = current.closest('td, th'); + + $current_tr.find('td, th').each($.proxy(function(i, elem) + { + if ($(elem)[0] === $current_td[0]) index = i; + + }, this)); + + $table.find('tr').each($.proxy(function(i, elem) + { + var $current = $(elem).find('td, th').eq(index); + + var td = $current.clone(); + td.html(this.opts.invisibleSpace); + + if (type == 'after') + { + $current.after(td); + } + else + { + $current.before(td); + } + + }, this)); + + this.code.sync(); + } + }; +}; \ No newline at end of file diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index 5f737288b5..cb1322e93d 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -7,1234 +7,1284 @@ if (!RedactorPlugins) var RedactorPlugins = {}; * @copyright 2001-2014 WoltLab GmbH * @license GNU Lesser General Public License */ -RedactorPlugins.wbbcode = { - /** - * Initializes the RedactorPlugins.wbbcode plugin. - */ - init: function() { - var $identifier = this.$source.wcfIdentify(); - - this.opts.initCallback = $.proxy(function() { - // use stored editor contents - var $content = $.trim(this.getOption('wOriginalValue')); - if ($content.length) { - this.toggle(); - this.$source.val($content); - this.toggle(); - } +RedactorPlugins.wbbcode = function() { + "use strict"; + + return { + /** + * Initializes the RedactorPlugins.wbbcode plugin. + */ + init: function() { + var $identifier = this.$textarea.wcfIdentify(); - delete this.opts.wOriginalValue; - }, this); - - this.opts.pasteBeforeCallback = $.proxy(this._wPasteBeforeCallback, this); - this.opts.pasteAfterCallback = $.proxy(this._wPasteAfterCallback, this); - - var $mpSyncClean = this.syncClean; - var self = this; - this.syncClean = function(html) { - html = html.replace(/

]+)?><\/p>/g, '

@@@wcf_empty_line@@@

'); - return $mpSyncClean.call(self, html); - }; - - if (this.getOption('wAutosaveOnce')) { - this._saveTextToStorage(); - delete this.opts.wAutosaveOnce; - } - - // we do not support table heads - var $tableButton = this.buttonGet('table'); - if ($tableButton.length) { - var $addHead = $tableButton.data('dropdown').children('a.redactor_dropdown_add_head'); + this.opts.initCallback = $.proxy(function() { + // use stored editor contents + var $content = $.trim(this.wutil.getOption('wOriginalValue')); + if ($content.length) { + this.toggle(); + this.$textarea.val($content); + this.toggle(); + } + + delete this.opts.wOriginalValue; + }, this); - // drop divider - $addHead.prev().remove(); + this.opts.pasteBeforeCallback = $.proxy(this.wbbcode._pasteBeforeCallback, this); + this.opts.pasteCallback = $.proxy(this.wbbcode._pasteCallback, this); - // drop 'delete head' - $addHead.next().remove(); + var $mpCleanOnSync = this.clean.onSync; + this.clean.onSync = function(html) { + html = html.replace(/

]+)?><\/p>/g, '

@@@wcf_empty_line@@@

'); + return $mpCleanOnSync.call(self, html); + }; - // drop 'add head' - $addHead.remove(); + if (this.wutil.getOption('wAutosaveOnce')) { + this.wutil._saveTextToStorage(); + delete this.opts.wAutosaveOnce; + } - // toggle dropdown options - $tableButton.click($.proxy(this._tableButtonClick, this)); - } - - // handle 'insert quote' button - WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'insertBBCode_quote_' + $identifier, $.proxy(function(data) { - data.cancel = true; + // we do not support table heads + var $tableButton = this.button.get('table'); + if ($tableButton.length) { + var $dropdown = $tableButton.data('dropdown'); + + // remove head add/delete + $dropdown.find('.redactor-dropdown-add_head').parent().remove(); + $dropdown.find('.redactor-dropdown-delete_head').parent().remove(); + + // add visual divider + $('