From f47d18467f297e9d00a8240f3539d7a9b5e749b3 Mon Sep 17 00:00:00 2001 From: Andreas Fernandez Date: Wed, 9 Dec 2015 16:41:02 +0100 Subject: [PATCH] [TASK] Make JavaScript Icon API a singleton The JavaScript Icon API is now a singleton. This ensures the code is only executed once and especially the cache is shared between all requests. Resolves: #72126 Releases: master Change-Id: Iafd61b90d2414f655e6500bc564b90490afc58b0 Reviewed-on: https://review.typo3.org/45196 Reviewed-by: Wouter Wolters Reviewed-by: Markus Klein Tested-by: Markus Klein Reviewed-by: Josef Glatz Reviewed-by: Morton Jonuschat Tested-by: Morton Jonuschat Reviewed-by: Frans Saris Tested-by: Frans Saris --- .../Resources/Public/JavaScript/Icons.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/Icons.js b/typo3/sysext/backend/Resources/Public/JavaScript/Icons.js index bc922033bb8d..4ba978983f09 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/Icons.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/Icons.js @@ -18,6 +18,28 @@ define(['jquery'], function($) { 'use strict'; + try { + // fetch from opening window + if (window.opener && window.opener.TYPO3 && window.opener.TYPO3.Icons) { + return window.opener.TYPO3.Icons; + } + + // fetch from parent + if (parent && parent.window.TYPO3 && parent.window.TYPO3.Icons) { + return parent.window.TYPO3.Icons; + } + + // fetch object from outer frame + if (top && top.TYPO3.Icons) { + return top.TYPO3.Icons; + } + } catch (e) { + // This only happens if the opener, parent or top is some other url (eg a local file) + // which loaded the current window. Then the browser's cross domain policy jumps in + // and raises an exception. + // For this case we are safe and we can create our global object below. + } + /** * * @type {{cache: {}, sizes: {small: string, default: string, large: string, overlay: string}, states: {default: string, disabled: string}}} @@ -124,5 +146,8 @@ define(['jquery'], function($) { Icons.cache[cacheIdentifier] = markup; }; + // attach to global frame + TYPO3.Icons = Icons; + return Icons; }); -- 2.20.1