summaryrefslogtreecommitdiffstats
path: root/module/web/static/js/utils
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-09-18 17:59:50 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-09-18 17:59:50 +0200
commit6130a2377ca6754fee88773097ce220abef1aa47 (patch)
tree76bea0d76393100fcf393c164c96d34f286aba7a /module/web/static/js/utils
parentAdded DuckcryptInfo decrypter, smaller fixes (diff)
parentdropdowns in navbar (diff)
downloadpyload-6130a2377ca6754fee88773097ce220abef1aa47.tar.xz
merged stable into default
Diffstat (limited to 'module/web/static/js/utils')
-rw-r--r--module/web/static/js/utils/animations.js36
-rw-r--r--module/web/static/js/utils/lazyRequire.js89
2 files changed, 125 insertions, 0 deletions
diff --git a/module/web/static/js/utils/animations.js b/module/web/static/js/utils/animations.js
new file mode 100644
index 000000000..9b1448f61
--- /dev/null
+++ b/module/web/static/js/utils/animations.js
@@ -0,0 +1,36 @@
+define(['jquery', 'underscore', 'transit'], function(jQuery, _) {
+
+ // Overwrite common animations with transitions
+ jQuery.each({
+ fadeIn: { opacity: "show" },
+ fadeOut: { opacity: "hide" }
+ }, function(name, props) {
+ jQuery.fn[ name ] = function(speed, easing, callback) {
+ return this.transition(props, speed, easing, callback);
+ };
+ });
+
+ jQuery.fn._transit = jQuery.fn.transit;
+
+ // Over riding transit plugin to support hide and show
+ // Props retains it properties across multiple calls, therefore props.show value is introduced
+ jQuery.fn.transit = jQuery.fn.transition = function(props, duration, easing, callback) {
+ var self = this;
+ var cb = callback;
+ if (props && (props.opacity === 'hide' || (props.opacity === 0 && props.show === true))) {
+ props.opacity = 0;
+ props.show = true;
+
+ callback = function() {
+ self.css({display: 'none'});
+ if (typeof cb === 'function') { cb.apply(self); }
+ };
+ } else if (props && (props.opacity === 'show' || (props.opacity === 1 && props.show === true))) {
+ props.opacity = 1;
+ props.show = true;
+ this.css({display: 'block'});
+ }
+
+ return this._transit(props, duration, easing, callback);
+ };
+}); \ No newline at end of file
diff --git a/module/web/static/js/utils/lazyRequire.js b/module/web/static/js/utils/lazyRequire.js
new file mode 100644
index 000000000..d20d78610
--- /dev/null
+++ b/module/web/static/js/utils/lazyRequire.js
@@ -0,0 +1,89 @@
+// Define the module.
+define(
+ [
+ "require"
+ ],
+ function( require ){
+
+
+ // Define the states of loading for a given set of modules
+ // within a require() statement.
+ var states = {
+ unloaded: "UNLOADED",
+ loading: "LOADING",
+ loaded: "LOADED"
+ };
+
+
+ // Define the top-level module container. Mostly, we're making
+ // the top-level container a non-Function so that users won't
+ // try to invoke this without calling the once() method below.
+ var lazyRequire = {};
+
+
+ // I will return a new, unique instance of the requrieOnce()
+ // method. Each instance will only call the require() method
+ // once internally.
+ lazyRequire.once = function(){
+
+ // The modules start in an unloaded state before
+ // requireOnce() is invoked by the calling code.
+ var state = states.unloaded;
+ var args;
+
+ var requireOnce = function( dependencies, loadCallback ){
+
+ // Use the module state to determine which method to
+ // invoke (or just to ignore the invocation).
+ if (state === states.loaded){
+ loadCallback.apply(null, args);
+
+ // The modules have not yet been requested - let's
+ // lazy load them.
+ } else if (state !== states.loading){
+
+ // We're about to load the modules asynchronously;
+ // flag the interim state.
+ state = states.loading;
+
+ // Load the modules.
+ require(
+ dependencies,
+ function(){
+
+ args = arguments;
+ loadCallback.apply( null, args );
+ state = states.loaded;
+
+
+ }
+ );
+
+ // RequireJS is currently loading the modules
+ // asynchronously, but they have not finished
+ // loading yet.
+ } else {
+
+ // Simply ignore this call.
+ return;
+
+ }
+
+ };
+
+ // Return the new lazy loader.
+ return( requireOnce );
+
+ };
+
+
+ // -------------------------------------------------- //
+ // -------------------------------------------------- //
+
+
+ // Return the module definition.
+ return( lazyRequire );
+
+
+ }
+); \ No newline at end of file