فهرست منبع

New version of QuoJS

@soyjavi 14 سال پیش
والد
کامیت
556b2d70d6
2فایلهای تغییر یافته به همراه241 افزوده شده و 127 حذف شده
  1. 216 127
      src/lib/QuoJS.js
  2. 25 0
      src/lib/quo.js

+ 216 - 127
src/lib/QuoJS.js

@@ -1,5 +1,7 @@
+// Generated by CoffeeScript 1.3.1
+
 /*
-    QuoJS 2.0.3
+    QuoJS 2.1
     http://quojs.tapquo.com
 
     Copyright (C) 2011,2012 Javi Jiménez Villar (@soyjavi)
@@ -23,6 +25,7 @@
     DEALINGS IN THE SOFTWARE.
 */
 
+
 (function() {
   var Quo;
 
@@ -35,13 +38,16 @@
       dom.selector = selector || '';
       return dom;
     };
-    $$ = function(selector) {
-      var domain_selector;
+    $$ = function(selector, children) {
+      var dom;
       if (!selector) {
         return Q();
       } else {
-        domain_selector = $$.getDomainSelector(selector);
-        return Q(domain_selector, selector);
+        dom = $$.getDOMObject(selector, children);
+        if (children) {
+          selector += ' ' + children;
+        }
+        return Q(dom, selector);
       }
     };
     $$.extend = function(target) {
@@ -64,10 +70,10 @@
   "$$" in window || (window.$$ = Quo);
 
 }).call(this);
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.3.1
 
 /*
-  QuoJS 2.0
+  QuoJS 2.1
   (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
   http://quojs.tapquo.com
 */
@@ -76,24 +82,48 @@
 (function() {
 
   (function($$) {
-    var EMPTY_ARRAY, OBJECT_PROTOTYPE, _compact, _flatten;
+    var EMPTY_ARRAY, HTML_CONTAINERS, IS_HTML_FRAGMENT, OBJECT_PROTOTYPE, TABLE, TABLE_ROW, _compact, _flatten;
     EMPTY_ARRAY = [];
     OBJECT_PROTOTYPE = Object.prototype;
+    IS_HTML_FRAGMENT = /^\s*<(\w+|!)[^>]*>/;
+    TABLE = document.createElement('table');
+    TABLE_ROW = document.createElement('tr');
+    HTML_CONTAINERS = {
+      "tr": document.createElement("tbody"),
+      "tbody": TABLE,
+      "thead": TABLE,
+      "tfoot": TABLE,
+      "td": TABLE_ROW,
+      "th": TABLE_ROW,
+      "*": document.createElement("div")
+    };
     $$.toType = function(obj) {
       return OBJECT_PROTOTYPE.toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
     };
     $$.isOwnProperty = function(object, property) {
       return OBJECT_PROTOTYPE.hasOwnProperty.call(object, property);
     };
-    $$.getDomainSelector = function(selector) {
+    $$.getDOMObject = function(selector, children) {
       var domain, elementTypes, type;
       domain = null;
       elementTypes = [1, 9, 11];
       type = $$.toType(selector);
       if (type === "array") {
         domain = _compact(selector);
+      } else if (type === "string" && IS_HTML_FRAGMENT.test(selector)) {
+        domain = $$.fragment(selector.trim(), RegExp.$1);
+        selector = null;
       } else if (type === "string") {
         domain = $$.query(document, selector);
+        if (children) {
+          if (domain.length === 1) {
+            domain = $$.query(domain[0], children);
+          } else {
+            domain = $$.map(function() {
+              return $$.query(domain, children);
+            });
+          }
+        }
       } else if (elementTypes.indexOf(selector.nodeType) >= 0 || selector === window) {
         domain = [selector];
         selector = null;
@@ -161,6 +191,20 @@
       }
       return child;
     };
+    $$.fragment = function(markup, tag) {
+      var container;
+      if (tag == null) {
+        tag = "*";
+      }
+      if (!(tag in HTML_CONTAINERS)) {
+        tag = "*";
+      }
+      container = HTML_CONTAINERS[tag];
+      container.innerHTML = "" + markup;
+      return $$.each(Array.prototype.slice.call(container.childNodes), function() {
+        return container.removeChild(this);
+      });
+    };
     $$.fn.map = function(fn) {
       return $$.map(this, function(el, i) {
         return fn.call(el, i, el);
@@ -196,7 +240,7 @@
 // Generated by CoffeeScript 1.3.3
 
 /*
-  QuoJS 2.0
+  QuoJS 2.1
   (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
   http://quojs.tapquo.com
 */
@@ -269,7 +313,7 @@
 // Generated by CoffeeScript 1.3.3
 
 /*
-  QuoJS 2.0
+  QuoJS 2.1
   (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
   http://quojs.tapquo.com
 */
@@ -342,10 +386,10 @@
   })(Quo);
 
 }).call(this);
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.3.1
 
 /*
-  QuoJS 2.0
+  QuoJS 2.1
   (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
   http://quojs.tapquo.com
 */
@@ -354,7 +398,7 @@
 (function() {
 
   (function($$) {
-    var _priv;
+    var _createElement;
     $$.fn.text = function(value) {
       if (!value) {
         return this[0].textContent;
@@ -377,12 +421,9 @@
     };
     $$.fn.append = function(value) {
       return this.each(function() {
-        var div;
         if ($$.toType(value) === "string") {
           if (value) {
-            div = document.createElement("div");
-            div.innerHTML = value;
-            return this.appendChild(div.firstChild);
+            return this.appendChild(_createElement(value));
           }
         } else {
           return this.insertBefore(value);
@@ -400,21 +441,37 @@
         }
       });
     };
+    $$.fn.replaceWith = function(content) {
+      return this.each(function() {
+        var parent;
+        if ($$.toType(content) === "string") {
+          content = _createElement(content);
+        }
+        parent = this.parentNode;
+        if (parent) {
+          parent.insertBefore(content, this);
+        }
+        return $$(this).remove();
+      });
+    };
     $$.fn.empty = function() {
       return this.each(function() {
         this.innerHTML = null;
       });
     };
-    _priv = function() {
-      return true;
+    _createElement = function(content) {
+      var div;
+      div = document.createElement("div");
+      div.innerHTML = content;
+      return div.firstChild;
     };
   })(Quo);
 
 }).call(this);
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.3.1
 
 /*
-  QuoJS 2.0
+  QuoJS 2.1
   (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
   http://quojs.tapquo.com
 */
@@ -433,7 +490,6 @@
     };
     $$.fn.find = function(selector) {
       var result;
-      result = void 0;
       if (this.length === 1) {
         result = Quo.query(this[0], selector);
       } else {
@@ -520,10 +576,10 @@
   })(Quo);
 
 }).call(this);
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.3.1
 
 /*
-  QuoJS 2.0
+  QuoJS 2.1
   (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
   http://quojs.tapquo.com
 */
@@ -543,8 +599,12 @@
     };
     $$.fn.removeClass = function(name) {
       return this.each(function() {
-        if (_existsClass(name, this.className)) {
-          return this.className = this.className.replace(name, " ").replace(/\s+/g, " ").trim();
+        if (!name) {
+          return this.className = "";
+        } else {
+          if (_existsClass(name, this.className)) {
+            return this.className = this.className.replace(name, " ").replace(/\s+/g, " ").trim();
+          }
         }
       });
     };
@@ -584,7 +644,7 @@
 // Generated by CoffeeScript 1.3.3
 
 /*
-  QuoJS 2.0.3
+  QuoJS 2.1.3
   (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
   http://quojs.tapquo.com
 */
@@ -799,7 +859,7 @@
 // Generated by CoffeeScript 1.3.3
 
 /*
-  QuoJS 2.0
+  QuoJS 2.1
   (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
   http://quojs.tapquo.com
 */
@@ -851,7 +911,7 @@
 // Generated by CoffeeScript 1.3.3
 
 /*
-    QuoJS 2.0
+    QuoJS 2.1
     (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
     http://quojs.tapquo.com
 */
@@ -881,11 +941,7 @@
       event = document.createEvent("Events");
       event.initEvent(type, true, true, null, null, null, null, null, null, null, null, null, null, null, null);
       if (touch) {
-        event.pageX = touch.x1;
-        event.pageY = touch.y1;
-        event.toX = touch.x2;
-        event.toY = touch.y2;
-        event.fingers = touch.fingers;
+        for(var property in touch) event[property] = touch[property];
       }
       return event;
     };
@@ -1023,21 +1079,23 @@
 // Generated by CoffeeScript 1.3.3
 
 /*
-  QuoJS 2.0
+  QuoJS 2.1
   (c) 2011, 2012 Javi Jiménez Villar (@soyjavi)
   http://quojs.tapquo.com
 */
 
 
 (function() {
-
   (function($$) {
-    var GESTURES, HOLD_DELAY, TOUCH, TOUCH_TIMEOUT, _captureTouch, _cleanGesture, _countFingers, _hold, _isSwipe, _listenTouches, _onTouchEnd, _onTouchMove, _onTouchStart, _parentIfText, _swipeDirection, _trigger;
-    TOUCH = {};
-    TOUCH_TIMEOUT = void 0;
-    HOLD_DELAY = 650;
-    GESTURES = ["doubleTap", "hold", "swipe", "swiping", "swipeLeft", "swipeRight", "swipeUp", "swipeDown", "drag"];
-    GESTURES.forEach(function(event) {
+    var TIMEOUT_HOLD = TIMEOUT_DBLTAP = void(0);
+    var gesture_data = events = {};
+    var touches = touches2 = [];
+    (["doubleTap", "hold",
+      "swipe", "swiping", "swipeLeft", "swipeRight", "swipeUp", "swipeDown",
+      "rotate", "rotating", "rotateLeft", "rotateRight",
+      "pinch", "pinching", "pinchIn", "pinchOut",
+      "drag"
+    ]).forEach(function(event) {
       $$.fn[event] = function(callback) {
         return this.on(event, callback);
       };
@@ -1051,111 +1109,142 @@
       environment.bind("touchstart", _onTouchStart);
       environment.bind("touchmove", _onTouchMove);
       environment.bind("touchend", _onTouchEnd);
-      return environment.bind("touchcancel", _cleanGesture);
+      environment.bind("touchcancel", _cleanGesture);
     };
     _onTouchStart = function(event) {
-      var delta, now, touch_event;
-      now = Date.now();
-      delta = now - (TOUCH.last || now);
-      touch_event = _captureTouch(event);
-      TOUCH_TIMEOUT && clearTimeout(TOUCH_TIMEOUT);
-      TOUCH = {
-        el: $$(_parentIfText(touch_event.target)),
-        x1: touch_event.pageX,
-        y1: touch_event.pageY,
-        isDoubleTap: (delta > 0 && delta <= 250 ? true : false),
-        last: now,
-        fingers: _countFingers(event)
+      var touch_data, fingers, t;
+      touch_data = _captureTouch(event);
+      fingers = touch_data.length;
+      if(touches.length > 0 && fingers === 1) {
+        _trigger('doubleTap');
+        _cleanGesture();
+      }
+      if(fingers === 1) TIMEOUT_HOLD = setTimeout(_hold, 650);
+      for(var i=0; i<fingers; i++) {
+        touches.push({
+          x:touch_data[i].pageX,
+          y:touch_data[i].pageY
+        });
+      }
+      gesture_data = {
+        element: $$(_parentIfText(touch_data[0].target)),
+        fingers: fingers
       };
-      return setTimeout(_hold, HOLD_DELAY);
+      if(fingers === 2) {
+        gesture_data.start_angle = _angle(touches);
+        gesture_data.last_angle = 0;
+        gesture_data.start_distance = _distance(touches);
+      }
     };
     _onTouchMove = function(event) {
-      var touch_event;
-      touch_event = _captureTouch(event);
-      TOUCH.x2 = touch_event.pageX;
-      TOUCH.y2 = touch_event.pageY;
-      if (_isSwipe(event)) {
-        return TOUCH.el.trigger("swiping", TOUCH);
+      var touch_data, fingers, t;
+      clearTimeout(TIMEOUT_HOLD);
+      clearTimeout(TIMEOUT_DBLTAP);
+      touches2 = [];
+      touch_data = _captureTouch(event);
+      fingers = touch_data.length;
+      if(fingers === gesture_data.fingers) {
+        for(var i=0; i<fingers; i++) {
+          touches2.push({
+            x:touch_data[i].pageX,
+            y:touch_data[i].pageY
+          });
+        }
+        if(fingers === 1) _captureSwipe();
+        else {
+          _captureRotation();
+          _capturePinch();
+        }
       }
     };
     _onTouchEnd = function(event) {
-      var swipe_direction;
-      if (TOUCH.isDoubleTap) {
-        return _trigger("doubleTap", true);
-      } else if (TOUCH.x2 > 0 || TOUCH.y2 > 0) {
-        if (_isSwipe(event)) {
-          if (TOUCH.fingers === 1) {
-            _trigger("swipe", false);
-            swipe_direction = _swipeDirection(TOUCH.x1, TOUCH.x2, TOUCH.y1, TOUCH.y2);
-            _trigger(swipe_direction, false);
-          } else {
-            _trigger("drag", false);
-          }
+      clearTimeout(TIMEOUT_HOLD);
+      var tap_triggered = false;
+      if(gesture_data.fingers === 1) {
+        if(events.swipeX) _trigger("swipe" + events.swipeX);
+        if(events.swipeY) _trigger("swipe" + events.swipeY);
+        if(events.swipeX || events.swipeY) _trigger("swipe");
+        else {
+          _trigger("tap");
+          tap_triggered = true;
         }
-        return _cleanGesture();
       } else {
-        if (TOUCH.el) {
-          _trigger("tap");
+        if(events.pinch) {
+          _trigger("pinch");
+          _trigger("pinch" + events.pinch);
+        }
+        if(events.rotate) {
+          _trigger("rotate", {angle: gesture_data.last_angle});
+          _trigger("rotate" + events.rotate, {angle: gesture_data.last_angle});
+        }
+      }
+      if(tap_triggered) TIMEOUT_DBLTAP = setTimeout(_cleanGesture, 300);
+      else _cleanGesture();
+    };
+    _captureRotation = function() {
+      var angle = _angle(touches2);
+      var diff = gesture_data.start_angle - angle;
+      if( Math.abs(diff) > 5 || gesture_data.last_angle != 0 ) {
+        if(diff != gesture_data.last_angle) {
+          var symbol = gesture_data.last_angle < 0 ? '-' : '+';
+          var i=0;
+          while(Math.abs(diff - gesture_data.last_angle) > 90 && i++<10) {
+            eval("diff "+symbol+"= 180;");
+          }
+          gesture_data.last_angle = diff;
+          events.rotate = diff>0 ? "Left" : "Right";
+          _trigger('rotating', {angle: gesture_data.last_angle});
         }
-        return TOUCH_TIMEOUT = setTimeout(_cleanGesture, 250);
       }
     };
-    _trigger = function(type, clean) {
-      TOUCH.el.trigger(type, TOUCH);
-      return clean && _cleanGesture();
+    _capturePinch = function() {
+      var distance = _distance(touches2);
+      var diff = gesture_data.start_distance - distance;
+      events.pinch = false;
+      if(Math.abs(diff) > 5) {
+        _trigger('pinching', {distance: diff});
+        events.pinch = diff<0 ? 'In' : 'Out';
+      }
     };
-    _cleanGesture = function(event) {
-      TOUCH = {};
-      return clearTimeout(TOUCH_TIMEOUT);
+    _captureSwipe = function() {
+      var xdiff = parseInt(touches2[0].x - touches[0].x, 10);
+      var ydiff = parseInt(touches2[0].y - touches[0].y, 10);
+      events.swipeX = Math.abs(xdiff) > 20 ? (xdiff>0 ? 'Right' : 'Left') : false;
+      events.swipeY = Math.abs(ydiff) > 20 ? (ydiff>0 ? 'Down' : 'Up') : false;
+      if(events.swipeX || events.swipeY) _trigger("swiping");
     };
-    _isSwipe = function(event) {
-      return TOUCH.el && (Math.abs(TOUCH.x1 - TOUCH.x2) > 30 || Math.abs(TOUCH.y1 - TOUCH.y2) > 30);
+    _angle = function(touches_data) {
+      var A = touches_data[0], B = touches_data[1];
+      var curr_angle = Math.atan((B.y-A.y)*-1/(B.x-A.x)) * (180/Math.PI);
+      return parseInt((curr_angle<0 ? curr_angle+180 : curr_angle), 10);
     };
-    _captureTouch = function(event) {
-      if ($$.isMobile()) {
-        return event.touches[0];
-      } else {
-        return event;
-      }
+    _distance = function(touches_data) {
+      var A = touches_data[0], B = touches_data[1];
+      return parseInt(Math.sqrt((B.x-A.x)*(B.x-A.x)+(B.y-A.y)*(B.y-A.y)), 10)*-1;
+    };
+    _hold = function() {
+      _trigger('hold');
+      _cleanGesture();
     };
     _parentIfText = function(node) {
-      if ("tagName" in node) {
-        return node;
-      } else {
-        return node.parentNode;
-      }
+      if ("tagName" in node) return node;
+      else return node.parentNode;
     };
-    _swipeDirection = function(x1, x2, y1, y2) {
-      var xDelta, yDelta;
-      xDelta = Math.abs(x1 - x2);
-      yDelta = Math.abs(y1 - y2);
-      if (xDelta >= yDelta) {
-        if (x1 - x2 > 0) {
-          return "swipeLeft";
-        } else {
-          return "swipeRight";
-        }
-      } else {
-        if (y1 - y2 > 0) {
-          return "swipeUp";
-        } else {
-          return "swipeDown";
-        }
-      }
+    _captureTouch = function(event) {
+      return ($$.isMobile() ? event.touches : [event]);
     };
-    _hold = function() {
-      if (TOUCH.last && (Date.now() - TOUCH.last >= HOLD_DELAY)) {
-        _trigger("hold");
-        _cleanGesture();
-      }
+    _cleanGesture = function() {
+      clearTimeout(TIMEOUT_HOLD);
+      clearTimeout(TIMEOUT_DBLTAP);
+      gesture_data = events = {};
+      touches = touches2 = [];
     };
-    _countFingers = function(event) {
-      if (event.touches) {
-        return event.touches.length;
-      } else {
-        return 1;
-      }
+    _trigger = function(type, params) {
+      params = params || {};
+      params.touches = [];
+      params.touches.push(touches);
+      params.touches.push(touches2);
+      gesture_data.element.trigger(type, params);
     };
   })(Quo);
-
 }).call(this);

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 25 - 0
src/lib/quo.js