summaryrefslogtreecommitdiff
blob: 3d1ef9d70e1464c3979e4b6b803af1031fe83585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/**
 *
 * @author Ardeleanu Ionut
 * @langversion JAVASCRIPT
 *
 * http://www.appticles.com
 * ionut@appticles.com
 * alexandra@appticles.com
 *
 */
 
 
/*****************************************************************************************************/
/*                                                                                                   */
/*                                         PRELOADER CLASS                                           */          
/*                                                                                                   */
/*****************************************************************************************************/ 
function WMPPreloader(){
	
	var JSObject = this;
	
	this.defaultParams = {width: 320,
						height: 80,
						message: 'Please wait...'};
						
	
	/*****************************************************************************************/
	/*                                      START PRELOADER                                  */
	/*****************************************************************************************/
	/**
	 * start the loader
	 * method type: LOCAL
	 * params: @params : a JSON with new params like defaultParams
	 */
	this.start = function(params){
		
		this.defaultParams = jQuery.extend({}, this.defaultParams, params);
		
		jQuery('#preloader_container').remove();
		jQuery('body *:first',document).before('<div id="preloader_container" style="position:fixed; z-index:999998; display:none;"><div class="preloader"></div><div style="position:fixed; background: #000;"><div id="preloader_table" align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#FFF; padding:10px;">'+this.defaultParams.message+'<br><br><img src="'+WMPJSInterface.localpath+'admin/images/loading_animation.gif" /></div></div></div>');
		
		var preloader_container = jQuery('#preloader_container');
		var table = jQuery('#preloader_table',preloader_container);
		var preloading_bg = jQuery('.preloader',preloader_container);
		
		var w = this.defaultParams.width;
		var h = this.defaultParams.height;
		
		table.width(w-20);
		table.height(h-20);
		table.parent().width(w);
		table.parent().height(h);
		preloading_bg.width(w);
		preloading_bg.height(h);
		preloading_bg.parent().width(w);
		preloading_bg.parent().height(h);
				
		var newW = (-w/2)+'px';
		var newH = (-h/2)+'px';
		
		preloader_container.css({'top':'50%' , 'left':'50%' , 'margin-left': newW, 'margin-top':newH}).fadeIn(500);	
		
		preloader_container.css({'top':'50%' , 'left':'50%' , 'margin-left': newW, 'margin-top':newH}).fadeIn(500);	
	}
	
	
	/*****************************************************************************************/
	/*                                      UPDATE PRELOADER                                 */
	/*****************************************************************************************/
	/**
	 * update the preloader with a new message
	 * method type: LOCAL
	 * params: @msg : the new message to display
	 */
	this.update = function(msg){
		
		var preloader_container = jQuery('#preloader_container');
		var table = jQuery('#preloader_table',preloader_container);
		table.get(0).rows[0].cells[0].innerHTML = msg;
		
	}
	
	/*****************************************************************************************/
	/*                                      REMOVE PRELOADER                                 */
	/*****************************************************************************************/
	/**
	 * remove the loader from the stage
	 * method type: LOCAL
	 * params: @time : the time for the loader to disappear
	 */
	this.remove = function(time){
		
		if (jQuery('#loading_container') != null){
			jQuery('#loading_container').remove();	
		}
		
		if (time == null){
			time = 100;	
		}
		
        var preloader_container = jQuery('#preloader_container');
        preloader_container.stop();
        
        preloader_container.fadeOut({duration: time},function(){ preloader_container.remove(); });
	}
	
}

