Created
October 15, 2015 09:43
-
-
Save alepez/60fe0276d832370b3192 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$.fn.dt_smartPreloader = function (action) { | |
var args = arguments; | |
return this.each(function (index, self) { | |
var $self = $(self); | |
var visibility = $self.css('visibility'); | |
/* wrap $self with a preloader div */ | |
$self.wrap($('<div>').addClass('preloader-mask ajaxLoading')); | |
var $preloader = $self.parent(); | |
var actions = { | |
start: function () { | |
/* hide the loading element */ | |
$self.css('visibility', 'hidden'); | |
}, | |
stop: function () { | |
/* restore initial visibility */ | |
$self.css('visibility', visibility); | |
/* unwrap the element */ | |
$preloader.replaceWith($self); | |
}, | |
load: function (url, callback) { | |
actions.start(); | |
$preloader.load(url, function (data) { | |
actions.stop(); | |
if (callback) callback($preloader.children()); | |
}); | |
} | |
}; | |
actions[action].apply(this, Array.prototype.slice.call(args, 1)); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment