function $() { var elements = new Array(); for (var i = 0; i < arguments.length; i++) { var element = arguments[i]; if (typeof element == 'string') element = document.getElementById(element); if (arguments.length == 1) return element; elements.push(element); } return elements; } var emptyCol="",overCol="#f1f1f1",checkedCol="#F4FFF4"; function getAbsoluteLeft( ob ){ if(!ob){return null;} var obj = ob; var objLeft = obj .offsetLeft; while( obj != null && obj .offsetParent != null && obj .offsetParent.tagName != "BODY" ){ objLeft += obj .offsetParent.offsetLeft; obj = obj .offsetParent; } return objLeft ; } // 获得绝对的顶部位置 function getAbsoluteTop( ob ){ if(!ob){return null;} var obj = ob; var objTop = obj .offsetTop; while( obj != null && obj .offsetParent != null && obj .offsetParent.tagName != "BODY" ){ objTop += obj .offsetParent.offsetTop; obj = obj .offsetParent; } return objTop ; } String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, "");} function isExist(child,obj){ //对象具有的子元素 for(var i=0;i<obj.elements.length;i++){ if(obj.elements[i].tagName.toLowerCase()=="input" && obj.elements[i].type=="checkbox"){ //alert(obj.elements[i].value.trim() +" | "+ child.trim()); if(obj.elements[i].value.trim() == child.trim() )return true; } } return false; } function countLength(obj){ if(obj==null)return; var dLen = 0,sLen = 0; for(i=0; i< obj.length; i++ ){ if(obj.charCodeAt(i) > "0" && obj.charCodeAt(i) < "128") sLen+=1; else dLen+=2; } totalLen = sLen+dLen; return totalLen; } var strAll=unescape("%u5168%u9009"); var canAll=unescape("%u53D6%u6D88"); function addSite(obj){ var oForm = null; oForm = document.getElementsByTagName("form")[0]; oForm.onsubmit = function(){ return false; }; var url=obj.url.value.trim(); if(url.match(/^\s*$/g) ){alert("请输入新备忘!");obj.url.focus();return;} var list=document.getElementById("list"); var chkbox=document.createElement("input"); chkbox.type="checkbox"; chkbox.onclick=function(){clickchk(obj);} chkbox.value=url; chkbox.name="url_chkbox"; var hr=document.createElement("hr"); hr.size="0";hr.style.borderTop="1px solid gray"; var txt=document.createTextNode(url); var div=document.createElement("div"); div.appendChild(chkbox); div.appendChild(txt); div.style.borderBottom="1px dashed gray"; div.style.padding="10px"; div.onmouseover=function(){ showDelete(this); } div.onmouseout=function(){ hideDelete(this); } //开始添加元素; list.appendChild(div); //结束添加元素; return false; } function del(list,obj){ //删除list的内容 var candel=false; var i=list.childNodes.length; var end = -1; while( i > end ){ //如果存在child var s=list.childNodes[i]; if(typeof(s)!="undefined" && s.tagName){ try{ //如果child的类型不为空; var tgname = s.tagName.toUpperCase(); if(tgname != "DIV" || s.childNodes.length <=0 )return; //子集是div且还有子集 var s1 = s.childNodes[0]; if( s1.type.toLowerCase() =="checkbox" && s1.checked==true ){ //如果该子集里的checkbox选中,那么删除改子集(div); candel = true; list.removeChild(s); } }catch(ex){ } } i--; } isDisabledButton(); } function isDisabledButton(){ var objform=document.sitelist; var list=$("list"); var hasDivChild = false; if(list.childNodes.length>0 ){ for(var i=0;i<list.childNodes.length;i++){ var s=list.childNodes[i]; if( typeof(s)!="undefined" && s.tagName) { if(s.tagName.toUpperCase()=="DIV") hasDivChild = true; } } } objform.check.disabled= hasDivChild?false:true; objform.recheck.disabled= hasDivChild?false:true; objform.check.value=strAll; objform.remove.disabled= hasDivChild?false:true; } function delSingle(objparent,objdel,objchild){ objparent.removeChild(objchild); objdel.style.display="none"; // isDisabledButton(); } function editSingle(objparent,objedit,objchild){ function makeLink(text , tag){ var temobj = document.createElement(tag); temobj.style.marginLeft="5px"; temobj.style.marginRight="5px"; temobj.style.textDecoration="underline";temobj.style.cursor="pointer"; temobj.appendChild( document.createTextNode(text) ); return temobj; } try{ var secondChild = objchild.childNodes[1]; var url = secondChild; var urlStr = url.nodeValue ;//? url.nodeValue : url.toString() ; if(urlStr==null || urlStr.trim=="")return; var editorPanel = document.createElement("span"); objchild.removeChild(url); var editor = document.createElement("input"); editor.type="text"; var maxLen = 50; var thisLen = parseInt( countLength(urlStr) ); editor.size = maxLen > thisLen ? thisLen : maxLen; editor.value = urlStr; editor.select(); editor.onmouseover=function(){this.select();} var update = makeLink("更新","font");update.title="更新"; update.onclick=function(){ var newvalue = editor.value; objchild.childNodes[0].value = newvalue; objchild.removeChild(objchild.childNodes[1]); objchild.appendChild(document.createTextNode(newvalue)); } var cancle = makeLink("取消","font");cancle.title="取消"; cancle.onclick=function(){ objchild.removeChild(objchild.childNodes[1]); objchild.appendChild(url); } //添加到编辑面板; editorPanel.style.fontSize="13px"; editorPanel.style.color="blue"; editorPanel.style.textDecoration="none"; editorPanel.appendChild(editor); editorPanel.appendChild(update); editorPanel.appendChild(document.createTextNode("|")); editorPanel.appendChild(cancle); //添加对象的子元素; objchild.appendChild(editorPanel); }catch(ex){ alert(ex.toString()); }finally{ // } } var currentDiv; function showDelete(self){ self.style.backgroundColor = overCol; currentDiv = self; var theid = "del_icon"; if(!$(theid)){ var delDiv=document.createElement("div"); delDiv.id=theid; var d=delDiv; d.style.textAlign="center";d.style.fontSize="13px"; var edit = document.createElement("span"); edit.title="修改备忘";edit.style.textDecoration="none"; edit.onclick=function(){ editSingle(currentDiv.parentNode,this.parentNode,currentDiv); } var clock = document.createElement("span"); clock.title="设置闹钟定时提醒";clock.style.textDecoration="none"; clock.onclick=function(){ clockSingle(currentDiv.parentNode,this.parentNode,currentDiv); } var del = document.createElement("span"); del.title="删除此备忘";del.style.textDecoration="none"; del.onclick=function(){ delSingle(currentDiv.parentNode,this.parentNode,currentDiv); } edit.appendChild(document.createTextNode("修改")); d.appendChild(edit); d.appendChild(document.createTextNode(" | ")); clock.appendChild(document.createTextNode("闹钟")); d.appendChild(clock); d.appendChild(document.createTextNode(" | ")); del.appendChild(document.createTextNode("删除")); d.appendChild(del); d.style.width="180px"; d.style.lineHeight="30px"; d.style.color="blue"; document.body.appendChild(d); $(theid).onmouseover=function(){ currentDiv.style.backgroundColor = overCol; this.style.display=""; } // $(theid).style.cursor="pointer"; } if($(theid)){ $(theid).style.display=""; var l= getAbsoluteLeft(self) + self.offsetWidth - 150; var t= getAbsoluteTop(self) + 5; var scrollT = self.parentNode.scrollTop;//减去出现滚动条的高度; var t= getAbsoluteTop(self) + 5 - scrollT; getAbsoluteTop(self) +"|"+ self.offsetWidth +"|"+ self.offsetHeight + "t:"+t + "l:"+l; $(theid).style.position="absolute"; $(theid).style.left = l+"px"; $(theid).style.top = t+"px"; } } function hideDelete(self){ var theid = "del_icon"; if( $(theid) ){ self.style.backgroundColor = self.childNodes[0].checked?checkedCol:emptyCol; $(theid).style.display="none"; } }