Вход Регистрация
Файл: static/plugins/admin/js/mobile.js
Строк: 407
<?php
MOBILE 
= {};

MOBILE.Navigation = (function() {
   
    var 
_panels = {}, _settings = {};
    var 
_bind_query_queryCallBack_newCounter 0;
    
   
// System functions
   
    
_bind= function( fncobjargs ) {
        
fnc fnc || function(){};
        
obj obj || window;
        
args args || [];

        return function() {
            return 
fnc.apply(objargs.concat(Array.prototype.slice.call(arguments)));
        };
    };
    
    
_query = function( commandparamscallBack ) {
        $.
post(_settings.rsp, {
                
"command"command,
                
"data"JSON.stringify(params),
                
"shared"JSON.stringify(_settings.shared)
            }, function( 
) {
                if ( $.
isFunction(callBack) ) {
                    
callBack(r);
                }

                
_queryCallBack(r);
            }, 
"json");
    };
    
    
_queryCallBack = function( ) {
        if ( !
) return;
        
        $.
each(r.items || {}, function(itemKeyitemData) {
            
changeItem(itemKeyitemData);
        });
    };
    

    var 
initsavePanelschangeItem;
    var 
PanelDefaultDelegateNewDelegateHiddenDelegate;

    
Panel = function( panelKeydelegate ) {
        
        
this.key panelKey;
        
this.node = $(".dnd-section[data-key="" + this.key + ""]");
        
this.alias this.node.data("alias");
        
        
this.delegate delegate || new DefaultDelegate();

        
this.options = {
            
cancel'.peep_dnd_freezed',
            
items'.component:not(.peep_dnd_freezed)',
            
placeholder'peep_dnd_placeholder',
            clone: 
"original",
            
            
start_bind(this.delegate.startthis.delegate, [this]),
            
sort_bind(this.delegate.sortthis.delegate, [this]),
            
stop_bind(this.delegate.stopthis.delegate, [this]),
            
beforeStop_bind(this.delegate.beforeStopthis.delegate, [this]),
            
receive_bind(this.delegate.receivethis.delegate, [this]),
            
over_bind(this.delegate.overthis.delegate, [this]),
            
change_bind(this.delegate.changethis.delegate, [this]),
            
update_bind(this.delegate.updatethis.delegate, [this]),
            
helper_bind(this.delegate.helperthis.delegate, [this])
            
        };
        
        
this.connections = {};

        
_bind(this.delegate.beforeInitthis.delegate, [this])();
        
this.init();
        
_bind(this.delegate.afterInitthis.delegate, [this])();
    };

    
Panel.prototype = {
        
init: function() {
            var 
self this;
            
            
this.node.sortable(this.options).disableSelection();
            
            
this.node.on("click"".dnd-control", function() {
                var 
item = $(this).parents(".component:eq(0)");
                
_bind(self.delegate.actionClickself.delegate, [selfitem])( $(this).data("action") );
            });
            
            return 
this;
        },
                
        
connect: function( panel ) {
            
this.connections[panel.key] = panel;
            
this.node.sortable("option""connectWith"this._connectedNodes());
            
            return 
this;
        },
        
        
disconnect: function( panel ) {
            if ( !
this.connections[panel.key] ) {
                return 
this;
            }
            
            
delete this.connections[panel.key];
            
this.node.sortable("option""connectWith"this._connectedNodes());
            
            return 
this;
        },
                
        
cancel: function() {
            
this.node.sortable("cancel");
        },
                
        
save: function() {
            var 
data this.node.sortable("toArray", {attribute"data-key"});
            return 
_bind(this.delegate.savethis.delegate, [this])(data);
        },
                
        
_connectedNodes: function() {
            var 
connections false;
            
            $.
each(this.connections, function(panelKeypanel) {
                
connections connections connections.add(panel.node) : panel.node;
            });
            
            return 
connections;
        }
    };


    
// Delegates

    
var _delegates = {};

    
_delegates.DefaultDelegate DefaultDelegate = function() {
        
this.sender null;
    };
    
    $.
extend(DefaultDelegate.prototype, {
        
        
helper: function(paneleitem) {
            var 
itemWidth item.outerWidth();

            if (
itemWidth 160)
            {
                var 
160 item.outerWidth();
                var 
offsetWindow item.offset();
                var 
offset * (e.pageX offsetWindow.left);

                
panel.node.sortable'option''cursorAt', {leftoffset } );
            }

            return $(
'<div class="peep_dnd_helper" style="width: 160px; height: 30px"></div>');
        },
        
        
start: function( paneleui ) {
            
ui.item.show().addClass("dnd-item-moving");
            
this.sender null;
        },
                
        
stop: function( paneleui ) {
            
ui.item.removeClass("dnd-item-moving");
            
savePanels([panel]);
        },
                
        
receive: function( paneleui ) {
            
savePanels([panel]);
        },
        
        
save: function( paneldata ) {
            return 
data;
        },
        
        
actionClick: function( panelitemaction ) {
            
            var 
editFloatBox;
            
            if ( 
action === "delete" ) {
                
item.appendTo(_panels.hidden.node);
                
savePanels([panel_panels.hidden]);
            }
            
            if ( 
action === "edit" ) {
                
editFloatBox PEEP.ajaxFloatBox("ADMIN_CMP_MobileNavigationItemSettings", [item.data("key")], {
                    
"title"PEEP.getLanguageText("mobile""admin_nav_settings_fb_title"),
                    
"scope": {
                        
"callBack"_queryCallBack,
                        
"floatBox"editFloatBox
                    
}
                });
            }
        }
    });
    
    
    
_delegates.NewDelegate NewDelegate = function() {
        
DefaultDelegate.call(this);
        
        
this.cloning false;
        
this.clone = null;
    };
    $.
extend(NewDelegate.prototypeDefaultDelegate.prototype, {
        
createItem: function( from ) {
            var 
item from.clone();
            
item.hide();
            
            return 
changeItem(item, {
                
"key": (_settings.prefix _settings.prefix ':' '') + "new-item-" + (_newCounter++),
                
"title"PEEP.getLanguageText("mobile""admin_nav_adding_message"),
                
"locked"true,
                
"parent"from.data("key")
            });
        },
        
        
start: function( paneleui ) {
            
this.cloning true;
            
ui.item.show();
            
this.clone = this.createItem(ui.item);
        },
                
        
update: function( paneleui ) {
            
this.cloning false;
            
ui.item.after(this.clone);

            
panel.cancel();
            
this.clone.show();
            
this.clone = null;
        },
                
        
stop: function( paneleui ) {

        },
                
        
save: function( paneldata ) {
            return 
null;
        },
                
        
actionClick: function( panelitemaction ) {
            
// Skip
        
}
    });
    
    
    
_delegates.HiddenDelegate HiddenDelegate= function() {
        
DefaultDelegate.call(this);
        
    };
    $.
extend(HiddenDelegate.prototypeDefaultDelegate.prototype, {
        
actionClick: function( panelitemaction ) {
            if ( 
action !== "delete" ) {
                
DefaultDelegate.prototype.actionClick.call(thispanelitemaction);
                
                return;
            }
            
            if ( !
item.data("custom") ) {
                return;
            }
            
            if ( 
confirm("Are you sure?") ) {
                
item.remove();
                
                
_query("deleteItem", {
                    
"key"item.data("key")
                });
            }
        }
    });
    
    
    
// Global functions
    
    
savePanels = function( panels ) {
        
        var 
query = {
            
"panels": {},
            
"items": {}
        };
        
        $.
each(panels, function(indexpanel) {
            var 
data panel.save();
            if ( 
data ) {
                $.
each(data, function(iitemKey){
                    var 
item = $(".component[data-key="" + itemKey + ""]");
                    
query.items[itemKey] = {
                       
"type"item.data("type"),
                       
"parent"item.data("parent"),
                       
"key"item.data("key")
                    };
                });
                
                
query.panels[panel.alias] = data;
            }
        });

        
console.log("savePanels"panels);
        
_query("saveOrder"query);
    };
    
    
changeItem = function( keyoptions ) {
        var 
item;
        
        if ( $.
type(key) === "string" ) {
            
item = $(".component[data-key="" + key + ""]");
        } else {
           
item key
        }

        if ( 
options.key ) {
            
item.attr("data-key"options.key);
            
item.data("key"options.key);
        }
        
        if ( 
options.type ) {
            
item.attr("data-type"options.type);
        }
        
        if ( 
options.parent ) {
            
item.attr("data-parent"options.parent);
        }
        
        if ( 
options.title ) {
            
item.find(".dnd-title").text(options.title);
        }
        
        if ( 
options.locked ) {
            
item.addClass("dnd-item-locked");
        } else {
            
item.removeClass("dnd-item-locked");
        }
        
        if ( 
options.custom !== undefined ) {
            
item.attr("data-custom"options.custom);
            
item[options.custom "addClass" "removeClass"]("dnd-item-custom");
        }
        
        return 
item;
    };
    
    
init = function( settings ) {
        
_settings settings;
        var 
sections = $(".dnd-section");
        
        
sections.each(function() {
           var 
=  $(this);
           
_panels[s.data("key")] = new Panel(s.data("key"), new _delegates[s.data("delegate")]());
        });
        
        
sections.each(function() {
           var 
=  $(this);
           var 
relation s.data("relation");
           
           if ( !
relation ) return;
           
           $.
each(relation.split(','), function(irel) {
               
_panels[s.data("key")].connect(_panels[$.trim(rel)]);
           });
        });
    };


    
// Public methods
    
return {
        
initinit
    
};
})();
?>
Онлайн: 3
Реклама