Skip to content

Commit

Permalink
Merge pull request #148 from xieyu33333/master
Browse files Browse the repository at this point in the history
fix desktop dependence bug
  • Loading branch information
xieyu33333 committed Jan 25, 2015
2 parents b6f793b + cc6bc7e commit c1cd61b
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ node_modules/
output/
test/
.idea/
npm-debug.log


45 changes: 29 additions & 16 deletions build/islider.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,20 @@ iSlider = function () {
};
};
/**
* bind all event handler
* bind all event handler, when on PC, disable drag event。
*/
iSlider.prototype._bindHandler = function () {
var outer = this.outer;
var device = this._device();
if (!device.hasTouch) {
outer.style.cursor = 'pointer';
outer.ondragstart = function (evt) {
if (evt) {
return false;
}
return true;
};
}
outer.addEventListener(device.startEvt, this);
outer.addEventListener(device.moveEvt, this);
outer.addEventListener(device.endEvt, this);
Expand Down Expand Up @@ -390,14 +399,15 @@ iSlider = function () {
* uniformity admin event
*/
iSlider.prototype.handleEvent = function (evt) {
var device = this._device();
switch (evt.type) {
case 'touchstart' || 'mousedown':
case device.startEvt:
this.startHandler(evt);
break;
case 'touchmove' || 'mousemove':
case device.moveEvt:
this.moveHandler(evt);
break;
case 'touchend' || 'mouseup':
case device.endEvt:
this.endHandler(evt);
break;
case 'orientationchange':
Expand Down Expand Up @@ -737,19 +747,22 @@ plugins_islider_zoom = function (iSlider) {
}
function moveHandler(evt) {
var result = 0, node = this.zoomNode;
if (evt.targetTouches.length == 2 && this.useZoom) {
node.style.webkitTransitionDuration = '0';
evt.preventDefault();
this._scaleImage(evt);
result = 2;
} else if (evt.targetTouches.length == 1 && this.useZoom && this.currentScale > 1) {
node.style.webkitTransitionDuration = '0';
evt.preventDefault();
this._moveImage(evt);
result = 1;
var device = this._device();
if (device.hasTouch) {
if (evt.targetTouches.length === 2 && this.useZoom) {
node.style.webkitTransitionDuration = '0';
evt.preventDefault();
this._scaleImage(evt);
result = 2;
} else if (evt.targetTouches.length == 1 && this.useZoom && this.currentScale > 1) {
node.style.webkitTransitionDuration = '0';
evt.preventDefault();
this._moveImage(evt);
result = 1;
}
this.gesture = result;
return result;
}
this.gesture = result;
return result;
}
function handleDoubleTap(evt) {
var zoomFactor = this.zoomFactor || 2;
Expand Down
18 changes: 14 additions & 4 deletions build/islider_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,20 @@ iSlider = function () {
};
};
/**
* bind all event handler
* bind all event handler, when on PC, disable drag event。
*/
iSlider.prototype._bindHandler = function () {
var outer = this.outer;
var device = this._device();
if (!device.hasTouch) {
outer.style.cursor = 'pointer';
outer.ondragstart = function (evt) {
if (evt) {
return false;
}
return true;
};
}
outer.addEventListener(device.startEvt, this);
outer.addEventListener(device.moveEvt, this);
outer.addEventListener(device.endEvt, this);
Expand Down Expand Up @@ -390,14 +399,15 @@ iSlider = function () {
* uniformity admin event
*/
iSlider.prototype.handleEvent = function (evt) {
var device = this._device();
switch (evt.type) {
case 'touchstart' || 'mousedown':
case device.startEvt:
this.startHandler(evt);
break;
case 'touchmove' || 'mousemove':
case device.moveEvt:
this.moveHandler(evt);
break;
case 'touchend' || 'mouseup':
case device.endEvt:
this.endHandler(evt);
break;
case 'orientationchange':
Expand Down
45 changes: 29 additions & 16 deletions demo/public/js/islider.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,20 @@ iSlider = function () {
};
};
/**
* bind all event handler
* bind all event handler, when on PC, disable drag event。
*/
iSlider.prototype._bindHandler = function () {
var outer = this.outer;
var device = this._device();
if (!device.hasTouch) {
outer.style.cursor = 'pointer';
outer.ondragstart = function (evt) {
if (evt) {
return false;
}
return true;
};
}
outer.addEventListener(device.startEvt, this);
outer.addEventListener(device.moveEvt, this);
outer.addEventListener(device.endEvt, this);
Expand Down Expand Up @@ -390,14 +399,15 @@ iSlider = function () {
* uniformity admin event
*/
iSlider.prototype.handleEvent = function (evt) {
var device = this._device();
switch (evt.type) {
case 'touchstart' || 'mousedown':
case device.startEvt:
this.startHandler(evt);
break;
case 'touchmove' || 'mousemove':
case device.moveEvt:
this.moveHandler(evt);
break;
case 'touchend' || 'mouseup':
case device.endEvt:
this.endHandler(evt);
break;
case 'orientationchange':
Expand Down Expand Up @@ -737,19 +747,22 @@ plugins_islider_zoom = function (iSlider) {
}
function moveHandler(evt) {
var result = 0, node = this.zoomNode;
if (evt.targetTouches.length == 2 && this.useZoom) {
node.style.webkitTransitionDuration = '0';
evt.preventDefault();
this._scaleImage(evt);
result = 2;
} else if (evt.targetTouches.length == 1 && this.useZoom && this.currentScale > 1) {
node.style.webkitTransitionDuration = '0';
evt.preventDefault();
this._moveImage(evt);
result = 1;
var device = this._device();
if (device.hasTouch) {
if (evt.targetTouches.length === 2 && this.useZoom) {
node.style.webkitTransitionDuration = '0';
evt.preventDefault();
this._scaleImage(evt);
result = 2;
} else if (evt.targetTouches.length == 1 && this.useZoom && this.currentScale > 1) {
node.style.webkitTransitionDuration = '0';
evt.preventDefault();
this._moveImage(evt);
result = 1;
}
this.gesture = result;
return result;
}
this.gesture = result;
return result;
}
function handleDoubleTap(evt) {
var zoomFactor = this.zoomFactor || 2;
Expand Down
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
{
"name": "iSlider",
"version": "1.0.0",
"name": "islider",
"version": "1.1.1",
"author": "qbatyqi",
"main": "build/islider.js",
"description": "Smooth mobile touch slider for Mobile WebApp, HTML5 App, Hybrid App",
"devDependencies": {
"gulp": "~3.8.9",
"amdclean": "~2.4.0",
"gulp-uglify": "~1.0.1",
"gulp-rename": "x",
"requirejs": "x",
"gulp-connect": "~2.2.0"
},
"repository": {
"type": "git",
"url": "[email protected]:BE-FE/iSlider.git"
},
"keywords": [
"monile",
"islider.js",
"javascript"
],
"bugs": {
"url": "https://github.com/BE-FE/iSlider/issues",
"email" : "[email protected]"
}
}
18 changes: 14 additions & 4 deletions src/islider_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,20 @@ define('iSlider', [], function(){
};

/**
* bind all event handler
* bind all event handler, when on PC, disable drag event。
*/
iSlider.prototype._bindHandler = function() {
var outer = this.outer;
var device = this._device();
if (!device.hasTouch) {
outer.style.cursor = 'pointer';
outer.ondragstart = function(evt){
if(evt) {
return false;
}
return true;
}
}
outer.addEventListener(device.startEvt, this);
outer.addEventListener(device.moveEvt, this);
outer.addEventListener(device.endEvt, this);
Expand Down Expand Up @@ -433,14 +442,15 @@ define('iSlider', [], function(){
* uniformity admin event
*/
iSlider.prototype.handleEvent = function(evt){
var device = this._device();
switch (evt.type) {
case 'touchstart' || 'mousedown':
case device.startEvt:
this.startHandler(evt);
break;
case 'touchmove' || 'mousemove':
case device.moveEvt:
this.moveHandler(evt);
break;
case 'touchend' || 'mouseup':
case device.endEvt:
this.endHandler(evt);
break;
case 'orientationchange':
Expand Down
27 changes: 15 additions & 12 deletions src/plugins/islider_zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,22 @@ define(['iSlider'], function (iSlider) {

function moveHandler(evt) {
var result = 0, node = this.zoomNode;
if (evt.targetTouches.length == 2 && this.useZoom) {
node.style.webkitTransitionDuration = "0";
evt.preventDefault();
this._scaleImage(evt);
result = 2;
} else if (evt.targetTouches.length == 1 && this.useZoom && this.currentScale > 1) {
node.style.webkitTransitionDuration = "0";
evt.preventDefault();
this._moveImage(evt);
result = 1;
var device = this._device();
if (device.hasTouch) {
if (evt.targetTouches.length === 2 && this.useZoom) {
node.style.webkitTransitionDuration = "0";
evt.preventDefault();
this._scaleImage(evt);
result = 2;
} else if (evt.targetTouches.length == 1 && this.useZoom && this.currentScale > 1) {
node.style.webkitTransitionDuration = "0";
evt.preventDefault();
this._moveImage(evt);
result = 1;
}
this.gesture = result;
return result;
}
this.gesture = result;
return result;

}

Expand Down

0 comments on commit c1cd61b

Please sign in to comment.