[TASK] Make JavaScript Icon API a singleton 96/45196/4
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 9 Dec 2015 15:41:02 +0000 (16:41 +0100)
committerFrans Saris <franssaris@gmail.com>
Fri, 11 Dec 2015 09:15:44 +0000 (10:15 +0100)
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 <typo3@wouterwolters.nl>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/backend/Resources/Public/JavaScript/Icons.js

index bc92203..4ba9789 100644 (file)
 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;
 });