Вход Регистрация
Файл: concrete5.7.5.6/concrete/js/build/core/app/edit-mode/area.js
Строк: 412
<?php
(function (window, $, _Concrete) {
    
'use strict';

    
/**
     * Area object, used for managing areas
     * @param {jQuery}   elem      The area's HTML element
     * @param {EditMode} edit_mode The EditMode instance
     */
    
var Area Concrete.Area = function Area(elemedit_mode) {
        
this.init.apply(this_(arguments).toArray());
    };

    
Area.prototype = {

        
init: function areaInit(elemedit_mode) {
            var 
my this;
            
elem.data('Concrete.area'my);

            
Concrete.createGetterSetters.call(my, {
                
idelem.data('area-id'),
                
activetrue,
                
blockTemplate_(elem.children('script[role=area-block-wrapper]').html()).template(),
                
elemelem,
                
totalBlocks0,
                
enableGridContainerelem.data('area-enable-grid-container'),
                
customTemplateselem.data('area-custom-templates'),
                
handleelem.data('area-handle'),
                
dragAreas: [],
                
blocks: [],
                
editModeedit_mode,
                
maximumBlocksparseInt(elem.data('maximumBlocks'), 10),
                
blockTypeselem.data('accepts-block-types').toLowerCase().split(' '),
                
blockContainerelem.children('.ccm-area-block-list')
            });
            
my.id my.getId();
            
my.setTotalBlocks(0); // we also need to update the DOM which this does.

            
my.bindEvent('EditModeBlockAddInline.area', function(edata) {
                if (
data.area === my) {
                    
my.setTotalBlocks(my.getTotalBlocks() + 1);
                }
            });
        },

        
/**
         * Get this area in the passed edit mode context
         * @param Concrete.EditMode edit_mode
         * @returns Concrete.Area|null
         */
        
inEditMode: function areaInEditMode(edit_mode) {
            return 
edit_mode.getAreaByID(this.getId());
        },

        
/**
         * Handle unbinding.
         */
        
destroy: function areaDestroy() {
            var 
my this;
            if (
my.getAttr('menu')) {
                
my.getAttr('menu').destroy();
            }

            
Concrete.event.unbind(".ccm-area-a" this.getId());

            
my.reset();
        },

        
reset: function areaReset() {
            var 
my this;
            
_(my.getDragAreas()).each(function (drag_area) {
                
drag_area.destroy();
            });

            
_(my.getBlocks()).each(function (block) {
                
block.destroy();
            });

            
my.setBlocks([]);
            
my.setDragAreas([]);

            
my.setTotalBlocks(0);
        },

        
bindEvent: function areaBindEvent(eventhandler) {
            return 
Concrete.EditMode.prototype.bindEvent.call(thisevent ".ccm-area-a" this.getId(), handler);
        },

        
scanBlocks: function areaScanBlocks() {
            var 
my thistypeblock;

            
my.reset();
            
my.addDragArea(null);

            $(
'div.ccm-block-edit[data-area-id=' my.getId() + ']'this.getElem()).each(function () {
                var 
me = $(this), handle me.data('block-type-handle');

                if (
handle === 'core_area_layout') {
                    
type Concrete.Layout;
                } else if (
handle === 'core_stack_display') {
                    
type Concrete.StackDisplay;
                } else {
                    
type Concrete.Block;
                }

                
block = new type(memy.getEditMode());
                
block.setArea(my);

                
my.addBlock(block);
            });
        },

        
getBlockByID: function areaGetBlockByID(bID) {
            var 
my this;
            return 
_.findWhere(my.getBlocks(), {idbID});
        },

        
getMenuElem: function areaGetMenuElem() {
            var 
my this;
            return $(
'[data-area-menu=area-menu-a' my.getId() + ']');
        },

        
bindMenu: function areaBindMenu() {
            var 
my this,
                
elem my.getElem(),
                
totalBlocks my.getTotalBlocks(),
                
$menuElem my.getMenuElem(),
                
menuHandle;

            if (
totalBlocks 0) {
                
menuHandle '#area-menu-footer-' my.getId();
            } else {
                
menuHandle 'div[data-area-menu-handle=' my.getId() + ']';
            }
            if (
my.getAttr('menu')) {
                
my.getAttr('menu').destroy();
            }

            var 
menu_config = {
                
'handle'menuHandle,
                
'highlightClassName''ccm-area-highlight',
                
'menuActiveClass''ccm-area-highlight',
                
'menu': $('[data-area-menu=' elem.attr('data-launch-area-menu') + ']')
            };

            if (
my.getElem().hasClass('ccm-global-area')) {
                
menu_config.menuActiveClass += " ccm-global-area-highlight";
                
menu_config.highlightClassName += " ccm-global-area-highlight";
            }

            
my.setAttr('menu', new ConcreteMenu(elemmenu_config));

            
$menuElem.find('a[data-menu-action=add-inline]')
                .
off('click.edit-mode')
                .
on('click.edit-mode', function (e) {
                    
// we are going to place this at the END of the list.
                    
var dragAreaLastBlock false;
                    
_.each(my.getBlocks(), function (block) {
                        
dragAreaLastBlock block;
                    });
                    
Concrete.event.fire('EditModeBlockAddInline', {
                        
areamy,
                        
cIDCCM_CID,
                        
btID: $(this).data('block-type-id'),
                        
arGridMaximumColumns: $(this).attr('data-area-grid-maximum-columns'),
                        
evente,
                        
dragAreaBlockdragAreaLastBlock,
                        
btHandle: $(this).data('block-type-handle')
                    });
                    return 
false;
                });

            
$menuElem.find('a[data-menu-action=edit-container-layout]')
                .
off('click.edit-mode')
                .
on('click.edit-mode', function (e) {
                    
// we are going to place this at the END of the list.
                    
var $link = $(this);
                    var 
bID parseInt($(this).attr('data-container-layout-block-id'));
                    var 
editor Concrete.getEditMode();
                    var 
block _.findWhere(editor.getBlocks(), {idbID});
                    
Concrete.event.fire('EditModeBlockEditInline', {
                        
blockblock,
                        
arGridMaximumColumns$link.attr('data-area-grid-maximum-columns'),
                        
evente
                    
});
                    return 
false;
                });

            
$menuElem.find('a[data-menu-action=edit-container-layout-style]')
                .
off('click.edit-mode')
                .
on('click.edit-mode', function (e) {
                    
e.preventDefault();
                    
// we are going to place this at the END of the list.
                    
var $link = $(this);
                    var 
bID parseInt($(this).attr('data-container-layout-block-id'));
                    var 
editor Concrete.getEditMode();
                    var 
block _.findWhere(editor.getBlocks(), {idbID});
                    
Concrete.event.fire('EditModeBlockEditInline', {
                        
blockblockeventeactionCCM_DISPATCHER_FILENAME '/ccm/system/dialogs/block/design'
                    
});
                });

            
$menuElem.find('a[data-menu-action=area-add-block]')
                .
off('click.edit-mode')
                .
on('click.edit-mode', function(e) {
                    var 
max my.getMaximumBlocks();
                    if (
max || max my.getTotalBlocks()) {
                        
my.getEditMode().setNextBlockArea(my);
                        var 
panelButton = $('[data-launch-panel="add-block"]');
                        
panelButton.click();
                    } else {
                        
ConcreteAlert.error({'message' ccmi18n.fullArea});
                    }
                    return 
false;
                });

            
my.bindEvent('ConcreteMenuShow', function(edata) {
                if (
data.menu == my.getAttr('menu')) {
                    var 
max my.getMaximumBlocks(),
                        
list_item data.menu.$menuPointer.find('a[data-menu-action=area-add-block]').parent();

                    if (
max || max my.getTotalBlocks()) {
                        
list_item.show();
                    } else {
                        
list_item.hide();
                    }
                }
            });


            
$menuElem.find('a[data-menu-action=edit-area-design]')
                .
off('click.edit-mode')
                .
on('click.edit-mode', function (e) {
                    
e.preventDefault();
                    
ConcreteToolbar.disable();
                    
my.getElem().addClass('ccm-area-inline-edit-disabled');
                    var 
postData = {
                        
'arHandle'my.getHandle(),
                        
'cID'CCM_CID
                    
};

                    
my.bindEvent('EditModeExitInline', function (e) {
                        
Concrete.event.unsubscribe(e);
                        
my.getEditMode().destroyInlineEditModeToolbars();
                    });

                    $.
ajax({
                        
type'GET',
                        
urlCCM_DISPATCHER_FILENAME '/ccm/system/dialogs/area/design',
                        
datapostData,
                        
success: function (r) {
                            var 
$container my.getElem();
                            
my.getEditMode().loadInlineEditModeToolbars($containerr);
                            $.
fn.dialog.hideLoader();
                        }
                    });


                });
        },

        
/**
         * Does this area accept a specific block type handle
         * @param type_handle the block type handle
         * @returns {bool}
         */
        
acceptsBlockType: function areaAcceptsBlockType(type_handle) {
            return 
_(this.getBlockTypes()).contains(type_handle.toLowerCase());
        },

        
/**
         * Add block to area
         * @param  {Block}   block     block to add
         * @param  {Block}   sub_block The block that should be above the added block
         * @return {Boolean}           Success, always true
         */
        
addBlock: function areaAddBlock(blocksub_block) {
            var 
my this;
            if (
sub_block) {
                return 
this.addBlockToIndex(block_(my.getBlocks()).indexOf(sub_block) + 1);
            }
            return 
this.addBlockToIndex(blockmy.getBlocks().length);
        },

        
setTotalBlocks: function (totalBlocks) {
            
this.setAttr('totalBlocks'totalBlocks);
            
this.getElem().attr('data-total-blocks'totalBlocks);
        },

        
/**
         * Add to specific index, pipes to addBlock
         * @param  {Block}   block Block to add
         * @param  {int}     index Index to add to
         * @return {Boolean}       Success, always true
         */
        
addBlockToIndex: function areaAddBlockToIndex(blockindex) {
            var 
totalBlocks this.getTotalBlocks(),
                
blocks this.getBlocks(),
                
totalHigherBlocks totalBlocks index;

            
block.setArea(this);
            
this.setTotalBlocks(totalBlocks 1);

            
// any blocks with indexes higher than this one need to have them incremented
            
if (totalHigherBlocks 0) {
                var 
updateBlocksArray = [];
                for (var 
0blocks.lengthi++) {
                    if (
>= index) {
                        
updateBlocksArray[1] = blocks[i];
                    } else {
                        
updateBlocksArray[i] = blocks[i];
                    }
                }
                
updateBlocksArray[index] = block;
                
this.setBlocks(updateBlocksArray);
            } else {
                
this.getBlocks()[index] = block;
            }

            
this.addDragArea(block);

            
// ensure that the DOM attributes are correct
            
block.getElem().attr("data-area-id"this.getId());

            return 
true;
        },

        
/**
         * Remove block from area
         * @param  {Block}   block The block to remove.
         * @return {Boolean}       Success, always true.
         */
        
removeBlock: function areaRemoveBlock(block) {
            var 
my thistotalBlocks my.getTotalBlocks();

            
my.getElem().removeClass('ccm-parent-menu-item-active');

            
block.getContainer().remove();
            
my.setBlocks(_(my.getBlocks()).without(block));

            
my.setTotalBlocks(totalBlocks 1);

            var 
drag_area _.first(_(my.getDragAreas()).filter(function (drag_area) {
                return 
drag_area.getBlock() === block;
            }));
            if (
drag_area) {
                
drag_area.getElem().remove();
                
my.setDragAreas(_(my.getDragAreas()).without(drag_area));
            }

            if (!
my.getTotalBlocks()) {
                
// we have to destroy the old menu and create it anew
                
my.bindMenu();
            }

            return 
true;
        },

        
/**
         * Add a drag area
         * @param  {Block}    block The block to add this area below.
         * @return {DragArea}       The added DragArea
         */
        
addDragArea: function areaAddDragArea(block) {
            var 
my thiselemdrag_area;

            if (!
block) {
                if (
my.getDragAreas().length) {
                    throw new 
Error('No block supplied');
                }
                
elem = $('<div class="ccm-area-drag-area"/>');
                
drag_area = new Concrete.DragArea(elemmyblock);
                
my.getBlockContainer().prepend(elem);
            } else {
                
elem = $('<div class="ccm-area-drag-area"/>');
                
drag_area = new Concrete.DragArea(elemmyblock);
                
block.getContainer().after(elem);
            }

            if (!
my.getElem().parent().is('#ccm-stack-container')) {
                
elem.text(_(ccmi18n.emptyArea).template({
                    
area_handlemy.getElem().data('area-display-name')
                }));
            }
            
my.getDragAreas().push(drag_area);
            return 
drag_area;
        },

        
/**
         * Find the contending DragArea's
         * @param  {Pep}      pep   The Pep object from the event.
         * @param  {Block|Stack}    block The Block object from the event.
         * @return {Array}          Array of all drag areas that are capable of accepting the block.
         */
        
contendingDragAreas: function areaContendingDragAreas(pepblock) {
            var 
my thismax_blocks my.getMaximumBlocks();

            if (
block instanceof Concrete.Stack || block.getHandle() === 'core_stack_display') {
                return 
_(my.getDragAreas()).filter(function (drag_area) {
                    return 
drag_area.isContender(pepblock);
                });
            } else if ((
max_blocks && my.getBlocks().length >= max_blocks) || !_(my.getBlockTypes()).contains(block.getHandle())) {
                return [];
            }
            return 
_(my.getDragAreas()).filter(function (drag_area) {
                return 
drag_area.isContender(pepblock);
            });
        }
    };

}(
windowjQuery_Concrete));
?>
Онлайн: 1
Реклама