/*****************************************************************************************************/
/*                                                                                                   */
/*                                            MESSAGE CLASS                                          */          
/*                                                                                                   */
/*****************************************************************************************************/
function WMPMessage(){
	var JSObject = this;
	
	this.defaultParams = {
							width: 				450,
							time: 				8000,
							speed:				500,
							delay:				500,
							message:			"",
							closeFunction: 		null};	// for redirect purpose...., after the message is closed
	
	this.parentContainer;				// the message container (div element)
	this.container;						
	
	
	
	/*****************************************************************************************/
	/*                                      VIEW MESSAGE                                     */
	/*****************************************************************************************/
	/**
	 * view message
	 * method type: LOCAL
	 * params: @params : a JSON with new params like defaultParams
	 */
	this.view = function(params){
		
		this.defaultParams = jQuery.extend({}, this.defaultParams, params);
		
		// number of messages current displayed
		var no_messages = jQuery('div[id="wmpMessageBox"]', this.parentContainer).get().length;
		
		// add message box to the parent container
		var html = '<div id="wmpMessageBox" class="loader" style="display:none;">';
			html += 	'<div id="wmpBoxTable" align="left" style="background: #fefcd4;">';
			html += 		'<div style="float:right; height:15px; padding-right:5px; padding-top:5px"><img id="wmpCloseMsg" src="'+WMPJSInterface.localpath+'admin/images/btn_close_msg.png" border="0" style="cursor:pointer" /></div>';
			html += 		'<div align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000; padding:15px;">' + this.defaultParams.message +'</div>';
			html += 	'</div>';
			html += '</div>';
			html += '<div style="height:5px;"></div>';
		
		jQuery(this.parentContainer).append(html);
						
		this.container = jQuery('div[id="wmpMessageBox"]:eq('+no_messages+')', this.parentContainer);
		var table = jQuery('#wmpBoxTable',this.container);
		var close_btn = jQuery('#wmpCloseMsg',table);
		
		// set message table width
		var w = this.defaultParams.width;
		table.width(w);
		table.parent().width(w);
		
		// open message box
		this.container.delay(this.defaultParams.delay).slideDown(this.defaultParams.speed);
		
		
		// start message timer
		this.container.unbind("countTimer");
		this.container.bind("countTimer",function(){
			
			var seconds = JSObject.defaultParams.time;
																		
			//wait until elapsed time reaches 0 seconds
			if (seconds/1000 - 1 >= 1){
				JSObject.defaultParams.time -= 1000;
			}
			else{
				jQuery(this).unbind("countTimer");
				clearInterval(jQuery(this).data("timerInterval"));
				jQuery(this).removeData("timerInterval");
				
				//remove the message from the stage
				JSObject.remove();
				
				if (typeof JSObject.defaultParams.closeFunction == "function") JSObject.defaultParams.closeFunction();
			}
			
		})
		
		this.container.data("timerInterval", setInterval(function(){ JSObject.container.trigger("countTimer")},1000));
		
		
		// close button 'click' action
		close_btn.unbind("click");
		close_btn.bind("click",function(){
			
			jQuery(this).unbind("click");
			
			//remove the message from the stage
			JSObject.remove();
		})
	}
	
	
	/*****************************************************************************************/
	/*                                      REMOVE MESSAGE                                   */
	/*****************************************************************************************/
	/**
	 * remove message
	 * method type: LOCAL
	 * params: no params
	 */
	this.remove = function(){
		
		// close message box
		JSObject.container.slideUp(JSObject.defaultParams.speed, function(){  
																		  var spacerDiv = jQuery(this).next();
																		  
																		  jQuery(this).remove();
																		  
																		  // close the bottom spacer
																		  spacerDiv.slideUp(200, function(){ jQuery(this).remove(); })
																		  });
	}
	
}


/*****************************************************************************************************/
/*                                                                                                   */
/*                                            LOADER CLASS                                           */          
/*                                                                                                   */
/*****************************************************************************************************/ 
function WMPLoader(){
	
 	var JSObject = this;
	
	this.arr_messages = [];		// an array with messages objects
	
	
	/*****************************************************************************************/
	/*                                      INIT LOADER                                      */
	/*****************************************************************************************/
	/**
	 * initialize the Loader, and create the messages box
	 * method type: LOCAL
	 * params: no params
	 */
	this.init = function(){
		
		jQuery('#wmp_messages_container').remove();
		jQuery(jQuery('body').get(0)).append('<div align="center" id="wmp_messages_container" style="position:fixed; z-index:999999; width: 100%; display:block; top: 5px; margin: 0 auto;"></div>');
		
		var messages_container = jQuery('#wmp_messages_container');
				
	}
	
	/*****************************************************************************************/
	/*                                      DISPLAY LOADER                                   */
	/*****************************************************************************************/
	/**
	 * display a new message
	 * method type: LOCAL
	 * params: @params : a JSON with params {time, width, message, speed, closeFunction}
	 */
	this.display = function(params){
		
		var messages_container = jQuery('#wmp_messages_container');
		
		var newMessage = new WMPMessage();
		newMessage.parentContainer = messages_container;
		this.arr_messages.push(newMessage);
		
		newMessage.view(params);
	}
	
}