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.4.13 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js
workarea-admin-3.4.12 app/assets/javascripts/workarea/admin/modules/menu_editor_links.js