![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/libs/absol-full/dist/js/ |
Upload File : |
/*** module: node_modules/absol-acomp/js/ckeditor/CKTemplatePlaceholder.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseCKTemplate = parseCKTemplate; exports.default = void 0; var _CKPlaceholder = _interopRequireDefault(require("./CKPlaceholder")); var _OOP = _interopRequireDefault(require("absol/src/HTML5/OOP")); var _ACore = _interopRequireWildcard(require("../../ACore")); var _utils = require("../utils"); var _base = require("absol/src/Converter/base64"); function parseCKTemplate(data, replacements) { var replaceF = replacements; if (typeof replacements !== "function") { replaceF = function (variable) { return replacements[variable] || '{{' + variable + '}}'; }; } return data.replace(/\{\{([a-zA-Z_$]([a-zA-Z_$0-9]*))(\.([a-zA-Z_$]([a-zA-Z_$0-9]*)))*\}\}/g, function (all) { var variable = all.substr(2, all.length - 2); return replaceF(variable) || '{{' + variable + '}}'; }.bind(this)); } /*** * @extends CKPlaceholder * @constructor */ function CKTemplatePlaceholder() { _CKPlaceholder.default.call(this); } _OOP.default.mixClass(CKTemplatePlaceholder, _CKPlaceholder.default); CKTemplatePlaceholder.property = Object.assign({}, _CKPlaceholder.default.property); CKTemplatePlaceholder.eventHandler = Object.assign({}, _CKPlaceholder.default.eventHandler); CKTemplatePlaceholder.tag = 'CKTemplatePlaceholder'.toLowerCase(); CKTemplatePlaceholder.render = function () { return (0, _ACore._)({ tag: 'as-ck-template-placeholder', extendEvent: ['editorcreated', 'editorready', 'command_add_variable'] }); }; CKTemplatePlaceholder.prototype.makeDefaultConfig = function (config) { config.toolbar = [{ name: 'feature', items: ['add_variable'] }, { name: 'clipboard', groups: ['clipboard', 'undo'], items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] }, { name: 'editing', groups: ['find', 'selection'], items: ['Find', 'Replace', '-', 'SelectAll'] }, '/', { name: 'basicstyles', groups: ['basicstyles', 'cleanup'], items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'CopyFormatting', 'RemoveFormat'] }, { name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi'], items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl'] }, { name: 'links', items: ['Link', 'Unlink', 'Anchor'] }, { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak'] }, '/', { name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] }, { name: 'colors', items: ['TextColor', 'BGColor'] }, { name: 'tools', items: ['Maximize', 'ShowBlocks'] }, { name: 'others', items: ['-'] }, { name: 'about', items: ['About'] }]; config.styles = { 'font-family': 'Arial', 'font-size': '14px' }; return config; }; CKTemplatePlaceholder.prototype.makeConfig = function (config) { this.makeDefaultConfig(config); if (typeof this.userMakeConfig === "function") this.userMakeConfig(config); return config; }; CKTemplatePlaceholder.prototype._setupTemplatePlugin = function () { var editor = this.editor; editor.ui.addButton('add_variable', { label: 'Add Variable', command: 'add_variable', icon: 'as-variable-box-ico' }); var cmd = editor.addCommand('add_variable', { exec: function () { this.emit('command_add_variable', { type: 'commandaddvariable', editor: this.editor, target: this }, this); }.bind(this) }); }; /*** * @this CKTemplatePlaceholder ***/ CKTemplatePlaceholder.eventHandler.attached = function () { this.$attachhook.remove(); this.editor = CKEDITOR.replace(this, this.makeConfig(this.config)); this.editor.on('instanceReady', this.eventHandler.instanceReady); if (this._pendingData.length > 0) { this.editor.setData(this._pendingData); this._pendingData = null; } this._setupTemplatePlugin(); this.emit('editorcreated', { type: 'editorcreated', target: this, editor: this.editor }, this); }; CKTemplatePlaceholder.prototype._makeVariableHtml = function (variable, text) { text = '{{' + text + '}}'; var width = (0, _utils.measureText)(text, '16px arial').width; var img = '<?xml version="1.0" encoding="UTF-8"?>\n' + '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 ' + (width + 2) + ' 24">\n' + ' <text style="font-family:Arial;font-size:16px;fill:blue" x="1" y="20">' + text + '</text>\n' + '</svg>'; var n64Ulr = 'data:image/svg+xml;base64,' + (0, _base.base64EncodeUnicode)(img); return '<img style="position: relative;bottom: -0.2em;height:1.5em; font-size: inherit;display: inline;" alt="{{' + variable + '}}" src="' + n64Ulr + '"></img>'; }; /** * @param {{value:string, text: string}} item */ CKTemplatePlaceholder.prototype.insertVariable = function (item) { console.log(this._makeVariableHtml(item.value, item.text || item.value)); this.editor.insertHtml(this._makeVariableHtml(item.value, item.text || item.value)); }; CKTemplatePlaceholder.prototype.dataExplicit = function (data) { var div = document.createElement('div'); div.innerHTML = data; (0, _ACore.$$)('img', div).forEach(function (elt) { var alt = elt.attr('alt'); var isVar = alt && !!alt.match(/^\{\{([a-zA-Z_$]([a-zA-Z_$0-9]*))(\.([a-zA-Z_$]([a-zA-Z_$0-9]*)))*\}\}$/); var textNode; if (isVar) { textNode = document.createTextNode(alt); elt.parentElement.replaceChild(textNode, elt); } }); return div.innerHTML; }; CKTemplatePlaceholder.prototype.dataImplicit = function (data) { if (typeof data !== "string") data = ''; var var2text = this.variable2Text || {}; return parseCKTemplate(data, function (variable) { return this._makeVariableHtml(variable, var2text[variable] || variable); }.bind(this)); }; CKTemplatePlaceholder.property.data = { set: function (data) { if (typeof data !== "string") data = ''; data = this.dataImplicit(data); if (this.editor) { this.editor.setData(data); } else { this._pendingData = data; } }, get: function () { if (this.editor) return this.editor.getData(); return this.dataExplicit(this._pendingData); } }; _ACore.default.install(CKTemplatePlaceholder); var _default = CKTemplatePlaceholder; exports.default = _default;