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
;
}
}
);
查看全文
相关阅读:
Jrain'Lのvueblog
前端知识整理 の IMWeb
js编程小练习1
mac版本cornerstone的无限期破解方法(转)
教你解锁被锁住的苹果mac电脑的文件跟文件夹,同时也可删除被锁的文件跟文件夹(转)
Mac下配置svn服务器
ios 查看模拟器路径以及应用的文件夹
python怎么解压压缩的字符串数据
python全局变量被覆盖的问题
PyInstaller:把你的Python转为Exe
原文地址:https://www.cnblogs.com/afxcn/p/1089572.html
最新文章
poj1703 Find them, Catch them
poj3263 Tallest Cow
poj2269 Friends
【数位DP】HDU 6156 Palindrome Function
【kmp或扩展kmp】HDU 6153 A Secret
【扩展kmp+最小循环节】HDU 4333 Revolving Digits
【kmp+求所有公共前后缀长度】poj 2752 Seek the Name, Seek the Fame
【kmp+最小循环节】poj 2406 Power Strings
【数位DP】HDU 2089 不要62
【字符串】BNUOJ 52781 Book Borders
热门文章
【极角排序+双指针线性扫】2017多校训练七 HDU 6127 Hard challenge
【(好题)组合数+Lucas定理+公式递推(lowbit+滚动数组)+打表找规律】2017多校训练七 HDU 6129 Just do it
【组合数+Lucas定理模板】HDU 3037 Saving
webAPP阅读器实现
JavaScript正则表达式知识点整理
Javascript Garden
js编程小练习2 の 牛客
JavaScript知识点小记2
JavaScript知识点小记1
JavaScript单线程
Copyright © 2011-2022 走看看