})();
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));
--- /dev/null
+(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