forked from 9elements/loadie.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dominik Schmidt
committed
Nov 13, 2013
1 parent
ade8179
commit 13188b1
Showing
2 changed files
with
30 additions
and
16 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,60 @@ | ||
/** | ||
* Loadie.js by 9elements (@sippndipp & @iDuuck) | ||
*/ | ||
(function( $ ) { | ||
function uniqueId() { | ||
var Loadie = {}; | ||
|
||
/* | ||
* Generate a unique id for more than one loadie | ||
*/ | ||
Loadie.uid = function() { | ||
var newDate = new Date; | ||
return newDate.getTime(); | ||
} | ||
}; | ||
|
||
function destroyGUI(dom) { | ||
/* | ||
* Finishes and fades the loadie out. | ||
*/ | ||
Loadie.finish = function(dom) { | ||
var loadie = $('#loadie-' + dom.data('loadie-id'), dom); | ||
loadie.fadeOut(200); | ||
} | ||
|
||
function updateGUI(dom, percent) { | ||
/* | ||
* Updates loadie with a float | ||
* | ||
* Loadie.update(0.2) | ||
* Loadie.update(1) // Finishes loadie, too | ||
*/ | ||
Loadie.update = function(dom, percent) { | ||
var loadie = $('#loadie-' + dom.data('loadie-id'), dom); | ||
var parentWidth = dom.width(); | ||
loadie.css('width', Math.floor(percent * parentWidth) + "px"); | ||
} | ||
|
||
function createGUI(dom, percent) { | ||
var uid = uniqueId(); | ||
/* | ||
* Loadie.js initializer | ||
*/ | ||
Loadie.init = function(dom, percent) { | ||
var uid = this.uid(); | ||
var loadie = dom.append($('<div id="loadie-' + uid + '" class="loadie"></div>')); | ||
dom.data('loadie-id', uid); | ||
dom.css('position', 'relative'); | ||
updateGUI(dom, percent); | ||
this.update(dom, percent); | ||
} | ||
|
||
$.fn.loadie = function(percent, callback) { | ||
var percent = percent || 0; | ||
var parent = $(this); | ||
|
||
if(parent.data('loadie-loaded') !== 1) { | ||
createGUI(parent, percent); | ||
Loadie.init(parent, percent); | ||
} else { | ||
updateGUI(parent, percent); | ||
Loadie.update(parent, percent); | ||
} | ||
if(percent >= 1) { | ||
setTimeout(function() { | ||
destroyGUI(parent); | ||
}, 700); | ||
Loadie.finish(parent); | ||
}, 200); | ||
} | ||
parent.data('loadie-loaded', 1); | ||
return this; | ||
}; | ||
}( jQuery )) | ||
}( jQuery )) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.