Вход Регистрация
Файл: concrete5.7.5.6/concrete/js/build/core/events.js
Строк: 214
<?php
(function (global, $) {
    
'use strict';
    global.
Concrete = global.Concrete || {};
    global.
console = global.console || {};

    global.
ConcreteEvent = (function (ns, $) {
        var 
target = $('<span />'), debug false;

        var 
hasGroup typeof global.console.group === 'function' && typeof global.console.groupEnd === 'function',
            
hasLog typeof global.console.log === 'function';


        function 
groupLog(groupvaluedontcall) {
            if (
hasGroup) {
                global.
console.groupCollapsed(group);

                if (!
dontcall && typeof value === 'function') {
                    
value();
                } else {
                    global.
console.log(value);
                }
                global.
console.groupEnd();
            } else if (
hasLog) {

                if (!
dontcall && typeof value === 'function') {
                    global.
console.log('Group: "' group '"');
                    
value();
                    global.
console.log('GroupEnd: "' group '"');
                } else {
                    global.
console.log(groupvalue);
                }
            }
        }

        function 
getTarget(given_target) {
            if (!
given_targetgiven_target target;
            if (!(
given_target instanceof $)) given_target = $(given_target);
            if (!
given_target.lengthgiven_target target;
            return 
given_target;
        }

        var 
ConcreteEvent = {

            
debug: function (enabled) {
                if (
typeof enabled === 'undefined') {
                    return 
debug;
                }
                return (
debug = !!enabled);
            },

            
subscribe: function (typehandlertarget) {

                var 
old_handler handlerbound_stack = (new Error('EventStack')).stack;
                
handler = function() {
                    if (
debug) {
                        
groupLog('Handler Fired.', function () {
                            
groupLog('Type'typetrue);
                            
groupLog('Handler'old_handlertrue);
                            
groupLog('Target'targettrue);
                            
groupLog('Bound Stack'bound_stacktrue);
                            if (
typeof global.console.trace === 'function') {
                                global.
console.trace();
                            } else {
                                
groupLog('Stack', (new Error('EventStack')).stack);
                            }

                        });
                    }

                    
old_handler.apply(this_(arguments).toArray());
                };
                if (
debug) {
                    
groupLog('Event Subscribed', function () {
                        
groupLog('Type'typetrue);
                        
groupLog('Handler'old_handlertrue);
                        
groupLog('Target'targettrue);
                        if (
typeof global.console.trace === 'function') {
                            global.
console.trace();
                        } else {
                            
groupLog('Stack', (new Error('EventStack')).stack);
                        }
                    });

                }
                if (
type instanceof Array) {
                    return 
_(type).each(function (v) {
                        
ConcreteEvent.subscribe(vhandlertarget);
                    });
                }
                
getTarget(target).bind(type.toLowerCase(), handler);
                return 
ConcreteEvent;
            },

            
publish: function (typedatatarget) {
                if (
debug) {
                    
groupLog('Event Published', function () {
                        
groupLog('Type'typetrue);
                        
groupLog('Data'datatrue);
                        
groupLog('Target'targettrue);
                        if (
typeof global.console.trace === 'function') {
                            global.
console.trace();
                        } else {
                            
groupLog('Stack', (new Error('EventStack')).stack);
                        }
                    });

                }
                if (
type instanceof Array) {
                    return 
_(type).each(function (v) {
                        
ConcreteEvent.publish(vdatatarget);
                    });
                }
                
getTarget(target).trigger(type.toLowerCase(), data);
                return 
ConcreteEvent;
            },

            
unsubscribe: function (typesecondary_argumenttarget) {
                var 
args;
                if (
debug) {
                    
groupLog('Event Unsubscribed', function () {
                        
groupLog('Type'typetrue);
                        
groupLog('Secondary Argument'secondary_argumenttrue);
                        
groupLog('Target'targettrue);
                        if (
typeof global.console.trace === 'function') {
                            global.
console.trace();
                        } else {
                            
groupLog('Stack', (new Error('EventStack')).stack);
                        }
                    });

                }

                
args = [(typeof type.toLowerCase === 'function' type.toLowerCase() : type)];

                if (
typeof secondary_argument !== 'undefined'args.push(secondary_argument);
                $.
fn.unbind.apply(getTarget(target), args);
                return 
ConcreteEvent;
            }
        };

        
ConcreteEvent.sub ConcreteEvent.bind ConcreteEvent.watch ConcreteEvent.on ConcreteEvent.subscribe;
        
ConcreteEvent.pub ConcreteEvent.fire ConcreteEvent.trigger ConcreteEvent.publish;
        
ConcreteEvent.unsub ConcreteEvent.unbind ConcreteEvent.unwatch ConcreteEvent.off ConcreteEvent.unsubscribe;

        
ns.event ConcreteEvent;
        return 
ConcreteEvent;
    }(global.
ConcretejQuery));

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