PageSourceSearch

https://www.youthforhumanrights.ru/sites/all/themes/gold_master/ipad_utils.js

js youthforhumanrights.ru collected 2026-09-26 19:40:00 UTC 4,713 bytes, 161 lines download raw bytes

1/**
2 * @file
3 * iPad-specific utils.
4 */
5
6/**
7 * Remove 0.3 sec click delay from elements.
8 * @from: http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone
9 * @usage: new NoClickDelay(document.getElementById('element')); // <- will apply for all clicks inside the element
10 */
11function NoClickDelay(el, props) {
12
13    if (typeof props == 'undefined') {
14        this.props = {
15            start: true,
16            move: true,
17            end: true,
18            clicks: true,
19            debug: false,
20            hoverDuringMove: false,
21            mouseOut: true
22        };
23    } else {
24        this.props = props;
25    }
26
27    if (this.props.hoverDuringMove) {
28        setInterval(function() {
29            this._hoverClose = true;
30        }, 2000);
31    }
32
33    this.element = typeof el == 'object' ? el : document.getElementById(el);
34
35    if( window.Touch ) {
36        this.element.addEventListener('touchstart', this, false);
37    }
38
39}
40
41NoClickDelay.prototype = {
42    handleEvent: function(e) {
43        switch(e.type) {
44            case 'touchstart': this.onTouchStart(e); break;
45            case 'touchmove': this.onTouchMove(e); break;
46            case 'touchend': this.onTouchEnd(e); break;
47        }
48    },
49
50    onTouchStart: function(e) {
51
52        if (!this.props.start) {
53            return;
54        }
55
56        if (this.props.debug) {
57            gcui_log('touch detected');
58        }
59
60        e.preventDefault();
61        this.moved = false;
62
63        this.element.addEventListener('touchmove', this, false);
64        this.element.addEventListener('touchend', this, false);
65
66        var theTarget = document.elementFromPoint(e.touches[0].clientX, e.touches[0].clientY);
67        if(theTarget.nodeType == 3) theTarget = theTarget.parentNode;
68        var theEvent = document.createEvent('MouseEvents');
69        theEvent.initEvent('mouseover', true, true);
70        theTarget.dispatchEvent(theEvent);
71
72        this.initialElem = theTarget;
73
74        if (this.props.debug) {
75            $(theTarget).css('border', '2px dashed blue');
76        }
77
78    },
79
80    onTouchMove: function(e) {
81
82        if (!this.props.move) {
83            return;
84        }
85
86        this.moved = true;
87
88        if (this.props.hoverDuringMove) {
89            var theTarget = document.elementFromPoint(e.touches[0].clientX, e.touches[0].clientY);
90            if(theTarget.nodeType == 3) theTarget = theTarget.parentNode;
91            var theEvent = document.createEvent('MouseEvents');
92            theEvent.initEvent('mouseover', true, true);
93            theTarget.dispatchEvent(theEvent);
94
95            if (this._hoverClose) {
96                theTarget = document.elementFromPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
97                if(theTarget.nodeType == 3) theTarget = theTarget.parentNode;
98                var theEvent = document.createEvent('MouseEvents');
99                theEvent.initEvent('mouseout', true, true);
100                theTarget.dispatchEvent(theEvent);
101                this._hoverClose = false;
102            }
103        }
104
105    },
106
107    onTouchEnd: function(e) {
108
109        if (!this.props.end) {
110            return;
111        }
112
113        if (this.props.debug) {
114            gcui_log('touch end');
115        }
116
117        this.element.removeEventListener('touchmove', this, false);
118        this.element.removeEventListener('touchend', this, false);
119
120        var theTarget = document.elementFromPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
121        if(theTarget.nodeType == 3) theTarget = theTarget.parentNode;
122
123        if( this.props.clicks &&  !this.moved) {
124
125            if (this.props.debug) {
126                $(theTarget).css('border', '2px dashed red');
127            }
128
129            var theEvent = document.createEvent('MouseEvents');
130            theEvent.initEvent('click', true, true);
131            theTarget.dispatchEvent(theEvent);
132        }
133
134        if (this.props.mouseOut) {
135
136            var theEvent2 = document.createEvent('MouseEvents');
137            theEvent2.initEvent('mouseout', true, true);
138            theTarget.dispatchEvent(theEvent2);
139
140            if (this.props.debug) {
141                setTimeout(function() {
142                    $(theTarget).css('border', 'none');
143                }, 500);
144            }
145
146            if (theTarget != this.initialElem) {
147                var theEvent3 = document.createEvent('MouseEvents');
148                theEvent3.initEvent('mouseout', true, true);
149                this.initialElem.dispatchEvent(theEvent3);
150
151                if (this.props.debug) {
152                    setTimeout(function() {
153                        $(this.initialElem).css('border', 'none');
154                    }, 500);
155                }
156            }
157
158        }
159
160    }
161};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.