ltsecurityinc安防产品在线商城代码
This commit is contained in:
+239
@@ -0,0 +1,239 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/* global tinymce, MagentovariablePlugin, varienGlobalEvents, Base64 */
|
||||
/* eslint-disable strict */
|
||||
define([
|
||||
'Magento_Variable/js/config-directive-generator',
|
||||
'Magento_Variable/js/custom-directive-generator',
|
||||
'wysiwygAdapter',
|
||||
'jquery',
|
||||
'mage/adminhtml/tools'
|
||||
], function (configDirectiveGenerator, customDirectiveGenerator, wysiwyg, jQuery) {
|
||||
return function (config) {
|
||||
tinymce.create('tinymce.plugins.magentovariable', {
|
||||
|
||||
/**
|
||||
* Initialize editor plugin.
|
||||
*
|
||||
* @param {tinymce.editor} editor - Editor instance that the plugin is initialized in.
|
||||
*/
|
||||
init: function (editor) {
|
||||
var self = this;
|
||||
|
||||
/**
|
||||
* Add new command to open variables selector slideout.
|
||||
*/
|
||||
editor.addCommand('openVariablesSlideout', function (commandConfig) {
|
||||
var selectedElement;
|
||||
|
||||
if (commandConfig) {
|
||||
selectedElement = commandConfig.selectedElement;
|
||||
} else {
|
||||
selectedElement = tinymce.activeEditor.selection.getNode();
|
||||
}
|
||||
MagentovariablePlugin.setEditor(editor);
|
||||
MagentovariablePlugin.loadChooser(
|
||||
config.url,
|
||||
wysiwyg.getId(),
|
||||
selectedElement
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Add button to the editor toolbar.
|
||||
*/
|
||||
editor.ui.registry.addIcon(
|
||||
'magentovariable',
|
||||
'<svg width="24" height="24" viewBox="0 0 32.000000 32.000000" ' +
|
||||
'preserveAspectRatio="xMidYMid meet"><g transform="translate(0.000000,32.000000) ' +
|
||||
'scale(0.100000,-0.100000)" fill="#000000" stroke="none"><path d="M68 250 c-56 -44 -75 -136 -37 ' +
|
||||
'-184 27 -34 42 -33 23 2 -26 50 -9 129 38 179 26 28 10 30 -24 3z"/><path d="M266 253 c5 -10 9 ' +
|
||||
'-41 9 -70 0 -42 -6 -60 -32 -97 -36 -51 -35 -56 7 -26 54 39 78 139 44 188 -18 26 -40 30 -28 5z"/>' +
|
||||
'<path d="M128 223 c-15 -4 -15 -6 0 -33 16 -28 16 -30 -11 -58 -30 -31 -34 -42 -13 -42 8 0 17 11 ' +
|
||||
'20 25 4 14 11 25 16 25 5 0 12 -11 16 -25 6 -25 37 -35 49 -15 3 5 2 10 -3 10 -23 0 -20 44 5 76 ' +
|
||||
'25 34 25 34 4 34 -12 0 -20 -4 -17 -8 2 -4 0 -14 -5 -22 -7 -10 -12 -11 -15 -4 -10 25 -30 40 ' +
|
||||
'-46 37z"/></g>' +
|
||||
'</svg>'
|
||||
);
|
||||
editor.ui.registry.addToggleButton('magentovariable', {
|
||||
icon: 'magentovariable',
|
||||
tooltip: jQuery.mage.__('Insert Variable'),
|
||||
|
||||
/**
|
||||
* execute openVariablesSlideout for onAction callback
|
||||
*/
|
||||
onAction: function () {
|
||||
editor.execCommand('openVariablesSlideout');
|
||||
},
|
||||
|
||||
/**
|
||||
* Highlight or dismiss Insert Variable button when variable is selected or deselected.
|
||||
*/
|
||||
onSetup: function (api) {
|
||||
/**
|
||||
* Toggle active state of Insert Variable button.
|
||||
*
|
||||
* @param {Object} e
|
||||
*/
|
||||
var toggleVariableButton = function (e) {
|
||||
api.setActive(false);
|
||||
|
||||
if (jQuery(e.target).hasClass('magento-variable')) {
|
||||
api.setActive(true);
|
||||
}
|
||||
};
|
||||
|
||||
editor.on('click', toggleVariableButton);
|
||||
editor.on('change', toggleVariableButton);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Double click handler on the editor to handle dbl click on variable placeholder.
|
||||
*/
|
||||
editor.on('dblclick', function (evt) {
|
||||
if (jQuery(evt.target).hasClass('magento-variable')) {
|
||||
editor.selection.collapse(false);
|
||||
editor.execCommand('openVariablesSlideout', {
|
||||
ui: true,
|
||||
selectedElement: evt.target
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Attach event handler for when wysiwyg editor is about to encode its content
|
||||
*/
|
||||
varienGlobalEvents.attachEventHandler('wysiwygEncodeContent', function (content) {
|
||||
content = self.encodeVariables(content);
|
||||
|
||||
return content;
|
||||
});
|
||||
|
||||
/**
|
||||
* Attach event handler for when wysiwyg editor is about to decode its content
|
||||
*/
|
||||
varienGlobalEvents.attachEventHandler('wysiwygDecodeContent', function (content) {
|
||||
content = self.decodeVariables(content);
|
||||
|
||||
return content;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Encode variables in content
|
||||
*
|
||||
* @param {String} content
|
||||
* @returns {*}
|
||||
*/
|
||||
encodeVariables: function (content) {
|
||||
content = content.gsub(/\{\{config path=\"([^\"]+)\"\}\}/i, function (match) {
|
||||
var path = match[1],
|
||||
magentoVariables,
|
||||
imageHtml;
|
||||
|
||||
magentoVariables = JSON.parse(config.placeholders);
|
||||
|
||||
if (magentoVariables[match[1]] && magentoVariables[match[1]]['variable_type'] === 'default') {
|
||||
imageHtml = '<span id="%id" class="magento-variable magento-placeholder mceNonEditable">' +
|
||||
'%s</span>';
|
||||
imageHtml = imageHtml.replace('%s', magentoVariables[match[1]]['variable_name']);
|
||||
} else {
|
||||
imageHtml = '<span id="%id" class="' +
|
||||
'magento-variable magento-placeholder magento-placeholder-error ' +
|
||||
'mceNonEditable' +
|
||||
'">' +
|
||||
'Not found' +
|
||||
'</span>';
|
||||
}
|
||||
|
||||
return imageHtml.replace('%id', Base64.idEncode(path));
|
||||
});
|
||||
|
||||
content = content.gsub(/\{\{customVar code=([^\}\"]+)\}\}/i, function (match) {
|
||||
var path = match[1],
|
||||
magentoVariables,
|
||||
imageHtml;
|
||||
|
||||
magentoVariables = JSON.parse(config.placeholders);
|
||||
|
||||
if (magentoVariables[match[1]] && magentoVariables[match[1]]['variable_type'] === 'custom') {
|
||||
imageHtml = '<span id="%id" class="magento-variable magento-custom-var magento-placeholder ' +
|
||||
'mceNonEditable">%s</span>';
|
||||
imageHtml = imageHtml.replace('%s', magentoVariables[match[1]]['variable_name']);
|
||||
} else {
|
||||
imageHtml = '<span id="%id" class="' +
|
||||
'magento-variable magento-custom-var magento-placeholder ' +
|
||||
'magento-placeholder-error mceNonEditable' +
|
||||
'">' +
|
||||
match[1] +
|
||||
'</span>';
|
||||
}
|
||||
|
||||
return imageHtml.replace('%id', Base64.idEncode(path));
|
||||
});
|
||||
|
||||
return content;
|
||||
},
|
||||
|
||||
/**
|
||||
* Decode variables in content.
|
||||
*
|
||||
* @param {String} content
|
||||
* @returns {String}
|
||||
*/
|
||||
decodeVariables: function (content) {
|
||||
var doc = new DOMParser().parseFromString(content.replace(/"/g, '&quot;'), 'text/html'),
|
||||
returnval = '';
|
||||
|
||||
[].forEach.call(doc.querySelectorAll('span.magento-variable'), function (el) {
|
||||
var $el = jQuery(el);
|
||||
|
||||
if ($el.hasClass('magento-custom-var')) {
|
||||
$el.replaceWith(
|
||||
customDirectiveGenerator.processConfig(
|
||||
Base64.idDecode(
|
||||
$el.attr('id')
|
||||
)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$el.replaceWith(
|
||||
configDirectiveGenerator.processConfig(
|
||||
Base64.idDecode(
|
||||
$el.attr('id')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
returnval += doc.head ? doc.head.innerHTML.replace(/&quot;/g, '"') : '';
|
||||
returnval += doc.body ? doc.body.innerHTML.replace(/&quot;/g, '"') : '';
|
||||
|
||||
return returnval ? returnval : content;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Object}
|
||||
*/
|
||||
getInfo: function () {
|
||||
return {
|
||||
longname: 'Magento Variable Manager Plugin',
|
||||
author: 'Magento Core Team',
|
||||
authorurl: 'http://magentocommerce.com',
|
||||
infourl: 'http://magentocommerce.com',
|
||||
version: '1.0'
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Register plugin
|
||||
*/
|
||||
tinymce.PluginManager.add('magentovariable', tinymce.plugins.magentovariable);
|
||||
};
|
||||
});
|
||||
+262
@@ -0,0 +1,262 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/* global tinymce, widgetTools, Base64 */
|
||||
/* eslint-disable strict */
|
||||
define([
|
||||
'wysiwygAdapter',
|
||||
'mage/adminhtml/events',
|
||||
'mage/adminhtml/wysiwyg/widget'
|
||||
], function (wysiwyg, varienGlobalEvents) {
|
||||
return function (config) {
|
||||
tinymce.create('tinymce.plugins.magentowidget', {
|
||||
|
||||
/**
|
||||
* @param {tinymce.Editor} editor - Editor instance that the plugin is initialized in.
|
||||
*/
|
||||
init: function (editor) {
|
||||
var self = this;
|
||||
|
||||
this.activePlaceholder = null;
|
||||
|
||||
editor.addCommand('mceMagentowidget', function (img) {
|
||||
if (self.activePlaceholder) {
|
||||
img = self.activePlaceholder;
|
||||
}
|
||||
|
||||
widgetTools.setActiveSelectedNode(img);
|
||||
widgetTools.openDialog(
|
||||
config['window_url'] + 'widget_target_id/' + editor.getElement().id + '/'
|
||||
);
|
||||
});
|
||||
|
||||
// Register Widget plugin button
|
||||
editor.ui.registry.addIcon(
|
||||
'magentowidget',
|
||||
'<svg width="24" height="24" viewBox="0 0 32.000000 32.000000" ' +
|
||||
'preserveAspectRatio="xMidYMid meet"> <g transform="translate(0.000000,32.000000) ' +
|
||||
'scale(0.100000,-0.100000)" fill="#000000" stroke="none"> <path d="M130 290 c0 -5 13 -10 30 ' +
|
||||
'-10 22 0 28 -4 24 -15 -5 -11 2 -15 26 -15 21 0 30 -4 28 -12 -7 -20 -40 -22 -50 -4 -5 9 -14 16 ' +
|
||||
'-20 16 -6 0 -19 7 -28 15 -9 8 -25 12 -38 8 -33 -8 -27 -26 8 -21 34 5 40 -6 12 -21 -14 -7 -25 -6 ' +
|
||||
'-40 5 -12 8 -23 10 -27 5 -5 -8 88 -71 105 -71 3 0 29 14 58 31 l53 30 -23 18 c-13 10 -31 20 -40 ' +
|
||||
'24 -10 3 -18 11 -18 17 0 5 -13 10 -30 10 -16 0 -30 -4 -30 -10z m58 -82 c-3 -7 -15 -13 -28 -13 ' +
|
||||
'-13 0 -25 6 -27 13 -3 8 6 12 27 12 21 0 30 -4 28 -12z"/> <path d="M30 151 l0 -60 61 -36 c33 ' +
|
||||
'-19 64 -35 69 -35 5 0 36 16 69 35 l61 36 0 60 0 61 -65 -37 -65 -36 -65 36 -65 37 0 -61z"/> </g>' +
|
||||
'</svg>'
|
||||
);
|
||||
editor.ui.registry.addToggleButton('magentowidget', {
|
||||
icon: 'magentowidget',
|
||||
tooltip: jQuery.mage.__('Insert Widget'),
|
||||
|
||||
/**
|
||||
* execute openVariablesSlideout for onAction callback
|
||||
*/
|
||||
onAction: function () {
|
||||
editor.execCommand('mceMagentowidget');
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a node change handler, selects the button in the UI when a image is selected
|
||||
* @param {ToolbarToggleButtonInstanceApi} api
|
||||
*/
|
||||
onSetup: function (api) {
|
||||
/**
|
||||
* NodeChange handler
|
||||
*/
|
||||
editor.on('NodeChange', function (e) {
|
||||
var placeholder = e.element;
|
||||
|
||||
if (self.isWidgetPlaceholderSelected(placeholder)) {
|
||||
widgetTools.setEditMode(true);
|
||||
api.setActive(true);
|
||||
} else {
|
||||
widgetTools.setEditMode(false);
|
||||
api.setActive(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Add a widget placeholder image double click callback
|
||||
editor.on('dblClick', function (e) {
|
||||
var placeholder = e.target;
|
||||
|
||||
if (self.isWidgetPlaceholderSelected(placeholder)) {
|
||||
widgetTools.setEditMode(true);
|
||||
this.execCommand('mceMagentowidget', null);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Attach event handler for when wysiwyg editor is about to encode its content
|
||||
*/
|
||||
varienGlobalEvents.attachEventHandler('wysiwygEncodeContent', function (content) {
|
||||
content = self.encodeWidgets(self.decodeWidgets(content));
|
||||
content = self.removeDuplicateAncestorWidgetSpanElement(content);
|
||||
|
||||
return content;
|
||||
});
|
||||
|
||||
/**
|
||||
* Attach event handler for when wysiwyg editor is about to decode its content
|
||||
*/
|
||||
varienGlobalEvents.attachEventHandler('wysiwygDecodeContent', function (content) {
|
||||
content = self.decodeWidgets(content);
|
||||
|
||||
return content;
|
||||
});
|
||||
|
||||
/**
|
||||
* Attach event handler for when popups associated with wysiwyg are about to be closed
|
||||
*/
|
||||
varienGlobalEvents.attachEventHandler('wysiwygClosePopups', function () {
|
||||
wysiwyg.closeEditorPopup('widget_window' + wysiwyg.getId());
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} placeholder - Contains the selected node
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isWidgetPlaceholderSelected: function (placeholder) {
|
||||
var isSelected = false;
|
||||
|
||||
if (placeholder.nodeName &&
|
||||
(placeholder.nodeName === 'SPAN' || placeholder.nodeName === 'IMG') &&
|
||||
placeholder.className && placeholder.className.indexOf('magento-widget') !== -1
|
||||
) {
|
||||
this.activePlaceholder = placeholder;
|
||||
isSelected = true;
|
||||
} else {
|
||||
this.activePlaceholder = null;
|
||||
}
|
||||
|
||||
return isSelected;
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert {{widget}} style syntax to image placeholder HTML
|
||||
* @param {String} content
|
||||
* @return {*}
|
||||
*/
|
||||
encodeWidgets: function (content) {
|
||||
return content.gsub(/\{\{widget([\S\s]*?)\}\}/i, function (match) {
|
||||
var attributes = wysiwyg.parseAttributesString(match[1]),
|
||||
imageSrc,
|
||||
imageHtml = '';
|
||||
|
||||
if (attributes.type) {
|
||||
attributes.type = attributes.type.replace(/\\\\/g, '\\');
|
||||
imageSrc = config.placeholders[attributes.type];
|
||||
|
||||
if (imageSrc) {
|
||||
imageHtml += '<span class="magento-placeholder magento-widget mceNonEditable" ' +
|
||||
'contenteditable="false">';
|
||||
} else {
|
||||
imageSrc = config['error_image_url'];
|
||||
imageHtml += '<span ' +
|
||||
'class="magento-placeholder magento-placeholder-error magento-widget mceNonEditable" ' +
|
||||
'contenteditable="false">';
|
||||
}
|
||||
|
||||
imageHtml += '<img';
|
||||
imageHtml += ' id="' + Base64.idEncode(match[0]) + '"';
|
||||
imageHtml += ' src="' + imageSrc + '"';
|
||||
imageHtml += ' />';
|
||||
|
||||
if (config.types[attributes.type]) {
|
||||
imageHtml += config.types[attributes.type];
|
||||
}
|
||||
|
||||
imageHtml += '</span>';
|
||||
|
||||
return imageHtml;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert image placeholder HTML to {{widget}} style syntax
|
||||
* @param {String} content
|
||||
* @return {*}
|
||||
*/
|
||||
decodeWidgets: function (content) {
|
||||
return content.gsub(
|
||||
/(<span class="[^"]*magento-widget[^"]*"[^>]*>)?<img([^>]+id="[^>]+)>(([^>]*)<\/span>)?/i,
|
||||
function (match) {
|
||||
var attributes = wysiwyg.parseAttributesString(match[2]),
|
||||
widgetCode,
|
||||
result = match[0];
|
||||
|
||||
if (attributes.id) {
|
||||
try {
|
||||
widgetCode = Base64.idDecode(attributes.id);
|
||||
} catch (e) {
|
||||
// Ignore and continue.
|
||||
}
|
||||
|
||||
if (widgetCode && widgetCode.indexOf('{{widget') !== -1) {
|
||||
result = widgetCode;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Tinymce has strange behavior with html and this removes one of its side-effects
|
||||
* @param {String} content
|
||||
* @return {String}
|
||||
*/
|
||||
removeDuplicateAncestorWidgetSpanElement: function (content) {
|
||||
var parser, doc, returnval = '';
|
||||
|
||||
if (!window.DOMParser) {
|
||||
return content;
|
||||
}
|
||||
|
||||
parser = new DOMParser();
|
||||
doc = parser.parseFromString(content.replace(/"/g, '&quot;'), 'text/html');
|
||||
|
||||
[].forEach.call(doc.querySelectorAll('.magento-widget'), function (widgetEl) {
|
||||
var widgetChildEl = widgetEl.querySelector('.magento-widget');
|
||||
|
||||
if (!widgetChildEl) {
|
||||
return;
|
||||
}
|
||||
|
||||
[].forEach.call(widgetEl.childNodes, function (el) {
|
||||
widgetEl.parentNode.insertBefore(el, widgetEl);
|
||||
});
|
||||
|
||||
widgetEl.parentNode.removeChild(widgetEl);
|
||||
});
|
||||
|
||||
returnval += doc.head ? doc.head.innerHTML.replace(/&quot;/g, '"') : '';
|
||||
returnval += doc.body ? doc.body.innerHTML.replace(/&quot;/g, '"') : '';
|
||||
|
||||
return returnval ? returnval : content;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Object}
|
||||
*/
|
||||
getInfo: function () {
|
||||
return {
|
||||
longname: 'Magento Widget Manager Plugin',
|
||||
author: 'Magento Core Team',
|
||||
authorurl: 'http://magentocommerce.com',
|
||||
infourl: 'http://magentocommerce.com',
|
||||
version: '1.0'
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// Register plugin
|
||||
tinymce.PluginManager.add('magentowidget', tinymce.plugins.magentowidget);
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user