[BUGFIX] Set active tab when DOM is ready 55/59055/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 7 Dec 2018 18:01:27 +0000 (19:01 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 7 Dec 2018 18:18:37 +0000 (19:18 +0100)
The latest used tab must be set to active only when the DOM has been
loaded.

Resolves: #84027
Releases: master
Change-Id: I52c8c190c5e58f1793335470427fc18203e4c561
Reviewed-on: https://review.typo3.org/59055
Reviewed-by: Florian Peters <fpeters1392@googlemail.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Florian Peters <fpeters1392@googlemail.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Resources/Private/TypeScript/Tabs.ts
typo3/sysext/backend/Resources/Public/JavaScript/Tabs.js

index 5b4f1b6..2d75c2b 100644 (file)
@@ -36,19 +36,21 @@ class Tabs {
     this.storage = Client;
 
     const that = this;
-    $('.t3js-tabs').each(function(this: Element): void {
-      const $tabContainer: JQuery = $(this);
-      that.storeLastActiveTab = $tabContainer.data('storeLastTab') === 1;
-      const currentActiveTab = that.receiveActiveTab($tabContainer.attr('id'));
-      if (currentActiveTab) {
-        $tabContainer.find('a[href="' + currentActiveTab + '"]').tab('show');
-      }
-      $tabContainer.on('show.bs.tab', (e: any) => {
-        if (that.storeLastActiveTab) {
-          const id = e.currentTarget.id;
-          const target = e.target.hash;
-          that.storeActiveTab(id, target);
+    $((): void => {
+      $('.t3js-tabs').each(function(this: Element): void {
+        const $tabContainer: JQuery = $(this);
+        that.storeLastActiveTab = $tabContainer.data('storeLastTab') === 1;
+        const currentActiveTab = that.receiveActiveTab($tabContainer.attr('id'));
+        if (currentActiveTab) {
+          $tabContainer.find('a[href="' + currentActiveTab + '"]').tab('show');
         }
+        $tabContainer.on('show.bs.tab', (e: any) => {
+          if (that.storeLastActiveTab) {
+            const id = e.currentTarget.id;
+            const target = e.target.hash;
+            that.storeActiveTab(id, target);
+          }
+        });
       });
     });
   }
index cd05935..91fb418 100644 (file)
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","jquery","./Storage/Client","bootstrap"],function(t,e,r,i){"use strict";return new(function(){function t(){this.cacheTimeInSeconds=1800,this.storeLastActiveTab=!0,this.storage=i;var t=this;r(".t3js-tabs").each(function(){var e=r(this);t.storeLastActiveTab=1===e.data("storeLastTab");var i=t.receiveActiveTab(e.attr("id"));i&&e.find('a[href="'+i+'"]').tab("show"),e.on("show.bs.tab",function(e){if(t.storeLastActiveTab){var r=e.currentTarget.id,i=e.target.hash;t.storeActiveTab(r,i)}})})}return t.getTimestamp=function(){return Math.round((new Date).getTime()/1e3)},t.prototype.receiveActiveTab=function(e){var r=this.storage.get(e)||"";return(this.storage.get(e+".expire")||0)>t.getTimestamp()?r:""},t.prototype.storeActiveTab=function(e,r){this.storage.set(e,r),this.storage.set(e+".expire",t.getTimestamp()+this.cacheTimeInSeconds)},t}())});
\ No newline at end of file
+define(["require","exports","jquery","./Storage/Client","bootstrap"],function(t,e,i,r){"use strict";return new(function(){function t(){this.cacheTimeInSeconds=1800,this.storeLastActiveTab=!0,this.storage=r;var t=this;i(function(){i(".t3js-tabs").each(function(){var e=i(this);t.storeLastActiveTab=1===e.data("storeLastTab");var r=t.receiveActiveTab(e.attr("id"));r&&e.find('a[href="'+r+'"]').tab("show"),e.on("show.bs.tab",function(e){if(t.storeLastActiveTab){var i=e.currentTarget.id,r=e.target.hash;t.storeActiveTab(i,r)}})})})}return t.getTimestamp=function(){return Math.round((new Date).getTime()/1e3)},t.prototype.receiveActiveTab=function(e){var i=this.storage.get(e)||"";return(this.storage.get(e+".expire")||0)>t.getTimestamp()?i:""},t.prototype.storeActiveTab=function(e,i){this.storage.set(e,i),this.storage.set(e+".expire",t.getTimestamp()+this.cacheTimeInSeconds)},t}())});
\ No newline at end of file