PageSourceSearch

https://smitechnology.com/js/jquerymobile-swipeupdown.js?v=260904

js smitechnology.com collected 2026-10-06 13:56:24 UTC 3,353 bytes, 92 lines download raw bytes

1// jQueryMobile-SwipeUpDown
2// ----------------------------------
3//
4// Copyright (c)2012 Donnovan Lewis
5// Distributed under MIT license
6//
7// https://github.com/blackdynamo/jquerymobile-swipeupdown
8
9(function () {
10// initializes touch and scroll events
11    var supportTouch = $.support.touch,
12        scrollEvent = "touchmove scroll",
13        touchStartEvent = supportTouch ? "touchstart" : "mousedown",
14        touchStopEvent = supportTouch ? "touchend" : "mouseup",
15        touchMoveEvent = supportTouch ? "touchmove" : "mousemove";
16
17    // handles swipeup and swipedown
18    $.event.special.swipeupdown = {
19        setup: function () {
20            var thisObject = this;
21            var $this = $(thisObject);
22
23            $this.bind(touchStartEvent, function (event) {
24                var data = event.originalEvent.touches ?
25                        event.originalEvent.touches[ 0 ] :
26                        event,
27                    start = {
28                        time: (new Date).getTime(),
29                        coords: [ data.pageX, data.pageY ],
30                        origin: $(event.target)
31                    },
32                    stop;
33
34                function moveHandler(event) {
35                    if (!start) {
36                        return;
37                    }
38
39                    var data = event.originalEvent.touches ?
40                        event.originalEvent.touches[ 0 ] :
41                        event;
42                    stop = {
43                        time: (new Date).getTime(),
44                        coords: [ data.pageX, data.pageY ]
45                    };
46
47                    // prevent scrolling
48                    if (Math.abs(start.coords[1] - stop.coords[1]) > 10) {
49                        event.preventDefault();
50                    }
51                }
52
53                $this
54                    .bind(touchMoveEvent, moveHandler)
55                    .one(touchStopEvent, function (event) {
56                        $this.unbind(touchMoveEvent, moveHandler);
57                        if (start && stop) {
58                            if (stop.time - start.time < 1000 &&
59                                Math.abs(start.coords[1] - stop.coords[1]) > 30 ||
60                                Math.abs(start.coords[0] - stop.coords[0]) < 75) {
61                                start.origin
62                                    .trigger("swipeupdown")
63                                    .trigger(start.coords[1] > stop.coords[1] ? "swipeup" : "swipedown");
64                            }
65                        }
66                        start = stop = undefined;
67                    });
68            });
69        }
70    };
71
72//Adds the events to the jQuery events special collection
73    $.each({
74        swipedown: "swipeupdown",
75        swipeup: "swipeupdown"
76    }, function (event, sourceEvent) {
77        $.event.special[event] = {
78            setup: function () {
79                $(this).bind(sourceEvent, $.noop);
80            }
81        };
82        //Adds new events shortcuts
83        $.fn[ event ] = function( fn ) {
84            return fn ? this.bind( event, fn ) : this.trigger( event );
85        };
86        // jQuery < 1.8
87        if ( $.attrFn ) {
88            $.attrFn[ event ] = true;
89        }
90    });
91
92})();

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.