Skip to content

Commit

Permalink
Allow instantiation of swiper on every jQuery / Zepto object (it was …
Browse files Browse the repository at this point in the history
…only the first element of the collection).

Instance can be used with method .data('swiper') on the jQuery / Zepto object.
  • Loading branch information
OxyDesign committed Aug 8, 2014
1 parent 3ca8149 commit beb3bac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions demos/19-chaining.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@
<script src="js/jquery-1.10.1.min.js"></script>
<script src="../src/idangerous.swiper.js"></script>
<script>
$('.swiper-container').swiper({
var mySwiper = $('.swiper-container').swiper({
pagination: '.pagination',
loop:true,
grabCursor: true,
paginationClickable: true
}).addClass('test-chaining');
});
$('.arrow-left').on('click', function(e){
e.preventDefault()
var swiper = $(this).siblings('.swiper-container').data('swiper');
Expand Down
5 changes: 4 additions & 1 deletion src/idangerous.swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2809,13 +2809,16 @@ if (window.jQuery || window.Zepto) {
(function ($) {
'use strict';
$.fn.swiper = function (params) {
return this.each(function() {
var firstInstance;
this.each(function(i) {
var that = $(this);
if (!that.data('swiper')) {
var s = new Swiper(that[0], params);
if (!i) firstInstance = s;
that.data('swiper', s);
}
});
return firstInstance;
};
})(window.jQuery || window.Zepto);
}
Expand Down

0 comments on commit beb3bac

Please sign in to comment.