Skip to content

Commit

Permalink
add dragging event to fix chrome on android
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Apr 14, 2014
1 parent 07933f0 commit 6b1efac
Show file tree
Hide file tree
Showing 60 changed files with 1,456 additions and 1,393 deletions.
46 changes: 23 additions & 23 deletions build/dd-min.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions build/dd.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2014, KISSY v5.0.0
MIT Licensed
build time: Apr 10 18:37
build time: Apr 14 14:14
*/
/*
Combined modules by KISSY Module Compiler:
Expand Down Expand Up @@ -198,7 +198,7 @@ KISSY.add("dd/ddm", ["node", "base", "ua"], function(S, require) {
return DDM
});
KISSY.add("dd/draggable", ["node", "event/gesture/base", "./ddm", "base", "event/gesture/drag", "ua"], function(S, require) {
var Node = require("node"), BaseGesture = require("event/gesture/base"), DDM = require("./ddm"), Base = require("base"), DragType = require("event/gesture/drag");
var Node = require("node"), BaseGesture = require("event/gesture/base"), DDM = require("./ddm"), Base = require("base"), DragGesture = require("event/gesture/drag");
var UA = require("ua"), $ = Node.all, $doc = $(document), each = S.each, ie = UA.ie, PREFIX_CLS = DDM.PREFIX_CLS, doc = S.Env.host.document;
function checkValid(fn) {
return function() {
Expand Down Expand Up @@ -236,20 +236,20 @@ KISSY.add("dd/draggable", ["node", "event/gesture/base", "./ddm", "base", "event
}, start:function() {
var self = this, node = self.getEventTargetEl();
if(node) {
node.on(DragType.DRAG_START, onDragStart, self).on(DragType.DRAG, onDrag, self).on(DragType.DRAG_END, onDragEnd, self).on(BaseGesture.START, onGestureStart, self).on("dragstart", self._fixDragStart)
node.on(DragGesture.DRAG_START, onDragStart, self).on(DragGesture.DRAG, onDrag, self).on(DragGesture.DRAG_END, onDragEnd, self).on(BaseGesture.START, onGestureStart, self).on(["dragstart", DragGesture.DRAGGING], preventDefault)
}
}, stop:function() {
var self = this, node = self.getEventTargetEl();
if(node) {
node.detach(DragType.DRAG_START, onDragStart, self).detach(DragType.DRAG, onDrag, self).detach(DragType.DRAG_END, onDragEnd, self).detach(BaseGesture.START, onGestureStart, self).detach("dragstart", self._fixDragStart)
node.detach(DragGesture.DRAG_START, onDragStart, self).detach(DragGesture.DRAG, onDrag, self).detach(DragGesture.DRAG_END, onDragEnd, self).detach(BaseGesture.START, onGestureStart, self).detach(["dragstart", DragGesture.DRAGGING], preventDefault)
}
}, _onSetDisabled:function(d) {
var self = this, node = self.get("dragNode");
if(node) {
node[d ? "addClass" : "removeClass"](PREFIX_CLS + "-disabled")
}
self[d ? "stop" : "start"]()
}, _fixDragStart:fixDragStart, _checkHandler:function(t) {
}, _checkHandler:function(t) {
var self = this, handlers = self.get("handlers"), ret = 0;
each(handlers, function(handler) {
if(handler[0] === t || handler.contains(t)) {
Expand Down Expand Up @@ -383,7 +383,7 @@ KISSY.add("dd/draggable", ["node", "event/gesture/base", "./ddm", "base", "event
doc.body.setCapture()
}
}
function fixDragStart(e) {
function preventDefault(e) {
e.preventDefault()
}
function fixIESelect() {
Expand Down
2 changes: 1 addition & 1 deletion build/event/base-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/event/base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2014, KISSY v5.0.0
MIT Licensed
build time: Apr 10 19:03
build time: Apr 14 14:15
*/
/*
Combined modules by KISSY Module Compiler:
Expand Down
2 changes: 1 addition & 1 deletion build/event/custom-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/event/custom.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2014, KISSY v5.0.0
MIT Licensed
build time: Apr 10 19:03
build time: Apr 14 14:15
*/
/*
Combined modules by KISSY Module Compiler:
Expand Down
2 changes: 1 addition & 1 deletion build/event/dom/base-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/event/dom/base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2014, KISSY v5.0.0
MIT Licensed
build time: Apr 10 19:03
build time: Apr 14 14:15
*/
/*
Combined modules by KISSY Module Compiler:
Expand Down
2 changes: 1 addition & 1 deletion build/event/dom/focusin-min.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2014, KISSY v5.0.0
MIT Licensed
build time: Apr 10 19:03
build time: Apr 14 14:15
*/
KISSY.add("event/dom/focusin",["event/dom/base"],function(d,g){var e=g("event/dom/base"),h=e.Special;d.each([{name:"focusin",fix:"focus"},{name:"focusout",fix:"blur"}],function(c){function f(a){return e.fire(a.target,c.name)}var b=d.guid("attaches_"+d.now()+"_");h[c.name]={setup:function(){var a=this.ownerDocument||this;b in a||(a[b]=0);a[b]+=1;1===a[b]&&a.addEventListener(c.fix,f,!0)},tearDown:function(){var a=this.ownerDocument||this;a[b]-=1;0===a[b]&&a.removeEventListener(c.fix,f,!0)}}});return e});
2 changes: 1 addition & 1 deletion build/event/dom/focusin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2014, KISSY v5.0.0
MIT Licensed
build time: Apr 10 19:03
build time: Apr 14 14:15
*/
/*
Combined modules by KISSY Module Compiler:
Expand Down
2 changes: 1 addition & 1 deletion build/event/dom/hashchange-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/event/dom/hashchange.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2014, KISSY v5.0.0
MIT Licensed
build time: Apr 10 19:03
build time: Apr 14 14:15
*/
/*
Combined modules by KISSY Module Compiler:
Expand Down
2 changes: 1 addition & 1 deletion build/event/dom/ie-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/event/dom/ie.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2014, KISSY v5.0.0
MIT Licensed
build time: Apr 10 19:03
build time: Apr 14 14:15
*/
/*
Combined modules by KISSY Module Compiler:
Expand Down
2 changes: 1 addition & 1 deletion build/event/dom/input-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/event/dom/input.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2014, KISSY v5.0.0
MIT Licensed
build time: Apr 10 19:03
build time: Apr 14 14:15
*/
/*
Combined modules by KISSY Module Compiler:
Expand Down
4 changes: 2 additions & 2 deletions build/event/gesture/base-min.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2014, KISSY v5.0.0
MIT Licensed
build time: Apr 10 19:04
build time: Apr 14 14:15
*/
KISSY.add("event/gesture/base",["event/dom/base","event/gesture/util"],function(f,a){function c(b,c){var a={isActive:1};a[c]=function(a){d.fire(a.target,b,a)};e(b,{order:1,handle:a})}var d=a("event/dom/base"),e=a("event/gesture/util").addEvent,b={START:"gestureStart",MOVE:"gestureMove",END:"gestureEnd"};c(b.START,"onTouchStart");c(b.MOVE,"onTouchMove");c(b.END,"onTouchEnd");return b});
KISSY.add("event/gesture/base",["event/dom/base","event/gesture/util"],function(f,a){function c(b,c){var a={isActive:1};a[c]=function(a){d.fire(a.target,b,a)};e(b,{order:1,handle:a})}var d=a("event/dom/base"),e=a("event/gesture/util").addEvent,b={START:"ksGestureStart",MOVE:"ksGestureMove",END:"ksGestureEnd"};c(b.START,"onTouchStart");c(b.MOVE,"onTouchMove");c(b.END,"onTouchEnd");return b});
4 changes: 2 additions & 2 deletions build/event/gesture/base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2014, KISSY v5.0.0
MIT Licensed
build time: Apr 10 19:04
build time: Apr 14 14:15
*/
/*
Combined modules by KISSY Module Compiler:
Expand All @@ -13,7 +13,7 @@ KISSY.add("event/gesture/base", ["event/dom/base", "event/gesture/util"], functi
var DomEvent = require("event/dom/base");
var GestureUtil = require("event/gesture/util");
var addGestureEvent = GestureUtil.addEvent;
var BaseGesture = {START:"gestureStart", MOVE:"gestureMove", END:"gestureEnd"};
var BaseGesture = {START:"ksGestureStart", MOVE:"ksGestureMove", END:"ksGestureEnd"};
function addBaseGestureEvent(event, onHandler) {
var handle = {isActive:1};
handle[onHandler] = function(e) {
Expand Down
10 changes: 5 additions & 5 deletions build/event/gesture/drag-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions build/event/gesture/drag.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2014, KISSY v5.0.0
MIT Licensed
build time: Apr 10 19:04
build time: Apr 14 14:15
*/
/*
Combined modules by KISSY Module Compiler:
Expand All @@ -14,7 +14,7 @@ KISSY.add("event/gesture/drag", ["event/gesture/util", "event/dom/base"], functi
var addGestureEvent = GestureUtil.addEvent;
var DomEvent = require("event/dom/base");
var SingleTouch = GestureUtil.SingleTouch;
var DRAG_START = "gestureDragStart", DRAG_END = "gestureDragEnd", DRAG = "gestureDrag", SAMPLE_INTERVAL = 300, MIN_DISTANCE = 3;
var DRAG_START = "ksDragStart", DRAG_END = "ksDragEnd", DRAGGING = "ksDragging", DRAG = "ksDrag", SAMPLE_INTERVAL = 300, MIN_DISTANCE = 3;
var doc = document;
function getDistance(p1, p2) {
var deltaX = p1.pageX - p2.pageX, deltaY = p1.pageY - p2.pageY;
Expand All @@ -23,6 +23,15 @@ KISSY.add("event/gesture/drag", ["event/gesture/util", "event/dom/base"], functi
function startDrag(self, e) {
var currentTouch = self.lastTouches[0];
var startPos = self.startPos;
if(!self.direction) {
var deltaX = e.pageX - self.startPos.pageX, deltaY = e.pageY - self.startPos.pageY, absDeltaX = Math.abs(deltaX), absDeltaY = Math.abs(deltaY);
if(absDeltaX > absDeltaY) {
self.direction = deltaX < 0 ? "left" : "right"
}else {
self.direction = deltaY < 0 ? "up" : "down"
}
}
DomEvent.fire(self.dragTarget, DRAGGING, getEventObject(self, e));
if(getDistance(currentTouch, startPos) > MIN_DISTANCE) {
if(self.isStarted) {
sample(self, e)
Expand Down Expand Up @@ -56,6 +65,7 @@ KISSY.add("event/gesture/drag", ["event/gesture/util", "event/dom/base"], functi
ret.startPos = self.startPos;
ret.touch = currentTouch;
ret.gestureType = e.gestureType;
ret.direction = self.direction;
return ret
}
function Drag() {
Expand All @@ -66,7 +76,8 @@ KISSY.add("event/gesture/drag", ["event/gesture/util", "event/dom/base"], functi
var touch = self.lastTouches[0];
self.lastTime = self.startTime;
self.dragTarget = touch.target;
self.startPos = self.lastPos = {pageX:touch.pageX, pageY:touch.pageY}
self.startPos = self.lastPos = {pageX:touch.pageX, pageY:touch.pageY};
self.direction = null
}, move:function(e) {
var self = this;
Drag.superclass.move.apply(self, arguments);
Expand All @@ -88,6 +99,6 @@ KISSY.add("event/gesture/drag", ["event/gesture/util", "event/dom/base"], functi
}
}});
addGestureEvent([DRAG_START, DRAG, DRAG_END], {handle:new Drag});
return{DRAG_START:DRAG_START, DRAG:DRAG, DRAG_END:DRAG_END}
return{DRAGGING:DRAGGING, DRAG_START:DRAG_START, DRAG:DRAG, DRAG_END:DRAG_END}
});

Loading

0 comments on commit 6b1efac

Please sign in to comment.