huangbo 9 years ago
parent
commit
aa27435cb1

+ 1 - 2
multiple-server/web/biz/js/index.js

@ -1,4 +1,4 @@
1
require(["wmTabbar","common","mobile","wademobile","util"], function(WmTabbar,Common,Mobile,WadeMobile) {
1
require(["wmTabbar","common","mobile","wadeMobile","util"], function(WmTabbar,Common,Mobile,WadeMobile) {
2 2
	var wmTabbar = new WmTabbar("tabbar");
3 3
	wmTabbar.create();
4 4
	
@ -18,7 +18,6 @@ require(["wmTabbar","common","mobile","wademobile","util"], function(WmTabbar,Co
18 18
			loginData.put("APP_TYPE",appType);
19 19
			loginData.put("APP_ID",appId);
20 20
			Common.callSvc("LoginBean.loginApp",loginData,function(result){
21
				alert(result)
22 21
				if(appType=="I"){
23 22
					//alert("打开IPU应用"+appId);
24 23
					WadeMobile.openIpuApp(appId);

+ 50 - 3
multiple-server/web/res/js/mobile/expand-mobile.js

@ -23,6 +23,15 @@ define(["require"],function(require) {
23 23
				}
24 24
				storageCallback("getDate",callback);
25 25
				execute("getDate", [date,format],err);
26
			},getContactsView:function(callback,data,setting,err){
27
				if(data==undefined){
28
					data = new Wade.DataMap();
29
				}
30
				if(setting==undefined){
31
					setting = new Wade.DataMap();
32
				}
33
				storageCallback("getContactsView",callback);
34
				execute("getContactsView", [data.toString(),setting.toString()],err);
26 35
			},getPhoto:function(callback,type,err){//获取照片
27 36
				if(type==undefined){
28 37
					type = 1;//0-Base64编码的字符串 1- 文件路径
@ -53,12 +62,12 @@ define(["require"],function(require) {
53 62
				execute("shock", [time],err);
54 63
			},call:function(sn,autoCall,err){
55 64
				if(autoCall==undefined){
56
					autoCall=1;//0-跳转至拨打界面,1-直接拨打
65
					autoCall = false;// false-跳转至拨打界面,true-直接拨打
57 66
				}
58 67
				execute("call", [sn,autoCall],err);
59 68
			},sms:function(sn,msg,autoSms,err){
60 69
				if(autoSms==undefined){
61
					autoSms=0;//0-跳转至短信界面,1-直接短信
70
					autoSms = false;// false-跳转至短信界面,true-直接短信
62 71
				}
63 72
				execute("sms", [sn,msg,autoSms],err);
64 73
			},openApp:function(appId,urlParams,installUrl,err){
@ -213,6 +222,44 @@ define(["require"],function(require) {
213 222
				execute("sendText", [account,content],err);
214 223
			},setCallbackForPush:function(callback){
215 224
				execute("setCallbackForPush", [callback]);
225
			},registerForPushWithYunba:function(account,callback,err){
226
				storageCallback("registerForPushWithYunba",callback);
227
				execute("registerForPushWithYunba",[account],err);
228
			},unregisterForPushWithYunba:function(callback){
229
				storageCallback("unregisterForPushWithYunba",callback);
230
				execute("unregisterForPushWithYunba", []);
231
			},sendTextWithYunba:function(account,content,callback,err){
232
				storageCallback("sendTextWithYunba",callback);
233
				execute("sendTextWithYunba", [account,content],err);
234
			},setCallbackForPushWithYunba:function(callback){
235
				execute("setCallbackForPushWithYunba", [callback]);
236
			},aliPay:function(tradeNo,subject,body,price,callback,err){
237
				storageCallback("aliPay",callback);
238
				execute("aliPay",[tradeNo,subject,body,price],err);	
239
			},uploadWithServlet:function(filePath,dataAction,param,callback,err){
240
				if(typeof(filePath)=="string"){
241
					filePath = [filePath];
242
				}
243
				storageCallback("uploadWithServlet",callback);
244
				execute("uploadWithServlet",[filePath,dataAction,param],err);	
245
			},downloadWithServlet:function(savePath,dataAction,param,callback,err){
246
				storageCallback("downloadWithServlet",callback);
247
				execute("downloadWithServlet",[savePath,dataAction,param],err);	
248
			},uploadFile:function(filePath,servletUrl,callback,err){
249
				storageCallback("uploadFile",callback);
250
				execute("uploadFile",[filePath,servletUrl],err);	
251
			},downloadFile:function(savePath,servletUrl,callback,err){
252
				storageCallback("downloadFile",callback);
253
				execute("downloadFile",[savePath,servletUrl],err);	
254
			},recordVideo:function(callback,compressRatio,timeLimit,err){
255
				storageCallback("recordVideo",callback);
256
				execute("recordVideo",[compressRatio,timeLimit],err);	
257
			},playVideo:function(videoPath,callback,err){
258
				storageCallback("playVideo",callback);
259
				execute("playVideo",[videoPath],err);	
260
			},getContacts:function(callback,err){
261
				storageCallback("getContacts",callback);
262
				execute("getContacts",[], err);	
216 263
			}
217 264
		};
218 265
	})();
@ -234,4 +281,4 @@ define(["require"],function(require) {
234 281
	}
235 282
	
236 283
	return ExpandMobile;
237
});
284
});

+ 10 - 1
multiple-server/web/res/js/mobile/mobile-browser.js

@ -19,6 +19,15 @@ define(["browserTool","jcl"],function(browserTool,Wade) {
19 19
		/*调用服务*/
20 20
		this.dataRequest = function(action, param, callback, isEscape, err) {
21 21
			browserTool.ajax.post(action, param, callback, isEscape, err);
22
			/*browserTool.ajax.post(action, param, function(resultData){
23
				resultData = Wade.DataMap(resultData);
24
				var x_resultcode = resultData.get("X_RESULTCODE");
25
				if(x_resultcode < 0){
26
					err(resultData);
27
				}else{
28
					callback(resultData);
29
				};
30
			}, isEscape, err);*/
22 31
		};
23 32
		/******************页面跳转**********************/
24 33
		/*页面跳转,url为跳转目标*/
@ -194,7 +203,7 @@ define(["browserTool","jcl"],function(browserTool,Wade) {
194 203
		this.selectFirst = function(dbName,table,columns,conds,callback,err){
195 204
			alert("等待实现");
196 205
		};
197
		
206

198 207
		this.openNativeApp = function(packageName,className,param,err){
199 208
			alert("openNativeApp等待实现");
200 209
		};

+ 17 - 13
multiple-server/web/res/js/mobile/mobile-client.js

@ -44,7 +44,11 @@ define(["wadeMobile","clientTool"],function(WadeMobile,clientTool) {
44 44
		};
45 45
		/*将Page转换成html源码*/
46 46
		this.getPage = function(action, param, callback, err){
47
			alert("getPage待开发……");
47
			param = param ? param : "";
48
			if(typeof(param) != "string"){
49
				param = param.toString();
50
			}
51
			WadeMobile.getPage(callback,action,param,err);
48 52
		};
49 53
		/*回退到前一个界面*/
50 54
		this.back = function(){
@ -82,8 +86,8 @@ define(["wadeMobile","clientTool"],function(WadeMobile,clientTool) {
82 86
				WadeMobile.setMemoryCache(key, value);
83 87
			}
84 88
		};
85
		this.getMemoryCache = function(callback,key, value){
86
			WadeMobile.getMemoryCache(callback,key, value);
89
		this.getMemoryCache = function(callback,key,value){
90
			WadeMobile.getMemoryCache(callback,key,value);
87 91
		};
88 92
		this.removeMemoryCache = function(key){
89 93
			WadeMobile.removeMemoryCache(key);
@ -143,21 +147,21 @@ define(["wadeMobile","clientTool"],function(WadeMobile,clientTool) {
143 147
		this.execSQL = function(dbName,sql,bindArgs,callback,err){
144 148
			WadeMobile.execSQL(dbName,sql,bindArgs,callback,err);
145 149
		};
146
		this.insert = function(dbName,table,datas,callback,err){
147
			WadeMobile.insert(dbName,table,datas,callback,err);
150
		this.insert = function(dbName,sql,bindArgs,callback,err){
151
			WadeMobile.insert(dbName,sql,bindArgs,callback,err);
148 152
		};
149
		this.delete = function(dbName,table,datas,callback,err){
150
			WadeMobile.delete(dbName,table,datas,callback,err);
153
		this.delete = function(dbName,sql,bindArgs,callback,err){
154
			WadeMobile.delete(dbName,sql,bindArgs,callback,err);
151 155
		};
152
		this.update = function(dbName,table,datas,conds,callback,err){
153
			WadeMobile.update(sql,bindArgs,callback,err);
156
		this.update = function(dbName,sql,bindArgs,callback,err){
157
			WadeMobile.update(dbName,sql,bindArgs,callback,err);
154 158
		};
155
		this.select = function(dbName,table,columns,conds,callback,err){
156
			WadeMobile.select(sql,bindArgs,callback,err);
159
		this.select = function(dbName,sql,bindArgs,callback,err){
160
			WadeMobile.select(dbName,sql,bindArgs,callback,err);
157 161
		};
158 162
		//查询第一行数据,效率高
159
		this.selectFirst = function(dbName,table,columns,conds,callback,err){
160
			WadeMobile.selectFirst(sql,bindArgs,callback,err);
163
		this.selectFirst = function(dbName,sql,bindArgs,callback,err){
164
			WadeMobile.selectFirst(dbName,sql,bindArgs,callback,err);
161 165
		};
162 166
		
163 167
		this.openNativeApp = function(packageName,className,param,err){

+ 17 - 22
multiple-server/web/res/js/mobile/wade-mobile.js

@ -1,20 +1,19 @@
1 1
/**
2 2
 * 与客户端交互的基础API
3 3
 */
4
define(["jcl","base64","util","res/js/mobile/expand-mobile.js","biz/js/common/biz-mobile.js"],function(Wade,Base64) {
4
define(["jcl","base64","res/js/mobile/expand-mobile.js","biz/js/common/biz-mobile.js"],function(Wade,Base64) {
5 5
	//终端类型,a为android,i为ios
6
    var terminalType = (function(){
6
	var terminalType = window["TerminalType"];
7
    var deviceType = (function(){
7 8
		var sUserAgent = navigator.userAgent.toLowerCase();
8 9
		var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
9
		var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
10
		var bIsIphone = sUserAgent.match(/iphone os/i) == "iphone os";
10 11
		var bIsAndroid = sUserAgent.match(/android/i) == "android";
11 12
		var bIsWinphone = sUserAgent.match(/windows phone /i) == "windows phone " || sUserAgent.match(/windows phone os /i) == "windows phone os ";
12 13
		if(bIsAndroid){
13 14
			return "a";
14
		}else if(bIsIpad||bIsIphoneOs){
15
		}else if(bIsIpad||bIsIphone){
15 16
			return "i";
16
		}else if(bIsWinphone){
17
			return "w";
18 17
		}else{
19 18
			return null;
20 19
		}
@ -22,14 +21,9 @@ define(["jcl","base64","util","res/js/mobile/expand-mobile.js","biz/js/common/bi
22 21
	
23 22
	WadeMobile = (function(){
24 23
        return{
25
        	isAndroid:function(){
26
        		return terminalType=='a';
27
        	},isIOS:function(){
28
        		return terminalType=='i';
29
        	},isWP:function(){
30
        		return terminalType=='w';
31
        	},isApp:function(){//判断是否是APP应用
32
				return terminalType!=null;
24
        	isApp:function(){//判断是否是APP应用
25
        		//deviceType=="i"是为了考虑客户端能加载远程Web页面
26
				return window["TerminalType"]||window["PluginManager"];
33 27
        	},getSysInfo:function(callback,key,err){//TELNUMBER|IMEI|IMSI|SDKVERSION|OSVERSION|PLATFORM|SIMNUMBER
34 28
				WadeMobile.callback.storageCallback("getSysInfo",callback);
35 29
				execute("getSysInfo", [key],err);
@ -92,8 +86,6 @@ define(["jcl","base64","util","res/js/mobile/expand-mobile.js","biz/js/common/bi
92 86
				execute("openSlidingMenu", [action,param,width,height,leftMargin,topMargin,isEscape],err);
93 87
			},closeSlidingMenu:function(result,state,err){
94 88
				execute("closeSlidingMenu", [result,state],err);
95
			},openIpuApp(callback,appName){
96
				execute("openIpuApp", [appName],err);
97 89
			}
98 90
		};
99 91
	})();
@ -105,6 +97,7 @@ define(["jcl","base64","util","res/js/mobile/expand-mobile.js","biz/js/common/bi
105 97
	var globalErrorKey = null;//全局错误关键字,定位错误
106 98
	
107 99
	/*绝大多数情况下,success回调函数是用不上的,有需要回调函数的时候异步方式传入取值*/
100
	var isAlert = true;//防止反复弹出alert
108 101
	var execute = function(action, args, error, success){
109 102
        args = stringify(args);
110 103
		if(terminalType=="a"){
@ -114,8 +107,12 @@ define(["jcl","base64","util","res/js/mobile/expand-mobile.js","biz/js/common/bi
114 107
		}else if(terminalType=="w"){
115 108
			winphoneExecute(action, args, error, success);
116 109
		}else{
117
			//alert("无终端类型");
118
			//iosExecute(action, args, error, success);
110
			if(isAlert){
111
				isAlert = false
112
				alert(action+"无终端类型");
113
			}else{
114
				console.log(action+"无终端类型");
115
			}
119 116
		}
120 117
	};
121 118
	
@ -145,7 +142,6 @@ define(["jcl","base64","util","res/js/mobile/expand-mobile.js","biz/js/common/bi
145 142
        }
146 143
        var WADE_SCHEME = "wade://";
147 144
        var url = WADE_SCHEME+action+"?param="+args+"&callback="+callbackKey;
148
        //var ifrmName = action;
149 145
        //一个动作请求客户端的最大数量,超过会造成请求覆盖
150 146
        var limitAction = 10;
151 147
        var ifrmName = "WADE_FRAME_"+(callbackId%limitAction);
@ -223,7 +219,7 @@ define(["jcl","base64","util","res/js/mobile/expand-mobile.js","biz/js/common/bi
223 219
		        }
224 220
			},execCallback:function(callbackKey, data){
225 221
				globalErrorKey = callbackKey;
226
				var callbackItem= callbackDefine[callbackKey];
222
				var callbackItem = callbackDefine[callbackKey];
227 223
				if (callbackItem) {
228 224
					data = data=="null"?null:data;
229 225
		        	if(data){
@ -349,8 +345,7 @@ define(["jcl","base64","util","res/js/mobile/expand-mobile.js","biz/js/common/bi
349 345
	        }
350 346
	        s = s + "]";
351 347
	        return s;
352
	    }
353
	    else {
348
	    }else {
354 349
	        return JSON.stringify(args);
355 350
	    }
356 351
	};

+ 4 - 2
multiple-server/web/res/js/require-config.js

@ -16,7 +16,7 @@ require.config({
16 16
		'iScroll5' : 'base/iscroll5',
17 17
		'hammer' : 'base/hammer',
18 18
		'o' : 'frame/o',
19
		'oEvent' : 'frame/o-event',
19
		//'oEvent' : 'frame/o-event',
20 20
		'oInput' : 'frame/o-input',
21 21
		'tap' : 'frame/tap',
22 22
		'browserTool' : 'mobile/browser-toolkit',
@ -43,7 +43,9 @@ require.config({
43 43
		'wmProgress' : 'ui/wm-progress',
44 44
		'wmSegment' : 'ui/wm-segment',
45 45
		'wmDialog' : 'ui/wm-dialog',
46
		'wmDropmenu' : 'ui/wm-dropmenu'
46
		'wmDialog2' : 'ui/wm-dialog2',
47
		'wmDropmenu' : 'ui/wm-dropmenu',
48
		'wmRefresh' : 'ui/wm-refresh'
47 49
		
48 50
	},
49 51
	deps: [],

+ 103 - 85
multiple-server/web/res/js/ui/wm-dropmenu.js

@ -4,132 +4,150 @@
4 4
 * example:
5 5
 * 		new IScroll("#content",{tap:true,scrollbars: true,useTransform:false});  
6 6
 */
7
define(["jcl","iScroll","wmWebUI"],function($,iScrol,WmWebUI){
8
	function DropmenuItem(obj,parent){
9
		this.entity=obj;
10
		this.parent=parent;
7
define(["jcl","wmWebUI"],function($,WmWebUI){
8
	/*下拉菜单构造方法*/
9
	function WmDropmenu(id) {
10
		this.items = new Array();
11
		var dropmenu = WmWebUI.getElement(id);
12
		/* 使用children方法代替子元素选择器,是为了防止有子元素误判 */
13
		this.selectLabel = dropmenu.children("div").eq(0).children("span").eq(0);
14
		this.menu = dropmenu.children("div").eq(1);
15
		this.closeAction;// 关闭事件
16
		this.openAction;// //打开事件
17
		WmWebUI.store(id, this);
11 18
	}
12
	DropmenuItem.prototype.remove=function(){
13
		this.entity.parentNode.removeChild(this.entity);
14
		this.parent.initMenu();
15
		this.parent.items.splice(this.getIndex(),1)
16
	}
17
	DropmenuItem.prototype.html=function(html){
18
		if(html==undefined){
19
			return this.entity.innerHTML;
20
		}else{
21
			this.entity.innerHTML=html;
19
	/*下拉菜单项构造方法*/
20
	function WmDropmenuItem(parent, index, domElement) {
21
		this.parent = parent; //父对象
22
		this.index = index; //菜单项序号
23
		this.domElement = domElement; //菜单项dom元素
24
		this.action;  //菜单项点击事件
25
		if(domElement.id){
26
			WmWebUI.store(domElement.id, this);
22 27
		}
28
		var that = this;
29
		$(this.domElement).tap(function() {
30
			that.action && that.action(that);
31
		});
23 32
	}
24
	DropmenuItem.prototype.click=function(callback){
25
		var that=this;
26
		this.entity.onclick=function(){
27
			callback(that);
33
	/*移除下拉菜单项*/
34
	WmDropmenuItem.prototype.remove = function() {
35
		this.domElement.parentNode.removeChild(this.domElement);
36
		this.parent.items.splice(this.index, 1);//删除第index个元素
37
		for ( var i = this.index; i < this.parent.items.length; i++) {
38
			this.parent.items[i].index = i;
28 39
		}
40
		this.parent.initMenu();
29 41
	}
30
	DropmenuItem.prototype.getIndex=function(){
31
		for(var i=0;i<this.parent.items.length;i++){
32
			if(this.parent.items[i]==this){
33
				return i;
34
			}
42
	/*设置或返回下拉菜单项的html*/
43
	WmDropmenuItem.prototype.html = function(html) {
44
		if (html == undefined) {
45
			return this.domElement.innerHTML;
46
		} else {
47
			this.domElement.innerHTML = html;
35 48
		}
36
		return -1;
37 49
	}
38
	DropmenuItem.prototype.getParent=function(){
39
		return this.parent;
50
	/*设置下拉菜单项的事件*/
51
	WmDropmenuItem.prototype.setAction = function(action) {
52
		this.action = action;
40 53
	}
41
	function WmDropmenu(id){
42
		this.entity=(function(obj){
43
			if(typeof(obj)=="object"){
44
				obj=$(obj);
45
			}else if(typeof(obj)=="string"){
46
				obj=$("#"+obj);
47
			}else{
48
				alert("没有匹配的类型");
49
				return null;
50
			}
51
			return obj;
52
		})(id);
53
		this.btn=this.entity.children("div").eq(0).children("span").eq(0);
54
		this.menu=this.entity.children("div").eq(1);
55
		this.closeAction=function(){};
56
		this.openAction=function(){};
57
		this.items=new Array();
58
		this.lis=this.menu.children("ul").children("li");
59
		this.temp=false;
60
		var that=this;
61
		$.each(this.lis,function(index,obj){
62
			var item=new DropmenuItem(obj,that);
63
			that.items.push(item);
64
		});
54
	/*获取下拉菜单项的序号*/
55
	WmDropmenuItem.prototype.getIndex=function(){
56
		return this.index;
65 57
	}
58
	/*初始化下拉菜单*/
66 59
	WmDropmenu.prototype.initMenu=function(){
67 60
		this.menu.css("display","");
68 61
		//设置 dropmenu
69 62
		//初始化(CSS已将它默认放到了界面之外,以下设置不会造成闪烁)
70 63
		this.menu.children("ul").css("top",(this.menu.height())*(-1) + "px");
71
		this.menu.children("ul").css("transition","transform 0.2s ease-out");
72
		this.btn.children(".e_ico-unfold").css("transition","transform 0.2s ease-out");
64
		this.menu.children("ul").css("transition","-webkit-transform 0.2s ease-out");
65
		this.menu.children("ul").css("-webkit-transition","transform 0.2s ease-out");
66
		this.selectLabel.children(".e_ico-unfold").css("transition","transform 0.2s ease-out");
67
		this.selectLabel.children(".e_ico-unfold").css("-webkit-transition","-webkit-transform 0.2s ease-out");
73 68
		this.menu.css("visibility","hidden");
74 69
		//位置
75
		this.menu.css("left",this.btn.offset().left + this.btn.width() - this.menu.width());//靠右要减去这两个 width(),靠左则不需要
76
		this.menu.css("top",this.btn.offset().top + 1.1 * this.btn.height());/*modified*/
70
		this.menu.css("left",this.selectLabel.offset().left + this.selectLabel.width() - this.menu.width());//靠右要减去这两个 width(),靠左则不需要
71
		this.menu.css("top",this.selectLabel.offset().top + 1.1 * this.selectLabel.height());/*modified*/
77 72
		this.menu.css("display","none");
78 73
		this.menu.css("visibility","visible");
79 74
	}
80
	WmDropmenu.prototype.create=function(){
75
	WmDropmenu.prototype.create = function() {
76
		var that = this;
77
		var lis = this.menu.children("ul").children("li");
78
		lis.each(function(index) {
79
			that.items.push(new WmDropmenuItem(that, index, this));
80
		});
81

81 82
		this.initMenu();
82
		var that=this;
83
		//显隐
84
		this.btn.click(function(){
85
			if(that.invisible()){
83
		// 显隐
84
		this.selectLabel.tap(function() {
85
			if (that.invisible()) {
86 86
				that.show();
87
			}else{
87
			} else {
88 88
				that.hidden();
89 89
			}
90 90
		});
91 91
	};
92
	WmDropmenu.prototype.invisible=function(){
92
	/*获取下拉菜单项*/
93
	WmDropmenu.prototype.getDropmenuItem = function(index){
94
		return this.items[index];
95
	}
96
	/*获取下拉菜单项集合*/
97
	WmDropmenu.prototype.getDropmenuItems = function() {
98
		return this.items;
99
	};
100
	/*判断下拉菜单是否可见*/
101
	WmDropmenu.prototype.invisible = function() {
93 102
		return this.menu.css("display") == "none";
94 103
	};
95
	WmDropmenu.prototype.show=function(){
96
		this.openAction();
97
		this.menu.css("display","");
104
	/*显示下拉菜单*/
105
	WmDropmenu.prototype.show = function() {
106
		this.openAction && this.openAction();
107
		this.menu.css("display", "block");
98 108
		this.menu.children("ul").css("transform","translateY(" + this.menu.height() + "px)");
99
		this.btn.find(".e_ico-unfold").css("transform","rotate(180deg)");
109
		this.menu.children("ul").css("-webkit-transform","translateY(" + this.menu.height() + "px)");
110
		this.selectLabel.find(".e_ico-unfold").css("transform","rotate(180deg)");
111
		this.selectLabel.find(".e_ico-unfold").css("-webkit-transform","rotate(180deg)");
100 112
	};
101
	WmDropmenu.prototype.hidden=function(){
102
		this.closeAction();
113
	/*隐藏下拉菜单*/
114
	WmDropmenu.prototype.hidden = function(){
115
		this.closeAction && this.closeAction();;
103 116
		this.menu.children("ul").css("transform","translateY(0)");
104
		this.btn.find(".e_ico-unfold").css("transform","rotate(0)");
117
		this.menu.children("ul").css("-webkit-transform","translateY(0)");
118
		this.selectLabel.find(".e_ico-unfold").css("transform","rotate(0)");
119
		this.selectLabel.find(".e_ico-unfold").css("-webkit-transform","rotate(0)");
105 120
		this.menu.css("display","none");
106 121
	};
107
	WmDropmenu.prototype.removeAll=function(){
108
		this.menu.children("ul")[0].innerHTML="";
109
		this.items=new Array();
122
	/*删除所有下拉菜单项*/
123
	WmDropmenu.prototype.removeAll = function() {
124
		this.menu.children("ul")[0].innerHTML = "";
125
		this.items = new Array();
110 126
	};
111
	WmDropmenu.prototype.push=function(obj){
127
	/*添加下拉菜单项*/
128
	WmDropmenu.prototype.push = function(obj){
112 129
		this.menu.children("ul").append("<li>"+obj+"</li>");
113 130
		this.initMenu();
114
		var li=this.menu.children("ul").children("li").last()[0];
115
		var item=new DropmenuItem(li,this);
131
		var lis = this.menu.children("ul").children("li");
132
		var item = new WmDropmenuItem(this,lis.length-1,lis.last()[0]);
116 133
		this.items.push(item);
117 134
		return item;
118 135
	};
119
	WmDropmenu.prototype.setLabel=function(label){
120
		this.btn.children("span")[0].innerHTML=label;
121
	};
122
	WmDropmenu.prototype.getLabel=function(){
123
		return this.btn.children("span")[0].innerHTML;
136
	/*设置下拉菜单文本 */
137
	WmDropmenu.prototype.setLabel = function(label) {
138
		this.selectLabel.children("span")[0].innerHTML = label;
124 139
	};
125
	WmDropmenu.prototype.setCloseAction=function(callback){
126
		this.closeAction=callback;
140
	/*获取下拉菜单文本 */
141
	WmDropmenu.prototype.getLabel = function() {
142
		return this.selectLabel.children("span")[0].innerHTML;
127 143
	};
128
	WmDropmenu.prototype.setOpenAction=function(callback){
129
		this.openAction=callback;
144
	/*设置下拉菜单打开事件 */
145
	WmDropmenu.prototype.setOpenAction = function(callback) {
146
		this.openAction = callback;
130 147
	};
131
	WmDropmenu.prototype.getItems=function(){
132
		return this.items;
148
	/*设置下拉菜单关闭事件 */
149
	WmDropmenu.prototype.setCloseAction = function(callback) {
150
		this.closeAction = callback;
133 151
	};
134 152
	return WmDropmenu;
135 153
});

+ 12 - 2
multiple-server/web/res/js/ui/wm-popup.js

@ -1,8 +1,10 @@
1
define(["module","oEvent"],function(module,oEvent){
1
define(["module","tap"],function(module,tap){
2
	var popup;
2 3
	function createNew(popupDom) {
3
		var popup = typeof popupDom == 'object' ? popupDom : document.getElementById(popupDom);
4
		popup = typeof popupDom == 'object' ? popupDom : document.getElementById(popupDom);
4 5
		for (var i = 1; i < arguments.length; i++) {
5 6
			var o = typeof arguments[i] == 'object' ? arguments[i] : document.getElementById(arguments[i]);
7
			/*
6 8
			oEvent.tap(o,(function(popup){
7 9
				if(popup.className == "c_popup") {
8 10
					popup.className = "c_popup c_popup-view";
@ -10,6 +12,14 @@ define(["module","oEvent"],function(module,oEvent){
10 12
					popup.className = "c_popup";
11 13
				}
12 14
			}),popup)
15
			*/
16
			$(o).tap(function(){
17
				if(popup.className == "c_popup") {
18
					popup.className = "c_popup c_popup-view";
19
				} else {
20
					popup.className = "c_popup";
21
				}
22
			});
13 23
		}
14 24
		return popup;
15 25
	}

+ 115 - 1
multiple-server/web/res/js/ui/wm-refresh.js

@ -1,3 +1,117 @@
1
define(["jcl","iScroll","wmWebUI"], function($,iScrol,WmWebUI){
1
define(["iScroll"], function(iScroll){
2 2
	
3
	function WmRefresh(id){
4
		this.id = id;
5
		this.pullDownAction = null;
6
		this.pullUpAction = null;
7
		this.init();
8
		
9
	}
10
	
11
	/**
12
	* 下拉刷新 (自定义实现此方法)
13
	* myScroll.refresh();		// 数据加载完成后,调用界面更新方法
14
	*/
15
	
16
	WmRefresh.prototype.setPullDownAction = function(action){
17
		if(typeof(action) == "function") {
18
			this.pullDownAction = action;
19
		}
20
		
21
	}
22
	
23
	/**
24
	* 滚动翻页 (自定义实现此方法)
25
	* myScroll.refresh();		// 数据加载完成后,调用界面更新方法
26
	*/
27
	
28
	WmRefresh.prototype.setPullUpAction = function(action){
29
		if(typeof(action) == "function") {
30
			this.pullUpAction = action;
31
		}
32
	}
33

34
	/**
35
	* 初始化iScroll控件
36
	*/
37
	WmRefresh.prototype.init = function() { 
38
		var pullDownEl, pullDownOffset,
39
		pullUpEl, pullUpOffset;
40
		var that = this;
41
		var maxHeight = document.getElementById(that.id).offsetHeight + "px";
42
		document.getElementById("c-refresh-wrapper").style.height = maxHeight;
43
		pullDownEl = document.getElementById('pullDown');
44
		pullDownOffset = pullDownEl.offsetHeight;
45
		pullUpEl = document.getElementById('pullUp');	
46
		pullUpOffset = pullUpEl.offsetHeight;
47
		var myScroll = new iScroll('c-refresh-wrapper', {
48
		//	scrollbarClass: 'myScrollbar', /* 重要样式 */
49
			useTransition: true, /* 此属性不知用意,本人从true改为false */
50
			topOffset: pullDownOffset,
51
			onRefresh: function () {
52
				console.log(this.maxScrollY);
53
				if (pullDownEl.className.match('loading')) {
54
					pullDownEl.className = '';
55
					pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
56
				} else if (pullUpEl.className.match('loading')) {
57
					pullUpEl.className = '';
58
					pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
59
				}
60
			},
61
			onScrollMove: function () {
62
				if (this.y > 5 && !pullDownEl.className.match('flip')) {
63
					pullDownEl.className = 'flip';
64
					pullDownEl.querySelector('.pullDownLabel').innerHTML = '松手开始更新...';
65
					this.minScrollY = 0;
66
				} else if (this.y < 5 && pullDownEl.className.match('flip')) {
67
					pullDownEl.className = '';
68
					pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
69
					this.minScrollY = -pullDownOffset;
70
				} else{
71
					var c_height = document.getElementById("c-refresh-wrapper").offsetHeight;
72
					var s_height = document.getElementById("c-refresh-scroller").offsetHeight;
73
					var distance;
74
					if (c_height > s_height) {
75
						distance = - (1.5 * pullUpOffset);
76
					}else{
77
						distance = this.maxScrollY - pullUpOffset;
78
					}
79

80
					if (this.y < distance && !pullUpEl.className.match('flip')) {
81
						pullUpEl.className = 'flip';
82
						pullUpEl.querySelector('.pullUpLabel').innerHTML = '松手开始更新...';
83
						this.maxScrollY = this.maxScrollY;
84
					} else if (this.y > distance && pullUpEl.className.match('flip')) {
85
						pullUpEl.className = '';
86
						pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
87
						// this.maxScrollY = pullUpOffset;
88
					}
89
				}
90
			},
91
			onScrollEnd: function () {
92
				if (pullDownEl.className.match('flip')) {
93
					pullDownEl.className = 'loading';
94
					pullDownEl.querySelector('.pullDownLabel').innerHTML = '加载中...';
95
					if(that.pullDownAction){
96
						that.pullDownAction(myScroll);	
97
					}else{
98
						console.log("未定义下拉刷新方法");
99
						myScroll.refresh();	
100
					}
101
					
102
				} else if (pullUpEl.className.match('flip')) {
103
					pullUpEl.className = 'loading';
104
					pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载中...';
105
					if(that.pullUpAction){
106
						that.pullUpAction(myScroll);	
107
					}else{
108
						console.log("未定义上拉加载更多");
109
						myScroll.refresh();	
110
					}
111
				}
112
			}
113
		});
114
	}
115
		
116
	return WmRefresh;
3 117
})

+ 113 - 145
multiple-server/web/res/js/ui/wm-switch.js

@ -1,234 +1,202 @@
1
define(["jcl","iScroll","wmWebUI"],function($,iScrol,WmWebUI){
2
	function WmSwitch(id){
3
		this.entity=(function(obj){
4
			if(typeof(obj)=="object"){
5
				obj=$(obj);
6
			}else if(typeof(obj)=="string"){
7
				obj=$("#"+obj);
8
			}else{
9
				alert("没有匹配类型");
10
				return null;
11
			}
12
			return obj;
13
		})(id);
14
		//存储开关状态的值
15
		this.input=this.entity.find("input");
16
		//三个span,用来存储开、关、及开关滑块
17
		this.span=this.entity.find("span");
18
		//根据开关的默认状态,计算开关滑块到开关控件最边缘的间隙
19
		var space=0;
20
		space=this.span[2].offsetLeft-this.span[2].offsetWidth;	
21
		//console.log("space:"+space)
22
		//计算滑块左右应当移动的距离
23
		this.distance=this.entity[0].offsetWidth-this.span[2].offsetWidth-2*space;
24
		//console.log("distancd:"+this.distance)
25
		//设置开关是否可用
26
		this.enable=true;
27
		//当开关状态改变,或试图改变开关状态时调用(开关不可用时)。
28
		this.changeAction=function(){};
29
		//当开关被打开时调用。
30
		this.onAction=function(){};
31
		//当开关被关闭时调用。
32
		this.offAction=function(){};
1
/**
2
 * 开关组件
3
 */
4
define(["jcl","wmWebUI"],function($,WmWebUI){
5
	function WmSwitch(id) {
6
		this.entity = WmWebUI.getElement(id);
7
		this.input = this.entity.find("input");// 存储开关状态的值
8
		this.span = this.entity.find("span");// 三个span,用来存储开、关、及开关滑块
9
		var space = 0;// 根据开关的默认状态,计算开关滑块到开关控件最边缘的间隙
10
		space = this.span[2].offsetLeft - this.span[2].offsetWidth;
11
		this.distance = this.entity[0].offsetWidth - this.span[2].offsetWidth - 2 * space;// 计算滑块左右应当移动的距离
12
		this.disabled = false;// 设置开关非禁用
13
		this.onAction;	// 开关打开事件
14
		this.offAction;	// 开关关闭事件
15
		this.changeAction;// 开关状态变化时的事件
16
		this.clickAction;// 开关点击事件
17
		
18
		WmWebUI.store(id,this);
33 19
	}
34 20

35 21
	WmSwitch.prototype.create=function(){
36
		var that=this;
37
		if(!this.entity){
38
			alert("无法获取网页元素");
39
			return;
40
		}
41 22
		dragEvent(this);
42 23
	};
24
	
43 25
	function getX(event){
44 26
		return event.touches?event.touches[0].pageX:event.clientX;
45 27
	};
46
	//鼠标拖拽事件
28
	/*鼠标拖拽事件*/
47 29
	function dragEvent(that){
48
		//开关控件本身
49
		var obj=that.entity[0];
50
		//滑块
51
		var blockObj=obj.children[2];
52
		//是否为触屏
30
		var obj = that.entity[0];// 开关控件本身
31
		var blockObj = obj.children[2];// 滑块
32
		// 判断是否为触屏
53 33
		var hasTouch = "ontouchstart" in window;
54 34
		var START_EVENT = hasTouch ? "touchstart" : "mousedown";
55 35
		var MOVE_EVENT = hasTouch ? "touchmove" : "mousemove";
56 36
		var END_EVENT = hasTouch ? "touchend" : "mouseup";
57 37
		var CANCEL_EVENT = hasTouch ? "touchcancel" : "mouseup";
58
		//开始移动的位置
59
		var startX=-1;
60
		//当前被操作的元素
61
		var currElement;
62
		//是否在移动
63
		var isMoving=false;
64
		//正则,用于获取translateX的数值
65
		var reg=/\-?[0-9]+/g;
66
		//移动标志,用于区分是单击,还是移动事件
67
		var moveFlag=false;
68
		//body上的鼠标结束移动回调函数
69
		var handler=function(event){
38
		
39
		var startX = -1;// 开始移动的位置
40
		var currElement;// 当前被操作的元素
41
		var isMoving = false;// 是否在移动
42
		var reg = /\-?[0-9]+/g;// 正则,用于获取translateX的数值
43
		var moveFlag = false;// 移动标志,用于区分是单击,还是移动事件
44
		// body上的鼠标结束移动回调函数
45
		var handler = function(event){
70 46
			switchEvent(event);
71 47
		}
72
		//body上的鼠标移动回调函数
73
		var moveHandler=function(event){
48
		// body上的鼠标移动回调函数
49
		var moveHandler = function(event){
74 50
			moveEvent(event);
75 51
		}
76
		//滑块上添加拖拽开始事件
52
		// 滑块上添加拖拽开始事件
77 53
		blockObj.addEventListener(START_EVENT,function(event){
78
			//如果正在移动,则忽略
54
			// 如果正在移动,则忽略
79 55
			if(!isMoving){
80
				//记录当前被单击的对象
81
				currElement=obj;
56
				// 记录当前被单击的对象
57
				currElement = obj;
82 58
				startX= getX(event);
83
				document.body.addEventListener(CANCEL_EVENT,handler,false);//使用touchcancel事件
59
				document.body.addEventListener(CANCEL_EVENT,handler,false);// 使用touchcancel事件
84 60
				document.body.addEventListener(MOVE_EVENT,moveHandler,false);
85 61
			}
86 62
		},false);
87
		//在开关控件上添加移动事件
63
		// 在开关上添加移动事件
88 64
		obj.addEventListener(MOVE_EVENT,function(event){
89 65
			moveEvent(event);
90 66
		},false);
91
		//在开关控件上添加移动结束事件
67
		// 在开关上添加移动结束事件
92 68
		obj.addEventListener(END_EVENT,function(event){
93 69
			if(currElement!=obj){
94
				if(that.enable){
70
				if(!that.disabled){
95 71
					that.setValue(!that.getValue());
96
				}else{
97
					that.changeAction(that.enable);	
72
				}
73
				if(that.clickAction){
74
					that.clickAction(that.disabled);
98 75
				}
99 76
			}
100 77
			switchEvent(event);
101 78
		},false);
102
		//在开关控件上添加移动取消事件
79
		// 在开关上添加移动取消事件
103 80
		obj.addEventListener(CANCEL_EVENT,function(event){
104 81
			switchEvent(event);
105 82
		},false);
106
		//移动事件
83
		// 移动事件
107 84
		function moveEvent(event){
108 85
			if(currElement==obj){
109
				if(that.enable){
110
					//如果进入了移动事件,刚将移动状态设置为true,区分单击事件
111
					moveFlag=true;
112
					//鼠标当前位置与起始位置的偏移量
113
					var leftX=getX(event)-startX;
114
					//如果开关为打开状态,则leftX为负数,that.distance为正数,并且不会执行下面一段逻辑
115
					//如果开关为关闭状态,则leftX为正数,that.distance为正数,执行下面一段逻辑后,得到一个绝对值较小的负数。
86
				if(!that.disabled){
87
					moveFlag = true; //设置移动状态为true,区分单击事件
88
					var leftX = getX(event)-startX; // 鼠标当前位置与起始位置的偏移量
89
					// 如果开关为打开状态,则leftX为负数,that.distance为正数,并且不会执行下面一段逻辑
90
					// 如果开关为关闭状态,则leftX为正数,that.distance为正数,得到一个绝对值较小的负数
116 91
					if(!that.getValue()){
117
						leftX=leftX-that.distance;
92
						leftX = leftX-that.distance;
118 93
					}
119
					//计算出界
94
					// 计算出界
120 95
					if(leftX>=-that.distance && leftX<=0 ){
121 96
						blockObj.style.webkitTransform = "translateX(" + leftX + "px)"
122 97
					}
123 98
				}
124 99
			}
125 100
		}
126
		//松开滑块后,自动执行动画的事件
101
		/*松开滑块自动执行动画*/
127 102
		function switchEvent(event){
128 103
			if(currElement==obj){
129
				//此方法根据currElement对象来区分是否执行。当执行了一次此方法后,在将currElement置空,表示一次流程已经走完。
130
				//也用currElement来区分是那个对象触发的事件
131
				currElement=null;
132
				if(that.enable){
104
				// 使用currElement判断事件是否执行,同时也用来获取事件源
105
				currElement = null;	//currElement置空,表示一次操作结束
106
				if(!that.disabled){
133 107
					if(moveFlag){
134
						//当执行拖拽完成后的小动画的时候,通过一个状态位,将开关控件锁定。
135
						isMoving=true;
136
						blockObj.style.webkitTransition="none";//关闭css3动画
137
						//获取到当前translateX的值
108
						isMoving = true;	//粘滞动画时锁定移动状态
109
						blockObj.style.webkitTransition="none";// 关闭css3动画
110
						// 获取到当前translateX的值
138 111
						var translateX=parseInt(blockObj.style.webkitTransform.match(reg));
139
						//判断此时滑块在哪一边
112
						// 判断此时滑块在哪一边
140 113
						if(translateX<-that.distance/2 && translateX<0){
141
							blockObj.style.webkitTransition="-webkit-transform 0.1s ease";//粘滞时长0.1秒
114
							blockObj.style.webkitTransition="-webkit-transform 0.1s ease";// 粘滞时长0.1秒
142 115
							blockObj.style.webkitTransform="translateX(-"+that.distance+"px)";
143 116
							if(that.getValue()){
144
								that.changeAction(that.enable);
145
								//console.log(that.offAction());
146
								that.offAction();
117
								that.changeAction && that.changeAction();
118
								that.offAction && that.offAction();
147 119
							}
148 120
							that.input.val(false);
149 121
						}else{
150
							blockObj.style.webkitTransition="-webkit-transform 0.1s ease";//粘滞时长0.1秒
122
							blockObj.style.webkitTransition="-webkit-transform 0.1s ease";// 粘滞时长0.1秒
151 123
							blockObj.style.webkitTransform="translateX(0px)";
152 124
							if(!that.getValue()){
153
								that.changeAction(that.enable);
154
								//console.log(that.onAction());
155
								that.onAction();
125
								that.changeAction && that.changeAction();
126
								that.onAction && that.onAction();
156 127
							}
157 128
							that.input.val(true);
158 129
						}
159 130
						setTimeout(function(){
160
							//关闭动画
161
							blockObj.style.webkitTransition="none";
162
							//当动画完成,自动解除锁定
163
							isMoving=false;
131
							blockObj.style.webkitTransition="none";// 关闭动画
132
							isMoving = false;// 动画完成时自动解除锁定
164 133
						},200);
165 134
					}else{
166
						//如果是单击事件,则转换一次开关状态
167
						that.setValue(!that.getValue());
135
						that.setValue(!that.getValue());// 单击则改变开关状态
168 136
					}
169
				}else{
170
					//如果开关被关闭,则仅执行changeAction回调方法。
171
					that.changeAction(that.enable);	
172 137
				}
173 138
				document.body.removeEventListener(END_EVENT,handler,false);
174 139
				document.body.removeEventListener(MOVE_EVENT,moveHandler,false);
175
				moveFlag=false;
140
				moveFlag = false;
176 141
			}
177 142
		}
178 143
	}
179
	WmSwitch.prototype.isEnable=function(enable){
180
		if(enable==undefined){
181
			return this.enable;
144
	/*设置开关是否可用*/
145
	WmSwitch.prototype.setDisabled = function(disabled){
146
		if(disabled==undefined){
147
			return this.disabled;
182 148
		}
183
		if(enable){
184
			this.enable=true;
185
			this.entity.removeClass("e_dis");
186
		}else{
187
			this.enable=false;
149
		
150
		if(disabled){
151
			this.disabled = true;
188 152
			this.entity.addClass("e_dis");
153
		}else{
154
			this.disabled = false;
155
			this.entity.removeClass("e_dis");
189 156
		}
190 157
	};
191
	WmSwitch.prototype.setLabel=function(label){
192
		var strs=label.split("|");
193
		this.span[0].innerHTML=strs[0];
194
		this.span[1].innerHTML=strs[1];
158
	/*设置开关文本*/
159
	WmSwitch.prototype.setLabel = function(label) {
160
		var strs = label.split("|");
161
		this.span[0].innerHTML = strs[0];
162
		this.span[1].innerHTML = strs[1];
195 163
	};
196
	WmSwitch.prototype.getLabel=function(){
197
		return this.span[0].innerHTML+"|"+this.span[1].innerHTML;
164
	/*获取开关文本*/
165
	WmSwitch.prototype.getLabel = function() {
166
		return this.span[0].innerHTML + "|" + this.span[1].innerHTML;
198 167
	};
199
	WmSwitch.prototype.setValue=function(val){
200
		if(this.getValue()!=val){
201
			if(val){
202
				if(this.onAction){
203
					this.changeAction(this.enable);
204
					//console.log(this.onAction());
205
					this.onAction();
206
				}
207
				this.span[2].style.webkitTransition="-webkit-transform 0.2s ease";//滑动时长0.1秒
208
				this.span[2].style.webkitTransform="translateX(0px)";
209
			}else{
210
				if(this.offAction){
211
					this.changeAction(this.enable);
212
					//console.log(this.offAction());
213
					this.offAction();
214
				}
215
				this.span[2].style.webkitTransition="-webkit-transform 0.2s ease";//滑动时长0.1秒
216
				this.span[2].style.webkitTransform="translateX(-"+this.distance+"px)";
168
	/*设置开关的值*/
169
	WmSwitch.prototype.setValue = function(value) {
170
		if (this.getValue() != value) {
171
			if (value) {
172
				this.onAction && this.onAction();
173
				this.changeAction && this.changeAction();
174
				this.span[2].style.webkitTransition = "-webkit-transform 0.2s ease";// 滑动时长0.1秒
175
				this.span[2].style.webkitTransform = "translateX(0px)";
176
			} else {
177
				this.offAction && this.offAction();
178
				this.changeAction && this.changeAction();
179
				this.span[2].style.webkitTransition = "-webkit-transform 0.2s ease";// 滑动时长0.1秒
180
				this.span[2].style.webkitTransform = "translateX(-" + this.distance + "px)";
217 181
			}
218
			this.input.val(val);
182
			this.input.val(value);
219 183
		}
220 184
	};
221
	WmSwitch.prototype.getValue=function(){
185
	/*获取开关的值*/
186
	WmSwitch.prototype.getValue = function(){
222 187
		return this.input.val()=="true";
223 188
	};
224
	WmSwitch.prototype.setChangeAction=function(callback){
225
		this.changeAction=callback;
226
	}
189
	/*指定开关打开事件*/
227 190
	WmSwitch.prototype.setOnAction=function(callback){
228
		this.onAction=callback;	
191
		this.onAction = callback;	
229 192
	};
193
	/*指定开关关闭事件*/
230 194
	WmSwitch.prototype.setOffAction=function(callback){
231
		this.offAction=callback;
195
		this.offAction = callback;
232 196
	};
197
	/*指定开关状态变化时的事件*/
198
	WmSwitch.prototype.setChangeAction=function(callback){
199
		this.changeAction = callback;
200
	}
233 201
	return WmSwitch;
234 202
});

+ 92 - 57
multiple-server/web/res/js/ui/wm-tab.js

@ -13,42 +13,50 @@ define(["jcl","wmWebUI"], function($,WmWebUI){
13 13
	})();
14 14
	/*WmTab对象定义*/
15 15
	function WmTab(id){
16
		this.listeners = new Array(); //存储监听事件
17 16
		/*常用对象*/
18 17
		this.tab = WmWebUI.getElement(id);
19
		this.parLabels = this.tab.find('div .title ul');
20
		this.labels = this.parLabels.find('li');
21
		this.parentPages = this.tab.find('div .pages');
22
		this.pages = this.parentPages.find('div .page');
23
		this.currIndex;
18
		this.items = new Array();//子元素
19
		this.parLabels = this.tab.children('div .title').eq(0).children("ul");
20
		this.labels = this.parLabels.children('li');
21
		this.parentPages = this.tab.children('div .pages');
22
		this.pages = this.parentPages.children('div .page');
23
		this.currIndex;//当前页面的索引
24
		this.isAnimation = true;//是否使用动画
25
		this.tabContentHeight; //标签页高度?
24 26
		
25 27
		WmWebUI.store(id,this);
26 28
	}
27
	/*刷新全局变量*/
28
	WmTab.prototype.refresh = function(){
29
		this.parLabels = this.tab.find('div .title ul');
30
		this.labels = this.parLabels.find('li');
31
		this.parentPages = this.tab.find('div .pages');
32
		this.pages = this.parentPages.find('div .page');
29
	
30
	/*标签菜单项构造方法*/
31
	var WmTabItem = function(parent,index,domElement){
32
		this.parent = parent;	//父对象
33
		this.index = index;	//菜单项序号
34
		this.domElement = domElement;	//菜单项dom元素
35
		this.action;	//菜单项点击事件
36
		if(domElement.id){
37
			WmWebUI.store(domElement.id,this);
38
		}
39
		
40
		this.parent.pages[index].style.height = this.parent.tabContentHeight; //初始化标签页高度
33 41
		
34
		$.each(this.labels, function(index, label){
35
			label.setAttribute("tab_index", index);
36
		});
37
	}
38
	this.parent.pages[index].style.height = this.parent.tabContentHeight; //*初始化标签元素*/
39
	WmTab.prototype.initPage = function (index, label){
40 42
		var that = this;
41 43
		/*绑定标签切换事件*/
42
		$(label).tap(function(idx) {
43
			that.active(idx);
44
		},index);
45
		this.pages[index].style.height = this.tabContentHeight;
46
		/*增加iScroll的效果*/
47
		/*if(this.pages[index].children[0]){
48
			new iScroll(this.pages[index]);//存在元素则增加iScroll
49
		}*/
44
		$(domElement).tap(function() {
45
			that.active();
46
		});
50 47
	}
51
	
48
	/*指定标签菜单项的点击事件*/
49
	WmTabItem.prototype.setAction = function(callback) {
50
		this.action = callback;
51
	};
52
	/*选中标签菜单项*/
53
	WmTabItem.prototype.active = function() {
54
		this.parent.active(this.index);
55
	};
56
	/*删除标签菜单项*/
57
	WmTabItem.prototype.remove = function() {
58
		this.parent.remove(this.index);
59
	};
52 60
	/*创建Tab对象*/
53 61
	WmTab.prototype.create = function(){
54 62
		var that = this;
@ -64,7 +72,7 @@ define(["jcl","wmWebUI"], function($,WmWebUI){
64 72
		this.tabContentHeight = content.offsetHeight - title.offsetHeight - 3*space + "px";
65 73
		
66 74
		$.each(this.labels, function(index, label){
67
			that.initPage(index, label);
75
			that.items.push(new WmTabItem(that, index, label));
68 76
			if("on" == label.className)
69 77
				that.currIndex = index;
70 78
		});
@ -83,6 +91,18 @@ define(["jcl","wmWebUI"], function($,WmWebUI){
83 91
			}
84 92
		});
85 93
	};
94
	/*获取标签菜单项*/
95
	WmTab.prototype.getTabItem = function(index){
96
		return this.items[index];
97
	}
98
	/*获取标签菜单项集合*/
99
	WmTab.prototype.getTabItems = function(){
100
		return this.items;
101
	}
102
	/*设置是否使用动画*/
103
	WmTab.prototype.setAnimation = function(isAnimation){
104
		this.isAnimation = isAnimation;
105
	}
86 106
	/*选中标签页*/
87 107
	WmTab.prototype.active = function(index){
88 108
		//防止传入数据异常
@ -104,36 +124,51 @@ define(["jcl","wmWebUI"], function($,WmWebUI){
104 124
			}
105 125
		});
106 126
		
107
		that = this;
127
		var that = this;
108 128
		var pages = that.tab.find(".pages .page");
109
		$.ui.css3animate(pages, {
110
			x: ((curIdx > prevIdx)?"0":"-100") + "%",
111
			y: "0%",
112
			complete:function(){
113
				$.ui.css3animate(pages, {
114
					x: ((curIdx > prevIdx)?"-100":"0") + "%",
115
					y: "0%",
116
					time: $.ui.transitionTime,
117
					complete:function(){
118
						var listener = that.listeners[index];
119
						if(listener){
120
							listener();
129
		/*判断是否使用动画*/
130
		if(this.isAnimation){
131
			$.ui.css3animate(pages, {
132
				x: ((curIdx > prevIdx)?"0":"-100") + "%",
133
				y: "0%",
134
				complete:function(){
135
					$.ui.css3animate(pages, {
136
						x: ((curIdx > prevIdx)?"-100":"0") + "%",
137
						y: "0%",
138
						time: $.ui.transitionTime,
139
						complete:function(){
140
							var wmTabItem = that.getTabItem(index);
141
							if(wmTabItem["action"]){
142
								wmTabItem.action();
143
							}
121 144
						}
122
					}
123
				});
145
					});
146
				}
147
			});
148
		}else{
149
			$(that.pages[prevIdx]).css("display","none");
150
			var wmTabItem = that.getTabItem(index);
151
			if(wmTabItem["action"]){
152
				wmTabItem.action();
124 153
			}
125
		});
154
		}
126 155
		
127 156
		$(this.labels[prevIdx]).removeClass("on");
128 157
		$(this.labels[curIdx]).addClass("on");
129 158
		this.currIndex = index;
130 159
	};
131
	/*增加点击标签的监听*/
132
	WmTab.prototype.addListener = function(index, callback) {
133
		this.listeners.splice(index, 0, callback);
134
	};
135
	/*增加Tab标签页*/
136
	WmTab.prototype.addItem = function(label,content,index){
160
	
161
	/*刷新全局变量*/
162
	WmTab.prototype.refresh = function(){
163
		this.parLabels = this.tab.children('div .title').eq(0).children("ul");
164
		this.labels = this.parLabels.children('li');
165
		this.parentPages = this.tab.children('div .pages');
166
		this.pages = this.parentPages.children('div .page');
167
		this.parentPages[0].className = this.parentPages[0].className+" pages-"+this.pages.length; 
168
	}
169
	
170
	/*添加标签页*/
171
	WmTab.prototype.add = function(label,content,index){
137 172
		if (index!=undefined && !isNaN(index)) {
138 173
			$(this.labels[index]).before('<li>' + label + '</li>');
139 174
			$(this.pages[index]).before('<div class="page">' + content + '</div>');
@ -143,21 +178,21 @@ define(["jcl","wmWebUI"], function($,WmWebUI){
143 178
			index = this.pages.length;
144 179
		}
145 180
		this.refresh();
146
		this.addListener(index,null);
147
		this.parentPages[0].className = this.parentPages[0].className+" pages-"+this.pages.length; 
148
		this.initPage(index,this.labels[index]);
181
		
182
		var item = new WmTabItem(this,index,this.labels[index]);
183
		this.items.push(item);
184
		return item;
149 185
	};
150 186
	/*删除标签页*/
151
	WmTab.prototype.removeItem = function(index){
187
	WmTab.prototype.remove = function(index){
152 188
		if(!this.labels[index]){
153 189
			throw "WmTab组件越界";
154 190
		}
155
		
156 191
		$(this.labels[index]).remove();
157 192
		$(this.pages[index]).remove();
158
		refresh();
159
		this.listeners.splice(index,1);
193
		this.refresh();
160 194
	};
195
	
161 196
	/*获取标签页的数量*/
162 197
	WmTab.prototype.length = function(){
163 198
		return this.labels.length;

+ 70 - 39
multiple-server/web/res/js/ui/wm-tabbar.js

@ -1,30 +1,44 @@
1 1
define(["jcl","iScroll","wmWebUI"],function($,iScroll,WmWebUI){
2
	/*标签菜单构造方法*/
2 3
	var WmTabbar = function(id){
3 4
		/*常用对象*/
4
		this.listeners = new Array(); //存储监听事件
5
		this.tabbar = (function(obj){
6
			if(typeof(obj)=="object"){
7
				obj = $(obj);
8
			}else if(typeof(obj)=="string"){
9
				obj = $("#"+obj);
10
			}else{
11
				throw "没有匹配类型";
12
			}
13
			return obj;
14
		})(id);
5
		this.tabbar = WmWebUI.getElement(id);
15 6
	
16
		this.navs = this.tabbar.find(".m_nav .wrapper .nav ");
17
		this.footers = this.tabbar.find("div[class=m_footer] li");
7
		//this.navs = this.tabbar.find(".m_nav > .wrapper .nav ");
8
		//this.footers = this.tabbar.find("div[class=m_footer] li");
9
		//使用children会更加严谨
10
		this.navs = this.tabbar.children(".m_nav").eq(0).children(".wrapper").eq(0).children(".nav");
11
		this.footers = this.tabbar.children(".m_footer").eq(0).children("ul").eq(0).children("li");
12
		this.items = new Array();//子元素
18 13
		this.currIndex;//当前页面的索引
14
		this.isAnimation = true;//是否使用动画
19 15
		
20 16
		WmWebUI.store(id,this);
21 17
	}
18
	/*标签菜单项构造方法*/
19
	var WmTabbarItem = function(parent,index,domElement){
20
		this.parent = parent;	//父对象
21
		this.index = index;	//菜单项序号
22
		this.domElement = domElement;	//菜单项dom元素
23
		this.action;	//菜单项点击事件
24
		if(domElement.id){
25
			WmWebUI.store(domElement.id,this);
26
		}
27
	}
28
	/*指定标签菜单项的点击事件*/
29
	WmTabbarItem.prototype.setAction = function(callback) {
30
		this.action = callback;
31
	};
32
	/*选中标签菜单项*/
33
	WmTabbarItem.prototype.active = function() {
34
		this.parent.active(this.index);
35
	};
22 36
	
23 37
	WmTabbar.prototype.create = function(){
24
		that = this;
25
		/*底部菜单绑定索引*/
38
		var that = this;
39
		/*构建底部菜单对象*/
26 40
		this.footers.each(function(index){
27
			$(this).attr("tabbar_index", index);
41
			that.items.push(new WmTabbarItem(that,index,this));
28 42
			if("on" == this.className)
29 43
				that.currIndex = index;
30 44
		});
@ -52,12 +66,24 @@ define(["jcl","iScroll","wmWebUI"],function($,iScroll,WmWebUI){
52 66
		});
53 67
	}
54 68
	
55
	/*选中标签页*/
69
	/*获取标签菜单项*/
70
	WmTabbar.prototype.getTabbarItem = function(index){
71
		return this.items[index];
72
	}
73
	/*获取标签菜单项集合*/
74
	WmTabbar.prototype.getTabbarItems = function(){
75
		return this.items;
76
	}
77
	/*设置是否使用动画*/
78
	WmTabbar.prototype.setAnimation = function(isAnimation){
79
		this.isAnimation = isAnimation;
80
	}
81
	/*选中标签菜单页*/
56 82
	WmTabbar.prototype.active = function(index){
57 83
		if(!this.navs[index]){
58 84
			throw "WmTabbar组件越界";//错误信息如何处理
59 85
		}
60
		that = this;
86
		var that = this;
61 87
		/*获取当前和先前的页面索引*/
62 88
		var curIdx = index;
63 89
		var prevIdx = that.currIndex;
@ -70,34 +96,39 @@ define(["jcl","iScroll","wmWebUI"],function($,iScroll,WmWebUI){
70 96
				$(this).css("display","");
71 97
		});
72 98

73
		var wrapper = that.tabbar.find(".m_nav > .wrapper");
74
		$.ui.css3animate(wrapper, {
75
			x: ((curIdx > prevIdx)?"0":"-50") + "%",
76
			y: "0%",
77
			complete:function(){
78
				$.ui.css3animate(wrapper, {
79
					x: ((curIdx > prevIdx)?"-50":"0") + "%",
80
					y: "0%",
81
					time: $.ui.transitionTime,
82
					complete:function(){
83
						var listener = that.listeners[index];
84
						if(listener){
85
							listener();
99
		/*判断是否使用动画*/
100
		if(this.isAnimation){
101
			var wrapper = that.tabbar.find(".m_nav > .wrapper");
102
			$.ui.css3animate(wrapper, {
103
				x: ((curIdx > prevIdx)?"0":"-50") + "%",
104
				y: "0%",
105
				complete:function(){
106
					$.ui.css3animate(wrapper, {
107
						x: ((curIdx > prevIdx)?"-50":"0") + "%",
108
						y: "0%",
109
						time: $.ui.transitionTime,
110
						complete:function(){
111
							var wmTabbarItem = that.getTabbarItem(index);
112
							if(wmTabbarItem["action"]){
113
								wmTabbarItem.action();
114
							}
86 115
						}
87
					}
88
				});
116
					});
117
				}
118
			});
119
		}else{
120
			$(that.navs[prevIdx]).css("display","none");
121
			var wmTabbarItem = that.getTabbarItem(index);
122
			if(wmTabbarItem["action"]){
123
				wmTabbarItem.action();
89 124
			}
90
		});
125
		}
126
		
91 127
		$(that.footers[prevIdx]).removeClass("on");
92 128
		$(that.footers[curIdx]).addClass("on");
93 129
		
94 130
		that.currIndex = curIdx;
95 131
	};
96 132
	
97
	/*增加点击标签的监听*/
98
	WmTabbar.prototype.addListener = function(index, callback) {
99
		this.listeners.splice(index, 0, callback);
100
	};
101
	
102 133
	return WmTabbar;
103 134
});

+ 1 - 1
multiple-server/web/template/common/Head.html

@ -5,7 +5,7 @@
5 5
<!--注:由于html页面会被加密,不能使用双斜杠作为注释符号-->
6 6
<script language="javascript">
7 7
/*自定义增加每个页面需要执行的公共逻辑*/
8
require(["domReady!","mobile","jcl","tap"],function(doc, Mobile, S) {
8
require(["domReady!","mobile","jcl","tap"],function(doc, Mobile, $) {
9 9
	/*每个页面的back样式都需要执行回退*/
10 10
	$(".c_navBar").find(".back").tap(function(){
11 11
		Mobile.back();