Skip to content

Commit

Permalink
Removes duplicates from gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
firedev committed Nov 22, 2015
1 parent 80c6857 commit 4dde9d4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 44 deletions.
8 changes: 0 additions & 8 deletions src/css/swipebox.css
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,9 @@ html.swipebox-html.swipebox-touch {
0% {
left: 0;
}

50% {
left: -30px;
}

100% {
left: 0;
}
Expand All @@ -229,11 +227,9 @@ html.swipebox-html.swipebox-touch {
0% {
left: 0;
}

50% {
left: -30px;
}

100% {
left: 0;
}
Expand All @@ -242,11 +238,9 @@ html.swipebox-html.swipebox-touch {
0% {
left: 0;
}

50% {
left: 30px;
}

100% {
left: 0;
}
Expand All @@ -255,11 +249,9 @@ html.swipebox-html.swipebox-touch {
0% {
left: 0;
}

50% {
left: 30px;
}

100% {
left: 0;
}
Expand Down
83 changes: 48 additions & 35 deletions src/js/jquery.swipebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@
}

elements = [];
var index , relType, relVal;
var index, relType, relVal;

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

if ( ! relVal ) {
Expand All @@ -111,6 +111,16 @@
$elem = $( selector );
}

var include = function(haystack, needle) {
for (var i = 0; i < haystack.length; i++) {
if(haystack[i] === needle) { return(true); }
}
return(false);
},
hrefs = [],
i = 0,
currentHref = $(this).attr('href');

$elem.each( function() {

var title = null,
Expand All @@ -120,18 +130,22 @@
title = $( this ).attr( 'title' );
}


if ( $( this ).attr( 'href' ) ) {
href = $( this ).attr( 'href' );
}

elements.push( {
href: href,
title: title
} );
if(include(hrefs, href)) {
} else {
if(currentHref === href) { index = i; }
hrefs.push(href);
elements.push( {
href: href,
title: title
} );
i++;
}
} );

index = $elem.index( $( this ) );
event.preventDefault();
event.stopPropagation();
ui.target = $( event.target );
Expand Down Expand Up @@ -220,7 +234,6 @@
}
}, false );


} else {

width = window.innerWidth ? window.innerWidth : $( window ).width();
Expand Down Expand Up @@ -748,7 +761,7 @@
if ( a.search ) {
qs = JSON.parse( '{"' + a.search.toLowerCase().replace('?','').replace(/&/g,'","').replace(/=/g,'":"') + '"}' );
}

// Extend with custom data
if ( $.isPlainObject( customData ) ) {
qs = $.extend( qs, customData, plugin.settings.queryStringData ); // The dev has always the final word
Expand Down Expand Up @@ -790,7 +803,7 @@
'portrait' : '0',
'color': plugin.settings.vimeoColor
});
iframe = '<iframe width="560" height="315" src="//player.vimeo.com/video/' + vimeoUrl[1] + '?' + qs + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
iframe = '<iframe width="560" height="315" src="//player.vimeo.com/video/' + vimeoUrl[1] + '?' + qs + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';

} else {
iframe = '<iframe width="560" height="315" src="' + url + '" frameborder="0" allowfullscreen></iframe>';
Expand All @@ -803,29 +816,29 @@
* Load image
*/
loadMedia : function ( src, callback ) {
// Inline content
if ( src.trim().indexOf('#') === 0 ) {
callback.call(
$('<div>', {
'class' : 'swipebox-inline-container'
})
.append(
$(src)
.clone()
.toggleClass( plugin.settings.toggleClassOnLoad )
)
);
}
// Everything else
else {
if ( ! this.isVideo( src ) ) {
var img = $( '<img>' ).on( 'load', function() {
callback.call( img );
} );

img.attr( 'src', src );
}
}
// Inline content
if ( src.trim().indexOf('#') === 0 ) {
callback.call(
$('<div>', {
'class' : 'swipebox-inline-container'
})
.append(
$(src)
.clone()
.toggleClass( plugin.settings.toggleClassOnLoad )
)
);
}
// Everything else
else {
if ( ! this.isVideo( src ) ) {
var img = $( '<img>' ).on( 'load', function() {
callback.call( img );
} );

img.attr( 'src', src );
}
}
},

/**
Expand Down Expand Up @@ -947,4 +960,4 @@

};

}( window, document, jQuery ) );
}( window, document, jQuery ) );
Loading

0 comments on commit 4dde9d4

Please sign in to comment.