]> gitweb @ CieloNegro.org - Rakka.git/commitdiff
hexdumping
authorpho <pho@cielonegro.org>
Tue, 11 Nov 2008 09:02:04 +0000 (18:02 +0900)
committerpho <pho@cielonegro.org>
Tue, 11 Nov 2008 09:02:04 +0000 (18:02 +0900)
darcs-hash:20081111090204-62b54-52da8f89c5dbc653f3f0ea9a014a3d9af543eec4.gz

Rakka.cabal
defaultPages/StyleSheet/CieloNegro.xml
defaultPages/StyleSheet/Default.xml
js/Makefile
js/editPage.js
js/hexDump.js [new file with mode: 0644]

index dca35757f89d53f63af9a71cf14b0549a6c58fbb..37a87abe2ffcb0f85efdc212f7cbe4df399f0d41 100644 (file)
@@ -37,6 +37,7 @@ Extra-Source-Files:
     js/base.js
     js/base64.js
     js/editPage.js
+    js/hexDump.js
     js/jquery-1.2.2.js
     js/jquery-dom.js
     js/localFile.js
index c663274fbf4f71f7f961501841e75fbdd9caf301..e89e3ab09ec04067a22525c69f0e326c52ecd9dc 100644 (file)
@@ -208,6 +208,12 @@ table.pageEditor {
 .pageEditor textarea.source {
     height: 30em;
 }
+.pageEditor textarea.hexDump {
+    font-size: 70%;
+    font-family: monospace;
+    white-space: pre;
+    height: 10em;
+}
 .pageEditor input[type="button"] {
     margin: 0 2px;
 }
index 15be5133b44d92ba2c8bcb087678e258089a88c0..06b84e8358e692f9560dedadab1e0f20b49c1f08 100644 (file)
@@ -212,6 +212,12 @@ table.pageEditor {
 .pageEditor textarea.source {
     height: 30em;
 }
+.pageEditor textarea.hexDump {
+    font-size: 70%;
+    font-family: monospace;
+    white-space: pre;
+    height: 10em;
+}
 .pageEditor input[type="button"] {
     margin: 0 2px;
 }
index ccd88fb2accf85687721a821afe2c5df0019163c..1fc9cee3461e560a11349f7a54a1c2e96433a2e5 100644 (file)
@@ -7,6 +7,7 @@ SOURCES = \
        base.js \
        base64.js \
        editPage.js \
+       hexDump.js \
        localFile.js \
        login.js \
        redirection.js \
index e4483a1e3520104e5372401ae8f6f12a13dfd489..eb5097c54da1fc3bd7fa524bb8d7e7a13a36824b 100644 (file)
@@ -36,7 +36,8 @@
                     })();
                     var source
                         = $page.attr("redirect") != null ? $page.attr("redirect")
-                        : $page.find("textData").text()
+                        : $page.attr("isBinary") != null ? Rakka.decodeBase64($page.find("binaryData").text())
+                        :                                  $page.find("textData").text()
                         ;
                     var summary     = $page.find("summary").text();
 
 
         $(fldJSSource).change(makeDirty);
 
+        var uploadFileBin
+            = (defaultType == "binary" && source != null ? source : "");
         var fldUploadFile
-            = $.INPUT({type: "text", disabled: true});
+            = $.TEXTAREA({className: "hexDump", disabled: true}, Rakka.hexDump(uploadFileBin, 128));
         var btnSelectFile
-            = $.INPUT({type: "button", value: "Select File"});
+            = $.INPUT({type: "button", value: "Select file..."});
 
         $(btnSelectFile).click(function () {
                                    var path = Rakka.selectFile("Select a binary file to upload", "open");
                                    if (path != null) {
-                                       fldUploadFile.value = path;
+                                       uploadFileBin = Rakka.loadLocalBinaryFile(path);
+                                       fldUploadFile.value = Rakka.hexDump(uploadFileBin, 128);
                                        makeDirty();
                                    }
                                });
                     fldPageName.value, fldRakkaSource.value);
             }
             else if (btnTypeBinary.checked) {
-                if (fldUploadFile.value != "") {
+                if (uploadFileBin != "") {
                     previewBinaryPage(
-                        fldPageName.value, fldUploadFile.value);
+                        fldPageName.value, uploadFileBin);
                 }
             }
         });
                         $(selPageLang).val(),
                         otherLangs,
                         fldSummary.value,
