PageRenderTime 68ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/example/public/application.js

http://github.com/gobhi/gbone.js
JavaScript | 4892 lines | 4106 code | 272 blank | 514 comment | 572 complexity | d759c46b510d0bc07d5e36681b40bba3 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. // Zepto.js
  2. // (c) 2010, 2011 Thomas Fuchs
  3. // Zepto.js may be freely distributed under the MIT license.
  4. (function(undefined){
  5. if (String.prototype.trim === undefined) // fix for iOS 3.2
  6. String.prototype.trim = function(){ return this.replace(/^\s+/, '').replace(/\s+$/, '') };
  7. // For iOS 3.x
  8. // from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduce
  9. if (Array.prototype.reduce === undefined)
  10. Array.prototype.reduce = function(fun){
  11. if(this === void 0 || this === null) throw new TypeError();
  12. var t = Object(this), len = t.length >>> 0, k = 0, accumulator;
  13. if(typeof fun != 'function') throw new TypeError();
  14. if(len == 0 && arguments.length == 1) throw new TypeError();
  15. if(arguments.length >= 2)
  16. accumulator = arguments[1];
  17. else
  18. do{
  19. if(k in t){
  20. accumulator = t[k++];
  21. break;
  22. }
  23. if(++k >= len) throw new TypeError();
  24. } while (true);
  25. while (k < len){
  26. if(k in t) accumulator = fun.call(undefined, accumulator, t[k], k, t);
  27. k++;
  28. }
  29. return accumulator;
  30. };
  31. })();
  32. // Zepto.js
  33. // (c) 2010, 2011 Thomas Fuchs
  34. // Zepto.js may be freely distributed under the MIT license.
  35. var Zepto = (function() {
  36. var undefined, key, $$, classList, emptyArray = [], slice = emptyArray.slice,
  37. document = window.document,
  38. elementDisplay = {}, classCache = {},
  39. getComputedStyle = document.defaultView.getComputedStyle,
  40. cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 },
  41. fragmentRE = /^\s*<(\w+)[^>]*>/,
  42. elementTypes = [1, 9, 11],
  43. adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ],
  44. table = document.createElement('table'),
  45. tableRow = document.createElement('tr'),
  46. containers = {
  47. 'tr': document.createElement('tbody'),
  48. 'tbody': table, 'thead': table, 'tfoot': table,
  49. 'td': tableRow, 'th': tableRow,
  50. '*': document.createElement('div')
  51. },
  52. readyRE = /complete|loaded|interactive/,
  53. classSelectorRE = /^\.([\w-]+)$/,
  54. idSelectorRE = /^#([\w-]+)$/,
  55. tagSelectorRE = /^[\w-]+$/;
  56. function isF(value) { return ({}).toString.call(value) == "[object Function]" }
  57. function isO(value) { return value instanceof Object }
  58. function isA(value) { return value instanceof Array }
  59. function likeArray(obj) { return typeof obj.length == 'number' }
  60. function compact(array) { return array.filter(function(item){ return item !== undefined && item !== null }) }
  61. function flatten(array) { return array.length > 0 ? [].concat.apply([], array) : array }
  62. function camelize(str) { return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) }
  63. function dasherize(str){
  64. return str.replace(/::/g, '/')
  65. .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
  66. .replace(/([a-z\d])([A-Z])/g, '$1_$2')
  67. .replace(/_/g, '-')
  68. .toLowerCase();
  69. }
  70. function uniq(array) { return array.filter(function(item,index,array){ return array.indexOf(item) == index }) }
  71. function classRE(name){
  72. return name in classCache ?
  73. classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)'));
  74. }
  75. function maybeAddPx(name, value) { return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value; }
  76. function defaultDisplay(nodeName) {
  77. var element, display;
  78. if (!elementDisplay[nodeName]) {
  79. element = document.createElement(nodeName);
  80. document.body.appendChild(element);
  81. display = getComputedStyle(element, '').getPropertyValue("display");
  82. element.parentNode.removeChild(element);
  83. display == "none" && (display = "block");
  84. elementDisplay[nodeName] = display;
  85. }
  86. return elementDisplay[nodeName];
  87. }
  88. function fragment(html, name) {
  89. if (name === undefined) fragmentRE.test(html) && RegExp.$1;
  90. if (!(name in containers)) name = '*';
  91. var container = containers[name];
  92. container.innerHTML = '' + html;
  93. return slice.call(container.childNodes);
  94. }
  95. function Z(dom, selector){
  96. dom = dom || emptyArray;
  97. dom.__proto__ = Z.prototype;
  98. dom.selector = selector || '';
  99. return dom;
  100. }
  101. function $(selector, context){
  102. if (!selector) return Z();
  103. if (context !== undefined) return $(context).find(selector);
  104. else if (isF(selector)) return $(document).ready(selector);
  105. else if (selector instanceof Z) return selector;
  106. else {
  107. var dom;
  108. if (isA(selector)) dom = compact(selector);
  109. else if (elementTypes.indexOf(selector.nodeType) >= 0 || selector === window)
  110. dom = [selector], selector = null;
  111. else if (fragmentRE.test(selector))
  112. dom = fragment(selector.trim(), RegExp.$1), selector = null;
  113. else if (selector.nodeType && selector.nodeType == 3) dom = [selector];
  114. else dom = $$(document, selector);
  115. return Z(dom, selector);
  116. }
  117. }
  118. $.extend = function(target){
  119. slice.call(arguments, 1).forEach(function(source) {
  120. for (key in source) target[key] = source[key];
  121. })
  122. return target;
  123. }
  124. $.qsa = $$ = function(element, selector){
  125. var found;
  126. return (element === document && idSelectorRE.test(selector)) ?
  127. ( (found = element.getElementById(RegExp.$1)) ? [found] : emptyArray ) :
  128. slice.call(
  129. classSelectorRE.test(selector) ? element.getElementsByClassName(RegExp.$1) :
  130. tagSelectorRE.test(selector) ? element.getElementsByTagName(selector) :
  131. element.querySelectorAll(selector)
  132. );
  133. }
  134. function filtered(nodes, selector){
  135. return selector === undefined ? $(nodes) : $(nodes).filter(selector);
  136. }
  137. function funcArg(context, arg, idx, payload){
  138. return isF(arg) ? arg.call(context, idx, payload) : arg;
  139. }
  140. $.isFunction = isF;
  141. $.isObject = isO;
  142. $.isArray = isA;
  143. $.map = function(elements, callback) {
  144. var value, values = [], i, key;
  145. if (likeArray(elements))
  146. for (i = 0; i < elements.length; i++) {
  147. value = callback(elements[i], i);
  148. if (value != null) values.push(value);
  149. }
  150. else
  151. for (key in elements) {
  152. value = callback(elements[key], key);
  153. if (value != null) values.push(value);
  154. }
  155. return flatten(values);
  156. }
  157. $.each = function(elements, callback) {
  158. var i, key;
  159. if (likeArray(elements))
  160. for(i = 0; i < elements.length; i++) {
  161. if(callback(i, elements[i]) === false) return elements;
  162. }
  163. else
  164. for(key in elements) {
  165. if(callback(key, elements[key]) === false) return elements;
  166. }
  167. return elements;
  168. }
  169. $.fn = {
  170. forEach: emptyArray.forEach,
  171. reduce: emptyArray.reduce,
  172. push: emptyArray.push,
  173. indexOf: emptyArray.indexOf,
  174. concat: emptyArray.concat,
  175. map: function(fn){
  176. return $.map(this, function(el, i){ return fn.call(el, i, el) });
  177. },
  178. slice: function(){
  179. return $(slice.apply(this, arguments));
  180. },
  181. ready: function(callback){
  182. if (readyRE.test(document.readyState)) callback($);
  183. else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false);
  184. return this;
  185. },
  186. get: function(idx){ return idx === undefined ? this : this[idx] },
  187. size: function(){ return this.length },
  188. remove: function () {
  189. return this.each(function () {
  190. if (this.parentNode != null) {
  191. this.parentNode.removeChild(this);
  192. }
  193. });
  194. },
  195. each: function(callback){
  196. this.forEach(function(el, idx){ callback.call(el, idx, el) });
  197. return this;
  198. },
  199. filter: function(selector){
  200. return $([].filter.call(this, function(element){
  201. return element.parentNode && $$(element.parentNode, selector).indexOf(element) >= 0;
  202. }));
  203. },
  204. end: function(){
  205. return this.prevObject || $();
  206. },
  207. andSelf:function(){
  208. return this.add(this.prevObject || $())
  209. },
  210. add:function(selector,context){
  211. return $(uniq(this.concat($(selector,context))));
  212. },
  213. is: function(selector){
  214. return this.length > 0 && $(this[0]).filter(selector).length > 0;
  215. },
  216. not: function(selector){
  217. var nodes=[];
  218. if (isF(selector) && selector.call !== undefined)
  219. this.each(function(idx){
  220. if (!selector.call(this,idx)) nodes.push(this);
  221. });
  222. else {
  223. var excludes = typeof selector == 'string' ? this.filter(selector) :
  224. (likeArray(selector) && isF(selector.item)) ? slice.call(selector) : $(selector);
  225. this.forEach(function(el){
  226. if (excludes.indexOf(el) < 0) nodes.push(el);
  227. });
  228. }
  229. return $(nodes);
  230. },
  231. eq: function(idx){
  232. return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1);
  233. },
  234. first: function(){ var el = this[0]; return el && !isO(el) ? el : $(el) },
  235. last: function(){ var el = this[this.length - 1]; return el && !isO(el) ? el : $(el) },
  236. find: function(selector){
  237. var result;
  238. if (this.length == 1) result = $$(this[0], selector);
  239. else result = this.map(function(){ return $$(this, selector) });
  240. return $(result);
  241. },
  242. closest: function(selector, context){
  243. var node = this[0], candidates = $$(context || document, selector);
  244. if (!candidates.length) node = null;
  245. while (node && candidates.indexOf(node) < 0)
  246. node = node !== context && node !== document && node.parentNode;
  247. return $(node);
  248. },
  249. parents: function(selector){
  250. var ancestors = [], nodes = this;
  251. while (nodes.length > 0)
  252. nodes = $.map(nodes, function(node){
  253. if ((node = node.parentNode) && node !== document && ancestors.indexOf(node) < 0) {
  254. ancestors.push(node);
  255. return node;
  256. }
  257. });
  258. return filtered(ancestors, selector);
  259. },
  260. parent: function(selector){
  261. return filtered(uniq(this.pluck('parentNode')), selector);
  262. },
  263. children: function(selector){
  264. return filtered(this.map(function(){ return slice.call(this.children) }), selector);
  265. },
  266. siblings: function(selector){
  267. return filtered(this.map(function(i, el){
  268. return slice.call(el.parentNode.children).filter(function(child){ return child!==el });
  269. }), selector);
  270. },
  271. empty: function(){ return this.each(function(){ this.innerHTML = '' }) },
  272. pluck: function(property){ return this.map(function(){ return this[property] }) },
  273. show: function(){
  274. return this.each(function() {
  275. this.style.display == "none" && (this.style.display = null);
  276. if (getComputedStyle(this, '').getPropertyValue("display") == "none") {
  277. this.style.display = defaultDisplay(this.nodeName)
  278. }
  279. })
  280. },
  281. replaceWith: function(newContent) {
  282. return this.each(function() {
  283. $(this).before(newContent).remove();
  284. });
  285. },
  286. wrap: function(newContent) {
  287. return this.each(function() {
  288. $(this).wrapAll($(newContent)[0].cloneNode(false));
  289. });
  290. },
  291. wrapAll: function(newContent) {
  292. if (this[0]) {
  293. $(this[0]).before(newContent = $(newContent));
  294. newContent.append(this);
  295. }
  296. return this;
  297. },
  298. unwrap: function(){
  299. this.parent().each(function(){
  300. $(this).replaceWith($(this).children());
  301. });
  302. return this;
  303. },
  304. hide: function(){
  305. return this.css("display", "none")
  306. },
  307. toggle: function(setting){
  308. return (setting === undefined ? this.css("display") == "none" : setting) ? this.show() : this.hide();
  309. },
  310. prev: function(){ return $(this.pluck('previousElementSibling')) },
  311. next: function(){ return $(this.pluck('nextElementSibling')) },
  312. html: function(html){
  313. return html === undefined ?
  314. (this.length > 0 ? this[0].innerHTML : null) :
  315. this.each(function (idx) {
  316. var originHtml = this.innerHTML;
  317. $(this).empty().append( funcArg(this, html, idx, originHtml) );
  318. });
  319. },
  320. text: function(text){
  321. return text === undefined ?
  322. (this.length > 0 ? this[0].textContent : null) :
  323. this.each(function(){ this.textContent = text });
  324. },
  325. attr: function(name, value){
  326. var res;
  327. return (typeof name == 'string' && value === undefined) ?
  328. (this.length == 0 ? undefined :
  329. (name == 'value' && this[0].nodeName == 'INPUT') ? this.val() :
  330. (!(res = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : res
  331. ) :
  332. this.each(function(idx){
  333. if (isO(name)) for (key in name) this.setAttribute(key, name[key])
  334. else this.setAttribute(name, funcArg(this, value, idx, this.getAttribute(name)));
  335. });
  336. },
  337. removeAttr: function(name) {
  338. return this.each(function() { this.removeAttribute(name); });
  339. },
  340. data: function(name, value){
  341. return this.attr('data-' + name, value);
  342. },
  343. val: function(value){
  344. return (value === undefined) ?
  345. (this.length > 0 ? this[0].value : null) :
  346. this.each(function(idx){
  347. this.value = funcArg(this, value, idx, this.value);
  348. });
  349. },
  350. offset: function(){
  351. if(this.length==0) return null;
  352. var obj = this[0].getBoundingClientRect();
  353. return {
  354. left: obj.left + window.pageXOffset,
  355. top: obj.top + window.pageYOffset,
  356. width: obj.width,
  357. height: obj.height
  358. };
  359. },
  360. css: function(property, value){
  361. if (value === undefined && typeof property == 'string') {
  362. return(
  363. this.length == 0
  364. ? undefined
  365. : this[0].style[camelize(property)] || getComputedStyle(this[0], '').getPropertyValue(property)
  366. );
  367. }
  368. var css = '';
  369. for (key in property) css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';';
  370. if (typeof property == 'string') css = dasherize(property) + ":" + maybeAddPx(property, value);
  371. return this.each(function() { this.style.cssText += ';' + css });
  372. },
  373. index: function(element){
  374. return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0]);
  375. },
  376. hasClass: function(name){
  377. if (this.length < 1) return false;
  378. else return classRE(name).test(this[0].className);
  379. },
  380. addClass: function(name){
  381. return this.each(function(idx) {
  382. classList = [];
  383. var cls = this.className, newName = funcArg(this, name, idx, cls);
  384. newName.split(/\s+/g).forEach(function(klass) {
  385. if (!$(this).hasClass(klass)) {
  386. classList.push(klass)
  387. }
  388. }, this);
  389. classList.length && (this.className += (cls ? " " : "") + classList.join(" "))
  390. });
  391. },
  392. removeClass: function(name){
  393. return this.each(function(idx) {
  394. if(name === undefined)
  395. return this.className = '';
  396. classList = this.className;
  397. funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass) {
  398. classList = classList.replace(classRE(klass), " ")
  399. });
  400. this.className = classList.trim()
  401. });
  402. },
  403. toggleClass: function(name, when){
  404. return this.each(function(idx){
  405. var newName = funcArg(this, name, idx, this.className);
  406. (when === undefined ? !$(this).hasClass(newName) : when) ?
  407. $(this).addClass(newName) : $(this).removeClass(newName);
  408. });
  409. }
  410. };
  411. 'filter,add,not,eq,first,last,find,closest,parents,parent,children,siblings'.split(',').forEach(function(property){
  412. var fn = $.fn[property];
  413. $.fn[property] = function() {
  414. var ret = fn.apply(this, arguments);
  415. ret.prevObject = this;
  416. return ret;
  417. }
  418. });
  419. ['width', 'height'].forEach(function(dimension){
  420. $.fn[dimension] = function(value) {
  421. var offset, Dimension = dimension.replace(/./, function(m) { return m[0].toUpperCase() });
  422. if (value === undefined) return this[0] == window ? window['inner' + Dimension] :
  423. this[0] == document ? document.documentElement['offset' + Dimension] :
  424. (offset = this.offset()) && offset[dimension];
  425. else return this.each(function(idx){
  426. var el = $(this);
  427. el.css(dimension, funcArg(this, value, idx, el[dimension]()));
  428. });
  429. }
  430. });
  431. function insert(operator, target, node) {
  432. var parent = (operator % 2) ? target : target.parentNode;
  433. parent && parent.insertBefore(node,
  434. !operator ? target.nextSibling : // after
  435. operator == 1 ? parent.firstChild : // prepend
  436. operator == 2 ? target : // before
  437. null); // append
  438. }
  439. function traverseNode (node, fun) {
  440. fun(node);
  441. for (var key in node.childNodes) {
  442. traverseNode(node.childNodes[key], fun);
  443. }
  444. }
  445. adjacencyOperators.forEach(function(key, operator) {
  446. $.fn[key] = function(html){
  447. var nodes = isO(html) ? html : fragment(html);
  448. if (!('length' in nodes) || nodes.nodeType) nodes = [nodes];
  449. if (nodes.length < 1) return this;
  450. var size = this.length, copyByClone = size > 1, inReverse = operator < 2;
  451. return this.each(function(index, target){
  452. for (var i = 0; i < nodes.length; i++) {
  453. var node = nodes[inReverse ? nodes.length-i-1 : i];
  454. traverseNode(node, function (node) {
  455. if (node.nodeName != null && node.nodeName.toUpperCase() === 'SCRIPT' && (!node.type || node.type === 'text/javascript')) {
  456. window['eval'].call(window, node.innerHTML);
  457. }
  458. });
  459. if (copyByClone && index < size - 1) node = node.cloneNode(true);
  460. insert(operator, target, node);
  461. }
  462. });
  463. };
  464. var reverseKey = (operator % 2) ? key+'To' : 'insert'+(operator ? 'Before' : 'After');
  465. $.fn[reverseKey] = function(html) {
  466. $(html)[key](this);
  467. return this;
  468. };
  469. });
  470. Z.prototype = $.fn;
  471. return $;
  472. })();
  473. window.Zepto = Zepto;
  474. '$' in window || (window.$ = Zepto);
  475. // Zepto.js
  476. // (c) 2010, 2011 Thomas Fuchs
  477. // Zepto.js may be freely distributed under the MIT license.
  478. (function($){
  479. var $$ = $.qsa, handlers = {}, _zid = 1, specialEvents={};
  480. specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents';
  481. function zid(element) {
  482. return element._zid || (element._zid = _zid++);
  483. }
  484. function findHandlers(element, event, fn, selector) {
  485. event = parse(event);
  486. if (event.ns) var matcher = matcherFor(event.ns);
  487. return (handlers[zid(element)] || []).filter(function(handler) {
  488. return handler
  489. && (!event.e || handler.e == event.e)
  490. && (!event.ns || matcher.test(handler.ns))
  491. && (!fn || handler.fn == fn)
  492. && (!selector || handler.sel == selector);
  493. });
  494. }
  495. function parse(event) {
  496. var parts = ('' + event).split('.');
  497. return {e: parts[0], ns: parts.slice(1).sort().join(' ')};
  498. }
  499. function matcherFor(ns) {
  500. return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)');
  501. }
  502. function eachEvent(events, fn, iterator){
  503. if ($.isObject(events)) $.each(events, iterator);
  504. else events.split(/\s/).forEach(function(type){ iterator(type, fn) });
  505. }
  506. function add(element, events, fn, selector, getDelegate){
  507. var id = zid(element), set = (handlers[id] || (handlers[id] = []));
  508. eachEvent(events, fn, function(event, fn){
  509. var delegate = getDelegate && getDelegate(fn, event),
  510. callback = delegate || fn;
  511. var proxyfn = function (event) {
  512. var result = callback.apply(element, [event].concat(event.data));
  513. if (result === false) event.preventDefault();
  514. return result;
  515. };
  516. var handler = $.extend(parse(event), {fn: fn, proxy: proxyfn, sel: selector, del: delegate, i: set.length});
  517. set.push(handler);
  518. element.addEventListener(handler.e, proxyfn, false);
  519. });
  520. }
  521. function remove(element, events, fn, selector){
  522. var id = zid(element);
  523. eachEvent(events || '', fn, function(event, fn){
  524. findHandlers(element, event, fn, selector).forEach(function(handler){
  525. delete handlers[id][handler.i];
  526. element.removeEventListener(handler.e, handler.proxy, false);
  527. });
  528. });
  529. }
  530. $.event = { add: add, remove: remove }
  531. $.fn.bind = function(event, callback){
  532. return this.each(function(){
  533. add(this, event, callback);
  534. });
  535. };
  536. $.fn.unbind = function(event, callback){
  537. return this.each(function(){
  538. remove(this, event, callback);
  539. });
  540. };
  541. $.fn.one = function(event, callback){
  542. return this.each(function(i, element){
  543. add(this, event, callback, null, function(fn, type){
  544. return function(){
  545. var result = fn.apply(element, arguments);
  546. remove(element, type, fn);
  547. return result;
  548. }
  549. });
  550. });
  551. };
  552. var returnTrue = function(){return true},
  553. returnFalse = function(){return false},
  554. eventMethods = {
  555. preventDefault: 'isDefaultPrevented',
  556. stopImmediatePropagation: 'isImmediatePropagationStopped',
  557. stopPropagation: 'isPropagationStopped'
  558. };
  559. function createProxy(event) {
  560. var proxy = $.extend({originalEvent: event}, event);
  561. $.each(eventMethods, function(name, predicate) {
  562. proxy[name] = function(){
  563. this[predicate] = returnTrue;
  564. return event[name].apply(event, arguments);
  565. };
  566. proxy[predicate] = returnFalse;
  567. })
  568. return proxy;
  569. }
  570. // emulates the 'defaultPrevented' property for browsers that have none
  571. function fix(event) {
  572. if (!('defaultPrevented' in event)) {
  573. event.defaultPrevented = false;
  574. var prevent = event.preventDefault;
  575. event.preventDefault = function() {
  576. this.defaultPrevented = true;
  577. prevent.call(this);
  578. }
  579. }
  580. }
  581. $.fn.delegate = function(selector, event, callback){
  582. return this.each(function(i, element){
  583. add(element, event, callback, selector, function(fn){
  584. return function(e){
  585. var evt, match = $(e.target).closest(selector, element).get(0);
  586. if (match) {
  587. evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element});
  588. return fn.apply(match, [evt].concat([].slice.call(arguments, 1)));
  589. }
  590. }
  591. });
  592. });
  593. };
  594. $.fn.undelegate = function(selector, event, callback){
  595. return this.each(function(){
  596. remove(this, event, callback, selector);
  597. });
  598. }
  599. $.fn.live = function(event, callback){
  600. $(document.body).delegate(this.selector, event, callback);
  601. return this;
  602. };
  603. $.fn.die = function(event, callback){
  604. $(document.body).undelegate(this.selector, event, callback);
  605. return this;
  606. };
  607. $.fn.on = function(event, selector, callback){
  608. return selector === undefined || $.isFunction(selector) ?
  609. this.bind(event, selector) : this.delegate(selector, event, callback);
  610. };
  611. $.fn.off = function(event, selector, callback){
  612. return selector === undefined || $.isFunction(selector) ?
  613. this.unbind(event, selector) : this.undelegate(selector, event, callback);
  614. };
  615. $.fn.trigger = function(event, data){
  616. if (typeof event == 'string') event = $.Event(event);
  617. fix(event);
  618. event.data = data;
  619. return this.each(function(){ this.dispatchEvent(event) });
  620. };
  621. // triggers event handlers on current element just as if an event occurred,
  622. // doesn't trigger an actual event, doesn't bubble
  623. $.fn.triggerHandler = function(event, data){
  624. var e, result;
  625. this.each(function(i, element){
  626. e = createProxy(typeof event == 'string' ? $.Event(event) : event);
  627. e.data = data; e.target = element;
  628. $.each(findHandlers(element, event.type || event), function(i, handler){
  629. result = handler.proxy(e);
  630. if (e.isImmediatePropagationStopped()) return false;
  631. });
  632. });
  633. return result;
  634. };
  635. // shortcut methods for `.bind(event, fn)` for each event type
  636. ('focusin focusout load resize scroll unload click dblclick '+
  637. 'mousedown mouseup mousemove mouseover mouseout '+
  638. 'change select keydown keypress keyup error').split(' ').forEach(function(event) {
  639. $.fn[event] = function(callback){ return this.bind(event, callback) };
  640. });
  641. ['focus', 'blur'].forEach(function(name) {
  642. $.fn[name] = function(callback) {
  643. if (callback) this.bind(name, callback);
  644. else if (this.length) try { this.get(0)[name]() } catch(e){};
  645. return this;
  646. };
  647. });
  648. $.Event = function(type, props) {
  649. var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true;
  650. if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name]);
  651. event.initEvent(type, bubbles, true, null, null, null, null, null, null, null, null, null, null, null, null);
  652. return event;
  653. };
  654. })(Zepto);
  655. // Zepto.js
  656. // (c) 2010, 2011 Thomas Fuchs
  657. // Zepto.js may be freely distributed under the MIT license.
  658. (function($){
  659. function detect(ua){
  660. var os = (this.os = {}), browser = (this.browser = {}),
  661. webkit = ua.match(/WebKit\/([\d.]+)/),
  662. android = ua.match(/(Android)\s+([\d.]+)/),
  663. ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
  664. iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
  665. webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/),
  666. touchpad = webos && ua.match(/TouchPad/),
  667. blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  668. if (webkit) browser.version = webkit[1];
  669. browser.webkit = !!webkit;
  670. if (android) os.android = true, os.version = android[2];
  671. if (iphone) os.ios = true, os.version = iphone[2].replace(/_/g, '.'), os.iphone = true;
  672. if (ipad) os.ios = true, os.version = ipad[2].replace(/_/g, '.'), os.ipad = true;
  673. if (webos) os.webos = true, os.version = webos[2];
  674. if (touchpad) os.touchpad = true;
  675. if (blackberry) os.blackberry = true, os.version = blackberry[2];
  676. }
  677. // ### $.os
  678. //
  679. // Object containing information about browser platform
  680. //
  681. // *Example:*
  682. //
  683. // $.os.ios // => true if running on Apple iOS
  684. // $.os.android // => true if running on Android
  685. // $.os.webos // => true if running on HP/Palm WebOS
  686. // $.os.touchpad // => true if running on a HP TouchPad
  687. // $.os.version // => string with a version number, e.g.
  688. // "4.0", "3.1.1", "2.1", etc.
  689. // $.os.iphone // => true if running on iPhone
  690. // $.os.ipad // => true if running on iPad
  691. // $.os.blackberry // => true if running on BlackBerry
  692. //
  693. // ### $.browser
  694. //
  695. // *Example:*
  696. //
  697. // $.browser.webkit // => true if the browser is WebKit-based
  698. // $.browser.version // => WebKit version string
  699. detect.call($, navigator.userAgent);
  700. // make available to unit tests
  701. $.__detect = detect;
  702. })(Zepto);
  703. // Zepto.js
  704. // (c) 2010, 2011 Thomas Fuchs
  705. // Zepto.js may be freely distributed under the MIT license.
  706. (function($, undefined){
  707. var prefix = '', eventPrefix, endEventName, endAnimationName,
  708. vendors = {Webkit: 'webkit', Moz: '', O: 'o', ms: 'MS'},
  709. document = window.document, testEl = document.createElement('div'),
  710. supportedTransforms = /^((translate|rotate|scale)(X|Y|Z|3d)?|matrix(3d)?|perspective|skew(X|Y)?)$/i;
  711. function downcase(str) { return str.toLowerCase() }
  712. function normalizeEvent(name) { return eventPrefix ? eventPrefix + name : downcase(name) };
  713. $.each(vendors, function(vendor, event){
  714. if (testEl.style[vendor + 'TransitionProperty'] !== undefined) {
  715. prefix = '-' + downcase(vendor) + '-';
  716. eventPrefix = event;
  717. return false;
  718. }
  719. });
  720. $.fx = {
  721. off: (eventPrefix === undefined && testEl.style.transitionProperty === undefined),
  722. cssPrefix: prefix,
  723. transitionEnd: normalizeEvent('TransitionEnd'),
  724. animationEnd: normalizeEvent('AnimationEnd')
  725. };
  726. $.fn.animate = function(properties, duration, ease, callback){
  727. if ($.isObject(duration))
  728. ease = duration.easing, callback = duration.complete, duration = duration.duration;
  729. if (duration) duration = duration / 1000;
  730. return this.anim(properties, duration, ease, callback);
  731. };
  732. $.fn.anim = function(properties, duration, ease, callback){
  733. var transforms, cssProperties = {}, key, that = this, wrappedCallback, endEvent = $.fx.transitionEnd;
  734. if (duration === undefined) duration = 0.4;
  735. if ($.fx.off) duration = 0;
  736. if (typeof properties == 'string') {
  737. // keyframe animation
  738. cssProperties[prefix + 'animation-name'] = properties;
  739. cssProperties[prefix + 'animation-duration'] = duration + 's';
  740. endEvent = $.fx.animationEnd;
  741. } else {
  742. // CSS transitions
  743. for (key in properties)
  744. if (supportedTransforms.test(key)) {
  745. transforms || (transforms = []);
  746. transforms.push(key + '(' + properties[key] + ')');
  747. }
  748. else cssProperties[key] = properties[key];
  749. if (transforms) cssProperties[prefix + 'transform'] = transforms.join(' ');
  750. if (!$.fx.off) cssProperties[prefix + 'transition'] = 'all ' + duration + 's ' + (ease || '');
  751. }
  752. wrappedCallback = function(){
  753. var props = {};
  754. props[prefix + 'transition'] = props[prefix + 'animation-name'] = 'none';
  755. $(this).css(props);
  756. callback && callback.call(this);
  757. }
  758. if (duration > 0) this.one(endEvent, wrappedCallback);
  759. setTimeout(function() {
  760. that.css(cssProperties);
  761. if (duration <= 0) setTimeout(function() {
  762. that.each(function(){ wrappedCallback.call(this) });
  763. }, 0);
  764. }, 0);
  765. return this;
  766. };
  767. testEl = null;
  768. })(Zepto);
  769. // Zepto.js
  770. // (c) 2010, 2011 Thomas Fuchs
  771. // Zepto.js may be freely distributed under the MIT license.
  772. (function($){
  773. var jsonpID = 0,
  774. isObject = $.isObject,
  775. document = window.document,
  776. key,
  777. name;
  778. // trigger a custom event and return false if it was cancelled
  779. function triggerAndReturn(context, eventName, data) {
  780. var event = $.Event(eventName);
  781. $(context).trigger(event, data);
  782. return !event.defaultPrevented;
  783. }
  784. // trigger an Ajax "global" event
  785. function triggerGlobal(settings, context, eventName, data) {
  786. if (settings.global) return triggerAndReturn(context || document, eventName, data);
  787. }
  788. // Number of active Ajax requests
  789. $.active = 0;
  790. function ajaxStart(settings) {
  791. if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart');
  792. }
  793. function ajaxStop(settings) {
  794. if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop');
  795. }
  796. // triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable
  797. function ajaxBeforeSend(xhr, settings) {
  798. var context = settings.context;
  799. if (settings.beforeSend.call(context, xhr, settings) === false ||
  800. triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false)
  801. return false;
  802. triggerGlobal(settings, context, 'ajaxSend', [xhr, settings]);
  803. }
  804. function ajaxSuccess(data, xhr, settings) {
  805. var context = settings.context, status = 'success';
  806. settings.success.call(context, data, status, xhr);
  807. triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data]);
  808. ajaxComplete(status, xhr, settings);
  809. }
  810. // type: "timeout", "error", "abort", "parsererror"
  811. function ajaxError(error, type, xhr, settings) {
  812. var context = settings.context;
  813. settings.error.call(context, xhr, type, error);
  814. triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error]);
  815. ajaxComplete(type, xhr, settings);
  816. }
  817. // status: "success", "notmodified", "error", "timeout", "abort", "parsererror"
  818. function ajaxComplete(status, xhr, settings) {
  819. var context = settings.context;
  820. settings.complete.call(context, xhr, status);
  821. triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings]);
  822. ajaxStop(settings);
  823. }
  824. // Empty function, used as default callback
  825. function empty() {}
  826. // ### $.ajaxJSONP
  827. //
  828. // Load JSON from a server in a different domain (JSONP)
  829. //
  830. // *Arguments:*
  831. //
  832. // options — object that configure the request,
  833. // see avaliable options below
  834. //
  835. // *Avaliable options:*
  836. //
  837. // url — url to which the request is sent
  838. // success — callback that is executed if the request succeeds
  839. // error — callback that is executed if the server drops error
  840. // context — in which context to execute the callbacks in
  841. //
  842. // *Example:*
  843. //
  844. // $.ajaxJSONP({
  845. // url: 'http://example.com/projects?callback=?',
  846. // success: function (data) {
  847. // projects.push(json);
  848. // }
  849. // });
  850. //
  851. $.ajaxJSONP = function(options){
  852. var callbackName = 'jsonp' + (++jsonpID),
  853. script = document.createElement('script'),
  854. abort = function(){
  855. $(script).remove();
  856. if (callbackName in window) window[callbackName] = empty;
  857. ajaxComplete(xhr, options, 'abort');
  858. },
  859. xhr = { abort: abort }, abortTimeout;
  860. window[callbackName] = function(data){
  861. clearTimeout(abortTimeout);
  862. $(script).remove();
  863. delete window[callbackName];
  864. ajaxSuccess(data, xhr, options);
  865. };
  866. script.src = options.url.replace(/=\?/, '=' + callbackName);
  867. $('head').append(script);
  868. if (options.timeout > 0) abortTimeout = setTimeout(function(){
  869. xhr.abort();
  870. ajaxComplete(xhr, options, 'timeout');
  871. }, options.timeout);
  872. return xhr;
  873. };
  874. // ### $.ajaxSettings
  875. //
  876. // AJAX settings
  877. //
  878. $.ajaxSettings = {
  879. // Default type of request
  880. type: 'GET',
  881. // Callback that is executed before request
  882. beforeSend: empty,
  883. // Callback that is executed if the request succeeds
  884. success: empty,
  885. // Callback that is executed the the server drops error
  886. error: empty,
  887. // Callback that is executed on request complete (both: error and success)
  888. complete: empty,
  889. // The context for the callbacks
  890. context: null,
  891. // Whether to trigger "global" Ajax events
  892. global: true,
  893. // Transport
  894. xhr: function () {
  895. return new window.XMLHttpRequest();
  896. },
  897. // MIME types mapping
  898. accepts: {
  899. script: 'text/javascript, application/javascript',
  900. json: 'application/json',
  901. xml: 'application/xml, text/xml',
  902. html: 'text/html',
  903. text: 'text/plain'
  904. },
  905. // Whether the request is to another domain
  906. crossDomain: false,
  907. // Default timeout
  908. timeout: 0
  909. };
  910. // ### $.ajax
  911. //
  912. // Perform AJAX request
  913. //
  914. // *Arguments:*
  915. //
  916. // options — object that configure the request,
  917. // see avaliable options below
  918. //
  919. // *Avaliable options:*
  920. //
  921. // type ('GET') — type of request GET / POST
  922. // url (window.location) — url to which the request is sent
  923. // data — data to send to server,
  924. // can be string or object
  925. // dataType ('json') — what response type you accept from
  926. // the server:
  927. // 'json', 'xml', 'html', or 'text'
  928. // timeout (0) — request timeout
  929. // beforeSend — callback that is executed before
  930. // request send
  931. // complete — callback that is executed on request
  932. // complete (both: error and success)
  933. // success — callback that is executed if
  934. // the request succeeds
  935. // error — callback that is executed if
  936. // the server drops error
  937. // context — in which context to execute the
  938. // callbacks in
  939. //
  940. // *Example:*
  941. //
  942. // $.ajax({
  943. // type: 'POST',
  944. // url: '/projects',
  945. // data: { name: 'Zepto.js' },
  946. // dataType: 'html',
  947. // timeout: 100,
  948. // context: $('body'),
  949. // success: function (data) {
  950. // this.append(data);
  951. // },
  952. // error: function (xhr, type) {
  953. // alert('Error!');
  954. // }
  955. // });
  956. //
  957. $.ajax = function(options){
  958. var settings = $.extend({}, options || {});
  959. for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key];
  960. ajaxStart(settings);
  961. if (!settings.crossDomain) settings.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(settings.url) &&
  962. RegExp.$2 != window.location.host;
  963. if (/=\?/.test(settings.url)) return $.ajaxJSONP(settings);
  964. if (!settings.url) settings.url = window.location.toString();
  965. if (settings.data && !settings.contentType) settings.contentType = 'application/x-www-form-urlencoded';
  966. if (isObject(settings.data)) settings.data = $.param(settings.data);
  967. if (settings.type.match(/get/i) && settings.data) {
  968. var queryString = settings.data;
  969. if (settings.url.match(/\?.*=/)) {
  970. queryString = '&' + queryString;
  971. } else if (queryString[0] != '?') {
  972. queryString = '?' + queryString;
  973. }
  974. settings.url += queryString;
  975. }
  976. var mime = settings.accepts[settings.dataType],
  977. baseHeaders = { },
  978. protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol,
  979. xhr = $.ajaxSettings.xhr(), abortTimeout;
  980. if (!settings.crossDomain) baseHeaders['X-Requested-With'] = 'XMLHttpRequest';
  981. if (mime) baseHeaders['Accept'] = mime;
  982. settings.headers = $.extend(baseHeaders, settings.headers || {});
  983. xhr.onreadystatechange = function(){
  984. if (xhr.readyState == 4) {
  985. clearTimeout(abortTimeout);
  986. var result, error = false;
  987. if ((xhr.status >= 200 && xhr.status < 300) || (xhr.status == 0 && protocol == 'file:')) {
  988. if (mime == 'application/json' && !(/^\s*$/.test(xhr.responseText))) {
  989. try { result = JSON.parse(xhr.responseText); }
  990. catch (e) { error = e; }
  991. }
  992. else result = xhr.responseText;
  993. if (error) ajaxError(error, 'parsererror', xhr, settings);
  994. else ajaxSuccess(result, xhr, settings);
  995. } else {
  996. ajaxError(null, 'error', xhr, settings);
  997. }
  998. }
  999. };
  1000. xhr.open(settings.type, settings.url, true);
  1001. if (settings.contentType) settings.headers['Content-Type'] = settings.contentType;
  1002. for (name in settings.headers) xhr.setRequestHeader(name, settings.headers[name]);
  1003. if (ajaxBeforeSend(xhr, settings) === false) {
  1004. xhr.abort();
  1005. return false;
  1006. }
  1007. if (settings.timeout > 0) abortTimeout = setTimeout(function(){
  1008. xhr.onreadystatechange = empty;
  1009. xhr.abort();
  1010. ajaxError(null, 'timeout', xhr, settings);
  1011. }, settings.timeout);
  1012. xhr.send(settings.data);
  1013. return xhr;
  1014. };
  1015. // ### $.get
  1016. //
  1017. // Load data from the server using a GET request
  1018. //
  1019. // *Arguments:*
  1020. //
  1021. // url — url to which the request is sent
  1022. // success — callback that is executed if the request succeeds
  1023. //
  1024. // *Example:*
  1025. //
  1026. // $.get(
  1027. // '/projects/42',
  1028. // function (data) {
  1029. // $('body').append(data);
  1030. // }
  1031. // );
  1032. //
  1033. $.get = function(url, success){ return $.ajax({ url: url, success: success }) };
  1034. // ### $.post
  1035. //
  1036. // Load data from the server using POST request
  1037. //
  1038. // *Arguments:*
  1039. //
  1040. // url — url to which the request is sent
  1041. // [data] — data to send to server, can be string or object
  1042. // [success] — callback that is executed if the request succeeds
  1043. // [dataType] — type of expected response
  1044. // 'json', 'xml', 'html', or 'text'
  1045. //
  1046. // *Example:*
  1047. //
  1048. // $.post(
  1049. // '/projects',
  1050. // { name: 'Zepto.js' },
  1051. // function (data) {
  1052. // $('body').append(data);
  1053. // },
  1054. // 'html'
  1055. // );
  1056. //
  1057. $.post = function(url, data, success, dataType){
  1058. if ($.isFunction(data)) dataType = dataType || success, success = data, data = null;
  1059. return $.ajax({ type: 'POST', url: url, data: data, success: success, dataType: dataType });
  1060. };
  1061. // ### $.getJSON
  1062. //
  1063. // Load JSON from the server using GET request
  1064. //
  1065. // *Arguments:*
  1066. //
  1067. // url — url to which the request is sent
  1068. // success — callback that is executed if the request succeeds
  1069. //
  1070. // *Example:*
  1071. //
  1072. // $.getJSON(
  1073. // '/projects/42',
  1074. // function (json) {
  1075. // projects.push(json);
  1076. // }
  1077. // );
  1078. //
  1079. $.getJSON = function(url, success){
  1080. return $.ajax({ url: url, success: success, dataType: 'json' });
  1081. };
  1082. // ### $.fn.load
  1083. //
  1084. // Load data from the server into an element
  1085. //
  1086. // *Arguments:*
  1087. //
  1088. // url — url to which the request is sent
  1089. // [success] — callback that is executed if the request succeeds
  1090. //
  1091. // *Examples:*
  1092. //
  1093. // $('#project_container').get(
  1094. // '/projects/42',
  1095. // function () {
  1096. // alert('Project was successfully loaded');
  1097. // }
  1098. // );
  1099. //
  1100. // $('#project_comments').get(
  1101. // '/projects/42 #comments',
  1102. // function () {
  1103. // alert('Comments was successfully loaded');
  1104. // }
  1105. // );
  1106. //
  1107. $.fn.load = function(url, success){
  1108. if (!this.length) return this;
  1109. var self = this, parts = url.split(/\s/), selector;
  1110. if (parts.length > 1) url = parts[0], selector = parts[1];
  1111. $.get(url, function(response){
  1112. self.html(selector ?
  1113. $(document.createElement('div')).html(response).find(selector).html()
  1114. : response);
  1115. success && success.call(self);
  1116. });
  1117. return this;
  1118. };
  1119. var escape = encodeURIComponent;
  1120. function serialize(params, obj, traditional, scope){
  1121. var array = $.isArray(obj);
  1122. $.each(obj, function(key, value) {
  1123. if (scope) key = traditional ? scope : scope + '[' + (array ? '' : key) + ']';
  1124. // handle data in serializeArray() format
  1125. if (!scope && array) params.add(value.name, value.value);
  1126. // recurse into nested objects
  1127. else if (traditional ? $.isArray(value) : isObject(value))
  1128. serialize(params, value, traditional, key);
  1129. else params.add(key, value);
  1130. });
  1131. }
  1132. // ### $.param
  1133. //
  1134. // Encode object as a string of URL-encoded key-value pairs
  1135. //
  1136. // *Arguments:*
  1137. //
  1138. // obj — object to serialize
  1139. // [traditional] — perform shallow serialization
  1140. //
  1141. // *Example:*
  1142. //
  1143. // $.param( { name: 'Zepto.js', version: '0.6' } );
  1144. //
  1145. $.param = function(obj, traditional){
  1146. var params = [];
  1147. params.add = function(k, v){ this.push(escape(k) + '=' + escape(v)) };
  1148. serialize(params, obj, traditional);
  1149. return params.join('&').replace('%20', '+');
  1150. };
  1151. })(Zepto);
  1152. // Zepto.js
  1153. // (c) 2010, 2011 Thomas Fuchs
  1154. // Zepto.js may be freely distributed under the MIT license.
  1155. (function ($) {
  1156. // ### $.fn.serializeArray
  1157. //
  1158. // Encode a set of form elements as an array of names and values
  1159. //
  1160. // *Example:*
  1161. //
  1162. // $('#login_form').serializeArray();
  1163. //
  1164. // returns
  1165. //
  1166. // [
  1167. // {
  1168. // name: 'email',
  1169. // value: 'koss@nocorp.me'
  1170. // },
  1171. // {
  1172. // name: 'password',
  1173. // value: '123456'
  1174. // }
  1175. // ]
  1176. //
  1177. $.fn.serializeArray = function () {
  1178. var result = [], el;
  1179. $( Array.prototype.slice.call(this.get(0).elements) ).each(function () {
  1180. el = $(this);
  1181. var type = el.attr('type');
  1182. if (
  1183. !this.disabled && type != 'submit' && type != 'reset' && type != 'button' &&
  1184. ((type != 'radio' && type != 'checkbox') || this.checked)
  1185. ) {
  1186. result.push({
  1187. name: el.attr('name'),
  1188. value: el.val()
  1189. });
  1190. }
  1191. });
  1192. return result;
  1193. };
  1194. // ### $.fn.serialize
  1195. //
  1196. //
  1197. // Encode a set of form elements as a string for submission
  1198. //
  1199. // *Example:*
  1200. //
  1201. // $('#login_form').serialize();
  1202. //
  1203. // returns
  1204. //
  1205. // "email=koss%40nocorp.me&password=123456"
  1206. //
  1207. $.fn.serialize = function () {
  1208. var result = [];
  1209. this.serializeArray().forEach(function (elm) {
  1210. result.push( encodeURIComponent(elm.name) + '=' + encodeURIComponent(elm.value) );
  1211. });
  1212. return result.join('&');
  1213. };
  1214. // ### $.fn.submit
  1215. //
  1216. // Bind or trigger the submit event for a form
  1217. //
  1218. // *Examples:*
  1219. //
  1220. // To bind a handler for the submit event:
  1221. //
  1222. // $('#login_form').submit(function (e) {
  1223. // alert('Form was submitted!');
  1224. // e.preventDefault();
  1225. // });
  1226. //
  1227. // To trigger form submit:
  1228. //
  1229. // $('#login_form').submit();
  1230. //
  1231. $.fn.submit = function (callback) {
  1232. if (callback) this.bind('submit', callback)
  1233. else if (this.length) {
  1234. var event = $.Event('submit');
  1235. this.eq(0).trigger(event);
  1236. if (!event.defaultPrevented) this.get(0).submit()
  1237. }
  1238. return this;
  1239. }
  1240. })(Zepto);
  1241. // Zepto.js
  1242. // (c) 2010, 2011 Thomas Fuchs
  1243. // Zepto.js may be freely distributed under the MIT license.
  1244. (function($){
  1245. var touch = {}, touchTimeout;
  1246. function parentIfText(node){
  1247. return 'tagName' in node ? node : node.parentNode;
  1248. }
  1249. function swipeDirection(x1, x2, y1, y2){
  1250. var xDelta = Math.abs(x1 - x2), yDelta = Math.abs(y1 - y2);
  1251. if (xDelta >= yDelta) {
  1252. return (x1 - x2 > 0 ? 'Left' : 'Right');
  1253. } else {
  1254. return (y1 - y2 > 0 ? 'Up' : 'Down');
  1255. }
  1256. }
  1257. var longTapDelay = 750;
  1258. function longTap(){
  1259. if (touch.last && (Date.now() - touch.last >= longTapDelay)) {
  1260. $(touch.target).trigger('longTap');
  1261. touch = {};
  1262. }
  1263. }
  1264. $(document).ready(function(){
  1265. $(document.body).bind('touchstart', function(e){
  1266. var now = Date.now(), delta = now - (touch.last || now);
  1267. touch.target = parentIfText(e.touches[0].target);
  1268. touchTimeout && clearTimeout(touchTimeout);
  1269. touch.x1 = e.touches[0].pageX;
  1270. touch.y1 = e.touches[0].pageY;
  1271. if (delta > 0 && delta <= 250) touch.isDoubleTap = true;
  1272. touch.last = now;
  1273. setTimeout(longTap, longTapDelay);
  1274. }).bind('touchmove', function(e){
  1275. touch.x2 = e.touches[0].pageX;
  1276. touch.y2 = e.touches[0].pageY;
  1277. }).bind('touchend', function(e){
  1278. if (touch.isDoubleTap) {
  1279. $(touch.target).trigger('doubleTap');
  1280. touch = {};
  1281. } else if (touch.x2 > 0 || touch.y2 > 0) {
  1282. (Math.abs(touch.x1 - touch.x2) > 30 || Math.abs(touch.y1 - touch.y2) > 30) &&
  1283. $(touch.target).trigger('swipe') &&
  1284. $(touch.target).trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2)));
  1285. touch.x1 = touch.x2 = touch.y1 = touch.y2 = touch.last = 0;
  1286. } else if ('last' in touch) {
  1287. touchTimeout = setTimeout(function(){
  1288. touchTimeout = null;
  1289. $(touch.target).trigger('tap')
  1290. touch = {};
  1291. }, 250);
  1292. }
  1293. }).bind('touchcancel', function(){ touch = {} });
  1294. });
  1295. ['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'longTap'].forEach(function(m){
  1296. $.fn[m] = function(callback){ return this.bind(m, callback) }
  1297. });
  1298. })(Zepto);
  1299. (function ($) {
  1300. var defaults = {
  1301. duration: 400,
  1302. easing: ''
  1303. },
  1304. vendor = (/webkit/i).test(navigator.appVersion) ? 'webkit' : 'moz',
  1305. prefix = '-' + vendor + '-',
  1306. vendorNames = n = {
  1307. transition: prefix + 'transition',
  1308. transform: prefix + 'transform',
  1309. transitionEnd: vendor + 'TransitionEnd'
  1310. },
  1311. transformTypes = [
  1312. 'scale', 'scaleX', 'scaleY', 'scale3d',
  1313. 'rotate', 'rotateX', 'rotateY', 'rotateZ', 'rotate3d',
  1314. 'translate', 'translateX', 'translateY', 'translateZ', 'translate3d',
  1315. 'skew', 'skewX', 'skewY',
  1316. 'matrix', 'matrix3d', 'perspective'
  1317. ];
  1318. // Implement Array.prototype.indexOf if it's not. This is
  1319. // mainly Internet Explorer.
  1320. if (!Array.prototype.indexOf) {
  1321. Array.prototype.indexOf = function(obj, start) {
  1322. for (var i = (start || 0), j = this.length; i < j; i++) {
  1323. if (this[i] === obj) return i;
  1324. }
  1325. return -1;
  1326. }
  1327. }
  1328. // Helper function for easily adding transforms.
  1329. $.fn.transform = function (properties) {
  1330. var transforms = [];
  1331. for (var key in properties) {
  1332. if (transformTypes.indexOf(key) !== -1) {
  1333. transforms.push(key + '(' + properties[key] + ')');
  1334. delete properties[key];
  1335. }
  1336. }
  1337. if (transforms.length)
  1338. properties[n.transform] = transforms.join(' ');
  1339. return $(this).css(properties);
  1340. };
  1341. // Effects
  1342. $.fn.gfxPopIn = function (options, cb) {
  1343. var $that = $(this),
  1344. opts = $.extend({}, defaults, options || {});
  1345. opts.scale = opts.scale || 0.2;
  1346. $that.transform({
  1347. '-webkit-transform-origin': '50% 50%',
  1348. '-moz-transform-origin': '50% 50%',
  1349. scale: opts.scale,
  1350. opacity: '0',
  1351. display: 'block'
  1352. }).animate({scale: '1', opacity: '1'},
  1353. opts.duration, opts.easing, cb);
  1354. };
  1355. $.fn.gfxPopOut = function (options, cb) {
  1356. var $that = $(this),
  1357. opts = $.extend({}, defaults, options || {});
  1358. opts.scale = opts.scale || 0.2;
  1359. $that.transform({
  1360. '-webkit-transform-origin': '50% 50%',
  1361. '-moz-transform-origin': '50% 50%',
  1362. scale: '1',
  1363. opacity: '1'
  1364. }).animate({opacity: 0, scale: opts.scale},
  1365. opts.duration, opts.easing, function () {
  1366. $that.transform({display: 'none',
  1367. opacity: 1, scale: 1});
  1368. cb && cb();
  1369. });
  1370. };
  1371. $.fn.gfxFadeIn = function (options, cb) {
  1372. var $that = $(this),
  1373. opts = $.extend({}, defaults, options || {});
  1374. opts.duration = opts.duration || 1000;
  1375. $that

Large files files are truncated, but you can click here to view the full file