PageRenderTime 60ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/files/quojs/2.3.1/quo.debug.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1248 lines | 1223 code | 22 blank | 3 comment | 239 complexity | 00552869884bf29c648f9d609af929d0 MD5 | raw file
  1. /* QuoJS v2.3.1 - 2/4/2013
  2. http://quojs.tapquo.com
  3. Copyright (c) 2013 Javi Jimenez Villar (@soyjavi) - Licensed MIT */
  4. var Quo;
  5. Quo = (function() {
  6. var $$, EMPTY_ARRAY, Q;
  7. EMPTY_ARRAY = [];
  8. $$ = function(selector, children) {
  9. var dom;
  10. if (!selector) {
  11. return Q();
  12. } else if ($$.toType(selector) === "function") {
  13. return $$(document).ready(selector);
  14. } else {
  15. dom = $$.getDOMObject(selector, children);
  16. return Q(dom, selector);
  17. }
  18. };
  19. Q = function(dom, selector) {
  20. dom = dom || EMPTY_ARRAY;
  21. dom.__proto__ = Q.prototype;
  22. dom.selector = selector || '';
  23. return dom;
  24. };
  25. $$.extend = function(target) {
  26. Array.prototype.slice.call(arguments, 1).forEach(function(source) {
  27. var key, _results;
  28. _results = [];
  29. for (key in source) {
  30. _results.push(target[key] = source[key]);
  31. }
  32. return _results;
  33. });
  34. return target;
  35. };
  36. Q.prototype = $$.fn = {};
  37. return $$;
  38. })();
  39. window.Quo = Quo;
  40. "$$" in window || (window.$$ = Quo);
  41. (function($$) {
  42. var EMPTY_ARRAY, HTML_CONTAINERS, IS_HTML_FRAGMENT, OBJECT_PROTOTYPE, TABLE, TABLE_ROW, _compact, _flatten;
  43. EMPTY_ARRAY = [];
  44. OBJECT_PROTOTYPE = Object.prototype;
  45. IS_HTML_FRAGMENT = /^\s*<(\w+|!)[^>]*>/;
  46. TABLE = document.createElement('table');
  47. TABLE_ROW = document.createElement('tr');
  48. HTML_CONTAINERS = {
  49. "tr": document.createElement("tbody"),
  50. "tbody": TABLE,
  51. "thead": TABLE,
  52. "tfoot": TABLE,
  53. "td": TABLE_ROW,
  54. "th": TABLE_ROW,
  55. "*": document.createElement("div")
  56. };
  57. $$.toType = function(obj) {
  58. return OBJECT_PROTOTYPE.toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
  59. };
  60. $$.isOwnProperty = function(object, property) {
  61. return OBJECT_PROTOTYPE.hasOwnProperty.call(object, property);
  62. };
  63. $$.getDOMObject = function(selector, children) {
  64. var domain, elementTypes, type;
  65. domain = null;
  66. elementTypes = [1, 9, 11];
  67. type = $$.toType(selector);
  68. if (type === "array") {
  69. domain = _compact(selector);
  70. } else if (type === "string" && IS_HTML_FRAGMENT.test(selector)) {
  71. domain = $$.fragment(selector.trim(), RegExp.$1);
  72. selector = null;
  73. } else if (type === "string") {
  74. domain = $$.query(document, selector);
  75. if (children) {
  76. if (domain.length === 1) {
  77. domain = $$.query(domain[0], children);
  78. } else {
  79. domain = $$.map(function() {
  80. return $$.query(domain, children);
  81. });
  82. }
  83. }
  84. } else if (elementTypes.indexOf(selector.nodeType) >= 0 || selector === window) {
  85. domain = [selector];
  86. selector = null;
  87. }
  88. return domain;
  89. };
  90. $$.map = function(elements, callback) {
  91. var i, key, value, values;
  92. values = [];
  93. i = void 0;
  94. key = void 0;
  95. if ($$.toType(elements) === "array") {
  96. i = 0;
  97. while (i < elements.length) {
  98. value = callback(elements[i], i);
  99. if (value != null) {
  100. values.push(value);
  101. }
  102. i++;
  103. }
  104. } else {
  105. for (key in elements) {
  106. value = callback(elements[key], key);
  107. if (value != null) {
  108. values.push(value);
  109. }
  110. }
  111. }
  112. return _flatten(values);
  113. };
  114. $$.each = function(elements, callback) {
  115. var i, key;
  116. i = void 0;
  117. key = void 0;
  118. if ($$.toType(elements) === "array") {
  119. i = 0;
  120. while (i < elements.length) {
  121. if (callback.call(elements[i], i, elements[i]) === false) {
  122. return elements;
  123. }
  124. i++;
  125. }
  126. } else {
  127. for (key in elements) {
  128. if (callback.call(elements[key], key, elements[key]) === false) {
  129. return elements;
  130. }
  131. }
  132. }
  133. return elements;
  134. };
  135. $$.mix = function() {
  136. var arg, argument, child, len, prop;
  137. child = {};
  138. arg = 0;
  139. len = arguments.length;
  140. while (arg < len) {
  141. argument = arguments[arg];
  142. for (prop in argument) {
  143. if ($$.isOwnProperty(argument, prop) && argument[prop] !== undefined) {
  144. child[prop] = argument[prop];
  145. }
  146. }
  147. arg++;
  148. }
  149. return child;
  150. };
  151. $$.fragment = function(markup, tag) {
  152. var container;
  153. if (tag == null) {
  154. tag = "*";
  155. }
  156. if (!(tag in HTML_CONTAINERS)) {
  157. tag = "*";
  158. }
  159. container = HTML_CONTAINERS[tag];
  160. container.innerHTML = "" + markup;
  161. return $$.each(Array.prototype.slice.call(container.childNodes), function() {
  162. return container.removeChild(this);
  163. });
  164. };
  165. $$.fn.map = function(fn) {
  166. return $$.map(this, function(el, i) {
  167. return fn.call(el, i, el);
  168. });
  169. };
  170. $$.fn.instance = function(property) {
  171. return this.map(function() {
  172. return this[property];
  173. });
  174. };
  175. $$.fn.filter = function(selector) {
  176. return $$([].filter.call(this, function(element) {
  177. return element.parentNode && $$.query(element.parentNode, selector).indexOf(element) >= 0;
  178. }));
  179. };
  180. $$.fn.forEach = EMPTY_ARRAY.forEach;
  181. $$.fn.indexOf = EMPTY_ARRAY.indexOf;
  182. _compact = function(array) {
  183. return array.filter(function(item) {
  184. return item !== void 0 && item !== null;
  185. });
  186. };
  187. return _flatten = function(array) {
  188. if (array.length > 0) {
  189. return [].concat.apply([], array);
  190. } else {
  191. return array;
  192. }
  193. };
  194. })(Quo);
  195. (function($$) {
  196. var IS_WEBKIT, SUPPORTED_OS, _current, _detectBrowser, _detectEnvironment, _detectOS, _detectScreen;
  197. _current = null;
  198. IS_WEBKIT = /WebKit\/([\d.]+)/;
  199. SUPPORTED_OS = {
  200. Android: /(Android)\s+([\d.]+)/,
  201. ipad: /(iPad).*OS\s([\d_]+)/,
  202. iphone: /(iPhone\sOS)\s([\d_]+)/,
  203. Blackberry: /(BlackBerry|BB10|Playbook).*Version\/([\d.]+)/,
  204. FirefoxOS: /(Mozilla).*Mobile[^\/]*\/([\d\.]*)/,
  205. webOS: /(webOS|hpwOS)[\s\/]([\d.]+)/
  206. };
  207. $$.isMobile = function() {
  208. _current = _current || _detectEnvironment();
  209. return _current.isMobile && _current.os.name !== "firefoxOS";
  210. };
  211. $$.environment = function() {
  212. _current = _current || _detectEnvironment();
  213. return _current;
  214. };
  215. $$.isOnline = function() {
  216. return navigator.onLine;
  217. };
  218. _detectEnvironment = function() {
  219. var environment, user_agent;
  220. user_agent = navigator.userAgent;
  221. environment = {};
  222. environment.browser = _detectBrowser(user_agent);
  223. environment.os = _detectOS(user_agent);
  224. environment.isMobile = !!environment.os;
  225. environment.screen = _detectScreen();
  226. return environment;
  227. };
  228. _detectBrowser = function(user_agent) {
  229. var is_webkit;
  230. is_webkit = user_agent.match(IS_WEBKIT);
  231. if (is_webkit) {
  232. return is_webkit[0];
  233. } else {
  234. return user_agent;
  235. }
  236. };
  237. _detectOS = function(user_agent) {
  238. var detected_os, os, supported;
  239. detected_os = null;
  240. for (os in SUPPORTED_OS) {
  241. supported = user_agent.match(SUPPORTED_OS[os]);
  242. if (supported) {
  243. detected_os = {
  244. name: (os === "iphone" || os === "ipad" ? "ios" : os),
  245. version: supported[2].replace("_", ".")
  246. };
  247. break;
  248. }
  249. }
  250. return detected_os;
  251. };
  252. return _detectScreen = function() {
  253. return {
  254. width: window.innerWidth,
  255. height: window.innerHeight
  256. };
  257. };
  258. })(Quo);
  259. (function($$) {
  260. var CLASS_SELECTOR, ID_SELECTOR, PARENT_NODE, TAG_SELECTOR, _filtered, _findAncestors;
  261. PARENT_NODE = "parentNode";
  262. CLASS_SELECTOR = /^\.([\w-]+)$/;
  263. ID_SELECTOR = /^#[\w\d-]+$/;
  264. TAG_SELECTOR = /^[\w-]+$/;
  265. $$.query = function(domain, selector) {
  266. var elements;
  267. selector = selector.trim();
  268. if (CLASS_SELECTOR.test(selector)) {
  269. elements = domain.getElementsByClassName(selector.replace(".", ""));
  270. } else if (TAG_SELECTOR.test(selector)) {
  271. elements = domain.getElementsByTagName(selector);
  272. } else if (ID_SELECTOR.test(selector) && domain === document) {
  273. elements = domain.getElementById(selector.replace("#", ""));
  274. if (!elements) {
  275. elements = [];
  276. }
  277. } else {
  278. elements = domain.querySelectorAll(selector);
  279. }
  280. if (elements.nodeType) {
  281. return [elements];
  282. } else {
  283. return Array.prototype.slice.call(elements);
  284. }
  285. };
  286. $$.fn.find = function(selector) {
  287. var result;
  288. if (this.length === 1) {
  289. result = Quo.query(this[0], selector);
  290. } else {
  291. result = this.map(function() {
  292. return Quo.query(this, selector);
  293. });
  294. }
  295. return $$(result);
  296. };
  297. $$.fn.parent = function(selector) {
  298. var ancestors;
  299. ancestors = (selector ? _findAncestors(this) : this.instance(PARENT_NODE));
  300. return _filtered(ancestors, selector);
  301. };
  302. $$.fn.siblings = function(selector) {
  303. var siblings_elements;
  304. siblings_elements = this.map(function(index, element) {
  305. return Array.prototype.slice.call(element.parentNode.children).filter(function(child) {
  306. return child !== element;
  307. });
  308. });
  309. return _filtered(siblings_elements, selector);
  310. };
  311. $$.fn.children = function(selector) {
  312. var children_elements;
  313. children_elements = this.map(function() {
  314. return Array.prototype.slice.call(this.children);
  315. });
  316. return _filtered(children_elements, selector);
  317. };
  318. $$.fn.get = function(index) {
  319. if (index === undefined) {
  320. return this;
  321. } else {
  322. return this[index];
  323. }
  324. };
  325. $$.fn.first = function() {
  326. return $$(this[0]);
  327. };
  328. $$.fn.last = function() {
  329. return $$(this[this.length - 1]);
  330. };
  331. $$.fn.closest = function(selector, context) {
  332. var candidates, node;
  333. node = this[0];
  334. candidates = $$(selector);
  335. if (!candidates.length) {
  336. node = null;
  337. }
  338. while (node && candidates.indexOf(node) < 0) {
  339. node = node !== context && node !== document && node.parentNode;
  340. }
  341. return $$(node);
  342. };
  343. $$.fn.each = function(callback) {
  344. this.forEach(function(element, index) {
  345. return callback.call(element, index, element);
  346. });
  347. return this;
  348. };
  349. _findAncestors = function(nodes) {
  350. var ancestors;
  351. ancestors = [];
  352. while (nodes.length > 0) {
  353. nodes = $$.map(nodes, function(node) {
  354. if ((node = node.parentNode) && node !== document && ancestors.indexOf(node) < 0) {
  355. ancestors.push(node);
  356. return node;
  357. }
  358. });
  359. }
  360. return ancestors;
  361. };
  362. return _filtered = function(nodes, selector) {
  363. if (selector === undefined) {
  364. return $$(nodes);
  365. } else {
  366. return $$(nodes).filter(selector);
  367. }
  368. };
  369. })(Quo);
  370. (function($$) {
  371. var VENDORS, _computedStyle, _existsClass;
  372. VENDORS = ["-webkit-", "-moz-", "-ms-", "-o-", ""];
  373. $$.fn.addClass = function(name) {
  374. return this.each(function() {
  375. if (!_existsClass(name, this.className)) {
  376. this.className += " " + name;
  377. return this.className = this.className.trim();
  378. }
  379. });
  380. };
  381. $$.fn.removeClass = function(name) {
  382. return this.each(function() {
  383. if (!name) {
  384. return this.className = "";
  385. } else {
  386. if (_existsClass(name, this.className)) {
  387. return this.className = this.className.replace(name, " ").replace(/\s+/g, " ").trim();
  388. }
  389. }
  390. });
  391. };
  392. $$.fn.toggleClass = function(name) {
  393. return this.each(function() {
  394. if (_existsClass(name, this.className)) {
  395. return this.className = this.className.replace(name, " ");
  396. } else {
  397. this.className += " " + name;
  398. return this.className = this.className.trim();
  399. }
  400. });
  401. };
  402. $$.fn.hasClass = function(name) {
  403. return _existsClass(name, this[0].className);
  404. };
  405. $$.fn.style = function(property, value) {
  406. if (value) {
  407. return this.each(function() {
  408. return this.style[property] = value;
  409. });
  410. } else {
  411. return this[0].style[property] || _computedStyle(this[0], property);
  412. }
  413. };
  414. $$.fn.css = function(property, value) {
  415. return this.style(property, value);
  416. };
  417. $$.fn.vendor = function(property, value) {
  418. var vendor, _i, _len, _results;
  419. _results = [];
  420. for (_i = 0, _len = VENDORS.length; _i < _len; _i++) {
  421. vendor = VENDORS[_i];
  422. _results.push(this.style("" + vendor + property, value));
  423. }
  424. return _results;
  425. };
  426. _existsClass = function(name, className) {
  427. var classes;
  428. classes = className.split(/\s+/g);
  429. return classes.indexOf(name) >= 0;
  430. };
  431. return _computedStyle = function(element, property) {
  432. return document.defaultView.getComputedStyle(element, "")[property];
  433. };
  434. })(Quo);
  435. (function($$) {
  436. $$.fn.attr = function(name, value) {
  437. if ($$.toType(name) === "string" && value === void 0) {
  438. return this[0].getAttribute(name);
  439. } else {
  440. return this.each(function() {
  441. return this.setAttribute(name, value);
  442. });
  443. }
  444. };
  445. $$.fn.removeAttr = function(name) {
  446. return this.each(function() {
  447. return this.removeAttribute(name);
  448. });
  449. };
  450. $$.fn.data = function(name, value) {
  451. return this.attr("data-" + name, value);
  452. };
  453. $$.fn.removeData = function(name) {
  454. return this.removeAttr("data-" + name);
  455. };
  456. $$.fn.val = function(value) {
  457. if ($$.toType(value) === "string") {
  458. return this.each(function() {
  459. return this.value = value;
  460. });
  461. } else {
  462. if (this.length > 0) {
  463. return this[0].value;
  464. } else {
  465. return null;
  466. }
  467. }
  468. };
  469. $$.fn.show = function() {
  470. return this.style("display", "block");
  471. };
  472. $$.fn.hide = function() {
  473. return this.style("display", "none");
  474. };
  475. $$.fn.height = function() {
  476. var offset;
  477. offset = this.offset();
  478. return offset.height;
  479. };
  480. $$.fn.width = function() {
  481. var offset;
  482. offset = this.offset();
  483. return offset.width;
  484. };
  485. $$.fn.offset = function() {
  486. var bounding;
  487. bounding = this[0].getBoundingClientRect();
  488. return {
  489. left: bounding.left + window.pageXOffset,
  490. top: bounding.top + window.pageYOffset,
  491. width: bounding.width,
  492. height: bounding.height
  493. };
  494. };
  495. return $$.fn.remove = function() {
  496. return this.each(function() {
  497. if (this.parentNode != null) {
  498. return this.parentNode.removeChild(this);
  499. }
  500. });
  501. };
  502. })(Quo);
  503. (function($$) {
  504. $$.fn.text = function(value) {
  505. if (value || $$.toType(value) === "number") {
  506. return this.each(function() {
  507. return this.textContent = value;
  508. });
  509. } else {
  510. return this[0].textContent;
  511. }
  512. };
  513. $$.fn.html = function(value) {
  514. var type;
  515. type = $$.toType(value);
  516. if (value || type === "number" || type === "string") {
  517. return this.each(function() {
  518. if (type === "string" || type === "number") {
  519. return this.innerHTML = value;
  520. } else {
  521. this.innerHTML = null;
  522. return this.appendChild(value);
  523. }
  524. });
  525. } else {
  526. return this[0].innerHTML;
  527. }
  528. };
  529. $$.fn.append = function(value) {
  530. var type;
  531. type = $$.toType(value);
  532. return this.each(function() {
  533. var _this = this;
  534. if (type === "string") {
  535. return this.insertAdjacentHTML("beforeend", value);
  536. } else if (type === "array") {
  537. return value.each(function(index, value) {
  538. return _this.appendChild(value);
  539. });
  540. } else {
  541. return this.appendChild(value);
  542. }
  543. });
  544. };
  545. $$.fn.prepend = function(value) {
  546. var type;
  547. type = $$.toType(value);
  548. return this.each(function() {
  549. var _this = this;
  550. if (type === "string") {
  551. return this.insertAdjacentHTML("afterbegin", value);
  552. } else if (type === "array") {
  553. return value.each(function(index, value) {
  554. return _this.insertBefore(value, _this.firstChild);
  555. });
  556. } else {
  557. return this.insertBefore(value, this.firstChild);
  558. }
  559. });
  560. };
  561. $$.fn.replaceWith = function(value) {
  562. var type;
  563. type = $$.toType(value);
  564. this.each(function() {
  565. var _this = this;
  566. if (this.parentNode) {
  567. if (type === "string") {
  568. return this.insertAdjacentHTML("beforeBegin", value);
  569. } else if (type === "array") {
  570. return value.each(function(index, value) {
  571. return _this.parentNode.insertBefore(value, _this);
  572. });
  573. } else {
  574. return this.parentNode.insertBefore(value, this);
  575. }
  576. }
  577. });
  578. return this.remove();
  579. };
  580. return $$.fn.empty = function() {
  581. return this.each(function() {
  582. return this.innerHTML = null;
  583. });
  584. };
  585. })(Quo);
  586. (function($$) {
  587. var DEFAULT, JSONP_ID, MIME_TYPES, _isJsonP, _parseResponse, _xhrError, _xhrForm, _xhrHeaders, _xhrStatus, _xhrSuccess, _xhrTimeout;
  588. DEFAULT = {
  589. TYPE: "GET",
  590. MIME: "json"
  591. };
  592. MIME_TYPES = {
  593. script: "text/javascript, application/javascript",
  594. json: "application/json",
  595. xml: "application/xml, text/xml",
  596. html: "text/html",
  597. text: "text/plain"
  598. };
  599. JSONP_ID = 0;
  600. $$.ajaxSettings = {
  601. type: DEFAULT.TYPE,
  602. async: true,
  603. success: {},
  604. error: {},
  605. context: null,
  606. dataType: DEFAULT.MIME,
  607. headers: {},
  608. xhr: function() {
  609. return new window.XMLHttpRequest();
  610. },
  611. crossDomain: false,
  612. timeout: 0
  613. };
  614. $$.ajax = function(options) {
  615. var abortTimeout, settings, xhr;
  616. settings = $$.mix($$.ajaxSettings, options);
  617. if (settings.type === DEFAULT.TYPE) {
  618. settings.url += $$.serializeParameters(settings.data, "?");
  619. } else {
  620. settings.data = $$.serializeParameters(settings.data);
  621. }
  622. if (_isJsonP(settings.url)) {
  623. return $$.jsonp(settings);
  624. }
  625. xhr = settings.xhr();
  626. xhr.onreadystatechange = function() {
  627. if (xhr.readyState === 4) {
  628. clearTimeout(abortTimeout);
  629. return _xhrStatus(xhr, settings);
  630. }
  631. };
  632. xhr.open(settings.type, settings.url, settings.async);
  633. _xhrHeaders(xhr, settings);
  634. if (settings.timeout > 0) {
  635. abortTimeout = setTimeout((function() {
  636. return _xhrTimeout(xhr, settings);
  637. }), settings.timeout);
  638. }
  639. try {
  640. xhr.send(settings.data);
  641. } catch (error) {
  642. xhr = error;
  643. _xhrError("Resource not found", xhr, settings);
  644. }
  645. if (settings.async) {
  646. return xhr;
  647. } else {
  648. return _parseResponse(xhr, settings);
  649. }
  650. };
  651. $$.jsonp = function(settings) {
  652. var abortTimeout, callbackName, script, xhr;
  653. if (settings.async) {
  654. callbackName = "jsonp" + (++JSONP_ID);
  655. script = document.createElement("script");
  656. xhr = {
  657. abort: function() {
  658. $$(script).remove();
  659. if (callbackName in window) {
  660. return window[callbackName] = {};
  661. }
  662. }
  663. };
  664. abortTimeout = void 0;
  665. window[callbackName] = function(response) {
  666. clearTimeout(abortTimeout);
  667. $$(script).remove();
  668. delete window[callbackName];
  669. return _xhrSuccess(response, xhr, settings);
  670. };
  671. script.src = settings.url.replace(RegExp("=\\?"), "=" + callbackName);
  672. $$("head").append(script);
  673. if (settings.timeout > 0) {
  674. abortTimeout = setTimeout((function() {
  675. return _xhrTimeout(xhr, settings);
  676. }), settings.timeout);
  677. }
  678. return xhr;
  679. } else {
  680. return console.error("QuoJS.ajax: Unable to make jsonp synchronous call.");
  681. }
  682. };
  683. $$.get = function(url, data, success, dataType) {
  684. return $$.ajax({
  685. url: url,
  686. data: data,
  687. success: success,
  688. dataType: dataType
  689. });
  690. };
  691. $$.post = function(url, data, success, dataType) {
  692. return _xhrForm("POST", url, data, success, dataType);
  693. };
  694. $$.put = function(url, data, success, dataType) {
  695. return _xhrForm("PUT", url, data, success, dataType);
  696. };
  697. $$["delete"] = function(url, data, success, dataType) {
  698. return _xhrForm("DELETE", url, data, success, dataType);
  699. };
  700. $$.json = function(url, data, success) {
  701. return $$.ajax({
  702. url: url,
  703. data: data,
  704. success: success,
  705. dataType: DEFAULT.MIME
  706. });
  707. };
  708. $$.serializeParameters = function(parameters, character) {
  709. var parameter, serialize;
  710. if (character == null) {
  711. character = "";
  712. }
  713. serialize = character;
  714. for (parameter in parameters) {
  715. if (parameters.hasOwnProperty(parameter)) {
  716. if (serialize !== character) {
  717. serialize += "&";
  718. }
  719. serialize += parameter + "=" + parameters[parameter];
  720. }
  721. }
  722. if (serialize === character) {
  723. return "";
  724. } else {
  725. return serialize;
  726. }
  727. };
  728. _xhrStatus = function(xhr, settings) {
  729. if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 0) {
  730. if (settings.async) {
  731. _xhrSuccess(_parseResponse(xhr, settings), xhr, settings);
  732. }
  733. } else {
  734. _xhrError("QuoJS.ajax: Unsuccesful request", xhr, settings);
  735. }
  736. };
  737. _xhrSuccess = function(response, xhr, settings) {
  738. settings.success.call(settings.context, response, xhr);
  739. };
  740. _xhrError = function(type, xhr, settings) {
  741. settings.error.call(settings.context, type, xhr, settings);
  742. };
  743. _xhrHeaders = function(xhr, settings) {
  744. var header;
  745. if (settings.contentType) {
  746. settings.headers["Content-Type"] = settings.contentType;
  747. }
  748. if (settings.dataType) {
  749. settings.headers["Accept"] = MIME_TYPES[settings.dataType];
  750. }
  751. for (header in settings.headers) {
  752. xhr.setRequestHeader(header, settings.headers[header]);
  753. }
  754. };
  755. _xhrTimeout = function(xhr, settings) {
  756. xhr.onreadystatechange = {};
  757. xhr.abort();
  758. _xhrError("QuoJS.ajax: Timeout exceeded", xhr, settings);
  759. };
  760. _xhrForm = function(method, url, data, success, dataType) {
  761. return $$.ajax({
  762. type: method,
  763. url: url,
  764. data: data,
  765. success: success,
  766. dataType: dataType,
  767. contentType: "application/x-www-form-urlencoded"
  768. });
  769. };
  770. _parseResponse = function(xhr, settings) {
  771. var response;
  772. response = xhr.responseText;
  773. if (response) {
  774. if (settings.dataType === DEFAULT.MIME) {
  775. try {
  776. response = JSON.parse(response);
  777. } catch (error) {
  778. response = error;
  779. _xhrError("QuoJS.ajax: Parse Error", xhr, settings);
  780. }
  781. } else {
  782. if (settings.dataType === "xml") {
  783. response = xhr.responseXML;
  784. }
  785. }
  786. }
  787. return response;
  788. };
  789. return _isJsonP = function(url) {
  790. return RegExp("=\\?").test(url);
  791. };
  792. })(Quo);
  793. (function($$) {
  794. var ELEMENT_ID, EVENTS_DESKTOP, EVENT_METHODS, HANDLERS, READY_EXPRESSION, _createProxy, _createProxyCallback, _environmentEvent, _findHandlers, _getElementId, _subscribe, _unsubscribe;
  795. ELEMENT_ID = 1;
  796. HANDLERS = {};
  797. EVENT_METHODS = {
  798. preventDefault: "isDefaultPrevented",
  799. stopImmediatePropagation: "isImmediatePropagationStopped",
  800. stopPropagation: "isPropagationStopped"
  801. };
  802. EVENTS_DESKTOP = {
  803. touchstart: "mousedown",
  804. touchmove: "mousemove",
  805. touchend: "mouseup",
  806. touch: "click",
  807. doubletap: "dblclick",
  808. orientationchange: "resize"
  809. };
  810. READY_EXPRESSION = /complete|loaded|interactive/;
  811. $$.fn.on = function(event, selector, callback) {
  812. if (selector === "undefined" || $$.toType(selector) === "function") {
  813. return this.bind(event, selector);
  814. } else {
  815. return this.delegate(selector, event, callback);
  816. }
  817. };
  818. $$.fn.off = function(event, selector, callback) {
  819. if (selector === "undefined" || $$.toType(selector) === "function") {
  820. return this.unbind(event, selector);
  821. } else {
  822. return this.undelegate(selector, event, callback);
  823. }
  824. };
  825. $$.fn.ready = function(callback) {
  826. if (READY_EXPRESSION.test(document.readyState)) {
  827. return callback($$);
  828. } else {
  829. return $$.fn.addEvent(document, "DOMContentLoaded", function() {
  830. return callback($$);
  831. });
  832. }
  833. };
  834. $$.Event = function(type, touch) {
  835. var event, property;
  836. event = document.createEvent("Events");
  837. event.initEvent(type, true, true, null, null, null, null, null, null, null, null, null, null, null, null);
  838. if (touch) {
  839. for (property in touch) {
  840. event[property] = touch[property];
  841. }
  842. }
  843. return event;
  844. };
  845. $$.fn.bind = function(event, callback) {
  846. return this.each(function() {
  847. _subscribe(this, event, callback);
  848. });
  849. };
  850. $$.fn.unbind = function(event, callback) {
  851. return this.each(function() {
  852. _unsubscribe(this, event, callback);
  853. });
  854. };
  855. $$.fn.delegate = function(selector, event, callback) {
  856. return this.each(function(i, element) {
  857. _subscribe(element, event, callback, selector, function(fn) {
  858. return function(e) {
  859. var evt, match;
  860. match = $$(e.target).closest(selector, element).get(0);
  861. if (match) {
  862. evt = $$.extend(_createProxy(e), {
  863. currentTarget: match,
  864. liveFired: element
  865. });
  866. return fn.apply(match, [evt].concat([].slice.call(arguments, 1)));
  867. }
  868. };
  869. });
  870. });
  871. };
  872. $$.fn.undelegate = function(selector, event, callback) {
  873. return this.each(function() {
  874. _unsubscribe(this, event, callback, selector);
  875. });
  876. };
  877. $$.fn.trigger = function(event, touch) {
  878. if ($$.toType(event) === "string") {
  879. event = $$.Event(event, touch);
  880. }
  881. return this.each(function() {
  882. this.dispatchEvent(event);
  883. });
  884. };
  885. $$.fn.addEvent = function(element, event_name, callback) {
  886. if (element.addEventListener) {
  887. return element.addEventListener(event_name, callback, false);
  888. } else if (element.attachEvent) {
  889. return element.attachEvent("on" + event_name, callback);
  890. } else {
  891. return element["on" + event_name] = callback;
  892. }
  893. };
  894. $$.fn.removeEvent = function(element, event_name, callback) {
  895. if (element.removeEventListener) {
  896. return element.removeEventListener(event_name, callback, false);
  897. } else if (element.detachEvent) {
  898. return element.detachEvent("on" + event_name, callback);
  899. } else {
  900. return element["on" + event_name] = null;
  901. }
  902. };
  903. _subscribe = function(element, event, callback, selector, delegate_callback) {
  904. var delegate, element_handlers, element_id, handler;
  905. event = _environmentEvent(event);
  906. element_id = _getElementId(element);
  907. element_handlers = HANDLERS[element_id] || (HANDLERS[element_id] = []);
  908. delegate = delegate_callback && delegate_callback(callback, event);
  909. handler = {
  910. event: event,
  911. callback: callback,
  912. selector: selector,
  913. proxy: _createProxyCallback(delegate, callback, element),
  914. delegate: delegate,
  915. index: element_handlers.length
  916. };
  917. element_handlers.push(handler);
  918. return $$.fn.addEvent(element, handler.event, handler.proxy);
  919. };
  920. _unsubscribe = function(element, event, callback, selector) {
  921. var element_id;
  922. event = _environmentEvent(event);
  923. element_id = _getElementId(element);
  924. return _findHandlers(element_id, event, callback, selector).forEach(function(handler) {
  925. delete HANDLERS[element_id][handler.index];
  926. return $$.fn.removeEvent(element, handler.event, handler.proxy);
  927. });
  928. };
  929. _getElementId = function(element) {
  930. return element._id || (element._id = ELEMENT_ID++);
  931. };
  932. _environmentEvent = function(event) {
  933. var environment_event;
  934. environment_event = ($$.isMobile() ? event : EVENTS_DESKTOP[event]);
  935. return environment_event || event;
  936. };
  937. _createProxyCallback = function(delegate, callback, element) {
  938. var proxy;
  939. callback = delegate || callback;
  940. proxy = function(event) {
  941. var result;
  942. result = callback.apply(element, [event].concat(event.data));
  943. if (result === false) {
  944. event.preventDefault();
  945. }
  946. return result;
  947. };
  948. return proxy;
  949. };
  950. _findHandlers = function(element_id, event, fn, selector) {
  951. return (HANDLERS[element_id] || []).filter(function(handler) {
  952. return handler && (!event || handler.event === event) && (!fn || handler.callback === fn) && (!selector || handler.selector === selector);
  953. });
  954. };
  955. return _createProxy = function(event) {
  956. var proxy;
  957. proxy = $$.extend({
  958. originalEvent: event
  959. }, event);
  960. $$.each(EVENT_METHODS, function(name, method) {
  961. proxy[name] = function() {
  962. this[method] = function() {
  963. return true;
  964. };
  965. return event[name].apply(event, arguments);
  966. };
  967. return proxy[method] = function() {
  968. return false;
  969. };
  970. });
  971. return proxy;
  972. };
  973. })(Quo);
  974. (function($$) {
  975. var CURRENT_TOUCH, FIRST_TOUCH, GESTURE, GESTURES, HOLD_DELAY, TAPS, TOUCH_TIMEOUT, _angle, _capturePinch, _captureRotation, _cleanGesture, _distance, _fingersPosition, _getTouches, _hold, _isSwipe, _listenTouches, _onTouchEnd, _onTouchMove, _onTouchStart, _parentIfText, _swipeDirection, _trigger;
  976. TAPS = null;
  977. GESTURE = {};
  978. FIRST_TOUCH = [];
  979. CURRENT_TOUCH = [];
  980. TOUCH_TIMEOUT = void 0;
  981. HOLD_DELAY = 650;
  982. GESTURES = ["tap", "singleTap", "doubleTap", "hold", "swipe", "swiping", "swipeLeft", "swipeRight", "swipeUp", "swipeDown", "rotate", "rotating", "rotateLeft", "rotateRight", "pinch", "pinching", "pinchIn", "pinchOut", "drag", "dragLeft", "dragRight", "dragUp", "dragDown"];
  983. GESTURES.forEach(function(event) {
  984. $$.fn[event] = function(callback) {
  985. return $$(document.body).delegate(this.selector, event, callback);
  986. };
  987. return this;
  988. });
  989. $$(document).ready(function() {
  990. return _listenTouches();
  991. });
  992. _listenTouches = function() {
  993. var environment;
  994. environment = $$(document.body);
  995. environment.bind("touchstart", _onTouchStart);
  996. environment.bind("touchmove", _onTouchMove);
  997. environment.bind("touchend", _onTouchEnd);
  998. return environment.bind("touchcancel", _cleanGesture);
  999. };
  1000. _onTouchStart = function(event) {
  1001. var delta, fingers, now, touches;
  1002. now = Date.now();
  1003. delta = now - (GESTURE.last || now);
  1004. TOUCH_TIMEOUT && clearTimeout(TOUCH_TIMEOUT);
  1005. touches = _getTouches(event);
  1006. fingers = touches.length;
  1007. FIRST_TOUCH = _fingersPosition(touches, fingers);
  1008. GESTURE.el = $$(_parentIfText(touches[0].target));
  1009. GESTURE.fingers = fingers;
  1010. GESTURE.last = now;
  1011. if (!GESTURE.taps) {
  1012. GESTURE.taps = 0;
  1013. }
  1014. GESTURE.taps++;
  1015. if (fingers === 1) {
  1016. if (fingers >= 1) {
  1017. GESTURE.gap = delta > 0 && delta <= 250;
  1018. }
  1019. return setTimeout(_hold, HOLD_DELAY);
  1020. } else if (fingers === 2) {
  1021. GESTURE.initial_angle = parseInt(_angle(FIRST_TOUCH), 10);
  1022. GESTURE.initial_distance = parseInt(_distance(FIRST_TOUCH), 10);
  1023. GESTURE.angle_difference = 0;
  1024. return GESTURE.distance_difference = 0;
  1025. }
  1026. };
  1027. _onTouchMove = function(event) {
  1028. var fingers, is_swipe, touches;
  1029. if (GESTURE.el) {
  1030. touches = _getTouches(event);
  1031. fingers = touches.length;
  1032. if (fingers === GESTURE.fingers) {
  1033. CURRENT_TOUCH = _fingersPosition(touches, fingers);
  1034. is_swipe = _isSwipe(event);
  1035. if (is_swipe) {
  1036. GESTURE.prevSwipe = true;
  1037. }
  1038. if (is_swipe || GESTURE.prevSwipe === true) {
  1039. _trigger("swiping");
  1040. }
  1041. if (fingers === 2) {
  1042. _captureRotation();
  1043. _capturePinch();
  1044. event.preventDefault();
  1045. }
  1046. } else {
  1047. _cleanGesture();
  1048. }
  1049. }
  1050. return true;
  1051. };
  1052. _isSwipe = function(event) {
  1053. var it_is, move_horizontal, move_vertical;
  1054. it_is = false;
  1055. if (CURRENT_TOUCH[0]) {
  1056. move_horizontal = Math.abs(FIRST_TOUCH[0].x - CURRENT_TOUCH[0].x) > 30;
  1057. move_vertical = Math.abs(FIRST_TOUCH[0].y - CURRENT_TOUCH[0].y) > 30;
  1058. it_is = GESTURE.el && (move_horizontal || move_vertical);
  1059. }
  1060. return it_is;
  1061. };
  1062. _onTouchEnd = function(event) {
  1063. var anyevent, drag_direction, pinch_direction, rotation_direction, swipe_direction;
  1064. if (GESTURE.fingers === 1) {
  1065. if (GESTURE.taps === 2 && GESTURE.gap) {
  1066. _trigger("doubleTap");
  1067. return _cleanGesture();
  1068. } else if (_isSwipe() || GESTURE.prevSwipe) {
  1069. _trigger("swipe");
  1070. swipe_direction = _swipeDirection(FIRST_TOUCH[0].x, CURRENT_TOUCH[0].x, FIRST_TOUCH[0].y, CURRENT_TOUCH[0].y);
  1071. _trigger("swipe" + swipe_direction);
  1072. return _cleanGesture();
  1073. } else {
  1074. _trigger("tap");
  1075. if (GESTURE.taps === 1) {
  1076. return TOUCH_TIMEOUT = setTimeout((function() {
  1077. _trigger("singleTap");
  1078. return _cleanGesture();
  1079. }), 100);
  1080. }
  1081. }
  1082. } else {
  1083. anyevent = false;
  1084. if (GESTURE.angle_difference !== 0) {
  1085. _trigger("rotate", {
  1086. angle: GESTURE.angle_difference
  1087. });
  1088. rotation_direction = GESTURE.angle_difference > 0 ? "rotateRight" : "rotateLeft";
  1089. _trigger(rotation_direction, {
  1090. angle: GESTURE.angle_difference
  1091. });
  1092. anyevent = true;
  1093. }
  1094. if (GESTURE.distance_difference !== 0) {
  1095. _trigger("pinch", {
  1096. angle: GESTURE.distance_difference
  1097. });
  1098. pinch_direction = GESTURE.distance_difference > 0 ? "pinchOut" : "pinchIn";
  1099. _trigger(pinch_direction, {
  1100. distance: GESTURE.distance_difference
  1101. });
  1102. anyevent = true;
  1103. }
  1104. if (!anyevent && CURRENT_TOUCH[0]) {
  1105. if (Math.abs(FIRST_TOUCH[0].x - CURRENT_TOUCH[0].x) > 10 || Math.abs(FIRST_TOUCH[0].y - CURRENT_TOUCH[0].y) > 10) {
  1106. _trigger("drag");
  1107. drag_direction = _swipeDirection(FIRST_TOUCH[0].x, CURRENT_TOUCH[0].x, FIRST_TOUCH[0].y, CURRENT_TOUCH[0].y);
  1108. _trigger("drag" + drag_direction);
  1109. }
  1110. }
  1111. return _cleanGesture();
  1112. }
  1113. };
  1114. _fingersPosition = function(touches, fingers) {
  1115. var i, result;
  1116. result = [];
  1117. i = 0;
  1118. touches = touches[0].targetTouches ? touches[0].targetTouches : touches;
  1119. while (i < fingers) {
  1120. result.push({
  1121. x: touches[i].pageX,
  1122. y: touches[i].pageY
  1123. });
  1124. i++;
  1125. }
  1126. return result;
  1127. };
  1128. _captureRotation = function() {
  1129. var angle, diff, i, symbol;
  1130. angle = parseInt(_angle(CURRENT_TOUCH), 10);
  1131. diff = parseInt(GESTURE.initial_angle - angle, 10);
  1132. if (Math.abs(diff) > 20 || GESTURE.angle_difference !== 0) {
  1133. i = 0;
  1134. symbol = GESTURE.angle_difference < 0 ? "-" : "+";
  1135. while (Math.abs(diff - GESTURE.angle_difference) > 90 && i++ < 10) {
  1136. eval("diff " + symbol + "= 180;");
  1137. }
  1138. GESTURE.angle_difference = parseInt(diff, 10);
  1139. return _trigger("rotating", {
  1140. angle: GESTURE.angle_difference
  1141. });
  1142. }
  1143. };
  1144. _capturePinch = function() {
  1145. var diff, distance;
  1146. distance = parseInt(_distance(CURRENT_TOUCH), 10);
  1147. diff = GESTURE.initial_distance - distance;
  1148. if (Math.abs(diff) > 10) {
  1149. GESTURE.distance_difference = diff;
  1150. return _trigger("pinching", {
  1151. distance: diff
  1152. });
  1153. }
  1154. };
  1155. _trigger = function(type, params) {
  1156. if (GESTURE.el) {
  1157. params = params || {};
  1158. if (CURRENT_TOUCH[0]) {
  1159. params.iniTouch = (GESTURE.fingers > 1 ? FIRST_TOUCH : FIRST_TOUCH[0]);
  1160. params.currentTouch = (GESTURE.fingers > 1 ? CURRENT_TOUCH : CURRENT_TOUCH[0]);
  1161. }
  1162. return GESTURE.el.trigger(type, params);
  1163. }
  1164. };
  1165. _cleanGesture = function(event) {
  1166. FIRST_TOUCH = [];
  1167. CURRENT_TOUCH = [];
  1168. GESTURE = {};
  1169. return clearTimeout(TOUCH_TIMEOUT);
  1170. };
  1171. _angle = function(touches_data) {
  1172. var A, B, angle;
  1173. A = touches_data[0];
  1174. B = touches_data[1];
  1175. angle = Math.atan((B.y - A.y) * -1 / (B.x - A.x)) * (180 / Math.PI);
  1176. if (angle < 0) {
  1177. return angle + 180;
  1178. } else {
  1179. return angle;
  1180. }
  1181. };
  1182. _distance = function(touches_data) {
  1183. var A, B;
  1184. A = touches_data[0];
  1185. B = touches_data[1];
  1186. return Math.sqrt((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y)) * -1;
  1187. };
  1188. _getTouches = function(event) {
  1189. if ($$.isMobile()) {
  1190. return event.touches;
  1191. } else {
  1192. return [event];
  1193. }
  1194. };
  1195. _parentIfText = function(node) {
  1196. if ("tagName" in node) {
  1197. return node;
  1198. } else {
  1199. return node.parentNode;
  1200. }
  1201. };
  1202. _swipeDirection = function(x1, x2, y1, y2) {
  1203. var xDelta, yDelta;
  1204. xDelta = Math.abs(x1 - x2);
  1205. yDelta = Math.abs(y1 - y2);
  1206. if (xDelta >= yDelta) {
  1207. if (x1 - x2 > 0) {
  1208. return "Left";
  1209. } else {
  1210. return "Right";
  1211. }
  1212. } else {
  1213. if (y1 - y2 > 0) {
  1214. return "Up";
  1215. } else {
  1216. return "Down";
  1217. }
  1218. }
  1219. };
  1220. return _hold = function() {
  1221. if (GESTURE.last && (Date.now() - GESTURE.last >= HOLD_DELAY)) {
  1222. _trigger("hold");
  1223. return GESTURE.taps = 0;
  1224. }
  1225. };
  1226. })(Quo);