mirror of
https://github.com/codex-team/editor.js
synced 2024-05-11 19:07:11 +02:00
Destroy module (#157)
* listeners module added
* Destroy method added
* Destroy method for plugins added
* Delete plugins properties from window obj
* Revert "Delete plugins properties from window obj"
This reverts commit 6c91f81229
.
* Twitter and instagram api's destroy
* Scripts destoy added
* Fix
* Replace regex with String.indexOf
* Settings for destroyer
This commit is contained in:
parent
e28349d3fb
commit
d2e755086a
|
@ -70,7 +70,8 @@
|
|||
"MutationObserver": true,
|
||||
"FormData": true,
|
||||
"XMLHttpRequest": true,
|
||||
"ActiveXObject": true
|
||||
"ActiveXObject": true,
|
||||
"RegExp": true
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
3
codex.js
3
codex.js
|
@ -10,6 +10,7 @@ module.exports = (function (editor) {
|
|||
'use strict';
|
||||
|
||||
editor.version = VERSION;
|
||||
editor.scriptPrefix = 'cdx-script-';
|
||||
|
||||
var init = function () {
|
||||
|
||||
|
@ -28,6 +29,8 @@ module.exports = (function (editor) {
|
|||
editor.parser = require('./modules/parser');
|
||||
editor.sanitizer = require('./modules/sanitizer');
|
||||
editor.anchors = require('./modules/anchors');
|
||||
editor.listeners = require('./modules/listeners');
|
||||
editor.destroyer = require('./modules/destroyer');
|
||||
editor.paste = require('./modules/paste');
|
||||
|
||||
};
|
||||
|
|
10
example.html
10
example.html
|
@ -62,6 +62,7 @@
|
|||
render: paragraph.render,
|
||||
validate: paragraph.validate,
|
||||
save: paragraph.save,
|
||||
destroy: paragraph.destroy,
|
||||
allowedToPaste: true,
|
||||
showInlineToolbar: true,
|
||||
allowRenderOnPaste: true
|
||||
|
@ -74,6 +75,7 @@
|
|||
render: header.render,
|
||||
validate: header.validate,
|
||||
save: header.save,
|
||||
destroy: header.destroy,
|
||||
displayInToolbox: true
|
||||
},
|
||||
code: {
|
||||
|
@ -85,6 +87,7 @@
|
|||
render: code.render,
|
||||
validate: code.validate,
|
||||
save: code.save,
|
||||
destroy: code.destroy,
|
||||
displayInToolbox: true,
|
||||
enableLineBreaks: true
|
||||
},
|
||||
|
@ -97,6 +100,7 @@
|
|||
render: link.render,
|
||||
validate: link.validate,
|
||||
save: link.save,
|
||||
destroy: link.destroy,
|
||||
displayInToolbox: true,
|
||||
enableLineBreaks: true
|
||||
},
|
||||
|
@ -109,6 +113,7 @@
|
|||
render: list.render,
|
||||
validate: list.validate,
|
||||
save: list.save,
|
||||
destroy: list.destroy,
|
||||
displayInToolbox: true,
|
||||
showInlineToolbar: true,
|
||||
enableLineBreaks: true,
|
||||
|
@ -122,6 +127,7 @@
|
|||
render: quote.render,
|
||||
validate: quote.validate,
|
||||
save: quote.save,
|
||||
destroy: quote.destroy,
|
||||
displayInToolbox: true,
|
||||
enableLineBreaks: true,
|
||||
showInlineToolbar: true,
|
||||
|
@ -138,6 +144,7 @@
|
|||
makeSettings: image.makeSettings,
|
||||
render: image.render,
|
||||
save: image.save,
|
||||
destroy: image.destroy,
|
||||
isStretched: true,
|
||||
showInlineToolbar: true,
|
||||
displayInToolbox: true,
|
||||
|
@ -153,6 +160,7 @@
|
|||
render: instagram.reneder,
|
||||
validate: instagram.validate,
|
||||
save: instagram.save,
|
||||
destroy: instagram.destroy,
|
||||
renderOnPastePatterns: instagram.pastePatterns,
|
||||
},
|
||||
tweet: {
|
||||
|
@ -162,6 +170,7 @@
|
|||
render: twitter.render,
|
||||
validate: twitter.validate,
|
||||
save: twitter.save,
|
||||
destroy: twitter.destroy,
|
||||
showInlineToolbar : true,
|
||||
renderOnPastePatterns: twitter.pastePatterns,
|
||||
config : {
|
||||
|
@ -173,6 +182,7 @@
|
|||
make: embed.make,
|
||||
render: embed.render,
|
||||
save: embed.save,
|
||||
destroy: embed.destroy,
|
||||
validate: embed.validate,
|
||||
renderOnPastePatterns: embed.pastePatterns,
|
||||
}
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
* @author Codex Team
|
||||
* @version 1.3.7
|
||||
*/
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (callbacks) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
callbacks.globalKeydown = function (event) {
|
||||
|
||||
switch (event.keyCode) {
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
* @author Codex Team
|
||||
* @version 1.0
|
||||
*/
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (caret) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
/**
|
||||
* @var {int} InputIndex - editable element in DOM
|
||||
*/
|
||||
|
|
|
@ -5,10 +5,11 @@
|
|||
* @author Codex Team
|
||||
* @version 1.3.11
|
||||
*/
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (content) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
/**
|
||||
* Links to current active block
|
||||
* @type {null | Element}
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
* @version 1.1.2
|
||||
*/
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (core) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
|
@ -215,8 +215,6 @@ module.exports = (function (core) {
|
|||
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
const instancePrefix = 'cdx-script-';
|
||||
|
||||
let script;
|
||||
|
||||
/** Script is already loaded */
|
||||
|
@ -224,7 +222,7 @@ module.exports = (function (core) {
|
|||
|
||||
reject('Instance name is missed');
|
||||
|
||||
} else if ( document.getElementById(instancePrefix + instanceName) ) {
|
||||
} else if ( document.getElementById(editor.scriptPrefix + instanceName) ) {
|
||||
|
||||
resolve(scriptPath);
|
||||
|
||||
|
@ -233,7 +231,7 @@ module.exports = (function (core) {
|
|||
script = document.createElement('SCRIPT');
|
||||
script.async = true;
|
||||
script.defer = true;
|
||||
script.id = instancePrefix + instanceName;
|
||||
script.id = editor.scriptPrefix + instanceName;
|
||||
|
||||
script.onload = function () {
|
||||
|
||||
|
|
98
modules/destroyer.js
Normal file
98
modules/destroyer.js
Normal file
|
@ -0,0 +1,98 @@
|
|||
/**
|
||||
* Codex Editor Destroyer module
|
||||
*
|
||||
* @auhor Codex Team
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
module.exports = function (destroyer) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
destroyer.removeNodes = function () {
|
||||
|
||||
editor.nodes.wrapper.remove();
|
||||
editor.nodes.notifications.remove();
|
||||
|
||||
};
|
||||
|
||||
destroyer.destroyPlugins = function () {
|
||||
|
||||
for (var tool in editor.tools) {
|
||||
|
||||
if (typeof editor.tools[tool].destroy === 'function') {
|
||||
|
||||
editor.tools[tool].destroy();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
destroyer.destroyScripts = function () {
|
||||
|
||||
var scripts = document.getElementsByTagName('SCRIPT');
|
||||
|
||||
for (var i = 0; i < scripts.length; i++) {
|
||||
|
||||
if (scripts[i].id.indexOf(editor.scriptPrefix) + 1) {
|
||||
|
||||
scripts[i].remove();
|
||||
i--;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Delete editor data from webpage.
|
||||
* You should send settings argument with boolean flags:
|
||||
* @param settings.ui- remove redactor event listeners and DOM nodes
|
||||
* @param settings.scripts - remove redactor scripts from DOM
|
||||
* @param settings.plugins - remove plugin's objects
|
||||
* @param settings.core - remove editor core. You can remove core only if UI and scripts flags is true
|
||||
* }
|
||||
*
|
||||
*/
|
||||
destroyer.destroy = function (settings) {
|
||||
|
||||
if (!settings || typeof settings !== 'object') {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (settings.ui) {
|
||||
|
||||
destroyer.removeNodes();
|
||||
editor.listeners.removeAll();
|
||||
|
||||
}
|
||||
|
||||
if (settings.scripts) {
|
||||
|
||||
destroyer.destroyScripts();
|
||||
|
||||
}
|
||||
|
||||
if (settings.plugins) {
|
||||
|
||||
destroyer.destroyPlugins();
|
||||
|
||||
}
|
||||
|
||||
if (settings.ui && settings.scripts && settings.core) {
|
||||
|
||||
delete codex.editor;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return destroyer;
|
||||
|
||||
}({});
|
192
modules/listeners.js
Normal file
192
modules/listeners.js
Normal file
|
@ -0,0 +1,192 @@
|
|||
/**
|
||||
* Codex Editor Listeners module
|
||||
*
|
||||
* @author Codex Team
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module-decorator for event listeners assignment
|
||||
*/
|
||||
module.exports = function (listeners) {
|
||||
|
||||
var allListeners = [];
|
||||
|
||||
/**
|
||||
* Search methods
|
||||
*
|
||||
* byElement, byType and byHandler returns array of suitable listeners
|
||||
* one and all takes element, eventType, and handler and returns first (all) suitable listener
|
||||
*
|
||||
*/
|
||||
listeners.search = function () {
|
||||
|
||||
var byElement = function (element, context) {
|
||||
|
||||
var listenersOnElement = [];
|
||||
|
||||
context = context || allListeners;
|
||||
|
||||
for (var i = 0; i < context.length; i++) {
|
||||
|
||||
var listener = context[i];
|
||||
|
||||
if (listener.element === element) {
|
||||
|
||||
listenersOnElement.push(listener);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return listenersOnElement;
|
||||
|
||||
};
|
||||
|
||||
var byType = function (eventType, context) {
|
||||
|
||||
var listenersWithType = [];
|
||||
|
||||
context = context || allListeners;
|
||||
|
||||
for (var i = 0; i < context.length; i++) {
|
||||
|
||||
var listener = context[i];
|
||||
|
||||
if (listener.type === eventType) {
|
||||
|
||||
listenersWithType.push(listener);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return listenersWithType;
|
||||
|
||||
};
|
||||
|
||||
var byHandler = function (handler, context) {
|
||||
|
||||
var listenersWithHandler = [];
|
||||
|
||||
context = context || allListeners;
|
||||
|
||||
for (var i = 0; i < context.length; i++) {
|
||||
|
||||
var listener = context[i];
|
||||
|
||||
if (listener.handler === handler) {
|
||||
|
||||
listenersWithHandler.push(listener);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return listenersWithHandler;
|
||||
|
||||
};
|
||||
|
||||
var one = function (element, eventType, handler) {
|
||||
|
||||
var result = allListeners;
|
||||
|
||||
if (element)
|
||||
result = byElement(element, result);
|
||||
|
||||
if (eventType)
|
||||
result = byType(eventType, result);
|
||||
|
||||
if (handler)
|
||||
result = byHandler(handler, result);
|
||||
|
||||
return result[0];
|
||||
|
||||
};
|
||||
|
||||
var all = function (element, eventType, handler) {
|
||||
|
||||
var result = allListeners;
|
||||
|
||||
if (element)
|
||||
result = byElement(element, result);
|
||||
|
||||
if (eventType)
|
||||
result = byType(eventType, result);
|
||||
|
||||
if (handler)
|
||||
result = byHandler(handler, result);
|
||||
|
||||
return result;
|
||||
|
||||
};
|
||||
|
||||
return {
|
||||
byElement : byElement,
|
||||
byType : byType,
|
||||
byHandler : byHandler,
|
||||
one : one,
|
||||
all : all
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
listeners.add = function (element, eventType, handler, isCapture) {
|
||||
|
||||
element.addEventListener(eventType, handler, isCapture);
|
||||
|
||||
var data = {
|
||||
element: element,
|
||||
type: eventType,
|
||||
handler: handler
|
||||
};
|
||||
|
||||
var alreadyAddedListener = listeners.search.one(element, eventType, handler);
|
||||
|
||||
if (!alreadyAddedListener) {
|
||||
|
||||
allListeners.push(data);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
listeners.remove = function (element, eventType, handler) {
|
||||
|
||||
element.removeEventListener(eventType, handler);
|
||||
|
||||
var existingListeners = listeners.search.all(element, eventType, handler);
|
||||
|
||||
for (var i = 0; i < existingListeners.length; i++) {
|
||||
|
||||
var index = allListeners.indexOf(existingListeners[i]);
|
||||
|
||||
if (index > 0) {
|
||||
|
||||
allListeners.splice(index, 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
listeners.removeAll = function () {
|
||||
|
||||
allListeners.map(function (current) {
|
||||
|
||||
listeners.remove(current.element, current.type, current.handler);
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
listeners.get = function (element, eventType, handler) {
|
||||
|
||||
return listeners.search.all(element, eventType, handler);
|
||||
|
||||
};
|
||||
|
||||
return listeners;
|
||||
|
||||
}({});
|
|
@ -138,8 +138,8 @@ module.exports = (function (notifications) {
|
|||
okBtn.textContent = settings.okMsg || 'ОК';
|
||||
cancelBtn.textContent = settings.cancelMsg || 'Отмена';
|
||||
|
||||
okBtn.addEventListener('click', confirmHandler);
|
||||
cancelBtn.addEventListener('click', cancelHandler);
|
||||
editor.listeners.add(okBtn, 'click', confirmHandler);
|
||||
editor.listeners.add(cancelBtn, 'click', cancelHandler);
|
||||
|
||||
wrapper.appendChild(message);
|
||||
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
* @author Codex Team
|
||||
* @version 1.1
|
||||
*/
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (parser) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
/** inserting text */
|
||||
parser.insertPastedContent = function (blockType, tag) {
|
||||
|
||||
|
|
|
@ -103,7 +103,6 @@ module.exports = function (paste) {
|
|||
|
||||
};
|
||||
|
||||
|
||||
return paste;
|
||||
|
||||
}({});
|
|
@ -5,10 +5,10 @@
|
|||
* @version 1.0
|
||||
*/
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (renderer) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
/**
|
||||
* Asyncronously parses input JSON to redactor blocks
|
||||
*/
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
* Codex Sanitizer
|
||||
*/
|
||||
|
||||
var janitor = require('html-janitor');
|
||||
|
||||
module.exports = (function (sanitizer) {
|
||||
|
||||
var janitor = require('html-janitor');
|
||||
|
||||
/**
|
||||
* Basic config
|
||||
*/
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
* @version 1.0.2
|
||||
*/
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (saver) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
/**
|
||||
* Saves blocks
|
||||
* @private
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
* @version 1.0
|
||||
*/
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (inline) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
inline.buttonsOpened = null;
|
||||
inline.actionsOpened = null;
|
||||
inline.wrappersOffset = null;
|
||||
|
@ -363,7 +363,7 @@ module.exports = (function (inline) {
|
|||
event.preventDefault();
|
||||
|
||||
/** Callback to link action */
|
||||
action.addEventListener('keydown', inlineToolbarAnchorInputKeydown_, false);
|
||||
editor.listeners.add(action, 'keydown', inlineToolbarAnchorInputKeydown_, false);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
* @version 1.0.4
|
||||
*/
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (settings) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
settings.opened = false;
|
||||
|
||||
settings.setting = null;
|
||||
|
@ -141,7 +141,7 @@ module.exports = (function (settings) {
|
|||
}
|
||||
|
||||
setting = editor.draw.node('DIV', editor.ui.className.SETTINGS_ITEM, data);
|
||||
setting.addEventListener('click', editor.toolbar.settings.updateFeedMode, false);
|
||||
editor.listeners.add(setting, 'click', editor.toolbar.settings.updateFeedMode, false);
|
||||
|
||||
return setting;
|
||||
|
||||
|
@ -182,10 +182,10 @@ module.exports = (function (settings) {
|
|||
hash = editor.draw.node('i', 'ce-settings__anchor-hash', {}),
|
||||
anchor = editor.draw.node('input', 'ce-settings__anchor-input', { placeholder: 'Якорь' });
|
||||
|
||||
anchor.addEventListener('keydown', editor.anchors.keyDownOnAnchorInput );
|
||||
anchor.addEventListener('keyup', editor.anchors.keyUpOnAnchorInput );
|
||||
anchor.addEventListener('input', editor.anchors.anchorChanged );
|
||||
anchor.addEventListener('blur', editor.anchors.anchorChanged );
|
||||
editor.listeners.add(anchor, 'keydown', editor.anchors.keyDownOnAnchorInput );
|
||||
editor.listeners.add(anchor, 'keyup', editor.anchors.keyUpOnAnchorInput );
|
||||
editor.listeners.add(anchor, 'input', editor.anchors.anchorChanged );
|
||||
editor.listeners.add(anchor, 'blur', editor.anchors.anchorChanged );
|
||||
|
||||
anchorWrapper.appendChild(hash);
|
||||
anchorWrapper.appendChild(anchor);
|
||||
|
@ -207,11 +207,11 @@ module.exports = (function (settings) {
|
|||
confirmAction = editor.draw.node('DIV', 'ce-toolbar__remove-confirm', { textContent : 'Удалить блок' }),
|
||||
cancelAction = editor.draw.node('DIV', 'ce-toolbar__remove-cancel', { textContent : 'Отмена' });
|
||||
|
||||
settingButton.addEventListener('click', editor.toolbar.settings.removeButtonClicked, false);
|
||||
editor.listeners.add(settingButton, 'click', editor.toolbar.settings.removeButtonClicked, false);
|
||||
|
||||
confirmAction.addEventListener('click', editor.toolbar.settings.confirmRemovingRequest, false);
|
||||
editor.listeners.add(confirmAction, 'click', editor.toolbar.settings.confirmRemovingRequest, false);
|
||||
|
||||
cancelAction.addEventListener('click', editor.toolbar.settings.cancelRemovingRequest, false);
|
||||
editor.listeners.add(cancelAction, 'click', editor.toolbar.settings.cancelRemovingRequest, false);
|
||||
|
||||
actionWrapper.appendChild(confirmAction);
|
||||
actionWrapper.appendChild(cancelAction);
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
* @version 1.0
|
||||
*/
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (toolbar) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
toolbar.settings = require('./settings');
|
||||
toolbar.inline = require('./inline');
|
||||
toolbar.toolbox = require('./toolbox');
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
* @version 1.0
|
||||
*/
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (toolbox) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
toolbox.opened = false;
|
||||
|
||||
/** Shows toolbox */
|
||||
|
|
|
@ -5,10 +5,11 @@
|
|||
* @author Codex Team
|
||||
* @version 1.0
|
||||
*/
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (transport) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
transport.input = null;
|
||||
|
||||
/**
|
||||
|
@ -21,7 +22,7 @@ module.exports = (function (transport) {
|
|||
var input = document.createElement('INPUT');
|
||||
|
||||
input.type = 'file';
|
||||
input.addEventListener('change', editor.transport.fileSelected);
|
||||
editor.listeners.add(input, 'change', editor.transport.fileSelected);
|
||||
|
||||
editor.transport.input = input;
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
* @version 1.1
|
||||
*/
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
module.exports = (function (ui) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
/**
|
||||
* Basic editor classnames
|
||||
*/
|
||||
|
@ -274,28 +274,28 @@ module.exports = (function (ui) {
|
|||
// }, false );
|
||||
|
||||
/** All keydowns on Document */
|
||||
document.addEventListener('keydown', editor.callback.globalKeydown, false );
|
||||
editor.listeners.add(document, 'keydown', editor.callback.globalKeydown, false);
|
||||
|
||||
/** All keydowns on Redactor zone */
|
||||
editor.nodes.redactor.addEventListener('keydown', editor.callback.redactorKeyDown, false);
|
||||
editor.listeners.add(editor.nodes.redactor, 'keydown', editor.callback.redactorKeyDown, false);
|
||||
|
||||
/** All keydowns on Document */
|
||||
document.addEventListener('keyup', editor.callback.globalKeyup, false );
|
||||
editor.listeners.add(document, 'keyup', editor.callback.globalKeyup, false );
|
||||
|
||||
/**
|
||||
* Mouse click to radactor
|
||||
*/
|
||||
editor.nodes.redactor.addEventListener('click', editor.callback.redactorClicked, false );
|
||||
editor.listeners.add(editor.nodes.redactor, 'click', editor.callback.redactorClicked, false );
|
||||
|
||||
/**
|
||||
* Clicks to the Plus button
|
||||
*/
|
||||
editor.nodes.plusButton.addEventListener('click', editor.callback.plusButtonClicked, false);
|
||||
editor.listeners.add(editor.nodes.plusButton, 'click', editor.callback.plusButtonClicked, false);
|
||||
|
||||
/**
|
||||
* Clicks to SETTINGS button in toolbar
|
||||
*/
|
||||
editor.nodes.showSettingsButton.addEventListener('click', editor.callback.showSettingsButtonClicked, false );
|
||||
editor.listeners.add(editor.nodes.showSettingsButton, 'click', editor.callback.showSettingsButtonClicked, false );
|
||||
|
||||
/**
|
||||
* @deprecated ( but now in use for syncronization );
|
||||
|
@ -306,7 +306,7 @@ module.exports = (function (ui) {
|
|||
/** Bind click listeners on toolbar buttons */
|
||||
for (var button in editor.nodes.toolbarButtons) {
|
||||
|
||||
editor.nodes.toolbarButtons[button].addEventListener('click', editor.callback.toolbarButtonClicked, false);
|
||||
editor.listeners.add(editor.nodes.toolbarButtons[button], 'click', editor.callback.toolbarButtonClicked, false);
|
||||
|
||||
}
|
||||
|
||||
|
@ -319,7 +319,7 @@ module.exports = (function (ui) {
|
|||
/**
|
||||
* Block keydowns
|
||||
*/
|
||||
block.addEventListener('keydown', editor.callback.blockKeydown, false);
|
||||
editor.listeners.add(block, 'keydown', editor.callback.blockKeydown, false);
|
||||
|
||||
/**
|
||||
* Pasting content from another source
|
||||
|
@ -340,9 +340,9 @@ module.exports = (function (ui) {
|
|||
* @example editor.callback.blockPasteViaSanitize(event), the second method.
|
||||
*
|
||||
*/
|
||||
block.addEventListener('paste', editor.callback.blockPasteCallback, false);
|
||||
editor.listeners.add(block, 'paste', editor.callback.blockPasteCallback, false);
|
||||
|
||||
block.addEventListener('mouseup', editor.toolbar.inline.show, false);
|
||||
editor.listeners.add(block, 'mouseup', editor.toolbar.inline.show, false);
|
||||
|
||||
};
|
||||
|
||||
|
@ -386,7 +386,7 @@ module.exports = (function (ui) {
|
|||
|
||||
ui.setInlineToolbarButtonBehaviour = function (button, type) {
|
||||
|
||||
button.addEventListener('mousedown', function (event) {
|
||||
editor.listeners.add(button, 'mousedown', function (event) {
|
||||
|
||||
editor.toolbar.inline.toolClicked(event, type);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "codex.editor",
|
||||
"version": "1.4.10",
|
||||
"version": "1.5.0",
|
||||
"description": "Codex Editor. Native JS, based on API and Open Source",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Creates code tag and adds content to this tag
|
||||
*/
|
||||
|
||||
var code = (function(code) {
|
||||
var code = (function(code_plugin) {
|
||||
|
||||
var baseClass = "ce-code";
|
||||
|
||||
|
@ -28,7 +28,7 @@ var code = (function(code) {
|
|||
/**
|
||||
* Method to render HTML block from JSON
|
||||
*/
|
||||
code.render = function (data) {
|
||||
code_plugin.render = function (data) {
|
||||
|
||||
return make_(data);
|
||||
};
|
||||
|
@ -36,7 +36,7 @@ var code = (function(code) {
|
|||
/**
|
||||
* Method to extract JSON data from HTML block
|
||||
*/
|
||||
code.save = function (blockContent){
|
||||
code_plugin.save = function (blockContent) {
|
||||
|
||||
var data = {
|
||||
text : blockContent.innerHTML
|
||||
|
@ -45,7 +45,7 @@ var code = (function(code) {
|
|||
|
||||
};
|
||||
|
||||
code.validate = function(data) {
|
||||
code_plugin.validate = function (data) {
|
||||
|
||||
if (data.text.trim() == '')
|
||||
return;
|
||||
|
@ -53,6 +53,12 @@ var code = (function(code) {
|
|||
return true;
|
||||
};
|
||||
|
||||
return code;
|
||||
code_plugin.destroy = function () {
|
||||
|
||||
code = null;
|
||||
|
||||
};
|
||||
|
||||
return code_plugin;
|
||||
|
||||
})({});
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Embed plugin by gohabereg
|
||||
* @version 1.0.0
|
||||
*/
|
||||
var embed = function(embed){
|
||||
var embed = function(embed_plugin){
|
||||
|
||||
var methods = {
|
||||
|
||||
|
@ -122,7 +122,7 @@ var embed = function(embed){
|
|||
};
|
||||
|
||||
|
||||
embed.make = function(data, isInternal) {
|
||||
embed_plugin.make = function(data, isInternal) {
|
||||
|
||||
if (!data.remote_id)
|
||||
return;
|
||||
|
@ -152,7 +152,7 @@ var embed = function(embed){
|
|||
* Saving JSON output.
|
||||
* Upload data via ajax
|
||||
*/
|
||||
embed.save = function(blockContent) {
|
||||
embed_plugin.save = function(blockContent) {
|
||||
|
||||
if (!blockContent)
|
||||
return;
|
||||
|
@ -175,11 +175,11 @@ var embed = function(embed){
|
|||
/**
|
||||
* Render data
|
||||
*/
|
||||
embed.render = function(data) {
|
||||
return embed.make(data);
|
||||
embed_plugin.render = function(data) {
|
||||
return embed_plugin.make(data);
|
||||
};
|
||||
|
||||
embed.urlPastedCallback = function(url, pattern) {
|
||||
embed_plugin.urlPastedCallback = function(url, pattern) {
|
||||
|
||||
var execArray = pattern.regex.exec(url),
|
||||
id = methods.getRemoteId(pattern.type, execArray);
|
||||
|
@ -190,10 +190,10 @@ var embed = function(embed){
|
|||
thumbnailUrl: url
|
||||
};
|
||||
|
||||
embed.make(data, true);
|
||||
embed_plugin.make(data, true);
|
||||
};
|
||||
|
||||
embed.validate = function(savedData) {
|
||||
embed_plugin.validate = function(savedData) {
|
||||
|
||||
var source = savedData.source,
|
||||
execArray = services[source].regex.exec(savedData.thumbnailUrl),
|
||||
|
@ -203,69 +203,74 @@ var embed = function(embed){
|
|||
|
||||
};
|
||||
|
||||
embed.pastePatterns = [
|
||||
embed_plugin.pastePatterns = [
|
||||
{
|
||||
type: 'vk',
|
||||
regex: /https?:\/\/vk\.com\/.*(?:video)([-0-9]+_[0-9]+)/, ///https?.+vk?.com\/feed\?w=wall\d+_\d+/,
|
||||
callback: embed.urlPastedCallback
|
||||
callback: embed_plugin.urlPastedCallback
|
||||
},
|
||||
{
|
||||
type: 'youtube',
|
||||
regex: /(?:https?:\/{2})?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\?v=|\/)([^\s&]+)/,
|
||||
callback: embed.urlPastedCallback
|
||||
callback: embed_plugin.urlPastedCallback
|
||||
},
|
||||
{
|
||||
type: 'vimeo',
|
||||
regex: /(?:http[s]?:\/\/)?(?:www.)?vimeo\.co(?:.+\/([^\/]\d+)(?:#t=[\d]+)?s?$)/,
|
||||
callback: embed.urlPastedCallback
|
||||
callback: embed_plugin.urlPastedCallback
|
||||
},
|
||||
{
|
||||
type: 'coub',
|
||||
regex: /https?:\/\/coub\.com\/view\/([^\/\?\&]+)/,
|
||||
callback: embed.urlPastedCallback
|
||||
callback: embed_plugin.urlPastedCallback
|
||||
},
|
||||
{
|
||||
type: 'vine',
|
||||
regex: /https?:\/\/vine\.co\/v\/([^\/\?\&]+)/,
|
||||
callback: embed.urlPastedCallback
|
||||
callback: embed_plugin.urlPastedCallback
|
||||
},
|
||||
{
|
||||
type: 'imgur',
|
||||
regex: /https?:\/\/(?:i\.)?imgur\.com.*\/([a-zA-Z0-9]+)(?:\.gifv)?/,
|
||||
callback: embed.urlPastedCallback
|
||||
callback: embed_plugin.urlPastedCallback
|
||||
},
|
||||
{
|
||||
type: 'gfycat',
|
||||
regex: /https?:\/\/gfycat\.com(?:\/detail)?\/([a-zA-Z]+)/,
|
||||
callback: embed.urlPastedCallback
|
||||
callback: embed_plugin.urlPastedCallback
|
||||
},
|
||||
{
|
||||
type: 'twitch-channel',
|
||||
regex: /https?:\/\/www.twitch.tv\/([^\/\?\&]*)/,
|
||||
callback: embed.urlPastedCallback
|
||||
callback: embed_plugin.urlPastedCallback
|
||||
},
|
||||
{
|
||||
type: 'twitch-video',
|
||||
regex: /https?:\/\/www.twitch.tv\/(?:[^\/\?\&]*\/v|videos)\/([0-9]*)/,
|
||||
callback: embed.urlPastedCallback
|
||||
callback: embed_plugin.urlPastedCallback
|
||||
},
|
||||
{
|
||||
type: 'yandex-music-album',
|
||||
regex: /https?:\/\/music.yandex.ru\/album\/([0-9]*)/,
|
||||
callback: embed.urlPastedCallback
|
||||
callback: embed_plugin.urlPastedCallback
|
||||
},
|
||||
{
|
||||
type: 'yandex-music-track',
|
||||
regex: /https?:\/\/music.yandex.ru\/album\/([0-9]*)\/track\/([0-9]*)/,
|
||||
callback: embed.urlPastedCallback
|
||||
callback: embed_plugin.urlPastedCallback
|
||||
},
|
||||
{
|
||||
type: 'yandex-music-playlist',
|
||||
regex: /https?:\/\/music.yandex.ru\/users\/([^\/\?\&]*)\/playlists\/([0-9]*)/,
|
||||
callback: embed.urlPastedCallback
|
||||
callback: embed_plugin.urlPastedCallback
|
||||
} ];
|
||||
|
||||
embed_plugin.destroy = function () {
|
||||
|
||||
return embed;
|
||||
embed = null;
|
||||
|
||||
};
|
||||
|
||||
return embed_plugin;
|
||||
|
||||
}({});
|
|
@ -3,7 +3,7 @@
|
|||
* H e a d e r
|
||||
*/
|
||||
|
||||
var header = (function(header) {
|
||||
var header = (function(header_plugin) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
@ -92,14 +92,14 @@ var header = (function(header) {
|
|||
|
||||
};
|
||||
|
||||
header.prepareDataForSave = function(data) {
|
||||
header_plugin.prepareDataForSave = function(data) {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Method to render HTML block from JSON
|
||||
*/
|
||||
header.render = function (data) {
|
||||
header_plugin.render = function (data) {
|
||||
|
||||
return make_(data);
|
||||
|
||||
|
@ -108,7 +108,7 @@ var header = (function(header) {
|
|||
/**
|
||||
* Method to extract JSON data from HTML block
|
||||
*/
|
||||
header.save = function (blockContent) {
|
||||
header_plugin.save = function (blockContent) {
|
||||
|
||||
var data = {
|
||||
"heading-styles": blockContent.dataset.headerData,
|
||||
|
@ -126,7 +126,7 @@ var header = (function(header) {
|
|||
* - - - - - - - - - - - - -
|
||||
* @return {Element} element contains all settings
|
||||
*/
|
||||
header.makeSettings = function () {
|
||||
header_plugin.makeSettings = function () {
|
||||
|
||||
var holder = codex.editor.draw.node('DIV', ['cdx-plugin-settings--horisontal'], {} ),
|
||||
types = {
|
||||
|
@ -148,7 +148,7 @@ var header = (function(header) {
|
|||
return holder;
|
||||
};
|
||||
|
||||
header.validate = function(data) {
|
||||
header_plugin.validate = function(data) {
|
||||
|
||||
if (data.text.trim() === '' || data['heading-styles'].trim() === ''){
|
||||
return false;
|
||||
|
@ -157,7 +157,13 @@ var header = (function(header) {
|
|||
return true;
|
||||
};
|
||||
|
||||
return header;
|
||||
header_plugin.destroy = function () {
|
||||
|
||||
header = null;
|
||||
|
||||
}
|
||||
|
||||
return header_plugin;
|
||||
|
||||
})({});
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @version 1.2.0
|
||||
*/
|
||||
var image = (function(image) {
|
||||
var image = (function(image_plugin) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
@ -428,9 +428,9 @@ var image = (function(image) {
|
|||
*/
|
||||
uploadImageFromUrl : function(path) {
|
||||
|
||||
var ajaxUrl = image.config.uploadUrl,
|
||||
var ajaxUrl = image_plugin.config.uploadUrl,
|
||||
file,
|
||||
image_plugin,
|
||||
image,
|
||||
current = codex.editor.content.currentNode,
|
||||
beforeSend,
|
||||
success_callback;
|
||||
|
@ -440,7 +440,7 @@ var image = (function(image) {
|
|||
|
||||
var imageInfo = JSON.parse(data);
|
||||
|
||||
var newImage = image_plugin.getElementsByTagName('IMG')[0];
|
||||
var newImage = image.getElementsByTagName('IMG')[0];
|
||||
|
||||
newImage.dataset.stretched = false;
|
||||
newImage.dataset.src = imageInfo.file.url;
|
||||
|
@ -449,7 +449,7 @@ var image = (function(image) {
|
|||
newImage.dataset.height = imageInfo.file.height;
|
||||
newImage.dataset.additionalData = imageInfo.file.additionalData;
|
||||
|
||||
image_plugin.classList.remove(elementClasses_.imagePreview);
|
||||
image.classList.remove(elementClasses_.imagePreview);
|
||||
|
||||
};
|
||||
|
||||
|
@ -473,19 +473,19 @@ var image = (function(image) {
|
|||
cover: null
|
||||
};
|
||||
|
||||
image_plugin = codex.editor.tools.image_extended.render(data);
|
||||
image = codex.editor.tools.image_extended.render(data);
|
||||
|
||||
image_plugin.classList.add(elementClasses_.imagePreview);
|
||||
image.classList.add(elementClasses_.imagePreview);
|
||||
|
||||
var img = image_plugin.querySelector('img');
|
||||
var img = image.querySelector('img');
|
||||
|
||||
codex.editor.content.switchBlock(codex.editor.content.currentNode, image_plugin, 'image_extended');
|
||||
codex.editor.content.switchBlock(codex.editor.content.currentNode, image, 'image_extended');
|
||||
|
||||
};
|
||||
|
||||
/** Preparing data for XMLHTTP */
|
||||
var data = {
|
||||
url: image.config.uploadUrl,
|
||||
url: image_plugin.config.uploadUrl,
|
||||
type: "POST",
|
||||
data : {
|
||||
url: path
|
||||
|
@ -504,12 +504,12 @@ var image = (function(image) {
|
|||
* Image path
|
||||
* @type {null}
|
||||
*/
|
||||
image.path = null;
|
||||
image_plugin.path = null;
|
||||
|
||||
/**
|
||||
* Plugin configuration
|
||||
*/
|
||||
image.config = null;
|
||||
image_plugin.config = null;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -567,9 +567,9 @@ var image = (function(image) {
|
|||
* @public
|
||||
* @param config
|
||||
*/
|
||||
image.prepare = function(config) {
|
||||
image_plugin.prepare = function(config) {
|
||||
|
||||
image.config = config;
|
||||
image_plugin.config = config;
|
||||
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
@ -579,7 +579,7 @@ var image = (function(image) {
|
|||
*
|
||||
* this tool works when tool is clicked in toolbox
|
||||
*/
|
||||
image.appendCallback = function(event) {
|
||||
image_plugin.appendCallback = function(event) {
|
||||
|
||||
/** Upload image and call success callback*/
|
||||
uploadButtonClicked_(event);
|
||||
|
@ -592,7 +592,7 @@ var image = (function(image) {
|
|||
* @param data
|
||||
* @return {*}
|
||||
*/
|
||||
image.render = function( data ) {
|
||||
image_plugin.render = function( data ) {
|
||||
|
||||
return make_(data);
|
||||
};
|
||||
|
@ -603,7 +603,7 @@ var image = (function(image) {
|
|||
* @param block
|
||||
* @return {{background: boolean, border: boolean, isstretch: boolean, file: {url: (*|string|Object), bigUrl: (null|*), width: *, height: *, additionalData: null}, caption: (string|*|string), cover: null}}
|
||||
*/
|
||||
image.save = function ( block ) {
|
||||
image_plugin.save = function ( block ) {
|
||||
|
||||
var content = block,
|
||||
image = ui_.getImage(content),
|
||||
|
@ -633,7 +633,7 @@ var image = (function(image) {
|
|||
* Settings panel content
|
||||
* @return {Element} element contains all settings
|
||||
*/
|
||||
image.makeSettings = function () {
|
||||
image_plugin.makeSettings = function () {
|
||||
|
||||
var currentNode = codex.editor.content.currentNode,
|
||||
wrapper = currentNode.querySelector('.' + elementClasses_.imageWrapper),
|
||||
|
@ -688,20 +688,26 @@ var image = (function(image) {
|
|||
/**
|
||||
* Share as API
|
||||
*/
|
||||
image.uploadImageFromUri = uploadingCallbacks_.ByPaste.uploadImageFromUrl;
|
||||
image_plugin.uploadImageFromUri = uploadingCallbacks_.ByPaste.uploadImageFromUrl;
|
||||
|
||||
image.pastePatterns = [
|
||||
image_plugin.pastePatterns = [
|
||||
{
|
||||
type: 'image',
|
||||
regex: /(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*\.(?:jpe?g|gif|png))(?:\?([^#]*))?(?:#(.*))?/i,
|
||||
callback: image.uploadImageFromUri
|
||||
callback: image_plugin.uploadImageFromUri
|
||||
},
|
||||
{
|
||||
type: 'uploadCare',
|
||||
regex: /^https:\/\/(uploadcare\.cmtt\.ru|ucarecdn\.com|static[0-9]+\.siliconrus\.cmtt\.ru|static[0-9]+\.cmtt\.ru)/i,
|
||||
callback: image.uploadImageFromUri
|
||||
callback: image_plugin.uploadImageFromUri
|
||||
} ];
|
||||
|
||||
return image;
|
||||
image_plugin.destroy = function () {
|
||||
|
||||
image = null;
|
||||
|
||||
};
|
||||
|
||||
return image_plugin;
|
||||
|
||||
})({});
|
|
@ -2,7 +2,7 @@
|
|||
* Instagram plugin
|
||||
* @version 1.0.0
|
||||
*/
|
||||
var instagram = (function(instagram) {
|
||||
var instagram = (function(instagram_plugin) {
|
||||
|
||||
var methods = {
|
||||
|
||||
|
@ -44,7 +44,7 @@ var instagram = (function(instagram) {
|
|||
* Prepare before usage
|
||||
* Load important scripts to render embed
|
||||
*/
|
||||
instagram.prepare = function() {
|
||||
instagram_plugin.prepare = function() {
|
||||
|
||||
return new Promise(function(resolve, reject){
|
||||
|
||||
|
@ -86,7 +86,7 @@ var instagram = (function(instagram) {
|
|||
return block;
|
||||
};
|
||||
|
||||
instagram.validate = function(data) {
|
||||
instagram_plugin.validate = function(data) {
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -94,7 +94,7 @@ var instagram = (function(instagram) {
|
|||
* Saving JSON output.
|
||||
* Upload data via ajax
|
||||
*/
|
||||
instagram.save = function(blockContent) {
|
||||
instagram_plugin.save = function(blockContent) {
|
||||
|
||||
var data;
|
||||
|
||||
|
@ -110,7 +110,7 @@ var instagram = (function(instagram) {
|
|||
|
||||
};
|
||||
|
||||
instagram.validate = function(data) {
|
||||
instagram_plugin.validate = function(data) {
|
||||
|
||||
var checkUrl = new RegExp("http?.+instagram.com\/p?.");
|
||||
|
||||
|
@ -123,7 +123,7 @@ var instagram = (function(instagram) {
|
|||
/**
|
||||
* Render data
|
||||
*/
|
||||
instagram.render = function(data) {
|
||||
instagram_plugin.render = function(data) {
|
||||
return make_(data);
|
||||
};
|
||||
|
||||
|
@ -132,7 +132,7 @@ var instagram = (function(instagram) {
|
|||
* Using instagram Embed Widgete to render
|
||||
* @param url
|
||||
*/
|
||||
instagram.urlPastedCallback = function(url) {
|
||||
instagram_plugin.urlPastedCallback = function(url) {
|
||||
var data = {
|
||||
instagram_url: url
|
||||
};
|
||||
|
@ -141,15 +141,22 @@ var instagram = (function(instagram) {
|
|||
|
||||
};
|
||||
|
||||
instagram.pastePatterns = [
|
||||
instagram_plugin.pastePatterns = [
|
||||
{
|
||||
type: 'instagram',
|
||||
regex: /http?.+instagram.com\/p\/([a-zA-Z0-9]*)/,
|
||||
callback: instagram.urlPastedCallback
|
||||
callback: instagram_plugin.urlPastedCallback
|
||||
}
|
||||
];
|
||||
|
||||
return instagram;
|
||||
instagram_plugin.destroy = function () {
|
||||
|
||||
instagram = null;
|
||||
delete window.instgrm
|
||||
|
||||
};
|
||||
|
||||
return instagram_plugin;
|
||||
|
||||
})({});
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Link tool plugin
|
||||
*/
|
||||
|
||||
var link = (function(link) {
|
||||
var link = (function(link_plugin) {
|
||||
|
||||
var settings = {
|
||||
defaultText : 'Вставьте ссылку ...',
|
||||
|
@ -178,7 +178,7 @@ var link = (function(link) {
|
|||
/* Show loader gif **/
|
||||
block.classList.add(settings.elementClasses.loader);
|
||||
|
||||
return fetch( link.config.fetchUrl + '?url=' + encodeURI(url) );
|
||||
return fetch( link_plugin.config.fetchUrl + '?url=' + encodeURI(url) );
|
||||
})
|
||||
|
||||
.then(function (response) {
|
||||
|
@ -242,9 +242,9 @@ var link = (function(link) {
|
|||
}
|
||||
};
|
||||
|
||||
link.prepare = function (config) {
|
||||
link_plugin.prepare = function (config) {
|
||||
|
||||
link.config = config;
|
||||
link_plugin.config = config;
|
||||
|
||||
return Promise.resolve();
|
||||
|
||||
|
@ -255,7 +255,7 @@ var link = (function(link) {
|
|||
* @param {object} JSON with block data
|
||||
* @return {Element} element to append
|
||||
*/
|
||||
link.makeNewBlock = function (data) {
|
||||
link_plugin.makeNewBlock = function (data) {
|
||||
|
||||
var wrapper = ui.mainBlock(),
|
||||
tag = ui.input();
|
||||
|
@ -278,7 +278,7 @@ var link = (function(link) {
|
|||
/**
|
||||
* Method to render HTML block from JSON
|
||||
*/
|
||||
link.render = function (json) {
|
||||
link_plugin.render = function (json) {
|
||||
|
||||
if ( json ) {
|
||||
|
||||
|
@ -312,7 +312,7 @@ var link = (function(link) {
|
|||
|
||||
};
|
||||
|
||||
link.validate = function (data) {
|
||||
link_plugin.validate = function (data) {
|
||||
|
||||
if (data.url.trim() == '' || data.title.trim() == '' || data.description.trim() == '')
|
||||
return;
|
||||
|
@ -323,7 +323,7 @@ var link = (function(link) {
|
|||
/**
|
||||
* Method to extract JSON data from HTML block
|
||||
*/
|
||||
link.save = function (blockContent){
|
||||
link_plugin.save = function (blockContent){
|
||||
|
||||
var linkElement = settings.elementClasses.link;
|
||||
|
||||
|
@ -339,6 +339,12 @@ var link = (function(link) {
|
|||
|
||||
};
|
||||
|
||||
return link;
|
||||
link_plugin.destroy = function () {
|
||||
|
||||
link = null;
|
||||
|
||||
};
|
||||
|
||||
return link_plugin;
|
||||
|
||||
})({});
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Code Plugin\
|
||||
* Creates code tag and adds content to this tag
|
||||
*/
|
||||
var list = (function(list) {
|
||||
var list = (function(list_plugin) {
|
||||
|
||||
/**
|
||||
* CSS class names
|
||||
|
@ -76,7 +76,6 @@ var list = (function(list) {
|
|||
|
||||
codex.editor.content.switchBlock(currentBlock, newEditable, 'list');
|
||||
},
|
||||
|
||||
keyDown: function (e) {
|
||||
|
||||
var controlKeyPressed = e.ctrlKey || e.metaKey,
|
||||
|
@ -117,7 +116,7 @@ var list = (function(list) {
|
|||
|
||||
}
|
||||
|
||||
range.selectNode(currentSelectedNode);
|
||||
range.selectNodeContents(currentSelectedNode);
|
||||
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
|
@ -128,7 +127,7 @@ var list = (function(list) {
|
|||
/**
|
||||
* Method to render HTML block from JSON
|
||||
*/
|
||||
list.render = function (data) {
|
||||
list_plugin.render = function (data) {
|
||||
|
||||
var type = data && data.type == 'ordered' ? 'OL' : 'UL',
|
||||
tag = ui.make(type),
|
||||
|
@ -158,7 +157,7 @@ var list = (function(list) {
|
|||
|
||||
};
|
||||
|
||||
list.validate = function(data) {
|
||||
list_plugin.validate = function(data) {
|
||||
|
||||
var items = data.items.every(function(item){
|
||||
return item.trim() !== '';
|
||||
|
@ -176,7 +175,7 @@ var list = (function(list) {
|
|||
/**
|
||||
* Method to extract JSON data from HTML block
|
||||
*/
|
||||
list.save = function (blockContent){
|
||||
list_plugin.save = function (blockContent){
|
||||
|
||||
var data = {
|
||||
type : null,
|
||||
|
@ -192,7 +191,7 @@ var list = (function(list) {
|
|||
|
||||
};
|
||||
|
||||
list.makeSettings = function () {
|
||||
list_plugin.makeSettings = function () {
|
||||
|
||||
var holder = document.createElement('DIV');
|
||||
|
||||
|
@ -219,6 +218,12 @@ var list = (function(list) {
|
|||
|
||||
};
|
||||
|
||||
return list;
|
||||
list_plugin.destroy = function () {
|
||||
|
||||
list = null;
|
||||
|
||||
};
|
||||
|
||||
return list_plugin;
|
||||
|
||||
})({});
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
* Creates DIV tag and adds content to this tag
|
||||
*/
|
||||
|
||||
var paragraph = (function(paragraph) {
|
||||
var paragraph = (function(paragraph_plugin) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* Make initial header block
|
||||
* Make initial paragraph block
|
||||
* @param {object} JSON with block data
|
||||
* @return {Element} element to append
|
||||
*/
|
||||
|
@ -44,7 +44,7 @@ var paragraph = (function(paragraph) {
|
|||
* Plugins should have prepare method
|
||||
* @param config
|
||||
*/
|
||||
paragraph.prepare = function(config) {
|
||||
paragraph_plugin.prepare = function(config) {
|
||||
|
||||
};
|
||||
|
||||
|
@ -53,7 +53,7 @@ var paragraph = (function(paragraph) {
|
|||
*
|
||||
* Method to render HTML block from JSON
|
||||
*/
|
||||
paragraph.render = function (data) {
|
||||
paragraph_plugin.render = function (data) {
|
||||
|
||||
return make_(data);
|
||||
|
||||
|
@ -65,7 +65,7 @@ var paragraph = (function(paragraph) {
|
|||
* Check output data for validity.
|
||||
* Should be defined by developer
|
||||
*/
|
||||
paragraph.validate = function(output) {
|
||||
paragraph_plugin.validate = function(output) {
|
||||
|
||||
if (output.text === '')
|
||||
return;
|
||||
|
@ -78,7 +78,7 @@ var paragraph = (function(paragraph) {
|
|||
*
|
||||
* Method to extract JSON data from HTML block
|
||||
*/
|
||||
paragraph.save = function (blockContent){
|
||||
paragraph_plugin.save = function (blockContent){
|
||||
|
||||
var wrappedText = codex.editor.content.wrapTextWithParagraphs(blockContent.innerHTML);
|
||||
|
||||
|
@ -92,6 +92,12 @@ var paragraph = (function(paragraph) {
|
|||
|
||||
};
|
||||
|
||||
return paragraph;
|
||||
paragraph_plugin.destroy = function () {
|
||||
|
||||
paragraph = null;
|
||||
|
||||
};
|
||||
|
||||
return paragraph_plugin;
|
||||
|
||||
})({});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Quote plugin
|
||||
*/
|
||||
|
||||
var quote = (function(quote) {
|
||||
var quote = (function(quote_plugin) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
@ -401,7 +401,7 @@ var quote = (function(quote) {
|
|||
|
||||
if (data && data.size) {
|
||||
|
||||
data.style = quote.config.defaultStyle;
|
||||
data.style = quote_plugin.config.defaultStyle;
|
||||
|
||||
/**
|
||||
* Supported types
|
||||
|
@ -457,11 +457,11 @@ var quote = (function(quote) {
|
|||
*
|
||||
* @param data
|
||||
*/
|
||||
quote.render = function(data) {
|
||||
quote_plugin.render = function(data) {
|
||||
return make_(data);
|
||||
};
|
||||
|
||||
quote.validate = function(output) {
|
||||
quote_plugin.validate = function(output) {
|
||||
|
||||
if (typeof output.text != "string") {
|
||||
return;
|
||||
|
@ -470,7 +470,7 @@ var quote = (function(quote) {
|
|||
return output;
|
||||
};
|
||||
|
||||
quote.save = function(blockContent) {
|
||||
quote_plugin.save = function(blockContent) {
|
||||
|
||||
/**
|
||||
* Extracts JSON quote data from HTML block
|
||||
|
@ -495,7 +495,7 @@ var quote = (function(quote) {
|
|||
*
|
||||
* Draws settings
|
||||
*/
|
||||
quote.makeSettings = function(data) {
|
||||
quote_plugin.makeSettings = function(data) {
|
||||
|
||||
var holder = document.createElement('DIV'),
|
||||
types = {
|
||||
|
@ -517,7 +517,7 @@ var quote = (function(quote) {
|
|||
|
||||
selectTypeButton.dataset.style = type;
|
||||
|
||||
if ( type == quote.config.defaultStyle ){
|
||||
if ( type == quote_plugin.config.defaultStyle ){
|
||||
selectTypeButton.classList.add(quoteTools.styles.settings.selectedType);
|
||||
}
|
||||
|
||||
|
@ -539,27 +539,33 @@ var quote = (function(quote) {
|
|||
* Default path to redactors images
|
||||
* @type {null}
|
||||
*/
|
||||
quote.path = null;
|
||||
quote_plugin.path = null;
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* @type {null}
|
||||
*/
|
||||
quote.config = null;
|
||||
quote_plugin.config = null;
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* @param config
|
||||
*/
|
||||
quote.prepare = function(config) {
|
||||
quote_plugin.prepare = function(config) {
|
||||
|
||||
quote.config = config;
|
||||
quote_plugin.config = config;
|
||||
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
return quote;
|
||||
quote_plugin.destroy = function () {
|
||||
|
||||
quote = null;
|
||||
|
||||
};
|
||||
|
||||
return quote_plugin;
|
||||
|
||||
})({});
|
|
@ -3,7 +3,7 @@
|
|||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
var twitter = (function(twitter) {
|
||||
var twitter = (function(twitter_plugin) {
|
||||
|
||||
/**
|
||||
* User's configuration object
|
||||
|
@ -158,7 +158,7 @@ var twitter = (function(twitter) {
|
|||
* Prepare twitter scripts
|
||||
* @param {object} config
|
||||
*/
|
||||
twitter.prepare = function(config) {
|
||||
twitter_plugin.prepare = function(config) {
|
||||
|
||||
/**
|
||||
* Save configs
|
||||
|
@ -199,11 +199,11 @@ var twitter = (function(twitter) {
|
|||
return tweet;
|
||||
};
|
||||
|
||||
twitter.validate = function(data) {
|
||||
twitter_plugin.validate = function(data) {
|
||||
return true;
|
||||
};
|
||||
|
||||
twitter.save = function(blockContent) {
|
||||
twitter_plugin.save = function(blockContent) {
|
||||
|
||||
var data,
|
||||
caption = blockContent.querySelector('.ce-twitter__caption');
|
||||
|
@ -228,11 +228,11 @@ var twitter = (function(twitter) {
|
|||
return data;
|
||||
};
|
||||
|
||||
twitter.render = function(data) {
|
||||
twitter_plugin.render = function(data) {
|
||||
return make_(data);
|
||||
};
|
||||
|
||||
twitter.urlPastedCallback = function(url) {
|
||||
twitter_plugin.urlPastedCallback = function(url) {
|
||||
|
||||
var tweetId,
|
||||
arr,
|
||||
|
@ -256,15 +256,22 @@ var twitter = (function(twitter) {
|
|||
make_(data);
|
||||
};
|
||||
|
||||
twitter.pastePatterns = [
|
||||
twitter_plugin.pastePatterns = [
|
||||
{
|
||||
type: 'twitter',
|
||||
regex: /http?.+twitter.com?.+\//,
|
||||
callback: twitter.urlPastedCallback
|
||||
callback: twitter_plugin.urlPastedCallback
|
||||
}
|
||||
];
|
||||
|
||||
return twitter;
|
||||
twitter_plugin.destroy = function () {
|
||||
|
||||
twitter = null;
|
||||
delete window.twttr;
|
||||
|
||||
};
|
||||
|
||||
return twitter_plugin;
|
||||
|
||||
})({});
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue