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
;
}
}
);
查看全文
相关阅读:
[开源] FreeSql.AdminLTE 功能升级
[开源] .NETCore websocket 即时通讯组件---ImCore
[开源] FreeSql 配套工具,基于 Razor 模板实现最高兼容的生成器
Redis 基础数据结构
Keepalived 原理与实战
反向代理与负载均衡
Nginx 安装与配置
CentOS 7.x编写开机启动服务
Mac 软件包管理器Homebrew使用指北
Springboot 关于日期时间格式化处理方式总结
原文地址:https://www.cnblogs.com/afxcn/p/1089572.html
最新文章
【.net core】电商平台升级之微服务架构应用实战(core-grpc)
Asp.Net Core 中IdentityServer4 授权中心之应用实战
Asp.Net Core EndPoint 终结点路由工作原理解读
遵守这些原则让你开发效率提高一倍
.net core HttpClient 使用之消息管道解析(二)
一文解读C# 动态拦截第三方进程中的方法函数(外挂必备)
.net core HttpClient 使用之掉坑解析(一)
Asp.Net Core Authorize你不知道的那些事(源码解读)
Asp.Net Core 中IdentityServer4 实战之 Claim详解
Asp.Net Core 中IdentityServer4 授权原理及刷新Token的应用
热门文章
Overt.GrpcTemplate.Service 模板使用教程
Asp.Net Core 中IdentityServer4 授权中心之自定义授权模式
[开源] .Net orm FreeSql 1.5.0 最新版本(番号:好久不见)
.NET ORM 开源项目 FreeSql 1.0 正式版发布
FreeSql 新手上路系列教程已发布在 cnblogs
【推荐】.NETCore 简单且高级的库 csredis v3.0.0
.NETCore 访问国产达梦数据库
FreeSql v0.11 几个实用功能说明
FreeSql 已支持 .NetFramework 4.0、ODBC 访问
FreeSql 导航属性的联级保存功能
Copyright © 2011-2022 走看看