Fork me on GitHub

Site header view

4617 bytes of JavaScript by mark

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
/**
 * ?????
 * @param {HTMLAnchorElement} object
 * @param {Function} inCallBack ??????? ????? ? ??????? ????????
 * @param {Function} outCallBack ??????? ?????? ?? ??????? ????????
 * @param {Function} moveCallBack ??????? ???????? ? ??????? ????????
*/
SLEDGE.hover = function(object, inCallBack, outCallBack, moveCallBack){
    var that = this,
        globalCache = that.cache,
        body = document.body,
        storage = [],
        i,
        iMax = 0;
/* something something
 * something dark side
 */
    if (that.$d.isTouch){
// touch
        body.addEventListener('touchmove',function(e){
            for (i = 0; i < iMax; i += 5){
                if (that.testParentOf(globalCache.touchOnElement, storage[i])){
                    if (!storage[i + 4] && (storage[i + 1] !== undefined)){
                        storage[i + 1].call(storage[i], e);
                    }
                    if (storage[i + 3] !== undefined){
                        storage[i + 3].call(storage[i], e);
                    }
                    storage[i + 4] = true;
                } else if (storage[i + 4]){
                    storage[i + 4] = false;
                    if (storage[i + 2] !== undefined){
// false in call is touchmove out flag
                        storage[i + 2].call(storage[i], e, false);
                    }
                }
            }
        });
        body.addEventListener('touchstart',function(e){
            for (i = 0; i < iMax; i += 5){
                if (that.testParentOf(globalCache.touchOnElement, storage[i])){
                    storage[i + 4] = true;
                    if (storage[i + 1] !== undefined){
                        storage[i + 1].call(storage[i], e);
                    }
                }
            }
        });
        body.addEventListener('touchend',function(e){
            for (i = 0; i < iMax; i += 5){
                if (storage[i + 4]){
                    storage[i + 4] = false;
                    if ((storage[i + 2] !== undefined) && that.testParentOf(globalCache.touchOnElement, storage[i])){
// true in call is touchend out flag
                        storage[i + 2].call(storage[i], e , true);
                    }
                }

            }
        });
        that.hover = function(object, inCallBack, outCallBack, moveCallBack){
            storage.push(object, inCallBack, outCallBack, moveCallBack, false);
            iMax += 5;
            return function(onDestruction){
                that.slice(storage, that.arrayIndexOf(storage, object), 5);
                iMax -= 5;
                object = inCallBack = outCallBack = moveCallBack = null;
                if (onDestruction !== undefined){
                    onDestruction();
                }
            };
        };
        return that.hover(object, inCallBack, outCallBack, moveCallBack);
    } else{
        that.hover = function(object, inCallBack, outCallBack, moveCallBack){
            var isIn = false;
            function bodyMove(e){
                if (isIn && !that.testParentOf(e.target, object)){
                    isIn = false;
                    if (typeof outCallBack === 'function'){
                        outCallBack.call(object, e);
                    }
                }
            }
            function objectOver(e){
                if (!isIn){
                    isIn = true;
                    if (typeof inCallBack === 'function'){
                        inCallBack.call(object, e);
                    }
                }
            }
            function objectMove(e){
                if (!isIn && (typeof inCallBack === 'function')){
                    inCallBack.call(object, e);
                }
                isIn = true;
                if (typeof moveCallBack === 'function'){
                    moveCallBack.call(object, e);
                }
            }
            that.addEvent(body, 'mousemove', bodyMove);
            that.addEvent(object, 'mouseover', objectOver);
            that.addEvent(object, 'mousemove', objectMove);
// destruction function
            return function(onDestruction){
                that.removeEvent(body, 'mousemove', bodyMove);
                that.removeEvent(object, 'mouseover', objectOver);
                that.removeEvent(object, 'mousemove', objectOver);
                inCallBack = outCallBack = moveCallBack = object = isIn = null;
                if (typeof onDestruction === 'function'){
                    onDestruction();
                }
            }
        };
        return that.hover(object, inCallBack, outCallBack, moveCallBack);
    }
};