CoreFiles by mySites.guru
tabs-state.js52 lines, 1,829 bytes, from Joomla_3.4.3-Stable-Full_Package.zip
Raw History Compare with 3.4.2
md5
26f97eebd016646e9f75ef6666bd4a2a
sha1
6e5fe9cb9d64244474ab01104aecdfb08f680fa4
sha256
75ca0724aa909dca540ba1940bcb7d691a3d72c3b9d2909a359d88724121df9a
/**
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

/**
 * JavaScript behavior to allow selected tab to be remained after save or page reload
 * keeping state in localstorage
 */

jQuery(function() {

    var loadTab = function() {
        var $ = jQuery.noConflict();

        jQuery(document).find('a[data-toggle="tab"]').on('click', function(e) {
            // Store the selected tab href in localstorage
            window.localStorage.setItem('tab-href', $(e.target).attr('href'));
        });

        var activateTab = function(href) {
            var $el = $('a[data-toggle="tab"]a[href*=' + href + ']');
            $el.tab('show');
        };

        var hasTab = function(href){
            return $('a[data-toggle="tab"]a[href*=' + href + ']').length;
        };

        if (localStorage.getItem('tab-href')) {
            // When moving from tab area to a different view
            if(!hasTab(localStorage.getItem('tab-href'))){
                localStorage.removeItem('tab-href');
                return true;
            }
            // Clean default tabs
            $('a[data-toggle="tab"]').parent().removeClass('active');
            var tabhref = localStorage.getItem('tab-href');
            // Add active attribute for selected tab indicated by url
            activateTab(tabhref);
            // Check whether internal tab is selected (in format <tabname>-<id>)
            var seperatorIndex = tabhref.indexOf('-');
            if (seperatorIndex !== -1) {
                var singular = tabhref.substring(0, seperatorIndex);
                var plural = singular + "s";
                activateTab(plural);
            }
        }
    };
    setTimeout(loadTab, 100);

});

The same content is in 20 releases, Joomla 3.4.0-beta1 to 3.5.0-beta. See them all, or every version of this file.