Sha256: 569995dbb93eac7aa0ce8d39983245dfe1bc50d97e023eaef37c813c278eacd5

Contents?: true

Size: 1.78 KB

Versions: 62

Compression:

Stored size: 1.78 KB

Contents

/**
 * @namespace WORKAREA.tabs
 */
WORKAREA.registerModule('tabs', (function () {
    'use strict';

    var tabMenuTemplate = JST['workarea/admin/templates/tabs_menu'],

        initTabsUi = function ($ui) {
            $ui.tabs();
        },

        injectTabMenu = function ($ui, tabMenuData, tabIndex) {
            $ui.prepend(tabMenuTemplate({
                tabs: tabMenuData,
                tabIndex: tabIndex
            }));
        },

        setPanelIds = function ($panels, tabIds, tabIndex) {
            $panels.each(function (index, panel) {
                panel.id = tabIds[index] + '-tab-panel-' + tabIndex;
            });
        },

        getTabIds = function (tabName, index) {
            return WORKAREA.string.dasherize(tabName) + '-' + index;
        },

        getTabNames = function ($panels) {
            return $('> .tabs__heading', $panels).map(function (index, name) {
                return _.trim($(name).text());
            }).toArray();
        },

        setupTabsUi = function (index, element) {
            var $ui = $(element),
                $panels = $('> .tabs__panel', $ui),
                tabNames = getTabNames($panels),
                tabIds = _.map(tabNames, getTabIds),
                tabMenuData = _.zip(tabNames, tabIds);

            setPanelIds($panels, tabIds, index);
            injectTabMenu($ui, tabMenuData, index);
            initTabsUi($ui);
        },

        destroy = function() {
            $('.tabs__menu').remove();
        },

        /**
         * @method
         * @name init
         * @memberof WORKAREA.tabs
         */
        init = function ($scope) {
            $('.tabs', $scope).each(setupTabsUi);
        };

        $(document).on('turbolinks:before-cache', destroy);

    return {
        init: init
    };
}()));

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.5.15 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.36 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.14 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.35 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.13 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.34 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.12 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.33 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.11 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.10 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.32 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.9 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.31 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.8 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.30 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.7 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.29 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.6 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.28 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.5 app/assets/javascripts/workarea/admin/modules/tabs.js