Ver Código Fonte

增加wmWebUI.initTags方法

huangbo 10 anos atrás
pai
commit
65db1c8b06
1 arquivos alterados com 61 adições e 15 exclusões
  1. 61 15
      display-server/web/res/js/ui/wm-webui.js

+ 61 - 15
display-server/web/res/js/ui/wm-webui.js

@ -1,26 +1,72 @@
1
define(["jcl","tap","wmUI","wmBase","wmAnimate"], function($){
2
	//一个页面只会加载一次
3
	var wmWebUI  = {};
1
define([ "jcl", "tap", "wmUI", "wmBase", "wmAnimate" ], function($) {
2
	// 一个页面只会加载一次
3
	var wmWebUI = {};
4 4
	wmWebUI.tags = {}
5
	
6
	wmWebUI.store = function(id,tag){
5

6
	wmWebUI.store = function(id, tag) {
7 7
		wmWebUI.tags[id] = tag;
8 8
	}
9
	
10
	wmWebUI.select = function(id){
11
		return wmWebUI.tags[id];
9

10
	/* 标签需要初始化时候执行 */
11
	wmWebUI.initTags = function(ids, initFunction) {
12
		var count = 0;// 尝试次数
13
		var bo;// 尝试10次的状态
14
		var intervalId;
15
		var tempFunc = function() {
16
			count++;// 计数器加1
17
			if (count > 10) {
18
				bo = true;// 尝试10次后返回结果
19
			}
20
			console.log("尝试次数:" + count);
21
			var tags = new Array();
22
			for ( var index in ids) {
23
				if (wmWebUI.tags[ids[index]] || bo) {
24
					tags.push(wmWebUI.tags[ids[index]]);
25
				} else {
26
					return;
27
				}
28
			}
29
			window.clearInterval(intervalId);// 获取成功以后停止尝试
30
			initFunction.apply(null, tags);
31
		}
32
		tempFunc();// 不延迟即尝试
33
		intervalId = setInterval(tempFunc, 20);// 20毫秒每次
34
	}
35
	/* 根据id查询自定义标签对象 */
36
	wmWebUI.select = function(id) {
37
		var tag = $("#" + id);
38
		if (tag.length == 0 && wmWebUI.tags[id])
39
			return wmWebUI.tags[id];
12 40
	}
13
	
14
	wmWebUI.getElement = function(obj){
15
		if(typeof(obj)=="object"){
41

42
	/* 公共方法:根据id或者元素查询zepto对象 */
43
	wmWebUI.getElement = function(obj) {
44
		if (typeof (obj) == "object") {
16 45
			obj = $(obj);
17
		}else if(typeof(obj)=="string"){
18
			obj = $("#"+obj);
19
		}else{
46
		} else if (typeof (obj) == "string") {
47
			obj = $("#" + obj);
48
		} else {
20 49
			throw "没有匹配类型";
21 50
		}
22 51
		return obj;
23 52
	}
24
	
53

25 54
	return wmWebUI;
26 55
});
56

57
/*
58
initTags方法测试代码
59
require(["wmTabbar"], function(WmTabbar) {
60
	setTimeout(function(){
61
		var wmTabbar = new WmTabbar("tabbar1");
62
		wmTabbar.create();
63
	},100);
64
});
65
require(["wmWebUI"], function(WmWebUI) {
66
	console.log(WmWebUI.select("tabbar1"))
67
	WmWebUI.initTags(["tabbar1","aaaa"],function(tabbar1,aaa){
68
		console.log(tabbar1);
69
		console.log(aaa);
70
	});
71
});
72
*/