Вход Регистрация
Файл: framework/thirdparty/jquery-entwine/src/jquery.entwine.events.js
Строк: 346
<?php
(function($) {    

    
/** Taken from jQuery 1.5.2 for backwards compatibility */
    
if ($.support.changeBubbles == undefined) {
        $.
support.changeBubbles true;

        var 
el document.createElement("div");
        
eventName "onchange";

        if (
el.attachEvent) {
            var 
isSupported = (eventName in el);
            if (!
isSupported) {
                
el.setAttribute(eventName"return;");
                
isSupported typeof el[eventName] === "function";
            }

            $.
support.changeBubbles isSupported;
        }
    }

    
/* Return true if node b is the same as, or is a descendant of, node a */
    
if (document.compareDocumentPosition) {
        var 
is_or_contains = function(ab) {
            return 
&& && (== || !!(a.compareDocumentPosition(b) & 16));
        };
    }
    else {
        var 
is_or_contains = function(ab) {
            return 
&& && (== || (a.contains a.contains(b) : true));
        };
    }

    
/* Add the methods to handle event binding to the Namespace class */
    
$.entwine.Namespace.addMethods({
        
build_event_proxy: function(name) {
            var 
one this.one(name'func');
            
            var 
prxy = function(edata) {
                
// For events that do not bubble we manually trigger delegation (see delegate_submit below) 
                // If this event is a manual trigger, the event we actually want to bubble is attached as a property of the passed event
                
e.delegatedEvent || e;
                
                var 
el e.target;
                while (
el && el.nodeType == && !e.isPropagationStopped()) {
                    var 
ret one(elarguments);
                    if (
ret !== undefinede.result ret;
                    if (
ret === false) { e.preventDefault(); e.stopPropagation(); }
                    
                    
el el.parentNode;
                }
            };
            
            return 
prxy;
        },
        
        
build_mouseenterleave_proxy: function(name) {
            var 
one this.one(name'func');
            
            var 
prxy = function(e) {
                var 
el e.target;
                var 
rel e.relatedTarget;
                
                while (
el && el.nodeType == && !e.isPropagationStopped()) {
                    
/* We know el contained target. If it also contains relatedTarget then we didn't mouseenter / leave. What's more, every ancestor will also
                    contan el and rel, and so we can just stop bubbling */
                    
if (is_or_contains(elrel)) break;
                    
                    var 
ret one(elarguments);
                    if (
ret !== undefinede.result ret;
                    if (
ret === false) { e.preventDefault(); e.stopPropagation(); }
                    
                    
el el.parentNode;
                }
            };
            
            return 
prxy;
        },
        
        
build_change_proxy: function(name) {
            var 
one this.one(name'func');

            
/*
            This change bubble emulation code is taken mostly from jQuery 1.6 - unfortunately we can't easily reuse any of
            it without duplication, so we'll have to re-migrate any bugfixes
            */

            // Get the value of an item. Isn't supposed to be interpretable, just stable for some value, and different
            // once the value changes
            
var getVal = function( elem ) {
                var 
type elem.typeval elem.value;

                if (
type === "radio" || type === "checkbox") {
                    
val elem.checked;
                }
                else if (
type === "select-multiple") {
                    
val "";
                    if (
elem.selectedIndex > -1) {
                        
val jQuery.map(elem.options, function(elem){ return elem.selected; }).join("-");
                    }
                }
                else if (
jQuery.nodeName(elem"select")) {
                    
val elem.selectedIndex;
                }

                return 
val;
            };

            
// Test if a node name is a form input
            
var rformElems = /^(?:textarea|input|select)$/i;

            
// Check if this event is a change, and bubble the change event if it is
            
var testChange = function(e) {
                var 
elem e.targetdataval;

                if (!
rformElems.test(elem.nodeName) || elem.readOnly) return;

                
data jQuery.data(elem"_entwine_change_data");
                
val getVal(elem);

                
// the current data will be also retrieved by beforeactivate
                
if (e.type !== "focusout" || elem.type !== "radio") {
                    
jQuery.data(elem"_entwine_change_data"val);
                }

                if (
data === undefined || val === data) return;

                if (
data != null || val) {
                    
e.type "change";

                    while (
elem && elem.nodeType == && !e.isPropagationStopped()) {
                        var 
ret one(elemarguments);
                        if (
ret !== undefinede.result ret;
                        if (
ret === false) { e.preventDefault(); e.stopPropagation(); }

                        
elem elem.parentNode;
                    }
                }
            };

            
// The actual proxy - responds to several events, some of which triger a change check, some
            // of which just store the value for future change checks
            
var prxy = function(e) {
                var 
event e.typeelem e.targettype jQuery.nodeNameelem"input" ) ? elem.type "";

                switch (
event) {
                    case 
'focusout':
                    case 
'beforedeactivate':
                        
testChange.apply(thisarguments);
                        break;

                    case 
'click':
                        if ( 
type === "radio" || type === "checkbox" || jQuery.nodeNameelem"select" ) ) {
                            
testChange.apply(thisarguments);
                        }
                        break;

                    
// Change has to be called before submit
                    // Keydown will be called before keypress, which is used in submit-event delegation
                    
case 'keydown':
                        if (
                            (
e.keyCode === 13 && !jQuery.nodeNameelem"textarea" ) ) ||
                            (
e.keyCode === 32 && (type === "checkbox" || type === "radio")) ||
                            
type === "select-multiple"
                        
) {
                            
testChange.apply(thisarguments);
                        }
                        break;

                    
// Beforeactivate happens also before the previous element is blurred
                    // with this event you can't trigger a change event, but you can store
                    // information
                    
case 'focusin':
                    case 
'beforeactivate':
                        
jQuery.dataelem"_entwine_change_data"getVal(elem) );
                        break;
                }
            }

            return 
prxy;
        },
        
        
bind_event: function(selectornamefuncevent) {
            var 
funcs this.store[name] || (this.store[name] = $.entwine.RuleList()) ;
            var 
proxies funcs.proxies || (funcs.proxies = {});
            
            var 
rule funcs.addRule(selectorname); rule.func func;
            
            if (!
proxies[name]) {
                switch (
name) {
                    case 
'onmouseenter':
                        
proxies[name] = this.build_mouseenterleave_proxy(name);
                        
event 'mouseover';
                        break;
                    case 
'onmouseleave':
                        
proxies[name] = this.build_mouseenterleave_proxy(name);
                        
event 'mouseout';
                        break;
                    case 
'onchange':
                        if (!$.
support.changeBubbles) {
                            
proxies[name] = this.build_change_proxy(name);
                            
event 'click keydown focusin focusout beforeactivate beforedeactivate';
                        }
                        break;
                    case 
'onsubmit':
                        
event 'delegatedSubmit';
                        break;
                    case 
'onfocus':
                    case 
'onblur':
                        $.
entwine.warn('Event '+event+' not supported - using focusin / focusout instead', $.entwine.WARN_LEVEL_IMPORTANT);
                }
                
                
// If none of the special handlers created a proxy, use the generic proxy
                
if (!proxies[name]) proxies[name] = this.build_event_proxy(name);

                $(
document).bind(event.replace(/(s+|$)/g'.entwine$1'), proxies[name]);
            }
        }
    });
    
    $.
entwine.Namespace.addHandler({
        
order40,
        
        
bind: function(selectorkv){
            var 
matchevent;
            if ($.
isFunction(v) && (match k.match(/^on(.*)/))) {
                
event match[1];
                
this.bind_event(selectorkvevent);
                return 
true;
            }
        }
    });
    
    
// Find all forms and bind onsubmit to trigger on the document too. 
    // This is the only event that can't be grabbed via delegation
    
    
var delegate_submit = function(edata){
        var 
delegationEvent = $.Event('delegatedSubmit'); delegationEvent.delegatedEvent e;
        return $(
document).trigger(delegationEventdata); 
    };

    $(
document).bind('EntwineElementsAdded', function(e){
        var 
forms = $(e.targets).filter('form');
        if (!
forms.length) return;

        
forms.bind('submit.entwine_delegate_submit'delegate_submit);
    });

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