Skip to content
Snippets Groups Projects
Commit da9da511 authored by Frank Naegler's avatar Frank Naegler Committed by Christian Kuhn
Browse files

[TASK] Migrate EXT:backend Tabs.js to TypeScript

Resolves: #82604
Releases: master
Change-Id: I9b9ff38c635902f2713602955ad9a3d04734ec88
Reviewed-on: https://review.typo3.org/54367


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: default avatarAndreas Fernandez <typo3@scripting-base.de>
Reviewed-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 41913e40
Branches
Tags
No related merge requests found
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
import $ = require('jquery');
import 'bootstrap';
import Client = require('./Storage/Client');
/**
* Module: TYPO3/CMS/Backend/Tabs
* @exports TYPO3/CMS/Backend/Tabs
*/
class Tabs {
/**
* Resolve timestamp
*/
public static getTimestamp(): number {
return Math.round((new Date()).getTime() / 1000);
}
public storage: any;
protected cacheTimeInSeconds = 1800;
protected storeLastActiveTab = true;
constructor() {
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);
}
});
});
}
/**
* Receive active tab from storage
*
* @param {string} id
* @returns {string}
*/
public receiveActiveTab(id: string): string {
const target = this.storage.get(id) || '';
const expire = this.storage.get(id + '.expire') || 0;
if (expire > Tabs.getTimestamp()) {
return target;
}
return '';
}
/**
* Set active tab to storage
*
* @param {string} id
* @param {string} target
*/
public storeActiveTab(id: string, target: string) {
this.storage.set(id, target);
this.storage.set(id + '.expire', Tabs.getTimestamp() + this.cacheTimeInSeconds);
}
}
const tabs = new Tabs();
export = tabs;
...@@ -10,80 +10,66 @@ ...@@ -10,80 +10,66 @@
* *
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
define(["require", "exports", "jquery", "./Storage/Client", "bootstrap"], function (require, exports, $, Client) {
/** "use strict";
* Module: TYPO3/CMS/Backend/Tabs /**
* This class handle the tabs in the TYPO3 backend. * Module: TYPO3/CMS/Backend/Tabs
* It stores the last active tab and open it again after a reload, * @exports TYPO3/CMS/Backend/Tabs
*/ */
define(['jquery', 'TYPO3/CMS/Backend/Storage/Client', 'bootstrap'], function ($, ClientStorage) { var Tabs = (function () {
'use strict'; function Tabs() {
this.cacheTimeInSeconds = 1800;
/** this.storeLastActiveTab = true;
* Tabs helper this.storage = Client;
* var that = this;
* @type {{storage: (ClientStorage|*), cacheTimeInSeconds: number, storeLastActiveTab: bool}} $('.t3js-tabs').each(function () {
* @exports TYPO3/CMS/Backend/Tabs var $tabContainer = $(this);
*/ that.storeLastActiveTab = $tabContainer.data('storeLastTab') === 1;
var Tabs = { var currentActiveTab = that.receiveActiveTab($tabContainer.attr('id'));
storage: ClientStorage, if (currentActiveTab) {
// cache lifetime in seconds $tabContainer.find('a[href="' + currentActiveTab + '"]').tab('show');
cacheTimeInSeconds: 1800, }
storeLastActiveTab: true $tabContainer.on('show.bs.tab', function (e) {
}; if (that.storeLastActiveTab) {
var id = e.currentTarget.id;
/** var target = e.target.hash;
* Receive active tab from storage that.storeActiveTab(id, target);
* }
* @param {String} id });
* @returns {String} });
*/ }
Tabs.receiveActiveTab = function(id) { /**
var target = Tabs.storage.get(id) || ''; * Resolve timestamp
var expire = Tabs.storage.get(id + '.expire') || 0; */
if (expire > Tabs.getTimestamp()) { Tabs.getTimestamp = function () {
return target; return Math.round((new Date()).getTime() / 1000);
} };
return ''; /**
}; * Receive active tab from storage
*
/** * @param {string} id
* Store active tab in storage * @returns {string}
* */
* @param {String} id Tabs.prototype.receiveActiveTab = function (id) {
* @param {String} target var target = this.storage.get(id) || '';
*/ var expire = this.storage.get(id + '.expire') || 0;
Tabs.storeActiveTab = function(id, target) { if (expire > Tabs.getTimestamp()) {
Tabs.storage.set(id, target); return target;
Tabs.storage.set(id + '.expire', Tabs.getTimestamp() + Tabs.cacheTimeInSeconds); }
}; return '';
};
/** /**
* Get unixtimestamp * Set active tab to storage
* *
* @returns {Number} * @param {string} id
*/ * @param {string} target
Tabs.getTimestamp = function() { */
return Math.round((new Date()).getTime() / 1000); Tabs.prototype.storeActiveTab = function (id, target) {
}; this.storage.set(id, target);
this.storage.set(id + '.expire', Tabs.getTimestamp() + this.cacheTimeInSeconds);
$(function () { };
$('.t3js-tabs').each(function() { return Tabs;
var $tabContainer = $(this); }());
Tabs.storeLastActiveTab = $tabContainer.data('storeLastTab') === 1; var tabs = new Tabs();
var currentActiveTab = Tabs.receiveActiveTab($tabContainer.attr('id')); return tabs;
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;
}); });
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment