///////////////////////////////////////////////// // 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対応 // v 1.8 2005/04/03 AJAX対応(auto set, リアルタイム更新) // 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 fusenObj; var fusenMovingObj = null; var fusenDustboxFlg = false; var fusenTimerID; //Interval Timer ID var fusenInterval = 0; //Interval time [msec] 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'); } // Create HTTP request object. function fusen_httprequest(){ try { return new XMLHttpRequest(); } catch(e) { var MSXML_XMLHTTP_PROGIDS = new Array( 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ); for (var i in MSXML_XMLHTTP_PROGIDS) { try { return new ActiveXObject(MSXML_XMLHTTP_PROGIDS[i]); } catch (e) { } } } throw 'Unable to create HTTP request object.'; } // Post fusen data. function fusen_postdata() { var frm = getElement('edit_frm'); var re = /input|textarea|select/i; var tag = ''; var postdata = ''; for (var i = 0; i < frm.length; i++ ) { var child = frm[i]; tag = String(child.tagName); if (tag.match(re)) { if (postdata!='') postdata += '&'; postdata += encodeURIComponent(child.name) + '=' + encodeURIComponent(child.value); } } try { var xmlhttp = fusen_httprequest(); var url = location.href; if (url.indexOf('?') > 0) url.substr(0, url.indexOf('?')); xmlhttp.open('POST', url, false); xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;'); xmlhttp.send(postdata); } catch(e) { alert(e); throw 'Unable to post fusen data.'; } if(xmlhttp.status == 200 || xmlhttp.status == 0){ return xmlhttp.responseText; } else { throw 'Fusen data not posted.'; } } // Get fusen date. function fusen_getdata() { var txt; try { getElement('edit_mode').value = 'getdata'; var txt = fusen_postdata(); eval( 'fusenObj = ' + txt ); } catch(e) { alert(e); } } // Get text in fusen. 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) { fusenMovingObj = null; 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() { fusenMovingObj = null; if (fusenInterval > 0 ) clearTimeout(fusenTimerID); 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; getElement('edit_mode').value = 'edit'; fusen_show('fusen_editbox'); } function fusen_editbox_hide() { fusenMovingObj = null; fusen_hide('fusen_editbox'); if (fusenInterval > 0) fusenTimerID = setInterval("fusen_init()", fusenInterval); } function fusen_setpos(id) { fusenMovingObj = null; 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(); fusen_postdata(); } function fusen_edit(id) { fusenMovingObj = null; if (fusenInterval > 0 ) clearTimeout(fusenTimerID); 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; getElement('edit_mode').value = 'edit'; 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) { fusenMovingObj = 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) { fusenMovingObj = 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) { fusenMovingObj = null; getElement('edit_id').value = id; getElement('edit_pass').value = prompt('管理用パスワードを入力してください。',''); getElement('edit_mode').value = 'lock'; getElement('edit_frm').submit(); } function fusen_unlock(id) { fusenMovingObj = null; getElement('edit_id').value = id; getElement('edit_pass').value = prompt('管理用パスワードを入力してください。',''); getElement('edit_mode').value = 'unlock'; getElement('edit_frm').submit(); } function fusen_recover(id) { fusenMovingObj = 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() { fusenMovingObj = 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) { if (fusenInterval > 0 ) clearTimeout(fusenTimerID); fusenMovingObj = this; if (IE) { offsetX = event.clientX + document.body.scrollLeft - fusenMovingObj.style.posLeft; offsetY = event.clientY + document.body.scrollTop - fusenMovingObj.style.posTop; } else { offsetX = e.pageX - parseInt(fusenMovingObj.style.left.replace("px","")); offsetY = e.pageY - parseInt(fusenMovingObj.style.top.replace("px","")); } for(var id in fusenObj) { getElement('fusen_id' + id).style.zIndex = 1; } fusenMovingObj.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 (fusenMovingObj) { if (IE) { fusenMovingObj.style.posLeft = event.clientX + document.body.scrollLeft - offsetX; fusenMovingObj.style.posTop = event.clientY + document.body.scrollTop - offsetY; } else { fusenMovingObj.style.left = (e.pageX - offsetX) + "px"; fusenMovingObj.style.top = (e.pageY - offsetY) + "px"; } if (!fusenDustboxFlg) fusen_setlines(); return false; } } function fusen_onmouseup(e) { if (fusenMovingObj) fusen_setpos(fusenMovingObj.id.replace('fusen_id','')); fusenMovingObj = null; if (fusenInterval > 0 ) fusenTimerID = setInterval("fusen_init()", fusenInterval); } // Initialize function fusen_init() { var obj = getElement('fusen_area'); while (obj.childNodes.length > 0) obj.removeChild(obj.firstChild); fusen_getdata(); 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; } fusen_setlines(); 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(); if (fusenInterval > 0) fusenTimerID = setInterval("fusen_init()", fusenInterval); } 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(); } }