浏览代码

1.tap.js。我还原了:使用
apply而没有使用call。因为依赖event来定位元素这样是不合适的。元素结构可能会发生变化,应该尽量通过最小粒度的方法来完成想要完成的事情。
2.上面的修改首先引起wm-tooltip.js的异常,点任何关闭按钮都是关闭最后一个气泡。原因是closeAction函数里面使用了一个全局对象,这个是不正确的,合适的做法,是将当前对象传入进去,然后执行hide()方法(或者传入this.tip,然后执行remove对应class的动作,但是这样hide函数没有复用,不是最好的选择)。

huangbo 10 年之前
父节点
当前提交
3310c939c0
共有 1 个文件被更改,包括 15 次插入20 次删除
  1. 15 20
      display-server/web/res/js/ui/wm-tooltip.js

+ 15 - 20
display-server/web/res/js/ui/wm-tooltip.js

@ -1,28 +1,18 @@
1 1
/*引入util对应的js文件*/
2 2

3
define(['util'], function(){
3
define(["jcl","wmWebUI"], function($,WmWebUI){
4 4
	/*WmToolTip对象定义*/
5
	function WmToolTip(id){
5
	var WmToolTip = function(id){
6 6
		this.listeners = new Array(); //存储监听事件
7 7
		this.id = id;
8 8
		/*常用对象*/
9
		this.tip = (function(obj){
10
			if(typeof(obj)=="object"){
11
				obj = $(obj);
12
			}else if(typeof(obj)=="string"){
13
				obj = $("#"+obj);
14
			}else{
15
				alert("没有匹配类型");
16
				return null;
17
			}
18
			return obj;
19
		})(id);
9
		this.tip = WmWebUI.getElement(id);
20 10
		this.baseSize = parseInt($(document.getElementsByTagName("html")[0]).css("font-size"));
21 11
	}
22 12
	/*关闭按钮事件*/
23 13
	WmToolTip.prototype.setCloseAction = function(action){
24
		var closeAction = function(e){
25
			$($(e.target).parents("div.c_toolTip-view")[0]).removeClass("c_toolTip-view");
14
		var closeAction = function(that){
15
			that.hide();
26 16
			if(action){
27 17
				if(typeof action =="function"){
28 18
					action();
@ -32,7 +22,7 @@ define(['util'], function(){
32 22
			}
33 23
		};
34 24
		var btn = this.tip.find("span.e_button");
35
		$(btn[0]).tap(closeAction);
25
		$(btn[0]).tap(closeAction,this);
36 26
	};
37 27
	/*设置位置参照元素*/
38 28
	WmToolTip.prototype.setBaseElement = function(ele){
@ -91,16 +81,21 @@ define(['util'], function(){
91 81
	};
92 82
	/*设置图标*/
93 83
	WmToolTip.prototype.setIcon = function(icon){
94
		var e = this.tip.find('div.ico');
95
		if(e.length){
96
			$(e[0]).html('<span class="e_ico '+icon+'"></span>');
84
		var elem = this.tip.find('div.ico');
85
		if(elem.length){
86
			$(elem[0]).html('<span class="e_ico '+icon+'"></span>');
97 87
		}else{
98 88
			$(this.tip.find("div.content")[0]).prepend('<div class="ico"><span class="e_ico '+icon+'"></span></div>');
99 89
		}
100 90
	};
101 91
	/*设置提示内容*/
102 92
	WmToolTip.prototype.setContent = function(text){
103
		$(this.tip.find("div.detail")[0]).text(text);
93
		var elem = this.tip.find("div.detail");
94
		if(elem.length){
95
			$(elem[0]).text(text);
96
		}else{
97
			$(this.tip.find("div.content")[0]).prepend('<div class="detail">'+text+'</div>');
98
		}
104 99
	};
105 100
	/*导出WmToolTip*/
106 101
	return WmToolTip;