Skip to content

Commit 33ce062

Browse files
committed
[ADD] evo links plugin
1 parent f8d88f1 commit 33ce062

6 files changed

Lines changed: 2936 additions & 3 deletions

File tree

plugins/eTinyMCEPlugin.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ function eTinyMCE_themeCssUrls($value): array
454454
$urlStrategy = 'relative';
455455
}
456456

457+
$linkEvoPath = MODX_BASE_PATH . 'assets/plugins/eTinyMCE/js/link-evo.js';
458+
$linkEvoMtime = @filemtime($linkEvoPath);
459+
$cacheBust = is_int($linkEvoMtime) ? (string)$linkEvoMtime : '';
460+
457461
$fileManagerConfig = [
458462
'enabled' => $fileManagerEnabled,
459463
'urlPrefix' => $lfmUrlPrefix,
@@ -470,6 +474,7 @@ function eTinyMCE_themeCssUrls($value): array
470474
'baseUrl' => $siteBaseUrl,
471475
'whichBrowser' => $whichBrowser,
472476
'fileManager' => $fileManagerConfig,
477+
'cacheBust' => $cacheBust,
473478
], JSON_UNESCAPED_SLASHES);
474479

475480
if ($configJson === false) {
@@ -478,7 +483,10 @@ function eTinyMCE_themeCssUrls($value): array
478483
}
479484

480485
$output[] = '<script>window.eTinyMCEConfig=' . $configJson . ';</script>';
481-
$output[] = '<script src="' . $baseUrl . '/js/etinymce-init.js"></script>';
486+
$initScriptPath = MODX_BASE_PATH . 'assets/plugins/eTinyMCE/js/etinymce-init.js';
487+
$initMtime = @filemtime($initScriptPath);
488+
$initVersion = is_int($initMtime) ? ('?v=' . $initMtime) : '';
489+
$output[] = '<script src="' . $baseUrl . '/js/etinymce-init.js' . $initVersion . '"></script>';
482490

483491
return implode("\n", $output);
484492
});

public/js/etinymce-init.js

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,47 @@
256256

257257
var profiles = window.eTinyMCEProfiles || {};
258258
var defaultKey = cfg.defaultProfile || '';
259+
var tinymceBaseUrl = normalizedBaseUrl + '/assets/plugins/eTinyMCE/tinymce';
260+
261+
function normalizePluginList(value) {
262+
if (Array.isArray(value)) {
263+
return value.slice();
264+
}
265+
if (typeof value === 'string') {
266+
// Split on whitespace and commas without treating "s" as a separator.
267+
return value.split(/[\s,]+/).filter(Boolean);
268+
}
269+
return [];
270+
}
271+
272+
function ensurePlugin(options, pluginName) {
273+
var list = normalizePluginList(options.plugins);
274+
if (list.indexOf(pluginName) === -1) {
275+
list.push(pluginName);
276+
}
277+
options.plugins = list.join(' ');
278+
}
279+
280+
function ensureExternalPlugin(options, name, url) {
281+
if (!url) {
282+
return;
283+
}
284+
var external = options.external_plugins;
285+
if (!external || typeof external !== 'object') {
286+
external = {};
287+
}
288+
if (!external[name]) {
289+
external[name] = url;
290+
}
291+
options.external_plugins = external;
292+
}
293+
294+
function normalizePluginsFromProfile(profileOptions) {
295+
if (!profileOptions || typeof profileOptions !== 'object') {
296+
return [];
297+
}
298+
return normalizePluginList(profileOptions.plugins);
299+
}
259300

260301
queue.forEach(function (item) {
261302
var profileKey = item.profile;
@@ -269,15 +310,43 @@
269310
}
270311
}
271312

272-
var profileOptions = profiles[profileKey] || {};
313+
var profileOptions = Object.assign({}, profiles[profileKey] || {});
314+
var profilePlugins = normalizePluginsFromProfile(profileOptions);
315+
var evolinksDefaults = {
316+
searchUrl: normalizedBaseUrl + '/evo-link-search',
317+
minChars: 2,
318+
debounce: 250,
319+
limit: 10,
320+
outputMode: 'placeholder',
321+
includeUnpublished: false,
322+
enableTree: true,
323+
cacheSize: 20
324+
};
325+
326+
var evolinksOverrides = {};
327+
if (profileOptions.evolinks && typeof profileOptions.evolinks === 'object') {
328+
evolinksOverrides = Object.assign({}, profileOptions.evolinks);
329+
}
330+
if (item.options && item.options.evolinks && typeof item.options.evolinks === 'object') {
331+
evolinksOverrides = Object.assign(evolinksOverrides, item.options.evolinks);
332+
}
333+
profileOptions.evolinks = Object.assign({}, evolinksDefaults, evolinksOverrides);
273334
var baseOptions = {
274335
selector: item.selectors,
275336
file_picker_callback: window.eTinyMCEFilePicker,
276337
setup: window.eTinyMCESetup,
277-
license_key: 'gpl'
338+
license_key: 'gpl',
339+
base_url: tinymceBaseUrl,
340+
suffix: '.min'
278341
};
279342

280343
var initOptions = Object.assign({}, profileOptions, item.options || {}, baseOptions);
344+
if (profilePlugins.length) {
345+
initOptions.plugins = profilePlugins.join(' ');
346+
}
347+
var linkCacheBust = cfg.cacheBust || '';
348+
var linkUrl = normalizedBaseUrl + '/assets/plugins/eTinyMCE/js/link-evo.js' + (linkCacheBust ? ('?v=' + encodeURIComponent(linkCacheBust)) : '');
349+
ensureExternalPlugin(initOptions, 'link', linkUrl);
281350
tinymce.init(initOptions);
282351
});
283352
})();

0 commit comments

Comments
 (0)