/usr/share/javascript/yui3/event-flick/event-flick.js is in libjs-yui3-full 3.5.1-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | /*
YUI 3.5.1 (build 22)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add('event-flick', function(Y) {
/**
* The gestures module provides gesture events such as "flick", which normalize user interactions
* across touch and mouse or pointer based input devices. This layer can be used by application developers
* to build input device agnostic components which behave the same in response to either touch or mouse based
* interaction.
*
* <p>Documentation for events added by this module can be found in the event document for the <a href="YUI.html#events">YUI</a> global.</p>
*
* @module event-gestures
*/
/**
* Adds support for a "flick" event, which is fired at the end of a touch or mouse based flick gesture, and provides
* velocity of the flick, along with distance and time information.
*
* @module event-gestures
* @submodule event-flick
*/
var EVENT = ((Y.config.win && ("ontouchstart" in Y.config.win)) && !(Y.UA.chrome && Y.UA.chrome < 6)) ? {
start: "touchstart",
end: "touchend",
move: "touchmove"
} : {
start: "mousedown",
end: "mouseup",
move: "mousemove"
},
START = "start",
END = "end",
MOVE = "move",
OWNER_DOCUMENT = "ownerDocument",
MIN_VELOCITY = "minVelocity",
MIN_DISTANCE = "minDistance",
PREVENT_DEFAULT = "preventDefault",
_FLICK_START = "_fs",
_FLICK_START_HANDLE = "_fsh",
_FLICK_END_HANDLE = "_feh",
_FLICK_MOVE_HANDLE = "_fmh",
NODE_TYPE = "nodeType";
/**
* Sets up a "flick" event, that is fired whenever the user initiates a flick gesture on the node
* where the listener is attached. The subscriber can specify a minimum distance or velocity for
* which the event is to be fired. The subscriber can also specify if there is a particular axis which
* they are interested in - "x" or "y". If no axis is specified, the axis along which there was most distance
* covered is used.
*
* <p>It is recommended that you use Y.bind to set up context and additional arguments for your event handler,
* however if you want to pass the context and arguments as additional signature arguments to "on",
* you need to provide a null value for the configuration object, e.g: <code>node.on("flick", fn, null, context, arg1, arg2, arg3)</code></p>
*
* @event flick
* @for YUI
* @param type {string} "flick"
* @param fn {function} The method the event invokes. It receives an event facade with an e.flick object containing the flick related properties: e.flick.time, e.flick.distance, e.flick.velocity and e.flick.axis, e.flick.start.
* @param cfg {Object} Optional. An object which specifies any of the following:
* <dl>
* <dt>minDistance (in pixels, defaults to 10)</dt>
* <dd>The minimum distance between start and end points, which would qualify the gesture as a flick.</dd>
* <dt>minVelocity (in pixels/ms, defaults to 0)</dt>
* <dd>The minimum velocity which would qualify the gesture as a flick.</dd>
* <dt>preventDefault (defaults to false)</dt>
* <dd>Can be set to true/false to prevent default behavior as soon as the touchstart/touchend or mousedown/mouseup is received so that things like scrolling or text selection can be
* prevented. This property can also be set to a function, which returns true or false, based on the event facade passed to it.</dd>
* <dt>axis (no default)</dt>
* <dd>Can be set to "x" or "y" if you want to constrain the flick velocity and distance to a single axis. If not
* defined, the axis along which the maximum distance was covered is used.</dd>
* </dl>
* @return {EventHandle} the detach handle
*/
Y.Event.define('flick', {
on: function (node, subscriber, ce) {
var startHandle = node.on(EVENT[START],
this._onStart,
this,
node,
subscriber,
ce);
subscriber[_FLICK_START_HANDLE] = startHandle;
},
detach: function (node, subscriber, ce) {
var startHandle = subscriber[_FLICK_START_HANDLE],
endHandle = subscriber[_FLICK_END_HANDLE];
if (startHandle) {
startHandle.detach();
subscriber[_FLICK_START_HANDLE] = null;
}
if (endHandle) {
endHandle.detach();
subscriber[_FLICK_END_HANDLE] = null;
}
},
processArgs: function(args) {
var params = (args.length > 3) ? Y.merge(args.splice(3, 1)[0]) : {};
if (!(MIN_VELOCITY in params)) {
params[MIN_VELOCITY] = this.MIN_VELOCITY;
}
if (!(MIN_DISTANCE in params)) {
params[MIN_DISTANCE] = this.MIN_DISTANCE;
}
if (!(PREVENT_DEFAULT in params)) {
params[PREVENT_DEFAULT] = this.PREVENT_DEFAULT;
}
return params;
},
_onStart: function(e, node, subscriber, ce) {
var start = true, // always true for mouse
endHandle,
moveHandle,
doc,
preventDefault = subscriber._extra.preventDefault,
origE = e;
if (e.touches) {
start = (e.touches.length === 1);
e = e.touches[0];
}
if (start) {
if (preventDefault) {
// preventDefault is a boolean or function
if (!preventDefault.call || preventDefault(e)) {
origE.preventDefault();
}
}
e.flick = {
time : new Date().getTime()
};
subscriber[_FLICK_START] = e;
endHandle = subscriber[_FLICK_END_HANDLE];
doc = (node.get(NODE_TYPE) === 9) ? node : node.get(OWNER_DOCUMENT);
if (!endHandle) {
endHandle = doc.on(EVENT[END], Y.bind(this._onEnd, this), null, node, subscriber, ce);
subscriber[_FLICK_END_HANDLE] = endHandle;
}
subscriber[_FLICK_MOVE_HANDLE] = doc.once(EVENT[MOVE], Y.bind(this._onMove, this), null, node, subscriber, ce);
}
},
_onMove: function(e, node, subscriber, ce) {
var start = subscriber[_FLICK_START];
// Start timing from first move.
if (start && start.flick) {
start.flick.time = new Date().getTime();
}
},
_onEnd: function(e, node, subscriber, ce) {
var endTime = new Date().getTime(),
start = subscriber[_FLICK_START],
valid = !!start,
endEvent = e,
startTime,
time,
preventDefault,
params,
xyDistance,
distance,
velocity,
axis,
moveHandle = subscriber[_FLICK_MOVE_HANDLE];
if (moveHandle) {
moveHandle.detach();
delete subscriber[_FLICK_MOVE_HANDLE];
}
if (valid) {
if (e.changedTouches) {
if (e.changedTouches.length === 1 && e.touches.length === 0) {
endEvent = e.changedTouches[0];
} else {
valid = false;
}
}
if (valid) {
params = subscriber._extra;
preventDefault = params[PREVENT_DEFAULT];
if (preventDefault) {
// preventDefault is a boolean or function
if (!preventDefault.call || preventDefault(e)) {
e.preventDefault();
}
}
startTime = start.flick.time;
endTime = new Date().getTime();
time = endTime - startTime;
xyDistance = [
endEvent.pageX - start.pageX,
endEvent.pageY - start.pageY
];
if (params.axis) {
axis = params.axis;
} else {
axis = (Math.abs(xyDistance[0]) >= Math.abs(xyDistance[1])) ? 'x' : 'y';
}
distance = xyDistance[(axis === 'x') ? 0 : 1];
velocity = (time !== 0) ? distance/time : 0;
if (isFinite(velocity) && (Math.abs(distance) >= params[MIN_DISTANCE]) && (Math.abs(velocity) >= params[MIN_VELOCITY])) {
e.type = "flick";
e.flick = {
time:time,
distance: distance,
velocity:velocity,
axis: axis,
start : start
};
ce.fire(e);
}
subscriber[_FLICK_START] = null;
}
}
},
MIN_VELOCITY : 0,
MIN_DISTANCE : 0,
PREVENT_DEFAULT : false
});
}, '3.5.1' ,{requires:['node-base','event-touch','event-synthetic']});
|