From: pho Date: Sun, 6 Jan 2008 06:20:49 +0000 (+0900) Subject: implemented previewer X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=736016f6e7b9c4ce5cec6d2fe82f8d2911783f8f;p=Rakka.git implemented previewer darcs-hash:20080106062049-62b54-aa2d3db84161eba10e9a0756f387b5f7ac247d2d.gz --- diff --git a/defaultPages/StyleSheet/Default.xml b/defaultPages/StyleSheet/Default.xml index 3355d28..af1cc97 100644 --- a/defaultPages/StyleSheet/Default.xml +++ b/defaultPages/StyleSheet/Default.xml @@ -485,5 +485,17 @@ img { .redirection input[type="button"]:active { background-color: #eeeeee; } + +/* preview ********************************************************************/ +.preview { + background-color: #eeeeee; + + margin: 0 0 20px 0; + padding: 10px; + + border-style: solid; + border-width: 1px; + border-color: #bbbbbb; +} diff --git a/js/editPage.js b/js/editPage.js index 4623849..2dd9951 100644 --- a/js/editPage.js +++ b/js/editPage.js @@ -1,3 +1,6 @@ +Rakka.$previewHeader = null; +Rakka.$previewArea = null; + Rakka.editPage = function (pageName) { var $area = Rakka.switchScreen(); @@ -45,8 +48,16 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source) var $area = Rakka.switchScreen(); $area.empty(); - $area.append($.H1({}, pageName == "" ? "Create page" : "Edit page")); + Rakka.$previewHeader = $( $.H1({}, "Preview") ); + $area.append(Rakka.$previewHeader); + Rakka.$previewHeader.hide(); + Rakka.$previewArea = $( $.DIV({className: "preview"}) ); + $area.append(Rakka.$previewArea); + Rakka.$previewArea.hide(); + + $area.append($.H1({}, pageName == "" ? "Create page" : "Edit page")); + var fldPageName = $.INPUT({type : "text", value: pageName}); @@ -92,7 +103,14 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source) = $.INPUT({type: "button", value: "Preview page"}); $(btnPreview).click(function () { - throw new Error("FIXME: not implemented yet"); + if (btnTypeRakka.checked) { + Rakka.previewRakkaPage( + fldPageName.value, fldRakkaSource.value); + } + else if (btnTypeBinary.checked) { + Rakka.previewBinaryPage( + fldPageName.value, fldUploadFile.value); + } }); var btnSubmit @@ -220,6 +238,42 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source) $area.append(pageEditor); }; +Rakka.previewRakkaPage = function (pageName, source) { + Rakka.displayWaitingMessage("Loading... please wait."); + + var url = Rakka.baseURI + "render/" + encodeURI(pageName); + $.ajax({ + type : "POST", + url : url, + contentType: "text/x-rakka", + data : source, + processData: false, + success : function (resultDoc) { + Rakka.hideWaitingMessage(); + Rakka.showPreview(resultDoc); + }, + error : function (req) { + alert("Error: " + req.status + " " + req.statusText); + } + }); +}; + +Rakka.showPreview = function (doc) { + Rakka.$previewArea.empty(); + + Rakka.$previewHeader.show(); + Rakka.$previewArea.show(); + + var root = doc.documentElement; + var child = root.firstChild; + do { + if (child.nodeType == 1) { + // 要素だったので複製 + Rakka.$previewArea.append(child.cloneNode(true)); + } + } while (child = child.nextSibling); +}; + Rakka.submitTextPage = function (pageName, oldRevision, givenPageName, mimeType, text) { var doc = document.implementation.createDocument( "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null); diff --git a/js/screen.js b/js/screen.js index 2e5ff37..c30d0ab 100644 --- a/js/screen.js +++ b/js/screen.js @@ -39,6 +39,10 @@ return null; }; + Rakka.getSwitchedScreen = function () { + return switchedArea; + }; + var waitingMessageBoard = null; Rakka.displayWaitingMessage = function (msg) {