mirror of
https://github.com/codex-team/editor.js
synced 2024-06-16 04:35:50 +02:00
Destroy method for plugins added
This commit is contained in:
parent
4962d27c22
commit
74e10eb3ce
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
13
example.html
13
example.html
|
@ -66,6 +66,7 @@
|
|||
render: paragraph.render,
|
||||
validate: paragraph.validate,
|
||||
save: paragraph.save,
|
||||
destroy: paragraph.destroy,
|
||||
allowedToPaste: true,
|
||||
showInlineToolbar: true
|
||||
},
|
||||
|
@ -77,6 +78,7 @@
|
|||
render: header.render,
|
||||
validate: header.validate,
|
||||
save: header.save,
|
||||
destroy: header.destroy,
|
||||
displayInToolbox: true
|
||||
},
|
||||
paste: {
|
||||
|
@ -84,6 +86,7 @@
|
|||
prepare: paste.prepare,
|
||||
make: paste.make,
|
||||
save: paste.save,
|
||||
destroy: paste.destroy,
|
||||
enableLineBreaks: false,
|
||||
callbacks: paste.pasted
|
||||
},
|
||||
|
@ -96,6 +99,7 @@
|
|||
render: code.render,
|
||||
validate: code.validate,
|
||||
save: code.save,
|
||||
destroy: code.destroy,
|
||||
displayInToolbox: true,
|
||||
enableLineBreaks: true
|
||||
},
|
||||
|
@ -108,6 +112,7 @@
|
|||
render: link.render,
|
||||
validate: link.validate,
|
||||
save: link.save,
|
||||
destroy: link.destroy,
|
||||
displayInToolbox: true,
|
||||
enableLineBreaks: true
|
||||
},
|
||||
|
@ -120,6 +125,7 @@
|
|||
render: list.render,
|
||||
validate: list.validate,
|
||||
save: list.save,
|
||||
destroy: list.destroy,
|
||||
displayInToolbox: true,
|
||||
showInlineToolbar: true,
|
||||
enableLineBreaks: true
|
||||
|
@ -132,6 +138,7 @@
|
|||
render: quote.render,
|
||||
validate: quote.validate,
|
||||
save: quote.save,
|
||||
destroy: quote.destroy,
|
||||
displayInToolbox: true,
|
||||
enableLineBreaks: true,
|
||||
showInlineToolbar: true,
|
||||
|
@ -148,6 +155,7 @@
|
|||
makeSettings: image.makeSettings,
|
||||
render: image.render,
|
||||
save: image.save,
|
||||
destroy: image.destroy,
|
||||
isStretched: true,
|
||||
showInlineToolbar: true,
|
||||
displayInToolbox: true,
|
||||
|
@ -161,7 +169,8 @@
|
|||
prepare: instagram.prepare,
|
||||
render: instagram.reneder,
|
||||
validate: instagram.validate,
|
||||
save: instagram.save
|
||||
save: instagram.save,
|
||||
destroy: instagram.destroy,
|
||||
},
|
||||
tweet: {
|
||||
type: 'tweet',
|
||||
|
@ -170,6 +179,7 @@
|
|||
render: twitter.render,
|
||||
validate: twitter.validate,
|
||||
save: twitter.save,
|
||||
destroy: twitter.destroy,
|
||||
showInlineToolbar : true,
|
||||
config : {
|
||||
fetchUrl : ''
|
||||
|
@ -180,6 +190,7 @@
|
|||
make: embed.make,
|
||||
render: embed.render,
|
||||
save: embed.save,
|
||||
destroy: embed.destroy,
|
||||
validate: embed.validate
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
/**
|
||||
* Codex Editor Destroyer module
|
||||
*
|
||||
* @auhor Codex Team
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
module.exports = function (destroyer) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
@ -9,10 +16,35 @@ module.exports = function (destroyer) {
|
|||
|
||||
};
|
||||
|
||||
destroyer.destroyPlugins = function () {
|
||||
|
||||
for (var tool in editor.tools) {
|
||||
|
||||
if (typeof editor.tools[tool].destroy === 'function') {
|
||||
|
||||
editor.tools[tool].destroy();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete all editor data from webpage:
|
||||
*
|
||||
* 1. Remove all listeners that was added by editor
|
||||
* 2. Calls plugins destroy method to remove plugins from storage
|
||||
* 3. Remove editor elements from DOM
|
||||
* 4. Delete editor object from storage
|
||||
*
|
||||
*/
|
||||
destroyer.destroy = function () {
|
||||
|
||||
editor.listeners.removeAll();
|
||||
|
||||
destroyer.destroyPlugins();
|
||||
|
||||
destroyer.removeNodes();
|
||||
|
||||
delete codex.editor;
|
||||
|
|
|
@ -1,72 +1,149 @@
|
|||
/**
|
||||
* Codex Editor Listeners module
|
||||
*
|
||||
* @author Codex Team
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module-decorator for event listeners assignment
|
||||
*/
|
||||
module.exports = function (listeners) {
|
||||
|
||||
var allListeners = [];
|
||||
|
||||
var search = function (element, listenerType, handler) {
|
||||
/**
|
||||
* 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 allListenersOnElement = [];
|
||||
var byElement = function (element, context) {
|
||||
|
||||
for (var i = 0; i < allListeners.length; i++) {
|
||||
var listenersOnElement = [];
|
||||
|
||||
var listener = allListeners[i];
|
||||
context = context || allListeners;
|
||||
|
||||
if (listener.element === element) {
|
||||
for (var i = 0; i < context.length; i++) {
|
||||
|
||||
allListenersOnElement.push(listener);
|
||||
var listener = context[i];
|
||||
|
||||
}
|
||||
if (listener.element === element) {
|
||||
|
||||
}
|
||||
|
||||
if (listenerType) {
|
||||
|
||||
for (i = 0; i < allListenersOnElement.length; i++) {
|
||||
|
||||
var listener = allListenersOnElement[i];
|
||||
|
||||
if (listener.listenerType !== listenerType) {
|
||||
|
||||
allListenersOnElement.splice(i, 1);
|
||||
listenersOnElement.push(listener);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return listenersOnElement;
|
||||
|
||||
if (handler) {
|
||||
};
|
||||
|
||||
for (i = 0; i < allListenersOnElement.length; i++) {
|
||||
var byType = function (eventType, context) {
|
||||
|
||||
var listener = allListenersOnElement[i];
|
||||
var listenersWithType = [];
|
||||
|
||||
if (listener.handler !== handler) {
|
||||
context = context || allListeners;
|
||||
|
||||
allListenersOnElement.splice(i, 1);
|
||||
for (var i = 0; i < context.length; i++) {
|
||||
|
||||
var listener = context[i];
|
||||
|
||||
if (listener.type === eventType) {
|
||||
|
||||
listenersWithType.push(listener);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return listenersWithType;
|
||||
|
||||
return allListenersOnElement;
|
||||
};
|
||||
|
||||
};
|
||||
var byHandler = function (handler, context) {
|
||||
|
||||
listeners.add = function (element, listenerType, handler, isCapture) {
|
||||
var listenersWithHandler = [];
|
||||
|
||||
element.addEventListener(listenerType, handler, isCapture);
|
||||
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: listenerType,
|
||||
type: eventType,
|
||||
handler: handler
|
||||
};
|
||||
|
||||
var alreadyAddedListeners = search(element, listenerType, handler);
|
||||
var alreadyAddedListener = listeners.search.one(element, eventType, handler);
|
||||
|
||||
if (alreadyAddedListeners.length == 0) {
|
||||
if (!alreadyAddedListener) {
|
||||
|
||||
allListeners.push(data);
|
||||
|
||||
|
@ -74,11 +151,11 @@ module.exports = function (listeners) {
|
|||
|
||||
};
|
||||
|
||||
listeners.remove = function (element, listenerType, handler) {
|
||||
listeners.remove = function (element, eventType, handler) {
|
||||
|
||||
element.removeEventListener(listenerType, handler);
|
||||
element.removeEventListener(eventType, handler);
|
||||
|
||||
var existingListeners = search(element, listenerType, handler);
|
||||
var existingListeners = listeners.search.all(element, eventType, handler);
|
||||
|
||||
for (var i = 0; i < existingListeners.length; i++) {
|
||||
|
||||
|
@ -104,15 +181,9 @@ module.exports = function (listeners) {
|
|||
|
||||
};
|
||||
|
||||
listeners.get = function (element, listenerType, handler) {
|
||||
listeners.get = function (element, eventType, handler) {
|
||||
|
||||
if (!element) {
|
||||
|
||||
return allListeners;
|
||||
|
||||
}
|
||||
|
||||
return search(element, listenerType, handler);
|
||||
return listeners.search.all(element, eventType, handler);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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,6 +203,12 @@ var embed = function(embed){
|
|||
|
||||
};
|
||||
|
||||
return embed;
|
||||
embed_plugin.destroy = function () {
|
||||
|
||||
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,8 +688,14 @@ var image = (function(image) {
|
|||
/**
|
||||
* Share as API
|
||||
*/
|
||||
image.uploadImageFromUri = uploadingCallbacks_.ByPaste.uploadImageFromUrl;
|
||||
image_plugin.uploadImageFromUri = uploadingCallbacks_.ByPaste.uploadImageFromUrl;
|
||||
|
||||
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,7 +141,13 @@ var instagram = (function(instagram) {
|
|||
|
||||
};
|
||||
|
||||
return instagram;
|
||||
instagram_plugin.destroy = function () {
|
||||
|
||||
instagram = null;
|
||||
|
||||
};
|
||||
|
||||
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) {
|
||||
|
||||
var baseClass = "tool-list";
|
||||
|
||||
|
@ -75,7 +75,7 @@ var list = (function(list) {
|
|||
* @param {object} JSON with block data
|
||||
* @return {Element} element to append
|
||||
*/
|
||||
list.make = function () {
|
||||
list_plugin.make = function () {
|
||||
|
||||
var tag = ui.make(),
|
||||
li = ui.block("li", "tool-link-li");
|
||||
|
@ -94,7 +94,7 @@ var list = (function(list) {
|
|||
/**
|
||||
* Method to render HTML block from JSON
|
||||
*/
|
||||
list.render = function (data) {
|
||||
list_plugin.render = function (data) {
|
||||
|
||||
var type = data.type == 'ordered' ? 'OL' : 'UL',
|
||||
tag = ui.make(type);
|
||||
|
@ -116,7 +116,7 @@ var list = (function(list) {
|
|||
|
||||
};
|
||||
|
||||
list.validate = function(data) {
|
||||
list_plugin.validate = function(data) {
|
||||
|
||||
var items = data.items.every(function(item){
|
||||
return item.trim() != '';
|
||||
|
@ -134,7 +134,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,
|
||||
|
@ -150,7 +150,7 @@ var list = (function(list) {
|
|||
|
||||
};
|
||||
|
||||
list.makeSettings = function(data) {
|
||||
list_plugin.makeSettings = function(data) {
|
||||
|
||||
var holder = document.createElement('DIV'),
|
||||
selectTypeButton;
|
||||
|
@ -178,6 +178,12 @@ var list = (function(list) {
|
|||
|
||||
};
|
||||
|
||||
return list;
|
||||
list_plugin.destroy = function () {
|
||||
|
||||
list = null;
|
||||
|
||||
};
|
||||
|
||||
return list_plugin;
|
||||
|
||||
})({});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Creates DIV tag and adds content to this tag
|
||||
*/
|
||||
|
||||
var paragraph = (function(paragraph) {
|
||||
var paragraph = (function(paragraph_plugin) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
@ -52,7 +52,7 @@ var paragraph = (function(paragraph) {
|
|||
* Plugins should have prepare method
|
||||
* @param config
|
||||
*/
|
||||
paragraph.prepare = function(config) {
|
||||
paragraph_plugin.prepare = function(config) {
|
||||
|
||||
};
|
||||
|
||||
|
@ -61,7 +61,7 @@ var paragraph = (function(paragraph) {
|
|||
*
|
||||
* Method to render HTML block from JSON
|
||||
*/
|
||||
paragraph.render = function (data) {
|
||||
paragraph_plugin.render = function (data) {
|
||||
|
||||
return make_(data);
|
||||
|
||||
|
@ -73,7 +73,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;
|
||||
|
@ -86,7 +86,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);
|
||||
|
||||
|
@ -100,6 +100,12 @@ var paragraph = (function(paragraph) {
|
|||
|
||||
};
|
||||
|
||||
return paragraph;
|
||||
paragraph_plugin.destroy = function () {
|
||||
|
||||
paragraph = null;
|
||||
|
||||
};
|
||||
|
||||
return paragraph_plugin;
|
||||
|
||||
})({});
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* Main tool settings.
|
||||
*/
|
||||
|
||||
var paste = function(paste) {
|
||||
var paste = function(paste_plugin) {
|
||||
|
||||
let editor = codex.editor;
|
||||
|
||||
|
@ -18,7 +18,7 @@ var paste = function(paste) {
|
|||
* Saves data
|
||||
* @param event
|
||||
*/
|
||||
paste.pasted = function(event) {
|
||||
paste_plugin.pasted = function(event) {
|
||||
|
||||
var clipBoardData = event.clipboardData || window.clipboardData,
|
||||
content = clipBoardData.getData('Text');
|
||||
|
@ -41,7 +41,7 @@ var paste = function(paste) {
|
|||
content = editor.content.currentNode,
|
||||
plugin = content.dataset.tool;
|
||||
|
||||
paste.patterns.map(function(pattern, i){
|
||||
paste_plugin.patterns.map(function(pattern, i){
|
||||
|
||||
if (pattern.regex.test(string)) {
|
||||
|
||||
|
@ -75,7 +75,13 @@ var paste = function(paste) {
|
|||
|
||||
};
|
||||
|
||||
return paste;
|
||||
paste_plugin.destroy = function () {
|
||||
|
||||
paste = null;
|
||||
|
||||
};
|
||||
|
||||
return paste_plugin;
|
||||
|
||||
}(paste || {});
|
||||
|
||||
|
|
|
@ -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,7 +256,13 @@ var twitter = (function(twitter) {
|
|||
make_(data);
|
||||
};
|
||||
|
||||
return twitter;
|
||||
twitter_plugin.destroy = function () {
|
||||
|
||||
twitter = null;
|
||||
|
||||
};
|
||||
|
||||
return twitter_plugin;
|
||||
|
||||
})({});
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue