Skip to content

Commit 1b9344d

Browse files
committed
Removes duplicates from gallery
1 parent c622743 commit 1b9344d

File tree

3 files changed

+46
-41
lines changed

3 files changed

+46
-41
lines changed

src/css/swipebox.css

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,9 @@ html.swipebox-html.swipebox-touch {
215215
0% {
216216
left: 0;
217217
}
218-
219218
50% {
220219
left: -30px;
221220
}
222-
223221
100% {
224222
left: 0;
225223
}
@@ -229,11 +227,9 @@ html.swipebox-html.swipebox-touch {
229227
0% {
230228
left: 0;
231229
}
232-
233230
50% {
234231
left: -30px;
235232
}
236-
237233
100% {
238234
left: 0;
239235
}
@@ -242,11 +238,9 @@ html.swipebox-html.swipebox-touch {
242238
0% {
243239
left: 0;
244240
}
245-
246241
50% {
247242
left: 30px;
248243
}
249-
250244
100% {
251245
left: 0;
252246
}
@@ -255,11 +249,9 @@ html.swipebox-html.swipebox-touch {
255249
0% {
256250
left: 0;
257251
}
258-
259252
50% {
260253
left: 30px;
261254
}
262-
263255
100% {
264256
left: 0;
265257
}

src/js/jquery.swipebox.js

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@
111111
$elem = $( selector );
112112
}
113113

114+
var include = function(haystack, needle) {
115+
for (var i = 0; i < haystack.length; i++) {
116+
if(haystack[i] === needle) { return(true); }
117+
}
118+
return(false);
119+
},
120+
hrefs = [],
121+
i = 0,
122+
currentHref = $(this).attr('href');
123+
114124
$elem.each( function() {
115125

116126
var title = null,
@@ -120,18 +130,22 @@
120130
title = $( this ).attr( 'title' );
121131
}
122132

123-
124133
if ( $( this ).attr( 'href' ) ) {
125134
href = $( this ).attr( 'href' );
126135
}
127136

128-
elements.push( {
129-
href: href,
130-
title: title
131-
} );
137+
if(include(hrefs, href)) {
138+
} else {
139+
if(currentHref === href) { index = i; }
140+
hrefs.push(href);
141+
elements.push( {
142+
href: href,
143+
title: title
144+
} );
145+
i++;
146+
}
132147
} );
133148

134-
index = $elem.index( $( this ) );
135149
event.preventDefault();
136150
event.stopPropagation();
137151
ui.target = $( event.target );
@@ -220,7 +234,6 @@
220234
}
221235
}, false );
222236

223-
224237
} else {
225238

226239
width = window.innerWidth ? window.innerWidth : $( window ).width();
@@ -756,7 +769,7 @@
756769
if ( a.search ) {
757770
qs = JSON.parse( '{"' + a.search.toLowerCase().replace('?','').replace(/&/g,'","').replace(/=/g,'":"') + '"}' );
758771
}
759-
772+
760773
// Extend with custom data
761774
if ( $.isPlainObject( customData ) ) {
762775
qs = $.extend( qs, customData, plugin.settings.queryStringData ); // The dev has always the final word
@@ -798,7 +811,7 @@
798811
'portrait' : '0',
799812
'color': plugin.settings.vimeoColor
800813
});
801-
iframe = '<iframe width="560" height="315" src="//player.vimeo.com/video/' + vimeoUrl[1] + '?' + qs + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
814+
iframe = '<iframe width="560" height="315" src="//player.vimeo.com/video/' + vimeoUrl[1] + '?' + qs + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
802815

803816
} else {
804817
iframe = '<iframe width="560" height="315" src="' + url + '" frameborder="0" allowfullscreen></iframe>';
@@ -811,29 +824,29 @@
811824
* Load image
812825
*/
813826
loadMedia : function ( src, callback ) {
814-
// Inline content
815-
if ( src.trim().indexOf('#') === 0 ) {
816-
callback.call(
817-
$('<div>', {
818-
'class' : 'swipebox-inline-container'
819-
})
820-
.append(
821-
$(src)
822-
.clone()
823-
.toggleClass( plugin.settings.toggleClassOnLoad )
824-
)
825-
);
826-
}
827-
// Everything else
828-
else {
829-
if ( ! this.isVideo( src ) ) {
830-
var img = $( '<img>' ).on( 'load', function() {
831-
callback.call( img );
832-
} );
833-
834-
img.attr( 'src', src );
835-
}
836-
}
827+
// Inline content
828+
if ( src.trim().indexOf('#') === 0 ) {
829+
callback.call(
830+
$('<div>', {
831+
'class' : 'swipebox-inline-container'
832+
})
833+
.append(
834+
$(src)
835+
.clone()
836+
.toggleClass( plugin.settings.toggleClassOnLoad )
837+
)
838+
);
839+
}
840+
// Everything else
841+
else {
842+
if ( ! this.isVideo( src ) ) {
843+
var img = $( '<img>' ).on( 'load', function() {
844+
callback.call( img );
845+
} );
846+
847+
img.attr( 'src', src );
848+
}
849+
}
837850
},
838851

839852
/**

0 commit comments

Comments
 (0)