Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After touchend event, resuming auto slide #468

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
##Fixed Issues(By Jinlong)
已修复问题

After touchend event, resuming Swipe's auto slide.
touchend 触发以后,恢复 Swipe 组件的自动轮播。

1. Compatible with api.setRefreshHeaderInfo (APICloud's method),兼容 APICloud 的 api.setRefreshHeaderInfo(下拉刷新组件),处理 JS 交互事件与 Native 事件的冲突
2. Compatible with api.openSlidLayout (APICloud's method),兼容 APICloud 的 api.openSlidLayout(侧滑布局模块),处理 JS 交互事件与 Native 事件的冲突
3. Compatible with api.openFrameGroup (APICloud's method),兼容 APICloud 的 api.openFrameGroup(子窗口组模块),处理 JS 交互事件与 Native 事件的冲突


## Usage
Swipe only needs to follow a simple pattern. Here is an example:

Expand Down Expand Up @@ -58,6 +69,16 @@ Swipe can take an optional second parameter– an object of key/value settings:

- **transitionEnd** Function - runs at the end slide transition.

- **compatWithPullToRefresh** 布尔型 - 是否兼容 APICloud 的 api.setRefreshHeaderInfo,默认为 false

- **frameName** 字符串 - 带有下拉刷新组件的 frame 的名字,当 compatWithPullToRefresh 为 true 时,需要传此参数

- **compatWithSlidLayout** 布尔型 - 是否兼容 APICloud 的 api.openSlidLayout,默认为 false

- **compatWithFrameGroup** 布尔型 - 是否兼容 APICloud 的 api.openFrameGroup,默认为 false

- **frameGroupName** 字符串 - frameGroup 组件的名字,当 compatWithFrameGroup 为 true 时,需要传此参数

### Example

``` js
Expand All @@ -70,7 +91,12 @@ window.mySwipe = new Swipe(document.getElementById('slider'), {
disableScroll: false,
stopPropagation: false,
callback: function(index, elem) {},
transitionEnd: function(index, elem) {}
transitionEnd: function(index, elem) {},
compatWithPullToRefresh: true,
frameName: 'frameName',
compatWithSlidLayout: true,
compatWithFrameGroup: true,
frameGroupName: 'frameGroupName'
});

```
Expand All @@ -92,15 +118,5 @@ Swipe exposes a few functions that can be useful for script control of your slid
## Browser Support
Swipe is now compatible with all browsers, including IE7+. Swipe works best on devices that support CSS transforms and touch, but can be used without these as well. A few helper methods determine touch and CSS transition support and choose the proper animation methods accordingly.

## Who's using Swipe
<img src='http://swipejs.com/assets/swipe-cnn.png' width='170'>
<img src='http://swipejs.com/assets/swipe-airbnb.png' width='170'>
<img src='http://swipejs.com/assets/swipe-nhl.png' width='170'>
<img src='http://swipejs.com/assets/swipe-htc.png' width='170'>
<img src='http://swipejs.com/assets/swipe-thinkgeek.png' width='170'>
<img src='http://swipejs.com/assets/swipe-snapguide.png' width='170'>

Shoot me a [note](mailto:[email protected]) if you want your logo here

## License
Copyright (c) 2013 Brad Birdsall Licensed under the [The MIT License (MIT)](http://opensource.org/licenses/MIT).
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h1>Swipe 2</h1>



<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="jquery-1.11.2.min.js"></script>
<script src='swipe.js'></script>
<script>

Expand Down
4 changes: 4 additions & 0 deletions jquery-1.11.2.min.js

Large diffs are not rendered by default.

66 changes: 61 additions & 5 deletions swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ function Swipe(container, options) {
var speed = options.speed || 300;
options.continuous = options.continuous !== undefined ? options.continuous : true;

//add by jinlong | [email protected]
//compatible with api.setRefreshHeaderInfo (APICloud's method)
options.compatWithPullToRefresh = options.compatWithPullToRefresh || false;
options.frameName = options.frameName || null;

//compatible with api.openSlidLayout (APICloud's method)
options.compatWithSlidLayout = options.compatWithSlidLayout || false;

//compatible with api.openFrameGroup (APICloud's method)
options.compatWithFrameGroup = options.compatWithFrameGroup || false;
options.frameGroupName = options.frameGroupName || null;

function setup() {

// cache slides
Expand Down Expand Up @@ -94,7 +106,6 @@ function Swipe(container, options) {
}

function next() {

if (options.continuous) slide(index+1);
else if (index < slides.length - 1) slide(index+1);

Expand Down Expand Up @@ -243,6 +254,7 @@ function Swipe(container, options) {
switch (event.type) {
case 'touchstart': this.start(event); break;
case 'touchmove': this.move(event); break;
//modify by jinlong | [email protected]
case 'touchend': offloadFn(this.end(event)); break;
case 'webkitTransitionEnd':
case 'msTransitionEnd':
Expand All @@ -256,7 +268,27 @@ function Swipe(container, options) {

},
start: function(event) {

//add by jinlong | [email protected]
if(options.compatWithPullToRefresh){
if(options.frameName){
api.setFrameAttr({
name: options.frameName,
bounces: false
});
}
}
if(options.compatWithSlidLayout){
api.lockSlidPane();
}
if(options.compatWithFrameGroup){
if(options.frameGroupName){
api.setFrameGroupAttr({
name: options.frameGroupName,
scrollEnabled: false
});
}
}

var touches = event.touches[0];

// measure start values
Expand Down Expand Up @@ -339,6 +371,26 @@ function Swipe(container, options) {

},
end: function(event) {
//add by jinlong | [email protected]
if(options.compatWithPullToRefresh){
if(options.frameName){
api.setFrameAttr({
name: options.frameName,
bounces: true
});
}
}
if(options.compatWithSlidLayout){
api.unlockSlidPane();
}
if(options.compatWithFrameGroup){
if(options.frameGroupName){
api.setFrameGroupAttr({
name: options.frameGroupName,
scrollEnabled: true
});
}
}

// measure duration
var duration = +new Date - start.time;
Expand Down Expand Up @@ -417,8 +469,12 @@ function Swipe(container, options) {
}

// kill touchmove and touchend event listeners until touchstart called again
element.removeEventListener('touchmove', events, false)
element.removeEventListener('touchend', events, false)
element.removeEventListener('touchmove', events, false);
element.removeEventListener('touchend', events, false);

//add by jinlong | [email protected]
//resume slide
delay = options.auto;

},
transitionEnd: function(event) {
Expand Down Expand Up @@ -461,7 +517,7 @@ function Swipe(container, options) {

} else {

window.onresize = function () { setup() }; // to play nice with old IE
window.onresize = function () { setup()}; // to play nice with old IE

}

Expand Down