Sha256: f6ba9ad2eb1094134942712fbc0b6df3638bdb69ff96c775f87e5761c4fc12b3

Contents?: true

Size: 1.92 KB

Versions: 62

Compression:

Stored size: 1.92 KB

Contents

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

    var patchPosition = function ($form) {
            $.ajax($form.attr('action'), {
                method: $('[name="_method"]', $form).val(),
                data: $form.serialize()
            });
        },

        updateBlockOrder = function (event) {
            var $ui = $(event.target),
                $form = $ui.closest('form'),
                $names = $('.content-block-list__item', $ui);

            $names.each(function (index, name) {
                var $block = $($(name).data('blockId'));

                $('input', name).val(index);

                $block.data('blockOrder', index).css({ order: index });
            });

            return $form;
        },

        reorder = _.flow(
            updateBlockOrder,
            patchPosition,
            WORKAREA.addContentBlockButtons.reorder
        ),

        scrollBlockIntoView = function($block) {
            $('html, body').animate({
                scrollTop: $block.offset().top - 70
            }, 200);

            return $block;
        },

        enableEditMode = _.flow(scrollBlockIntoView, WORKAREA.contentBlocks.activateBlock),

        handleListItemclick = function(event) {
            var $blockButton = $(event.currentTarget).closest('.content-block-list__item'),
                $activeBlock = $($blockButton.data('blockId'));

            enableEditMode($activeBlock);
        },

        /**
         * @method
         * @name init
         * @memberof WORKAREA.contentBlockList
         */
        init = function ($scope) {
            $('.content-block-list', $scope)
            .on('click', '.content-block-list__name', handleListItemclick)
            .sortable({
                stop: reorder,
                handle: '.content-block-list__icon--move'
            });
        };

    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/content_block_list.js
workarea-admin-3.5.26 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.4.45 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.5.25 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.5.23 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.4.44 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.5.22 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.4.43 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.5.21 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.4.42 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.5.20 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.4.41 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.5.19 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.4.40 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.5.18 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.4.39 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.5.17 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.4.38 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.5.16 app/assets/javascripts/workarea/admin/modules/content_block_list.js
workarea-admin-3.4.37 app/assets/javascripts/workarea/admin/modules/content_block_list.js