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.4.27 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.4 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.26 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.3 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.25 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.2 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.24 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.1 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.23 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.22 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.0 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.21 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.5.0.beta.1 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.20 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.19 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.18 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.17 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.16 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.15 app/assets/javascripts/workarea/admin/modules/tabs.js
workarea-admin-3.4.14 app/assets/javascripts/workarea/admin/modules/tabs.js