Lot's of bug fixes
This commit is contained in:
parent
ad320963fc
commit
7718ed6c32
196 changed files with 51167 additions and 3010 deletions
105
public/assets/development/plugins/autosave.js
vendored
Normal file
105
public/assets/development/plugins/autosave.js
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
/**
|
||||
* SCEditor AutoSave Plugin
|
||||
* http://www.sceditor.com/
|
||||
*
|
||||
* Copyright (C) 2017, Sam Clarke (samclarke.com)
|
||||
*
|
||||
* SCEditor is licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* @author Sam Clarke
|
||||
*/
|
||||
(function (sceditor) {
|
||||
'use strict';
|
||||
|
||||
var defaultKey = 'sce-autodraft-' + location.pathname + location.search;
|
||||
|
||||
function clear(key) {
|
||||
localStorage.removeItem(key || defaultKey);
|
||||
}
|
||||
|
||||
sceditor.plugins.autosave = function () {
|
||||
var base = this;
|
||||
var editor;
|
||||
var storageKey = defaultKey;
|
||||
// 86400000 = 24 hrs (24 * 60 * 60 * 1000)
|
||||
var expires = 86400000;
|
||||
var saveHandler = function (value) {
|
||||
localStorage.setItem(storageKey, JSON.stringify(value));
|
||||
};
|
||||
var loadHandler = function () {
|
||||
return JSON.parse(localStorage.getItem(storageKey));
|
||||
};
|
||||
|
||||
function gc() {
|
||||
for (var i = 0; i < localStorage.length; i++) {
|
||||
var key = localStorage.key(i);
|
||||
|
||||
if (/^sce\-autodraft\-/.test(key)) {
|
||||
var item = JSON.parse(localStorage.getItem(storageKey));
|
||||
if (item && item.time < Date.now() - expires) {
|
||||
clear(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
base.init = function () {
|
||||
editor = this;
|
||||
var opts = editor.opts && editor.opts.autosave || {};
|
||||
|
||||
saveHandler = opts.save || saveHandler;
|
||||
loadHandler = opts.load || loadHandler;
|
||||
storageKey = opts.storageKey || storageKey;
|
||||
expires = opts.expires || expires;
|
||||
|
||||
gc();
|
||||
};
|
||||
|
||||
base.signalReady = function () {
|
||||
// Add submit event listener to clear autosave
|
||||
var parent = editor.getContentAreaContainer();
|
||||
while (parent) {
|
||||
if (/form/i.test(parent.nodeName)) {
|
||||
parent.addEventListener(
|
||||
'submit', clear.bind(null, storageKey), true
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
parent = parent.parentNode;
|
||||
}
|
||||
|
||||
var state = loadHandler();
|
||||
if (state) {
|
||||
editor.sourceMode(state.sourceMode);
|
||||
editor.val(state.value, false);
|
||||
editor.focus();
|
||||
|
||||
if (state.sourceMode) {
|
||||
editor.sourceEditorCaret(state.caret);
|
||||
} else {
|
||||
editor.getRangeHelper().restoreRange();
|
||||
}
|
||||
}
|
||||
|
||||
saveHandler({
|
||||
caret: this.sourceEditorCaret(),
|
||||
sourceMode: this.sourceMode(),
|
||||
value: editor.val(null, false),
|
||||
time: Date.now()
|
||||
});
|
||||
};
|
||||
|
||||
base.signalValuechangedEvent = function (e) {
|
||||
saveHandler({
|
||||
caret: this.sourceEditorCaret(),
|
||||
sourceMode: this.sourceMode(),
|
||||
value: e.detail.rawValue,
|
||||
time: Date.now()
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
sceditor.plugins.autosave.clear = clear;
|
||||
}(sceditor));
|
94
public/assets/development/plugins/autoyoutube.js
vendored
Normal file
94
public/assets/development/plugins/autoyoutube.js
vendored
Normal file
|
@ -0,0 +1,94 @@
|
|||
/**
|
||||
* SCEditor Auto Youtube Plugin
|
||||
* http://www.sceditor.com/
|
||||
*
|
||||
* Copyright (C) 2016, Sam Clarke (samclarke.com)
|
||||
*
|
||||
* SCEditor is licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* @author Sam Clarke
|
||||
*/
|
||||
(function (document, sceditor) {
|
||||
'use strict';
|
||||
|
||||
var dom = sceditor.dom;
|
||||
|
||||
/*
|
||||
(^|\s) Start of line or space
|
||||
(?:https?:\/\/)? Optional scheme like http://
|
||||
(?:www\.)? Optional www. prefix
|
||||
(?:
|
||||
youtu\.be\/ Ends with .be/ so whatever comes next is the ID
|
||||
|
|
||||
youtube\.com\/watch\?v= Matches the .com version
|
||||
)
|
||||
([^"&?\/ ]{11}) The actual YT ID
|
||||
(?:\&[\&_\?0-9a-z\#]+)? Any extra URL params
|
||||
(\s|$) End of line or space
|
||||
*/
|
||||
var ytUrlRegex = /(^|\s)(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/watch\?v=)([^"&?\/ ]{11})(?:\&[\&_\?0-9a-z\#]+)?(\s|$)/i;
|
||||
|
||||
function youtubeEmbedCode(id) {
|
||||
return '<iframe width="560" height="315" frameborder="0" ' +
|
||||
'src="https://www.youtube-nocookie.com/embed/' + id + '" ' +
|
||||
'data-youtube-id="' + id + '" allowfullscreen></iframe>';
|
||||
}
|
||||
|
||||
function convertYoutubeLinks(root) {
|
||||
var node = root.firstChild;
|
||||
|
||||
while (node) {
|
||||
// 3 is TextNodes
|
||||
if (node.nodeType === 3) {
|
||||
var text = node.nodeValue;
|
||||
var parent = node.parentNode;
|
||||
var match = text.match(ytUrlRegex);
|
||||
|
||||
if (match) {
|
||||
parent.insertBefore(document.createTextNode(
|
||||
text.substr(0, match.index) + match[1]
|
||||
), node);
|
||||
|
||||
parent.insertBefore(
|
||||
dom.parseHTML(youtubeEmbedCode(match[2])), node
|
||||
);
|
||||
|
||||
node.nodeValue = match[3] +
|
||||
text.substr(match.index + match[0].length);
|
||||
}
|
||||
} else {
|
||||
// TODO: Make this tag configurable.
|
||||
if (!dom.is(node, 'code')) {
|
||||
convertYoutubeLinks(node);
|
||||
}
|
||||
}
|
||||
|
||||
node = node.nextSibling;
|
||||
}
|
||||
};
|
||||
|
||||
sceditor.plugins.autoyoutube = function () {
|
||||
this.signalPasteRaw = function (data) {
|
||||
// TODO: Make this tag configurable.
|
||||
// Skip code tags
|
||||
if (dom.closest(this.currentNode(), 'code')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.html || data.text) {
|
||||
var html = document.createElement('div');
|
||||
|
||||
if (data.html) {
|
||||
html.innerHTML = data.html;
|
||||
} else {
|
||||
html.textContent = data.text;
|
||||
}
|
||||
|
||||
convertYoutubeLinks(html);
|
||||
|
||||
data.html = html.innerHTML;
|
||||
}
|
||||
};
|
||||
};
|
||||
})(document, sceditor);
|
222
public/assets/development/plugins/dragdrop.js
vendored
Normal file
222
public/assets/development/plugins/dragdrop.js
vendored
Normal file
|
@ -0,0 +1,222 @@
|
|||
/**
|
||||
* SCEditor Drag and Drop Plugin
|
||||
* http://www.sceditor.com/
|
||||
*
|
||||
* Copyright (C) 2017, Sam Clarke (samclarke.com)
|
||||
*
|
||||
* SCEditor is licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* @author Sam Clarke
|
||||
*/
|
||||
(function (sceditor) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Place holder GIF shown while image is loading.
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
var loadingGif = 'data:image/gif;base64,R0lGODlhlgBkAPABAH19ffb29iH5BAAK' +
|
||||
'AAAAIf4aQ3JlYXRlZCB3aXRoIGFqYXhsb2FkLmluZm8AIf8LTkVUU0NBUEUyLjADAQA' +
|
||||
'AACwAAAAAlgBkAAAC1YyPqcvtD6OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s' +
|
||||
'73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5LL5jE6r1+y2+w2Py+f0u' +
|
||||
'v2OvwD2fP6iD/gH6Pc2GIhg2JeQSNjGuLf4GMlYKIloefAIUEl52ZmJyaY5mUhqyFnq' +
|
||||
'mQr6KRoaMKp66hbLumpQ69oK+5qrOyg4a6qYV2x8jJysvMzc7PwMHS09TV1tfY2drb3' +
|
||||
'N3e39DR4uPk5ebn6Onq6+zt7u/g4fL99UAAAh+QQACgAAACwAAAAAlgBkAIEAAAB9fX' +
|
||||
'329vYAAAAC3JSPqcvtD6OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MC' +
|
||||
'ofEovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5LL5jE6r1+y2+w2Py+f0uv2OvwD2' +
|
||||
'fP4iABgY+CcoCNeHuJdQyLjIaOiWiOj4CEhZ+SbZd/nI2RipqYhQOThKGpAZCuBZyAr' +
|
||||
'ZprpqSupaCqtaazmLCRqai7rb2av5W5wqSShcm8fc7PwMHS09TV1tfY2drb3N3e39DR' +
|
||||
'4uPk5ebn6Onq6+zt7u/g4fLz9PX29/j5/vVAAAIfkEAAoAAAAsAAAAAJYAZACBAAAAf' +
|
||||
'X199vb2AAAAAuCUj6nL7Q+jnLTai7PevPsPhuJIluaJpurKtu4Lx/JM1/aN5/rO9/4P' +
|
||||
'DAqHxKLxiEwql8ym8wmNSqfUqvWKzWq33K73Cw6Lx+Sy+YxOq9fstvsNj8vn9Lr9jr8' +
|
||||
'E9nz+AgAYGLjQVwhXiJgguAiYgGjo9tinyCjoKLn3hpmJUGmJsBmguUnpCXCJOZraaX' +
|
||||
'oKShoJe9DqehCqKlnqiZobuzrbyvuIO8xqKpxIPKlwrPCbBx0tPU1dbX2Nna29zd3t/' +
|
||||
'Q0eLj5OXm5+jp6uvs7e7v4OHy8/T19vf4+fr7/P379UAAAh+QQACgAAACwAAAAAlgBk' +
|
||||
'AIEAAAB9fX329vYAAAAC4JSPqcvtD6OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3' +
|
||||
'n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5LL5jE6r1+y2+w2Py+' +
|
||||
'f0uv2OvwT2fP6iD7gAMEhICAeImIAYiFDoOPi22KcouZfw6BhZGUBZeYlp6LbJiTD6C' +
|
||||
'Qqg6Vm6eQqqKtkZ24iaKtrKunpQa9tmmju7Wwu7KFtMi3oYDMzompkHHS09TV1tfY2d' +
|
||||
'rb3N3e39DR4uPk5ebn6Onq6+zt7u/g4fLz9PX29/j5+vv8/f31QAADs=';
|
||||
|
||||
/**
|
||||
* Basic check for browser support
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
var isSupported = typeof window.FileReader !== 'undefined';
|
||||
var base64DataUri = /data:[^;]+;base64,/i;
|
||||
|
||||
function base64DataUriToBlob(url) {
|
||||
// 5 is length of "data:" prefix
|
||||
var mime = url.substr(5, url.indexOf(';') - 5);
|
||||
var data = atob(url.substr(url.indexOf(',') + 1));
|
||||
/* global Uint8Array */
|
||||
var binary = new Uint8Array(data.length);
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
binary[i] = data[i].charCodeAt(0);
|
||||
}
|
||||
|
||||
try {
|
||||
return new Blob([binary], { type: mime });
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
sceditor.plugins.dragdrop = function () {
|
||||
if (!isSupported) {
|
||||
return;
|
||||
}
|
||||
|
||||
var base = this;
|
||||
var opts;
|
||||
var editor;
|
||||
var handleFile;
|
||||
var container;
|
||||
var cover;
|
||||
var placeholderId = 0;
|
||||
|
||||
|
||||
function hideCover() {
|
||||
cover.style.display = 'none';
|
||||
container.className = container.className.replace(/(^| )dnd( |$)/g, '');
|
||||
}
|
||||
|
||||
function showCover() {
|
||||
if (cover.style.display === 'none') {
|
||||
cover.style.display = 'block';
|
||||
container.className += ' dnd';
|
||||
}
|
||||
}
|
||||
|
||||
function isAllowed(file) {
|
||||
// FF sets type to application/x-moz-file until it has been dropped
|
||||
if (file.type !== 'application/x-moz-file' && opts.allowedTypes &&
|
||||
opts.allowedTypes.indexOf(file.type) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return opts.isAllowed ? opts.isAllowed(file) : true;
|
||||
};
|
||||
|
||||
function createHolder(toReplace) {
|
||||
var placeholder = document.createElement('img');
|
||||
placeholder.src = loadingGif;
|
||||
placeholder.className = 'sceditor-ignore';
|
||||
placeholder.id = 'sce-dragdrop-' + placeholderId++;
|
||||
|
||||
function replace(html) {
|
||||
var node = editor
|
||||
.getBody()
|
||||
.ownerDocument
|
||||
.getElementById(placeholder.id);
|
||||
|
||||
if (node) {
|
||||
if (typeof html === 'string') {
|
||||
node.insertAdjacentHTML('afterend', html);
|
||||
}
|
||||
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
return function () {
|
||||
if (toReplace) {
|
||||
toReplace.parentNode.replaceChild(placeholder, toReplace);
|
||||
} else {
|
||||
editor.wysiwygEditorInsertHtml(placeholder.outerHTML);
|
||||
}
|
||||
|
||||
return {
|
||||
insert: function (html) {
|
||||
replace(html);
|
||||
},
|
||||
cancel: replace
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function handleDragOver(e) {
|
||||
var dt = e.dataTransfer;
|
||||
var files = dt.files.length || !dt.items ? dt.files : dt.items;
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
// Dragging a string should be left to default
|
||||
if (files[i].kind === 'string') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
showCover();
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
function handleDrop(e) {
|
||||
var dt = e.dataTransfer;
|
||||
var files = dt.files.length || !dt.items ? dt.files : dt.items;
|
||||
|
||||
hideCover();
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
// Dragging a string should be left to default
|
||||
if (files[i].kind === 'string') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAllowed(files[i])) {
|
||||
handleFile(files[i], createHolder());
|
||||
}
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
base.signalReady = function () {
|
||||
editor = this;
|
||||
opts = editor.opts.dragdrop || {};
|
||||
handleFile = opts.handleFile;
|
||||
|
||||
container = editor.getContentAreaContainer().parentNode;
|
||||
|
||||
cover = container.appendChild(sceditor.dom.parseHTML(
|
||||
'<div class="sceditor-dnd-cover" style="display: none">' +
|
||||
'<p>' + editor._('Drop files here') + '</p>' +
|
||||
'</div>'
|
||||
).firstChild);
|
||||
|
||||
container.addEventListener('dragover', handleDragOver);
|
||||
container.addEventListener('dragleave', hideCover);
|
||||
container.addEventListener('dragend', hideCover);
|
||||
container.addEventListener('drop', handleDrop);
|
||||
|
||||
editor.getBody().addEventListener('dragover', handleDragOver);
|
||||
editor.getBody().addEventListener('drop', hideCover);
|
||||
};
|
||||
|
||||
base.signalPasteHtml = function (paste) {
|
||||
if (!('handlePaste' in opts) || opts.handlePaste) {
|
||||
var div = document.createElement('div');
|
||||
div.innerHTML = paste.val;
|
||||
|
||||
var images = div.querySelectorAll('img');
|
||||
for (var i = 0; i < images.length; i++) {
|
||||
var image = images[i];
|
||||
|
||||
if (base64DataUri.test(image.src)) {
|
||||
var file = base64DataUriToBlob(image.src);
|
||||
if (file && isAllowed(file)) {
|
||||
handleFile(file, createHolder(image));
|
||||
} else {
|
||||
image.parentNode.removeChild(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
paste.val = div.innerHTML;
|
||||
}
|
||||
};
|
||||
};
|
||||
})(sceditor);
|
127
public/assets/development/plugins/format.js
vendored
Normal file
127
public/assets/development/plugins/format.js
vendored
Normal file
|
@ -0,0 +1,127 @@
|
|||
/**
|
||||
* SCEditor Paragraph Formatting Plugin
|
||||
* http://www.sceditor.com/
|
||||
*
|
||||
* Copyright (C) 2011-2013, Sam Clarke (samclarke.com)
|
||||
*
|
||||
* SCEditor is licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* @fileoverview SCEditor Paragraph Formatting Plugin
|
||||
* @author Sam Clarke
|
||||
*/
|
||||
(function (sceditor) {
|
||||
'use strict';
|
||||
|
||||
sceditor.plugins.format = function () {
|
||||
var base = this;
|
||||
|
||||
/**
|
||||
* Default tags
|
||||
* @type {Object}
|
||||
* @private
|
||||
*/
|
||||
var tags = {
|
||||
p: 'Paragraph',
|
||||
h1: 'Heading 1',
|
||||
h2: 'Heading 2',
|
||||
h3: 'Heading 3',
|
||||
h4: 'Heading 4',
|
||||
h5: 'Heading 5',
|
||||
h6: 'Heading 6',
|
||||
address: 'Address',
|
||||
pre: 'Preformatted Text'
|
||||
};
|
||||
|
||||
/**
|
||||
* Private functions
|
||||
* @private
|
||||
*/
|
||||
var insertTag,
|
||||
formatCmd;
|
||||
|
||||
|
||||
base.init = function () {
|
||||
var opts = this.opts,
|
||||
pOpts = opts.paragraphformat;
|
||||
|
||||
// Don't enable if the BBCode plugin is enabled.
|
||||
if (opts.format && opts.format === 'bbcode') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pOpts) {
|
||||
if (pOpts.tags) {
|
||||
tags = pOpts.tags;
|
||||
}
|
||||
|
||||
if (pOpts.excludeTags) {
|
||||
pOpts.excludeTags.forEach(function (val) {
|
||||
delete tags[val];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.commands.format) {
|
||||
this.commands.format = {
|
||||
exec: formatCmd,
|
||||
txtExec: formatCmd,
|
||||
tooltip: 'Format Paragraph'
|
||||
};
|
||||
}
|
||||
|
||||
if (opts.toolbar === sceditor.defaultOptions.toolbar) {
|
||||
opts.toolbar = opts.toolbar.replace(',color,',
|
||||
',color,format,');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Inserts the specified tag into the editor
|
||||
*
|
||||
* @param {sceditor} editor
|
||||
* @param {string} tag
|
||||
* @private
|
||||
*/
|
||||
insertTag = function (editor, tag) {
|
||||
if (editor.sourceMode()) {
|
||||
editor.insert('<' + tag + '>', '</' + tag + '>');
|
||||
} else {
|
||||
editor.execCommand('formatblock', '<' + tag + '>');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Function for the exec and txtExec properties
|
||||
*
|
||||
* @param {node} caller
|
||||
* @private
|
||||
*/
|
||||
formatCmd = function (caller) {
|
||||
var editor = this,
|
||||
content = document.createElement('div');
|
||||
|
||||
sceditor.utils.each(tags, function (tag, val) {
|
||||
var link = document.createElement('a');
|
||||
link.className = 'sceditor-option';
|
||||
link.textContent = val.name || val;
|
||||
link.addEventListener('click', function (e) {
|
||||
editor.closeDropDown(true);
|
||||
|
||||
if (val.exec) {
|
||||
val.exec(editor);
|
||||
} else {
|
||||
insertTag(editor, tag);
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
content.appendChild(link);
|
||||
});
|
||||
|
||||
editor.createDropDown(caller, 'format', content);
|
||||
};
|
||||
};
|
||||
})(sceditor);
|
59
public/assets/development/plugins/plaintext.js
vendored
Normal file
59
public/assets/development/plugins/plaintext.js
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* SCEditor Plain Text Plugin
|
||||
* http://www.sceditor.com/
|
||||
*
|
||||
* Copyright (C) 2016, Sam Clarke (samclarke.com)
|
||||
*
|
||||
* SCEditor is licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* @author Sam Clarke
|
||||
*/
|
||||
(function (sceditor) {
|
||||
'use strict';
|
||||
|
||||
var extend = sceditor.utils.extend;
|
||||
|
||||
/**
|
||||
* Options:
|
||||
*
|
||||
* pastetext.addButton - If to replace the plaintext button with a toggle
|
||||
* button that enables and disables plain text mode.
|
||||
*
|
||||
* pastetext.enabled - If the plain text button should be enabled at start
|
||||
* up. Only applies if addButton is enabled.
|
||||
*/
|
||||
sceditor.plugins.plaintext = function () {
|
||||
var plainTextEnabled = true;
|
||||
|
||||
this.init = function () {
|
||||
var commands = this.commands;
|
||||
var opts = this.opts;
|
||||
|
||||
if (opts && opts.plaintext && opts.plaintext.addButton) {
|
||||
plainTextEnabled = opts.plaintext.enabled;
|
||||
|
||||
commands.pastetext = extend(commands.pastetext || {}, {
|
||||
state: function () {
|
||||
return plainTextEnabled ? 1 : 0;
|
||||
},
|
||||
exec: function () {
|
||||
plainTextEnabled = !plainTextEnabled;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.signalPasteRaw = function (data) {
|
||||
if (plainTextEnabled) {
|
||||
if (data.html && !data.text) {
|
||||
var div = document.createElement('div');
|
||||
div.innerHTML = data.html;
|
||||
data.text = div.innerText;
|
||||
}
|
||||
|
||||
data.html = null;
|
||||
}
|
||||
};
|
||||
};
|
||||
}(sceditor));
|
21
public/assets/development/plugins/strictbbcode.js
vendored
Normal file
21
public/assets/development/plugins/strictbbcode.js
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* SCEditor Strict BBCode Plugin
|
||||
* http://www.sceditor.com/
|
||||
*
|
||||
* Copyright (C) 2016, Sam Clarke (samclarke.com)
|
||||
*
|
||||
* SCEditor is licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* @author Sam Clarke
|
||||
*/
|
||||
// (function (sceditor) {
|
||||
// 'use strict';
|
||||
|
||||
// // var extend = sceditor.utils.extend;
|
||||
|
||||
// sceditor.plugins.strictbbcode = function () {
|
||||
// // override bbcode plugin add and update default bbcodes to have attrs
|
||||
// // and override their exec funcs
|
||||
// };
|
||||
// }(sceditor));
|
187
public/assets/development/plugins/undo.js
vendored
Normal file
187
public/assets/development/plugins/undo.js
vendored
Normal file
|
@ -0,0 +1,187 @@
|
|||
(function (sceditor) {
|
||||
'use strict';
|
||||
|
||||
sceditor.plugins.undo = function () {
|
||||
var base = this;
|
||||
var editor;
|
||||
var charChangedCount = 0;
|
||||
var previousValue;
|
||||
|
||||
var undoLimit = 50;
|
||||
var redoStates = [];
|
||||
var undoStates = [];
|
||||
var ignoreNextValueChanged = false;
|
||||
|
||||
/**
|
||||
* Sets the editor to the specified state.
|
||||
*
|
||||
* @param {Object} state
|
||||
* @private
|
||||
*/
|
||||
var applyState = function (state) {
|
||||
ignoreNextValueChanged = true;
|
||||
|
||||
previousValue = state.value;
|
||||
|
||||
editor.sourceMode(state.sourceMode);
|
||||
editor.val(state.value, false);
|
||||
editor.focus();
|
||||
|
||||
if (state.sourceMode) {
|
||||
editor.sourceEditorCaret(state.caret);
|
||||
} else {
|
||||
editor.getRangeHelper().restoreRange();
|
||||
}
|
||||
|
||||
ignoreNextValueChanged = false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the number of characters that have changed
|
||||
* between two strings.
|
||||
*
|
||||
* @param {String} strA
|
||||
* @param {String} strB
|
||||
* @return {String}
|
||||
* @private
|
||||
*/
|
||||
var simpleDiff = function (strA, strB) {
|
||||
var start, end, aLenDiff, bLenDiff,
|
||||
aLength = strA.length,
|
||||
bLength = strB.length,
|
||||
length = Math.max(aLength, bLength);
|
||||
|
||||
// Calculate the start
|
||||
for (start = 0; start < length; start++) {
|
||||
if (strA.charAt(start) !== strB.charAt(start)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the end
|
||||
aLenDiff = aLength < bLength ? bLength - aLength : 0;
|
||||
bLenDiff = bLength < aLength ? aLength - bLength : 0;
|
||||
|
||||
for (end = length - 1; end >= 0; end--) {
|
||||
if (strA.charAt(end - aLenDiff) !==
|
||||
strB.charAt(end - bLenDiff)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (end - start) + 1;
|
||||
};
|
||||
|
||||
base.init = function () {
|
||||
// The this variable will be set to the instance of the editor
|
||||
// calling it, hence why the plugins "this" is saved to the base
|
||||
// variable.
|
||||
editor = this;
|
||||
|
||||
undoLimit = editor.undoLimit || undoLimit;
|
||||
|
||||
// addShortcut is the easiest way to add handlers to specific
|
||||
// shortcuts
|
||||
editor.addShortcut('ctrl+z', base.undo);
|
||||
editor.addShortcut('ctrl+shift+z', base.redo);
|
||||
editor.addShortcut('ctrl+y', base.redo);
|
||||
};
|
||||
|
||||
base.undo = function () {
|
||||
var state = undoStates.pop();
|
||||
var rawEditorValue = editor.val(null, false);
|
||||
|
||||
if (state && !redoStates.length && rawEditorValue === state.value) {
|
||||
state = undoStates.pop();
|
||||
}
|
||||
|
||||
if (state) {
|
||||
if (!redoStates.length) {
|
||||
redoStates.push({
|
||||
'caret': editor.sourceEditorCaret(),
|
||||
'sourceMode': editor.sourceMode(),
|
||||
'value': rawEditorValue
|
||||
});
|
||||
}
|
||||
|
||||
redoStates.push(state);
|
||||
applyState(state);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
base.redo = function () {
|
||||
var state = redoStates.pop();
|
||||
|
||||
if (!undoStates.length) {
|
||||
undoStates.push(state);
|
||||
state = redoStates.pop();
|
||||
}
|
||||
|
||||
if (state) {
|
||||
undoStates.push(state);
|
||||
applyState(state);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
base.signalReady = function () {
|
||||
var rawValue = editor.val(null, false);
|
||||
|
||||
// Store the initial value as the last value
|
||||
previousValue = rawValue;
|
||||
|
||||
undoStates.push({
|
||||
'caret': this.sourceEditorCaret(),
|
||||
'sourceMode': this.sourceMode(),
|
||||
'value': rawValue
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle the valueChanged signal.
|
||||
*
|
||||
* e.rawValue will either be the raw HTML from the WYSIWYG editor with
|
||||
* the rangeHelper range markers inserted, or it will be the raw value
|
||||
* of the source editor (BBCode or HTML depending on plugins).
|
||||
* @return {void}
|
||||
*/
|
||||
base.signalValuechangedEvent = function (e) {
|
||||
var rawValue = e.detail.rawValue;
|
||||
|
||||
if (undoLimit > 0 && undoStates.length > undoLimit) {
|
||||
undoStates.shift();
|
||||
}
|
||||
|
||||
// If the editor hasn't fully loaded yet,
|
||||
// then the previous value won't be set.
|
||||
if (ignoreNextValueChanged || !previousValue ||
|
||||
previousValue === rawValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Value has changed so remove all redo states
|
||||
redoStates.length = 0;
|
||||
charChangedCount += simpleDiff(previousValue, rawValue);
|
||||
|
||||
if (charChangedCount < 20) {
|
||||
return;
|
||||
// ??
|
||||
} else if (charChangedCount < 50 && !/\s$/g.test(e.rawValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
undoStates.push({
|
||||
'caret': editor.sourceEditorCaret(),
|
||||
'sourceMode': editor.sourceMode(),
|
||||
'value': rawValue
|
||||
});
|
||||
|
||||
charChangedCount = 0;
|
||||
previousValue = rawValue;
|
||||
};
|
||||
};
|
||||
}(sceditor));
|
97
public/assets/development/plugins/v1compat.js
vendored
Normal file
97
public/assets/development/plugins/v1compat.js
vendored
Normal file
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
* Version 1 compatibility plugin
|
||||
*
|
||||
* Patches commands and BBCodes set with
|
||||
* command.set and bbcode.set to wrap DOM
|
||||
* node arguments in jQuery objects.
|
||||
*
|
||||
* Should only be used to ease migrating.
|
||||
*/
|
||||
(function (sceditor, $) {
|
||||
'use strict';
|
||||
|
||||
var plugins = sceditor.plugins;
|
||||
|
||||
/**
|
||||
* Patches a method to wrap and DOM nodes in a jQuery object
|
||||
* @private
|
||||
*/
|
||||
function patchMethodArguments(fn) {
|
||||
if (fn._scePatched) {
|
||||
return fn;
|
||||
}
|
||||
|
||||
var patch = function () {
|
||||
var args = [];
|
||||
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var arg = arguments[i];
|
||||
|
||||
if (arg && arg.nodeType) {
|
||||
args.push($(arg));
|
||||
} else {
|
||||
args.push(arg);
|
||||
}
|
||||
}
|
||||
|
||||
return fn.apply(this, args);
|
||||
};
|
||||
|
||||
patch._scePatched = true;
|
||||
return patch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Patches a method to wrap any return value in a jQuery object
|
||||
* @private
|
||||
*/
|
||||
function patchMethodReturn(fn) {
|
||||
if (fn._scePatched) {
|
||||
return fn;
|
||||
}
|
||||
|
||||
var patch = function () {
|
||||
return $(fn.apply(this, arguments));
|
||||
};
|
||||
|
||||
patch._scePatched = true;
|
||||
return patch;
|
||||
}
|
||||
|
||||
var oldSet = sceditor.command.set;
|
||||
sceditor.command.set = function (name, cmd) {
|
||||
if (cmd && typeof cmd.exec === 'function') {
|
||||
cmd.exec = patchMethodArguments(cmd.exec);
|
||||
}
|
||||
|
||||
if (cmd && typeof cmd.txtExec === 'function') {
|
||||
cmd.txtExec = patchMethodArguments(cmd.txtExec);
|
||||
}
|
||||
|
||||
return oldSet.call(this, name, cmd);
|
||||
};
|
||||
|
||||
if (plugins.bbcode) {
|
||||
var oldBBCodeSet = plugins.bbcode.bbcode.set;
|
||||
plugins.bbcode.bbcode.set = function (name, bbcode) {
|
||||
if (bbcode && typeof bbcode.format === 'function') {
|
||||
bbcode.format = patchMethodArguments(bbcode.format);
|
||||
}
|
||||
|
||||
return oldBBCodeSet.call(this, name, bbcode);
|
||||
};
|
||||
};
|
||||
|
||||
var oldCreate = sceditor.create;
|
||||
sceditor.create = function (textarea, options) {
|
||||
oldCreate.call(this, textarea, options);
|
||||
|
||||
if (textarea && textarea._sceditor) {
|
||||
var editor = textarea._sceditor;
|
||||
|
||||
editor.getBody = patchMethodReturn(editor.getBody);
|
||||
editor.getContentAreaContainer =
|
||||
patchMethodReturn(editor.getContentAreaContainer);
|
||||
}
|
||||
};
|
||||
}(sceditor, jQuery));
|
Reference in a new issue