| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140 |
- /*!
- * QuoJS 1.0.1 ~ Copyright (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
- * http://quojs.tapquo.com
- * Released under MIT license, https://raw.github.com/soyjavi/QuoJS/master/LICENSE.txt
- */
- var Quo = (function() {
- var EMPTY_ARRAY = [];
- function Q(dom, selector) {
- dom = dom || EMPTY_ARRAY;
- dom.__proto__ = Q.prototype;
- dom.selector = selector || '';
- return dom;
- };
- /**
- * ?
- */
- function $$(selector) {
- if (!selector) {
- return Q();
- } else {
- var domain_selector = $$.getDomainSelector(selector);
- return Q(domain_selector, selector);
- }
- };
- /**
- * ?
- */
- $$.extend = function(target) {
- Array.prototype.slice.call(arguments, 1).forEach(function(source) {
- for (key in source) target[key] = source[key];
- })
- return target;
- };
- Q.prototype = $$.fn = {};
- return $$;
- })();
- window.Quo = Quo;
- '$$' in window || (window.$$ = Quo);
- (function($$) {
- var OBJ_PROTO = Object.prototype;
- var EMPTY_ARRAY = [];
- /**
- * Determine the internal JavaScript [[Class]] of an object.
- *
- * @param {object} obj to get the real type of itself.
- * @return {string} with the internal JavaScript [[Class]] of itself.
- */
- $$.toType = function(obj) {
- return OBJ_PROTO.toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
- };
- /**
- * ?
- */
- $$.isOwnProperty = function(object, property) {
- return OBJ_PROTO.hasOwnProperty.call(object, property);
- };
- /**
- * ?
- */
- $$.getDomainSelector = function(selector) {
- var domain = null;
- var elementTypes = [1, 9, 11];
- var type = $$.toType(selector);
- if (type === 'array') {
- domain = _compact(selector);
- } else if (type === 'string') {
- domain = $$.query(document, selector);
- } else if (elementTypes.indexOf(selector.nodeType) >= 0 || selector === window) {
- domain = [selector];
- selector = null;
- }
- return domain;
- };
- /**
- * ?
- */
- $$.map = function(elements, callback) {
- //@TODO: Refactor!!!
- var values = [];
- var i;
- var key;
- if ($$.toType(elements) === 'array') {
- for (i = 0; i < elements.length; i++) {
- var value = callback(elements[i], i);
- if (value != null) values.push(value);
- }
- } else {
- for (key in elements) {
- value = callback(elements[key], key);
- if (value != null) values.push(value);
- }
- }
- return _flatten(values);
- };
- /**
- * ?
- */
- $$.each = function(elements, callback) {
- var i, key;
- if ($$.toType(elements) === 'array')
- for(i = 0; i < elements.length; i++) {
- if(callback.call(elements[i], i, elements[i]) === false) return elements;
- }
- else
- for(key in elements) {
- if(callback.call(elements[key], key, elements[key]) === false) return elements;
- }
- return elements;
- };
- /**
- * ?
- */
- $$.mix = function() {
- var child = {};
- for (var arg = 0, len = arguments.length; arg < len; arg++) {
- var argument = arguments[arg];
- for (var prop in argument) {
- if ($$.isOwnProperty(argument, prop) && argument[prop] !== undefined) {
- child[prop] = argument[prop];
- }
- }
- }
- return child;
- };
- /**
- * ?
- */
- $$.fn.forEach = EMPTY_ARRAY.forEach;
- /**
- * ?
- */
- $$.fn.indexOf = EMPTY_ARRAY.indexOf;
- /**
- * ?
- */
- $$.fn.map = function(fn){
- return $$.map(this, function(el, i){ return fn.call(el, i, el) });
- };
- /**
- * ?
- */
- /*
- $$.fn.slice = function(){
- return $$(slice.apply(this, arguments));
- };
- */
- /**
- * ?
- */
- $$.fn.instance = function(property) {
- return this.map(function() {
- return this[property];
- });
- };
- /**
- * ?
- */
- $$.fn.filter = function(selector) {
- return $$([].filter.call(this, function(element) {
- return element.parentNode && $$.query(element.parentNode, selector).indexOf(element) >= 0;
- }));
- };
- function _compact(array) {
- return array.filter(function(item) {
- return item !== undefined && item !== null
- });
- }
- function _flatten(array) {
- return array.length > 0 ? [].concat.apply([], array) : array
- }
- })(Quo);
- (function($$) {
- /**
- * ?
- */
- $$.fn.attr = function(name, value) {
- if ($$.toType(name) === 'string' && value === undefined) {
- return this[0].getAttribute(name);
- } else {
- return this.each(function() {
- this.setAttribute(name, value);
- });
- }
- };
- /**
- * ?
- */
- $$.fn.data = function(name, value) {
- return this.attr('data-' + name, value);
- };
- /**
- * ?
- */
- $$.fn.val = function(value) {
- if ($$.toType(value) === 'string') {
- return this.each(function() {
- this.value = value;
- });
- } else {
- return (this.length > 0 ? this[0].value : null)
- }
- };
- /**
- * ?
- */
- $$.fn.show = function() {
- return this.style("display", "block")
- };
- /**
- * ?
- */
- $$.fn.hide = function() {
- return this.style("display", "none")
- };
- /**
- * ?
- */
- $$.fn.height = function() {
- var offset = this.offset();
- return offset.height;
- };
- /**
- * ?
- */
- $$.fn.width = function() {
- var offset = this.offset();
- return offset.width;
- };
- /**
- * ?
- */
- $$.fn.offset = function() {
- var bounding = this[0].getBoundingClientRect();
- return {
- left: bounding.left + window.pageXOffset,
- top: bounding.top + window.pageYOffset,
- width: bounding.width,
- height: bounding.height
- };
- };
- /**
- * ?
- */
- $$.fn.remove = function() {
- return this.each(function() {
- if (this.parentNode != null) {
- this.parentNode.removeChild(this);
- }
- });
- };
- })(Quo);
- (function($$) {
- var IS_WEBKIT = /WebKit\/([\d.]+)/;
- var SUPPORTED_OS = {
- android: /(Android)\s+([\d.]+)/,
- ipad: /(iPad).*OS\s([\d_]+)/,
- iphone: /(iPhone\sOS)\s([\d_]+)/,
- blackberry: /(BlackBerry).*Version\/([\d.]+)/,
- webos: /(webOS|hpwOS)[\s\/]([\d.]+)/
- };
- var CURRENT_ENVIRONMENT = null;
- /**
- * ?
- */
- $$.isMobile = function() {
- CURRENT_ENVIRONMENT = CURRENT_ENVIRONMENT || _detectEnvironment();
- return CURRENT_ENVIRONMENT.isMobile;
- };
- /**
- * ?
- */
- $$.environment = function() {
- CURRENT_ENVIRONMENT = CURRENT_ENVIRONMENT || _detectEnvironment();
- return CURRENT_ENVIRONMENT;
- };
- /**
- * ?
- */
- $$.isOnline = function() {
- return (navigator.onLine);
- };
- var _detectEnvironment = function() {
- var user_agent = navigator.userAgent;
- var environment = {};
- environment.browser = _detectBrowser(user_agent);
- environment.os = _detectOS(user_agent);
- environment.isMobile = (environment.os) ? true : false;
- return environment;
- }
- var _detectBrowser = function(user_agent) {
- var is_webkit = user_agent.match(IS_WEBKIT);
- return (is_webkit) ? is_webkit[0]: user_agent;
- }
- var _detectOS = function(user_agent) {
- var detected_os;
- for (os in SUPPORTED_OS) {
- var supported = user_agent.match(SUPPORTED_OS[os]);
- if (supported) {
- detected_os = {
- name: (os === 'iphone' || os === 'ipad') ? 'ios' : os,
- version: supported[2].replace('_', '.')
- }
- break;
- }
- }
- return detected_os;
- }
- })(Quo);
- (function($$) {
- /**
- * ?
- */
- $$.fn.text = function(value) {
- return (!value) ?
- this[0].textContent
- :
- this.each(function() {
- this.textContent = value;
- });
- };
- /**
- * ?
- */
- $$.fn.html = function(value) {
- return ($$.toType('value') === 'string') ?
- this.each(function() {
- this.innerHTML = value;
- })
- :
- this[0].innerHTML;
- };
- /**
- * ?
- */
- $$.fn.append = function(value) {
- return this.each(function() {
- if ($$.toType(value) === 'string') {
- if (value) {
- var div = document.createElement();
- div.innerHTML = value;
- this.appendChild(div.firstChild);
- }
- } else {
- this.insertBefore(value);
- }
- });
- };
- /**
- * ?
- */
- $$.fn.prepend = function(value) {
- return this.each(function() {
- if ($$.toType(value) === 'string') {
- this.innerHTML = value + this.innerHTML;
- } else {
- var parent = this.parentNode;
- parent.insertBefore(value, parent.firstChild);
- }
- });
- };
- /**
- * ?
- */
- $$.fn.empty = function() {
- return this.each(function() {
- this.innerHTML = null;
- });
- };
- })(Quo);
- (function($$){
- var PARENT_NODE = 'parentNode';
- /**
- * ?
- */
- $$.query = function(domain, selector) {
- var dom_elements = document.querySelectorAll(selector);
- dom_elements = Array.prototype.slice.call(dom_elements);
- return dom_elements;
- };
- /**
- * ?
- */
- $$.fn.parent = function(selector) {
- var ancestors = (selector) ? _findAncestors(this) : this.instance(PARENT_NODE);
- return _filtered(ancestors, selector);
- };
- /**
- * ?
- */
- $$.fn.siblings = function(selector) {
- var siblings_elements = this.map(function(index, element) {
- return Array.prototype.slice.call(element.parentNode.children).filter(function(child) {
- return child !== element
- });
- });
- return _filtered(siblings_elements, selector);
- };
- /**
- * ?
- */
- $$.fn.children = function(selector) {
- var children_elements = this.map(function() {
- return Array.prototype.slice.call(this.children);
- });
- return _filtered(children_elements, selector);
- };
- /**
- * ?
- */
- $$.fn.get = function(index) {
- return index === undefined ? this : this[index]
- };
- /**
- * ?
- */
- $$.fn.first = function() {
- return $$(this[0]);
- };
- /**
- * ?
- */
- $$.fn.last = function() {
- var last_element_index = this.length - 1;
- return $$(this[last_element_index]);
- };
- /**
- * ?
- */
- $$.fn.closest = function(selector, context) {
- var node = this[0];
- var candidates = $$(selector);
- if (!candidates.length) node = null;
- while (node && candidates.indexOf(node) < 0) {
- node = node !== context && node !== document && node.parentNode;
- }
- return $$(node);
- };
- /**
- * ?
- */
- $$.fn.each = function(callback) {
- this.forEach( function(el, idx) {
- callback.call(el, idx, el)
- });
- return this;
- };
- var _findAncestors = function(nodes) {
- var ancestors = []
- while (nodes.length > 0) {
- nodes = $$.map(nodes, function(node) {
- if ((node = node.parentNode) && node !== document && ancestors.indexOf(node) < 0) {
- ancestors.push(node);
- return node;
- }
- });
- }
- return ancestors;
- }
- var _filtered = function(nodes, selector) {
- return (selector === undefined) ? $$(nodes) : $$(nodes).filter(selector);
- }
- })(Quo);
- (function($){
- /**
- * ?
- */
- $.fn.addClass = function(name) {
- return this.each(function() {
- if (!_existsClass(name, this.className)) {
- this.className += ' ' + name;
- }
- });
- };
- /**
- * ?
- */
- $.fn.removeClass = function(name) {
- return this.each(function() {
- if (_existsClass(name, this.className)) {
- this.className = this.className.replace(name, ' ');
- }
- });
- };
- /**
- * ?
- */
- $.fn.toggleClass = function(name) {
- return this.each(function() {
- if (_existsClass(name, this.className)) {
- this.className = this.className.replace(name, ' ');
- } else {
- this.className += ' ' + name;
- }
- });
- };
- /**
- * ?
- */
- $.fn.hasClass = function(name) {
- return _existsClass(name, this[0].className);
- }
- /**
- * ?
- */
- $.fn.style = function(property, value) {
- return (!value) ?
- this[0].style[property] || _computedStyle(this[0], property)
- :
- this.each(function() {
- this.style[property] = value;
- });
- };
- function _existsClass(name, className) {
- var classes = className.split(/\s+/g);
- return (classes.indexOf(name) >= 0);
- }
- function _computedStyle(element, property) {
- return document.defaultView.getComputedStyle(element, '')[property];
- }
- })(Quo);
- (function($$) {
- var DEFAULT = { TYPE: 'GET', MIME: 'json' };
- var MIME_TYPES = {
- script: 'text/javascript, application/javascript',
- json: 'application/json',
- xml: 'application/xml, text/xml',
- html: 'text/html',
- text: 'text/plain'
- };
- var JSONP_ID = 0;
- /**
- * ?
- */
- $$.ajaxSettings = {
- type: DEFAULT.TYPE,
- async: true,
- success: {},
- error: {},
- context: null,
- dataType: DEFAULT.MIME,
- headers: {},
- xhr: function () {
- return new window.XMLHttpRequest();
- },
- crossDomain: false,
- timeout: 0
- };
- /**
- * ?
- */
- $$.ajax = function(options) {
- var settings = $$.mix($$.ajaxSettings, options);
- if (_isJsonP(settings.url)) return $$.jsonp(settings);
- var xhr = settings.xhr();
- xhr.onreadystatechange = function() {
- if (xhr.readyState === 4) {
- clearTimeout(abortTimeout);
- _xhrStatus(xhr, settings);
- }
- }
- xhr.open(settings.type, settings.url, settings.async);
- _xhrHeaders(xhr, settings);
- if (settings.timeout > 0) {
- var abortTimeout = setTimeout(function() {
- _xhrTimeout(xhr, settings);
- }, settings.timeout);
- }
- xhr.send(settings.data);
- return (settings.async) ? xhr : _parseResponse(xhr, settings);
- };
- /**
- * ?
- */
- $$.jsonp = function(settings) {
- var callbackName = 'jsonp' + (++JSONP_ID);
- var script = document.createElement('script');
- var xhr = {
- abort: function() {
- $$(script).remove();
- if (callbackName in window) window[callbackName] = {};
- }
- };
- var abortTimeout;
- window[callbackName] = function(response) {
- clearTimeout(abortTimeout);
- $$(script).remove();
- delete window[callbackName];
- _xhrSuccess(response, xhr, settings);
- };
- script.src = settings.url.replace(/=\?/, '=' + callbackName);
- $$('head').append(script);
- if (settings.timeout > 0) {
- abortTimeout = setTimeout(function() {
- _xhrTimeout(xhr, settings);
- }, settings.timeout);
- }
- return xhr;
- };
- /**
- * ?
- */
- $$.get = function(url, data, success, dataType) {
- url += _serializeParameters(data);
- return $$.ajax({
- url: url,
- success: success,
- dataType: dataType
- });
- };
- /**
- * ?
- */
- $$.post = function(url, data, success, dataType) {
- return $$.ajax({
- type: 'POST',
- url: url,
- data: data,
- success: success,
- dataType: dataType,
- contentType: 'application/x-www-form-urlencoded'
- });
- };
- /**
- * ?
- */
- $$.json = function(url, data, success) {
- url += _serializeParameters(data);
- return $$.ajax({
- url: url,
- success: success,
- dataType: DEFAULT.MIME
- });
- };
- function _xhrStatus(xhr, settings) {
- if (xhr.status === 200 || xhr.status === 0) {
- if (settings.async) {
- var response = _parseResponse(xhr, settings);
- _xhrSuccess(response, xhr, settings);
- }
- } else {
- _xhrError('QuoJS » $$.ajax', xhr, settings);
- }
- }
- function _xhrSuccess(response, xhr, settings) {
- settings.success.call(settings.context, response, xhr);
- }
- function _xhrError(type, xhr, settings) {
- settings.error.call(settings.context, type, xhr, settings);
- }
- function _xhrHeaders(xhr, settings) {
- if (settings.contentType) settings.headers['Content-Type'] = settings.contentType;
- if (settings.dataType) settings.headers['Accept'] = MIME_TYPES[settings.dataType];
- for (header in settings.headers) {
- xhr.setRequestHeader(header, settings.headers[header]);
- }
- }
- function _xhrTimeout(xhr, settings) {
- xhr.onreadystatechange = {};
- xhr.abort();
- _xhrError('QuoJS » $$.ajax : timeout exceeded', xhr, settings);
- }
- function _parseResponse(xhr, settings) {
- var response = xhr.responseText;
- if (response) {
- if (settings.dataType === DEFAULT.MIME) {
- try {
- response = JSON.parse(response);
- }
- catch (error) {
- response = error;
- _xhrError('Parse Error', xhr, settings);
- }
- } else if (settings.dataType === 'xml') {
- response = xhr.responseXML;
- }
- }
- return response;
- }
- var _serializeParameters = function(parameters) {
- var serialize = '?';
- for (var parameter in parameters) {
- if (parameters.hasOwnProperty(parameter)) {
- if (serialize !== '?') serialize += '&';
- serialize += parameter + '=' + parameters[parameter];
- }
- }
- return (serialize === '?') ? '' : serialize;
- }
- var _isJsonP = function(url) {
- return (/=\?/.test(url));
- }
- })(Quo);
- (function($$) {
- var SHORTCUTS = [
- 'touch',
- 'tap' ];
- var SHORTCUTS_EVENTS = {
- touch: 'touchstart',
- tap: 'tap' };
- var READY_EXPRESSION = /complete|loaded|interactive/;
- /**
- * ?
- */
- SHORTCUTS.forEach(function(event) {
- $$.fn[event] = function(callback) {
- $$(document.body).delegate(this.selector, SHORTCUTS_EVENTS[event], callback);
- return this;
- };
- });
- /**
- * ?
- */
- $$.fn.on = function(event, selector, callback) {
- return (selector === undefined || $$.toType(selector) === 'function') ?
- this.bind(event, selector)
- :
- this.delegate(selector, event, callback);
- };
- /**
- * ?
- */
- $$.fn.off = function(event, selector, callback){
- return (selector === undefined || $$.toType(selector) === 'function') ?
- this.unbind(event, selector)
- :
- this.undelegate(selector, event, callback);
- };
- /**
- * ?
- */
- $$.fn.ready = function(callback) {
- if (READY_EXPRESSION.test(document.readyState)) {
- callback($$);
- }
- else {
- document.addEventListener('DOMContentLoaded', function(){ callback($$) }, false);
- }
- return this;
- };
- })(Quo);
- (function($$) {
- var ELEMENT_ID = 1;
- var HANDLERS = {};
- var EVENT_METHODS = {
- preventDefault: 'isDefaultPrevented',
- stopImmediatePropagation: 'isImmediatePropagationStopped',
- stopPropagation: 'isPropagationStopped' };
- var EVENTS_DESKTOP = {
- touchstart : 'mousedown',
- touchmove: 'mousemove',
- touchend: 'mouseup',
- tap: 'click',
- doubletap: 'dblclick',
- orientationchange: 'resize' };
- /**
- * ?
- */
- $$.Event = function(type, props) {
- var event = document.createEvent('Events');
- event.initEvent(type, true, true, null, null, null, null, null, null, null, null, null, null, null, null);
- return event;
- };
- /**
- * ?
- */
- $$.fn.bind = function(event, callback) {
- return this.each(function() {
- _subscribe(this, event, callback);
- });
- };
- /**
- * ?
- */
- $$.fn.unbind = function(event, callback){
- return this.each(function() {
- _unsubscribe(this, event, callback);
- });
- };
- /**
- * ?
- */
- $$.fn.delegate = function(selector, event, callback) {
- return this.each(function(i, element) {
- _subscribe(element, event, callback, selector, function(fn) {
- return function(e) {
- var match = $$(e.target).closest(selector, element).get(0);
- if (match) {
- var evt = $$.extend(_createProxy(e), {
- currentTarget: match,
- liveFired: element
- });
- return fn.apply(match, [evt].concat([].slice.call(arguments, 1)));
- }
- }
- });
- });
- };
- /**
- * ?
- */
- $$.fn.undelegate = function(selector, event, callback){
- return this.each(function(){
- _unsubscribe(this, event, callback, selector);
- });
- };
- /**
- * ?
- */
- $$.fn.trigger = function(event) {
- if ($$.toType(event) === 'string') event = $$.Event(event);
- return this.each(function() {
- this.dispatchEvent(event);
- });
- };
- function _subscribe(element, event, callback, selector, delegate_callback) {
- event = _environmentEvent(event);
- var element_id = _getElementId(element);
- var element_handlers = HANDLERS[element_id] || (HANDLERS[element_id] = []);
- var delegate = delegate_callback && delegate_callback(callback, event);
- var handler = {
- event: event,
- callback: callback,
- selector: selector,
- proxy: _createProxyCallback(delegate, callback, element),
- delegate: delegate,
- index: element_handlers.length
- };
- element_handlers.push(handler);
- element.addEventListener(handler.event, handler.proxy, false);
- }
- function _unsubscribe(element, event, callback, selector) {
- event = _environmentEvent(event);
- var element_id = _getElementId(element);
- _findHandlers(element_id, event, callback, selector).forEach(function(handler) {
- delete HANDLERS[element_id][handler.index];
- element.removeEventListener(handler.event, handler.proxy, false);
- });
- }
- function _getElementId(element) {
- return element._id || (element._id = ELEMENT_ID++);
- }
- function _environmentEvent(event) {
- var environment_event = ($$.isMobile()) ? event : EVENTS_DESKTOP[event];
- return (environment_event) || event;
- }
- function _createProxyCallback(delegate, callback, element) {
- var callback = delegate || callback;
- var proxy = function (event) {
- var result = callback.apply(element, [event].concat(event.data));
- if (result === false) {
- event.preventDefault();
- }
- return result;
- };
- return proxy;
- }
- function _findHandlers(element_id, event, fn, selector) {
- return (HANDLERS[element_id] || []).filter(function(handler) {
- return handler
- && (!event || handler.event == event)
- && (!fn || handler.fn == fn)
- && (!selector || handler.selector == selector);
- });
- }
- function _createProxy(event) {
- var proxy = $$.extend({originalEvent: event}, event);
- $$.each(EVENT_METHODS, function(name, method) {
- proxy[name] = function() {
- this[method] = function(){ return true };
- return event[name].apply(event, arguments);
- };
- proxy[method] = function() { return false };
- })
- return proxy;
- }
- })(Quo);
- (function($$) {
- var TOUCH = {};
- var TOUCH_TIMEOUT;
- var LONGTAP_DELAY = 750;
- var GESTURES = ['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'longTap'];
- /**
- * ?
- */
- GESTURES.forEach(function(event) {
- $$.fn[event] = function(callback) {
- return this.on(event, callback);
- };
- });
- /**
- * ?
- */
- $$(document).ready(function() {
- _listenTouches();
- });
- function _listenTouches() {
- var environment = $$(document.body);
- environment.bind('touchstart', _onTouchStart);
- environment.bind('touchmove', _onTouchMove);
- environment.bind('touchend', _onTouchEnd);
- environment.bind('touchcancel', _onTouchCancel);
- }
- function _onTouchStart(event) {
- var now = Date.now();
- var delta = now - (TOUCH.last || now);
- var first_touch = ($$.isMobile()) ? event.touches[0] : event;
- TOUCH_TIMEOUT && clearTimeout(TOUCH_TIMEOUT);
- TOUCH = {
- el: $$(_parentIfText(first_touch.target)),
- x1: first_touch.pageX,
- y1: first_touch.pageY,
- isDoubleTap: (delta > 0 && delta <= 250) ? true : false,
- last: now
- }
- setTimeout(_longTap, LONGTAP_DELAY);
- }
- function _onTouchMove(event) {
- var move_touch = ($$.isMobile()) ? event.touches[0] : event;
- TOUCH.x2 = move_touch.pageX;
- TOUCH.y2 = move_touch.pageY;
- }
- function _onTouchEnd(event) {
- if (TOUCH.isDoubleTap) {
- TOUCH.el.trigger('doubleTap');
- TOUCH = {};
- } else if (TOUCH.x2 > 0 || TOUCH.y2 > 0) {
- (Math.abs(TOUCH.x1 - TOUCH.x2) > 30 || Math.abs(TOUCH.y1 - TOUCH.y2) > 30) &&
- TOUCH.el.trigger('swipe') &&
- TOUCH.el.trigger('swipe' + (_swipeDirection(TOUCH.x1, TOUCH.x2, TOUCH.y1, TOUCH.y2)));
- TOUCH.x1 = TOUCH.x2 = TOUCH.y1 = TOUCH.y2 = TOUCH.last = 0;
- TOUCH = {};
- } else {
- TOUCH.el.trigger('tap');
- TOUCH_TIMEOUT = setTimeout(function(){
- TOUCH_TIMEOUT = null;
- TOUCH = {};
- }, 250);
- }
- }
- function _onTouchCancel(event) {
- TOUCH = {};
- clearTimeout(TOUCH_TIMEOUT);
- }
- function _parentIfText(node) {
- return 'tagName' in node ? node : node.parentNode;
- }
- function _swipeDirection(x1, x2, y1, y2) {
- var xDelta = Math.abs(x1 - x2);
- var yDelta = Math.abs(y1 - y2);
- if (xDelta >= yDelta) {
- return (x1 - x2 > 0 ? 'Left' : 'Right');
- } else {
- return (y1 - y2 > 0 ? 'Up' : 'Down');
- }
- }
- function _longTap() {
- if (TOUCH.last && (Date.now() - TOUCH.last >= LONGTAP_DELAY)) {
- TOUCH.el.trigger('longTap');
- TOUCH = {};
- }
- }
- })(Quo);
|