Skip to content

Commit 71d88f1

Browse files
committed
Removes duplicates from gallery
1 parent 80c6857 commit 71d88f1

File tree

3 files changed

+49
-44
lines changed

3 files changed

+49
-44
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: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@
9292
}
9393

9494
elements = [];
95-
var index , relType, relVal;
95+
var index, relType, relVal;
9696

9797
// Allow for HTML5 compliant attribute before legacy use of rel
9898
if ( ! relVal ) {
9999
relType = 'data-rel';
100-
relVal = $( this ).attr( relType );
100+
relVal = $( this ).attr( relType );
101101
}
102102

103103
if ( ! relVal ) {
@@ -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();
@@ -748,7 +761,7 @@
748761
if ( a.search ) {
749762
qs = JSON.parse( '{"' + a.search.toLowerCase().replace('?','').replace(/&/g,'","').replace(/=/g,'":"') + '"}' );
750763
}
751-
764+
752765
// Extend with custom data
753766
if ( $.isPlainObject( customData ) ) {
754767
qs = $.extend( qs, customData, plugin.settings.queryStringData ); // The dev has always the final word
@@ -790,7 +803,7 @@
790803
'portrait' : '0',
791804
'color': plugin.settings.vimeoColor
792805
});
793-
iframe = '<iframe width="560" height="315" src="//player.vimeo.com/video/' + vimeoUrl[1] + '?' + qs + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
806+
iframe = '<iframe width="560" height="315" src="//player.vimeo.com/video/' + vimeoUrl[1] + '?' + qs + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
794807

795808
} else {
796809
iframe = '<iframe width="560" height="315" src="' + url + '" frameborder="0" allowfullscreen></iframe>';
@@ -803,29 +816,29 @@
803816
* Load image
804817
*/
805818
loadMedia : function ( src, callback ) {
806-
// Inline content
807-
if ( src.trim().indexOf('#') === 0 ) {
808-
callback.call(
809-
$('<div>', {
810-
'class' : 'swipebox-inline-container'
811-
})
812-
.append(
813-
$(src)
814-
.clone()
815-
.toggleClass( plugin.settings.toggleClassOnLoad )
816-
)
817-
);
818-
}
819-
// Everything else
820-
else {
821-
if ( ! this.isVideo( src ) ) {
822-
var img = $( '<img>' ).on( 'load', function() {
823-
callback.call( img );
824-
} );
825-
826-
img.attr( 'src', src );
827-
}
828-
}
819+
// Inline content
820+
if ( src.trim().indexOf('#') === 0 ) {
821+
callback.call(
822+
$('<div>', {
823+
'class' : 'swipebox-inline-container'
824+
})
825+
.append(
826+
$(src)
827+
.clone()
828+
.toggleClass( plugin.settings.toggleClassOnLoad )
829+
)
830+
);
831+
}
832+
// Everything else
833+
else {
834+
if ( ! this.isVideo( src ) ) {
835+
var img = $( '<img>' ).on( 'load', function() {
836+
callback.call( img );
837+
} );
838+
839+
img.attr( 'src', src );
840+
}
841+
}
829842
},
830843

831844
/**
@@ -947,4 +960,4 @@
947960

948961
};
949962

950-
}( window, document, jQuery ) );
963+
}( window, document, jQuery ) );

0 commit comments

Comments
 (0)