Client build: modularize loading indicator from ui.js

This commit is contained in:
Carl Eberhard
2014-12-09 12:37:36 -05:00
parent 5fec4a727c
commit 76b523196a
9 changed files with 203 additions and 178 deletions
@@ -0,0 +1,98 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else {
// Browser globals
root.LoadingIndicator = factory();
}
//============================================================================
}(this, function () {
//TODO: too specific to history panel
function LoadingIndicator( $where, options ){
var self = this;
// defaults
options = jQuery.extend({
cover : false
}, options || {} );
function render(){
var html = [
'<div class="loading-indicator">',
'<div class="loading-indicator-text">',
'<span class="fa fa-spinner fa-spin fa-lg"></span>',
'<span class="loading-indicator-message">loading...</span>',
'</div>',
'</div>'
].join( '\n' );
var $indicator = $( html ).hide().css( options.css || {
position : 'fixed'
}),
$text = $indicator.children( '.loading-indicator-text' );
if( options.cover ){
$indicator.css({
'z-index' : 2,
top : $where.css( 'top' ),
bottom : $where.css( 'bottom' ),
left : $where.css( 'left' ),
right : $where.css( 'right' ),
opacity : 0.5,
'background-color': 'white',
'text-align': 'center'
});
$text = $indicator.children( '.loading-indicator-text' ).css({
'margin-top' : '20px'
});
} else {
$text = $indicator.children( '.loading-indicator-text' ).css({
margin : '12px 0px 0px 10px',
opacity : '0.85',
color : 'grey'
});
$text.children( '.loading-indicator-message' ).css({
margin : '0px 8px 0px 0px',
'font-style' : 'italic'
});
}
return $indicator;
}
self.show = function( msg, speed, callback ){
msg = msg || 'loading...';
speed = speed || 'fast';
// remove previous
$where.parent().find( '.loading-indicator' ).remove();
// since position is fixed - we insert as sibling
self.$indicator = render().insertBefore( $where );
self.message( msg );
self.$indicator.fadeIn( speed, callback );
return self;
};
self.message = function( msg ){
self.$indicator.find( 'i' ).text( msg );
};
self.hide = function( speed, callback ){
speed = speed || 'fast';
if( self.$indicator && self.$indicator.size() ){
self.$indicator.fadeOut( speed, function(){
self.$indicator.remove();
if( callback ){ callback(); }
});
} else {
if( callback ){ callback(); }
}
return self;
};
return self;
}
//============================================================================
return LoadingIndicator;
}));
+2 -1
View File
@@ -1,9 +1,10 @@
define([
"mvc/list/list-item",
"jq-plugins/ui/loading-indicator",
"mvc/base-mvc",
"utils/localization",
"jq-plugins/ui/search-input"
], function( LIST_ITEM, BASE_MVC, _l ){
], function( LIST_ITEM, LoadingIndicator, BASE_MVC, _l ){
/* ============================================================================
TODO:
-87
View File
@@ -514,90 +514,3 @@ var faIconButton = function( options ){
}
return $button;
};
//==============================================================================
function LoadingIndicator( $where, options ){
//TODO: move out of global
//TODO: too specific to history panel
var self = this;
// defaults
options = jQuery.extend({
cover : false
}, options || {} );
function render(){
var html = [
'<div class="loading-indicator">',
'<div class="loading-indicator-text">',
'<span class="fa fa-spinner fa-spin fa-lg"></span>',
'<span class="loading-indicator-message">loading...</span>',
'</div>',
'</div>'
].join( '\n' );
var $indicator = $( html ).hide().css( options.css || {
position : 'fixed'
}),
$text = $indicator.children( '.loading-indicator-text' );
if( options.cover ){
$indicator.css({
'z-index' : 2,
top : $where.css( 'top' ),
bottom : $where.css( 'bottom' ),
left : $where.css( 'left' ),
right : $where.css( 'right' ),
opacity : 0.5,
'background-color': 'white',
'text-align': 'center'
});
$text = $indicator.children( '.loading-indicator-text' ).css({
'margin-top' : '20px'
});
} else {
$text = $indicator.children( '.loading-indicator-text' ).css({
margin : '12px 0px 0px 10px',
opacity : '0.85',
color : 'grey'
});
$text.children( '.loading-indicator-message' ).css({
margin : '0px 8px 0px 0px',
'font-style' : 'italic'
});
}
return $indicator;
}
self.show = function( msg, speed, callback ){
msg = msg || 'loading...';
speed = speed || 'fast';
// remove previous
$where.parent().find( '.loading-indicator' ).remove();
// since position is fixed - we insert as sibling
self.$indicator = render().insertBefore( $where );
self.message( msg );
self.$indicator.fadeIn( speed, callback );
return self;
};
self.message = function( msg ){
self.$indicator.find( 'i' ).text( msg );
};
self.hide = function( speed, callback ){
speed = speed || 'fast';
if( self.$indicator && self.$indicator.size() ){
self.$indicator.fadeOut( speed, function(){
self.$indicator.remove();
if( callback ){ callback(); }
});
} else {
if( callback ){ callback(); }
}
return self;
};
return self;
}
@@ -0,0 +1,98 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else {
// Browser globals
root.LoadingIndicator = factory();
}
//============================================================================
}(this, function () {
//TODO: too specific to history panel
function LoadingIndicator( $where, options ){
var self = this;
// defaults
options = jQuery.extend({
cover : false
}, options || {} );
function render(){
var html = [
'<div class="loading-indicator">',
'<div class="loading-indicator-text">',
'<span class="fa fa-spinner fa-spin fa-lg"></span>',
'<span class="loading-indicator-message">loading...</span>',
'</div>',
'</div>'
].join( '\n' );
var $indicator = $( html ).hide().css( options.css || {
position : 'fixed'
}),
$text = $indicator.children( '.loading-indicator-text' );
if( options.cover ){
$indicator.css({
'z-index' : 2,
top : $where.css( 'top' ),
bottom : $where.css( 'bottom' ),
left : $where.css( 'left' ),
right : $where.css( 'right' ),
opacity : 0.5,
'background-color': 'white',
'text-align': 'center'
});
$text = $indicator.children( '.loading-indicator-text' ).css({
'margin-top' : '20px'
});
} else {
$text = $indicator.children( '.loading-indicator-text' ).css({
margin : '12px 0px 0px 10px',
opacity : '0.85',
color : 'grey'
});
$text.children( '.loading-indicator-message' ).css({
margin : '0px 8px 0px 0px',
'font-style' : 'italic'
});
}
return $indicator;
}
self.show = function( msg, speed, callback ){
msg = msg || 'loading...';
speed = speed || 'fast';
// remove previous
$where.parent().find( '.loading-indicator' ).remove();
// since position is fixed - we insert as sibling
self.$indicator = render().insertBefore( $where );
self.message( msg );
self.$indicator.fadeIn( speed, callback );
return self;
};
self.message = function( msg ){
self.$indicator.find( 'i' ).text( msg );
};
self.hide = function( speed, callback ){
speed = speed || 'fast';
if( self.$indicator && self.$indicator.size() ){
self.$indicator.fadeOut( speed, function(){
self.$indicator.remove();
if( callback ){ callback(); }
});
} else {
if( callback ){ callback(); }
}
return self;
};
return self;
}
//============================================================================
return LoadingIndicator;
}));
+2 -1
View File
@@ -1,9 +1,10 @@
define([
"mvc/list/list-item",
"jq-plugins/ui/loading-indicator",
"mvc/base-mvc",
"utils/localization",
"jq-plugins/ui/search-input"
], function( LIST_ITEM, BASE_MVC, _l ){
], function( LIST_ITEM, LoadingIndicator, BASE_MVC, _l ){
/* ============================================================================
TODO:
-87
View File
@@ -514,90 +514,3 @@ var faIconButton = function( options ){
}
return $button;
};
//==============================================================================
function LoadingIndicator( $where, options ){
//TODO: move out of global
//TODO: too specific to history panel
var self = this;
// defaults
options = jQuery.extend({
cover : false
}, options || {} );
function render(){
var html = [
'<div class="loading-indicator">',
'<div class="loading-indicator-text">',
'<span class="fa fa-spinner fa-spin fa-lg"></span>',
'<span class="loading-indicator-message">loading...</span>',
'</div>',
'</div>'
].join( '\n' );
var $indicator = $( html ).hide().css( options.css || {
position : 'fixed'
}),
$text = $indicator.children( '.loading-indicator-text' );
if( options.cover ){
$indicator.css({
'z-index' : 2,
top : $where.css( 'top' ),
bottom : $where.css( 'bottom' ),
left : $where.css( 'left' ),
right : $where.css( 'right' ),
opacity : 0.5,
'background-color': 'white',
'text-align': 'center'
});
$text = $indicator.children( '.loading-indicator-text' ).css({
'margin-top' : '20px'
});
} else {
$text = $indicator.children( '.loading-indicator-text' ).css({
margin : '12px 0px 0px 10px',
opacity : '0.85',
color : 'grey'
});
$text.children( '.loading-indicator-message' ).css({
margin : '0px 8px 0px 0px',
'font-style' : 'italic'
});
}
return $indicator;
}
self.show = function( msg, speed, callback ){
msg = msg || 'loading...';
speed = speed || 'fast';
// remove previous
$where.parent().find( '.loading-indicator' ).remove();
// since position is fixed - we insert as sibling
self.$indicator = render().insertBefore( $where );
self.message( msg );
self.$indicator.fadeIn( speed, callback );
return self;
};
self.message = function( msg ){
self.$indicator.find( 'i' ).text( msg );
};
self.hide = function( speed, callback ){
speed = speed || 'fast';
if( self.$indicator && self.$indicator.size() ){
self.$indicator.fadeOut( speed, function(){
self.$indicator.remove();
if( callback ){ callback(); }
});
} else {
if( callback ){ callback(); }
}
return self;
};
return self;
}
@@ -0,0 +1 @@
(function(a,b){if(typeof define==="function"&&define.amd){define([],b)}else{a.LoadingIndicator=b()}}(this,function(){function a(b,d){var c=this;d=jQuery.extend({cover:false},d||{});function e(){var f=['<div class="loading-indicator">','<div class="loading-indicator-text">','<span class="fa fa-spinner fa-spin fa-lg"></span>','<span class="loading-indicator-message">loading...</span>',"</div>","</div>"].join("\n");var h=$(f).hide().css(d.css||{position:"fixed"}),g=h.children(".loading-indicator-text");if(d.cover){h.css({"z-index":2,top:b.css("top"),bottom:b.css("bottom"),left:b.css("left"),right:b.css("right"),opacity:0.5,"background-color":"white","text-align":"center"});g=h.children(".loading-indicator-text").css({"margin-top":"20px"})}else{g=h.children(".loading-indicator-text").css({margin:"12px 0px 0px 10px",opacity:"0.85",color:"grey"});g.children(".loading-indicator-message").css({margin:"0px 8px 0px 0px","font-style":"italic"})}return h}c.show=function(g,f,h){g=g||"loading...";f=f||"fast";b.parent().find(".loading-indicator").remove();c.$indicator=e().insertBefore(b);c.message(g);c.$indicator.fadeIn(f,h);return c};c.message=function(f){c.$indicator.find("i").text(f)};c.hide=function(f,g){f=f||"fast";if(c.$indicator&&c.$indicator.size()){c.$indicator.fadeOut(f,function(){c.$indicator.remove();if(g){g()}})}else{if(g){g()}}return c};return c}return a}));
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long