tools
程序员文章站
2022-06-24 17:02:07
...
#coffeescript
isIE = /msie/i.test(navigator.userAgent)
traverseChildren = (elem)->
pushAll = (elemArray) ->
q.push item for item in elemArray
children = [];
q = [];
q.push(elem);
while q.length > 0
elem = q.pop();
children.push(elem);
pushAll(elem.children);
return children;
mouseoutEvent = (event,dom,callback)->
elem = event.toElement || event.relatedTarget
list = traverseChildren(dom)
if elem in list
return;
callback()
return
appendEvent = (dom, event, fun) ->
if isIE
dom.attachEvent("on" + event, fun)
else
dom.addEventListener(event, fun, false)
return
hasClass = (ele,cls)->
if not ele
return
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'))
addClass = (ele,cls)->
if not ele
return
if not hasClass(ele,cls) then ele.className += " "+cls
return
removeClass = (ele,cls)->
if not ele
return
if hasClass(ele,cls)
reg = new RegExp('(\\s|^)'+cls+'(\\s|$)')
ele.className=ele.className.replace(reg,' ')
return
getDomIndex = (e)->
i=0
while e.previousSibling
e=e.previousSibling
if(e.nodeType is 1)
i=i+1
return i
jsonp = (url)->
_href = window.location.href
if _href.indexOf('https://') is 0
url = url.replace('http://','https://')
methodName = 'jsonp' + Math.random().toString(36).substring(2)
data = null
callbackChain=[]
window[methodName] = (callbackData)->
data=callbackData
for m in callbackChain
m(data)
return
url=url.replace('callback=?','callback='+methodName)
script = document.createElement( 'script' )
script.setAttribute( 'src', url )
script.setAttribute( 'charset', "utf-8" )
document.getElementsByTagName( 'head' )[0].appendChild(script)
return {
done:(fun)->
if(data)
fun(data)
callbackChain.push(fun)
return
}
window.isIE = isIE
window.traverseChildren = traverseChildren
window.mouseoutEvent = mouseoutEvent
window.appendEvent = appendEvent
window.hasClass = hasClass
window.addClass = addClass
window.removeClass = removeClass
window.getDomIndex = getDomIndex
window.jsonp = jsonp
上一篇: golang 错误处理
推荐阅读
-
Eclipse怎么在线配置Hibernate Tools?
-
安装Daemon Tools重启导致蓝屏是什么情况如何解决
-
DAEMON Tools加载错误或无法载入镜像文件
-
彻底删除Daemon tools虚拟光驱不想让其留在电脑上
-
MySQL图形工具 MySQL GUI Tools的安装使用方法
-
pycharm配置pyqt5-tools开发环境的方法步骤
-
MySQL图形工具 MySQL GUI Tools的安装使用方法
-
虚拟机中的Linux安装VMware Tools的方法
-
虚拟机VMware中安装VMware Tools for Linux的方法(Fedora16)
-
在VMware中为Linux系统安装vmware tools的详解教程