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.15 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.36 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.14 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.35 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.13 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.34 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.12 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.33 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.11 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.10 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.32 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.9 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.31 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.8 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.30 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.7 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.29 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.6 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.28 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.5.5 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js