Skip to content

Instantly share code, notes, and snippets.

@jonathanheilmann
Created June 23, 2018 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanheilmann/3e6e21559a0850450a366a67546a33c4 to your computer and use it in GitHub Desktop.
Save jonathanheilmann/3e6e21559a0850450a366a67546a33c4 to your computer and use it in GitHub Desktop.
EXT:jh_magnificpopup jquery.filter-isImageFile.js supporting EXT:jumpurl
/*! jQuery :isImageFile filter - v0.0.5 - 2014-08-21
*
* Copyright (c) 2013-2018 Jonathan Heilmann;
*
* CHANGELOG
* 0.0.6: -ignore images and links with class "excludeFromMagnificpopup"
* 0.0.5: -ignore images with class "excludeFromMagnificpopup"
* 0.0.4: -fixed bug #59696 (filter-isImageFile doesn't work with UpperCase Filetype)
* 0.0.3: -removed jQuery.noConflict() and added IIFE
* -added support for zepto
* 0.0.2: -added jpeg to filter
* 0.0.1: -initial release
*
*/
;(function($) {
$.extend($.expr[':'], {
isImageFile: function(obj){
var $this = $(obj);
if ($this.hasClass('excludeFromMagnificpopup')) {return false;} // Ignore images and links with class "excludeFromMagnificpopup"
var file = $this.attr('href');
if (file == null) {return false;} // Return false if the path is empty
file = file.toLowerCase(); // Convert to lower case
var extension = file.substr((file.lastIndexOf('.')+1)); // Get extension of file
extension = extension.substr(0, (extension.lastIndexOf('&')));
switch (extension) {
case 'jpeg':
case 'jpg':
case 'png':
case 'gif':
// Got an image - return true
return true;
break;
default:
// No image found - return false
return false;
}
}
});
})(window.jQuery || window.Zepto);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment