Created
April 30, 2014 12:53
-
-
Save AstakhovArtem/10373fa0ecc3e1f07725 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function($) { | |
/** | |
* Show preloader under element | |
* | |
* @param {string} height of preloader block | |
* @param {string} width of preloader block | |
* @return {void} | |
*/ | |
$.fn.showPreloader = function(width, height) { | |
width = width || '100%'; | |
height = height || '100%'; | |
return this.each(function() { | |
var blockEl = $(this); | |
if (blockEl.css('position') == 'static') { | |
blockEl.css('position', 'relative'); | |
} | |
if (blockEl.css('display') != 'inline' || | |
blockEl.css('display') != 'inline-block' | |
) { | |
blockEl.attr('display_old', blockEl.css('display')); | |
blockEl.css('display', 'block'); | |
} | |
blockEl.prepend( | |
$('<div>', { | |
'class': 'preloaders', | |
height: height, | |
width: width | |
}) | |
); | |
}); | |
}; | |
/** | |
* Remove preloader | |
* | |
* @return {void} | |
*/ | |
$.fn.removePreloader = function() { | |
return this.each(function() { | |
var blockEl = $(this); | |
var preloaders = blockEl.children('.preloaders'); | |
if (blockEl.attr('display_old')) { | |
blockEl.css('display', blockEl.attr('display_old')); | |
blockEl.removeAttr('display_old'); | |
} | |
preloaders.remove(); | |
}); | |
}; | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment