Sha256: 3ccee92339559a2e5e124162f3877cc1ff55df828f9597794010a367ef7ec9d2

Contents?: true

Size: 1.97 KB

Versions: 62

Compression:

Stored size: 1.97 KB

Contents

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

    var appendNextList = function ($currentMenu, response) {
            var $newMenu = $(response);

            $currentMenu.nextAll('.menu-editor__menu').remove();
            $currentMenu.after($newMenu);

            WORKAREA.initModules($newMenu);
        },

        activateLink = function ($link) {
            $link
                .closest('.menu-editor__menu-list')
                    .find('.menu-editor__list-item--active')
                    .removeClass('menu-editor__list-item--active');

            $link
                .closest('.menu-editor__list-item')
                .addClass('menu-editor__list-item--active');
        },

        preserveActiveState = function (index, link) {
            var $menu = $(link).closest('.menu-editor__menu'),
                $nextMenu = $menu.next('.menu-editor__menu'),
                taxonId, nextMenuId;

            if (_.isEmpty($nextMenu)) { return; }

            taxonId = $(link).data('menuEditorLink').id;
            nextMenuId = $nextMenu.data('menuEditorParentId');

            if (taxonId !== nextMenuId) { return; }

            activateLink($(link));
        },

        handleLinkClick = function (event) {
            var $link = $(event.currentTarget),
                $currentMenu = $link.closest('.menu-editor__menu'),
                endpoint = $link.attr('href'),
                gettingNextList = $.get(endpoint);

            event.preventDefault();

            activateLink($link);

            gettingNextList.done(_.partial(appendNextList, $currentMenu));
        },

        /**
         * @method
         * @name init
         * @memberof WORKAREA.menuEditorLinks
         */
        init = function ($scope) {
            $('[data-menu-editor-link]', $scope)
            .on('click', handleLinkClick)
            .each(preserveActiveState);
        };

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

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.26 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.45 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.25 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.23 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.44 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.22 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.43 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.21 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.42 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.20 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.41 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.19 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.40 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.18 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.39 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.17 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.38 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.16 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.37 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js