zoukankan
html css js c++ java
一段自以为写得不错的JS代码
//
expand event:
//
mouseClick plus/minus
//
rowSelected row
ctit.treeNode
=
Class.create(
{
initialize:
function
(element, options)
{
this
.element
=
$(element);
this
.options
=
options;
this
.eventMouseClick
=
this
.options.mouseClick.bindAsEventListener(
this
);
this
.eventRowSelected
=
this
.rowSelected.bindAsEventListener(
this
);
this
._onRequest
=
false
;
Event.observe(
this
.element,
"
click
"
,
this
.eventMouseClick);
Event.observe(
this
.options.row,
"
dblclick
"
,
this
.eventMouseClick);
Event.observe(
this
.options.row,
"
click
"
,
this
.eventRowSelected);
}
,
destroy:
function
()
{
Event.stopObserving(
this
.element,
"
click
"
,
this
.eventMouseClick);
Event.stopObserving(
this
.options.row,
"
dblclick
"
,
this
.eventMouseClick);
Event.stopObserving(
this
.options.row,
"
click
"
,
this
.eventRowSelected);
}
,
rowSelected:
function
(event)
{
var
cs
=
this
.options.table.getElementsByClassName(
this
.options.currentSelectedClass);
for
(
var
i
=
0
; i
<
cs.length; i
++
)
{
Element.removeClassName(cs[i],
this
.options.currentSelectedClass);
cs[i].style.backgroundColor
=
'
#fff
'
;
}
var
tds
=
this
.options.row.cells;
for
(
var
i
=
0
; i
<
tds.length; i
++
)
{
Element.addClassName(tds[i],
this
.options.currentSelectedClass);
tds[i].style.backgroundColor
=
'
#d7e2e8
'
;
}
}
,
ajaxRequest:
function
(url, param, onSuccessCallback)
{
if
(
!
this
._beginRequest())
{
return
;
}
if
(
this
._changePlusMinusIcon())
{
param.ajax
=
true
;
pThis
=
this
;
new
Ajax.Request(url,
{
method:
'
post
'
,
postBody: $H(param).toQueryString(),
onSuccess:
function
(o)
{
if
(
typeof
(onSuccessCallback)
===
'
function
'
)
{
var
ls
=
o.responseText.evalJSON();
onSuccessCallback(ls, pThis.options.tBody, pThis.options.row);
}
}
,
onFailure:
function
(o)
{
alert(
"
Connect to server failure.
"
);
}
,
onComplete:
function
(o)
{
pThis._endRequest();
}
,
evalScripts:
false
}
);
}
else
{
this
._endRequest();
}
}
,
_changePlusMinusIcon:
function
()
{
var
imgs
=
this
.element.getElementsByTagName(
'
img
'
);
if
(
!
imgs)
return
false
;
if
(imgs[
0
].src.indexOf(
'
inactive_img.gif
'
)
>
0
)
{
var
src
=
imgs[
0
].src.replace(
/
\binactive_img.gif\b
/
,
'
active_img.gif
'
);
imgs[
0
].src
=
src;
imgs[
0
].alt
=
'
Open
'
;
this
._removeItWithChildren();
return
false
;
}
else
{
var
src
=
imgs[
0
].src.replace(
/
\bactive_img.gif\b
/
,
'
inactive_img.gif
'
);
imgs[
0
].src
=
src;
imgs[
0
].alt
=
'
Close
'
;
return
true
;
}
}
,
_beginRequest:
function
()
{
if
(
this
._onRequest)
return
false
;
this
._onRequest
=
true
;
return
true
;
}
,
_endRequest:
function
()
{
this
._onRequest
=
false
;
}
,
_removeItWithChildren:
function
()
{
var
row
=
this
.options.row;
var
level
=
this
._getLevel(row);
var
tBody
=
this
.options.tBody;
var
i
=
0
;
while
(
true
)
{
var
nextRow
=
row.nextSibling;
if
(isNull(nextRow))
break
;
var
pLevel
=
this
._getLevel(nextRow);
if
(pLevel
>
level)
{
tBody.removeChild(nextRow);
}
else
{
break
;
}
}
}
,
_getLevel:
function
(row)
{
if
(
!
isNull(row))
{
var
o
=
row.cells[
this
.options.treeNodeIndex];
if
(o)
{
var
mtch
=
o.className.match(
/
\bcontent_indent([0-9]+)\b
/
);
if
(mtch
&&
mtch[
1
])
{
return
parseInt(mtch[
1
]);
}
}
}
return
0
;
}
}
);
查看全文
相关阅读:
解决安装python3后yum不能使用情况
一文教您如何通过 Docker 快速搭建各种测试环境(Mysql, Redis, Elasticsearch, MongoDB
nginx 的基本配置与虚拟主机配置
/etc/nginx/nginx.conf配置文件详解
简单使用ab命令压力测试
死锁和死锁检测
centos7下搭建消息中间件--RocketMQ
Centos7.2配置https
Mysql 通过binlog日志恢复数据
MySQL主从复制+备份
原文地址:https://www.cnblogs.com/afxcn/p/1089572.html
最新文章
封装 用canvas绘制直线的函数--面向对象
普通函数和构造函数的区别
算法中交换两个数据
js--找字符串中出现最多的字符
CSS3——3D翻转相册
CSS3——3D旋转图(跑马灯效果图)
javascript中BOM部分基础知识总结
javascript中DOM部分基础知识总结
jQuery基础知识总结
js中兼容性问题的封装(能力检测)
热门文章
[Lua快速了解一下]Lua的控制语句
[Lua快速了解一下]Lua的语法
[Lua快速了解一下]Lua运行
[LintCode笔记了解一下]39.恢复旋转排序数组
[算法基础]Big O Notation时间复杂度计算方法
c++基础之向量Vector
c++基础之struct
c++基础之引用reference
c++数组和指针
c++基本
Copyright © 2011-2022 走看看