From 3ca814943d14951d8287b01b7859fb234bfd234a Mon Sep 17 00:00:00 2001 From: Escoffier Nicolas Date: Wed, 30 Jul 2014 01:33:26 +0200 Subject: [PATCH 1/2] Allow instantiation of swiper on every jQuery / Zepto object (it was only the first element of the collection) and allow to chain methods because it returns the object (the return was the instance). Instance can be used with method .data('swiper') on the jQuery / Zepto object. --- demos/19-chaining.html | 134 +++++++++++++++++++++++++++++++++++++++ src/idangerous.swiper.js | 16 +++-- 2 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 demos/19-chaining.html diff --git a/demos/19-chaining.html b/demos/19-chaining.html new file mode 100644 index 000000000..b2af3483e --- /dev/null +++ b/demos/19-chaining.html @@ -0,0 +1,134 @@ + + + + + Demo + + + + +
+ + +
+
+
+
+
+
+

Slide with HTML

+

You can put any HTML inside of slide with any layout, not only images, even another Swiper!

+
+
+
+
+ +
+
+ + +
+
+
+
+
+
+

Slide with HTML

+

You can put any HTML inside of slide with any layout, not only images, even another Swiper!

+
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/src/idangerous.swiper.js b/src/idangerous.swiper.js index dea91eb0d..7307932a2 100755 --- a/src/idangerous.swiper.js +++ b/src/idangerous.swiper.js @@ -568,7 +568,7 @@ var Swiper = function (selector, params) { var _width = _this.h.getWidth(_this.container, false, params.roundLengths); var _height = _this.h.getHeight(_this.container, false, params.roundLengths); if (_width === _this.width && _height === _this.height && !force) return; - + _this.width = _width; _this.height = _height; @@ -675,7 +675,7 @@ var Swiper = function (selector, params) { _this.snapGrid.push(slideLeft); } } - + } else { _this.snapGrid.push(slideLeft); @@ -1910,7 +1910,7 @@ var Swiper = function (selector, params) { else { _this.fireCallback(params.onSlideChangeEnd, _this, direction); } - + } _this.setWrapperTranslate(newPosition); _this._DOMAnimating = false; @@ -2809,9 +2809,13 @@ if (window.jQuery || window.Zepto) { (function ($) { 'use strict'; $.fn.swiper = function (params) { - var s = new Swiper($(this)[0], params); - $(this).data('swiper', s); - return s; + return this.each(function() { + var that = $(this); + if (!that.data('swiper')) { + var s = new Swiper(that[0], params); + that.data('swiper', s); + } + }); }; })(window.jQuery || window.Zepto); } From beb3bac276e58fb5e732cf2b944d9b23ad650b6a Mon Sep 17 00:00:00 2001 From: Escoffier Nicolas Date: Fri, 8 Aug 2014 22:49:22 +0200 Subject: [PATCH 2/2] Allow instantiation of swiper on every jQuery / Zepto object (it was only the first element of the collection). Instance can be used with method .data('swiper') on the jQuery / Zepto object. --- demos/19-chaining.html | 4 ++-- src/idangerous.swiper.js | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/demos/19-chaining.html b/demos/19-chaining.html index b2af3483e..104a42855 100644 --- a/demos/19-chaining.html +++ b/demos/19-chaining.html @@ -113,12 +113,12 @@