-                        fldUploadFile.value);
+                        uploadFileBin);
                 }
             }
             else if (btnTypeRedirect.checked) {
                     }
 
                     if (btnTypeBinary.checked) {
-                        if (fldUploadFile.value == "") {
+                        if (uploadFileBin == "") {
                             return false;
                         }
                     }
             .add(fldRedirect)
             .change(validate)
             .keyup(validate);
+        $(btnSelectFile).click(validate);
         validate();
 
         if (oldRevision == null || oldRevision == 0) {
         });
     };
 
-    var previewBinaryPage = function (pageName, path) {
+    var previewBinaryPage = function (pageName, data) {
         Rakka.displayWaitingMessage("Loading... please wait.");
 
         /* Firefox でバイナリを送らうとすると 0x00 の位置で切れてしまふ。*/
-        var bin = Rakka.loadLocalBinaryFile(path);
         var url = Rakka.baseURI + "render/" + encodeURI(pageName);
         $.ajax({
             type       : "POST",
             url        : url,
             contentType: "application/x-rakka-base64-stream",
-            data       : Rakka.encodeBase64(bin),
+            data       : Rakka.encodeBase64(data),
             processData: false,
             success    : function (resultDoc) {
                 Rakka.hideWaitingMessage();
         });
     };
 
-    var submitBinaryPage = function (pageName, oldRevision, givenPageName, isLocked, lang, otherLangs, summary, path) {
+    var submitBinaryPage = function (pageName, oldRevision, givenPageName, isLocked, lang, otherLangs, summary, data) {
         var NS   = "http://cielonegro.org/schema/Rakka/Page/1.0";
         var doc  = document.implementation.createDocument(NS, "page", null);
         var page = doc.documentElement;
         }
         page.appendChild(oLang);
 
-        var bin = Rakka.loadLocalBinaryFile(path);
-        var b64 = Rakka.encodeBase64(bin);
-
+        var b64 = Rakka.encodeBase64(data);
         var binaryData = doc.createElementNS(NS, "binaryData");
         binaryData.appendChild(
             doc.createTextNode(b64));
diff --git a/js/hexDump.js b/js/hexDump.js
new file mode 100644 (file)
index 0000000..66c3e7f
--- /dev/null
@@ -0,0 +1,85 @@
+(function () {
+
+     var repeat = function (times, str) {
+         var ret = "";
+
+         for (var i = 0; i < times; i++) {
+             ret += str;
+         }
+
+         return ret;
+     };
+
+     var printHex = function (width, num) {
+         var ret = Number(num).toString(16);
+
+         if (ret.length < width) {
+             return repeat(width - ret.length, "0") + ret;
+         }
+         else {
+             return ret;
+         }
+     };
+
+     var isPrintableAscii = function (code) {
+         return (code >= 0x20 && code <= 0x7e);
+     };
+
+     Rakka.hexDump = function (data, limit) {
+         var offset = 0;
+         var size   = Math.min(data.length, limit);
+         var ret    = "";
+
+         for (; offset < size; offset += 16) {
+             ret += printHex(8, offset);
+             ret += "  ";
+
+             var begin = offset;
+             var end   = Math.min(offset + 16, size);
+
+             for (var i = begin; i < end; i++) {
+                 var c = data.charCodeAt(i);
+
+                 ret += printHex(2, c);
+                 ret += " ";
+
+                 if (end - i == 9) {
+                     ret += " ";
+                 }
+             }
+             for (var i = end; i < offset + 16; i++) {
+                 ret += "   ";
+                 if (end - i == 9) {
+                     ret += " ";
+                 }
+             }
+
+             ret += "  |";
+
+             for (var i = begin; i < end; i++) {
+                 var c = data.charCodeAt(i);
+
+                 if (isPrintableAscii(c)) {
+                     ret += data.charAt(i);
+                 }
+                 else {
+                     ret += ".";
+                 }
+             }
+             ret += "|";
+             for (var i = end; i < offset + 16; i++) {
+                 ret += " ";
+             }
+
+             ret += "\n";
+         }
+
+         if (data.length > limit) {
+             ret += printHex(8, offset);
+             ret += "  ...\n";
+         }
+
+         return ret;
+     };
+
+ })();
\ No newline at end of file