PageRenderTime 57ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/files/photoswipe/3.0.5/code.photoswipe-3.0.5.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 2268 lines | 1276 code | 681 blank | 311 comment | 181 complexity | 77f4104a6b9fae365445942b87376ea6 MD5 | raw file
  1. // Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com)
  2. // Licensed under the MIT license
  3. // version: 3.0.5
  4. (function (window) {
  5. // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
  6. if (!Function.prototype.bind ) {
  7. Function.prototype.bind = function( obj ) {
  8. var slice = [].slice,
  9. args = slice.call(arguments, 1),
  10. self = this,
  11. nop = function () {},
  12. bound = function () {
  13. return self.apply( this instanceof nop ? this : ( obj || {} ),
  14. args.concat( slice.call(arguments) ) );
  15. };
  16. nop.prototype = self.prototype;
  17. bound.prototype = new nop();
  18. return bound;
  19. };
  20. }
  21. if (typeof window.Code === "undefined") {
  22. window.Code = {};
  23. }
  24. window.Code.Util = {
  25. /*
  26. * Function: registerNamespace
  27. */
  28. registerNamespace: function () {
  29. var
  30. args = arguments, obj = null, i, j, ns, nsParts, root, argsLen, nsPartsLens;
  31. for (i=0, argsLen=args.length; i<argsLen; i++) {
  32. ns = args[i];
  33. nsParts = ns.split(".");
  34. root = nsParts[0];
  35. if (typeof window[root] === "undefined"){
  36. window[root] = {};
  37. }
  38. obj = window[root];
  39. //eval('if (typeof ' + root + ' == "undefined"){' + root + ' = {};} obj = ' + root + ';');
  40. for (j=1, nsPartsLens=nsParts.length; j<nsPartsLens; ++j) {
  41. obj[nsParts[j]] = obj[nsParts[j]] || {};
  42. obj = obj[nsParts[j]];
  43. }
  44. }
  45. },
  46. /*
  47. * Function: coalesce
  48. * Takes any number of arguments and returns the first non Null / Undefined argument.
  49. */
  50. coalesce: function () {
  51. var i, j;
  52. for (i=0, j=arguments.length; i<j; i++) {
  53. if (!this.isNothing(arguments[i])) {
  54. return arguments[i];
  55. }
  56. }
  57. return null;
  58. },
  59. /*
  60. * Function: extend
  61. */
  62. extend: function(destination, source, overwriteProperties){
  63. var prop;
  64. if (this.isNothing(overwriteProperties)){
  65. overwriteProperties = true;
  66. }
  67. if (destination && source && this.isObject(source)){
  68. for(prop in source){
  69. if (this.objectHasProperty(source, prop)) {
  70. if (overwriteProperties){
  71. destination[prop] = source[prop];
  72. }
  73. else{
  74. if(typeof destination[prop] === "undefined"){
  75. destination[prop] = source[prop];
  76. }
  77. }
  78. }
  79. }
  80. }
  81. },
  82. /*
  83. * Function: clone
  84. */
  85. clone: function(obj) {
  86. var retval = {};
  87. this.extend(retval, obj);
  88. return retval;
  89. },
  90. /*
  91. * Function: isObject
  92. */
  93. isObject: function(obj){
  94. return obj instanceof Object;
  95. },
  96. /*
  97. * Function: isFunction
  98. */
  99. isFunction: function(obj){
  100. return ({}).toString.call(obj) === "[object Function]";
  101. },
  102. /*
  103. * Function: isArray
  104. */
  105. isArray: function(obj){
  106. return obj instanceof Array;
  107. },
  108. /*
  109. * Function: isLikeArray
  110. */
  111. isLikeArray: function(obj) {
  112. return typeof obj.length === 'number';
  113. },
  114. /*
  115. * Function: isNumber
  116. */
  117. isNumber: function(obj){
  118. return typeof obj === "number";
  119. },
  120. /*
  121. * Function: isString
  122. */
  123. isString: function(obj){
  124. return typeof obj === "string";
  125. },
  126. /*
  127. * Function: isNothing
  128. */
  129. isNothing: function (obj) {
  130. if (typeof obj === "undefined" || obj === null) {
  131. return true;
  132. }
  133. return false;
  134. },
  135. /*
  136. * Function: swapArrayElements
  137. */
  138. swapArrayElements: function(arr, i, j){
  139. var temp = arr[i];
  140. arr[i] = arr[j];
  141. arr[j] = temp;
  142. },
  143. /*
  144. * Function: trim
  145. */
  146. trim: function(val) {
  147. return val.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  148. },
  149. /*
  150. * Function: toCamelCase
  151. */
  152. toCamelCase: function(val){
  153. return val.replace(/(\-[a-z])/g, function($1){return $1.toUpperCase().replace('-','');});
  154. },
  155. /*
  156. * Function: toDashedCase
  157. */
  158. toDashedCase: function(val){
  159. return val.replace(/([A-Z])/g, function($1){return "-"+$1.toLowerCase();});
  160. },
  161. /*
  162. * Function: indexOf
  163. */
  164. arrayIndexOf: function(obj, array, prop){
  165. var i, j, retval, arrayItem;
  166. retval = -1;
  167. for (i=0, j=array.length; i<j; i++){
  168. arrayItem = array[i];
  169. if (!this.isNothing(prop)){
  170. if (this.objectHasProperty(arrayItem, prop)) {
  171. if (arrayItem[prop] === obj){
  172. retval = i;
  173. break;
  174. }
  175. }
  176. }
  177. else{
  178. if (arrayItem === obj){
  179. retval = i;
  180. break;
  181. }
  182. }
  183. }
  184. return retval;
  185. },
  186. /*
  187. * Function: objectHasProperty
  188. */
  189. objectHasProperty: function(obj, propName){
  190. if (obj.hasOwnProperty){
  191. return obj.hasOwnProperty(propName);
  192. }
  193. else{
  194. return ('undefined' !== typeof obj[propName]);
  195. }
  196. }
  197. };
  198. }(window));
  199. // Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com)
  200. // Licensed under the MIT license
  201. // version: 3.0.5
  202. (function(window, Util) {
  203. Util.Browser = {
  204. ua: null,
  205. version: null,
  206. safari: null,
  207. webkit: null,
  208. opera: null,
  209. msie: null,
  210. chrome: null,
  211. mozilla: null,
  212. android: null,
  213. blackberry: null,
  214. iPad: null,
  215. iPhone: null,
  216. iPod: null,
  217. iOS: null,
  218. is3dSupported: null,
  219. isCSSTransformSupported: null,
  220. isTouchSupported: null,
  221. isGestureSupported: null,
  222. _detect: function(){
  223. this.ua = window.navigator.userAgent;
  224. this.version = (this.ua.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || []);
  225. this.safari = (/Safari/gi).test(window.navigator.appVersion);
  226. this.webkit = /webkit/i.test(this.ua);
  227. this.opera = /opera/i.test(this.ua);
  228. this.msie = /msie/i.test(this.ua) && !this.opera;
  229. this.chrome = /Chrome/i.test(this.ua);
  230. this.firefox = /Firefox/i.test(this.ua);
  231. this.fennec = /Fennec/i.test(this.ua);
  232. this.mozilla = /mozilla/i.test(this.ua) && !/(compatible|webkit)/.test(this.ua);
  233. this.android = /android/i.test(this.ua);
  234. this.blackberry = /blackberry/i.test(this.ua);
  235. this.iOS = (/iphone|ipod|ipad/gi).test(window.navigator.platform);
  236. this.iPad = (/ipad/gi).test(window.navigator.platform);
  237. this.iPhone = (/iphone/gi).test(window.navigator.platform);
  238. this.iPod = (/ipod/gi).test(window.navigator.platform);
  239. var testEl = document.createElement('div');
  240. this.is3dSupported = !Util.isNothing(testEl.style.WebkitPerspective);
  241. this.isCSSTransformSupported = ( !Util.isNothing(testEl.style.WebkitTransform) || !Util.isNothing(testEl.style.MozTransform) || !Util.isNothing(testEl.style.transformProperty) );
  242. this.isTouchSupported = this.isEventSupported('touchstart');
  243. this.isGestureSupported = this.isEventSupported('gesturestart');
  244. },
  245. _eventTagNames: {
  246. 'select':'input',
  247. 'change':'input',
  248. 'submit':'form',
  249. 'reset':'form',
  250. 'error':'img',
  251. 'load':'img',
  252. 'abort':'img'
  253. },
  254. /*
  255. * Function: isEventSupported
  256. * http://perfectionkills.com/detecting-event-support-without-browser-sniffing/
  257. */
  258. isEventSupported: function(eventName) {
  259. var
  260. el = document.createElement(this._eventTagNames[eventName] || 'div'),
  261. isSupported;
  262. eventName = 'on' + eventName;
  263. isSupported = Util.objectHasProperty(el, eventName);
  264. if (!isSupported) {
  265. el.setAttribute(eventName, 'return;');
  266. isSupported = typeof el[eventName] === 'function';
  267. }
  268. el = null;
  269. return isSupported;
  270. },
  271. isLandscape: function(){
  272. return (Util.DOM.windowWidth() > Util.DOM.windowHeight());
  273. }
  274. };
  275. Util.Browser._detect();
  276. }
  277. (
  278. window,
  279. window.Code.Util
  280. ))
  281. ;
  282. // Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com)
  283. // Licensed under the MIT license
  284. // version: 3.0.5
  285. (function (window, Util) {
  286. Util.extend(Util, {
  287. Events: {
  288. /*
  289. * Function: add
  290. * Add an event handler
  291. */
  292. add: function(obj, type, handler){
  293. this._checkHandlersProperty(obj);
  294. if (type === 'mousewheel'){
  295. type = this._normaliseMouseWheelType();
  296. }
  297. if (typeof obj.__eventHandlers[type] === 'undefined'){
  298. obj.__eventHandlers[type] = [];
  299. }
  300. obj.__eventHandlers[type].push(handler);
  301. // DOM element
  302. if (this._isBrowserObject(obj)){
  303. obj.addEventListener(type, handler, false);
  304. }
  305. },
  306. /*
  307. * Function: remove
  308. * Removes a handler or all handlers associated with a type
  309. */
  310. remove: function(obj, type, handler){
  311. this._checkHandlersProperty(obj);
  312. if (type === 'mousewheel'){
  313. type = this._normaliseMouseWheelType();
  314. }
  315. if (obj.__eventHandlers[type] instanceof Array){
  316. var
  317. i, j,
  318. handlers = obj.__eventHandlers[type];
  319. // Removing all handlers for a type
  320. if (Util.isNothing(handler)){
  321. if (this._isBrowserObject(obj)){
  322. for (i=0, j=handlers.length; i<j; i++){
  323. obj.removeEventListener(type, handlers[i], false);
  324. }
  325. }
  326. obj.__eventHandlers[type] = [];
  327. return;
  328. }
  329. // Removing a specific handler
  330. for (i=0, j=handlers.length; i<j; i++){
  331. if (handlers[i] === handler){
  332. handlers.splice(i, 1);
  333. break;
  334. }
  335. }
  336. // DOM element
  337. if (this._isBrowserObject(obj)){
  338. obj.removeEventListener(type, handler, false);
  339. return;
  340. }
  341. }
  342. },
  343. /*
  344. * Function: fire
  345. * Fire an event
  346. */
  347. fire: function(obj, type){
  348. var
  349. i, j,
  350. event,
  351. listeners,
  352. listener,
  353. args = Array.prototype.slice.call(arguments).splice(2),
  354. isNative;
  355. if (type === 'mousewheel'){
  356. type = this._normaliseMouseWheelType();
  357. }
  358. // DOM element
  359. if (this._isBrowserObject(obj)){
  360. if (typeof type !== "string"){
  361. throw 'type must be a string for DOM elements';
  362. }
  363. isNative = this._NATIVE_EVENTS[type];
  364. event = document.createEvent(isNative ? "HTMLEvents" : "UIEvents");
  365. event[isNative ? 'initEvent' : 'initUIEvent'](type, true, true, window, 1);
  366. // Fire an event on an element that has no extra arguments
  367. if (args.length < 1){
  368. obj.dispatchEvent(event);
  369. return;
  370. }
  371. }
  372. this._checkHandlersProperty(obj);
  373. if (typeof type === "string"){
  374. event = { type: type };
  375. }
  376. else{
  377. event = type;
  378. }
  379. if (!event.target){
  380. event.target = obj;
  381. }
  382. if (!event.type){
  383. throw new Error("Event object missing 'type' property.");
  384. }
  385. if (obj.__eventHandlers[event.type] instanceof Array){
  386. listeners = obj.__eventHandlers[event.type];
  387. args.unshift(event);
  388. for (i=0, j=listeners.length; i<j; i++){
  389. listener = listeners[i];
  390. if (!Util.isNothing(listener)){
  391. listener.apply(obj, args);
  392. }
  393. }
  394. }
  395. },
  396. /*
  397. * Function: getMousePosition
  398. */
  399. getMousePosition: function(event){
  400. var retval = {
  401. x: 0,
  402. y: 0
  403. };
  404. if (event.pageX) {
  405. retval.x = event.pageX;
  406. }
  407. else if (event.clientX) {
  408. retval.x = event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft);
  409. }
  410. if (event.pageY) {
  411. retval.y = event.pageY;
  412. }
  413. else if (event.clientY) {
  414. retval.y = event.clientY + ( document.documentElement.scrollTop || document.body.scrollTop);
  415. }
  416. return retval;
  417. },
  418. /*
  419. * Function: getTouchEvent
  420. */
  421. getTouchEvent: function(event){
  422. return event;
  423. },
  424. /*
  425. * Function: getWheelDelta
  426. */
  427. getWheelDelta: function(event){
  428. var delta = 0;
  429. if (!Util.isNothing(event.wheelDelta)){
  430. delta = event.wheelDelta / 120;
  431. }
  432. else if (!Util.isNothing(event.detail)){
  433. delta = -event.detail / 3;
  434. }
  435. return delta;
  436. },
  437. /*
  438. * Function: domReady
  439. */
  440. domReady: function(handler){
  441. document.addEventListener('DOMContentLoaded', handler, false);
  442. },
  443. _checkHandlersProperty: function(obj){
  444. if (Util.isNothing(obj.__eventHandlers)){
  445. Util.extend(obj, {
  446. __eventHandlers: { }
  447. });
  448. }
  449. },
  450. _isBrowserObject: function(obj){
  451. if (obj === window || obj === window.document){
  452. return true;
  453. }
  454. return this._isElement(obj) || this._isNode(obj);
  455. },
  456. _isElement: function(obj){
  457. return (
  458. typeof window.HTMLElement === "object" ? obj instanceof window.HTMLElement : //DOM2
  459. typeof obj === "object" && obj.nodeType === 1 && typeof obj.nodeName==="string"
  460. );
  461. },
  462. _isNode: function(obj){
  463. return (
  464. typeof window.Node === "object" ? obj instanceof window.Node :
  465. typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName==="string"
  466. );
  467. },
  468. _normaliseMouseWheelType: function(){
  469. if (Util.Browser.isEventSupported('mousewheel')){
  470. return 'mousewheel';
  471. }
  472. return 'DOMMouseScroll';
  473. },
  474. _NATIVE_EVENTS: {
  475. click: 1, dblclick: 1, mouseup: 1, mousedown: 1, contextmenu: 1, //mouse buttons
  476. mousewheel: 1, DOMMouseScroll: 1, //mouse wheel
  477. mouseover: 1, mouseout: 1, mousemove: 1, selectstart: 1, selectend: 1, //mouse movement
  478. keydown: 1, keypress: 1, keyup: 1, //keyboard
  479. orientationchange: 1, // mobile
  480. touchstart: 1, touchmove: 1, touchend: 1, touchcancel: 1, // touch
  481. gesturestart: 1, gesturechange: 1, gestureend: 1, // gesture
  482. focus: 1, blur: 1, change: 1, reset: 1, select: 1, submit: 1, //form elements
  483. load: 1, unload: 1, beforeunload: 1, resize: 1, move: 1, DOMContentLoaded: 1, readystatechange: 1, //window
  484. error: 1, abort: 1, scroll: 1
  485. }
  486. }
  487. });
  488. }
  489. (
  490. window,
  491. window.Code.Util
  492. ));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com)
  493. // Licensed under the MIT license
  494. // version: 3.0.5
  495. (function (window, Util) {
  496. Util.extend(Util, {
  497. DOM: {
  498. /*
  499. * Function: setData
  500. */
  501. setData: function(el, key, value){
  502. if (Util.isLikeArray(el)){
  503. var i, len;
  504. for (i=0, len=el.length; i<len; i++){
  505. Util.DOM._setData(el[i], key, value);
  506. }
  507. }
  508. else{
  509. Util.DOM._setData(el, key, value);
  510. }
  511. },
  512. _setData: function(el, key, value){
  513. Util.DOM.setAttribute(el, 'data-' + key, value);
  514. },
  515. /*
  516. * Function: getData
  517. */
  518. getData: function(el, key, defaultValue){
  519. return Util.DOM.getAttribute(el, 'data-' + key, defaultValue);
  520. },
  521. /*
  522. * Function: removeData
  523. */
  524. removeData: function(el, key){
  525. if (Util.isLikeArray(el)){
  526. var i, len;
  527. for (i=0, len=el.length; i<len; i++){
  528. Util.DOM._removeData(el[i], key);
  529. }
  530. }
  531. else{
  532. Util.DOM._removeData(el, key);
  533. }
  534. },
  535. _removeData: function(el, key){
  536. Util.DOM.removeAttribute(el, 'data-' + key);
  537. },
  538. /*
  539. * Function: isChildOf
  540. */
  541. isChildOf: function(childEl, parentEl)
  542. {
  543. if (parentEl === childEl){
  544. return false;
  545. }
  546. while (childEl && childEl !== parentEl)
  547. {
  548. childEl = childEl.parentNode;
  549. }
  550. return childEl === parentEl;
  551. },
  552. /*
  553. * Function: find
  554. */
  555. find: function(selectors, contextEl){
  556. if (Util.isNothing(contextEl)){
  557. contextEl = window.document;
  558. }
  559. var
  560. els = contextEl.querySelectorAll(selectors),
  561. retval = [],
  562. i, j;
  563. for (i=0, j=els.length; i<j; i++){
  564. retval.push(els[i]);
  565. }
  566. return retval;
  567. },
  568. /*
  569. * Function: createElement
  570. */
  571. createElement: function(type, attributes, content){
  572. var
  573. attribute,
  574. retval = document.createElement(type);
  575. for(attribute in attributes) {
  576. if(Util.objectHasProperty(attributes, attribute)){
  577. retval.setAttribute(attribute, attributes[attribute]);
  578. }
  579. }
  580. retval.innerHTML = content || '';
  581. return retval;
  582. },
  583. /*
  584. * Function: appendChild
  585. */
  586. appendChild: function(childEl, parentEl){
  587. parentEl.appendChild(childEl);
  588. },
  589. /*
  590. * Function: insertBefore
  591. */
  592. insertBefore: function(newEl, refEl, parentEl){
  593. parentEl.insertBefore(newEl, refEl);
  594. },
  595. /*
  596. * Function: appendText
  597. */
  598. appendText: function(text, parentEl){
  599. Util.DOM.appendChild(document.createTextNode(text), parentEl);
  600. },
  601. /*
  602. * Function: appendToBody
  603. */
  604. appendToBody: function(childEl){
  605. this.appendChild(childEl, document.body);
  606. },
  607. /*
  608. * Function: removeChild
  609. */
  610. removeChild: function(childEl, parentEl){
  611. parentEl.removeChild(childEl);
  612. },
  613. /*
  614. * Function: removeChildren
  615. */
  616. removeChildren: function(parentEl){
  617. if (parentEl.hasChildNodes()){
  618. while (parentEl.childNodes.length >= 1){
  619. parentEl.removeChild(parentEl.childNodes[parentEl.childNodes.length -1]);
  620. }
  621. }
  622. },
  623. /*
  624. * Function: hasAttribute
  625. */
  626. hasAttribute: function(el, attributeName){
  627. return !Util.isNothing(el.getAttribute(attributeName));
  628. },
  629. /*
  630. * Function: getAttribute
  631. */
  632. getAttribute: function(el, attributeName, defaultValue){
  633. var retval = el.getAttribute(attributeName);
  634. if (Util.isNothing(retval) && !Util.isNothing(defaultValue)){
  635. retval = defaultValue;
  636. }
  637. return retval;
  638. },
  639. /*
  640. * Function: el, attributeName
  641. */
  642. setAttribute: function(el, attributeName, value){
  643. if (Util.isLikeArray(el)){
  644. var i, len;
  645. for (i=0, len=el.length; i<len; i++){
  646. Util.DOM._setAttribute(el[i], attributeName, value);
  647. }
  648. }
  649. else{
  650. Util.DOM._setAttribute(el, attributeName, value);
  651. }
  652. },
  653. _setAttribute: function(el, attributeName, value){
  654. el.setAttribute(attributeName, value);
  655. },
  656. /*
  657. * Function: removeAttribute
  658. */
  659. removeAttribute: function(el, attributeName){
  660. if (Util.isLikeArray(el)){
  661. var i, len;
  662. for (i=0, len=el.length; i<len; i++){
  663. Util.DOM._removeAttribute(el[i], attributeName);
  664. }
  665. }
  666. else{
  667. Util.DOM._removeAttribute(el, attributeName);
  668. }
  669. },
  670. _removeAttribute: function(el, attributeName){
  671. if (this.hasAttribute(el, attributeName)){
  672. el.removeAttribute(attributeName);
  673. }
  674. },
  675. /*
  676. * Function: addClass
  677. */
  678. addClass: function(el, className){
  679. if (Util.isLikeArray(el)){
  680. var i, len;
  681. for (i=0, len=el.length; i<len; i++){
  682. Util.DOM._addClass(el[i], className);
  683. }
  684. }
  685. else{
  686. Util.DOM._addClass(el, className);
  687. }
  688. },
  689. _addClass: function(el, className){
  690. var
  691. currentClassValue = Util.DOM.getAttribute(el, 'class', ''),
  692. re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
  693. if ( ! re.test(currentClassValue) ){
  694. if (currentClassValue !== ''){
  695. currentClassValue = currentClassValue + ' ';
  696. }
  697. currentClassValue = currentClassValue + className;
  698. Util.DOM.setAttribute(el, 'class', currentClassValue);
  699. }
  700. },
  701. /*
  702. * Function: removeClass
  703. */
  704. removeClass: function(el, className){
  705. if (Util.isLikeArray(el)){
  706. var i, len;
  707. for (i=0, len=el.length; i<len; i++){
  708. Util.DOM._removeClass(el[i], className);
  709. }
  710. }
  711. else{
  712. Util.DOM._removeClass(el, className);
  713. }
  714. },
  715. _removeClass: function(el, className){
  716. var
  717. currentClassValue = Util.DOM.getAttribute(el, 'class', ''),
  718. classes = Util.trim(currentClassValue).split(' '),
  719. newClassVal = '',
  720. i, j;
  721. for (i=0, j=classes.length; i<j; i++){
  722. if (classes[i] !== className){
  723. if (newClassVal !== ''){
  724. newClassVal += ' ';
  725. }
  726. newClassVal += classes[i];
  727. }
  728. }
  729. if (newClassVal === ''){
  730. Util.DOM.removeAttribute(el, 'class');
  731. }
  732. else{
  733. Util.DOM.setAttribute(el, 'class', newClassVal);
  734. }
  735. },
  736. /*
  737. * Function: hasClass
  738. */
  739. hasClass: function(el, className){
  740. var re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
  741. return re.test(Util.DOM.getAttribute(el, 'class', ''));
  742. },
  743. /*
  744. * Function: setStyle
  745. */
  746. setStyle: function(el, style, value){
  747. if (Util.isLikeArray(el)){
  748. var i, len;
  749. for (i=0, len=el.length; i<len; i++){
  750. Util.DOM._setStyle(el[i], style, value);
  751. }
  752. }
  753. else{
  754. Util.DOM._setStyle(el, style, value);
  755. }
  756. },
  757. _setStyle: function(el, style, value){
  758. var prop, val;
  759. if (Util.isObject(style)) {
  760. for(prop in style) {
  761. if(Util.objectHasProperty(style, prop)){
  762. if (prop === 'width'){
  763. Util.DOM.width(el, style[prop]);
  764. }
  765. else if (prop === 'height'){
  766. Util.DOM.height(el, style[prop]);
  767. }
  768. else{
  769. el.style[prop] = style[prop];
  770. }
  771. }
  772. }
  773. }
  774. else {
  775. el.style[style] = value;
  776. }
  777. },
  778. /*
  779. * Function: getStyle
  780. */
  781. getStyle: function(el, styleName){
  782. var retval = window.getComputedStyle(el,'').getPropertyValue(styleName);
  783. if (retval === ''){
  784. retval = el.style[styleName];
  785. }
  786. return retval;
  787. },
  788. /*
  789. * Function: hide
  790. */
  791. hide: function(el){
  792. if (Util.isLikeArray(el)){
  793. var i, len;
  794. for (i=0, len=el.length; i<len; i++){
  795. Util.DOM._hide(el[i]);
  796. }
  797. }
  798. else{
  799. Util.DOM._hide(el);
  800. }
  801. },
  802. _hide: function(el){
  803. // Store the current display value if we use show
  804. Util.DOM.setData(el, 'ccl-disp', Util.DOM.getStyle(el, 'display'));
  805. Util.DOM.setStyle(el, 'display', 'none');
  806. },
  807. /*
  808. * Function: show
  809. */
  810. show: function(el){
  811. if (Util.isLikeArray(el)){
  812. var i, len;
  813. for (i=0, len=el.length; i<len; i++){
  814. Util.DOM._show(el[i]);
  815. }
  816. }
  817. else{
  818. Util.DOM._show(el);
  819. }
  820. },
  821. _show: function(el){
  822. if (Util.DOM.getStyle(el, 'display') === 'none'){
  823. var oldDisplayValue = Util.DOM.getData(el, 'ccl-disp', 'block');
  824. if (oldDisplayValue === 'none' || oldDisplayValue === ''){
  825. oldDisplayValue = 'block';
  826. }
  827. Util.DOM.setStyle(el, 'display', oldDisplayValue);
  828. }
  829. },
  830. /*
  831. * Function: width
  832. * Content width, excludes padding
  833. */
  834. width: function(el, value){
  835. if (!Util.isNothing(value)){
  836. if (Util.isNumber(value)){
  837. value = value + 'px';
  838. }
  839. el.style.width = value;
  840. }
  841. return this._getDimension(el, 'width');
  842. },
  843. /*
  844. * Function: outerWidth
  845. */
  846. outerWidth: function(el){
  847. var retval = Util.DOM.width(el);
  848. retval += parseInt(Util.DOM.getStyle(el, 'padding-left'), 10) + parseInt(Util.DOM.getStyle(el, 'padding-right'), 10);
  849. retval += parseInt(Util.DOM.getStyle(el, 'margin-left'), 10) + parseInt(Util.DOM.getStyle(el, 'margin-right'), 10);
  850. retval += parseInt(Util.DOM.getStyle(el, 'border-left-width'), 10) + parseInt(Util.DOM.getStyle(el, 'border-right-width'), 10);
  851. return retval;
  852. },
  853. /*
  854. * Function: height
  855. * Content height, excludes padding
  856. */
  857. height: function(el, value){
  858. if (!Util.isNothing(value)){
  859. if (Util.isNumber(value)){
  860. value = value + 'px';
  861. }
  862. el.style.height = value;
  863. }
  864. return this._getDimension(el, 'height');
  865. },
  866. /*
  867. * Function: _getDimension
  868. */
  869. _getDimension: function(el, dimension){
  870. var
  871. retval = window.parseInt(window.getComputedStyle(el,'').getPropertyValue(dimension)),
  872. styleBackup;
  873. if (isNaN(retval)){
  874. // If this is the case, chances are the element is not displayed and we can't get
  875. // the width and height. This temporarily shows and hides to get the value
  876. styleBackup = {
  877. display: el.style.display,
  878. left: el.style.left
  879. };
  880. el.style.display = 'block';
  881. el.style.left = '-1000000px';
  882. retval = window.parseInt(window.getComputedStyle(el,'').getPropertyValue(dimension));
  883. el.style.display = styleBackup.display;
  884. el.style.left = styleBackup.left;
  885. }
  886. return retval;
  887. },
  888. /*
  889. * Function: outerHeight
  890. */
  891. outerHeight: function(el){
  892. var retval = Util.DOM.height(el);
  893. retval += parseInt(Util.DOM.getStyle(el, 'padding-top'), 10) + parseInt(Util.DOM.getStyle(el, 'padding-bottom'), 10);
  894. retval += parseInt(Util.DOM.getStyle(el, 'margin-top'), 10) + parseInt(Util.DOM.getStyle(el, 'margin-bottom'), 10);
  895. retval += parseInt(Util.DOM.getStyle(el, 'border-top-width'), 10) + parseInt(Util.DOM.getStyle(el, 'border-bottom-width'), 10);
  896. return retval;
  897. },
  898. /*
  899. * Function: documentWidth
  900. */
  901. documentWidth: function(){
  902. return Util.DOM.width(document.documentElement);
  903. },
  904. /*
  905. * Function: documentHeight
  906. */
  907. documentHeight: function(){
  908. return Util.DOM.height(document.documentElement);
  909. },
  910. /*
  911. * Function: documentOuterWidth
  912. */
  913. documentOuterWidth: function(){
  914. return Util.DOM.width(document.documentElement);
  915. },
  916. /*
  917. * Function: documentOuterHeight
  918. */
  919. documentOuterHeight: function(){
  920. return Util.DOM.outerHeight(document.documentElement);
  921. },
  922. /*
  923. * Function: bodyWidth
  924. */
  925. bodyWidth: function(){
  926. return Util.DOM.width(document.body);
  927. },
  928. /*
  929. * Function: bodyHeight
  930. */
  931. bodyHeight: function(){
  932. return Util.DOM.height(document.body);
  933. },
  934. /*
  935. * Function: bodyOuterWidth
  936. */
  937. bodyOuterWidth: function(){
  938. return Util.DOM.outerWidth(document.body);
  939. },
  940. /*
  941. * Function: bodyOuterHeight
  942. */
  943. bodyOuterHeight: function(){
  944. return Util.DOM.outerHeight(document.body);
  945. },
  946. /*
  947. * Function: windowWidth
  948. */
  949. windowWidth: function(){
  950. return window.innerWidth;
  951. },
  952. /*
  953. * Function: windowHeight
  954. */
  955. windowHeight: function(){
  956. return window.innerHeight;
  957. },
  958. /*
  959. * Function: windowScrollLeft
  960. */
  961. windowScrollLeft: function(){
  962. return window.pageXOffset;
  963. },
  964. /*
  965. * Function: windowScrollTop
  966. */
  967. windowScrollTop: function(){
  968. return window.pageYOffset;
  969. }
  970. }
  971. });
  972. }
  973. (
  974. window,
  975. window.Code.Util
  976. ));
  977. // Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com)
  978. // Licensed under the MIT license
  979. // version: 3.0.5
  980. (function (window, Util) {
  981. Util.extend(Util, {
  982. Animation: {
  983. _applyTransitionDelay: 50,
  984. _transitionEndLabel: (window.document.documentElement.style.webkitTransition !== undefined) ? "webkitTransitionEnd" : "transitionend",
  985. _transitionEndHandler: null,
  986. _transitionPrefix: (window.document.documentElement.style.webkitTransition !== undefined) ? "webkitTransition" : (window.document.documentElement.style.MozTransition !== undefined) ? "MozTransition" : "transition",
  987. _transformLabel: (window.document.documentElement.style.webkitTransform !== undefined) ? "webkitTransform" : (window.document.documentElement.style.MozTransition !== undefined) ? "MozTransform" : "transform",
  988. /*
  989. * Function: _getTransitionEndHandler
  990. */
  991. _getTransitionEndHandler: function(){
  992. if (Util.isNothing(this._transitionEndHandler)){
  993. this._transitionEndHandler = this._onTransitionEnd.bind(this);
  994. }
  995. return this._transitionEndHandler;
  996. },
  997. /*
  998. * Function: stop
  999. */
  1000. stop: function(el){
  1001. if (Util.Browser.isCSSTransformSupported){
  1002. var
  1003. property = el.style[this._transitionPrefix + 'Property'],
  1004. callbackLabel = (property !== '') ? 'ccl' + property + 'callback' : 'cclallcallback',
  1005. style = {};
  1006. Util.Events.remove(el, this._transitionEndLabel, this._getTransitionEndHandler());
  1007. if (Util.isNothing(el.callbackLabel)){
  1008. delete el.callbackLabel;
  1009. }
  1010. style[this._transitionPrefix + 'Property'] = '';
  1011. style[this._transitionPrefix + 'Duration'] = '';
  1012. style[this._transitionPrefix + 'TimingFunction'] = '';
  1013. style[this._transitionPrefix + 'Delay'] = '';
  1014. style[this._transformLabel] = '';
  1015. Util.DOM.setStyle(el, style);
  1016. }
  1017. else if (!Util.isNothing(window.jQuery)){
  1018. window.jQuery(el).stop(true, true);
  1019. }
  1020. },
  1021. /*
  1022. * Function: fadeIn
  1023. */
  1024. fadeIn: function(el, speed, callback, timingFunction, opacity){
  1025. opacity = Util.coalesce(opacity, 1);
  1026. if (opacity <= 0){
  1027. opacity = 1;
  1028. }
  1029. if (speed <= 0){
  1030. Util.DOM.setStyle(el, 'opacity', opacity);
  1031. if (!Util.isNothing(callback)){
  1032. callback(el);
  1033. return;
  1034. }
  1035. }
  1036. var currentOpacity = Util.DOM.getStyle(el, 'opacity');
  1037. if (currentOpacity >= 1){
  1038. Util.DOM.setStyle(el, 'opacity', 0);
  1039. }
  1040. if (Util.Browser.isCSSTransformSupported){
  1041. this._applyTransition(el, 'opacity', opacity, speed, callback, timingFunction);
  1042. }
  1043. else if (!Util.isNothing(window.jQuery)){
  1044. window.jQuery(el).fadeTo(speed, opacity, callback);
  1045. }
  1046. },
  1047. /*
  1048. * Function: fadeTo
  1049. */
  1050. fadeTo: function(el, opacity, speed, callback, timingFunction){
  1051. this.fadeIn(el, speed, callback, timingFunction, opacity);
  1052. },
  1053. /*
  1054. * Function: fadeOut
  1055. */
  1056. fadeOut: function(el, speed, callback, timingFunction){
  1057. if (speed <= 0){
  1058. Util.DOM.setStyle(el, 'opacity', 0);
  1059. if (!Util.isNothing(callback)){
  1060. callback(el);
  1061. return;
  1062. }
  1063. }
  1064. if (Util.Browser.isCSSTransformSupported){
  1065. this._applyTransition(el, 'opacity', 0, speed, callback, timingFunction);
  1066. }
  1067. else{
  1068. window.jQuery(el).fadeTo(speed, 0, callback);
  1069. }
  1070. },
  1071. /*
  1072. * Function: slideBy
  1073. */
  1074. slideBy: function(el, x, y, speed, callback, timingFunction){
  1075. var style = {};
  1076. x = Util.coalesce(x, 0);
  1077. y = Util.coalesce(y, 0);
  1078. timingFunction = Util.coalesce(timingFunction, 'ease-out');
  1079. style[this._transitionPrefix + 'Property'] = 'all';
  1080. style[this._transitionPrefix + 'Delay'] = '0';
  1081. if (speed === 0){
  1082. style[this._transitionPrefix + 'Duration'] = '';
  1083. style[this._transitionPrefix + 'TimingFunction'] = '';
  1084. }
  1085. else{
  1086. style[this._transitionPrefix + 'Duration'] = speed + 'ms';
  1087. style[this._transitionPrefix + 'TimingFunction'] = Util.coalesce(timingFunction, 'ease-out');
  1088. Util.Events.add(el, this._transitionEndLabel, this._getTransitionEndHandler());
  1089. }
  1090. style[this._transformLabel] = (Util.Browser.is3dSupported) ? 'translate3d(' + x + 'px, ' + y + 'px, 0px)' : 'translate(' + x + 'px, ' + y + 'px)';
  1091. if (!Util.isNothing(callback)){
  1092. el.cclallcallback = callback;
  1093. }
  1094. Util.DOM.setStyle(el, style);
  1095. if (speed === 0){
  1096. window.setTimeout(function(){
  1097. this._leaveTransforms(el);
  1098. }.bind(this), this._applyTransitionDelay);
  1099. }
  1100. },
  1101. /*
  1102. * Function:
  1103. */
  1104. resetTranslate: function(el){
  1105. var style = {};
  1106. style[this._transformLabel] = style[this._transformLabel] = (Util.Browser.is3dSupported) ? 'translate3d(0px, 0px, 0px)' : 'translate(0px, 0px)';
  1107. Util.DOM.setStyle(el, style);
  1108. },
  1109. /*
  1110. * Function: _applyTransition
  1111. */
  1112. _applyTransition: function(el, property, val, speed, callback, timingFunction){
  1113. var style = {};
  1114. timingFunction = Util.coalesce(timingFunction, 'ease-in');
  1115. style[this._transitionPrefix + 'Property'] = property;
  1116. style[this._transitionPrefix + 'Duration'] = speed + 'ms';
  1117. style[this._transitionPrefix + 'TimingFunction'] = timingFunction;
  1118. style[this._transitionPrefix + 'Delay'] = '0';
  1119. Util.Events.add(el, this._transitionEndLabel, this._getTransitionEndHandler());
  1120. Util.DOM.setStyle(el, style);
  1121. if (!Util.isNothing(callback)){
  1122. el['ccl' + property + 'callback'] = callback;
  1123. }
  1124. window.setTimeout(function(){
  1125. Util.DOM.setStyle(el, property, val);
  1126. }, this._applyTransitionDelay);
  1127. },
  1128. /*
  1129. * Function: _onTransitionEnd
  1130. */
  1131. _onTransitionEnd: function(e){
  1132. Util.Events.remove(e.currentTarget, this._transitionEndLabel, this._getTransitionEndHandler());
  1133. this._leaveTransforms(e.currentTarget);
  1134. },
  1135. /*
  1136. * Function: _leaveTransforms
  1137. */
  1138. _leaveTransforms: function(el){
  1139. var
  1140. property = el.style[this._transitionPrefix + 'Property'],
  1141. callbackLabel = (property !== '') ? 'ccl' + property + 'callback' : 'cclallcallback',
  1142. callback,
  1143. transform = Util.coalesce(el.style.webkitTransform, el.style.MozTransform, el.style.transform),
  1144. transformMatch,
  1145. transformExploded,
  1146. domX = window.parseInt(Util.DOM.getStyle(el, 'left'), 0),
  1147. domY = window.parseInt(Util.DOM.getStyle(el, 'top'), 0),
  1148. transformedX,
  1149. transformedY,
  1150. style = {};
  1151. if (transform !== ''){
  1152. if (Util.Browser.is3dSupported){
  1153. transformMatch = transform.match( /translate3d\((.*?)\)/ );
  1154. }
  1155. else{
  1156. transformMatch = transform.match( /translate\((.*?)\)/ );
  1157. }
  1158. if (!Util.isNothing(transformMatch)){
  1159. transformExploded = transformMatch[1].split(', ');
  1160. transformedX = window.parseInt(transformExploded[0], 0);
  1161. transformedY = window.parseInt(transformExploded[1], 0);
  1162. }
  1163. }
  1164. style[this._transitionPrefix + 'Property'] = '';
  1165. style[this._transitionPrefix + 'Duration'] = '';
  1166. style[this._transitionPrefix + 'TimingFunction'] = '';
  1167. style[this._transitionPrefix + 'Delay'] = '';
  1168. Util.DOM.setStyle(el, style);
  1169. window.setTimeout(function(){
  1170. if(!Util.isNothing(transformExploded)){
  1171. style = {};
  1172. style[this._transformLabel] = '';
  1173. style.left = (domX + transformedX) + 'px';
  1174. style.top = (domY + transformedY) + 'px';
  1175. Util.DOM.setStyle(el, style);
  1176. }
  1177. if (!Util.isNothing(el[callbackLabel])){
  1178. callback = el[callbackLabel];
  1179. delete el[callbackLabel];
  1180. callback(el);
  1181. }
  1182. }.bind(this), this._applyTransitionDelay);
  1183. }
  1184. }
  1185. });
  1186. }
  1187. (
  1188. window,
  1189. window.Code.Util
  1190. ));
  1191. // Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com)
  1192. // Licensed under the MIT license
  1193. // version: 3.0.5
  1194. (function(window, klass, Util){
  1195. Util.registerNamespace('Code.Util.TouchElement');
  1196. Util.TouchElement.EventTypes = {
  1197. onTouch: 'CodeUtilTouchElementOnTouch'
  1198. };
  1199. Util.TouchElement.ActionTypes = {
  1200. touchStart: 'touchStart',
  1201. touchMove: 'touchMove',
  1202. touchEnd: 'touchEnd',
  1203. touchMoveEnd: 'touchMoveEnd',
  1204. tap: 'tap',
  1205. doubleTap: 'doubleTap',
  1206. swipeLeft: 'swipeLeft',
  1207. swipeRight: 'swipeRight',
  1208. swipeUp: 'swipeUp',
  1209. swipeDown: 'swipeDown',
  1210. gestureStart: 'gestureStart',
  1211. gestureChange: 'gestureChange',
  1212. gestureEnd: 'gestureEnd'
  1213. };
  1214. }
  1215. (
  1216. window,
  1217. window.klass,
  1218. window.Code.Util
  1219. ));// Copyright (c) 2012 by Code Computerlove (http://www.codecomputerlove.com)
  1220. // Licensed under the MIT license
  1221. // version: 3.0.5
  1222. (function(window, klass, Util){
  1223. Util.registerNamespace('Code.Util.TouchElement');
  1224. Util.TouchElement.TouchElementClass = klass({
  1225. el: null,
  1226. captureSettings: null,
  1227. touchStartPoint: null,
  1228. touchEndPoint: null,
  1229. touchStartTime: null,
  1230. doubleTapTimeout: null,
  1231. touchStartHandler: null,
  1232. touchMoveHandler: null,
  1233. touchEndHandler: null,
  1234. mouseDownHandler: null,
  1235. mouseMoveHandler: null,
  1236. mouseUpHandler: null,
  1237. mouseOutHandler: null,
  1238. gestureStartHandler: null,
  1239. gestureChangeHandler: null,
  1240. gestureEndHandler: null,
  1241. swipeThreshold: null,
  1242. swipeTimeThreshold: null,
  1243. doubleTapSpeed: null,
  1244. /*
  1245. * Function: dispose
  1246. */
  1247. dispose: function(){
  1248. var prop;
  1249. this.removeEventHandlers();
  1250. for (prop in this) {
  1251. if (Util.objectHasProperty(this, prop)) {
  1252. this[prop] = null;
  1253. }
  1254. }
  1255. },
  1256. /*
  1257. * Function: initialize
  1258. */
  1259. initialize: function(el, captureSettings){
  1260. this.el = el;
  1261. this.captureSettings = {
  1262. swipe: false,
  1263. move: false,
  1264. gesture: false,
  1265. doubleTap: false,
  1266. preventDefaultTouchEvents: true
  1267. };
  1268. Util.extend(this.captureSettings, captureSettings);
  1269. this.swipeThreshold = 50;
  1270. this.swipeTimeThreshold = 250;
  1271. this.doubleTapSpeed = 250;
  1272. this.touchStartPoint = { x: 0, y: 0 };
  1273. this.touchEndPoint = { x: 0, y: 0 };
  1274. },
  1275. /*
  1276. * Function: addEventHandlers
  1277. */
  1278. addEventHandlers: function(){
  1279. if (Util.isNothing(this.touchStartHandler)){
  1280. this.touchStartHandler = this.onTouchStart.bind(this);
  1281. this.touchMoveHandler = this.onTouchMove.bind(this);
  1282. this.touchEndHandler = this.onTouchEnd.bind(this);
  1283. this.mouseDownHandler = this.onMouseDown.bind(this);
  1284. this.mouseMoveHandler = this.onMouseMove.bind(this);
  1285. this.mouseUpHandler = this.onMouseUp.bind(this);
  1286. this.mouseOutHandler = this.onMouseOut.bind(this);
  1287. this.gestureStartHandler = this.onGestureStart.bind(this);
  1288. this.gestureChangeHandler = this.onGestureChange.bind(this);
  1289. this.gestureEndHandler = this.onGestureEnd.bind(this);
  1290. }
  1291. Util.Events.add(this.el, 'touchstart', this.touchStartHandler);
  1292. if (this.captureSettings.move){
  1293. Util.Events.add(this.el, 'touchmove', this.touchMoveHandler);
  1294. }
  1295. Util.Events.add(this.el, 'touchend', this.touchEndHandler);
  1296. Util.Events.add(this.el, 'mousedown', this.mouseDownHandler);
  1297. if (Util.Browser.isGestureSupported && this.captureSettings.gesture){
  1298. Util.Events.add(this.el, 'gesturestart', this.gestureStartHandler);
  1299. Util.Events.add(this.el, 'gesturechange', this.gestureChangeHandler);
  1300. Util.Events.add(this.el, 'gestureend', this.gestureEndHandler);
  1301. }
  1302. },
  1303. /*
  1304. * Function: removeEventHandlers
  1305. */
  1306. removeEventHandlers: function(){
  1307. Util.Events.remove(this.el, 'touchstart', this.touchStartHandler);
  1308. if (this.captureSettings.move){
  1309. Util.Events.remove(this.el, 'touchmove', this.touchMoveHandler);
  1310. }
  1311. Util.Events.remove(this.el, 'touchend', this.touchEndHandler);
  1312. Util.Events.remove(this.el, 'mousedown', this.mouseDownHandler);
  1313. if (Util.Browser.isGestureSupported && this.captureSettings.gesture){
  1314. Util.Events.remove(this.el, 'gesturestart', this.gestureStartHandler);
  1315. Util.Events.remove(this.el, 'gesturechange', this.gestureChangeHandler);
  1316. Util.Events.remove(this.el, 'gestureend', this.gestureEndHandler);
  1317. }
  1318. },
  1319. /*
  1320. * Function: getTouchPoint
  1321. */
  1322. getTouchPoint: function(touches){
  1323. return {
  1324. x: touches[0].pageX,
  1325. y: touches[0].pageY
  1326. };
  1327. },
  1328. /*
  1329. * Function: fireTouchEvent
  1330. */
  1331. fireTouchEvent: function(e){
  1332. var
  1333. action,
  1334. distX = 0,
  1335. distY = 0,
  1336. dist = 0,
  1337. self,
  1338. endTime,
  1339. diffTime;
  1340. distX = this.touchEndPoint.x - this.touchStartPoint.x;
  1341. distY = this.touchEndPoint.y - this.touchStartPoint.y;
  1342. dist = Math.sqrt( (distX * distX) + (distY * distY) );
  1343. if (this.captureSettings.swipe){
  1344. endTime = new Date();
  1345. diffTime = endTime - this.touchStartTime;
  1346. // See if there was a swipe gesture
  1347. if (diffTime <= this.swipeTimeThreshold){
  1348. if (window.Math.abs(distX) >= this.swipeThreshold){
  1349. Util.Events.fire(this, {
  1350. type: Util.TouchElement.EventTypes.onTouch,
  1351. target: this,
  1352. point: this.touchEndPoint,
  1353. action: (distX < 0) ? Util.TouchElement.ActionTypes.swipeLeft : Util.TouchElement.ActionTypes.swipeRight,
  1354. targetEl: e.target,
  1355. currentTargetEl: e.currentTarget
  1356. });
  1357. return;
  1358. }
  1359. if (window.Math.abs(distY) >= this.swipeThreshold){
  1360. Util.Events.fire(this, {
  1361. type: Util.TouchElement.EventTypes.onTouch,
  1362. target: this,
  1363. point: this.touchEndPoint,
  1364. action: (distY < 0) ? Util.TouchElement.ActionTypes.swipeUp : Util.TouchElement.ActionTypes.swipeDown,
  1365. targetEl: e.target,
  1366. currentTargetEl: e.currentTarget
  1367. });
  1368. return;
  1369. }
  1370. }
  1371. }
  1372. if (dist > 1){
  1373. Util.Events.fire(this, {
  1374. type: Util.TouchElement.EventTypes.onTouch,
  1375. target: this,
  1376. action: Util.TouchElement.ActionTypes.touchMoveEnd,
  1377. point: this.touchEndPoint,
  1378. targetEl: e.target,
  1379. currentTargetEl: e.currentTarget
  1380. });
  1381. return;
  1382. }
  1383. if (!this.captureSettings.doubleTap){
  1384. Util.Events.fire(this, {
  1385. type: Util.TouchElement.EventTypes.onTouch,
  1386. target: this,
  1387. point: this.touchEndPoint,
  1388. action: Util.TouchElement.ActionTypes.tap,
  1389. targetEl: e.target,
  1390. currentTargetEl: e.currentTarget
  1391. });
  1392. return;
  1393. }
  1394. if (Util.isNothing(this.doubleTapTimeout)){
  1395. this.doubleTapTimeout = window.setTimeout(function(){
  1396. this.doubleTapTimeout = null;
  1397. Util.Events.fire(this, {
  1398. type: Util.TouchElement.EventTypes.onTouch,
  1399. target: this,
  1400. point: this.touchEndPoint,
  1401. action: Util.TouchElement.ActionTypes.tap,
  1402. targetEl: e.target,
  1403. currentTargetEl: e.currentTarget
  1404. });
  1405. }.bind(this), this.doubleTapSpeed);
  1406. return;
  1407. }
  1408. else{
  1409. window.clearTimeout(this.doubleTapTimeout);
  1410. this.doubleTapTimeout = null;
  1411. Util.Events.fire(this, {
  1412. type: Util.TouchElement.EventTypes.onTouch,
  1413. target: this,
  1414. point: this.touchEndPoint,
  1415. action: Util.TouchElement.ActionTypes.doubleTap,
  1416. targetEl: e.target,
  1417. currentTargetEl: e.currentTarget
  1418. });
  1419. }
  1420. },
  1421. /*
  1422. * Function: onTouchStart
  1423. */
  1424. onTouchStart: function(e){
  1425. if (this.captureSettings.preventDefaultTouchEvents){
  1426. e.preventDefault();
  1427. }
  1428. // No longer need mouse events
  1429. Util.Events.remove(this.el, 'mousedown', this.mouseDownHandler);
  1430. var
  1431. touchEvent = Util.Events.getTouchEvent(e),
  1432. touches = touchEvent.touches;
  1433. if (touches.length > 1 && this.captureSettings.gesture){
  1434. this.isGesture = true;
  1435. return;
  1436. }
  1437. this.touchStartTime = new Date();
  1438. this.isGesture = false;
  1439. this.touchStartPoint = this.getTouchPoint(touches);
  1440. Util.Events.fire(this, {
  1441. type: Util.TouchElement.EventTypes.onTouch,
  1442. target: this,
  1443. action: Util.TouchElement.ActionTypes.touchStart,
  1444. point: this.touchStartPoint,
  1445. targetEl: e.target,
  1446. currentTargetEl: e.currentTarget
  1447. });
  1448. },
  1449. /*
  1450. * Function: onTouchMove
  1451. */
  1452. onTouchMove: function(e){
  1453. if (this.captureSettings.preventDefaultTouchEvents){
  1454. e.preventDefault();
  1455. }
  1456. if (this.isGesture && this.captureSettings.gesture){
  1457. return;
  1458. }
  1459. var
  1460. touchEvent = Util.Events.getTouchEvent(e),
  1461. touches = touchEvent.touches;
  1462. Util.Events.fire(this, {
  1463. type: Util.TouchElement.EventTypes.onTouch,
  1464. target: this,
  1465. action: Util.TouchElement.ActionTypes.touchMove,
  1466. point: this.getTouchPoint(touches),
  1467. targetEl: e.target,
  1468. currentTargetEl: e.currentTarget
  1469. });
  1470. },
  1471. /*
  1472. * Function: onTouchEnd
  1473. */
  1474. onTouchEnd: function(e){
  1475. if (this.isGesture && this.captureSettings.gesture){
  1476. return;
  1477. }
  1478. if (this.captureSettings.preventDefaultTouchEvents){
  1479. e.preventDefault();
  1480. }
  1481. // http://backtothecode.blogspot.com/2009/10/javascript-touch-and-gesture-events.html
  1482. // iOS removed the current touch from e.touches on "touchend"
  1483. // Need to look into e.changedTouches
  1484. var
  1485. touchEvent = Util.Events.getTouchEvent(e),
  1486. touches = (!Util.isNothing(touchEvent.changedTouches)) ? touchEvent.changedTouches : touchEvent.touches;
  1487. this.touchEndPoint = this.getTouchPoint(touches);
  1488. Util.Events.fire(this, {
  1489. type: Util.TouchElement.EventTypes.onTouch,
  1490. target: this,
  1491. action: Util.TouchElement.ActionTypes.touchEnd,
  1492. point: this.touchEndPoint,
  1493. targetEl: e.target,
  1494. currentTargetEl: e.currentTarget
  1495. });
  1496. this.fireTouchEvent(e);
  1497. },
  1498. /*
  1499. * Function: onMouseDown
  1500. */
  1501. onMouseDown: function(e){
  1502. e.preventDefault();
  1503. // No longer need touch events
  1504. Util.Events.remove(this.el, 'touchstart', this.mouseDownHandler);
  1505. Util.Events.remove(this.el, 'touchmove', this.touchMoveHandler);
  1506. Util.Events.remove(this.el, 'touchend', this.touchEndHandler);
  1507. // Add move/up/out
  1508. if (this.captureSettings.move){
  1509. Util.Events.add(this.el, 'mousemove', this.mouseMoveHandler);
  1510. }
  1511. Util.Events.add(this.el, 'mouseup', this.mouseUpHandler);
  1512. Util.Events.add(this.el, 'mouseout', this.mouseOutHandler);
  1513. this.touchStartTime = new Date();
  1514. this.isGesture = false;
  1515. this.touchStartPoint = Util.Events.getMousePosition(e);
  1516. Util.Events.fire(this, {
  1517. type: Util.TouchElement.EventTypes.onTouch,
  1518. target: this,
  1519. action: Util.TouchElement.ActionTypes.touchStart,
  1520. point: this.touchStartPoint,
  1521. targetEl: e.target,
  1522. currentTargetEl: e.currentTarget
  1523. });
  1524. },
  1525. /*
  1526. * Function: onMouseMove
  1527. */
  1528. onMouseMove: function(e){
  1529. e.preventDefault();
  1530. Util.Events.fire(this, {
  1531. type: Util.TouchElement.EventTypes.onTouch,
  1532. target: this,
  1533. action: Util.TouchElement.ActionTypes.touchMove,
  1534. point: Util.Events.getMousePosition(e),
  1535. targetEl: e.target,
  1536. currentTargetEl: e.currentTarget
  1537. });
  1538. },
  1539. /*
  1540. * Function: onMouseUp
  1541. */
  1542. onMouseUp: function(e){
  1543. e.preventDefault();
  1544. if (this.captureSettings.move){
  1545. Util.Events.remove(this.el, 'mousemove', this.mouseMoveHandler);
  1546. }
  1547. Util.Events.remove(this.el, 'mouseup', this.mouseUpHandler);
  1548. Util.Events.remove(this.el, 'mouseout', this.mouseOutHandler);
  1549. this.touchEndPoint = Util.Events.getMousePosition(e);
  1550. Util.Events.fire(this, {
  1551. type: Util.TouchElement.EventTypes.onTouch,
  1552. target: this,
  1553. action: Util.TouchElement.ActionTypes.touchEnd,
  1554. point: this.touchEndPoint,
  1555. targetEl: e.target,
  1556. currentTargetEl: e.currentTarget
  1557. });
  1558. this.fireTouchEvent(e);
  1559. },
  1560. /*
  1561. * Function: onMouseOut
  1562. */
  1563. onMouseOut: function(e){
  1564. /*
  1565. * http://blog.stchur.com/2007/03/15/mouseenter-and-mouseleave-events-for-firefox-and-other-non-ie-browsers/
  1566. */
  1567. var relTarget = e.relatedTarget;
  1568. if (this.el === relTarget || Util.DOM.isChildOf(relTarget, this.el)){
  1569. return;
  1570. }
  1571. e.preventDefault();
  1572. if (this.captureSettings.move){
  1573. Util.Events.remove(this.el, 'mousemove', this.mouseMoveHandler);
  1574. }
  1575. Util.Events.remove(this.el, 'mouseup', this.mouseUpHandler);
  1576. Util.Events.remove(this.el, 'mouseout', this.mouseOutHandler);
  1577. this.touchEndPoint = Util.Events.getMousePosition(e);
  1578. Util.Events.fire(this, {
  1579. type: Util.TouchElement.EventTypes.onTouch,
  1580. target: this,
  1581. action: Util.TouchElement.ActionTypes.touchEnd,
  1582. point: this.touchEndPoint,
  1583. targetEl: e.target,
  1584. currentTargetEl: e.currentTarget
  1585. });
  1586. this.fireTouchEvent(e);
  1587. },