[BUGFIX] Fix usage of TYPO3.Storage JS and Tabs.js 65/43965/6
authorMarkus Klein <markus.klein@typo3.org>
Sat, 10 Oct 2015 14:08:41 +0000 (16:08 +0200)
committerFrank Nägler <frank.naegler@typo3.org>
Mon, 12 Oct 2015 14:10:29 +0000 (16:10 +0200)
The Storage module must be required as dependency in modules as usual.
The module itself has to take care whether a global object
is already present. If this is the case, the global object is used.

Additionally the Tabs.js is fixed to work again.

Resolves: #70568
Releases: master
Change-Id: I808fb1e9d7760d93f578696e2ae1cb6c45bc2a91
Reviewed-on: http://review.typo3.org/43965
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
typo3/sysext/backend/Resources/Public/JavaScript/PageActions.js
typo3/sysext/backend/Resources/Public/JavaScript/Storage.js
typo3/sysext/backend/Resources/Public/JavaScript/Tabs.js
typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/SystemInformationMenu.js
typo3/sysext/viewpage/Resources/Public/JavaScript/Main.js

index e984ed4..a25f5fa 100644 (file)
@@ -14,7 +14,7 @@
 /**
  * JavaScript implementations for page actions
  */
-define(['jquery'], function($) {
+define(['jquery', 'TYPO3/CMS/Backend/Storage'], function($, Storage) {
        'use strict';
 
        var PageActions = {
@@ -91,7 +91,7 @@ define(['jquery'], function($) {
                        $hiddenElements.slideUp();
                }
 
-               top.TYPO3.Storage.Persistent.set('moduleData.web_layout.tt_content_showHidden', $me.prop('checked') ? 1 : 0).done(function() {
+               Storage.Persistent.set('moduleData.web_layout.tt_content_showHidden', $me.prop('checked') ? 1 : 0).done(function() {
                        $spinner.remove();
                        $me.show();
                });
@@ -212,7 +212,7 @@ define(['jquery'], function($) {
                });
        };
 
-       $(document).ready(function() {
+       $(function() {
                PageActions.initializeElements();
                PageActions.initializeEvents();
                PageActions.documentIsReady = true;
index b9e8468..979bb9d 100644 (file)
  * available via TYPO3.Storage.Persistent
  */
 define(['jquery'], function ($) {
+       'use strict';
+
+       // fetch from opening window
+       if (window.opener && window.opener.TYPO3 && window.opener.TYPO3.Storage) {
+               return window.opener.TYPO3.Storage;
+       }
+
+       // fetch from parent
+       if (parent && parent.window.TYPO3 && parent.window.TYPO3.Storage) {
+               return parent.window.TYPO3.Storage;
+       }
+
+       // fetch object from outer frame
+       if (top && top.TYPO3.Storage) {
+               return top.TYPO3.Storage;
+       }
+
+       // we didn't find an existing object, so create it
        var Storage = {
                Client: {},
                Persistent: {
@@ -171,11 +189,8 @@ define(['jquery'], function ($) {
                }
        };
 
-       /**
-        * return the Storage object, and attach it to the global TYPO3 object on the global frame
-        */
-       return function() {
-               top.TYPO3.Storage = Storage;
-               return Storage;
-       }();
+       // attach to global frame
+       TYPO3.Storage = Storage;
+
+       return Storage;
 });
index 68f8246..d50592a 100644 (file)
  * This class handle the tabs in the TYPO3 backend.
  * It stores the last active tab and open it again after a reload,
  */
-define(['jquery', 'TYPO3/CMS/Backend/Storage', 'bootstrap'], function ($) {
+define(['jquery', 'TYPO3/CMS/Backend/Storage', 'bootstrap'], function ($, Storage) {
+       'use strict';
 
        /**
         * Tabs helper
         *
-        * @type {{storage: (Storage.Client|*), cacheTimeInSeconds: number, storeLastActiveTab: number}}
+        * @type {{storage: (Storage.Client|*), cacheTimeInSeconds: number, storeLastActiveTab: bool}}
         */
        var Tabs = {
-               storage: top.TYPO3.Storage.Client,
-               // cache liftime in seconds
+               storage: Storage.Client,
+               // cache lifetime in seconds
                cacheTimeInSeconds: 1800,
-               storeLastActiveTab: 1
-       };
-
-       /**
-        * initialize Tabs Helper
-        */
-       Tabs.initialize = function() {
-               $('.t3js-tabs').each(function() {
-                       var $tabContainer = $(this);
-                       Tabs.storeLastActiveTab = $tabContainer.data('store-last-tab') == '1' ? 1 : 0;
-                       $tabContainer.find('a[href="' + Tabs.receiveActiveTab($tabContainer.attr('id')) + '"]').tab('show');
-                       $tabContainer.on('show.bs.tab', function(e) {
-                               if (Tabs.storeLastActiveTab == 1) {
-                                       var id = e.currentTarget.id;
-                                       var target = e.target.hash;
-                                       Tabs.storeActiveTab(id, target);
-                               }
-                       });
-               });
+               storeLastActiveTab: true
        };
 
        /**
@@ -82,11 +65,23 @@ define(['jquery', 'TYPO3/CMS/Backend/Storage', 'bootstrap'], function ($) {
                return Math.round((new Date()).getTime() / 1000);
        };
 
-       /**
-        * return the Tabs object
-        */
-       return function() {
-               Tabs.initialize();
-               return Tabs;
-       }();
+       $(function () {
+               $('.t3js-tabs').each(function() {
+                       var $tabContainer = $(this);
+                       Tabs.storeLastActiveTab = $tabContainer.data('storeLastTab') === 1;
+                       var currentActiveTab = Tabs.receiveActiveTab($tabContainer.attr('id'));
+                       if (currentActiveTab) {
+                               $tabContainer.find('a[href="' + currentActiveTab + '"]').tab('show');
+                       }
+                       $tabContainer.on('show.bs.tab', function(e) {
+                               if (Tabs.storeLastActiveTab) {
+                                       var id = e.currentTarget.id;
+                                       var target = e.target.hash;
+                                       Tabs.storeActiveTab(id, target);
+                               }
+                       });
+               });
+       });
+
+       return Tabs;
 });
index 4b29e75..02a3f04 100644 (file)
@@ -14,7 +14,9 @@
 /**
  * System information menu handler
  */
-define(['jquery', 'TYPO3/CMS/Backend/Storage'], function($) {
+define(['jquery', 'TYPO3/CMS/Backend/Storage'], function($, Storage) {
+       'use strict';
+
        var SystemInformationMenu = {
                identifier: {
                        containerSelector: '#typo3-cms-backend-backend-toolbaritems-systeminformationtoolbaritem',
@@ -62,7 +64,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Storage'], function($) {
 
                                SystemInformationMenu.initialize();
                        }
-               })
+               });
        };
 
        /**
@@ -91,28 +93,23 @@ define(['jquery', 'TYPO3/CMS/Backend/Storage'], function($) {
                var storedSystemInformationSettings = {},
                        moduleStorageObject = {},
                        requestedModule = $(e.currentTarget).data('modulename'),
-                       timestamp = Math.floor((new Date).getTime() / 1000);
+                       timestamp = Math.floor((new Date()).getTime() / 1000);
 
-               if (TYPO3.Storage.Persistent.isset('systeminformation')) {
-                       storedSystemInformationSettings = JSON.parse(TYPO3.Storage.Persistent.get('systeminformation'));
+               if (Storage.Persistent.isset('systeminformation')) {
+                       storedSystemInformationSettings = JSON.parse(Storage.Persistent.get('systeminformation'));
                }
 
                moduleStorageObject[requestedModule] = {lastAccess: timestamp};
                $.extend(true, storedSystemInformationSettings, moduleStorageObject);
-               TYPO3.Storage.Persistent.set('systeminformation', JSON.stringify(storedSystemInformationSettings)).done(function() {
+               var $ajax = Storage.Persistent.set('systeminformation', JSON.stringify(storedSystemInformationSettings));
+               $ajax.done(function() {
                        // finally, open the module now
                        TYPO3.ModuleMenu.App.showModule(requestedModule);
                        SystemInformationMenu.updateMenu();
                });
        };
 
-       /**
-        * Initialize and return the SystemInformationMenu object
-        */
-       $(document).ready(function() {
-               SystemInformationMenu.updateMenu();
-       });
+       $(SystemInformationMenu.updateMenu);
 
-       TYPO3.SystemInformationMenu = SystemInformationMenu;
        return SystemInformationMenu;
 });
index 1dec389..558ac2f 100644 (file)
 /**
  * Main logic for resizing the view of the frame
  */
-define(['jquery', 'jquery-ui/resizable'], function($) {
-       "use strict";
-
-       // fetch the storage from the outer frame
-       var Storage = top.TYPO3.Storage;
+define(['jquery', 'TYPO3/CMS/Backend/Storage', 'jquery-ui/resizable'], function($, Storage) {
+       'use strict';
 
        var ViewPage = {
                resizableContainerIdentifier: '#resizeable',
                widthSelectorIdentifier: '#width',
+               moduleBodySelector: '.t3js-module-body',
                storagePrefix: 'moduleData.web_view.States.'
        };
 
@@ -124,7 +122,8 @@ define(['jquery', 'jquery-ui/resizable'], function($) {
 
        ViewPage.calculateContainerMaxHeight = function() {
                ViewPage.$resizableContainer.hide();
-               var padding = $('.t3js-module-body').outerHeight() - $('.t3js-module-body').height(),
+               var $moduleBody = $(ViewPage.moduleBodySelector);
+               var padding = $moduleBody.outerHeight() - $moduleBody.height(),
                        controlsHeight = ViewPage.$widthSelector.parents('form:first').height(),
                        documentHeight = $(document).height();
                ViewPage.$resizableContainer.show();