Вход Регистрация
Файл: contao-3.5.8/assets/mootools/core/1.5.1/mootools-mobile-uncompressed.js
Строк: 293
<?php
// packager build Custom-Event/* Mobile/Browser.Features.Touch Mobile/Swipe
/*
---

name: Element.defineCustomEvent

description: Allows to create custom events based on other custom events.

authors: Christoph Pojer (@cpojer)

license: MIT-style license.

requires: [Core/Element.Event]

provides: Element.defineCustomEvent

...
*/

(function(){

[
ElementWindowDocument].invoke('implement', {hasEvent: function(event){
    var 
events this.retrieve('events'),
        list = (
events && events[event]) ? events[event].values null;
    if (list){
        var 
= list.length;
        while (
i--) if (i in list){
            return 
true;
        }
    }
    return 
false;
}});

var 
wrap = function(custommethodextended){
    
method custom[method];
    
extended custom[extended];

    return function(
fnname){
        if (
extended && !this.hasEvent(name)) extended.call(thisfnname);
        if (
methodmethod.call(thisfnname);
    };
};

var 
inherit = function(custombasemethod){
    return function(
fnname){
        
base[method].call(thisfnname);
        
custom[method].call(thisfnname);
    };
};

var 
events Element.Events;

Element.defineCustomEvent = function(namecustom){
    var 
base events[custom.base];

    
custom.onAdd wrap(custom'onAdd''onSetup');
    
custom.onRemove wrap(custom'onRemove''onTeardown');

    
events[name] = base Object.append({}, custom, {

        
basebase.base,

        
condition: function(eventname){
            return (!
base.condition || base.condition.call(thiseventname)) &&
                (!
custom.condition || custom.condition.call(thiseventname));
        },

        
onAddinherit(custombase'onAdd'),
        
onRemoveinherit(custombase'onRemove')

    }) : 
custom;

    return 
this;
};

Element.enableCustomEvents = function(){
  
Object.each(events, function(eventname){
    if (
event.onEnableevent.onEnable.call(eventname);
  });
};

Element.disableCustomEvents = function(){
  
Object.each(events, function(eventname){
    if (
event.onDisableevent.onDisable.call(eventname);
  });
};

})();


/*
---

name: Browser.Features.Touch

description: Checks whether the used Browser has touch events

authors: Christoph Pojer (@cpojer)

license: MIT-style license.

requires: [Core/Browser]

provides: Browser.Features.Touch

...
*/

Browser.Features.Touch = (function(){
    try {
        
document.createEvent('TouchEvent').initTouchEvent('touchstart');
        return 
true;
    } catch (
exception){}
    
    return 
false;
})();

// Android doesn't have a touch delay and dispatchEvent does not fire the handler
Browser.Features.iOSTouch = (function(){
    var 
name 'cantouch'// Name does not matter
        
html document.html,
        
hasTouch false;

    if (!
html.addEventListener) return false;

    var 
handler = function(){
        
html.removeEventListener(namehandlertrue);
        
hasTouch true;
    };

    try {
        
html.addEventListener(namehandlertrue);
        var 
event document.createEvent('TouchEvent');
        
event.initTouchEvent(name);
        
html.dispatchEvent(event);
        return 
hasTouch;
    } catch (
exception){}

    
handler(); // Remove listener
    
return false;
})();


/*
---

name: Swipe

description: Provides a custom swipe event for touch devices

authors: Christopher Beloch (@C_BHole), Christoph Pojer (@cpojer), Ian Collins (@3n)

license: MIT-style license.

requires: [Core/Element.Event, Custom-Event/Element.defineCustomEvent, Browser.Features.Touch]

provides: Swipe

...
*/

(function(){

var 
name 'swipe',
    
distanceKey name ':distance',
    
cancelKey name ':cancelVertical',
    
dflt 50;

var 
start = {}, disabledactive;

var 
clean = function(){
    
active false;
};

var 
events = {

    
touchstart: function(event){
        if (
event.touches.length 1) return;

        var 
touch event.touches[0];
        
active true;
        
start = {xtouch.pageXytouch.pageY};
    },
    
    
touchmove: function(event){
        if (
disabled || !active) return;
        
        var 
touch event.changedTouches[0],
            
end = {xtouch.pageXytouch.pageY};
        if (
this.retrieve(cancelKey) && Math.abs(start.end.y) > 10){
            
active false;
            return;
        }
        
        var 
distance this.retrieve(distanceKeydflt),
            
delta end.start.x,
            
isLeftSwipe delta < -distance,
            
isRightSwipe delta distance;

        if (!
isRightSwipe && !isLeftSwipe)
            return;
        
        
event.preventDefault();
        
active false;
        
event.direction = (isLeftSwipe 'left' 'right');
        
event.start start;
        
event.end end;
        
        
this.fireEvent(nameevent);
    },

    
touchendclean,
    
touchcancelclean

};

Element.defineCustomEvent(name, {

    
onSetup: function(){
        
this.addEvents(events);
    },

    
onTeardown: function(){
        
this.removeEvents(events);
    },

    
onEnable: function(){
        
disabled false;
    },

    
onDisable: function(){
        
disabled true;
        
clean();
    }

});

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