
var Post = function(refData, Parent) { var refThis = this; refThis.refData = refData; this.Init = function() { var divView = _newElement("div", "PostView"); refThis.eView = divView; if(refData.title) { var span = _newElement("span"); span.innerHTML = Local.title + "<br/>"; divView.appendChild(span); var tInput = _newElement("input"); tInput.type = "text"; tInput.style.width = "90%"; refThis.eTitle = tInput; tInput.value = refData.title; divView.appendChild(tInput); } var divFrame = _newElement("div"); var divPad = _newElement("div"); divFrame.appendChild(divPad); if(refData.codeble) { var divTab = _newElement("div", "Tab"); var divTextA = _newElement("textarea"); divTextA.style.width = "100%"; divTextA.style.height = "100px"; divTextA.style.display = "none"; divTab.appendChild(divFrame); divTab.appendChild(divTextA); var ulTab = _newElement("ul"); var liTab1 = _newElement("li", "liTab"); var liTab2 = _newElement("li", "liTab"); liTab1.appendChild(_newText(Local.design)); liTab2.appendChild(_newText(Local.html)); ulTab.appendChild(liTab1); ulTab.appendChild(liTab2); liTab1.page = divFrame; liTab2.page = divTextA; divTab.appendChild(ulTab); divView.appendChild(divTab); refThis.InitTab(liTab1, liTab2); } else { divView.appendChild(divFrame); } var iFrame = _newElement("iframe"); iFrame.id = "postIframe"; iFrame.name = iFrame.id; iFrame.style.width = "100%"; iFrame.style.height = "200px"; iFrame.scolling = "auto"; divFrame.appendChild(iFrame); refThis.iFrame = iFrame; Parent.onSizeChanged = function() { var sub = 160; if(refData.title) sub += 40; if(refData.tags) sub += 40; var rect = getRect(Parent.parentNode); var h = rect.bottom-rect.top; if(h > 320 && h < 580) { iFrame.style.height = (h - sub) + "px"; if(typeof divTextA != "undefined") divTextA.style.height = (h - sub) + "px"; } }; Parent.onSizeChanged(); if(refData.tags) { var span = _newElement("span"); span.innerHTML = "<br/>"+Local.tags + ":<font color=gray>("+Local.tagsTip+")</font><br/>"; divView.appendChild(span); var tTags = _newElement("input"); tTags.type = "text"; tTags.style.width = "90%"; tTags.value = refData.tags; refThis.eTags = tTags; divView.appendChild(tTags); } var center = _newElement("center"); center.style.margin = "5px"; var msg = _newElement("span", "msg"); var btOK = _newElement("input", "OK"); btOK.type = "button"; btOK.value = Local.OK; btOK.onclick = function() { msg.innerHTML = ""; zoomImages(); var iframe = frames["postIframe"]; if(iframe && iframe.document) { var content = iframe.document.body; if(content) { var as = content.getElementsByTagName("a"); for(var i=0; i<as.length; i++) { as[i].target = "_blank"; } function clength(str) { var len=0; for(var i=0; i<str.length; i++) if(str.charAt(i)>'!') len++; return len; } function strim(str) { var s = str.replace(/(^\s*)|(\s*$)/g, ""); str = s; } if(refThis.eTitle) { strim(refThis.eTitle.value); if(clength(refThis.eTitle.value) < 2) { msg.innerHTML = "<font color=red>" +Local.title+Local.tooShort +"</font><br>"; return false; } refData.title = refThis.eTitle.value; } if(clength(_innerText(content)) < 2) { var imgs = content.getElementsByTagName("img"); if(imgs.length == 0) { msg.innerHTML = "<font color=red>" +Local.tooShort+"</font><br>"; return false; } } if(refThis.eTags) { strim(refThis.eTags.value); refData.tags = refThis.eTags.value; } refData.content = content; if(refData.onOK) { if(refData.onOK(refData) == true) { _removeNode(divView); delete refThis; } } } } }; center.appendChild(msg); center.appendChild(btOK); divView.appendChild(center); Parent.appendChild(divView); function formatText(command, option) { var iframe = frames["postIframe"]; iframe.focus(); if(command == "InsertHTML") { if(refThis.range) { refThis.range.pasteHTML(option); } return; } iframe.document.execCommand(command, false, option); iframe.focus(); if(command == "InsertImage") { zoomImages(); } } function zoomImages() { var iframe = frames["postIframe"]; if(iframe && iframe.document) { var content = iframe.document.body; if(content) { var imgs = content.getElementsByTagName("img"); for(var i=0; i<imgs.length; i++) { ImageZoom(imgs[i], 512); } } } } function onSelection() { if(Browser.isIE) { var iframe = frames["postIframe"]; iframe.focus(); var doc = iframe.document; var range = doc.selection.createRange(); refThis.range = range; } } var editor = iFrame.contentWindow; if(editor && editor.document) { var doc = editor.document; doc.designMode = 'On'; doc.contentEditable = true; doc.open(); doc.writeln('<html><head><link href="/css/iframe.css" rel="stylesheet" type="text/css"/></head><body></body></html>'); doc.close(); function PadBtn(command) { var img = _newElement("img"); img.src = "/img/post/"+command+".gif"; img.style.cursor = "pointer"; img.style.padding = "3px"; img.alt = Local[command]; img.command = command; img.onclick = function() { formatText(command); }; divPad.appendChild(img); } PadBtn("cut"); PadBtn("copy"); PadBtn("paste"); PadBtn("bold"); PadBtn("italic"); PadBtn("underline"); PadBtn("JustifyLeft"); PadBtn("JustifyCenter"); PadBtn("JustifyRight"); PadBtn("InsertUnorderedList"); PadBtn("outdent"); PadBtn("indent"); PadBtn("createLink"); function PadBox(name, command, width) { var box = _newElement("div", "box"); box.style.width = width+"px"; var img = _newElement("img"); img.src = "/img/post/box.gif"; img.style.cursor = "pointer"; box.appendChild(img); box.appendChild(_newText(Local[name])); box.onclick = function() { onSelection(); function onPicked(option) { var iframe = frames["postIframe"]; iframe.focus(); if(refThis.range) { refThis.range.select(); } formatText(command, option); } var r = getRect(this); Pick(name, r.left+5, r.bottom+5, onPicked); }; divPad.appendChild(box); } PadBox("fonts", "fontname", 96); PadBox("color", "ForeColor", 64); PadBox("fsize", "fontsize", 64); function PadPic(name, command) { var img = _newElement("img"); img.src = "/img/post/"+name+".gif"; img.style.cursor = "pointer"; img.style.padding = "3px"; img.alt = Local[name]; img.onclick = function() { onSelection(); function onPicked(option) { var iframe = frames["postIframe"]; iframe.focus(); if(refThis.range) { refThis.range.select(); } formatText(command, option); } var r = getRect(this); Pick(name, r.left+5, r.bottom+5, onPicked); }; divPad.appendChild(img); } PadPic("faces", "InsertImage"); PadPic("table", "InsertHTML"); PadPic("frame", "InsertHTML"); function PadUp(name) { var img = _newElement("img"); img.src = "/img/post/"+name+".gif"; img.style.cursor = "pointer"; img.style.padding = "3px"; img.alt = Local[name]; img.onclick = function() { onSelection(); function onPicked(url) { var iframe = frames["postIframe"]; iframe.focus(); if(refThis.range) { refThis.range.select(); } formatText('InsertImage', url); } FileView({id:'fviewPost', path:'~', title:Local.upload, onOpen:onPicked}, document.body); }; divPad.appendChild(img); } PadUp("upload"); } }; this.InitTab = function(tab1, tab2) { var selected = null; function swapto(tab) { if(selected) { selected.page.style.display = "none"; selected.className = "liTab"; } selected = tab; selected.page.style.display = ""; selected.className = "liSel"; } tab1.onclick = function() { if(selected != this) { var iframe = frames["postIframe"]; iframe.document.body.innerHTML = tab2.page.value; swapto(this); } }; tab2.onclick = function() { if(selected != this) { var rect = getRect(tab1.page); this.page.style.height = (rect.bottom-rect.top-5)+"px"; var iframe = frames["postIframe"]; this.page.value = iframe.document.body.innerHTML; swapto(this); } }; swapto(tab1); }; this.Show = function(bShow) { if(bShow) refThis.eView.style.display = ""; else refThis.eView.style.display = "none"; }; this.Bind = function(newRefData) { newRefData.cbox = refData.cbox; var iframe = frames["postIframe"]; refData = newRefData; if(refData.content) { iframe.document.body.innerHTML = refData.content; } else { iframe.document.body.innerHTML = ""; } }; this.Free = function() { _removeNode(refThis.eView); delete refThis; }; this.Init(); }; function PostTopic(szWebxDB, szClassId, Parent, caller, callback) { function onPostOK(refData) { function onPosted(response) { var nId = 0; var root = Request.Validate(response); if(root && root.tagName == "post") { nId = parseInt(_text(root)); refData.cbox.Close(); } if(callback) callback(nId); } if(refData.title) { var data = "&classid="+szClassId + "&title="+escape(refData.title) + "&content="+escape(refData.content.innerHTML); if(refData.tags) data += "&tags="+escape(refData.tags); Request.POST("/Post.aspx?webxdb="+szWebxDB, data, onPosted); if(caller == null && refData.cbox) refData.cbox.Show(false); } } function doPost() { var data = {classId:szClassId, title:' ', tags:' ', onOK:onPostOK}; if(Parent == null) { Parent = document.body; data.cbox = new Cbox({title:Local.post, screenCover:true, cssName:'CDlg', width:480,height:360, caller:caller}, Parent); return new Post(data, data.cbox.eContent); } else { return new Post(data, Parent); } } if(caller) { doPost(); } else { EnsureUser(doPost); } } function PostReply(szWebxDB, szTopicId, Parent) { function onPostOK(refData) { function onPosted(response) { var root = Request.Validate(response); if(root && root.tagName == "post") { window.location.reload(); } } function doPost() { var data = "&topicid="+szTopicId + "&content="+escape(refData.content.innerHTML); Request.POST("/Post.aspx?webxdb="+szWebxDB, data, onPosted); } EnsureUser(doPost); } var data = {topicId:szTopicId, onOK:onPostOK}; if(Parent == null) { Parent = document.body; data.cbox = new Cbox({title:'post', screenCover:true, cssName:'CDlg', width:480,height:360}, Parent); return new Post(data, data.cbox.eContent); } else { return new Post(data, Parent); } } 
