diff --git a/css/redactor.css b/css/redactor.css index dcea50240d395bcb8b0d8e022f5d39cc72eea799..ea8a3820ae39bc06eae0b6d271a5dd36bbba4ddd 100644 --- a/css/redactor.css +++ b/css/redactor.css @@ -970,3 +970,20 @@ body .redactor-box-fullscreen { font-size: 1em; text-transform: uppercase; } +.redactor.color-swatch { + float: left; + font-size: 0; + border: 2px solid #fff; + padding: 0; + margin: 0; + width: 22px; + height: 22px; + box-sizing: border-box; +} +.redactor.uncolor { + display: block; + clear: both; + padding: 5px; + font-size: 12px; + line-height: 1; +} diff --git a/js/redactor-plugins.js b/js/redactor-plugins.js index ba446ca0019da9d6d1e526b23015ea5bfd3ab33e..a7a143a05d48df8b33c6a3d015a34530f5a17ed5 100644 --- a/js/redactor-plugins.js +++ b/js/redactor-plugins.js @@ -1,53 +1,56 @@ if (!RedactorPlugins) var RedactorPlugins = {}; -RedactorPlugins.definedlinks = function() +(function($) { - return { - init: function() - { - if (!this.opts.definedLinks) return; - - this.modal.addCallback('link', $.proxy(this.definedlinks.load, this)); - - }, - load: function() - { - var $select = $('<select id="redactor-defined-links" />'); - $('#redactor-modal-link-insert').prepend($select); + $.Redactor.prototype.definedlinks = function() + { + return { + init: function() + { + if (!this.opts.definedLinks) return; - this.definedlinks.storage = {}; + this.modal.addCallback('link', $.proxy(this.definedlinks.load, this)); - $.getJSON(this.opts.definedLinks, $.proxy(function(data) - { - $.each(data, $.proxy(function(key, val) - { - this.definedlinks.storage[key] = val; - $select.append($('<option>').val(key).html(val.name)); + }, + load: function() + { + var $select = $('<select id="redactor-defined-links" />'); + $('#redactor-modal-link-insert').prepend($select); - }, this)); + this.definedlinks.storage = {}; - $select.on('change', $.proxy(this.definedlinks.select, this)); + $.getJSON(this.opts.definedLinks, $.proxy(function(data) + { + $.each(data, $.proxy(function(key, val) + { + this.definedlinks.storage[key] = val; + $select.append($('<option>').val(key).html(val.name)); - }, this)); + }, this)); - }, - select: function(e) - { - var key = $(e.target).val(); - var name = '', url = ''; - if (key !== 0) - { - name = this.definedlinks.storage[key].name; - url = this.definedlinks.storage[key].url; - } + $select.on('change', $.proxy(this.definedlinks.select, this)); - $('#redactor-link-url').val(url); + }, this)); - var $el = $('#redactor-link-url-text'); - if ($el.val() === '') $el.val(name); - } - }; -}; + }, + select: function(e) + { + var key = $(e.target).val(); + var name = '', url = ''; + if (key !== 0) + { + name = this.definedlinks.storage[key].name; + url = this.definedlinks.storage[key].url; + } + + $('#redactor-link-url').val(url); + + var $el = $('#redactor-link-url-text'); + if ($el.val() === '') $el.val(name); + } + }; + }; +})(jQuery); RedactorPlugins.fontcolor = function() { @@ -86,21 +89,23 @@ RedactorPlugins.fontcolor = function() var func = function(e) { e.preventDefault(); - self.fontcolor.set($(this).data('rule'), $(this).attr('rel')); + var $this = $(e.target); + self.fontcolor.set($this.data('rule'), $this.attr('rel')); }; + $dropdown.on('click', 'a.redactor.color-swatch', func); + + var template = $('<a class="redactor color-swatch" href="#"></a>') + .data('rule', rule); for (var z = 0; z < len; z++) { var color = colors[z]; - - var $swatch = $('<a rel="' + color + '" data-rule="' + rule +'" href="#" style="float: left; font-size: 0; border: 2px solid #fff; padding: 0; margin: 0; width: 22px; height: 22px; box-sizing: border-box;"></a>'); + var $swatch = template.clone().attr('rel', color); $swatch.css('background-color', color); - $swatch.on('click', func); - $dropdown.append($swatch); } - var $elNone = $('<a href="#" style="display: block; clear: both; padding: 5px; font-size: 12px; line-height: 1;"></a>').html(this.lang.get('none')); + var $elNone = $('<a href="#" style="redactor uncolor"></a>').html(this.lang.get('none')); $elNone.on('click', $.proxy(function(e) { e.preventDefault(); @@ -270,387 +275,546 @@ RedactorPlugins.fullscreen = function() }; }; -RedactorPlugins.imagemanager = function() +(function($) { - return { - init: function() - { - if (!this.opts.imageManagerJson) return; + $.Redactor.prototype.imagemanager = function() + { + return { + init: function() + { + if (!this.opts.imageManagerJson) return; - this.modal.addCallback('image', this.imagemanager.load); - }, - load: function() - { - var $modal = this.modal.getModal(); + this.modal.addCallback('image', this.imagemanager.load); + }, + load: function() + { + var $modal = this.modal.getModal(); - this.modal.createTabber($modal); - this.modal.addTab(1, 'Upload', 'active'); - this.modal.addTab(2, 'Choose'); + this.modal.createTabber($modal); + this.modal.addTab(1, 'Upload', 'active'); + this.modal.addTab(2, 'Choose'); - $('#redactor-modal-image-droparea').addClass('redactor-tab redactor-tab1'); + $('#redactor-modal-image-droparea').addClass('redactor-tab redactor-tab1'); - var $box = $('<div id="redactor-image-manager-box" style="overflow: auto; height: 300px;" class="redactor-tab redactor-tab2">').hide(); - $modal.append($box); + var $box = $('<div id="redactor-image-manager-box" style="overflow: auto; height: 300px;" class="redactor-tab redactor-tab2">').hide(); + $modal.append($box); - $.ajax({ - dataType: "json", - cache: false, - url: this.opts.imageManagerJson, - success: $.proxy(function(data) - { - $.each(data, $.proxy(function(key, val) - { - // title - var thumbtitle = ''; - if (typeof val.title !== 'undefined') thumbtitle = val.title; + $.ajax({ + dataType: "json", + cache: false, + url: this.opts.imageManagerJson, + success: $.proxy(function(data) + { + $.each(data, $.proxy(function(key, val) + { + // title + var thumbtitle = ''; + if (typeof val.title !== 'undefined') thumbtitle = val.title; - var img = $('<img src="' + val.thumb + '" rel="' + val.image + '" title="' + thumbtitle + '" style="width: 100px; height: 75px; cursor: pointer;" />'); - $('#redactor-image-manager-box').append(img); - $(img).click($.proxy(this.imagemanager.insert, this)); + var img = $('<img src="' + val.thumb + '" rel="' + val.image + '" title="' + thumbtitle + '" style="width: 100px; height: 75px; cursor: pointer;" />'); + $('#redactor-image-manager-box').append(img); + $(img).click($.proxy(this.imagemanager.insert, this)); - }, this)); + }, this)); - }, this) - }); + }, this) + }); - }, - insert: function(e) - { - this.image.insert('<img src="' + $(e.target).attr('rel') + '" alt="' + $(e.target).attr('title') + '">'); - } - }; -}; + }, + insert: function(e) + { + this.image.insert('<img src="' + $(e.target).attr('rel') + '" alt="' + $(e.target).attr('title') + '">'); + } + }; + }; +})(jQuery); -RedactorPlugins.table = function() +(function($) { - return { - getTemplate: function() - { - return String() - + '<section id="redactor-modal-table-insert">' - + '<label>' + this.lang.get('rows') + '</label>' - + '<input type="text" size="5" value="2" id="redactor-table-rows" />' - + '<label>' + this.lang.get('columns') + '</label>' - + '<input type="text" size="5" value="3" id="redactor-table-columns" />' - + '</section>'; - }, - init: function() - { + $.Redactor.prototype.table = function() + { + return { + getTemplate: function() + { + return String() + + '<section id="redactor-modal-table-insert">' + + '<label>' + this.lang.get('rows') + '</label>' + + '<input type="text" size="5" value="2" id="redactor-table-rows" />' + + '<label>' + this.lang.get('columns') + '</label>' + + '<input type="text" size="5" value="3" id="redactor-table-columns" />' + + '</section>'; + }, + init: function() + { + var dropdown = {}; + + dropdown.insert_table = { + title: this.lang.get('insert_table'), + func: this.table.show, + observe: { + element: 'table', + in: { + attr: { + 'class': 'redactor-dropdown-link-inactive', + 'aria-disabled': true, + } + } + } + }; + + dropdown.insert_row_above = { + title: this.lang.get('insert_row_above'), + func: this.table.addRowAbove, + observe: { + element: 'table', + out: { + attr: { + 'class': 'redactor-dropdown-link-inactive', + 'aria-disabled': true, + } + } + } + }; + + dropdown.insert_row_below = { + title: this.lang.get('insert_row_below'), + func: this.table.addRowBelow, + observe: { + element: 'table', + out: { + attr: { + 'class': 'redactor-dropdown-link-inactive', + 'aria-disabled': true, + } + } + } + }; + + dropdown.insert_row_below = { + title: this.lang.get('insert_row_below'), + func: this.table.addRowBelow, + observe: { + element: 'table', + out: { + attr: { + 'class': 'redactor-dropdown-link-inactive', + 'aria-disabled': true, + } + } + } + }; + + dropdown.insert_column_left = { + title: this.lang.get('insert_column_left'), + func: this.table.addColumnLeft, + observe: { + element: 'table', + out: { + attr: { + 'class': 'redactor-dropdown-link-inactive', + 'aria-disabled': true, + } + } + } + }; + + dropdown.insert_column_right = { + title: this.lang.get('insert_column_right'), + func: this.table.addColumnRight, + observe: { + element: 'table', + out: { + attr: { + 'class': 'redactor-dropdown-link-inactive', + 'aria-disabled': true, + } + } + } + }; + + dropdown.add_head = { + title: this.lang.get('add_head'), + func: this.table.addHead, + observe: { + element: 'table', + out: { + attr: { + 'class': 'redactor-dropdown-link-inactive', + 'aria-disabled': true, + } + } + } + }; + + dropdown.delete_head = { + title: this.lang.get('delete_head'), + func: this.table.deleteHead, + observe: { + element: 'table', + out: { + attr: { + 'class': 'redactor-dropdown-link-inactive', + 'aria-disabled': true, + } + } + } + }; + + dropdown.delete_column = { + title: this.lang.get('delete_column'), + func: this.table.deleteColumn, + observe: { + element: 'table', + out: { + attr: { + 'class': 'redactor-dropdown-link-inactive', + 'aria-disabled': true, + } + } + } + }; + + dropdown.delete_row = { + title: this.lang.get('delete_row'), + func: this.table.deleteRow, + observe: { + element: 'table', + out: { + attr: { + 'class': 'redactor-dropdown-link-inactive', + 'aria-disabled': true, + } + } + } + }; + + dropdown.delete_row = { + title: this.lang.get('delete_table'), + func: this.table.deleteTable, + observe: { + element: 'table', + out: { + attr: { + 'class': 'redactor-dropdown-link-inactive', + 'aria-disabled': true, + } + } + } + }; + + 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()); - var dropdown = {}; + this.modal.load('table', this.lang.get('insert_table'), 300); + this.modal.createCancelButton(); - 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()); + var button = this.modal.createActionButton(this.lang.get('insert')); + button.on('click', this.table.insert); - this.modal.load('table', this.lang.get('insert_table'), 300); - this.modal.createCancelButton(); + this.selection.save(); + this.modal.show(); - var button = this.modal.createActionButton(this.lang.get('insert')); - button.on('click', this.table.insert); + $('#redactor-table-rows').focus(); - this.selection.save(); - this.modal.show(); + }, + insert: function() + { + this.placeholder.remove(); - $('#redactor-table-rows').focus(); + var rows = $('#redactor-table-rows').val(), + columns = $('#redactor-table-columns').val(), + $tableBox = $('<div>'), + tableId = Math.floor(Math.random() * 99999), + $table = $('<table id="table' + tableId + '"><tbody></tbody></table>'), + i, $row, z, $column; - }, - insert: function() - { + for (i = 0; i < rows; i++) + { + $row = $('<tr>'); - var rows = $('#redactor-table-rows').val(), - columns = $('#redactor-table-columns').val(), - $tableBox = $('<div>'), - tableId = Math.floor(Math.random() * 99999), - $table = $('<table id="table' + tableId + '"><tbody></tbody></table>'), - i, $row, z, $column; + for (z = 0; z < columns; z++) + { + $column = $('<td>' + this.opts.invisibleSpace + '</td>'); - for (i = 0; i < rows; i++) - { - $row = $('<tr>'); + // set the focus to the first td + if (i === 0 && z === 0) + { + $column.append(this.selection.getMarker()); + } - for (z = 0; z < columns; z++) - { - $column = $('<td>' + this.opts.invisibleSpace + '</td>'); + $($row).append($column); + } - // set the focus to the first td - if (i === 0 && z === 0) - { - $column.append(this.selection.getMarker()); - } + $table.append($row); + } - $($row).append($column); - } + $tableBox.append($table); + var html = $tableBox.html(); - $table.append($row); - } + this.modal.close(); + this.selection.restore(); - $tableBox.append($table); - var html = $tableBox.html(); + if (this.table.getTable()) return; + this.buffer.set(); - this.modal.close(); - this.selection.restore(); + 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, false); + } - if (this.table.getTable()) return; + this.selection.restore(); - this.buffer.set(); + var table = this.$editor.find('#table' + tableId); - 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); - } + var p = table.prev("p"); - this.selection.restore(); + if (p.length > 0 && this.utils.isEmpty(p.html())) + { + p.remove(); + } - 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); + } + } - 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(); - this.observe.buttons(); + table.find('span.redactor-selection-marker').remove(); + table.removeAttr('id'); - 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'); - 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; - 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; - 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(); - this.buffer.set(); + var $next = $table.next(); + if (!this.opts.linebreaks && $next.length !== 0) + { + this.caret.setStart($next); + } + else + { + this.caret.setAfter($table); + } - var $next = $table.next(); - if (!this.opts.linebreaks && $next.length !== 0) - { - this.caret.setStart($next); - } - else - { - this.caret.setAfter($table); - } + $table.remove(); - $table.remove(); + this.code.sync(); + }, + deleteRow: function() + { + var $table = this.table.getTable(); + if (!$table) return; - this.code.sync(); - }, - deleteRow: function() - { - var $table = this.table.getTable(); - if (!$table) return; + var $current = $(this.selection.getCurrent()); - var $current = $(this.selection.getCurrent()); + this.buffer.set(); - 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()); + } - 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; - $current_tr.remove(); - this.table.restoreAfterDelete($table); - }, - deleteColumn: function() - { - var $table = this.table.getTable(); - if (!$table) return; + this.buffer.set(); - this.buffer.set(); + var $current = $(this.selection.getCurrent()); + var $current_td = $current.closest('td, th'); + var index = $current_td[0].cellIndex; - 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()); - $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(); - $elem.find('td, th').eq(index).remove(); + }, this)); - }, this)); + this.table.restoreAfterDelete($table); + }, + addHead: function() + { + var $table = this.table.getTable(); + if (!$table) return; - this.table.restoreAfterDelete($table); - }, - addHead: function() - { - var $table = this.table.getTable(); - if (!$table) return; + this.buffer.set(); - this.buffer.set(); + if ($table.find('thead').size() !== 0) + { + this.table.deleteHead(); + return; + } - if ($table.find('thead').size() !== 0) - { - this.table.deleteHead(); - return; - } + var tr = $table.find('tr').first().clone(); + tr.find('td').replaceWith($.proxy(function() + { + return $('<th>').html(this.opts.invisibleSpace); + }, this)); - var tr = $table.find('tr').first().clone(); - tr.find('td').html(this.opts.invisibleSpace); - $thead = $('<thead></thead>').append(tr); - $table.prepend($thead); + $thead = $('<thead></thead>').append(tr); + $table.prepend($thead); - this.code.sync(); + this.code.sync(); - }, - deleteHead: function() - { - var $table = this.table.getTable(); - if (!$table) return; + }, + deleteHead: function() + { + var $table = this.table.getTable(); + if (!$table) return; - var $thead = $table.find('thead'); - if ($thead.size() === 0) return; + var $thead = $table.find('thead'); + if ($thead.size() === 0) return; - this.buffer.set(); + 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; + $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(); + this.buffer.set(); - var $current = $(this.selection.getCurrent()); - var $current_tr = $current.closest('tr'); - var new_tr = $current_tr.clone(); + 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>'); - $td[0].attributes = this.attributes; + new_tr.find('th').replaceWith(function() + { + var $td = $('<td>'); + $td[0].attributes = this.attributes; - return $td.append($(this).contents()); - }); + return $td.append($(this).contents()); + }); - new_tr.find('td').html(this.opts.invisibleSpace); + new_tr.find('td').html(this.opts.invisibleSpace); - if (type == 'after') - { - $current_tr.after(new_tr); - } - else - { - $current_tr.before(new_tr); - } + 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; + this.code.sync(); + }, + addColumn: function (type) + { + var $table = this.table.getTable(); + if (!$table) return; - var index = 0; - var current = $(this.selection.getCurrent()); + var index = 0; + var current = $(this.selection.getCurrent()); - this.buffer.set(); + this.buffer.set(); - var $current_tr = current.closest('tr'); - var $current_td = current.closest('td, th'); + 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; + $current_tr.find('td, th').each($.proxy(function(i, elem) + { + if ($(elem)[0] === $current_td[0]) index = i; - }, this)); + }, this)); - $table.find('tr').each($.proxy(function(i, elem) - { - var $current = $(elem).find('td, th').eq(index); + $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); + var td = $current.clone(); + td.html(this.opts.invisibleSpace); - if (type == 'after') - { - $current.after(td); - } - else - { - $current.before(td); - } + if (type == 'after') + { + $current.after(td); + } + else + { + $current.before(td); + } - }, this)); + }, this)); - this.code.sync(); - } - }; -}; + this.code.sync(); + } + }; + }; +})(jQuery); RedactorPlugins.textdirection = function() { return { @@ -706,74 +870,81 @@ RedactorPlugins.textdirection = function() { }; }; -RedactorPlugins.video = function() +(function($) { - return { - reUrlYoutube: /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w.-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/ig, - reUrlVimeo: /https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/, - getTemplate: function() - { - return String() - + '<section id="redactor-modal-video-insert">' - + '<label>' + this.lang.get('video_html_code') + '</label>' - + '<textarea id="redactor-insert-video-area" style="height: 160px;"></textarea>' - + '</section>'; - }, - init: function() - { - var button = this.button.addAfter('image', 'video', this.lang.get('video')); - this.button.addCallback(button, this.video.show); - }, - show: function() - { - this.modal.addTemplate('video', this.video.getTemplate()); - - this.modal.load('video', this.lang.get('video'), 700); - this.modal.createCancelButton(); - - var button = this.modal.createActionButton(this.lang.get('insert')); - button.on('click', this.video.insert); - - this.selection.save(); - this.modal.show(); - - $('#redactor-insert-video-area').focus(); + $.Redactor.prototype.video = function() + { + return { + reUrlYoutube: /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w.-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/ig, + reUrlVimeo: /https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/, + getTemplate: function() + { + return String() + + '<section id="redactor-modal-video-insert">' + + '<label>' + this.lang.get('video_html_code') + '</label>' + + '<textarea id="redactor-insert-video-area" style="height: 160px;"></textarea>' + + '</section>'; + }, + init: function() + { + var button = this.button.addAfter('image', 'video', this.lang.get('video')); + this.button.addCallback(button, this.video.show); + }, + show: function() + { + this.modal.addTemplate('video', this.video.getTemplate()); - }, - insert: function() - { - var data = $('#redactor-insert-video-area').val(); - data = this.clean.stripTags(data); + this.modal.load('video', this.lang.get('video'), 700); + this.modal.createCancelButton(); - // parse if it is link on youtube & vimeo - var iframeStart = '<iframe style="width: 500px; height: 281px;" src="', - iframeEnd = '" frameborder="0" allowfullscreen></iframe>'; + var button = this.modal.createActionButton(this.lang.get('insert')); + button.on('click', this.video.insert); - if (data.match(this.video.reUrlYoutube)) - { - data = data.replace(this.video.reUrlYoutube, iframeStart + '//www.youtube.com/embed/$1' + iframeEnd); - } - else if (data.match(this.video.reUrlVimeo)) - { - data = data.replace(this.video.reUrlVimeo, iframeStart + '//player.vimeo.com/video/$2' + iframeEnd); - } + this.selection.save(); + this.modal.show(); - this.selection.restore(); - this.modal.close(); + $('#redactor-insert-video-area').focus(); - var current = this.selection.getBlock() || this.selection.getCurrent(); - - if (current) $(current).after(data); - else - { - this.insert.html(data); - } - - this.code.sync(); - } + }, + insert: function() + { + var data = $('#redactor-insert-video-area').val(); + + if (!data.match(/<iframe|<video/gi)) + { + data = this.clean.stripTags(data); + + // parse if it is link on youtube & vimeo + var iframeStart = '<iframe style="width: 500px; height: 281px;" src="', + iframeEnd = '" frameborder="0" allowfullscreen></iframe>'; + + if (data.match(this.video.reUrlYoutube)) + { + data = data.replace(this.video.reUrlYoutube, iframeStart + '//www.youtube.com/embed/$1' + iframeEnd); + } + else if (data.match(this.video.reUrlVimeo)) + { + data = data.replace(this.video.reUrlVimeo, iframeStart + '//player.vimeo.com/video/$2' + iframeEnd); + } + } + + this.selection.restore(); + this.modal.close(); + + var current = this.selection.getBlock() || this.selection.getCurrent(); + + if (current) $(current).after(data); + else + { + this.insert.html(data); + } + + this.code.sync(); + } - }; -}; + }; + }; +})(jQuery); RedactorPlugins.imagepaste = function() { return {