|
256 | 256 |
|
257 | 257 | var profiles = window.eTinyMCEProfiles || {}; |
258 | 258 | 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 | + } |
259 | 300 |
|
260 | 301 | queue.forEach(function (item) { |
261 | 302 | var profileKey = item.profile; |
|
269 | 310 | } |
270 | 311 | } |
271 | 312 |
|
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); |
273 | 334 | var baseOptions = { |
274 | 335 | selector: item.selectors, |
275 | 336 | file_picker_callback: window.eTinyMCEFilePicker, |
276 | 337 | setup: window.eTinyMCESetup, |
277 | | - license_key: 'gpl' |
| 338 | + license_key: 'gpl', |
| 339 | + base_url: tinymceBaseUrl, |
| 340 | + suffix: '.min' |
278 | 341 | }; |
279 | 342 |
|
280 | 343 | 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); |
281 | 350 | tinymce.init(initOptions); |
282 | 351 | }); |
283 | 352 | })(); |
0 commit comments