summaryrefslogtreecommitdiff
blob: b387c78d0a94cdfa2ca71e533b1063b0898e7463 (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
/**
 *
 * @author Ardeleanu Ionut
 * @langversion JAVASCRIPT
 *
 * http://www.appticles.com
 * ionut@appticles.com
 * alexandra@appticles.com
 *
 */
 /* Browsers tested: IE6+, Firefox 3+, Opera 8+, Chrome, Safari 4 for windows*/

// hack for IE
if (window.console === undefined) {
	var console = { log : function(param){ alert(param);} };
}

var WMPJSInterface =  function(){
	
	var objects_arr = new Array();
	
	return{	
		
		localpath: '',				    		// domain path
		
		AjaxUpload: new WMPAjaxUpload(),   		// object that makes the upload of a form without refreshin via AJAX
		Preloader: new WMPPreloader(),  		// the preloader object used for sending data to server through AJAX
		Loader: new WMPLoader(),   				// the object used to display AJAX error messages
				
		
		/*****************************************************************************************/
		/*                                      INIT INTERFACE                                   */
		/*****************************************************************************************/
		/**
		 * initialize the WMPJSInterface
		 * method type: LOCAL
		 * params: none
		 */
		init: function(){
			
			//when document is finish loaded, initialize the interface objects (UI_register, UI_users, UI_comments, etc)
			jQuery(document).ready(function(){
			 
                WMPJSInterface.Loader.init();
				WMPJSInterface.initObjects();
                
			});	
		},
		
		
		
		/*****************************************************************************************/
		/*                                      INIT INTERFACE OBJECTS                           */
		/*****************************************************************************************/
		/**
		 * initialize the WMPJSInterface objects
		 * method type: LOCAL
		 * params: none
		 */
		initObjects: function(){
			for (var i=0; i<objects_arr.length; i++){
				objects_arr[i].init();	
			}
		},
		
		
		/*****************************************************************************************/
		/*                                   ADD INTERFACE OBJECT                                */
		/*****************************************************************************************/
		/**
		 * add an object to the WMPJSInterface
		 * method type: LOCAL
		 * params: @objName : the name of the object in the WMPJSInterface
		 *         @objType : object type like: REGISTER, USERS, COMMENTS, etc
		 *         @params  : a JSON with params to pass to the new created object. Ex: {'name':'Johnson','age':24}
		 */
		add: function(objName, objType, params, iframeWindow){

			//find similar object and remove it	
			for (var i=0; i<objects_arr.length; i++){
				var obj = objects_arr.shift();
				if (obj === this[objName]){
					this[objName] = null;
				}
				else{
					objects_arr.push(obj);
				}
			}
			
			iframeWindow = (iframeWindow == null) ? window : iframeWindow;
			
			//create object
			this[objName] = new iframeWindow[objType]();
			if (params != null){
				for (var property in params){
					this[objName][property] = params[property];
					
				}
			}
			objects_arr.push(this[objName]);
			
		},
		
		
		/*****************************************************************************************/
		/*                                   SCROLL TO FIT SIZE                                  */
		/*****************************************************************************************/
		/**
		 * scroll the document body so that the object fits his entire height inside the body visible area
		 * method type: LOCAL
		 * params: @obj : jQuery object such as jQuery(div), jQuery(p) ... 
		 */
		scrollToFit: function(obj){
			
			var container = jQuery('html,body');
			var scrollTop = parseInt(container.scrollTop());
			var containerHeight = container.get(0).clientHeight;
			var objTop = parseInt(obj.offset().top);
			var objHeight = obj.height();
			var objBottom = objTop + objHeight;
			
			if (objTop < scrollTop){
				jQuery(container).animate({scrollTop: objTop }, 1000);	
			}
			else if (objTop >= scrollTop && objTop < containerHeight+scrollTop){
				if (objBottom > containerHeight+scrollTop){
					jQuery(container).animate({scrollTop: objBottom-containerHeight }, 1000);		
				}
			}
			else if (objTop >= containerHeight+scrollTop){
				jQuery(container).animate({scrollTop: objBottom-containerHeight }, 1000);		
			}
		}		
	}
}();