Repository: stephband/jquery.event.swipe
Branch: master
Commit: 355d015abf34
Files: 6
Total size: 18.0 KB
Directory structure:
gitextract_o4lzu_em/
├── README.md
├── bower.json
├── event.swipe.jquery.json
├── index.html
├── js/
│ └── jquery.event.swipe.js
└── package.json
================================================
FILE CONTENTS
================================================
================================================
FILE: README.md
================================================
<h1>jquery.event.swipe</h1>
<h2>Dependencies</h2>
<p>jQuery.event.move: <a href="http://stephband.info/jquery.event.move/">stephband.info/jquery.event.move</a></p>
<p>One of swipeleft, swiperight, swipeup or swipedown is triggered on moveend, when the move has covered at least a threshold proportion of the dimension of the target node.</p>
<p>Swipe events are a thin wrapper around the moveend event, a convenience to reveal when a finger has made a swipe gesture. As such they don't bubble — they are retriggered on each passing of a moveend event. The underlying move events do bubble and delegate. Use them if you need more flexibility.</p>
<h2>CommonJS</h2>
<p>If you're using Browserify, or any other CommonJS-compatible module system, you can require this script by passing it your jQuery reference. For example,<p>
<pre><code class="js">
require('./path/to/jquery.event.move.js')(jQuery);
</code></pre>
<h2>Demo and docs</h2>
<a href="http://stephband.info/jquery.event.swipe">stephband.info/jquery.event.swipe</a>
================================================
FILE: bower.json
================================================
{
"name": "jquery.event.swipe",
"version": "0.5.3",
"author": {
"name": "Stephen Band",
"url": "http://stephband.info",
"twitter": "stephband"
},
"dependencies": {
"jquery": ">=1.7.0",
"jquery.event.move": "1.x"
},
"licenses": [{"url":"http://www.wtfpl.net/txt/copying/"}],
"main": "js/jquery.event.swipe.js",
"description": "jQuery special events for the gestures swipeleft, swiperight, swipeup and swipedown.",
"keywords": ["touch","special","event","swipe"],
"homepage": "http://github.com/stephband/jquery.event.swipe",
"docs": "http://stephband.info/jquery.event.swipe"
}
================================================
FILE: event.swipe.jquery.json
================================================
{
"name": "event.swipe",
"title": "jquery.event.swipe",
"version": "0.5.3",
"author": {
"name": "Stephen Band",
"url": "http://stephband.info"
},
"dependencies": {
"jquery": ">=1.7.0",
"jquery.event.move": "1.3.x"
},
"licenses": [{"url":"http://www.wtfpl.net/txt/copying/"}],
"files": ["js/jquery.event.swipe.js"],
"description": "jQuery special events for the gestures swipeleft, swiperight, swipeup and swipedown.",
"keywords": ["touch","special","event","swipe"],
"homepage": "http://github.com/stephband/jquery.event.swipe",
"docs": "http://stephband.info/jquery.event.swipe"
}
================================================
FILE: index.html
================================================
---
title: jQuery.event.swipe
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="author" content="">
<meta name="description" content="">
<title>jQuery.event.swipe</title>
<script>document.documentElement.className = 'js';</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.5">
<!-- Force latest IE rendering engine & Chrome Frame -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!-- Make IE recognise HTML5 elements for styling -->
<!--[if lte IE 8]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link rel="icon" type="image/png" href="images/favicon.png" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="stylesheet" type="text/css" href="http://stephband.info/css/template.min.css" />
<link rel="stylesheet" type="text/css" href="http://stephband.info/css/template.theme.min.css" />
<link rel="stylesheet" type="text/css" href="http://stephband.github.com/css/site.layout.css" />
<link rel="stylesheet" type="text/css" href="http://stephband.github.com/css/docs.classes.css" />
<link rel="stylesheet" type="text/css" href="http://stephband.github.com/css/site.highlight.light.css" />
<!--[if lte IE 8]><link rel="stylesheet" type="text/css" href="http://stephband.github.com/template/css/template.ie.css" /><![endif]-->
<!--[if IE 8]><link rel="stylesheet" type="text/css" href="http://stephband.github.com/template/css/template.ie8.css" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" type="text/css" href="http://stephband.github.com/template/css/template.ie7.css" /><![endif]-->
<style>
.site_wrap > .slides_wrap {
margin-bottom: 1em;
margin-left: -8px;
margin-right: -8px;
}
.img_slides_wrap {
width: 784px;
border: 8px solid #333333;
background-color: #444444;
overflow: hidden;
}
.img_slide {
padding: 0;
}
.js .img_slide {
/* Overide template's height transitions. */
width: 100%;
height: auto;
}
.slide_buttons_index {
text-align: center;
}
.notransition,
.notransition .slide {
-webkit-transition-duration: 0 !important;
-moz-transition-duration: 0 !important;
-ms-transition-duration: 0 !important;
transition-duration: 0 !important;
-webkit-transition-delay: 0 !important;
-moz-transition-delay: 0 !important;
-ms-transition-delay: 0 !important;
transition-delay: 0 !important;
}
@media screen and (max-width: 640px) {
.img_slides_wrap {
width: 100%;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
-ms-box-sizing: content-box;
box-sizing: content-box;
}
}
</style>
</head>
<body>
<header class="site_header" id="page_header">
<div class="site_wrap wrap">
<a class="logo_thumb thumb" href="http://stephband.info" title="stephband" rel="index">
<h1>stephband.info</h1>
</a>
</div>
</header>
<div class="site_wrap wrap">
<h1>jQuery.event.swipe</h1>
<div class="img_slides_wrap slides_wrap wrap">
<img class="img_slide slide active" id="slide1" src="https://lh5.googleusercontent.com/-MShhyv4lWuM/T4Si18g0XsI/AAAAAAAAANU/Nnnxh68myRA/s768/Norway_201241.png"
/><img class="img_slide slide" id="slide2" src="https://lh6.googleusercontent.com/-BED5h574s1Q/T4Sji7_hmOI/AAAAAAAAAO8/JMChDngsCDk/s768/Norway_201284.png"
/><img class="img_slide slide" id="slide3" src="https://lh6.googleusercontent.com/-n31QkVB4M9c/T4SjckZM1TI/AAAAAAAAAOs/H26JyEo9970/s768/Norway_201276.png"
/><img class="img_slide slide" id="slide4" src="https://lh6.googleusercontent.com/-jti_dD8mDiQ/T4ShY14T5HI/AAAAAAAAAKE/-jF6OT_zmb4/s768/Norway_2012102.png" />
</div>
<ul class="horizontal slide_buttons_index buttons_index index">
<li><a class="slide_button button" href="#slide1">1</a></li>
<li><a class="slide_button button" href="#slide2">2</a></li>
<li><a class="slide_button button" href="#slide3">3</a></li>
<li><a class="slide_button button" href="#slide4">4</a></li>
</ul>
<h2>Project</h2>
<ul>
<li>Github: <a href="http://github.com/stephband/jquery.event.swipe">github.com/stephband/jquery.event.swipe</a></li>
<li>Issues: <a href="http://github.com/stephband/jquery.event.swipe/issues">github.com/stephband/jquery.event.swipe/issues</a></li>
<li>Dependency: <a href="http://github.com/stephband/jquery.event.move">github.com/stephband/jquery.event.move</a></li>
</ul>
<h2 id="what">Swipe events</h2>
<dl>
<dt>swipeleft, swiperight, swipeup, swipedown</dt>
<dd>Fired when the finger is released from the touch surface (or mouse button) if the finger has a) just moved at least a threshold distance or b) moved quickly over a shorter distance.
Also responds to mouse events.</dd>
</dl>
<p>Swipe event objects are augmented with the properties:</p>
<dl>
<dt>e.pageX, e.pageY</dt>
<dd>Current page coordinates of pointer.</dd>
<dt>e.startX, e.startY</dt>
<dd>Page coordinates the pointer had at the start of the swipe.</dd>
<dt>e.distX, e.distY</dt>
<dd>Distance finger moved during the swipe.</dd>
<dt>e.velocityX, e.velocityY</dt>
<dd>Velocity, in pixels/ms, averaged over the last few move events.</dd>
</dl>
<h2 id="how">How to use swipe events</h2>
{% highlight js %}
var slides = jQuery('.slides'),
i = 0;
slides
.on('swipeleft', function(e) {
slides.eq(i + 1).addClass('active');
})
.on('swiperight', function(e) {
slides.eq(i - 1).addClass('active');
});{% endhighlight %}
<p>
Swipe events are a thin wrapper around the moveend event; a convenience to reveal when a finger has moved in a swipe gesture.
The underlying move events bubble and you can delegate them, but making the swipe events also do this would be unnecessarily expensive.
Use move events if you need more flexibility.
</p>
<h2 id="scroll">Swipe or scroll</h2>
<p>
Swipe events are a thin wrapper built on top of move events (<a href="http://stephband.info/jquery.event.move/">stephband.info/jquery.event.move</a>).
Move events, by default, override native scrolling, as they assume that you want to move something rather than scroll the window.
To re-enable scrolling, call <code>e.preventDefault()</code> inside a movestart handler.
</p>
<p>
In the example above, we want to be able to <code>swipeleft</code> and <code>swiperight</code>, but scroll up and down.
Inside a movestart handler, the direction of the finger is moving is calculated and the event is prevented if it is found to be moving up or down::</p>
{% highlight js %}
jQuery('.mydiv')
.on('movestart', function(e) {
// If the movestart is heading off in an upwards or downwards
// direction, prevent it so that the browser scrolls normally.
if ((e.distX > e.distY && e.distX < -e.distY) ||
(e.distX < e.distY && e.distX > -e.distY)) {
e.preventDefault();
}
});{% endhighlight %}
<p>To see how the example at the top of the page works, view source.</p>
<h2 id="where">Who made it?</h2>
<p>I did. I'm <a href="http://twitter.com/stephband">stephband</a> on twitter, if you're into that sort of thing.</p>
</div>
<footer class="site_footer">
<div class="full_wrap wrap">
<div class="bio_col col">
<h3>Who made this?</h3>
<p>I did. I come from Scotland and I live in Lausanne, Switzerland. I make web things at <a href="http://cruncher.ch">Cruncher</a>. I miss Branston Pickle. When I'm not glued to a screen I play music and hike mountains.</p>
</div
><div class="repo_col col">
<h3>More code</h3>
<ul class="repo_index index">
<li><a href="http://stephband.info/bolt">Bolt</a></li>
<li><a href="http://stephband.info/jparallax/">jQuery.parallax</a></li>
<li><a href="http://stephband.info/jquery.event.tap/">jQuery.event.tap</a></li>
<li><a href="http://stephband.info/jquery.event.move/">jQuery.event.move</a></li>
<li><a href="http://stephband.info/jquery.event.swipe/">jQuery.event.swipe</a></li>
</ul>
</div
><div class="social_col col">
<h3>Find me on...</h3>
<ul class="social_index index">
<li><a href="http://twitter.com/stephband">twitter</a></li>
<li><a href="http://github.com/stephband">github</a></li>
<li><a href="http://plus.google.com/114566808430966059989/photos">google+</a></li>
<li><a href="http://www.linkedin.com/profile/view?id=27013870">linkedin</a></li>
</ul>
</div>
</div>
</footer>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script>
<script src="http://stephband.info/jquery.event.move/js/jquery.event.move.js"></script>
<script src="js/jquery.event.swipe.js"></script>
<script>
(function(jQuery, undefined) {
jQuery(document).ready(function() {
var wrap = jQuery('.slides_wrap'),
slides = wrap.find('.img_slide'),
active = slides.filter('.active'),
buttons = jQuery('.slide_button'),
i = slides.index(active),
width = wrap.width();
// Listen for swipe events on slides, and use a custom 'activate'
// event to add and remove the class 'active' to the previous
// or next slide, and to keep the index up-to-date. The class
// 'active' uses CSS transitions to make the slide move.
slides
.on('swipeleft', function(e) {
if (i === slides.length - 1) { return; }
slides.eq(i + 1).trigger('activate');
})
.on('swiperight', function(e) {
if (i === 0) { return; }
slides.eq(i - 1).trigger('activate');
})
.on('activate', function(e) {
slides.eq(i).removeClass('active');
buttons.eq(i).removeClass('on');
jQuery(e.target).addClass('active');
// Update the active slide index
i = slides.index(e.target);
// select active class for slide button
buttons.eq(i).addClass('on');
})
// The code below handles what happens before any swipe event is triggered.
// It makes the slides demo on this page work nicely, but really doesn't
// have much to do with demonstrating the swipe events themselves. For more
// on move events see:
//
// http://stephband.info/jquery.event.move
.on('movestart', function(e) {
// If the movestart heads off in a upwards or downwards
// direction, prevent it so that the browser scrolls normally.
if ((e.distX > e.distY && e.distX < -e.distY) ||
(e.distX < e.distY && e.distX > -e.distY)) {
e.preventDefault();
return;
}
// To allow the slide to keep step with the finger,
// temporarily disable transitions.
wrap.addClass('notransition');
})
.on('move', function(e) {
var left = 100 * e.distX / width;
// Move slides with the finger
if (e.distX < 0) {
if (slides[i+1]) {
slides[i].style.left = left + '%';
slides[i+1].style.left = (left+100)+'%';
}
else {
slides[i].style.left = left/4 + '%';
}
}
if (e.distX > 0) {
if (slides[i-1]) {
slides[i].style.left = left + '%';
slides[i-1].style.left = (left-100)+'%';
}
else {
slides[i].style.left = left/5 + '%';
}
}
})
.on('moveend', function(e) {
wrap.removeClass('notransition');
slides[i].style.left = '';
if (slides[i+1]) {
slides[i+1].style.left = '';
}
if (slides[i-1]) {
slides[i-1].style.left = '';
}
});
// Make the buttons work, too. Hijack the id stored in the href and use
// it to activate the slide.
jQuery(document)
.on('click', '.slide_button', function(e) {
var href = e.currentTarget.hash;
jQuery(href).trigger('activate');
e.preventDefault();
});
});
})(jQuery);
</script>
</body>
</html>
================================================
FILE: js/jquery.event.swipe.js
================================================
// jQuery.event.swipe
// 0.5
// Stephen Band
// Dependencies
// jQuery.event.move 1.2
// One of swipeleft, swiperight, swipeup or swipedown is triggered on
// moveend, when the move has covered a threshold ratio of the dimension
// of the target node, or has gone really fast. Threshold and velocity
// sensitivity changed with:
//
// jQuery.event.special.swipe.settings.threshold
// jQuery.event.special.swipe.settings.sensitivity
(function (thisModule) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery', undefined, 'jquery.event.move'], thisModule);
} else if ((typeof module !== "undefined" && module !== null) && module.exports) {
module.exports = thisModule;
} else {
// Browser globals
thisModule(jQuery);
}
})(function(jQuery, undefined){
var add = jQuery.event.add,
remove = jQuery.event.remove,
// Just sugar, so we can have arguments in the same order as
// add and remove.
trigger = function(node, type, data) {
jQuery.event.trigger(type, data, node);
},
settings = {
// Ratio of distance over target finger must travel to be
// considered a swipe.
threshold: 0.4,
// Faster fingers can travel shorter distances to be considered
// swipes. 'sensitivity' controls how much. Bigger is shorter.
sensitivity: 6
};
function moveend(e) {
var w, h, event;
w = e.currentTarget.offsetWidth;
h = e.currentTarget.offsetHeight;
// Copy over some useful properties from the move event
event = {
distX: e.distX,
distY: e.distY,
velocityX: e.velocityX,
velocityY: e.velocityY,
finger: e.finger
};
// Find out which of the four directions was swiped
if (e.distX > e.distY) {
if (e.distX > -e.distY) {
if (e.distX/w > settings.threshold || e.velocityX * e.distX/w * settings.sensitivity > 1) {
event.type = 'swiperight';
trigger(e.currentTarget, event);
}
}
else {
if (-e.distY/h > settings.threshold || e.velocityY * e.distY/w * settings.sensitivity > 1) {
event.type = 'swipeup';
trigger(e.currentTarget, event);
}
}
}
else {
if (e.distX > -e.distY) {
if (e.distY/h > settings.threshold || e.velocityY * e.distY/w * settings.sensitivity > 1) {
event.type = 'swipedown';
trigger(e.currentTarget, event);
}
}
else {
if (-e.distX/w > settings.threshold || e.velocityX * e.distX/w * settings.sensitivity > 1) {
event.type = 'swipeleft';
trigger(e.currentTarget, event);
}
}
}
}
function getData(node) {
var data = jQuery.data(node, 'event_swipe');
if (!data) {
data = { count: 0 };
jQuery.data(node, 'event_swipe', data);
}
return data;
}
jQuery.event.special.swipe =
jQuery.event.special.swipeleft =
jQuery.event.special.swiperight =
jQuery.event.special.swipeup =
jQuery.event.special.swipedown = {
setup: function( data, namespaces, eventHandle ) {
var data = getData(this);
// If another swipe event is already setup, don't setup again.
if (data.count++ > 0) { return; }
add(this, 'moveend', moveend);
return true;
},
teardown: function() {
var data = getData(this);
// If another swipe event is still setup, don't teardown.
if (--data.count > 0) { return; }
remove(this, 'moveend', moveend);
return true;
},
settings: settings
};
});
================================================
FILE: package.json
================================================
{
"name": "jquery.event.swipe",
"title": "jquery.event.swipe",
"version": "0.5.4",
"author": {
"name": "Stephen Band",
"url": "http://stephband.info",
"twitter": "stephband"
},
"dependencies": {
"jquery": ">=1.7.0",
"jquery.event.move": "1.x"
},
"licenses": [{"url": "http://www.wtfpl.net/txt/copying/"}],
"files": ["js/jquery.event.swipe.js"],
"main": "js/jquery.event.swipe.js",
"description": "jQuery special events for the gestures swipeleft, swiperight, swipeup and swipedown.",
"keywords": ["touch","special","event","swipe","dom","jquery"],
"homepage": "http://github.com/stephband/jquery.event.swipe",
"docs": "http://stephband.info/jquery.event.swipe"
}
gitextract_o4lzu_em/ ├── README.md ├── bower.json ├── event.swipe.jquery.json ├── index.html ├── js/ │ └── jquery.event.swipe.js └── package.json
SYMBOL INDEX (2 symbols across 1 files)
FILE: js/jquery.event.swipe.js
function moveend (line 46) | function moveend(e) {
function getData (line 92) | function getData(node) {
Condensed preview — 6 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (21K chars).
[
{
"path": "README.md",
"chars": 1038,
"preview": "<h1>jquery.event.swipe</h1>\n\n<h2>Dependencies</h2>\n<p>jQuery.event.move: <a href=\"http://stephband.info/jquery.event.mov"
},
{
"path": "bower.json",
"chars": 665,
"preview": "{\n \"name\": \"jquery.event.swipe\",\n \"version\": \"0.5.3\",\n \"author\": {\n \"name\": \"Stephen Band\",\n \"url"
},
{
"path": "event.swipe.jquery.json",
"chars": 666,
"preview": "{\n \"name\": \"event.swipe\",\n \"title\": \"jquery.event.swipe\",\n \"version\": \"0.5.3\",\n \"author\": {\n \"name\": "
},
{
"path": "index.html",
"chars": 11895,
"preview": "---\ntitle: jQuery.event.swipe\n---\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n\t<meta charset=\"utf-8\" />\n\t<meta name=\"author\""
},
{
"path": "js/jquery.event.swipe.js",
"chars": 3437,
"preview": "// jQuery.event.swipe\n// 0.5\n// Stephen Band\n\n// Dependencies\n// jQuery.event.move 1.2\n\n// One of swipeleft, swiperight,"
},
{
"path": "package.json",
"chars": 759,
"preview": "{\n \"name\": \"jquery.event.swipe\",\n \"title\": \"jquery.event.swipe\",\n \"version\": \"0.5.4\",\n \"author\": {\n \""
}
]
About this extraction
This page contains the full source code of the stephband/jquery.event.swipe GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 6 files (18.0 KB), approximately 5.5k tokens, and a symbol index with 2 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.