///////////////////////////////////////////////// // PukiWiki - Yet another WikiWikiWeb clone. // // fusen.js // 付箋プラグイン用JavaScript // ohguma@rnc-com.co.jp // // v 1.0 2005/03/12 初版 // v 1.1 (欠番) // v 1.2 2005/03/16 削除確認追加,Lock時のDrag廃止 // v 1.3 2005/03/17 XHTML1.1対応? // v 1.4 2005/03/18 検索機能追加 // v 1.5 2005/03/18 検索機能修正(convert_html後の表示内容で検索) // v 1.6 (欠番) // v 1.7 2005/04/02 onload修正,関数名変更,付箋データ保持方法変更,線関係修正,DblClick対応 // var obj = null; var offsetX = 0; var offsetY = 0; // browser check var GK = document.getElementById; // Gecko or IE var IE = document.all; // IE // mouse position var mouseX = ''; var mouseY = ''; var fusenDustboxFlg = false; function getElement(id) { return document.getElementById(id); } // Open window for object information. function fusen_debugObj(objref) { var obj = null; var str = ''; if (typeof(objref) == 'string') obj = getElement(objref); else obj = objref; if (obj) for(i in obj) try { str += i + "=" + obj[i] + "\n"; } catch (e) { } else str = objref; debugWin = window.open('', ''); window.debugWin.document.write('\n\n
\n' + str + '\n
\n\n'); } function fusen_getchildtext(objref) { var obj; var output = ''; if (typeof objref == 'string') obj = getElement(objref); else obj = objref; if (!obj) return ''; var group = obj.childNodes; for (var i = 0; i < group.length; i++) { if (group[i].nodeType == 3) output += group[i].nodeValue.replace(/[\r\n]/,''); if (group[i].childNodes.length > 0) output += fusen_getchildtext(group[i]); } return output; } function fusen_grep(pat) { var re = new RegExp(pat, 'im'); for(var id in fusenObj) { if (!fusenDustboxFlg && (fusenObj[id].del)) continue; if (fusenDustboxFlg && !(fusenObj[id].del)) continue; if (fusenObj[id].disp.match(re)) { getElement('fusen_id' + id).style.visibility = "visible"; } else { getElement('fusen_id' + id).style.visibility = "hidden"; } } } // editbox control function fusen_new() { getElement('edit_id').value = ''; getElement('edit_ln').value = ''; getElement('tc000000').selected = true; getElement('bgffffff').selected = true; getElement('edit_body').value = ''; getElement('edit_l').value = mouseX; getElement('edit_t').value = mouseY; fusen_show('fusen_editbox'); obj = null; } function fusen_editbox_hide() { fusen_hide('fusen_editbox'); obj = null; } function fusen_setpos(id) { var obj = getElement('fusen_id' + id); getElement('edit_id').value = id; getElement('edit_l').value = parseInt(obj.style.left.replace("px","")); getElement('edit_t').value = parseInt(obj.style.top.replace("px","")); // getElement('edit_z').value = getElement(id).style.zIndex; getElement('edit_mode').value = 'set'; getElement('edit_frm').submit(); } function fusen_edit(id) { var obj = getElement('fusen_id' + id); getElement('edit_id').value = id; getElement('edit_l').value = parseInt(obj.style.left.replace("px","")); getElement('edit_t').value = parseInt(obj.style.top.replace("px","")); getElement('edit_ln').value = (fusenObj[id].ln) ? 'id' + fusenObj[id].ln : ''; getElement('edit_body').value = fusenObj[id].txt; var tcid = fusenObj[id].tc; if (!tcid) tcid = 'tc000000'; else tcid = 'tc' + tcid.substr(1); var tcobj = getElement(tcid); if (!tcobj) getElement('tc000000').selected = true; else getElement(tcid).selected = true; var bgid = fusenObj[id].bg; if (!bgid) bgid = 'bgffffff'; else bgid = 'bg' + bgid.substr(1); var bgobj = getElement(bgid); if (!bgobj) getElement('bg000000').selected = true; else getElement(bgid).selected = true; fusen_show('fusen_editbox'); } function fusen_link(id) { obj = null; getElement('edit_l').value = 200; getElement('edit_t').value = 200; getElement('edit_id').value = ''; getElement('edit_ln').value = 'id' + id; getElement('edit_body').value = ''; fusen_show('fusen_editbox'); } function fusen_del(id) { obj = null; var ok; if (fusenDustboxFlg) ok = confirm('完全削除しますか?'); else ok = confirm('削除しますか?'); if (ok) { getElement('edit_id').value = id; getElement('edit_mode').value = 'del'; getElement('edit_frm').submit(); } } function fusen_lock(id) { obj = null; getElement('edit_id').value = id; getElement('edit_pass').value = prompt('管理用パスワードを入力してください。',''); getElement('edit_mode').value = 'lock'; getElement('edit_frm').submit(); } function fusen_unlock(id) { obj = null; getElement('edit_id').value = id; getElement('edit_pass').value = prompt('管理用パスワードを入力してください。',''); getElement('edit_mode').value = 'unlock'; getElement('edit_frm').submit(); } function fusen_recover(id) { obj = null; getElement('edit_id').value = id; getElement('edit_mode').value = 'recover'; getElement('edit_frm').submit(); } function fusen_show(id) { getElement(id).onmousedown = null; getElement(id).style.visibility = "visible"; getElement(id).style.zIndex = 2; document.onmouseup = null; document.onmousemove = null; } function fusen_hide(id) { getElement(id).style.visibility = "hidden"; document.onmouseup = fusen_onmouseup; document.onmousemove = fusen_onmousemove; } function fusen_dustbox() { obj = null; fusenDustboxFlg = !fusenDustboxFlg; for(var id in fusenObj) { var obj = getElement('fusen_id' + id); if (fusenObj[id].del) { if (fusenDustboxFlg) obj.style.visibility = 'visible'; else obj.style.visibility = 'hidden'; } else { if (fusenDustboxFlg) obj.style.visibility = 'hidden'; else obj.style.visibility = 'visible'; } } if (fusenDustboxFlg) fusen_removelines(); else fusen_setlines(); } function fusen_create_menuobj(id, mode) { var menuobj = document.createElement("DIV"); menuobj.style.color = '#000000'; menuobj.style.width = 'auto'; menuobj.style.height = 'auto'; menuobj.style.backgroundColor = '#cccccc'; menuobj.style.borderBottom = '1px solid #000000'; menuobj.style.padding = '1px'; menuobj.style.whiteSpace = 'nowrap'; menuobj.style.fontSize = '80%'; menuobj.innerHTML = 'id' + id if (mode == 'del') menuobj.innerHTML += ' recover' + ' del'; else if (mode == 'lock') menuobj.innerHTML += ' unlock'; else menuobj.innerHTML += ' set' + ' edit' + ' lock' + ' line' + ' del'; return menuobj; } function fusen_create_contentsobj(id, obj) { var contentsobj = document.createElement("DIV"); contentsobj.style.width = 'auto'; contentsobj.style.height = 'auto'; contentsobj.style.padding = '2px'; contentsobj.id = 'fusen_id' + id + 'contents'; contentsobj.innerHTML = obj.disp; return contentsobj; } function fusen_create(id, obj) { var fusenobj = document.createElement("DIV"); var menuobj; var border; var visible = 'visible'; if (obj.del) { menuobj = fusen_create_menuobj(id, 'del'); border = fusenBorderObj['del']; visible = 'hidden'; } else if (obj.lk) { menuobj = fusen_create_menuobj(id, 'lock'); border = fusenBorderObj['lock']; } else { menuobj = fusen_create_menuobj(id, 'normal'); border = fusenBorderObj['normal']; } fusenobj.id = 'fusen_id' + id; fusenobj.style.left = obj.x + 'px'; fusenobj.style.top = obj.y + 'px'; fusenobj.style.color = obj.tc; fusenobj.style.backgroundColor = obj.bg; fusenobj.style.zIndex = obj.z; fusenobj.style.border = border; fusenobj.style.visibility = visible; fusenobj.style.position = 'absolute'; fusenobj.style.whiteSpace = 'nowrap'; fusenobj.style.width = 'auto'; fusenobj.style.height = 'auto'; fusenobj.appendChild(menuobj); fusenobj.appendChild(fusen_create_contentsobj(id, obj)); return fusenobj; } // Line draw function fusen_removelines() { var id, lineid, obj; for(id in fusenObj) { if (fusenObj[id].ln) { lineid = 'line' + id + '_' + fusenObj[id].ln; obj = getElement(lineid); if (obj) obj.parentNode.removeChild(obj); } } } function fusen_setlines() { for(var id in fusenObj) { if (fusenObj[id].ln && !fusenObj[id].del && !fusenObj[fusenObj[id].ln].del) { fusen_setline(id, fusenObj[id].ln); } } } function fusen_setline(fromid, toid){ function getCenter(obj){ x = parseInt(obj.style.left.replace("px","")); x = x + obj.offsetWidth / 2; return x; } function getVCenter(obj){ y = parseInt(obj.style.top.replace("px","")); y = y + obj.offsetHeight / 2; return y; } var lineid = 'line' + fromid + '_' + toid; var obj = getElement(lineid); if (obj) obj.parentNode.removeChild(obj); var fobj = getElement('fusen_id' + fromid); var tobj = getElement('fusen_id' + toid); if(!fobj) return; if(!tobj) return; var x1 = getCenter(fobj); var y1 = getVCenter(fobj); var x2 = getCenter(tobj); var y2 = getVCenter(tobj); var obj = fusen_drawLine(x1, y1, x2, y2, '#000000', lineid); document.getElementById('fusen_area').appendChild(obj); } function fusen_drawLine(x1, y1, x2, y2, color, nid){ function _drawLine(x1,y1,x2,y2,color){ var objLine = document.createElement("div") var strColor = color with(objLine.style){ backgroundColor = strColor position = "absolute" overflow = "hidden" width = Math.abs(x2-x1+1) + "px" height = Math.abs(y2-y1+1) + "px" top = Math.min(y1,y2) + "px" left = Math.min(x1,x2) + "px" zIndex = "0" } return objLine; } var objLines = document.createElement("div") objLines.id = nid; if((x1 == x2) || (y1 == y2)){ objLines.appendChild(_drawLine(x1,y1,x2,y2,color)); } else{ objLines.appendChild(_drawLine(x1,y1,x1,y2,color)); objLines.appendChild(_drawLine(x1,y2,x2,y2,color)); } return objLines; } // Event function fusen_onmousedown(e) { obj = this; if (IE) { offsetX = event.clientX + document.body.scrollLeft - obj.style.posLeft; offsetY = event.clientY + document.body.scrollTop - obj.style.posTop; } else if (GK) { offsetX = e.pageX - parseInt(obj.style.left); offsetY = e.pageY - parseInt(obj.style.top); } for(var id in fusenObj) { getElement('fusen_id' + id).style.zIndex = 1; } obj.style.zIndex = 2; return false; } function fusen_onmousemove(e) { if(IE){ mouseX = document.body.scrollLeft+event.clientX; mouseY = document.body.scrollTop+event.clientY; } else { mouseX = e.pageX; mouseY = e.pageY; } if (obj) { if (IE) { obj.style.posLeft = event.clientX + document.body.scrollLeft - offsetX; obj.style.posTop = event.clientY + document.body.scrollTop - offsetY; } else { obj.style.left = (e.pageX - offsetX) + "px"; obj.style.top = (e.pageY - offsetY) + "px"; } if (!fusenDustboxFlg) fusen_setlines(); return false; } } function fusen_onmouseup(e) { obj = null; } // Initialize function fusen_init() { var obj; for(var id in fusenObj) { obj = fusen_create(id, fusenObj[id]); document.getElementById('fusen_area').appendChild(obj); if (!(fusenObj[id].del) && !(fusenObj[id].lk)) obj.onmousedown = fusen_onmousedown; } document.onmouseup = fusen_onmouseup; document.onmousemove = fusen_onmousemove; } var __fusen_onload_save = window.onload; window.onload = function() { if (__fusen_onload_save) __fusen_onload_save(); fusen_init(); fusen_setlines(); } if (IE) { var __fusen_ondblclick_save = document.ondblclick; document.ondblclick = function() { if (__fusen_ondblclick_save) __fusen_ondblclick_save(); fusen_new(); } } else { var __fusen_ondblclick_save = window.ondblclick; window.ondblclick = function() { if (__fusen_ondblclick_save) __fusen_ondblclick_save(); fusen_new(); } }