VCEventHandle_wev8.js
2.98 KB
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
/*
* VCEventHandle.js Version:1.1
* 本插件提供对流程HTML模式下用户绑定onpropertychange事件的支持,支持所有浏览器。
* 事件执行机制与原生类似。在非IE下,事件触发可能会存在延迟(最大为500毫秒),IE下使用的是远程事件机制。
* <font color="red">注意:本插件仅供流程HTML模式调用,不提供对其他功能的支持, 请不要将此插件修改为全局插件</font>
* Made by CC Tsai
* Last update time : 2015-04-23
*/
var __bindPropertyChangefn = {};
var __bindPropertyChangefnArray = {};
var __propertyEleValMap = new Map();
(function ($) {
$.fn.bindPropertyChange = function (funobj) {
return this.each(function () {
var $this = $(this);
//获取元素id,或者name
var thisid = $this.attr('id');
//支持对单个元素多次绑定start
var __pcfarray = __bindPropertyChangefnArray[thisid];
if (!!!__pcfarray) {
__pcfarray = new Array();
__bindPropertyChangefnArray[thisid] = __pcfarray;
}
__pcfarray.push(funobj);
//支持对单个元素多次绑定end
//test
var isIE = false;
try {
isIE = $.client.browser == 'Explorer' ? true : false;
} catch (e) {
}
if (isIE) {
//保存原值
__propertyEleValMap.put(thisid, $this.val());
//保存事件
/*
__bindPropertyChangefn[thisid] = function (target) {
var __newVal4e = jQuery(target).val();
var __oldVal4e = __propertyEleValMap.get(thisid);
if (__newVal4e != __oldVal4e) {
__propertyEleValMap.put(thisid, __newVal4e);
funobj(target);
}
};
*/
//保存事件
__bindPropertyChangefn[thisid] = function (target) {
var __newVal4e = jQuery(target).val();
var __oldVal4e = __propertyEleValMap.get(thisid);
if (__newVal4e != __oldVal4e) {
__propertyEleValMap.put(thisid, __newVal4e);
var __vcfnarray = __bindPropertyChangefnArray[thisid];
for (var i97=0; i97<__vcfnarray.length; i97++) {
try {
__vcfnarray[i97](target);
} catch (__e97) {}
}
}
};
} else {
//__bindPropertyChangefn[thisid] = funobj;
__bindPropertyChangefn[thisid] = function (target) {
var __vcfnarray = __bindPropertyChangefnArray[thisid];
for (var i97=0; i97<__vcfnarray.length; i97++) {
try {
__vcfnarray[i97](target);
} catch (__e97) {}
}
};
}
//调用事件方法,并把当前对象作为参数传递过去
var crtpcstr = '__bindPropertyChangefn[\'' + thisid + '\'](document.getElementById(\'' + thisid + '\'))';
var pcstr = '';
var attrname = '';
if (isIE) {
attrname = 'onpropertychange';
} else {
attrname = '_listener';
}
pcstr = this.getAttribute(attrname);
if (!!!pcstr) pcstr = '';
if (pcstr.indexOf(crtpcstr) == -1) {
if (pcstr === '') {
pcstr = crtpcstr;
} else {
pcstr += ';' + crtpcstr;
}
this.setAttribute(attrname, pcstr);
}
if (!isIE) {
loadListener();
}
});
};
})(jQuery);