PageSourceSearch

http://pr.kebhana.com/contents/js/overflow.js

js kebhana.com collected 2026-09-24 09:13:54 UTC 18,652 bytes, 372 lines download raw bytes

1/*INISEAL:[GvA47Aes8vOg%2B3GDvXKezoDeY3Y%3D%0A]*/
2/*! tblscrol v.0.1.0. An overflow:auto polyfill for responsive design. (c) 2012: Scott Jehl, Filament Group, Inc. http://filamentgroup.github.com/tblscrol/license.txt */
3(function( w, undefined ){
4     
5    var doc = w.document,
6        docElem = doc.documentElement,
7        classtext = "tblscrol-enabled",
8     
9        // Touch events are used in the polyfill, and thus are a prerequisite
10        canBeFilledWithPoly = "ontouchmove" in doc,
11         
12        // The following attempts to determine whether the browser has native overflow support
13        // so we can enable it but not polyfill
14        overflowProbablyAlreadyWorks = 
15            // Features-first. iOS5 overflow scrolling property check - no UA needed here. thanks Apple :)
16            "WebkitOverflowScrolling" in docElem.style ||
17            // Touch events aren't supported and screen width is greater than X
18            // ...basically, this is a loose "desktop browser" check. 
19            // It may wrongly opt-in very large tablets with no touch support.
20            ( !canBeFilledWithPoly && w.screen.width > 1200 ) ||
21            // Hang on to your hats.
22            // Whitelist some popular, overflow-supporting mobile browsers for now and the future
23            // These browsers are known to get overlow support right, but give us no way of detecting it.
24            (function(){
25                var ua = w.navigator.userAgent,
26                    // Webkit crosses platforms, and the browsers on our list run at least version 534
27                    webkit = ua.match( /AppleWebKit\/([0-9]+)/ ),
28                    wkversion = webkit && webkit[1],
29                    wkLte534 = webkit && wkversion >= 534;
30                     
31                return (
32                    /* Android 3+ with webkit gte 534
33                    ~: Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13 */
34                    ua.match( /Android ([0-9]+)/ ) && RegExp.$1 >= 3 && wkLte534 ||
35                    /* Blackberry 7+ with webkit gte 534
36                    ~: Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0 Mobile Safari/534.11+ */
37                    ua.match( / Version\/([0-9]+)/ ) && RegExp.$1 >= 0 && w.blackberry && wkLte534 ||
38                    /* Blackberry Playbook with webkit gte 534
39                    ~: Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.8+ (KHTML, like Gecko) Version/0.0.1 Safari/534.8+ */  
40                    ua.indexOf( /PlayBook/ ) > -1 && RegExp.$1 >= 0 && wkLte534 ||
41                    /* Firefox Mobile (Fennec) 4 and up
42                    ~: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:2.1.1) Gecko/ Firefox/4.0.2pre Fennec/4.0. */
43                    ua.match( /Fennec\/([0-9]+)/ ) && RegExp.$1 >= 4 ||
44                    /* WebOS 3 and up (TouchPad too)
45                    ~: Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.48 Safari/534.6 TouchPad/1.0 */
46                    ua.match( /wOSBrowser\/([0-9]+)/ ) && RegExp.$1 >= 233 && wkLte534 ||
47                    /* Nokia Browser N8
48                    ~: Mozilla/5.0 (Symbian/3; Series60/5.2 NokiaN8-00/012.002; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/533.4 (KHTML, like Gecko) NokiaBrowser/7.3.0 Mobile Safari/533.4 3gpp-gba 
49                    ~: Note: the N9 doesn't have native overflow with one-finger touch. wtf */
50                    ua.match( /NokiaBrowser\/([0-9\.]+)/ ) && parseFloat(RegExp.$1) === 7.3 && webkit && wkversion >= 533
51                );
52            })(),
53             
54        // Easing can use any of Robert Penner's equations (http://www.robertpenner.com/easing_terms_of_use.html). By default, tblscrol includes ease-out-cubic
55        // arguments: t = current iteration, b = initial value, c = end value, d = total iterations
56        // use w.tblscrol.easing to provide a custom function externally, or pass an easing function as a callback to the toss method
57        defaultEasing = function (t, b, c, d) {
58            return c*((t=t/d-1)*t*t + 1) + b;
59        },  
60             
61        enabled = false,
62         
63        // Keeper of intervals
64        timeKeeper,
65                 
66        /* toss scrolls and element with easing
67         
68        // elem is the element to scroll
69        // options hash:
70            * left is the desired horizontal scroll. Default is "+0". For relative distances, pass a string with "+" or "-" in front.
71            * top is the desired vertical scroll. Default is "+0". For relative distances, pass a string with "+" or "-" in front.
72            * duration is the number of milliseconds the throw will take. Default is 100.
73            * easing is an optional custom easing function. Default is w.tblscrol.easing. Must follow the easing function signature 
74        */
75        toss = function( elem, options ){
76            var i = 0,
77                sLeft = elem.scrollLeft,
78                sTop = elem.scrollTop,
79                // Toss defaults
80                o = {
81                    top: "+0",
82                    left: "+0",
83                    duration: 100,
84                    easing: w.tblscrol.easing
85                },
86                endLeft, endTop;
87             
88            // Mixin based on predefined defaults
89            if( options ){
90                for( var j in o ){
91                    if( options[ j ] !== undefined ){
92                        o[ j ] = options[ j ];
93                    }
94                }
95            }
96             
97            // Convert relative values to ints
98            // First the left val
99            if( typeof o.left === "string" ){
100                o.left = parseFloat( o.left );
101                endLeft = o.left + sLeft;
102            }
103            else {
104                endLeft = o.left;
105                o.left = o.left - sLeft;
106            }
107            // Then the top val
108            if( typeof o.top === "string" ){
109                o.top = parseFloat( o.top );
110                endTop = o.top + sTop;
111            }
112            else {
113                endTop = o.top;
114                o.top = o.top - sTop;
115            }
116 
117            timeKeeper = setInterval(function(){                    
118                if( i++ < o.duration ){
119                    elem.scrollLeft = o.easing( i, sLeft, o.left, o.duration );
120                    elem.scrollTop = o.easing( i, sTop, o.top, o.duration );
121                }
122                else{
123                    if( endLeft !== elem.scrollLeft ){
124                        elem.scrollLeft = endLeft;
125                    }
126                    if( endTop !== elem.scrollTop ){
127                        elem.scrollTop = endTop;
128                    }
129                    intercept();
130                }
131            }, 1 );
132             
133            // Return the values, post-mixin, with end values specified
134            return { top: endTop, left: endLeft, duration: o.duration, easing: o.easing };
135        },
136         
137        // find closest tblscrol (elem or a parent)
138        closest = function( target, ascend ){
139            return !ascend && target.className && target.className.indexOf( "tblscrol" ) > -1 && target || closest( target.parentNode );
140        },
141                 
142        // Intercept any throw in progress
143        intercept = function(){
144            clearInterval( timeKeeper );
145        },
146             
147        // Enable and potentially polyfill overflow
148        enable = function(){
149                 
150            // If it's on, 
151            if( enabled ){
152                return;
153            }
154            // It's on.
155            enabled = true;
156                 
157            // If overflowProbablyAlreadyWorks or at least the element canBeFilledWithPoly, add a class to cue CSS that assumes overflow scrolling will work (setting height on elements and such)
158            if( overflowProbablyAlreadyWorks || canBeFilledWithPoly ){
159                docElem.className += " " + classtext;
160            }
161                 
162            // Destroy everything later. If you want to.
163            w.tblscrol.forget = function(){
164                // Strip the class name from docElem
165                docElem.className = docElem.className.replace( classtext, "" );
166                // Remove touch binding (check for method support since this part isn't qualified by touch support like the rest)
167                if( doc.removeEventListener ){
168                    doc.removeEventListener( "touchstart", start, false );
169                }
170                // reset easing to default
171                w.tblscrol.easing = defaultEasing;
172                 
173                // Let 'em know
174                enabled = false;
175            };
176     
177            // If overflowProbablyAlreadyWorks or it doesn't look like the browser canBeFilledWithPoly, our job is done here. Exit viewport left.
178            if( overflowProbablyAlreadyWorks || !canBeFilledWithPoly ){
179                return;
180            }
181 
182            // Fill 'er up!
183            // From here down, all logic is associated with touch scroll handling
184                // elem references the tblscrol element in use
185            var elem,
186                 
187                // The last several Y values are kept here
188                lastTops = [],
189         
190                // The last several X values are kept here
191                lastLefts = [],
192                 
193                // lastDown will be true if the last scroll direction was down, false if it was up
194                lastDown,
195                 
196                // lastRight will be true if the last scroll direction was right, false if it was left
197                lastRight,
198                 
199                // For a new gesture, or change in direction, reset the values from last scroll
200                resetVertTracking = function(){
201                    lastTops = [];
202                    lastDown = null;
203                },
204                 
205                resetHorTracking = function(){
206                    lastLefts = [];
207                    lastRight = null;
208                },
209                 
210                // After releasing touchend, throw the tblscrol element, depending on momentum
211                finishScroll = function(){
212                    // Come up with a distance and duration based on how 
213                    // Multipliers are tweaked to a comfortable balance across platforms
214                    var top = ( lastTops[ 0 ] - lastTops[ lastTops.length -1 ] ) * 8,
215                        left = ( lastLefts[ 0 ] - lastLefts[ lastLefts.length -1 ] ) * 8,
216                        duration = Math.max( Math.abs( left ), Math.abs( top ) ) / 8;
217                     
218                    // Make top and left relative-style strings (positive vals need "+" prefix)
219                    top = ( top > 0 ? "+" : "" ) + top;
220                    left = ( left > 0 ? "+" : "" ) + left;
221                     
222                    // Make sure there's a significant amount of throw involved, otherwise, just stay still
223                    if( !isNaN( duration ) && duration > 0 && ( Math.abs( left ) > 80 || Math.abs( top ) > 80 ) ){
224                        toss( elem, { left: left, top: top, duration: duration } );
225                    }
226                },
227             
228                // On webkit, touch events hardly trickle through textareas and inputs
229                // Disabling CSS pointer events makes sure they do, but it also makes the controls innaccessible
230                // Toggling pointer events at the right moments seems to do the trick
231                // Thanks Thomas Bachem http://stackoverflow.com/a/5798681 for the following
232                inputs,
233                setPointers = function( val ){
234                    inputs = elem.querySelectorAll( "textarea, input" );
235                    for( var i = 0, il = inputs.length; i < il; i++ ) {
236                        inputs[ i ].style.pointerEvents = val;
237                    }
238                },
239                 
240                // For nested tblscrols, changeScrollTarget restarts a touch event cycle on a parent or child tblscrol
241                changeScrollTarget = function( startEvent, ascend ){
242                    if( doc.createEvent ){
243                        var newTarget = ( !ascend || ascend === undefined ) && elem.parentNode || elem.touchchild || elem,
244                            tEnd;
245                                 
246                        if( newTarget !== elem ){
247                            tEnd = doc.createEvent( "HTMLEvents" );
248                            tEnd.initEvent( "touchend", true, true );
249                            elem.dispatchEvent( tEnd );
250                            newTarget.touchchild = elem;
251                            elem = newTarget;
252                            newTarget.dispatchEvent( startEvent );
253                        }
254                    }
255                },
256                 
257                // Touchstart handler
258                // On touchstart, touchmove and touchend are freshly bound, and all three share a bunch of vars set by touchstart
259                // Touchend unbinds them again, until next time
260                start = function( e ){
261                     
262                    // Stop any throw in progress
263                    intercept();
264                     
265                    // Reset the distance and direction tracking
266                    resetVertTracking();
267                    resetHorTracking();
268                         
269                    elem = closest( e.target );
270                         
271                    if( !elem || elem === docElem || e.touches.length > 1 ){
272                        return;
273                    }           
274 
275                    setPointers( "none" );
276                    var touchStartE = e,
277                        scrollT = elem.scrollTop,
278                        scrollL = elem.scrollLeft,
279                        height = elem.offsetHeight,
280                        width = elem.offsetWidth,
281                        startY = e.touches[ 0 ].pageY,
282                        startX = e.touches[ 0 ].pageX,
283                        scrollHeight = elem.scrollHeight,
284                        scrollWidth = elem.scrollWidth,
285                     
286                        // Touchmove handler
287                        move = function( e ){
288                         
289                            var ty = scrollT + startY - e.touches[ 0 ].pageY,
290                                tx = scrollL + startX - e.touches[ 0 ].pageX,
291                                down = ty >= ( lastTops.length ? lastTops[ 0 ] : 0 ),
292                                right = tx >= ( lastLefts.length ? lastLefts[ 0 ] : 0 );
293                                 
294                            // If there's room to scroll the current container, prevent the default window scroll
295                            if( ( ty > 0 && ty < scrollHeight - height ) || ( tx > 0 && tx < scrollWidth - width ) ){
296                                e.preventDefault();
297                            }
298                            // This bubbling is dumb. Needs a rethink.
299                            else {
300                                changeScrollTarget( touchStartE );
301                            }
302                             
303                            // If down and lastDown are inequal, the y scroll has changed direction. Reset tracking.
304                            if( lastDown && down !== lastDown ){
305                                resetVertTracking();
306                            }
307                             
308                            // If right and lastRight are inequal, the x scroll has changed direction. Reset tracking.
309                            if( lastRight && right !== lastRight ){
310                                resetHorTracking();
311                            }
312                             
313                            // remember the last direction in which we were headed
314                            lastDown = down;
315                            lastRight = right;                          
316                             
317                            // set the container's scroll
318                            elem.scrollTop = ty;
319                            elem.scrollLeft = tx;
320                         
321                            lastTops.unshift( ty );
322                            lastLefts.unshift( tx );
323                         
324                            if( lastTops.length > 3 ){
325                                lastTops.pop();
326                            }
327                            if( lastLefts.length > 3 ){
328                                lastLefts.pop();
329                            }
330                        },
331                     
332                        // Touchend handler
333                        end = function( e ){
334                            // Apply momentum based easing for a graceful finish
335                            finishScroll(); 
336                            // Bring the pointers back
337                            setPointers( "auto" );
338                            setTimeout( function(){
339                                setPointers( "none" );
340                            }, 450 );
341                            elem.removeEventListener( "touchmove", move, false );
342                            elem.removeEventListener( "touchend", end, false );
343                        };
344                     
345                    elem.addEventListener( "touchmove", move, false );
346                    elem.addEventListener( "touchend", end, false );
347                };
348                 
349            // Bind to touch, handle move and end within
350            doc.addEventListener( "touchstart", start, false );
351        };
352         
353    // Expose tblscrol API
354    w.tblscrol = {
355        set: enable,
356        forget: function(){},
357        easing: defaultEasing,
358        toss: toss,
359        intercept: intercept,
360        closest: closest,
361        support: overflowProbablyAlreadyWorks ? "native" : canBeFilledWithPoly && "polyfilled" || "none"
362    };
363     
364    // Auto-init
365    enable();
366         
367})( this );
368/*
369$(document).ready(function(){
370	alert('1');
371});
372*/

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.