diff --git a/.gitignore b/.gitignore index 6b319f8..365a945 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store -*-min.js \ No newline at end of file +*-min.js +/node_modules/ \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..d782015 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,42 @@ +module.exports = function(grunt) { + + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + connect: { + server: { + options: { + base: "", + port: 9999 + } + } + }, + uglify: { + options: { + banner: '/*! <%= pkg.name %> <%= pkg.version %> - <%= pkg.description %> */\n' + }, + build: { + src: 'src/<%= pkg.name %>.js', + dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.min.js' + } + }, + jshint: { + all: { + src: ['src/<%= pkg.name %>.js'] + } + }, + watch: { + all: { + files: ['src/*.js', 'demo/*/*.js'], + tasks: ['default', 'dev'] + } + } + }); + + grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks('grunt-contrib-connect'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + + grunt.registerTask('default', ['jshint', 'uglify']); + grunt.registerTask("dev", ["connect", "watch"]); +}; diff --git a/README.md b/README.md index f1c7a95..0b0c307 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,16 @@ -SwipeView v1.0 - 2012-08-25 -============================ +SwipeView v1.3.0 - 2013-09-28 +============================= + +- the SwipeView instanciation does not auto-bind anymore +- Add bind() and unbind() +- the old unbind() has been renamed to offAll() + +SwipeView v1.0.5 - 2013-07-04 +============================= + +Modified version of Matteo's SwipeView which allows vertical swipe (with the `vertical` option) and also allows multiple SwipeViews in the same document: + +example: Multiple SwipeViews in the same document + vertical swipe: [http://peutetre.github.io/SwipeView/demo/gallery7/](http://peutetre.github.io/SwipeView/demo/gallery7/) Virtually infinite loop-able horizontal carousel for desktop and mobile browsers. @@ -11,4 +22,4 @@ eReader Demo: [http://cubiq.org/dropbox/SwipeView/demo/ereader](http://cubiq.org Inline Demo: [http://cubiq.org/dropbox/SwipeView/demo/inline](http://cubiq.org/dropbox/SwipeView/demo/inline) -Screencast: [http://www.youtube.com/watch?v=Hhes5JHs8jQ](http://www.youtube.com/watch?v=Hhes5JHs8jQ) \ No newline at end of file +Screencast: [http://www.youtube.com/watch?v=Hhes5JHs8jQ](http://www.youtube.com/watch?v=Hhes5JHs8jQ) diff --git a/demo/ereader/index.html b/demo/ereader/index.html index d6dec0d..2351857 100644 --- a/demo/ereader/index.html +++ b/demo/ereader/index.html @@ -21,6 +21,7 @@ req = new XMLHttpRequest(); ereader = new SwipeView('#wrapper', { hastyPageFlip:true }); + ereader.bind(); // Ajax request req.open('GET', 'flowers.txt', true); @@ -154,4 +155,4 @@
- \ No newline at end of file + diff --git a/demo/gallery/index.html b/demo/gallery/index.html index 8feb43b..bac9e0d 100644 --- a/demo/gallery/index.html +++ b/demo/gallery/index.html @@ -71,6 +71,7 @@ ]; gallery = new SwipeView('#wrapper', { numberOfPages: slides.length }); +gallery.bind(); // Load initial data for (i=0; i<3; i++) { @@ -81,6 +82,10 @@ el.width = slides[page].width; el.height = slides[page].height; el.onload = function () { this.className = ''; } + // fixes for IE + el.setAttribute("unselectable", "on"); + el.ondragstart = function() { return false; }; + gallery.masterPages[i].appendChild(el); el = document.createElement('span'); @@ -123,4 +128,4 @@ - \ No newline at end of file + diff --git a/demo/gallery/style.css b/demo/gallery/style.css index c1217be..229f0f6 100644 --- a/demo/gallery/style.css +++ b/demo/gallery/style.css @@ -72,7 +72,7 @@ body { background:rgba(255,255,255,0.4); } -#swipeview-slider > div { +.swipeview-slider > div { position:relative; display:-webkit-box; display:-moz-box; @@ -97,7 +97,7 @@ body { overflow:hidden; } -#swipeview-slider img { +.swipeview-slider img { display:block; border:5px solid #eee; -webkit-box-shadow:0 2px 6px #000; @@ -124,7 +124,7 @@ body { pointer-events:none; } -#swipeview-slider span { +.swipeview-slider span { position:absolute; bottom:0; left:0; @@ -165,7 +165,7 @@ body { transform:translate(0,100%) translateZ(0); } -#swipeview-slider .swipeview-active span { +.swipeview-slider .swipeview-active span { -webkit-transform:translate(0,0) translateZ(0); -moz-transform:translate(0,0) translateZ(0); -ms-transform:translate(0,0); @@ -184,7 +184,7 @@ body { } #wrapper > div > .swipeview-loading img, -#swipeview-slider img.loading { +.swipeview-slider img.loading { -webkit-transition-duration:0s; opacity:0; } @@ -202,4 +202,4 @@ body { -o-transform:translate(0,100%); -o-transform:translate(0,100%) translateZ(0); transform:translate(0,100%) translateZ(0); -} \ No newline at end of file +} diff --git a/demo/gallery2/index.html b/demo/gallery2/index.html new file mode 100644 index 0000000..7beef62 --- /dev/null +++ b/demo/gallery2/index.html @@ -0,0 +1,117 @@ + + + + + + + + SwipeView + + + + + +
+
+
+
+
+ + + + diff --git a/demo/gallery2/style.css b/demo/gallery2/style.css new file mode 100644 index 0000000..8f9b852 --- /dev/null +++ b/demo/gallery2/style.css @@ -0,0 +1,83 @@ +html, body { height:100%; } +body { + padding:0; + margin:0; + background:#333; + -webkit-user-select:none; + -moz-user-select:none; + -ms-user-select:none; + -o-user-select:none; + user-select:none; + -webkit-text-size-adjust:none; + -moz-text-size-adjust:none; + -ms-text-size-adjust:none; + -o-text-size-adjust:none; + text-size-adjust:none; + color:#eee; + font-family:helvetica; + font-size:12px; +} + +.wrapper { + width:1024px; + min-width:320px; + height:145px; + margin:10px auto; + border: 5px solid rgb(43, 38, 38); +} + +.swipeview-slider > div { + position:relative; + display:-webkit-box; + display:-moz-box; + display:-ms-box; + display:-o-box; + display:box; + -webkit-box-orient:vertical; + -moz-box-orient:vertical; + -ms-box-orient:vertical; + -o-box-orient:vertical; + box-orient:vertical; + -webkit-box-pack:center; + -moz-box-pack:center; + -ms-box-pack:center; + -o-box-pack:center; + box-pack:center; + -webkit-box-align:center; + -mox-box-align:center; + -ms-box-align:center; + -o-box-align:center; + box-align:center; + overflow:hidden; +} + +.swipeview-slider img { + display:block; + -webkit-transition-duration:.4s; + -moz-transition-duration:.4s; + -ms-transition-duration:.4s; + -o-transition-duration:.4s; + transition-duration:.4s; + -webkit-transition-property:opacity; + -moz-transition-property:opacity; + -ms-transition-property:opacity; + -o-transition-property:opacity; + transition-property:opacity; + opacity:1; + pointer-events:none; + visibility:visible; +} + +.swipeview-slider .set-container { + margin:auto; +} + +.swipeview-slider .container { + background: rgb(197, 197, 197); + float: left; + margin: 0 5px; +} + +.swipeview-slider img.loading { + visibility:hidden; +} diff --git a/demo/gallery3/index.html b/demo/gallery3/index.html new file mode 100644 index 0000000..1f84acb --- /dev/null +++ b/demo/gallery3/index.html @@ -0,0 +1,56 @@ + + + + + + + + SwipeView + + + + + + +
+
+
+
+
+ + + + diff --git a/demo/gallery3/infinitegraphset.js b/demo/gallery3/infinitegraphset.js new file mode 100644 index 0000000..7486003 --- /dev/null +++ b/demo/gallery3/infinitegraphset.js @@ -0,0 +1,70 @@ +/* + * infinitegraphset.js + */ +(function (win, doc) { + + function InfiniteGraphSet(id, dataO) { + var gallery = new SwipeView(id, { + hastyPageFlip:true, + numberOfPages: dataO.length + }), i, page; + gallery.bind(); + + function genImgs(container, page, d) { + var img, div; + for(var i=0; i< 5; i++) { + div = doc.createElement('div'); + div.className = 'container'; + img = doc.createElement('img'); + img.className = 'loading'; + img.src = d.get(page).imgs[i]; + img.width = d.get(page).width; + img.height = d.get(page).height; + div.style.width = d.get(page).width + "px"; + div.style.height = d.get(page).height + "px"; + img.onload = function () { this.className = ''; } + // fixes for IE + img.setAttribute("unselectable", "on"); + img.ondragstart = function() { return false; }; + div.appendChild(img); + container.appendChild(div); + } + } + + for(i=0; i<3; i++) { + page = i==0 ? dataO.length-1 : i-1; + div = doc.createElement('div'); + div.className = 'set-container'; + genImgs(div, page, dataO); + gallery.masterPages[i].appendChild(div); + } + + function setImg(el, src) { + el.className = 'loading'; + el.src = src; + el.onload = function () { this.className = ''; } + } + + gallery.onFlip(function () { + var el, + upcoming, + i; + + for (i=0; i<3; i++) { + upcoming = gallery.masterPages[i].dataset.upcomingPageIndex; + + if (upcoming != gallery.masterPages[i].dataset.pageIndex) { + els = gallery.masterPages[i].querySelectorAll('img'); + setImg(els[0], dataO.get(upcoming).imgs[0]); + setImg(els[1], dataO.get(upcoming).imgs[1]); + setImg(els[2], dataO.get(upcoming).imgs[2]); + setImg(els[3], dataO.get(upcoming).imgs[3]); + setImg(els[4], dataO.get(upcoming).imgs[4]); + } + } + }); + return gallery; + } + + win.InfiniteGraphSet = InfiniteGraphSet; +})(window, window.document); diff --git a/demo/gallery3/style.css b/demo/gallery3/style.css new file mode 100644 index 0000000..8f9b852 --- /dev/null +++ b/demo/gallery3/style.css @@ -0,0 +1,83 @@ +html, body { height:100%; } +body { + padding:0; + margin:0; + background:#333; + -webkit-user-select:none; + -moz-user-select:none; + -ms-user-select:none; + -o-user-select:none; + user-select:none; + -webkit-text-size-adjust:none; + -moz-text-size-adjust:none; + -ms-text-size-adjust:none; + -o-text-size-adjust:none; + text-size-adjust:none; + color:#eee; + font-family:helvetica; + font-size:12px; +} + +.wrapper { + width:1024px; + min-width:320px; + height:145px; + margin:10px auto; + border: 5px solid rgb(43, 38, 38); +} + +.swipeview-slider > div { + position:relative; + display:-webkit-box; + display:-moz-box; + display:-ms-box; + display:-o-box; + display:box; + -webkit-box-orient:vertical; + -moz-box-orient:vertical; + -ms-box-orient:vertical; + -o-box-orient:vertical; + box-orient:vertical; + -webkit-box-pack:center; + -moz-box-pack:center; + -ms-box-pack:center; + -o-box-pack:center; + box-pack:center; + -webkit-box-align:center; + -mox-box-align:center; + -ms-box-align:center; + -o-box-align:center; + box-align:center; + overflow:hidden; +} + +.swipeview-slider img { + display:block; + -webkit-transition-duration:.4s; + -moz-transition-duration:.4s; + -ms-transition-duration:.4s; + -o-transition-duration:.4s; + transition-duration:.4s; + -webkit-transition-property:opacity; + -moz-transition-property:opacity; + -ms-transition-property:opacity; + -o-transition-property:opacity; + transition-property:opacity; + opacity:1; + pointer-events:none; + visibility:visible; +} + +.swipeview-slider .set-container { + margin:auto; +} + +.swipeview-slider .container { + background: rgb(197, 197, 197); + float: left; + margin: 0 5px; +} + +.swipeview-slider img.loading { + visibility:hidden; +} diff --git a/demo/gallery4/images/pic01.jpg b/demo/gallery4/images/pic01.jpg new file mode 100644 index 0000000..97dd265 Binary files /dev/null and b/demo/gallery4/images/pic01.jpg differ diff --git a/demo/gallery4/images/pic02.jpg b/demo/gallery4/images/pic02.jpg new file mode 100644 index 0000000..c496c74 Binary files /dev/null and b/demo/gallery4/images/pic02.jpg differ diff --git a/demo/gallery4/images/pic03.jpg b/demo/gallery4/images/pic03.jpg new file mode 100644 index 0000000..ae8f453 Binary files /dev/null and b/demo/gallery4/images/pic03.jpg differ diff --git a/demo/gallery4/images/pic04.jpg b/demo/gallery4/images/pic04.jpg new file mode 100644 index 0000000..60d601c Binary files /dev/null and b/demo/gallery4/images/pic04.jpg differ diff --git a/demo/gallery4/images/pic05.jpg b/demo/gallery4/images/pic05.jpg new file mode 100644 index 0000000..4b4cbc7 Binary files /dev/null and b/demo/gallery4/images/pic05.jpg differ diff --git a/demo/gallery4/images/pic06.jpg b/demo/gallery4/images/pic06.jpg new file mode 100644 index 0000000..c942540 Binary files /dev/null and b/demo/gallery4/images/pic06.jpg differ diff --git a/demo/gallery4/index.html b/demo/gallery4/index.html new file mode 100644 index 0000000..983fa4d --- /dev/null +++ b/demo/gallery4/index.html @@ -0,0 +1,94 @@ + + + + + + + + SwipeView + + + + + +
+ + + + diff --git a/demo/gallery4/style.css b/demo/gallery4/style.css new file mode 100644 index 0000000..229f0f6 --- /dev/null +++ b/demo/gallery4/style.css @@ -0,0 +1,205 @@ +html, body { height:100%; } +body { + padding:0; + margin:0; + background:#333; + -webkit-user-select:none; + -moz-user-select:none; + -ms-user-select:none; + -o-user-select:none; + user-select:none; + -webkit-text-size-adjust:none; + -moz-text-size-adjust:none; + -ms-text-size-adjust:none; + -o-text-size-adjust:none; + text-size-adjust:none; + color:#eee; + font-family:helvetica; + font-size:12px; +} + +#wrapper { + width:100%; + min-width:320px; + height:100%; +} + +#nav { + position:absolute; + z-index:100; + top:8px; + width:200px; + height:20px; + left:50%; + background:rgba(0,0,0,0.75); + padding:0; + margin:0 0 0 -100px; + -webkit-border-radius:10px; + -moz-border-radius:10px; + -ms-border-radius:10px; + -o-border-radius:10px; + border-radius:10px; +} + +#nav li { + display:block; + float:left; + width:14px; + height:14px; line-height:14px; + -webkit-border-radius:7px; + -moz-border-radius:7px; + -ms-border-radius:7px; + -o-border-radius:7px; + border-radius:7px; + background:rgba(255,255,255,0.1); + overflow:hidden; + padding:0; + margin:3px 11px 0 0; + text-align:center; +} + +#nav li#prev { + margin-left:5px; + background:transparent; +} + +#nav li#next { + margin-right:0; + background:transparent; +} + +#nav li.selected { + background:rgba(255,255,255,0.4); +} + +.swipeview-slider > div { + position:relative; + display:-webkit-box; + display:-moz-box; + display:-ms-box; + display:-o-box; + display:box; + -webkit-box-orient:vertical; + -moz-box-orient:vertical; + -ms-box-orient:vertical; + -o-box-orient:vertical; + box-orient:vertical; + -webkit-box-pack:center; + -moz-box-pack:center; + -ms-box-pack:center; + -o-box-pack:center; + box-pack:center; + -webkit-box-align:center; + -mox-box-align:center; + -ms-box-align:center; + -o-box-align:center; + box-align:center; + overflow:hidden; +} + +.swipeview-slider img { + display:block; + border:5px solid #eee; + -webkit-box-shadow:0 2px 6px #000; + -moz-box-shadow:0 2px 6px #000; + -ms-box-shadow:0 2px 6px #000; + -o-box-shadow:0 2px 6px #000; + box-shadow:0 2px 6px #000; + -webkit-border-radius:2px; + -moz-border-radius:2px; + -ms-border-radius:2px; + -o-border-radius:2px; + border-radius:2px; + -webkit-transition-duration:.4s; + -moz-transition-duration:.4s; + -ms-transition-duration:.4s; + -o-transition-duration:.4s; + transition-duration:.4s; + -webkit-transition-property:opacity; + -moz-transition-property:opacity; + -ms-transition-property:opacity; + -o-transition-property:opacity; + transition-property:opacity; + opacity:1; + pointer-events:none; +} + +.swipeview-slider span { + position:absolute; + bottom:0; + left:0; + width:100%; + padding:20px 0; + display:block; + background:rgba(0,0,0,0.75); + font-size:20px; + text-align:center; + text-shadow:0 1px 0 #000; + border-top:1px solid rgba(255,255,255,0.2); + -webkit-border-top-left-radius:10px; + -moz-border-top-left-radius:10px; + -ms-border-top-left-radius:10px; + -o-border-top-left-radius:10px; + border-top-left-radius:10px; + -webkit-border-top-right-radius:10px; + -moz-border-top-right-radius:10px; + -ms-border-top-right-radius:10px; + -o-border-top-right-radius:10px; + border-top-right-radius:10px; + -webkit-transition-duration:.3s; + -moz-transition-duration:.3s; + -ms-transition-duration:.3s; + -o-transition-duration:.3s; + transition-duration:.3s; + -webkit-transition-property:-webkit-transform; + -moz-transition-property:-moz-transform; + -ms-transition-property:-ms-transform; + -o-transition-property:-o-transform; + transition-property:transform; + -webkit-transform:translate(0,100%) translateZ(0); + -moz-transform:translate(0,100%) translateZ(0); + -ms-transform:translate(0,100%); + -ms-transform:translate(0,100%) translateZ(0); + -o-transform:translate(0,100%); + -o-transform:translate(0,100%) translateZ(0); + transform:translate(0,100%) translateZ(0); +} + +.swipeview-slider .swipeview-active span { + -webkit-transform:translate(0,0) translateZ(0); + -moz-transform:translate(0,0) translateZ(0); + -ms-transform:translate(0,0); + -ms-transform:translate(0,0) translateZ(0); + -o-transform:translate(0,0); + -o-transform:translate(0,0) translateZ(0); + transform:translate(0,0) translateZ(0); +} + +#wrapper > div > .swipeview-loading { + background-image:-webkit-gradient(linear, 0 0, 0 100%, from(#444), to(#555)), + -webkit-gradient(linear, 0 0, 100% 0, from(#777), to(#777)); + background-position:50% 50%, 50% 50%; + background-size:200px 140px, 210px 150px; + background-repeat:no-repeat; +} + +#wrapper > div > .swipeview-loading img, +.swipeview-slider img.loading { + -webkit-transition-duration:0s; + opacity:0; +} + +#wrapper > div > .swipeview-loading span { + -webkit-transition-duration:0s; + -moz-transition-duration:0s; + -ms-transition-duration:0s; + -o-transition-duration:0s; + transition-duration:0s; + -webkit-transform:translate(0,100%) translateZ(0); + -moz-transform:translate(0,100%) translateZ(0); + -ms-transform:translate(0,100%); + -ms-transform:translate(0,100%) translateZ(0); + -o-transform:translate(0,100%); + -o-transform:translate(0,100%) translateZ(0); + transform:translate(0,100%) translateZ(0); +} diff --git a/demo/gallery5/index.html b/demo/gallery5/index.html new file mode 100644 index 0000000..7ed3a1e --- /dev/null +++ b/demo/gallery5/index.html @@ -0,0 +1,117 @@ + + + + + + + + SwipeView + + + + + + +
+ + + + diff --git a/demo/gallery5/infinitegraphset.js b/demo/gallery5/infinitegraphset.js new file mode 100644 index 0000000..b40c07f --- /dev/null +++ b/demo/gallery5/infinitegraphset.js @@ -0,0 +1,70 @@ +/* + * infinitegraphset.js + */ +(function (win, doc) { + + function InfiniteGraphSet(id, dataO) { + var gallery = new SwipeView(id, { + hastyPageFlip:true, + numberOfPages: dataO.length + }), i, page; + gallery.bind(); + + function genImgs(container, page, d) { + var img, div; + for(var i=0; i< 5; i++) { + div = doc.createElement('div'); + div.className = 'container'; + img = doc.createElement('img'); + img.className = 'loading'; + img.src = d.get(page).imgs[i]; + img.width = d.get(page).width; + img.height = d.get(page).height; + // fixes for IE + img.setAttribute("unselectable", "on"); + img.ondragstart = function() { return false; }; + div.style.width = d.get(page).width + "px"; + div.style.height = d.get(page).height + "px"; + img.onload = function () { this.className = ''; } + div.appendChild(img); + container.appendChild(div); + } + } + + for(i=0; i<3; i++) { + page = i==0 ? dataO.length-1 : i-1; + div = doc.createElement('div'); + div.className = 'set-container'; + genImgs(div, page, dataO); + gallery.masterPages[i].appendChild(div); + } + + function setImg(el, src) { + el.className = 'loading'; + el.src = src; + el.onload = function () { this.className = ''; } + } + + gallery.onFlip(function () { + var el, + upcoming, + i; + + for (i=0; i<3; i++) { + upcoming = gallery.masterPages[i].dataset.upcomingPageIndex; + + if (upcoming != gallery.masterPages[i].dataset.pageIndex) { + els = gallery.masterPages[i].querySelectorAll('img'); + setImg(els[0], dataO.get(upcoming).imgs[0]); + setImg(els[1], dataO.get(upcoming).imgs[1]); + setImg(els[2], dataO.get(upcoming).imgs[2]); + setImg(els[3], dataO.get(upcoming).imgs[3]); + setImg(els[4], dataO.get(upcoming).imgs[4]); + } + } + }); + return gallery; + } + + win.InfiniteGraphSet = InfiniteGraphSet; +})(window, window.document); diff --git a/demo/gallery5/style.css b/demo/gallery5/style.css new file mode 100644 index 0000000..8a119db --- /dev/null +++ b/demo/gallery5/style.css @@ -0,0 +1,89 @@ +html, body { height:100%; } +body { + padding:0; + margin:0; + background:#333; + -webkit-user-select:none; + -moz-user-select:none; + -ms-user-select:none; + -o-user-select:none; + user-select:none; + -webkit-text-size-adjust:none; + -moz-text-size-adjust:none; + -ms-text-size-adjust:none; + -o-text-size-adjust:none; + text-size-adjust:none; + color:#eee; + font-family:helvetica; + font-size:12px; +} + +#wrapper { + width:100%; + height:100%; + position:relative; +} + +.wrapper { + width:1024px; + min-width:320px; + height:145px; + margin:20px auto; + background-color: rgb(43, 38, 38); +} + +.swipeview-slider > div , .vertical-swipeview-slider > div{ + position:relative; + display:-webkit-box; + display:-moz-box; + display:-ms-box; + display:-o-box; + display:box; + -webkit-box-orient:vertical; + -moz-box-orient:vertical; + -ms-box-orient:vertical; + -o-box-orient:vertical; + box-orient:vertical; + -webkit-box-pack:center; + -moz-box-pack:center; + -ms-box-pack:center; + -o-box-pack:center; + box-pack:center; + -webkit-box-align:center; + -mox-box-align:center; + -ms-box-align:center; + -o-box-align:center; + box-align:center; + overflow:hidden; +} + +.swipeview-slider img { + display:block; + -webkit-transition-duration:.4s; + -moz-transition-duration:.4s; + -ms-transition-duration:.4s; + -o-transition-duration:.4s; + transition-duration:.4s; + -webkit-transition-property:opacity; + -moz-transition-property:opacity; + -ms-transition-property:opacity; + -o-transition-property:opacity; + transition-property:opacity; + opacity:1; + pointer-events:none; + visibility:visible; +} + +.swipeview-slider .set-container { + margin:auto; +} + +.swipeview-slider .container { + background: rgb(197, 197, 197); + float: left; + margin: 0 5px; +} + +.swipeview-slider img.loading { + visibility:hidden; +} diff --git a/demo/gallery6/imgs/1.png b/demo/gallery6/imgs/1.png new file mode 100644 index 0000000..d167e8d Binary files /dev/null and b/demo/gallery6/imgs/1.png differ diff --git a/demo/gallery6/imgs/10.png b/demo/gallery6/imgs/10.png new file mode 100644 index 0000000..3de16cf Binary files /dev/null and b/demo/gallery6/imgs/10.png differ diff --git a/demo/gallery6/imgs/11.png b/demo/gallery6/imgs/11.png new file mode 100644 index 0000000..4a895e9 Binary files /dev/null and b/demo/gallery6/imgs/11.png differ diff --git a/demo/gallery6/imgs/12.png b/demo/gallery6/imgs/12.png new file mode 100644 index 0000000..f67b51b Binary files /dev/null and b/demo/gallery6/imgs/12.png differ diff --git a/demo/gallery6/imgs/2.png b/demo/gallery6/imgs/2.png new file mode 100644 index 0000000..46b1fb8 Binary files /dev/null and b/demo/gallery6/imgs/2.png differ diff --git a/demo/gallery6/imgs/3.png b/demo/gallery6/imgs/3.png new file mode 100644 index 0000000..d7e90e5 Binary files /dev/null and b/demo/gallery6/imgs/3.png differ diff --git a/demo/gallery6/imgs/4.png b/demo/gallery6/imgs/4.png new file mode 100644 index 0000000..0a4571d Binary files /dev/null and b/demo/gallery6/imgs/4.png differ diff --git a/demo/gallery6/imgs/5.png b/demo/gallery6/imgs/5.png new file mode 100644 index 0000000..f7a8db7 Binary files /dev/null and b/demo/gallery6/imgs/5.png differ diff --git a/demo/gallery6/imgs/6.png b/demo/gallery6/imgs/6.png new file mode 100644 index 0000000..55114b6 Binary files /dev/null and b/demo/gallery6/imgs/6.png differ diff --git a/demo/gallery6/imgs/7.png b/demo/gallery6/imgs/7.png new file mode 100644 index 0000000..8fe30ca Binary files /dev/null and b/demo/gallery6/imgs/7.png differ diff --git a/demo/gallery6/imgs/8.png b/demo/gallery6/imgs/8.png new file mode 100644 index 0000000..e57c754 Binary files /dev/null and b/demo/gallery6/imgs/8.png differ diff --git a/demo/gallery6/imgs/9.png b/demo/gallery6/imgs/9.png new file mode 100644 index 0000000..0362b54 Binary files /dev/null and b/demo/gallery6/imgs/9.png differ diff --git a/demo/gallery6/index.html b/demo/gallery6/index.html new file mode 100644 index 0000000..c701674 --- /dev/null +++ b/demo/gallery6/index.html @@ -0,0 +1,138 @@ + + + + + + + + SwipeView + + + + + + +
+ + + + diff --git a/demo/gallery6/infinitegraphset.js b/demo/gallery6/infinitegraphset.js new file mode 100644 index 0000000..4b144e4 --- /dev/null +++ b/demo/gallery6/infinitegraphset.js @@ -0,0 +1,90 @@ +/* + * infinitegraphset.js + */ +(function (win, doc) { + + function InfiniteGraphSet(id, dataO) { + var gallery = new SwipeView(id, { + hastyPageFlip:true, + numberOfPages: dataO.length + }), i, page, df = dataO; + gallery.bind(); + + function genImgs(container, page, d) { + var img, div; + for(var i=0; i< 5; i++) { + div = doc.createElement('div'); + div.className = 'container'; + img = doc.createElement('img'); + img.className = 'loading'; + img.src = d.get(page).imgs[i]; + img.width = d.get(page).width; + img.height = d.get(page).height; + // fixes for IE + img.setAttribute("unselectable", "on"); + img.ondragstart = function() { return false; }; + div.style.width = d.get(page).width + "px"; + div.style.height = d.get(page).height + "px"; + img.onload = function () { this.className = ''; } + div.appendChild(img); + container.appendChild(div); + } + } + + for(i=0; i<3; i++) { + page = i==0 ? df.length-1 : i-1; + div = doc.createElement('div'); + div.className = 'set-container'; + genImgs(div, page, df); + gallery.masterPages[i].appendChild(div); + } + + function setImg(el, src) { + el.className = 'loading'; + el.src = src; + el.onload = function () { this.className = ''; } + } + + function init(newdf) { + df = newdf; + var el, page, i; + for (i=0; i<3; i++) { + page = i==0 ? newdf.length-1 : i-1; + els = gallery.masterPages[i].querySelectorAll('img'); + setImg(els[0], newdf.get(page).imgs[0]); + setImg(els[1], newdf.get(page).imgs[1]); + setImg(els[2], newdf.get(page).imgs[2]); + setImg(els[3], newdf.get(page).imgs[3]); + setImg(els[4], newdf.get(page).imgs[4]); + } + } + + gallery.onFlip(function () { + var els, + upcoming, + i; + + for (i=0; i<3; i++) { + upcoming = gallery.masterPages[i].dataset.upcomingPageIndex; + + if (upcoming != gallery.masterPages[i].dataset.pageIndex) { + els = gallery.masterPages[i].querySelectorAll('img'); + setImg(els[0], df.get(upcoming).imgs[0]); + setImg(els[1], df.get(upcoming).imgs[1]); + setImg(els[2], df.get(upcoming).imgs[2]); + setImg(els[3], df.get(upcoming).imgs[3]); + setImg(els[4], df.get(upcoming).imgs[4]); + } + } + }); + return { + gallery: gallery, + reset:function (newdf) { + gallery.reset(); + init(newdf); + } + }; + } + + win.InfiniteGraphSet = InfiniteGraphSet; +})(window, window.document); diff --git a/demo/gallery6/style.css b/demo/gallery6/style.css new file mode 100644 index 0000000..8a119db --- /dev/null +++ b/demo/gallery6/style.css @@ -0,0 +1,89 @@ +html, body { height:100%; } +body { + padding:0; + margin:0; + background:#333; + -webkit-user-select:none; + -moz-user-select:none; + -ms-user-select:none; + -o-user-select:none; + user-select:none; + -webkit-text-size-adjust:none; + -moz-text-size-adjust:none; + -ms-text-size-adjust:none; + -o-text-size-adjust:none; + text-size-adjust:none; + color:#eee; + font-family:helvetica; + font-size:12px; +} + +#wrapper { + width:100%; + height:100%; + position:relative; +} + +.wrapper { + width:1024px; + min-width:320px; + height:145px; + margin:20px auto; + background-color: rgb(43, 38, 38); +} + +.swipeview-slider > div , .vertical-swipeview-slider > div{ + position:relative; + display:-webkit-box; + display:-moz-box; + display:-ms-box; + display:-o-box; + display:box; + -webkit-box-orient:vertical; + -moz-box-orient:vertical; + -ms-box-orient:vertical; + -o-box-orient:vertical; + box-orient:vertical; + -webkit-box-pack:center; + -moz-box-pack:center; + -ms-box-pack:center; + -o-box-pack:center; + box-pack:center; + -webkit-box-align:center; + -mox-box-align:center; + -ms-box-align:center; + -o-box-align:center; + box-align:center; + overflow:hidden; +} + +.swipeview-slider img { + display:block; + -webkit-transition-duration:.4s; + -moz-transition-duration:.4s; + -ms-transition-duration:.4s; + -o-transition-duration:.4s; + transition-duration:.4s; + -webkit-transition-property:opacity; + -moz-transition-property:opacity; + -ms-transition-property:opacity; + -o-transition-property:opacity; + transition-property:opacity; + opacity:1; + pointer-events:none; + visibility:visible; +} + +.swipeview-slider .set-container { + margin:auto; +} + +.swipeview-slider .container { + background: rgb(197, 197, 197); + float: left; + margin: 0 5px; +} + +.swipeview-slider img.loading { + visibility:hidden; +} diff --git a/demo/gallery7/app.js b/demo/gallery7/app.js new file mode 100644 index 0000000..f9c237e --- /dev/null +++ b/demo/gallery7/app.js @@ -0,0 +1,61 @@ +/** + * app.js + */ + +function genData(size) { + + function getImgURL() { + return "http://lorempixel.com/186/125/?t=" + Math.ceil(Math.random()*100000); + } + + return { + get : function (i) { + return { + imgs : [getImgURL(), getImgURL(), getImgURL(), getImgURL(), getImgURL()], + height : 125, + width : 186 + }; + }, + length : size + }; +} + +var gallery, el, i = 0, page; + +gallery = new SwipeView('#wrapper', { + numberOfPages: 100, + vertical: true, + hastyPageFlip:true +}); +gallery.bind(); + +function init(domElt, myGallery, id, idx) { + domElt = document.createElement('div'); + domElt.className = 'wrapper'; + domElt.id = "wrap" + idx + "-" + id; + + myGallery.masterPages[id]['swipeview'+idx] = InfiniteGraphSet(domElt, genData(100)); + myGallery.masterPages[id].appendChild(domElt); +} + +// Load initial data +for (; i<3; i++) { + page = i==0 ? 100-1 : i-1; + init(el, gallery, i, 0); + init(el, gallery, i, 1); + init(el, gallery, i, 2); + init(el, gallery, i, 3); +} + +gallery.onFlip(function () { + var upcoming, i=0; + for (; i<3; i++) { + upcoming = gallery.masterPages[i].dataset.upcomingPageIndex; + if (upcoming != gallery.masterPages[i].dataset.pageIndex) { + gallery.masterPages[i].swipeview0.reset(genData(100)); + gallery.masterPages[i].swipeview1.reset(genData(100)); + gallery.masterPages[i].swipeview2.reset(genData(100)); + gallery.masterPages[i].swipeview3.reset(genData(100)); + } + } +}); diff --git a/demo/gallery7/index.html b/demo/gallery7/index.html new file mode 100644 index 0000000..c9a862b --- /dev/null +++ b/demo/gallery7/index.html @@ -0,0 +1,18 @@ + + + + + + + + SwipeView + + + + +
+ + + + + diff --git a/demo/gallery7/infinitegraphset.js b/demo/gallery7/infinitegraphset.js new file mode 100644 index 0000000..4b144e4 --- /dev/null +++ b/demo/gallery7/infinitegraphset.js @@ -0,0 +1,90 @@ +/* + * infinitegraphset.js + */ +(function (win, doc) { + + function InfiniteGraphSet(id, dataO) { + var gallery = new SwipeView(id, { + hastyPageFlip:true, + numberOfPages: dataO.length + }), i, page, df = dataO; + gallery.bind(); + + function genImgs(container, page, d) { + var img, div; + for(var i=0; i< 5; i++) { + div = doc.createElement('div'); + div.className = 'container'; + img = doc.createElement('img'); + img.className = 'loading'; + img.src = d.get(page).imgs[i]; + img.width = d.get(page).width; + img.height = d.get(page).height; + // fixes for IE + img.setAttribute("unselectable", "on"); + img.ondragstart = function() { return false; }; + div.style.width = d.get(page).width + "px"; + div.style.height = d.get(page).height + "px"; + img.onload = function () { this.className = ''; } + div.appendChild(img); + container.appendChild(div); + } + } + + for(i=0; i<3; i++) { + page = i==0 ? df.length-1 : i-1; + div = doc.createElement('div'); + div.className = 'set-container'; + genImgs(div, page, df); + gallery.masterPages[i].appendChild(div); + } + + function setImg(el, src) { + el.className = 'loading'; + el.src = src; + el.onload = function () { this.className = ''; } + } + + function init(newdf) { + df = newdf; + var el, page, i; + for (i=0; i<3; i++) { + page = i==0 ? newdf.length-1 : i-1; + els = gallery.masterPages[i].querySelectorAll('img'); + setImg(els[0], newdf.get(page).imgs[0]); + setImg(els[1], newdf.get(page).imgs[1]); + setImg(els[2], newdf.get(page).imgs[2]); + setImg(els[3], newdf.get(page).imgs[3]); + setImg(els[4], newdf.get(page).imgs[4]); + } + } + + gallery.onFlip(function () { + var els, + upcoming, + i; + + for (i=0; i<3; i++) { + upcoming = gallery.masterPages[i].dataset.upcomingPageIndex; + + if (upcoming != gallery.masterPages[i].dataset.pageIndex) { + els = gallery.masterPages[i].querySelectorAll('img'); + setImg(els[0], df.get(upcoming).imgs[0]); + setImg(els[1], df.get(upcoming).imgs[1]); + setImg(els[2], df.get(upcoming).imgs[2]); + setImg(els[3], df.get(upcoming).imgs[3]); + setImg(els[4], df.get(upcoming).imgs[4]); + } + } + }); + return { + gallery: gallery, + reset:function (newdf) { + gallery.reset(); + init(newdf); + } + }; + } + + win.InfiniteGraphSet = InfiniteGraphSet; +})(window, window.document); diff --git a/demo/gallery7/style.css b/demo/gallery7/style.css new file mode 100644 index 0000000..5b48ebd --- /dev/null +++ b/demo/gallery7/style.css @@ -0,0 +1,89 @@ +html, body { height:100%; } +body { + padding:0; + margin:0; + background:#333; + -webkit-user-select:none; + -moz-user-select:none; + -ms-user-select:none; + -o-user-select:none; + user-select:none; + -webkit-text-size-adjust:none; + -moz-text-size-adjust:none; + -ms-text-size-adjust:none; + -o-text-size-adjust:none; + text-size-adjust:none; + color:#eee; + font-family:helvetica; + font-size:12px; +} + +#wrapper { + width:100%; + height:100%; + position:relative; +} + +.wrapper { + width:1024px; + min-width:320px; + height:145px; + margin:20px auto; + background-color: rgb(43, 38, 38); +} + +.swipeview-slider > div , .vertical-swipeview-slider > div{ + position:relative; + display:-webkit-box; + display:-moz-box; + display:-ms-box; + display:-o-box; + display:box; + -webkit-box-orient:vertical; + -moz-box-orient:vertical; + -ms-box-orient:vertical; + -o-box-orient:vertical; + box-orient:vertical; + -webkit-box-pack:center; + -moz-box-pack:center; + -ms-box-pack:center; + -o-box-pack:center; + box-pack:center; + -webkit-box-align:center; + -moz-box-align:center; + -ms-box-align:center; + -o-box-align:center; + box-align:center; + overflow:hidden; +} + +.swipeview-slider img { + display:block; + -webkit-transition-duration:.4s; + -moz-transition-duration:.4s; + -ms-transition-duration:.4s; + -o-transition-duration:.4s; + transition-duration:.4s; + -webkit-transition-property:opacity; + -moz-transition-property:opacity; + -ms-transition-property:opacity; + -o-transition-property:opacity; + transition-property:opacity; + opacity:1; + pointer-events:none; + visibility:visible; +} + +.swipeview-slider .set-container { + margin:auto; +} + +.swipeview-slider .container { + background: rgb(197, 197, 197); + float: left; + margin: 0 5px; +} + +.swipeview-slider img.loading { + visibility:hidden; +} diff --git a/demo/gallery8/app.js b/demo/gallery8/app.js new file mode 100644 index 0000000..f9c237e --- /dev/null +++ b/demo/gallery8/app.js @@ -0,0 +1,61 @@ +/** + * app.js + */ + +function genData(size) { + + function getImgURL() { + return "http://lorempixel.com/186/125/?t=" + Math.ceil(Math.random()*100000); + } + + return { + get : function (i) { + return { + imgs : [getImgURL(), getImgURL(), getImgURL(), getImgURL(), getImgURL()], + height : 125, + width : 186 + }; + }, + length : size + }; +} + +var gallery, el, i = 0, page; + +gallery = new SwipeView('#wrapper', { + numberOfPages: 100, + vertical: true, + hastyPageFlip:true +}); +gallery.bind(); + +function init(domElt, myGallery, id, idx) { + domElt = document.createElement('div'); + domElt.className = 'wrapper'; + domElt.id = "wrap" + idx + "-" + id; + + myGallery.masterPages[id]['swipeview'+idx] = InfiniteGraphSet(domElt, genData(100)); + myGallery.masterPages[id].appendChild(domElt); +} + +// Load initial data +for (; i<3; i++) { + page = i==0 ? 100-1 : i-1; + init(el, gallery, i, 0); + init(el, gallery, i, 1); + init(el, gallery, i, 2); + init(el, gallery, i, 3); +} + +gallery.onFlip(function () { + var upcoming, i=0; + for (; i<3; i++) { + upcoming = gallery.masterPages[i].dataset.upcomingPageIndex; + if (upcoming != gallery.masterPages[i].dataset.pageIndex) { + gallery.masterPages[i].swipeview0.reset(genData(100)); + gallery.masterPages[i].swipeview1.reset(genData(100)); + gallery.masterPages[i].swipeview2.reset(genData(100)); + gallery.masterPages[i].swipeview3.reset(genData(100)); + } + } +}); diff --git a/demo/gallery8/index.html b/demo/gallery8/index.html new file mode 100644 index 0000000..c9a862b --- /dev/null +++ b/demo/gallery8/index.html @@ -0,0 +1,18 @@ + + + + + + + + SwipeView + + + + +
+ + + + + diff --git a/demo/gallery8/infinitegraphset.js b/demo/gallery8/infinitegraphset.js new file mode 100644 index 0000000..a630586 --- /dev/null +++ b/demo/gallery8/infinitegraphset.js @@ -0,0 +1,139 @@ +/* + * infinitegraphset.js + */ +(function (win, doc) { + + function InfiniteGraphSet(id, dataO, f) { + var gallery = new SwipeView(id, { + hastyPageFlip:true, + numberOfPages: dataO.length + }), i, page, df = dataO, + ƒ = f || function () { + console.log("tap cb"); + }, + locked = false, + x = 0, y = 0, id; + gallery.bind(); + + function onTouchStart(evt) { + console.log('touchstart'); + if (locked) return; + locked = true; + x = evt.targetTouches.item(0).pageX; + y = evt.targetTouches.item(0).pageY; + id = evt.targetTouches.item(0).identifier; + } + function onTouchMove(evt) { + console.log('touchmove'); + if(!locked) return; + var i,l= evt.changedTouches.length, point; + for(; i + + + + + + + SwipeView + + + + +
+
+
+ + + + + diff --git a/demo/gallery9/infinitegraphset.js b/demo/gallery9/infinitegraphset.js new file mode 100644 index 0000000..1501372 --- /dev/null +++ b/demo/gallery9/infinitegraphset.js @@ -0,0 +1,140 @@ +/* + * infinitegraphset.js + */ +(function (win, doc) { + + function InfiniteGraphSet(id, dataO, f, n, w, h) { + var gallery = new SwipeView(id, { + hastyPageFlip:true, + numberOfPages: dataO.length, + clientWidth : w, + clientHeight : h + }), i, page, df = dataO, + ƒ = f || function () { + console.log("tap cb"); + }, + n = n || 5; + locked = false, + x = 0, y = 0, id; + + gallery.bind(); + // FIXME + /*function onTouchStart(evt) { + console.log('touchstart'); + if (locked) return; + locked = true; + x = evt.targetTouches.item(0).pageX; + y = evt.targetTouches.item(0).pageY; + id = evt.targetTouches.item(0).identifier; + } + function onTouchMove(evt) { + console.log('touchmove'); + if(!locked) return; + var i,l= evt.changedTouches.length, point; + for(; i div , .vertical-swipeview-slider > div{ + position:relative; + display:-webkit-box; + display:-moz-box; + display:-ms-box; + display:-o-box; + display:box; + -webkit-box-orient:vertical; + -moz-box-orient:vertical; + -ms-box-orient:vertical; + -o-box-orient:vertical; + box-orient:vertical; + -webkit-box-pack:center; + -moz-box-pack:center; + -ms-box-pack:center; + -o-box-pack:center; + box-pack:center; + -webkit-box-align:center; + -mox-box-align:center; + -ms-box-align:center; + -o-box-align:center; + box-align:center; + overflow:hidden; +} diff --git a/demo/inline/index.html b/demo/inline/index.html index 4b6f0e6..3caae11 100644 --- a/demo/inline/index.html +++ b/demo/inline/index.html @@ -45,6 +45,7 @@

Three Laws of Robotics

numberOfPages: slides.length, hastyPageFlip: true }); +carousel.bind(); // Load initial data for (i=0; i<3; i++) { @@ -73,4 +74,4 @@

Three Laws of Robotics

- \ No newline at end of file + diff --git a/demo/inline/style.css b/demo/inline/style.css index 830a1b2..79c3961 100644 --- a/demo/inline/style.css +++ b/demo/inline/style.css @@ -66,7 +66,7 @@ h1 { background:rgba(255,255,255,0.4); } -#swipeview-slider > div { +.swipeview-slider > div { position:relative; display:-webkit-box; -webkit-box-orient:vertical; @@ -75,7 +75,7 @@ h1 { overflow:hidden; } -#swipeview-slider span { +.swipeview-slider span { -webkit-box-sizing:border-box; display:block; text-align:center; diff --git a/dist/swipeview-1.1.1.min.js b/dist/swipeview-1.1.1.min.js new file mode 100644 index 0000000..bc7d833 --- /dev/null +++ b/dist/swipeview-1.1.1.min.js @@ -0,0 +1,2 @@ +/*! swipeview 1.1.1 - Virtually infinite loop-able horizontal carousel - a fork of the original SwipeView from Matteo Spinelli */ +var SwipeView=function(a,b){function c(a){return""===e?a:(a=a.charAt(0).toUpperCase()+a.substr(1),e+a)}var d=b.createElement("div").style,e=function(){for(var a,b="t,webkitT,MozT,msT,OT".split(","),c=0,e=b.length;e>c;c++)if(a=b[c]+"ransform",a in d)return b[c].substr(0,b[c].length-1);return!1}(),f=e?"-"+e.toLowerCase()+"-":"",g=c("transform"),h=c("transitionDuration"),i=c("perspective")in d,j="ontouchstart"in a,k=(c("transition")in d,i?" translateZ(0)":""),l="onorientationchange"in a?"orientationchange":"resize",m=j?"touchstart":"mousedown",n=j?"touchmove":"mousemove",o=j?"touchend":"mouseup",p=j?"touchcancel":"mouseup",q=function(){if(e===!1)return!1;var a={"":"transitionend",webkit:"webkitTransitionEnd",Moz:"transitionend",O:"oTransitionEnd",ms:"MSTransitionEnd"};return a[e]}(),r=0,s=function(c,d){var g,h,i,k;this.wrapper="string"==typeof c?b.querySelector(c):c,this.id=this.wrapper.id||"sw-id"+ ++r,this.options={text:null,numberOfPages:3,snapThreshold:null,hastyPageFlip:!1,vertical:!1,loop:!0,clientWidth:1024,clientHeight:145};for(g in d)this.options[g]=d[g];for(this.currentMasterPage=1,this.k=0,this.maxK=0,this.page=0,this.pageIndex=0,this.customEvents=[],this.wrapperWidth=0,this.wrapperHeight=0,this.pageSize=0,this.initiated=!1,this.identifier=null,this.moved=!1,this.thresholdExceeded=!1,this.startX=0,this.startX=0,this.pointX=0,this.pointY=0,this.stepsX=0,this.stepsY=0,this.direction=0,this.directionLocked=!1,this.cssPosition=this.options.vertical?"top":"left",this.wrapper.style.overflow="hidden",this.wrapper.style.position="relative",this.masterPages=[],h=b.createElement("div"),h.className="swipeview-slider",h.style.cssText="position:relative;top:0;height:100%;width:100%;"+f+"transition-duration:0;"+f+"transform:translateZ(0);"+f+"transition-timing-function:ease-out",this.wrapper.appendChild(h),this.slider=h,this.refreshSize(),g=-1;2>g;g++)h=b.createElement("div"),h.style.cssText=f+"transform:translateZ(0);position:absolute;top:0;height:100%;width:100%;"+this.cssPosition+":"+100*g+"%",h.dataset||(h.dataset={}),k=-1==g?this.options.numberOfPages-1:g,h.dataset.pageIndex=k,h.dataset.upcomingPageIndex=k,this.options.loop||-1!=g||(h.style.visibility="hidden"),this.slider.appendChild(h),this.masterPages.push(h);i=this.masterPages[1].className,this.masterPages[1].className=i?i+" swipeview-active":"swipeview-active",a.addEventListener(l,this,!1),this.wrapper.addEventListener(m,this,!1),this.wrapper.addEventListener(n,this,!1),this.wrapper.addEventListener(o,this,!1),this.slider.addEventListener(q,this,!1),"O"==e&&this.slider.addEventListener(q.toLowerCase(),this,!1),j||this.wrapper.addEventListener("mouseout",this,!1)};return s.prototype={reset:function(a){this.goToPage(0),this.updatePageCount(a),this.refreshSize()},onFlip:function(a){this.wrapper.addEventListener(this.id+"swipeview-flip",a,!1),this.customEvents.push([this.id+"flip",a])},onMoveOut:function(a){this.wrapper.addEventListener(this.id+"swipeview-moveout",a,!1),this.customEvents.push([this.id+"moveout",a])},onMoveIn:function(a){this.wrapper.addEventListener(this.id+"swipeview-movein",a,!1),this.customEvents.push([this.id+"movein",a])},onTouchStart:function(a){this.wrapper.addEventListener(this.id+"swipeview-touchstart",a,!1),this.customEvents.push([this.id+"touchstart",a])},destroy:function(){for(;this.customEvents.length;)this.wrapper.removeEventListener(this.id+"swipeview-"+this.customEvents[0][0],this.customEvents[0][1],!1),this.customEvents.shift();a.removeEventListener(l,this,!1),this.wrapper.removeEventListener(m,this,!1),this.wrapper.removeEventListener(n,this,!1),this.wrapper.removeEventListener(o,this,!1),this.slider.removeEventListener(q,this,!1),j||this.wrapper.removeEventListener("mouseout",this,!1)},refreshSize:function(){this.wrapperWidth=0===this.wrapper.clientWidth?this.options.clientWidth:this.wrapper.clientWidth,this.wrapperHeight=0===this.wrapper.clientHeight?this.options.clientHeight:this.wrapper.clientHeight,this.wrapperSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.pageSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize,this.snapThreshold=null===this.options.snapThreshold?Math.round(.15*this.pageSize):/%/.test(this.options.snapThreshold)?Math.round(this.pageSize*this.options.snapThreshold.replace("%","")/100):this.options.snapThreshold},updatePageCount:function(a){this.options.numberOfPages=a,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize},goToPage:function(a){var b;for(this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/,""),b=0;3>b;b++)className=this.masterPages[b].className,/(^|\s)swipeview-loading(\s|$)/.test(className)||(this.masterPages[b].className=className?className+" swipeview-loading":"swipeview-loading");a=0>a?0:a>this.options.numberOfPages-1?this.options.numberOfPages-1:a,this.page=a,this.pageIndex=a,this.slider.style[h]="0s",this.__pos(-a*this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className+" swipeview-active",0===this.currentMasterPage?(this.masterPages[2].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[0].style[this.cssPosition]=100*this.page+"%",this.masterPages[1].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[2].dataset.upcomingPageIndex=0===this.page?this.options.numberOfPages-1:this.page-1,this.masterPages[0].dataset.upcomingPageIndex=this.page,this.masterPages[1].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?0:this.page+1):1==this.currentMasterPage?(this.masterPages[0].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[1].style[this.cssPosition]=100*this.page+"%",this.masterPages[2].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[0].dataset.upcomingPageIndex=0===this.page?this.options.numberOfPages-1:this.page-1,this.masterPages[1].dataset.upcomingPageIndex=this.page,this.masterPages[2].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?0:this.page+1):(this.masterPages[1].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[2].style[this.cssPosition]=100*this.page+"%",this.masterPages[0].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[1].dataset.upcomingPageIndex=0===this.page?this.options.numberOfPages-1:this.page-1,this.masterPages[2].dataset.upcomingPageIndex=this.page,this.masterPages[0].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?0:this.page+1),this.__flip()},next:function(){(this.options.loop||this.k!=this.maxK)&&(this.direction=-1,this.k-=1,this.__checkPosition())},prev:function(){(this.options.loop||0!==this.k)&&(this.direction=1,this.k+=1,this.__checkPosition())},handleEvent:function(a){switch(a.type){case m:this.__start(a);break;case n:this.__move(a);break;case"mouseout":if(this.initiated){for(var b=this.wrapper.getElementsByTagName("*"),c=0;cb;b++)a.changedTouches.item(b).identifier===this.identifier&&(d=a.changedTouches.item(b));if(!d)return}else d=a;var e=d.pageX-this.pointX,f=d.pageY-this.pointY,g=this.options.vertical?this.k+f:this.k+e,h=this.options.vertical?Math.abs(d.pageY-this.startY):Math.abs(d.pageX-this.startX);if(!(Math.abs(h)>=this.pageSize||(this.moved=!0,this.pointX=d.pageX,this.pointY=d.pageY,this.direction=this.options.vertical?f>0?1:0>f?-1:0:e>0?1:0>e?-1:0,this.stepsX+=Math.abs(e),this.stepsY+=Math.abs(f),this.stepsX<10&&this.stepsY<10))){if(!this.directionLocked&&(this.options.vertical?this.stepsX>this.stepsY:this.stepsY>this.stepsX))return this.initiated=!1,void 0;a.preventDefault(),this.directionLocked=!0,!this.options.loop&&(g>0||g=this.snapThreshold?(this.thresholdExceeded=!0,this.__event("moveout")):this.thresholdExceeded&&hc;c++)if(a.touches.item(c).identifier===this.identifier)return;for(c=0,d=a.changedTouches.length;d>c;c++)a.changedTouches.item(c).identifier===this.identifier&&(b=a.changedTouches.item(c));if(!b)return this.__pos(-this.page*this.pageSize),this.initiated=!1,void 0}else b=a;var e=this.options.vertical?Math.abs(b.pageY-this.startY):Math.abs(b.pageX-this.startX);if(this.initiated=!1,this.moved)return!this.options.loop&&(this.k>0||this.k0?(this.page=-Math.ceil(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=0===this.pageIndex?this.options.numberOfPages-1:this.pageIndex-1,a=this.currentMasterPage-1,a=0>a?2:a,this.masterPages[a].style[this.cssPosition]=100*this.page-100+"%",b=this.page-1):(this.page=-Math.floor(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=this.pageIndex==this.options.numberOfPages-1?0:this.pageIndex+1,a=this.currentMasterPage+1,a=a>2?0:a,this.masterPages[a].style[this.cssPosition]=100*this.page+100+"%",b=this.page+1),c=this.masterPages[this.currentMasterPage].className,/(^|\s)swipeview-active(\s|$)/.test(c)||(this.masterPages[this.currentMasterPage].className=c?c+" swipeview-active":"swipeview-active"),c=this.masterPages[a].className,/(^|\s)swipeview-loading(\s|$)/.test(c)||(this.masterPages[a].className=c?c+" swipeview-loading":"swipeview-loading"),b-=Math.floor(b/this.options.numberOfPages)*this.options.numberOfPages,this.masterPages[a].dataset.upcomingPageIndex=b,newC=-this.page*this.pageSize,this.slider.style[h]=Math.floor(500*Math.abs(this.k-newC)/this.pageSize)+"ms",this.options.loop||(this.masterPages[a].style.visibility=0===newC||newC==this.maxK?"hidden":""),this.k==newC?this.__flip():(this.__pos(newC),this.options.hastyPageFlip&&this.__flip())},__flip:function(){this.__event("flip");for(var a=0;3>a;a++)this.masterPages[a].className=this.masterPages[a].className.replace(/(^|\s)swipeview-loading(\s|$)/,""),this.masterPages[a].dataset.pageIndex=this.masterPages[a].dataset.upcomingPageIndex},__event:function(a){var c=b.createEvent("Event");c.initEvent(this.id+"swipeview-"+a,!0,!0),this.wrapper.dispatchEvent(c)}},s}(window,document); \ No newline at end of file diff --git a/dist/swipeview-1.1.2.min.js b/dist/swipeview-1.1.2.min.js new file mode 100644 index 0000000..4893cc7 --- /dev/null +++ b/dist/swipeview-1.1.2.min.js @@ -0,0 +1,2 @@ +/*! swipeview 1.1.2 - Virtually infinite loop-able horizontal carousel - a fork of the original SwipeView from Matteo Spinelli */ +var SwipeView=function(a,b){function c(a){return""===e?a:(a=a.charAt(0).toUpperCase()+a.substr(1),e+a)}var d=b.createElement("div").style,e=function(){for(var a,b="t,webkitT,MozT,msT,OT".split(","),c=0,e=b.length;e>c;c++)if(a=b[c]+"ransform",a in d)return b[c].substr(0,b[c].length-1);return!1}(),f=e?"-"+e.toLowerCase()+"-":"",g=c("transform"),h=c("transitionDuration"),i=c("perspective")in d,j="ontouchstart"in a,k=(c("transition")in d,i?" translateZ(0)":""),l="onorientationchange"in a?"orientationchange":"resize",m=j?"touchstart":"mousedown",n=j?"touchmove":"mousemove",o=j?"touchend":"mouseup",p=j?"touchcancel":"mouseup",q=function(){if(e===!1)return!1;var a={"":"transitionend",webkit:"webkitTransitionEnd",Moz:"transitionend",O:"oTransitionEnd",ms:"MSTransitionEnd"};return a[e]}(),r=function(a,b,c,d){"addEventListener"in a?a.addEventListener(b,c,d):"attachEvent"in a&&("object"==typeof c&&c.handleEvent?a.attachEvent("on"+b,function(a){c.handleEvent.call(c,a)}):a.attachEvent("on"+b,c))},s=0,t=function(c,d){var g,h,i,k;this.wrapper="string"==typeof c?b.querySelector(c):c,this.id=this.wrapper.id||"sw-id"+ ++s,this.options={text:null,numberOfPages:3,snapThreshold:null,hastyPageFlip:!1,vertical:!1,loop:!0,clientWidth:1024,clientHeight:145};for(g in d)this.options[g]=d[g];for(this.currentMasterPage=1,this.k=0,this.maxK=0,this.page=0,this.pageIndex=0,this.customEvents=[],this.wrapperWidth=0,this.wrapperHeight=0,this.pageSize=0,this.initiated=!1,this.identifier=null,this.moved=!1,this.thresholdExceeded=!1,this.startX=0,this.startX=0,this.pointX=0,this.pointY=0,this.stepsX=0,this.stepsY=0,this.direction=0,this.directionLocked=!1,this.cssPosition=this.options.vertical?"top":"left",this.wrapper.style.overflow="hidden",this.wrapper.style.position="relative",this.masterPages=[],h=b.createElement("div"),h.className="swipeview-slider",h.style.cssText="position:relative;top:0;height:100%;width:100%;"+f+"transition-duration:0;"+f+"transform:translateZ(0);"+f+"transition-timing-function:ease-out",this.wrapper.appendChild(h),this.slider=h,this.refreshSize(),g=-1;2>g;g++)h=b.createElement("div"),h.style.cssText=f+"transform:translateZ(0);position:absolute;top:0;height:100%;width:100%;"+this.cssPosition+":"+100*g+"%",h.dataset||(h.dataset={}),k=-1==g?this.options.numberOfPages-1:g,h.dataset.pageIndex=k,h.dataset.upcomingPageIndex=k,this.options.loop||-1!=g||(h.style.visibility="hidden"),this.slider.appendChild(h),this.masterPages.push(h);i=this.masterPages[1].className,this.masterPages[1].className=i?i+" swipeview-active":"swipeview-active",r(a,l,this,!1),r(this.wrapper,m,this,!1),r(this.wrapper,n,this,!1),r(this.wrapper,o,this,!1),r(this.slider,q,this,!1),"O"==e&&r(this.slider,q.toLowerCase(),this,!1),j||r(this.wrapper,"mouseout",this,!1)};return t.prototype={reset:function(a){this.goToPage(0),this.updatePageCount(a),this.refreshSize()},onFlip:function(a){r(this.wrapper,this.id+"swipeview-flip",a,!1),this.customEvents.push([this.id+"flip",a])},onMoveOut:function(a){r(this.wrapper,this.id+"swipeview-moveout",a,!1),this.customEvents.push([this.id+"moveout",a])},onMoveIn:function(a){r(this.wrapper,this.id+"swipeview-movein",a,!1),this.customEvents.push([this.id+"movein",a])},onTouchStart:function(a){r(this.wrapper,this.id+"swipeview-touchstart",a,!1),this.customEvents.push([this.id+"touchstart",a])},destroy:function(){for(;this.customEvents.length;)this.wrapper.removeEventListener(this.id+"swipeview-"+this.customEvents[0][0],this.customEvents[0][1],!1),this.customEvents.shift();a.removeEventListener(l,this,!1),this.wrapper.removeEventListener(m,this,!1),this.wrapper.removeEventListener(n,this,!1),this.wrapper.removeEventListener(o,this,!1),this.slider.removeEventListener(q,this,!1),j||this.wrapper.removeEventListener("mouseout",this,!1)},refreshSize:function(){this.wrapperWidth=0===this.wrapper.clientWidth?this.options.clientWidth:this.wrapper.clientWidth,this.wrapperHeight=0===this.wrapper.clientHeight?this.options.clientHeight:this.wrapper.clientHeight,this.wrapperSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.pageSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize,this.snapThreshold=null===this.options.snapThreshold?Math.round(.15*this.pageSize):/%/.test(this.options.snapThreshold)?Math.round(this.pageSize*this.options.snapThreshold.replace("%","")/100):this.options.snapThreshold},updatePageCount:function(a){this.options.numberOfPages=a,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize},goToPage:function(a){var b;for(this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/,""),b=0;3>b;b++)className=this.masterPages[b].className,/(^|\s)swipeview-loading(\s|$)/.test(className)||(this.masterPages[b].className=className?className+" swipeview-loading":"swipeview-loading");a=0>a?0:a>this.options.numberOfPages-1?this.options.numberOfPages-1:a,this.page=a,this.pageIndex=a,this.slider.style[h]="0s",this.__pos(-a*this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className+" swipeview-active",0===this.currentMasterPage?(this.masterPages[2].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[0].style[this.cssPosition]=100*this.page+"%",this.masterPages[1].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[2].dataset.upcomingPageIndex=0===this.page?this.options.numberOfPages-1:this.page-1,this.masterPages[0].dataset.upcomingPageIndex=this.page,this.masterPages[1].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?0:this.page+1):1==this.currentMasterPage?(this.masterPages[0].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[1].style[this.cssPosition]=100*this.page+"%",this.masterPages[2].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[0].dataset.upcomingPageIndex=0===this.page?this.options.numberOfPages-1:this.page-1,this.masterPages[1].dataset.upcomingPageIndex=this.page,this.masterPages[2].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?0:this.page+1):(this.masterPages[1].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[2].style[this.cssPosition]=100*this.page+"%",this.masterPages[0].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[1].dataset.upcomingPageIndex=0===this.page?this.options.numberOfPages-1:this.page-1,this.masterPages[2].dataset.upcomingPageIndex=this.page,this.masterPages[0].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?0:this.page+1),this.__flip()},next:function(){(this.options.loop||this.k!=this.maxK)&&(this.direction=-1,this.k-=1,this.__checkPosition())},prev:function(){(this.options.loop||0!==this.k)&&(this.direction=1,this.k+=1,this.__checkPosition())},handleEvent:function(a){switch(a.type){case m:this.__start(a);break;case n:this.__move(a);break;case"mouseout":if(this.initiated){for(var b=this.wrapper.getElementsByTagName("*"),c=0;cb;b++)a.changedTouches.item(b).identifier===this.identifier&&(d=a.changedTouches.item(b));if(!d)return}else d=a;var e=d.pageX-this.pointX,f=d.pageY-this.pointY,g=this.options.vertical?this.k+f:this.k+e,h=this.options.vertical?Math.abs(d.pageY-this.startY):Math.abs(d.pageX-this.startX);if(!(Math.abs(h)>=this.pageSize||(this.moved=!0,this.pointX=d.pageX,this.pointY=d.pageY,this.direction=this.options.vertical?f>0?1:0>f?-1:0:e>0?1:0>e?-1:0,this.stepsX+=Math.abs(e),this.stepsY+=Math.abs(f),this.stepsX<10&&this.stepsY<10))){if(!this.directionLocked&&(this.options.vertical?this.stepsX>this.stepsY:this.stepsY>this.stepsX))return this.initiated=!1,void 0;a.preventDefault(),this.directionLocked=!0,!this.options.loop&&(g>0||g=this.snapThreshold?(this.thresholdExceeded=!0,this.__event("moveout")):this.thresholdExceeded&&hc;c++)if(a.touches.item(c).identifier===this.identifier)return;for(c=0,d=a.changedTouches.length;d>c;c++)a.changedTouches.item(c).identifier===this.identifier&&(b=a.changedTouches.item(c));if(!b)return this.__pos(-this.page*this.pageSize),this.initiated=!1,void 0}else b=a;var e=this.options.vertical?Math.abs(b.pageY-this.startY):Math.abs(b.pageX-this.startX);if(this.initiated=!1,this.moved)return!this.options.loop&&(this.k>0||this.k0?(this.page=-Math.ceil(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=0===this.pageIndex?this.options.numberOfPages-1:this.pageIndex-1,a=this.currentMasterPage-1,a=0>a?2:a,this.masterPages[a].style[this.cssPosition]=100*this.page-100+"%",b=this.page-1):(this.page=-Math.floor(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=this.pageIndex==this.options.numberOfPages-1?0:this.pageIndex+1,a=this.currentMasterPage+1,a=a>2?0:a,this.masterPages[a].style[this.cssPosition]=100*this.page+100+"%",b=this.page+1),c=this.masterPages[this.currentMasterPage].className,/(^|\s)swipeview-active(\s|$)/.test(c)||(this.masterPages[this.currentMasterPage].className=c?c+" swipeview-active":"swipeview-active"),c=this.masterPages[a].className,/(^|\s)swipeview-loading(\s|$)/.test(c)||(this.masterPages[a].className=c?c+" swipeview-loading":"swipeview-loading"),b-=Math.floor(b/this.options.numberOfPages)*this.options.numberOfPages,this.masterPages[a].dataset.upcomingPageIndex=b,newC=-this.page*this.pageSize,this.slider.style[h]=Math.floor(500*Math.abs(this.k-newC)/this.pageSize)+"ms",this.options.loop||(this.masterPages[a].style.visibility=0===newC||newC==this.maxK?"hidden":""),this.k==newC?this.__flip():(this.__pos(newC),this.options.hastyPageFlip&&this.__flip())},__flip:function(){this.__event("flip");for(var a=0;3>a;a++)this.masterPages[a].className=this.masterPages[a].className.replace(/(^|\s)swipeview-loading(\s|$)/,""),this.masterPages[a].dataset.pageIndex=this.masterPages[a].dataset.upcomingPageIndex},__event:function(a){var c=b.createEvent("Event");c.initEvent(this.id+"swipeview-"+a,!0,!0),this.wrapper.dispatchEvent(c)}},t}(window,document); \ No newline at end of file diff --git a/dist/swipeview-1.2.0.min.js b/dist/swipeview-1.2.0.min.js new file mode 100644 index 0000000..cccd49f --- /dev/null +++ b/dist/swipeview-1.2.0.min.js @@ -0,0 +1,2 @@ +/*! swipeview 1.2.0 - Virtually infinite loop-able horizontal carousel - a fork of the original SwipeView from Matteo Spinelli */ +var SwipeView=function(a,b){function c(a,b){var c;for(c=a.length-1;c>-1&&a[c]!==b;--c);return c}function d(a){return""===g?a:(a=a.charAt(0).toUpperCase()+a.substr(1),g+a)}var e=function(){};e.prototype={bind:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},unbind:function(a,b){this._events=this._events||{},a in this._events!=!1&&this._events[a].splice(c(this._events[a],b),1)},trigger:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;bc;c++)if(a=b[c]+"ransform",a in f)return b[c].substr(0,b[c].length-1);return!1}(),h=g?"-"+g.toLowerCase()+"-":"",i=d("transform"),j=d("transitionDuration"),k=d("perspective")in f,l="ontouchstart"in a,m=!!g,n=(d("transition")in f,k?" translateZ(0)":""),o="onorientationchange"in a?"orientationchange":"resize",p=l?"touchstart":"mousedown",q=l?"touchmove":"mousemove",r=l?"touchend":"mouseup",s=l?"touchcancel":"mouseup",t=function(){if(g===!1)return!1;var a={"":"transitionend",webkit:"webkitTransitionEnd",Moz:"transitionend",O:"oTransitionEnd",ms:"MSTransitionEnd"};return a[g]}(),u=function(a,b,c,d){"addEventListener"in a?a.addEventListener(b,c,d):"attachEvent"in a&&a.attachEvent("on"+b,c)},v=function(a,b,c){"removeEventListener"in a?a.removeEventListener(b,c):"detachEvent"in a&&a.detachEvent("on"+b,c)},w=function(a){a.preventDefault?a.preventDefault():a.returnValue=!1},x=function(a){return"pageX"in a?a.pageX:a.clientX+b.body.scrollLeft+b.documentElement.scrollLeft},y=function(a){return"pageY"in a?a.pageY:a.clientY+b.body.scrollTop+b.documentElement.scrollTop},z=0,A=function(c,d){var f,i,j,k;this.wrapper="string"==typeof c?b.querySelector(c):c,this.id=this.wrapper.id||"sw-id"+ ++z,this.options={text:null,numberOfPages:3,snapThreshold:null,hastyPageFlip:!1,vertical:!1,loop:!0,clientWidth:1024,clientHeight:145};for(f in d)this.options[f]=d[f];for(this.currentMasterPage=1,this.k=0,this.maxK=0,this.page=0,this.pageIndex=0,this.E=new e,this.customEvents=[],this.wrapperWidth=0,this.wrapperHeight=0,this.pageSize=0,this.initiated=!1,this.identifier=null,this.moved=!1,this.thresholdExceeded=!1,this.startX=0,this.startX=0,this.pointX=0,this.pointY=0,this.stepsX=0,this.stepsY=0,this.direction=0,this.directionLocked=!1,this.cssPosition=this.options.vertical?"top":"left",this.wrapper.style.overflow="hidden",this.wrapper.style.position="relative",this.masterPages=[],i=b.createElement("div"),i.className="swipeview-slider",i.style.cssText="position:relative;top:0;height:100%;width:100%;"+h+"transition-duration:0;"+h+"transform:translateZ(0);"+h+"transition-timing-function:ease-out",this.wrapper.appendChild(i),this.slider=i,this.refreshSize(),f=-1;2>f;f++)i=b.createElement("div"),i.style.cssText=h+"transform:translateZ(0);position:absolute;top:0;height:100%;width:100%;"+this.cssPosition+":"+100*f+"%",i.dataset||(i.dataset={}),k=-1==f?this.options.numberOfPages-1:f,i.dataset.pageIndex=k,i.dataset.upcomingPageIndex=k,this.options.loop||-1!=f||(i.style.visibility="hidden"),this.slider.appendChild(i),this.masterPages.push(i);j=this.masterPages[1].className,this.masterPages[1].className=j?j+" swipeview-active":"swipeview-active";var m=this;this.handleEventF=function(a){m.handleEvent(a)},u(a,o,this.handleEventF,!1),u(this.wrapper,p,this.handleEventF,!1),u(this.wrapper,q,this.handleEventF,!1),u(this.wrapper,r,this.handleEventF,!1),u(this.slider,t,this.handleEventF,!1),"O"==g&&u(this.slider,t.toLowerCase(),this.handleEventF,!1),l||u(this.wrapper,"mouseout",this.handleEventF,!1)};return A.prototype={reset:function(a){this.goToPage(0),this.updatePageCount(a),this.refreshSize()},onFlip:function(a){this.E.bind("flip",a),this.customEvents.push(["flip",a])},onMoveOut:function(a){this.E.bind("moveout",a),this.customEvents.push(["moveout",a])},onMoveIn:function(a){this.E.bind("movein",a),this.customEvents.push(["movein",a])},onTouchStart:function(a){this.E.bind("touchstart",a),this.customEvents.push(["touchstart",a])},destroy:function(){for(;this.customEvents.length;)this.E.unbind(this.customEvents[0][0],this.customEvents[0][1]),this.customEvents.shift();v(a,o,this.handleEventF),v(this.wrapper,p,this.handleEventF),v(this.wrapper,q,this.handleEventF),v(this.wrapper,r,this.handleEventF),v(this.slider,t,this.handleEventF),l||v(this.wrapper,"mouseout",this.handleEventF)},refreshSize:function(){this.wrapperWidth=0===this.wrapper.clientWidth?this.options.clientWidth:this.wrapper.clientWidth,this.wrapperHeight=0===this.wrapper.clientHeight?this.options.clientHeight:this.wrapper.clientHeight,this.wrapperSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.pageSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize,this.snapThreshold=null===this.options.snapThreshold?Math.round(.15*this.pageSize):/%/.test(this.options.snapThreshold)?Math.round(this.pageSize*this.options.snapThreshold.replace("%","")/100):this.options.snapThreshold},updatePageCount:function(a){this.options.numberOfPages=a,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize},goToPage:function(a){var b;for(this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/,""),b=0;3>b;b++)className=this.masterPages[b].className,/(^|\s)swipeview-loading(\s|$)/.test(className)||(this.masterPages[b].className=className?className+" swipeview-loading":"swipeview-loading");a=0>a?0:a>this.options.numberOfPages-1?this.options.numberOfPages-1:a,this.page=a,this.pageIndex=a,this.slider.style[j]="0s",this.__pos(-a*this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className+" swipeview-active",0===this.currentMasterPage?(this.masterPages[2].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[0].style[this.cssPosition]=100*this.page+"%",this.masterPages[1].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[2].dataset.upcomingPageIndex=0===this.page?this.options.numberOfPages-1:this.page-1,this.masterPages[0].dataset.upcomingPageIndex=this.page,this.masterPages[1].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?0:this.page+1):1==this.currentMasterPage?(this.masterPages[0].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[1].style[this.cssPosition]=100*this.page+"%",this.masterPages[2].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[0].dataset.upcomingPageIndex=0===this.page?this.options.numberOfPages-1:this.page-1,this.masterPages[1].dataset.upcomingPageIndex=this.page,this.masterPages[2].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?0:this.page+1):(this.masterPages[1].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[2].style[this.cssPosition]=100*this.page+"%",this.masterPages[0].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[1].dataset.upcomingPageIndex=0===this.page?this.options.numberOfPages-1:this.page-1,this.masterPages[2].dataset.upcomingPageIndex=this.page,this.masterPages[0].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?0:this.page+1),this.__flip()},next:function(){(this.options.loop||this.k!=this.maxK)&&(this.direction=-1,this.k-=1,this.__checkPosition())},prev:function(){(this.options.loop||0!==this.k)&&(this.direction=1,this.k+=1,this.__checkPosition())},handleEvent:function(a){switch(a.type){case p:this.__start(a);break;case q:this.__move(a);break;case"mouseout":if(this.initiated){for(var b=this.wrapper.getElementsByTagName("*"),c=0;cb;b++)a.changedTouches.item(b).identifier===this.identifier&&(d=a.changedTouches.item(b));if(!d)return}else d=a;var e=x(d)-this.pointX,f=y(d)-this.pointY,g=this.options.vertical?this.k+f:this.k+e,h=this.options.vertical?Math.abs(y(d)-this.startY):Math.abs(x(d)-this.startX);if(!(Math.abs(h)>=this.pageSize||(this.moved=!0,this.pointX=x(d),this.pointY=y(d),this.direction=this.options.vertical?f>0?1:0>f?-1:0:e>0?1:0>e?-1:0,this.stepsX+=Math.abs(e),this.stepsY+=Math.abs(f),this.stepsX<10&&this.stepsY<10))){if(!this.directionLocked&&(this.options.vertical?this.stepsX>this.stepsY:this.stepsY>this.stepsX))return this.initiated=!1,void 0;w(a),this.directionLocked=!0,!this.options.loop&&(g>0||g=this.snapThreshold?(this.thresholdExceeded=!0,this.E.trigger("moveout")):this.thresholdExceeded&&hc;c++)if(a.touches.item(c).identifier===this.identifier)return;for(c=0,d=a.changedTouches.length;d>c;c++)a.changedTouches.item(c).identifier===this.identifier&&(b=a.changedTouches.item(c));if(!b)return this.__pos(-this.page*this.pageSize),this.initiated=!1,void 0}else b=a;var e=this.options.vertical?Math.abs(y(b)-this.startY):Math.abs(x(b)-this.startX);if(this.initiated=!1,this.moved)return!this.options.loop&&(this.k>0||this.k0?(this.page=-Math.ceil(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=0===this.pageIndex?this.options.numberOfPages-1:this.pageIndex-1,a=this.currentMasterPage-1,a=0>a?2:a,this.masterPages[a].style[this.cssPosition]=100*this.page-100+"%",b=this.page-1):(this.page=-Math.floor(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=this.pageIndex==this.options.numberOfPages-1?0:this.pageIndex+1,a=this.currentMasterPage+1,a=a>2?0:a,this.masterPages[a].style[this.cssPosition]=100*this.page+100+"%",b=this.page+1),c=this.masterPages[this.currentMasterPage].className,/(^|\s)swipeview-active(\s|$)/.test(c)||(this.masterPages[this.currentMasterPage].className=c?c+" swipeview-active":"swipeview-active"),c=this.masterPages[a].className,/(^|\s)swipeview-loading(\s|$)/.test(c)||(this.masterPages[a].className=c?c+" swipeview-loading":"swipeview-loading"),b-=Math.floor(b/this.options.numberOfPages)*this.options.numberOfPages,this.masterPages[a].dataset.upcomingPageIndex=b,newC=-this.page*this.pageSize,this.slider.style[j]=Math.floor(500*Math.abs(this.k-newC)/this.pageSize)+"ms",this.options.loop||(this.masterPages[a].style.visibility=0===newC||newC==this.maxK?"hidden":""),this.k==newC?this.__flip():(this.__pos(newC),this.options.hastyPageFlip&&this.__flip())},__flip:function(){this.E.trigger("flip");for(var a=0;3>a;a++)this.masterPages[a].className=this.masterPages[a].className.replace(/(^|\s)swipeview-loading(\s|$)/,""),this.masterPages[a].dataset.pageIndex=this.masterPages[a].dataset.upcomingPageIndex}},A}(window,document); \ No newline at end of file diff --git a/dist/swipeview-1.2.1.min.js b/dist/swipeview-1.2.1.min.js new file mode 100644 index 0000000..b3030a1 --- /dev/null +++ b/dist/swipeview-1.2.1.min.js @@ -0,0 +1,2 @@ +/*! swipeview 1.2.1 - Virtually infinite loop-able horizontal carousel - a fork of the original SwipeView from Matteo Spinelli */ +var SwipeView=function(a,b){function c(a,b){var c;for(c=a.length-1;c>-1&&a[c]!==b;--c);return c}function d(a){return""===g?a:(a=a.charAt(0).toUpperCase()+a.substr(1),g+a)}var e=function(){};e.prototype={bind:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},unbind:function(a,b){this._events=this._events||{},a in this._events!=!1&&this._events[a].splice(c(this._events[a],b),1)},trigger:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;bc;c++)if(a=b[c]+"ransform",a in f)return b[c].substr(0,b[c].length-1);return!1}(),h=g?"-"+g.toLowerCase()+"-":"",i=d("transform"),j=d("transitionDuration"),k=d("perspective")in f,l="ontouchstart"in a,m=!!g,n=(d("transition")in f,k?" translateZ(0)":""),o="onorientationchange"in a?"orientationchange":"resize",p=l?"touchstart":"mousedown",q=l?"touchmove":"mousemove",r=l?"touchend":"mouseup",s=l?"touchcancel":"mouseup",t=function(){if(g===!1)return!1;var a={"":"transitionend",webkit:"webkitTransitionEnd",Moz:"transitionend",O:"oTransitionEnd",ms:"MSTransitionEnd"};return a[g]}(),u=function(a,b,c,d){"addEventListener"in a?a.addEventListener(b,c,d):"attachEvent"in a&&a.attachEvent("on"+b,c)},v=function(a,b,c){"removeEventListener"in a?a.removeEventListener(b,c):"detachEvent"in a&&a.detachEvent("on"+b,c)},w=function(a){a.preventDefault?a.preventDefault():a.returnValue=!1},x=function(a){return"pageX"in a?a.pageX:a.clientX+b.body.scrollLeft+b.documentElement.scrollLeft},y=function(a){return"pageY"in a?a.pageY:a.clientY+b.body.scrollTop+b.documentElement.scrollTop},z=0,A=function(c,d){var f,i,j,k;this.wrapper="string"==typeof c?b.querySelector(c):c,this.id=this.wrapper.id||"sw-id"+ ++z,this.options={text:null,numberOfPages:3,snapThreshold:null,hastyPageFlip:!1,vertical:!1,loop:!0,clientWidth:1024,clientHeight:145};for(f in d)this.options[f]=d[f];for(this.currentMasterPage=1,this.k=0,this.maxK=0,this.page=0,this.pageIndex=0,this.E=new e,this.customEvents=[],this.wrapperWidth=0,this.wrapperHeight=0,this.pageSize=0,this.initiated=!1,this.identifier=null,this.moved=!1,this.thresholdExceeded=!1,this.startX=0,this.startX=0,this.pointX=0,this.pointY=0,this.stepsX=0,this.stepsY=0,this.direction=0,this.directionLocked=!1,this.cssPosition=this.options.vertical?"top":"left",this.wrapper.style.overflow="hidden",this.wrapper.style.position="relative",this.masterPages=[],i=b.createElement("div"),i.className="swipeview-slider",i.style.cssText="position:relative;top:0;height:100%;width:100%;"+h+"transition-duration:0;"+h+"transform:translateZ(0);"+h+"transition-timing-function:ease-out",this.wrapper.appendChild(i),this.slider=i,this.refreshSize(),f=-1;2>f;f++)i=b.createElement("div"),i.style.cssText=h+"transform:translateZ(0);position:absolute;top:0;height:100%;width:100%;"+this.cssPosition+":"+100*f+"%",i.dataset||(i.dataset={}),k=-1==f?this.options.numberOfPages-1:f,i.dataset.pageIndex=k,i.dataset.upcomingPageIndex=k,this.options.loop||-1!=f||(i.style.visibility="hidden"),this.slider.appendChild(i),this.masterPages.push(i);j=this.masterPages[1].className,this.masterPages[1].className=j?j+" swipeview-active":"swipeview-active";var m=this;this.handleEventF=function(a){m.handleEvent(a)},u(a,o,this.handleEventF,!1),u(this.wrapper,p,this.handleEventF,!1),u(this.wrapper,q,this.handleEventF,!1),u(this.wrapper,r,this.handleEventF,!1),u(this.slider,t,this.handleEventF,!1),"O"==g&&u(this.slider,t.toLowerCase(),this.handleEventF,!1),l||u(this.wrapper,"mouseout",this.handleEventF,!1)};return A.prototype={reset:function(a){this.goToPage(0),this.updatePageCount(a),this.refreshSize()},onFlip:function(a){this.E.bind("flip",a),this.customEvents.push(["flip",a])},onMoveOut:function(a){this.E.bind("moveout",a),this.customEvents.push(["moveout",a])},onMoveIn:function(a){this.E.bind("movein",a),this.customEvents.push(["movein",a])},onTouchStart:function(a){this.E.bind("touchstart",a),this.customEvents.push(["touchstart",a])},unbind:function(){for(;this.customEvents.length;)this.E.unbind(this.customEvents[0][0],this.customEvents[0][1]),this.customEvents.shift()},destroy:function(){this.unbind(),v(a,o,this.handleEventF),v(this.wrapper,p,this.handleEventF),v(this.wrapper,q,this.handleEventF),v(this.wrapper,r,this.handleEventF),v(this.slider,t,this.handleEventF),l||v(this.wrapper,"mouseout",this.handleEventF)},refreshSize:function(){this.wrapperWidth=0===this.wrapper.clientWidth?this.options.clientWidth:this.wrapper.clientWidth,this.wrapperHeight=0===this.wrapper.clientHeight?this.options.clientHeight:this.wrapper.clientHeight,this.wrapperSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.pageSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize,this.snapThreshold=null===this.options.snapThreshold?Math.round(.15*this.pageSize):/%/.test(this.options.snapThreshold)?Math.round(this.pageSize*this.options.snapThreshold.replace("%","")/100):this.options.snapThreshold},updatePageCount:function(a){this.options.numberOfPages=a,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize},goToPage:function(a){var b;for(this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/,""),b=0;3>b;b++)className=this.masterPages[b].className,/(^|\s)swipeview-loading(\s|$)/.test(className)||(this.masterPages[b].className=className?className+" swipeview-loading":"swipeview-loading");a=0>a?0:a>this.options.numberOfPages-1?this.options.numberOfPages-1:a,this.page=a,this.pageIndex=a,this.slider.style[j]="0s",this.__pos(-a*this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className+" swipeview-active",0===this.currentMasterPage?(this.masterPages[2].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[0].style[this.cssPosition]=100*this.page+"%",this.masterPages[1].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[2].dataset.upcomingPageIndex=0===this.page?this.options.numberOfPages-1:this.page-1,this.masterPages[0].dataset.upcomingPageIndex=this.page,this.masterPages[1].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?0:this.page+1):1==this.currentMasterPage?(this.masterPages[0].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[1].style[this.cssPosition]=100*this.page+"%",this.masterPages[2].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[0].dataset.upcomingPageIndex=0===this.page?this.options.numberOfPages-1:this.page-1,this.masterPages[1].dataset.upcomingPageIndex=this.page,this.masterPages[2].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?0:this.page+1):(this.masterPages[1].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[2].style[this.cssPosition]=100*this.page+"%",this.masterPages[0].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[1].dataset.upcomingPageIndex=0===this.page?this.options.numberOfPages-1:this.page-1,this.masterPages[2].dataset.upcomingPageIndex=this.page,this.masterPages[0].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?0:this.page+1),this.__flip()},next:function(){(this.options.loop||this.k!=this.maxK)&&(this.direction=-1,this.k-=1,this.__checkPosition())},prev:function(){(this.options.loop||0!==this.k)&&(this.direction=1,this.k+=1,this.__checkPosition())},handleEvent:function(a){switch(a.type){case p:this.__start(a);break;case q:this.__move(a);break;case"mouseout":if(this.initiated){for(var b=this.wrapper.getElementsByTagName("*"),c=0;cb;b++)a.changedTouches.item(b).identifier===this.identifier&&(d=a.changedTouches.item(b));if(!d)return}else d=a;var e=x(d)-this.pointX,f=y(d)-this.pointY,g=this.options.vertical?this.k+f:this.k+e,h=this.options.vertical?Math.abs(y(d)-this.startY):Math.abs(x(d)-this.startX);if(!(Math.abs(h)>=this.pageSize||(this.moved=!0,this.pointX=x(d),this.pointY=y(d),this.direction=this.options.vertical?f>0?1:0>f?-1:0:e>0?1:0>e?-1:0,this.stepsX+=Math.abs(e),this.stepsY+=Math.abs(f),this.stepsX<10&&this.stepsY<10))){if(!this.directionLocked&&(this.options.vertical?this.stepsX>this.stepsY:this.stepsY>this.stepsX))return this.initiated=!1,void 0;w(a),this.directionLocked=!0,!this.options.loop&&(g>0||g=this.snapThreshold?(this.thresholdExceeded=!0,this.E.trigger("moveout")):this.thresholdExceeded&&hc;c++)if(a.touches.item(c).identifier===this.identifier)return;for(c=0,d=a.changedTouches.length;d>c;c++)a.changedTouches.item(c).identifier===this.identifier&&(b=a.changedTouches.item(c));if(!b)return this.__pos(-this.page*this.pageSize),this.initiated=!1,void 0}else b=a;var e=this.options.vertical?Math.abs(y(b)-this.startY):Math.abs(x(b)-this.startX);if(this.initiated=!1,this.moved)return!this.options.loop&&(this.k>0||this.k0?(this.page=-Math.ceil(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=0===this.pageIndex?this.options.numberOfPages-1:this.pageIndex-1,a=this.currentMasterPage-1,a=0>a?2:a,this.masterPages[a].style[this.cssPosition]=100*this.page-100+"%",b=this.page-1):(this.page=-Math.floor(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=this.pageIndex==this.options.numberOfPages-1?0:this.pageIndex+1,a=this.currentMasterPage+1,a=a>2?0:a,this.masterPages[a].style[this.cssPosition]=100*this.page+100+"%",b=this.page+1),c=this.masterPages[this.currentMasterPage].className,/(^|\s)swipeview-active(\s|$)/.test(c)||(this.masterPages[this.currentMasterPage].className=c?c+" swipeview-active":"swipeview-active"),c=this.masterPages[a].className,/(^|\s)swipeview-loading(\s|$)/.test(c)||(this.masterPages[a].className=c?c+" swipeview-loading":"swipeview-loading"),b-=Math.floor(b/this.options.numberOfPages)*this.options.numberOfPages,this.masterPages[a].dataset.upcomingPageIndex=b,newC=-this.page*this.pageSize,this.slider.style[j]=Math.floor(500*Math.abs(this.k-newC)/this.pageSize)+"ms",this.options.loop||(this.masterPages[a].style.visibility=0===newC||newC==this.maxK?"hidden":""),this.k==newC?this.__flip():(this.__pos(newC),this.options.hastyPageFlip&&this.__flip())},__flip:function(){this.E.trigger("flip");for(var a=0;3>a;a++)this.masterPages[a].className=this.masterPages[a].className.replace(/(^|\s)swipeview-loading(\s|$)/,""),this.masterPages[a].dataset.pageIndex=this.masterPages[a].dataset.upcomingPageIndex}},A}(window,document); \ No newline at end of file diff --git a/dist/swipeview-1.2.2.min.js b/dist/swipeview-1.2.2.min.js new file mode 100644 index 0000000..611accf --- /dev/null +++ b/dist/swipeview-1.2.2.min.js @@ -0,0 +1,2 @@ +/*! swipeview 1.2.2 - Virtually infinite loop-able horizontal carousel - a fork of the original SwipeView from Matteo Spinelli */ +var SwipeView=function(a,b){function c(a,b){var c;for(c=a.length-1;c>-1&&a[c]!==b;--c);return c}function d(a){return""===g?a:(a=a.charAt(0).toUpperCase()+a.substr(1),g+a)}var e=function(){};e.prototype={bind:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},unbind:function(a,b){this._events=this._events||{},a in this._events!=!1&&this._events[a].splice(c(this._events[a],b),1)},trigger:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;bc;c++)if(a=b[c]+"ransform",a in f)return b[c].substr(0,b[c].length-1);return!1}(),h=g?"-"+g.toLowerCase()+"-":"",i=d("transform"),j=d("transitionDuration"),k=d("perspective")in f,l="ontouchstart"in a,m=!!g,n=(d("transition")in f,k?" translateZ(0)":""),o="onorientationchange"in a?"orientationchange":"resize",p=l?"touchstart":"mousedown",q=l?"touchmove":"mousemove",r=l?"touchend":"mouseup",s=l?"touchcancel":"mouseup",t=function(){if(g===!1)return!1;var a={"":"transitionend",webkit:"webkitTransitionEnd",Moz:"transitionend",O:"oTransitionEnd",ms:"MSTransitionEnd"};return a[g]}(),u=function(a,b,c,d){"addEventListener"in a?a.addEventListener(b,c,d):"attachEvent"in a&&a.attachEvent("on"+b,c)},v=function(a,b,c){"removeEventListener"in a?a.removeEventListener(b,c):"detachEvent"in a&&a.detachEvent("on"+b,c)},w=function(a){a.preventDefault?a.preventDefault():a.returnValue=!1},x=function(a){return"pageX"in a?a.pageX:a.clientX+b.body.scrollLeft+b.documentElement.scrollLeft},y=function(a){return"pageY"in a?a.pageY:a.clientY+b.body.scrollTop+b.documentElement.scrollTop},z=0,A=function(c,d){var f,i,j,k;this.wrapper="string"==typeof c?b.querySelector(c):c,this.id=this.wrapper.id||"sw-id"+ ++z,this.options={text:null,numberOfPages:3,snapThreshold:null,hastyPageFlip:!1,vertical:!1,loop:!0,clientWidth:1024,clientHeight:145};for(f in d)this.options[f]=d[f];for(this.currentMasterPage=1,this.k=0,this.maxK=0,this.page=0,this.pageIndex=0,this.E=new e,this.customEvents=[],this.wrapperWidth=0,this.wrapperHeight=0,this.pageSize=0,this.initiated=!1,this.identifier=null,this.moved=!1,this.thresholdExceeded=!1,this.startX=0,this.startX=0,this.pointX=0,this.pointY=0,this.stepsX=0,this.stepsY=0,this.direction=0,this.directionLocked=!1,this.cssPosition=this.options.vertical?"top":"left",this.wrapper.style.overflow="hidden",this.wrapper.style.position="relative",this.masterPages=[],i=b.createElement("div"),i.className="swipeview-slider",i.style.cssText="position:relative;top:0;height:100%;width:100%;"+h+"transition-duration:0;"+h+"transform:translateZ(0);"+h+"transition-timing-function:ease-out",this.wrapper.appendChild(i),this.slider=i,this.refreshSize(),f=-1;2>f;f++)i=b.createElement("div"),i.style.cssText=h+"transform:translateZ(0);position:absolute;top:0;height:100%;width:100%;"+this.cssPosition+":"+100*f+"%",i.dataset||(i.dataset={}),k=-1==f?this.options.numberOfPages-1:f,i.dataset.pageIndex=k,i.dataset.upcomingPageIndex=k,this.options.loop||-1!=f||(i.style.visibility="hidden"),this.slider.appendChild(i),this.masterPages.push(i);j=this.masterPages[1].className,this.masterPages[1].className=j?j+" swipeview-active":"swipeview-active";var m=this;this.handleEventF=function(a){m.handleEvent(a)},u(a,o,this.handleEventF,!1),u(this.wrapper,p,this.handleEventF,!1),u(this.wrapper,q,this.handleEventF,!1),u(this.wrapper,r,this.handleEventF,!1),u(this.slider,t,this.handleEventF,!1),"O"==g&&u(this.slider,t.toLowerCase(),this.handleEventF,!1),l||u(this.wrapper,"mouseout",this.handleEventF,!1)};return A.prototype={reset:function(a){this.goToPage(0),this.updatePageCount(a),this.refreshSize()},onFlip:function(a){this.E.bind("flip",a),this.customEvents.push(["flip",a])},onMoveOut:function(a){this.E.bind("moveout",a),this.customEvents.push(["moveout",a])},onMoveIn:function(a){this.E.bind("movein",a),this.customEvents.push(["movein",a])},onTouchStart:function(a){this.E.bind("touchstart",a),this.customEvents.push(["touchstart",a])},unbind:function(){for(;this.customEvents.length;)this.E.unbind(this.customEvents[0][0],this.customEvents[0][1]),this.customEvents.shift()},destroy:function(){this.unbind(),v(a,o,this.handleEventF),v(this.wrapper,p,this.handleEventF),v(this.wrapper,q,this.handleEventF),v(this.wrapper,r,this.handleEventF),v(this.slider,t,this.handleEventF),l||v(this.wrapper,"mouseout",this.handleEventF)},refreshSize:function(){this.wrapperWidth=0===this.wrapper.clientWidth?this.options.clientWidth:this.wrapper.clientWidth,this.wrapperHeight=0===this.wrapper.clientHeight?this.options.clientHeight:this.wrapper.clientHeight,this.wrapperSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.pageSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize,this.snapThreshold=null===this.options.snapThreshold?Math.round(.15*this.pageSize):/%/.test(this.options.snapThreshold)?Math.round(this.pageSize*this.options.snapThreshold.replace("%","")/100):this.options.snapThreshold},updatePageCount:function(a){this.options.numberOfPages=a,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize},goToPage:function(a){var b;for(this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/,""),b=0;3>b;b++)className=this.masterPages[b].className,/(^|\s)swipeview-loading(\s|$)/.test(className)||(this.masterPages[b].className=className?className+" swipeview-loading":"swipeview-loading");a=0>a?0:a>this.options.numberOfPages-1?this.options.numberOfPages-1:a,this.page=a,this.pageIndex=a,this.slider.style[j]="0s",this.__pos(-a*this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className+" swipeview-active";var c=function(a){return 0===a?[2,0,1]:1===a?[0,1,2]:[1,2,0]}(this.currentMasterPage);this.masterPages[c[0]].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[c[1]].style[this.cssPosition]=100*this.page+"%",this.masterPages[c[2]].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[c[0]].dataset.upcomingPageIndex=0===this.page?this.options.loop?this.options.numberOfPages-1:void 0:this.page-1,this.masterPages[c[1]].dataset.upcomingPageIndex=this.page,this.masterPages[c[2]].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?this.options.loop?0:void 0:this.page+1,this.__flip(!0)},next:function(){(this.options.loop||this.k!=this.maxK)&&(this.direction=-1,this.k-=1,this.__checkPosition())},prev:function(){(this.options.loop||0!==this.k)&&(this.direction=1,this.k+=1,this.__checkPosition())},handleEvent:function(a){switch(a.type){case p:this.__start(a);break;case q:this.__move(a);break;case"mouseout":if(this.initiated){for(var b=this.wrapper.getElementsByTagName("*"),c=0;cb;b++)a.changedTouches.item(b).identifier===this.identifier&&(d=a.changedTouches.item(b));if(!d)return}else d=a;var e=x(d)-this.pointX,f=y(d)-this.pointY,g=this.options.vertical?this.k+f:this.k+e,h=this.options.vertical?Math.abs(y(d)-this.startY):Math.abs(x(d)-this.startX);if(!(Math.abs(h)>=this.pageSize||(this.moved=!0,this.pointX=x(d),this.pointY=y(d),this.direction=this.options.vertical?f>0?1:0>f?-1:0:e>0?1:0>e?-1:0,this.stepsX+=Math.abs(e),this.stepsY+=Math.abs(f),this.stepsX<10&&this.stepsY<10))){if(!this.directionLocked&&(this.options.vertical?this.stepsX>this.stepsY:this.stepsY>this.stepsX))return this.initiated=!1,void 0;w(a),this.directionLocked=!0,!this.options.loop&&(g>0||g=this.snapThreshold?(this.thresholdExceeded=!0,this.E.trigger("moveout")):this.thresholdExceeded&&hc;c++)if(a.touches.item(c).identifier===this.identifier)return;for(c=0,d=a.changedTouches.length;d>c;c++)a.changedTouches.item(c).identifier===this.identifier&&(b=a.changedTouches.item(c));if(!b)return this.__pos(-this.page*this.pageSize),this.initiated=!1,void 0}else b=a;var e=this.options.vertical?Math.abs(y(b)-this.startY):Math.abs(x(b)-this.startX);if(this.initiated=!1,this.moved)return!this.options.loop&&(this.k>0||this.k0?(this.page=-Math.ceil(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=0===this.pageIndex?this.options.numberOfPages-1:this.pageIndex-1,a=this.currentMasterPage-1,a=0>a?2:a,this.masterPages[a].style[this.cssPosition]=100*this.page-100+"%",b=this.page-1,b-=Math.floor(b/this.options.numberOfPages)*this.options.numberOfPages,b=b!==this.options.numberOfPages||this.options.loop?b:void 0):(this.page=-Math.floor(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=this.pageIndex==this.options.numberOfPages-1?0:this.pageIndex+1,a=this.currentMasterPage+1,a=a>2?0:a,this.masterPages[a].style[this.cssPosition]=100*this.page+100+"%",b=this.page+1,b-=Math.floor(b/this.options.numberOfPages)*this.options.numberOfPages,b=0!==b||this.options.loop?b:void 0),c=this.masterPages[this.currentMasterPage].className,/(^|\s)swipeview-active(\s|$)/.test(c)||(this.masterPages[this.currentMasterPage].className=c?c+" swipeview-active":"swipeview-active"),c=this.masterPages[a].className,/(^|\s)swipeview-loading(\s|$)/.test(c)||(this.masterPages[a].className=c?c+" swipeview-loading":"swipeview-loading"),this.masterPages[a].dataset.upcomingPageIndex=b,newC=-this.page*this.pageSize,this.slider.style[j]=Math.floor(500*Math.abs(this.k-newC)/this.pageSize)+"ms",this.options.loop||(this.masterPages[a].style.visibility=0===newC||newC==this.maxK?"hidden":""),this.k==newC?this.__flip():(this.__pos(newC),this.options.hastyPageFlip&&this.__flip())},__flip:function(a){this.E.trigger("flip",{triggeredByGoto:!!a});for(var b=0;3>b;b++)this.masterPages[b].className=this.masterPages[b].className.replace(/(^|\s)swipeview-loading(\s|$)/,""),this.masterPages[b].dataset.pageIndex=this.masterPages[b].dataset.upcomingPageIndex}},A}(window,document); \ No newline at end of file diff --git a/dist/swipeview-1.2.3.min.js b/dist/swipeview-1.2.3.min.js new file mode 100644 index 0000000..ab63caf --- /dev/null +++ b/dist/swipeview-1.2.3.min.js @@ -0,0 +1,2 @@ +/*! swipeview 1.2.3 - Virtually infinite loop-able horizontal carousel - a fork of the original SwipeView from Matteo Spinelli */ +var SwipeView=function(a,b){function c(a,b){var c;for(c=a.length-1;c>-1&&a[c]!==b;--c);return c}function d(a){return""===g?a:(a=a.charAt(0).toUpperCase()+a.substr(1),g+a)}var e=function(){};e.prototype={bind:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},unbind:function(a,b){this._events=this._events||{},a in this._events!=!1&&this._events[a].splice(c(this._events[a],b),1)},trigger:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;bc;c++)if(a=b[c]+"ransform",a in f)return b[c].substr(0,b[c].length-1);return!1}(),h=g?"-"+g.toLowerCase()+"-":"",i=d("transform"),j=d("transitionDuration"),k=d("perspective")in f,l="ontouchstart"in a,m=!!g,n=(d("transition")in f,k?" translateZ(0)":""),o="onorientationchange"in a?"orientationchange":"resize",p=l?"touchstart":"mousedown",q=l?"touchmove":"mousemove",r=l?"touchend":"mouseup",s=l?"touchcancel":"mouseup",t=function(){if(g===!1)return!1;var a={"":"transitionend",webkit:"webkitTransitionEnd",Moz:"transitionend",O:"oTransitionEnd",ms:"MSTransitionEnd"};return a[g]}(),u=function(a,b,c,d){"addEventListener"in a?a.addEventListener(b,c,d):"attachEvent"in a&&a.attachEvent("on"+b,c)},v=function(a,b,c){"removeEventListener"in a?a.removeEventListener(b,c):"detachEvent"in a&&a.detachEvent("on"+b,c)},w=function(a){a.preventDefault?a.preventDefault():a.returnValue=!1},x=function(a){return"pageX"in a?a.pageX:a.clientX+b.body.scrollLeft+b.documentElement.scrollLeft},y=function(a){return"pageY"in a?a.pageY:a.clientY+b.body.scrollTop+b.documentElement.scrollTop},z=0,A=function(c,d){var f,i,j,k;this.wrapper="string"==typeof c?b.querySelector(c):c,this.id=this.wrapper.id||"sw-id"+ ++z,this.options={text:null,numberOfPages:3,snapThreshold:null,hastyPageFlip:!1,vertical:!1,loop:!0,clientWidth:1024,clientHeight:145};for(f in d)this.options[f]=d[f];for(this.currentMasterPage=1,this.k=0,this.maxK=0,this.page=0,this.pageIndex=0,this.E=new e,this.customEvents=[],this.wrapperWidth=0,this.wrapperHeight=0,this.pageSize=0,this.initiated=!1,this.identifier=null,this.moved=!1,this.thresholdExceeded=!1,this.startX=0,this.startX=0,this.pointX=0,this.pointY=0,this.stepsX=0,this.stepsY=0,this.direction=0,this.directionLocked=!1,this.cssPosition=this.options.vertical?"top":"left",this.wrapper.style.overflow="hidden",this.wrapper.style.position="relative",this.masterPages=[],i=b.createElement("div"),i.className="swipeview-slider",i.style.cssText="position:relative;top:0;height:100%;width:100%;"+h+"transition-duration:0;"+h+"transform:translateZ(0);"+h+"transition-timing-function:ease-out",this.wrapper.appendChild(i),this.slider=i,this.refreshSize(),f=-1;2>f;f++)i=b.createElement("div"),i.style.cssText=h+"transform:translateZ(0);position:absolute;top:0;height:100%;width:100%;"+this.cssPosition+":"+100*f+"%",i.dataset||(i.dataset={}),k=-1==f?this.options.numberOfPages-1:f,i.dataset.pageIndex=k,i.dataset.upcomingPageIndex=k,this.options.loop||-1!=f||(i.style.visibility="hidden"),this.slider.appendChild(i),this.masterPages.push(i);j=this.masterPages[1].className,this.masterPages[1].className=j?j+" swipeview-active":"swipeview-active";var m=this;this.handleEventF=function(a){m.handleEvent(a)},u(a,o,this.handleEventF,!1),u(this.wrapper,p,this.handleEventF,!1),u(this.wrapper,q,this.handleEventF,!1),u(this.wrapper,r,this.handleEventF,!1),u(this.slider,t,this.handleEventF,!1),"O"==g&&u(this.slider,t.toLowerCase(),this.handleEventF,!1),l||u(this.wrapper,"mouseout",this.handleEventF,!1)};return A.prototype={reset:function(a){this.goToPage(0),this.updatePageCount(a),this.refreshSize()},onFlip:function(a){this.E.bind("flip",a),this.customEvents.push(["flip",a])},onMoveOut:function(a){this.E.bind("moveout",a),this.customEvents.push(["moveout",a])},onMoveIn:function(a){this.E.bind("movein",a),this.customEvents.push(["movein",a])},onTouchStart:function(a){this.E.bind("touchstart",a),this.customEvents.push(["touchstart",a])},unbind:function(){for(;this.customEvents.length;)this.E.unbind(this.customEvents[0][0],this.customEvents[0][1]),this.customEvents.shift()},destroy:function(){this.unbind(),v(a,o,this.handleEventF),v(this.wrapper,p,this.handleEventF),v(this.wrapper,q,this.handleEventF),v(this.wrapper,r,this.handleEventF),v(this.slider,t,this.handleEventF),l||v(this.wrapper,"mouseout",this.handleEventF)},refreshSize:function(){this.wrapperWidth=0===this.wrapper.clientWidth?this.options.clientWidth:this.wrapper.clientWidth,this.wrapperHeight=0===this.wrapper.clientHeight?this.options.clientHeight:this.wrapper.clientHeight,this.wrapperSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.pageSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize,this.snapThreshold=null===this.options.snapThreshold?Math.round(.15*this.pageSize):/%/.test(this.options.snapThreshold)?Math.round(this.pageSize*this.options.snapThreshold.replace("%","")/100):this.options.snapThreshold},updatePageCount:function(a){this.options.numberOfPages=a,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize},goToPage:function(a){var b;for(this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/,""),b=0;3>b;b++)className=this.masterPages[b].className,/(^|\s)swipeview-loading(\s|$)/.test(className)||(this.masterPages[b].className=className?className+" swipeview-loading":"swipeview-loading");a=0>a?0:a>this.options.numberOfPages-1?this.options.numberOfPages-1:a,this.page=a,this.pageIndex=a,this.slider.style[j]="0s",this.__pos(-a*this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className+" swipeview-active";var c=function(a){return 0===a?[2,0,1]:1===a?[0,1,2]:[1,2,0]}(this.currentMasterPage);this.masterPages[c[0]].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[c[1]].style[this.cssPosition]=100*this.page+"%",this.masterPages[c[2]].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[c[0]].dataset.upcomingPageIndex=0===this.page?this.options.loop?this.options.numberOfPages-1:void 0:this.page-1,this.masterPages[c[1]].dataset.upcomingPageIndex=this.page,this.masterPages[c[2]].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?this.options.loop?0:void 0:this.page+1,this.options.loop||(this.masterPages[c[0]].style.visibility=0===this.page?"hidden":"",this.masterPages[c[1]].style.visibility="",this.masterPages[c[2]].style.visibility=this.page===this.options.numberOfPages-1?"hidden":""),this.__flip(!0)},next:function(){(this.options.loop||this.k!=this.maxK)&&(this.direction=-1,this.k-=1,this.__checkPosition())},prev:function(){(this.options.loop||0!==this.k)&&(this.direction=1,this.k+=1,this.__checkPosition())},handleEvent:function(a){switch(a.type){case p:this.__start(a);break;case q:this.__move(a);break;case"mouseout":if(this.initiated){for(var b=this.wrapper.getElementsByTagName("*"),c=0;cb;b++)a.changedTouches.item(b).identifier===this.identifier&&(d=a.changedTouches.item(b));if(!d)return}else d=a;var e=x(d)-this.pointX,f=y(d)-this.pointY,g=this.options.vertical?this.k+f:this.k+e,h=this.options.vertical?Math.abs(y(d)-this.startY):Math.abs(x(d)-this.startX);if(!(Math.abs(h)>=this.pageSize||(this.moved=!0,this.pointX=x(d),this.pointY=y(d),this.direction=this.options.vertical?f>0?1:0>f?-1:0:e>0?1:0>e?-1:0,this.stepsX+=Math.abs(e),this.stepsY+=Math.abs(f),this.stepsX<10&&this.stepsY<10))){if(!this.directionLocked&&(this.options.vertical?this.stepsX>this.stepsY:this.stepsY>this.stepsX))return this.initiated=!1,void 0;w(a),this.directionLocked=!0,!this.options.loop&&(g>0||g=this.snapThreshold?(this.thresholdExceeded=!0,this.E.trigger("moveout")):this.thresholdExceeded&&hc;c++)if(a.touches.item(c).identifier===this.identifier)return;for(c=0,d=a.changedTouches.length;d>c;c++)a.changedTouches.item(c).identifier===this.identifier&&(b=a.changedTouches.item(c));if(!b)return this.__pos(-this.page*this.pageSize),this.initiated=!1,void 0}else b=a;var e=this.options.vertical?Math.abs(y(b)-this.startY):Math.abs(x(b)-this.startX);if(this.initiated=!1,this.moved)return!this.options.loop&&(this.k>0||this.k0?(this.page=-Math.ceil(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=0===this.pageIndex?this.options.numberOfPages-1:this.pageIndex-1,a=this.currentMasterPage-1,a=0>a?2:a,this.masterPages[a].style[this.cssPosition]=100*this.page-100+"%",b=this.page-1,b-=Math.floor(b/this.options.numberOfPages)*this.options.numberOfPages,b=b!==this.options.numberOfPages||this.options.loop?b:void 0):(this.page=-Math.floor(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=this.pageIndex==this.options.numberOfPages-1?0:this.pageIndex+1,a=this.currentMasterPage+1,a=a>2?0:a,this.masterPages[a].style[this.cssPosition]=100*this.page+100+"%",b=this.page+1,b-=Math.floor(b/this.options.numberOfPages)*this.options.numberOfPages,b=0!==b||this.options.loop?b:void 0),c=this.masterPages[this.currentMasterPage].className,/(^|\s)swipeview-active(\s|$)/.test(c)||(this.masterPages[this.currentMasterPage].className=c?c+" swipeview-active":"swipeview-active"),c=this.masterPages[a].className,/(^|\s)swipeview-loading(\s|$)/.test(c)||(this.masterPages[a].className=c?c+" swipeview-loading":"swipeview-loading"),this.masterPages[a].dataset.upcomingPageIndex=b,newC=-this.page*this.pageSize,this.slider.style[j]=Math.floor(500*Math.abs(this.k-newC)/this.pageSize)+"ms",this.options.loop||(this.masterPages[a].style.visibility=0===newC||newC==this.maxK?"hidden":""),this.k==newC?this.__flip():(this.__pos(newC),this.options.hastyPageFlip&&this.__flip())},__flip:function(a){this.E.trigger("flip",{triggeredByGoto:!!a});for(var b=0;3>b;b++)this.masterPages[b].className=this.masterPages[b].className.replace(/(^|\s)swipeview-loading(\s|$)/,""),this.masterPages[b].dataset.pageIndex=this.masterPages[b].dataset.upcomingPageIndex}},A}(window,document); \ No newline at end of file diff --git a/dist/swipeview-1.3.0.min.js b/dist/swipeview-1.3.0.min.js new file mode 100644 index 0000000..bac9752 --- /dev/null +++ b/dist/swipeview-1.3.0.min.js @@ -0,0 +1,2 @@ +/*! swipeview 1.3.0 - Virtually infinite loop-able horizontal carousel - a fork of the original SwipeView from Matteo Spinelli */ +var SwipeView=function(a,b){function c(a,b){var c;for(c=a.length-1;c>-1&&a[c]!==b;--c);return c}function d(a){return""===g?a:(a=a.charAt(0).toUpperCase()+a.substr(1),g+a)}var e=function(){};e.prototype={bind:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},unbind:function(a,b){this._events=this._events||{},a in this._events!=!1&&this._events[a].splice(c(this._events[a],b),1)},trigger:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;bc;c++)if(a=b[c]+"ransform",a in f)return b[c].substr(0,b[c].length-1);return!1}(),h=g?"-"+g.toLowerCase()+"-":"",i=d("transform"),j=d("transitionDuration"),k=d("perspective")in f,l="ontouchstart"in a,m=!!g,n=(d("transition")in f,k?" translateZ(0)":""),o="onorientationchange"in a?"orientationchange":"resize",p=l?"touchstart":"mousedown",q=l?"touchmove":"mousemove",r=l?"touchend":"mouseup",s=l?"touchcancel":"mouseup",t=function(){if(g===!1)return!1;var a={"":"transitionend",webkit:"webkitTransitionEnd",Moz:"transitionend",O:"oTransitionEnd",ms:"MSTransitionEnd"};return a[g]}(),u=function(a,b,c,d){"addEventListener"in a?a.addEventListener(b,c,d):"attachEvent"in a&&a.attachEvent("on"+b,c)},v=function(a,b,c){"removeEventListener"in a?a.removeEventListener(b,c):"detachEvent"in a&&a.detachEvent("on"+b,c)},w=function(a){a.preventDefault?a.preventDefault():a.returnValue=!1},x=function(a){return"pageX"in a?a.pageX:a.clientX+b.body.scrollLeft+b.documentElement.scrollLeft},y=function(a){return"pageY"in a?a.pageY:a.clientY+b.body.scrollTop+b.documentElement.scrollTop},z=0,A=function(a,c){var d,f,g,i;this.wrapper="string"==typeof a?b.querySelector(a):a,this.id=this.wrapper.id||"sw-id"+ ++z,this.options={text:null,numberOfPages:3,snapThreshold:null,hastyPageFlip:!1,vertical:!1,loop:!0,clientWidth:1024,clientHeight:145};for(d in c)this.options[d]=c[d];for(this.currentMasterPage=1,this.k=0,this.maxK=0,this.page=0,this.pageIndex=0,this.E=new e,this.customEvents=[],this.wrapperWidth=0,this.wrapperHeight=0,this.pageSize=0,this.initiated=!1,this.identifier=null,this.moved=!1,this.thresholdExceeded=!1,this.startX=0,this.startX=0,this.pointX=0,this.pointY=0,this.stepsX=0,this.stepsY=0,this.direction=0,this.directionLocked=!1,this.cssPosition=this.options.vertical?"top":"left",this.wrapper.style.overflow="hidden",this.wrapper.style.position="relative",this.masterPages=[],f=b.createElement("div"),f.className="swipeview-slider",f.style.cssText="position:relative;top:0;height:100%;width:100%;"+h+"transition-duration:0;"+h+"transform:translateZ(0);"+h+"transition-timing-function:ease-out",this.wrapper.appendChild(f),this.slider=f,this.refreshSize(),d=-1;2>d;d++)f=b.createElement("div"),f.style.cssText=h+"transform:translateZ(0);position:absolute;top:0;height:100%;width:100%;"+this.cssPosition+":"+100*d+"%",f.dataset||(f.dataset={}),i=-1==d?this.options.numberOfPages-1:d,f.dataset.pageIndex=i,f.dataset.upcomingPageIndex=i,this.options.loop||-1!=d||(f.style.visibility="hidden"),this.slider.appendChild(f),this.masterPages.push(f);g=this.masterPages[1].className,this.masterPages[1].className=g?g+" swipeview-active":"swipeview-active";var j=this;this.handleEventF=function(a){j.handleEvent(a)}};return A.prototype={bind:function(){return u(a,o,this.handleEventF,!1),u(this.wrapper,p,this.handleEventF,!1),u(this.wrapper,q,this.handleEventF,!1),u(this.wrapper,r,this.handleEventF,!1),u(this.slider,t,this.handleEventF,!1),"O"==g&&u(this.slider,t.toLowerCase(),this.handleEventF,!1),l||u(this.wrapper,"mouseout",this.handleEventF,!1),this},unbind:function(){return v(a,o,this.handleEventF),v(this.wrapper,p,this.handleEventF),v(this.wrapper,q,this.handleEventF),v(this.wrapper,r,this.handleEventF),v(this.slider,t,this.handleEventF),l||v(this.wrapper,"mouseout",this.handleEventF),this},offAll:function(){for(;this.customEvents.length;)this.E.unbind(this.customEvents[0][0],this.customEvents[0][1]),this.customEvents.shift()},reset:function(a){this.goToPage(0),this.updatePageCount(a),this.refreshSize()},onFlip:function(a){this.E.bind("flip",a),this.customEvents.push(["flip",a])},onMoveOut:function(a){this.E.bind("moveout",a),this.customEvents.push(["moveout",a])},onMoveIn:function(a){this.E.bind("movein",a),this.customEvents.push(["movein",a])},onTouchStart:function(a){this.E.bind("touchstart",a),this.customEvents.push(["touchstart",a])},destroy:function(){this.unbind(),this.offAll()},refreshSize:function(){this.wrapperWidth=0===this.wrapper.clientWidth?this.options.clientWidth:this.wrapper.clientWidth,this.wrapperHeight=0===this.wrapper.clientHeight?this.options.clientHeight:this.wrapper.clientHeight,this.wrapperSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.pageSize=this.options.vertical?this.wrapperHeight:this.wrapperWidth,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize,this.snapThreshold=null===this.options.snapThreshold?Math.round(.15*this.pageSize):/%/.test(this.options.snapThreshold)?Math.round(this.pageSize*this.options.snapThreshold.replace("%","")/100):this.options.snapThreshold},updatePageCount:function(a){this.options.numberOfPages=a,this.maxK=-this.options.numberOfPages*this.pageSize+this.wrapperSize},goToPage:function(a){var b;for(this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/,""),b=0;3>b;b++)className=this.masterPages[b].className,/(^|\s)swipeview-loading(\s|$)/.test(className)||(this.masterPages[b].className=className?className+" swipeview-loading":"swipeview-loading");a=0>a?0:a>this.options.numberOfPages-1?this.options.numberOfPages-1:a,this.page=a,this.pageIndex=a,this.slider.style[j]="0s",this.__pos(-a*this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.masterPages[this.currentMasterPage].className=this.masterPages[this.currentMasterPage].className+" swipeview-active";var c=function(a){return 0===a?[2,0,1]:1===a?[0,1,2]:[1,2,0]}(this.currentMasterPage);this.masterPages[c[0]].style[this.cssPosition]=100*this.page-100+"%",this.masterPages[c[1]].style[this.cssPosition]=100*this.page+"%",this.masterPages[c[2]].style[this.cssPosition]=100*this.page+100+"%",this.masterPages[c[0]].dataset.upcomingPageIndex=0===this.page?this.options.loop?this.options.numberOfPages-1:void 0:this.page-1,this.masterPages[c[1]].dataset.upcomingPageIndex=this.page,this.masterPages[c[2]].dataset.upcomingPageIndex=this.page==this.options.numberOfPages-1?this.options.loop?0:void 0:this.page+1,this.options.loop||(this.masterPages[c[0]].style.visibility=0===this.page?"hidden":"",this.masterPages[c[1]].style.visibility="",this.masterPages[c[2]].style.visibility=this.page===this.options.numberOfPages-1?"hidden":""),this.__flip(!0)},next:function(){(this.options.loop||this.k!=this.maxK)&&(this.direction=-1,this.k-=1,this.__checkPosition())},prev:function(){(this.options.loop||0!==this.k)&&(this.direction=1,this.k+=1,this.__checkPosition())},handleEvent:function(a){switch(a.type){case p:this.__start(a);break;case q:this.__move(a);break;case"mouseout":if(this.initiated){for(var b=this.wrapper.getElementsByTagName("*"),c=0;cb;b++)a.changedTouches.item(b).identifier===this.identifier&&(d=a.changedTouches.item(b));if(!d)return}else d=a;var e=x(d)-this.pointX,f=y(d)-this.pointY,g=this.options.vertical?this.k+f:this.k+e,h=this.options.vertical?Math.abs(y(d)-this.startY):Math.abs(x(d)-this.startX);if(!(Math.abs(h)>=this.pageSize||(this.moved=!0,this.pointX=x(d),this.pointY=y(d),this.direction=this.options.vertical?f>0?1:0>f?-1:0:e>0?1:0>e?-1:0,this.stepsX+=Math.abs(e),this.stepsY+=Math.abs(f),this.stepsX<10&&this.stepsY<10))){if(!this.directionLocked&&(this.options.vertical?this.stepsX>this.stepsY:this.stepsY>this.stepsX))return this.initiated=!1,void 0;w(a),this.directionLocked=!0,!this.options.loop&&(g>0||g=this.snapThreshold?(this.thresholdExceeded=!0,this.E.trigger("moveout")):this.thresholdExceeded&&hc;c++)if(a.touches.item(c).identifier===this.identifier)return;for(c=0,d=a.changedTouches.length;d>c;c++)a.changedTouches.item(c).identifier===this.identifier&&(b=a.changedTouches.item(c));if(!b)return this.__pos(-this.page*this.pageSize),this.initiated=!1,void 0}else b=a;var e=this.options.vertical?Math.abs(y(b)-this.startY):Math.abs(x(b)-this.startX);if(this.initiated=!1,this.moved)return!this.options.loop&&(this.k>0||this.k0?(this.page=-Math.ceil(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=0===this.pageIndex?this.options.numberOfPages-1:this.pageIndex-1,a=this.currentMasterPage-1,a=0>a?2:a,this.masterPages[a].style[this.cssPosition]=100*this.page-100+"%",b=this.page-1,b-=Math.floor(b/this.options.numberOfPages)*this.options.numberOfPages,b=b!==this.options.numberOfPages||this.options.loop?b:void 0):(this.page=-Math.floor(this.k/this.pageSize),this.currentMasterPage=this.page+1-3*Math.floor((this.page+1)/3),this.pageIndex=this.pageIndex==this.options.numberOfPages-1?0:this.pageIndex+1,a=this.currentMasterPage+1,a=a>2?0:a,this.masterPages[a].style[this.cssPosition]=100*this.page+100+"%",b=this.page+1,b-=Math.floor(b/this.options.numberOfPages)*this.options.numberOfPages,b=0!==b||this.options.loop?b:void 0),c=this.masterPages[this.currentMasterPage].className,/(^|\s)swipeview-active(\s|$)/.test(c)||(this.masterPages[this.currentMasterPage].className=c?c+" swipeview-active":"swipeview-active"),c=this.masterPages[a].className,/(^|\s)swipeview-loading(\s|$)/.test(c)||(this.masterPages[a].className=c?c+" swipeview-loading":"swipeview-loading"),this.masterPages[a].dataset.upcomingPageIndex=b,newC=-this.page*this.pageSize,this.slider.style[j]=Math.floor(500*Math.abs(this.k-newC)/this.pageSize)+"ms",this.options.loop||(this.masterPages[a].style.visibility=0===newC||newC==this.maxK?"hidden":""),this.k==newC?this.__flip():(this.__pos(newC),this.options.hastyPageFlip&&this.__flip())},__flip:function(a){this.E.trigger("flip",{triggeredByGoto:!!a});for(var b=0;3>b;b++)this.masterPages[b].className=this.masterPages[b].className.replace(/(^|\s)swipeview-loading(\s|$)/,""),this.masterPages[b].dataset.pageIndex=this.masterPages[b].dataset.upcomingPageIndex}},A}(window,document); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..b3f09d3 --- /dev/null +++ b/package.json @@ -0,0 +1,31 @@ +{ + "name": "swipeview", + "version": "1.3.0", + "description": "Virtually infinite loop-able horizontal carousel - a fork of the original SwipeView from Matteo Spinelli", + "keywords": [ + "swipe", + "mobile", + "carousel", + "infinite" + ], + "author": "Matteo Spinelli (http://cubiq.org/)", + "contributors": [{ + "name" : "Paul Panserrieu", + "email": "paul@42loops.com", + "url" : "http://42loops.com" + }], + "dependencies" : { }, + "devDependencies": { + "grunt": "~0.4.1", + "grunt-contrib-jshint": "~0.6.0", + "grunt-contrib-connect" : "~0.1.2", + "grunt-contrib-uglify": "~0.2.2", + "grunt-contrib-watch": "~0.4.4" + }, + "main": "src/swipeview.js", + "license": "MIT", + "repository": { + "type": "git", + "url": "git@github.com:peutetre/SwipeView.git" + } +} diff --git a/src/swipeview.js b/src/swipeview.js index 56b0a00..65fb605 100644 --- a/src/swipeview.js +++ b/src/swipeview.js @@ -2,470 +2,674 @@ * SwipeView v1.0 ~ Copyright (c) 2012 Matteo Spinelli, http://cubiq.org * Released under MIT license, http://cubiq.org/license */ + var SwipeView = (function (window, document) { - var dummyStyle = document.createElement('div').style, - vendor = (function () { - var vendors = 't,webkitT,MozT,msT,OT'.split(','), - t, - i = 0, - l = vendors.length; - - for ( ; i < l; i++ ) { - t = vendors[i] + 'ransform'; - if ( t in dummyStyle ) { - return vendors[i].substr(0, vendors[i].length - 1); - } - } - - return false; - })(), - cssVendor = vendor ? '-' + vendor.toLowerCase() + '-' : '', - - // Style properties - transform = prefixStyle('transform'), - transitionDuration = prefixStyle('transitionDuration'), - - // Browser capabilities - has3d = prefixStyle('perspective') in dummyStyle, - hasTouch = 'ontouchstart' in window, - hasTransform = !!vendor, - hasTransitionEnd = prefixStyle('transition') in dummyStyle, - - // Helpers - translateZ = has3d ? ' translateZ(0)' : '', - - // Events - resizeEvent = 'onorientationchange' in window ? 'orientationchange' : 'resize', - startEvent = hasTouch ? 'touchstart' : 'mousedown', - moveEvent = hasTouch ? 'touchmove' : 'mousemove', - endEvent = hasTouch ? 'touchend' : 'mouseup', - cancelEvent = hasTouch ? 'touchcancel' : 'mouseup', - transitionEndEvent = (function () { - if ( vendor === false ) return false; - - var transitionEnd = { - '' : 'transitionend', - 'webkit' : 'webkitTransitionEnd', - 'Moz' : 'transitionend', - 'O' : 'oTransitionEnd', - 'ms' : 'MSTransitionEnd' - }; - - return transitionEnd[vendor]; - })(), - - SwipeView = function (el, options) { - var i, - div, - className, - pageIndex; - - this.wrapper = typeof el == 'string' ? document.querySelector(el) : el; - this.options = { - text: null, - numberOfPages: 3, - snapThreshold: null, - hastyPageFlip: false, - loop: true - }; - - // User defined options - for (i in options) this.options[i] = options[i]; - - this.wrapper.style.overflow = 'hidden'; - this.wrapper.style.position = 'relative'; - - this.masterPages = []; - - div = document.createElement('div'); - div.id = 'swipeview-slider'; - div.style.cssText = 'position:relative;top:0;height:100%;width:100%;' + cssVendor + 'transition-duration:0;' + cssVendor + 'transform:translateZ(0);' + cssVendor + 'transition-timing-function:ease-out'; - this.wrapper.appendChild(div); - this.slider = div; - - this.refreshSize(); - - for (i=-1; i<2; i++) { - div = document.createElement('div'); - div.id = 'swipeview-masterpage-' + (i+1); - div.style.cssText = cssVendor + 'transform:translateZ(0);position:absolute;top:0;height:100%;width:100%;left:' + i*100 + '%'; - if (!div.dataset) div.dataset = {}; - pageIndex = i == -1 ? this.options.numberOfPages - 1 : i; - div.dataset.pageIndex = pageIndex; - div.dataset.upcomingPageIndex = pageIndex; - - if (!this.options.loop && i == -1) div.style.visibility = 'hidden'; - - this.slider.appendChild(div); - this.masterPages.push(div); - } - - className = this.masterPages[1].className; - this.masterPages[1].className = !className ? 'swipeview-active' : className + ' swipeview-active'; - - window.addEventListener(resizeEvent, this, false); - this.wrapper.addEventListener(startEvent, this, false); - this.wrapper.addEventListener(moveEvent, this, false); - this.wrapper.addEventListener(endEvent, this, false); - this.slider.addEventListener(transitionEndEvent, this, false); - // in Opera >= 12 the transitionend event is lowercase so we register both events - if ( vendor == 'O' ) this.slider.addEventListener(transitionEndEvent.toLowerCase(), this, false); - -/* if (!hasTouch) { - this.wrapper.addEventListener('mouseout', this, false); - }*/ - }; - - SwipeView.prototype = { - currentMasterPage: 1, - x: 0, - page: 0, - pageIndex: 0, - customEvents: [], - - onFlip: function (fn) { - this.wrapper.addEventListener('swipeview-flip', fn, false); - this.customEvents.push(['flip', fn]); - }, - - onMoveOut: function (fn) { - this.wrapper.addEventListener('swipeview-moveout', fn, false); - this.customEvents.push(['moveout', fn]); - }, - - onMoveIn: function (fn) { - this.wrapper.addEventListener('swipeview-movein', fn, false); - this.customEvents.push(['movein', fn]); - }, - - onTouchStart: function (fn) { - this.wrapper.addEventListener('swipeview-touchstart', fn, false); - this.customEvents.push(['touchstart', fn]); - }, - - destroy: function () { - while ( this.customEvents.length ) { - this.wrapper.removeEventListener('swipeview-' + this.customEvents[0][0], this.customEvents[0][1], false); - this.customEvents.shift(); - } - - // Remove the event listeners - window.removeEventListener(resizeEvent, this, false); - this.wrapper.removeEventListener(startEvent, this, false); - this.wrapper.removeEventListener(moveEvent, this, false); - this.wrapper.removeEventListener(endEvent, this, false); - this.slider.removeEventListener(transitionEndEvent, this, false); - -/* if (!hasTouch) { - this.wrapper.removeEventListener('mouseout', this, false); - }*/ - }, - - refreshSize: function () { - this.wrapperWidth = this.wrapper.clientWidth; - this.wrapperHeight = this.wrapper.clientHeight; - this.pageWidth = this.wrapperWidth; - this.maxX = -this.options.numberOfPages * this.pageWidth + this.wrapperWidth; - this.snapThreshold = this.options.snapThreshold === null ? - Math.round(this.pageWidth * 0.15) : - /%/.test(this.options.snapThreshold) ? - Math.round(this.pageWidth * this.options.snapThreshold.replace('%', '') / 100) : - this.options.snapThreshold; - }, - - updatePageCount: function (n) { - this.options.numberOfPages = n; - this.maxX = -this.options.numberOfPages * this.pageWidth + this.wrapperWidth; - }, - - goToPage: function (p) { - var i; - - this.masterPages[this.currentMasterPage].className = this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/, ''); - for (i=0; i<3; i++) { - className = this.masterPages[i].className; - /(^|\s)swipeview-loading(\s|$)/.test(className) || (this.masterPages[i].className = !className ? 'swipeview-loading' : className + ' swipeview-loading'); - } - - p = p < 0 ? 0 : p > this.options.numberOfPages-1 ? this.options.numberOfPages-1 : p; - this.page = p; - this.pageIndex = p; - this.slider.style[transitionDuration] = '0s'; - this.__pos(-p * this.pageWidth); - - this.currentMasterPage = (this.page + 1) - Math.floor((this.page + 1) / 3) * 3; - - this.masterPages[this.currentMasterPage].className = this.masterPages[this.currentMasterPage].className + ' swipeview-active'; - - if (this.currentMasterPage === 0) { - this.masterPages[2].style.left = this.page * 100 - 100 + '%'; - this.masterPages[0].style.left = this.page * 100 + '%'; - this.masterPages[1].style.left = this.page * 100 + 100 + '%'; - - this.masterPages[2].dataset.upcomingPageIndex = this.page === 0 ? this.options.numberOfPages-1 : this.page - 1; - this.masterPages[0].dataset.upcomingPageIndex = this.page; - this.masterPages[1].dataset.upcomingPageIndex = this.page == this.options.numberOfPages-1 ? 0 : this.page + 1; - } else if (this.currentMasterPage == 1) { - this.masterPages[0].style.left = this.page * 100 - 100 + '%'; - this.masterPages[1].style.left = this.page * 100 + '%'; - this.masterPages[2].style.left = this.page * 100 + 100 + '%'; - - this.masterPages[0].dataset.upcomingPageIndex = this.page === 0 ? this.options.numberOfPages-1 : this.page - 1; - this.masterPages[1].dataset.upcomingPageIndex = this.page; - this.masterPages[2].dataset.upcomingPageIndex = this.page == this.options.numberOfPages-1 ? 0 : this.page + 1; - } else { - this.masterPages[1].style.left = this.page * 100 - 100 + '%'; - this.masterPages[2].style.left = this.page * 100 + '%'; - this.masterPages[0].style.left = this.page * 100 + 100 + '%'; - - this.masterPages[1].dataset.upcomingPageIndex = this.page === 0 ? this.options.numberOfPages-1 : this.page - 1; - this.masterPages[2].dataset.upcomingPageIndex = this.page; - this.masterPages[0].dataset.upcomingPageIndex = this.page == this.options.numberOfPages-1 ? 0 : this.page + 1; - } - - this.__flip(); - }, - - next: function () { - if (!this.options.loop && this.x == this.maxX) return; - - this.directionX = -1; - this.x -= 1; - this.__checkPosition(); - }, - - prev: function () { - if (!this.options.loop && this.x === 0) return; - - this.directionX = 1; - this.x += 1; - this.__checkPosition(); - }, - - handleEvent: function (e) { - switch (e.type) { - case startEvent: - this.__start(e); - break; - case moveEvent: - this.__move(e); - break; - case cancelEvent: - case endEvent: - this.__end(e); - break; - case resizeEvent: - this.__resize(); - break; - case transitionEndEvent: - case 'otransitionend': - if (e.target == this.slider && !this.options.hastyPageFlip) this.__flip(); - break; - } - }, - - - /** - * - * Pseudo private methods - * - */ - __pos: function (x) { - this.x = x; - this.slider.style[transform] = 'translate(' + x + 'px,0)' + translateZ; - }, - - __resize: function () { - this.refreshSize(); - this.slider.style[transitionDuration] = '0s'; - this.__pos(-this.page * this.pageWidth); - }, - - __start: function (e) { - //e.preventDefault(); - - if (this.initiated) return; - - var point = hasTouch ? e.touches[0] : e; - - this.initiated = true; - this.moved = false; - this.thresholdExceeded = false; - this.startX = point.pageX; - this.startY = point.pageY; - this.pointX = point.pageX; - this.pointY = point.pageY; - this.stepsX = 0; - this.stepsY = 0; - this.directionX = 0; - this.directionLocked = false; - -/* var matrix = getComputedStyle(this.slider, null).webkitTransform.replace(/[^0-9-.,]/g, '').split(','); - this.x = matrix[4] * 1;*/ - - this.slider.style[transitionDuration] = '0s'; - - this.__event('touchstart'); - }, - - __move: function (e) { - if (!this.initiated) return; - - var point = hasTouch ? e.touches[0] : e, - deltaX = point.pageX - this.pointX, - deltaY = point.pageY - this.pointY, - newX = this.x + deltaX, - dist = Math.abs(point.pageX - this.startX); - - this.moved = true; - this.pointX = point.pageX; - this.pointY = point.pageY; - this.directionX = deltaX > 0 ? 1 : deltaX < 0 ? -1 : 0; - this.stepsX += Math.abs(deltaX); - this.stepsY += Math.abs(deltaY); - - // We take a 10px buffer to figure out the direction of the swipe - if (this.stepsX < 10 && this.stepsY < 10) { -// e.preventDefault(); - return; - } - - // We are scrolling vertically, so skip SwipeView and give the control back to the browser - if (!this.directionLocked && this.stepsY > this.stepsX) { - this.initiated = false; - return; - } - - e.preventDefault(); - - this.directionLocked = true; - - if (!this.options.loop && (newX > 0 || newX < this.maxX)) { - newX = this.x + (deltaX / 2); - } - - if (!this.thresholdExceeded && dist >= this.snapThreshold) { - this.thresholdExceeded = true; - this.__event('moveout'); - } else if (this.thresholdExceeded && dist < this.snapThreshold) { - this.thresholdExceeded = false; - this.__event('movein'); - } - -/* if (newX > 0 || newX < this.maxX) { - newX = this.x + (deltaX / 2); - }*/ - - this.__pos(newX); - }, - - __end: function (e) { - if (!this.initiated) return; - - var point = hasTouch ? e.changedTouches[0] : e, - dist = Math.abs(point.pageX - this.startX); - - this.initiated = false; - - if (!this.moved) return; - - if (!this.options.loop && (this.x > 0 || this.x < this.maxX)) { - dist = 0; - this.__event('movein'); - } - - // Check if we exceeded the snap threshold - if (dist < this.snapThreshold) { - this.slider.style[transitionDuration] = Math.floor(300 * dist / this.snapThreshold) + 'ms'; - this.__pos(-this.page * this.pageWidth); - return; - } - - this.__checkPosition(); - }, - - __checkPosition: function () { - var pageFlip, - pageFlipIndex, - className; - - this.masterPages[this.currentMasterPage].className = this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/, ''); - - // Flip the page - if (this.directionX > 0) { - this.page = -Math.ceil(this.x / this.pageWidth); - this.currentMasterPage = (this.page + 1) - Math.floor((this.page + 1) / 3) * 3; - this.pageIndex = this.pageIndex === 0 ? this.options.numberOfPages - 1 : this.pageIndex - 1; - - pageFlip = this.currentMasterPage - 1; - pageFlip = pageFlip < 0 ? 2 : pageFlip; - this.masterPages[pageFlip].style.left = this.page * 100 - 100 + '%'; - - pageFlipIndex = this.page - 1; - } else { - this.page = -Math.floor(this.x / this.pageWidth); - this.currentMasterPage = (this.page + 1) - Math.floor((this.page + 1) / 3) * 3; - this.pageIndex = this.pageIndex == this.options.numberOfPages - 1 ? 0 : this.pageIndex + 1; - - pageFlip = this.currentMasterPage + 1; - pageFlip = pageFlip > 2 ? 0 : pageFlip; - this.masterPages[pageFlip].style.left = this.page * 100 + 100 + '%'; - - pageFlipIndex = this.page + 1; - } - - // Add active class to current page - className = this.masterPages[this.currentMasterPage].className; - /(^|\s)swipeview-active(\s|$)/.test(className) || (this.masterPages[this.currentMasterPage].className = !className ? 'swipeview-active' : className + ' swipeview-active'); - - // Add loading class to flipped page - className = this.masterPages[pageFlip].className; - /(^|\s)swipeview-loading(\s|$)/.test(className) || (this.masterPages[pageFlip].className = !className ? 'swipeview-loading' : className + ' swipeview-loading'); - - pageFlipIndex = pageFlipIndex - Math.floor(pageFlipIndex / this.options.numberOfPages) * this.options.numberOfPages; - this.masterPages[pageFlip].dataset.upcomingPageIndex = pageFlipIndex; // Index to be loaded in the newly flipped page - - newX = -this.page * this.pageWidth; - - this.slider.style[transitionDuration] = Math.floor(500 * Math.abs(this.x - newX) / this.pageWidth) + 'ms'; - - // Hide the next page if we decided to disable looping - if (!this.options.loop) { - this.masterPages[pageFlip].style.visibility = newX === 0 || newX == this.maxX ? 'hidden' : ''; - } - - if (this.x == newX) { - this.__flip(); // If we swiped all the way long to the next page (extremely rare but still) - } else { - this.__pos(newX); - if (this.options.hastyPageFlip) this.__flip(); - } - }, - - __flip: function () { - this.__event('flip'); - - for (var i=0; i<3; i++) { - this.masterPages[i].className = this.masterPages[i].className.replace(/(^|\s)swipeview-loading(\s|$)/, ''); // Remove the loading class - this.masterPages[i].dataset.pageIndex = this.masterPages[i].dataset.upcomingPageIndex; - } - }, - - __event: function (type) { - var ev = document.createEvent("Event"); - - ev.initEvent('swipeview-' + type, true, true); - - this.wrapper.dispatchEvent(ev); - } - }; - - function prefixStyle (style) { - if ( vendor === '' ) return style; - - style = style.charAt(0).toUpperCase() + style.substr(1); - return vendor + style; - } - - return SwipeView; -})(window, document); \ No newline at end of file + + + function indexOf (array, el) { + var i; + for (i=array.length-1; i>-1 && array[i]!==el; --i); + return i; + } + + /** + * MicroEvent - https://github.com/jeromeetienne/microevent.js + * +Copyright (c) 2011 Jerome Etienne, http://jetienne.com + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + var MicroEvent = function(){}; + MicroEvent.prototype = { + bind: function(event, fct){ + this._events = this._events || {}; + this._events[event] = this._events[event] || []; + this._events[event].push(fct); + }, + unbind: function(event, fct){ + this._events = this._events || {}; + if( event in this._events === false ) return; + this._events[event].splice(indexOf(this._events[event], fct), 1); + }, + trigger: function(event /* , args... */){ + this._events = this._events || {}; + if( event in this._events === false ) return; + for(var i = 0; i < this._events[event].length; i++){ + this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1)); + } + } + }; + + + var dummyStyle = document.createElement('div').style, + vendor = (function () { + var vendors = 't,webkitT,MozT,msT,OT'.split(','), + t, + i = 0, + l = vendors.length; + + for ( ; i < l; i++ ) { + t = vendors[i] + 'ransform'; + if ( t in dummyStyle ) { + return vendors[i].substr(0, vendors[i].length - 1); + } + } + + return false; + })(), + cssVendor = vendor ? '-' + vendor.toLowerCase() + '-' : '', + + // Style properties + transform = prefixStyle('transform'), + transitionDuration = prefixStyle('transitionDuration'), + + // Browser capabilities + has3d = prefixStyle('perspective') in dummyStyle, + hasTouch = 'ontouchstart' in window, + hasTransform = !!vendor, + hasTransitionEnd = prefixStyle('transition') in dummyStyle, + + // Helpers + translateZ = has3d ? ' translateZ(0)' : '', + + // Events + resizeEvent = 'onorientationchange' in window ? 'orientationchange' : 'resize', + startEvent = hasTouch ? 'touchstart' : 'mousedown', + moveEvent = hasTouch ? 'touchmove' : 'mousemove', + endEvent = hasTouch ? 'touchend' : 'mouseup', + cancelEvent = hasTouch ? 'touchcancel' : 'mouseup', + transitionEndEvent = (function () { + if ( vendor === false ) return false; + + var transitionEnd = { + '' : 'transitionend', + 'webkit' : 'webkitTransitionEnd', + 'Moz' : 'transitionend', + 'O' : 'oTransitionEnd', + 'ms' : 'MSTransitionEnd' + }; + + return transitionEnd[vendor]; + })(), + + //~~~ IE polyfills + on = function (el, evt, fn, bubble) { + if("addEventListener" in el) { + el.addEventListener(evt, fn, bubble); + } else if("attachEvent" in el) { + el.attachEvent("on" + evt, fn); + } + }, + off = function (el, evt, fn) { + if("removeEventListener" in el) { + el.removeEventListener(evt, fn); + } + else if ("detachEvent" in el) { + el.detachEvent("on" + evt, fn); + } + }, + preventDefault = function (e) { + if (e.preventDefault) e.preventDefault(); + else e.returnValue = false; + }, + getPageX = function (e) { + if ('pageX' in e) + return e.pageX; + else + return e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; + return 0; + }, + getPageY = function (e) { + if ('pageY' in e) + return e.pageY; + else + return e.clientY + document.body.scrollTop + document.documentElement.scrollTop; + return 0; + }, + //~~~ end of IE polyfills + + uuid = 0, + + SwipeView = function (el, options) { + var i, + div, + className, + pageIndex; + + this.wrapper = typeof el == 'string' ? document.querySelector(el) : el; + this.id = this.wrapper.id || 'sw-id' + (++uuid); + this.options = { + text: null, + numberOfPages: 3, + snapThreshold: null, + hastyPageFlip: false, + vertical: false, + loop: true, + clientWidth: 1024, + clientHeight: 145 + }; + + // User defined options + for (i in options) this.options[i] = options[i]; + + this.currentMasterPage = 1; + this.k = 0; + this.maxK = 0; + this.page = 0; + this.pageIndex = 0; + this.E = new MicroEvent(); + this.customEvents = []; + this.wrapperWidth = 0; + this.wrapperHeight = 0; + this.pageSize = 0; + this.initiated = false; + this.identifier = null; + this.moved = false; + this.thresholdExceeded = false; + this.startX = 0; + this.startX = 0; + this.pointX = 0; + this.pointY = 0; + this.stepsX = 0; + this.stepsY = 0; + this.direction = 0; + this.directionLocked = false; + this.cssPosition = this.options.vertical ? 'top' : 'left'; + + this.wrapper.style.overflow = 'hidden'; + this.wrapper.style.position = 'relative'; + + this.masterPages = []; + + div = document.createElement('div'); + div.className = 'swipeview-slider'; + div.style.cssText = 'position:relative;top:0;height:100%;width:100%;' + + cssVendor + 'transition-duration:0;' + + cssVendor + 'transform:translateZ(0);' + + cssVendor + 'transition-timing-function:ease-out'; + this.wrapper.appendChild(div); + this.slider = div; + + this.refreshSize(); + + for (i=-1; i<2; i++) { + div = document.createElement('div'); + div.style.cssText = cssVendor + + 'transform:translateZ(0);position:absolute;top:0;height:100%;width:100%;' + + this.cssPosition + ':' + i*100 + '%'; + if (!div.dataset) div.dataset = {}; + pageIndex = i == -1 ? this.options.numberOfPages - 1 : i; + div.dataset.pageIndex = pageIndex; + div.dataset.upcomingPageIndex = pageIndex; + + if (!this.options.loop && i == -1) { + div.style.visibility = 'hidden'; + } + + this.slider.appendChild(div); + this.masterPages.push(div); + } + + className = this.masterPages[1].className; + this.masterPages[1].className = !className ? 'swipeview-active' : className + ' swipeview-active'; + + // handleEventF is used for binding function (required for IE) + var self = this; + this.handleEventF = function (e) { + self.handleEvent(e); + }; + + }; + + SwipeView.prototype = { + bind: function () { + if (this._bound) throw new Error("SwipeView was already bounded"); + this._bound = true; + on(window, resizeEvent, this.handleEventF, false); + on(this.wrapper, startEvent, this.handleEventF, false); + on(this.wrapper, moveEvent, this.handleEventF, false); + on(this.wrapper, endEvent, this.handleEventF, false); + on(this.slider, transitionEndEvent, this.handleEventF, false); + // in Opera >= 12 the transitionend event is lowercase so we register both events + if ( vendor == 'O' ) on(this.slider, transitionEndEvent.toLowerCase(), this.handleEventF, false); + + if (!hasTouch) { + on(this.wrapper, 'mouseout', this.handleEventF, false); + } + return this; + }, + + unbind : function(){ + if (!this._bound) throw new Error("SwipeView was not bounded"); + this._bound = false; + // Remove the event listeners + off(window, resizeEvent, this.handleEventF); + off(this.wrapper, startEvent, this.handleEventF); + off(this.wrapper, moveEvent, this.handleEventF); + off(this.wrapper, endEvent, this.handleEventF); + off(this.slider, transitionEndEvent, this.handleEventF); + + if (!hasTouch) { + off(this.wrapper, 'mouseout', this.handleEventF); + } + return this; + }, + + /** + * Removes all external events callbacks + */ + offAll: function () { + while ( this.customEvents.length ) { + this.E.unbind(this.customEvents[0][0], this.customEvents[0][1]); + this.customEvents.shift(); + } + }, + + reset : function (pageCount) { + this.goToPage(0); + this.updatePageCount(pageCount); + this.refreshSize(); + }, + + onFlip: function (fn) { + this.E.bind('flip', fn); + this.customEvents.push(['flip', fn]); + }, + + onMoveOut: function (fn) { + this.E.bind('moveout', fn); + this.customEvents.push(['moveout', fn]); + }, + + onMoveIn: function (fn) { + this.E.bind('movein', fn); + this.customEvents.push(['movein', fn]); + }, + + onTouchStart: function (fn) { + this.E.bind('touchstart', fn); + this.customEvents.push(['touchstart', fn]); + }, + + destroy: function () { + this.unbind(); + this.offAll(); + }, + + refreshSize: function () { + this.wrapperWidth = this.wrapper.clientWidth === 0 ? this.options.clientWidth : this.wrapper.clientWidth; + this.wrapperHeight = this.wrapper.clientHeight === 0 ? this.options.clientHeight : this.wrapper.clientHeight; + this.wrapperSize = this.options.vertical ? this.wrapperHeight : this.wrapperWidth; + this.pageSize = this.options.vertical ? this.wrapperHeight : this.wrapperWidth; + this.maxK = -this.options.numberOfPages * this.pageSize + this.wrapperSize; + this.snapThreshold = this.options.snapThreshold === null ? + Math.round(this.pageSize * 0.15) : + /%/.test(this.options.snapThreshold) ? + Math.round(this.pageSize * this.options.snapThreshold.replace('%', '') / 100) : + this.options.snapThreshold; + }, + + updatePageCount: function (n) { + this.options.numberOfPages = n; + this.maxK = -this.options.numberOfPages * this.pageSize + this.wrapperSize; + }, + + goToPage: function (p) { + var i; + + this.masterPages[this.currentMasterPage].className = this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/, ''); + for (i=0; i<3; i++) { + className = this.masterPages[i].className; + if(!/(^|\s)swipeview-loading(\s|$)/.test(className)) + this.masterPages[i].className = !className ? 'swipeview-loading' : className + ' swipeview-loading'; + } + + p = p < 0 ? 0 : p > this.options.numberOfPages-1 ? this.options.numberOfPages-1 : p; + this.page = p; + this.pageIndex = p; + this.slider.style[transitionDuration] = '0s'; + this.__pos(-p * this.pageSize); + + this.currentMasterPage = (this.page + 1) - Math.floor((this.page + 1) / 3) * 3; + + this.masterPages[this.currentMasterPage].className = this.masterPages[this.currentMasterPage].className + ' swipeview-active'; + + + var indices = (function calculatePagesIndexFromCurrent( currentMasterPage ){ + if (currentMasterPage === 0) return [2, 0, 1]; + else if (currentMasterPage === 1) return [0, 1, 2]; + else return [1, 2, 0]; + })(this.currentMasterPage); + + this.masterPages[ indices[0] ].style[this.cssPosition] = this.page * 100 - 100 + '%'; + this.masterPages[ indices[1] ].style[this.cssPosition] = this.page * 100 + '%'; + this.masterPages[ indices[2] ].style[this.cssPosition] = this.page * 100 + 100 + '%'; + + this.masterPages[ indices[0] ].dataset.upcomingPageIndex = this.page === 0 ? + (this.options.loop ? this.options.numberOfPages-1 : undefined ): this.page - 1; + this.masterPages[ indices[1] ].dataset.upcomingPageIndex = this.page; + this.masterPages[ indices[2] ].dataset.upcomingPageIndex = this.page == this.options.numberOfPages-1 ? + (this.options.loop ? 0 : undefined ): this.page + 1; + + if (!this.options.loop) { + this.masterPages[ indices[0] ].style.visibility = this.page === 0 ? "hidden" : ""; + this.masterPages[ indices[1] ].style.visibility = ""; + this.masterPages[ indices[2] ].style.visibility = this.page === this.options.numberOfPages-1 ? "hidden" : ""; + } + + this.__flip( true ); + }, + + next: function () { + if (!this.options.loop && this.k == this.maxK) return; + + this.direction = -1; + this.k -= 1; + this.__checkPosition(); + }, + + prev: function () { + if (!this.options.loop && this.k === 0) return; + + this.direction = 1; + this.k += 1; + this.__checkPosition(); + }, + + handleEvent: function (e) { + switch (e.type) { + case startEvent: + this.__start(e); + break; + case moveEvent: + this.__move(e); + break; + case "mouseout": + if (this.initiated) { + var elts = this.wrapper.getElementsByTagName('*'); + for (var i=0; i< elts.length; i++) + if( e.toElement == elts[i]) return; + this.__end(e); + } + break; + case cancelEvent: + case endEvent: + this.__end(e); + break; + case resizeEvent: + this.__resize(); + break; + case transitionEndEvent: + case 'otransitionend': + if (e.target == this.slider && !this.options.hastyPageFlip) this.__flip(); + break; + } + }, + + + /** + * + * Pseudo private methods + * + */ + __pos: function (k) { + this.k = k; + if (hasTransform) { + this.slider.style[transform] = (this.options.vertical ? 'translate(0,' + k + 'px)' : 'translate(' + k + 'px,0)') + translateZ; + } + else { + if (this.options.vertical) { + this.slider.style.top = k+"px"; + } + else { + this.slider.style.left = k+"px"; + } + } + }, + + __resize: function () { + this.refreshSize(); + this.slider.style[transitionDuration] = '0s'; + this.__pos(-this.page * this.pageSize); + }, + + __start: function (e) { + //e.preventDefault(); + + if (this.initiated) return; + + var point = hasTouch ? e.targetTouches[0] : e; + + this.initiated = true; + this.identifier = point.identifier; + this.moved = false; + this.thresholdExceeded = false; + this.startX = getPageX(point); + this.startY = getPageY(point); + this.pointX = getPageX(point); + this.pointY = getPageY(point); + this.stepsX = 0; + this.stepsY = 0; + this.direction = 0; + this.directionLocked = false; + + this.slider.style[transitionDuration] = '0s'; + + this.E.trigger('touchstart'); + }, + + __move: function (e) { + if (!this.initiated) return; + var i, l, point; + + if (hasTouch) { + i = 0; + l = e.changedTouches.length; + for(;i= this.pageSize) { return; } + + this.moved = true; + this.pointX = getPageX(point); + this.pointY = getPageY(point); + this.direction = this.options.vertical ? (deltaY > 0 ? 1 : deltaY < 0 ? -1 : 0): (deltaX > 0 ? 1 : deltaX < 0 ? -1 : 0); + this.stepsX += Math.abs(deltaX); + this.stepsY += Math.abs(deltaY); + + // We take a 10px buffer to figure out the direction of the swipe + if (this.stepsX < 10 && this.stepsY < 10) { +// e.preventDefault(); + return; + } + + // We are scrolling vertically, so skip SwipeView and give the control back to the browser + if (!this.directionLocked && (this.options.vertical ? this.stepsX > this.stepsY : this.stepsY > this.stepsX)) { + this.initiated = false; + return; + } + + preventDefault(e); + + this.directionLocked = true; + + if (!this.options.loop && (newC > 0 || newC < this.maxC)) { + newC = this.k + ((this.options.vertical ?deltaY : deltaX) / 2); + } + + if (!this.thresholdExceeded && dist >= this.snapThreshold) { + this.thresholdExceeded = true; + this.E.trigger('moveout'); + } else if (this.thresholdExceeded && dist < this.snapThreshold) { + this.thresholdExceeded = false; + this.E.trigger('movein'); + } + + this.__pos(newC); + }, + + __end: function (e) { + if (!this.initiated) return; + + var point; + + if(hasTouch) { + var i=0, l = e.touches.length; + for(;i 0 || this.k < this.maxK)) { + dist = 0; + this.E.trigger('movein'); + } + + // Check if we exceeded the snap threshold + if (dist < this.snapThreshold) { + this.slider.style[transitionDuration] = Math.floor(300 * dist / this.snapThreshold) + 'ms'; + this.__pos(-this.page * this.pageSize); + return; + } + + this.__checkPosition(); + }, + + abort: function () { + if (!this.initiated) return; + this.__pos(-this.page * this.pageSize); + this.initiated = false; + }, + + __checkPosition: function () { + var pageFlip, + pageFlipIndex, + className; + + this.masterPages[this.currentMasterPage].className = this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/, ''); + + // Flip the page + if (this.direction > 0) { + this.page = -Math.ceil(this.k / this.pageSize); + this.currentMasterPage = (this.page + 1) - Math.floor((this.page + 1) / 3) * 3; + this.pageIndex = this.pageIndex === 0 ? this.options.numberOfPages - 1 : this.pageIndex - 1; + + pageFlip = this.currentMasterPage - 1; + pageFlip = pageFlip < 0 ? 2 : pageFlip; + this.masterPages[pageFlip].style[this.cssPosition] = this.page * 100 - 100 + '%'; + + pageFlipIndex = this.page - 1; + pageFlipIndex = pageFlipIndex - Math.floor(pageFlipIndex / this.options.numberOfPages) * this.options.numberOfPages; + pageFlipIndex = pageFlipIndex === this.options.numberOfPages && !this.options.loop ? undefined : pageFlipIndex; + } else { + this.page = -Math.floor(this.k / this.pageSize); + this.currentMasterPage = (this.page + 1) - Math.floor((this.page + 1) / 3) * 3; + this.pageIndex = this.pageIndex == this.options.numberOfPages - 1 ? 0 : this.pageIndex + 1; + + pageFlip = this.currentMasterPage + 1; + pageFlip = pageFlip > 2 ? 0 : pageFlip; + this.masterPages[pageFlip].style[this.cssPosition] = this.page * 100 + 100 + '%'; + + pageFlipIndex = this.page + 1; + pageFlipIndex = pageFlipIndex - Math.floor(pageFlipIndex / this.options.numberOfPages) * this.options.numberOfPages; + pageFlipIndex = pageFlipIndex === 0 && !this.options.loop ? undefined : pageFlipIndex; + } + + // Add active class to current page + className = this.masterPages[this.currentMasterPage].className; + if(!/(^|\s)swipeview-active(\s|$)/.test(className)) + this.masterPages[this.currentMasterPage].className = !className ? 'swipeview-active' : className + ' swipeview-active'; + + // Add loading class to flipped page + className = this.masterPages[pageFlip].className; + if(!/(^|\s)swipeview-loading(\s|$)/.test(className)) + this.masterPages[pageFlip].className = !className ? 'swipeview-loading' : className + ' swipeview-loading'; + + this.masterPages[pageFlip].dataset.upcomingPageIndex = pageFlipIndex; // Index to be loaded in the newly flipped page + + newC = -this.page * this.pageSize; + + this.slider.style[transitionDuration] = Math.floor(500 * Math.abs(this.k - newC) / this.pageSize) + 'ms'; + + // Hide the next page if we decided to disable looping + if (!this.options.loop) { + this.masterPages[pageFlip].style.visibility = newC === 0 || newC == this.maxK ? 'hidden' : ''; + } + + if (this.k == newC) { + this.__flip(); // If we swiped all the way long to the next page (extremely rare but still) + } else { + this.__pos(newC); + if (this.options.hastyPageFlip) this.__flip(); + } + }, + + __flip: function ( fromGoTo ) { + this.E.trigger('flip', { triggeredByGoto : !!fromGoTo }); + + for (var i=0; i<3; i++) { + this.masterPages[i].className = this.masterPages[i].className.replace(/(^|\s)swipeview-loading(\s|$)/, ''); // Remove the loading class + this.masterPages[i].dataset.pageIndex = this.masterPages[i].dataset.upcomingPageIndex; + } + } + }; + + function prefixStyle (style) { + if ( vendor === '' ) return style; + + style = style.charAt(0).toUpperCase() + style.substr(1); + return vendor + style; + } + + return SwipeView; +})(window, document);