$(fldJSSource).change(makeDirty);
var fldUploadFile
- = $.INPUT({type: "file"});
-
- $(fldUploadFile).change(makeDirty);
+ = $.INPUT({type: "text", disabled: true});
+ var btnSelectFile
+ = $.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;
+ makeDirty();
+ }
+ });
var fldRedirect
= $.INPUT({type: "text", value: (defaultType == "redirect" ? source : "")});
$(trOtherLangs).show();
$(trSummary).show();
$(trContent).find("th").text("File");
- $(trContent).find("td").empty().append(fldUploadFile);
+ $(trContent).find("td").empty().append(fldUploadFile).append(btnSelectFile);
$(btnPreview).show();
}
else if (btnTypeRedirect.checked) {
(function () {
- Rakka.canAccessLocalFile = function () {
- return $.browser.mozilla;
- };
-
- var loadBin_mozilla = function (path) {
- try {
- netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
- }
- catch (e) {
- alert("Permission to read local file was denied. " +
- "Open about:config and check that " +
- "signed.applets.codebase_principal_support is set to true.");
- }
-
- var localFile
- = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
- localFile.initWithPath(path);
-
- var stream
- = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
- stream.init(localFile, 0x01, 00004, null);
-
- var bstream
- = Components.classes["@mozilla.org/network/buffered-input-stream;1"].getService();
- bstream.QueryInterface(Components.interfaces.nsIBufferedInputStream);
- bstream.init(stream, 1000);
- bstream.QueryInterface(Components.interfaces.nsIInputStream);
-
- var binary
- = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
- binary.setInputStream(stream);
-
- return binary.readBytes(binary.available());
- };
-
- Rakka.loadLocalBinaryFile = function (path) {
- if ($.browser.mozilla) {
- return loadBin_mozilla(path);
- }
- };
-
+ Rakka.canAccessLocalFile = function () {
+ return $.browser.mozilla;
+ };
+
+ var loadBin_mozilla = function (path) {
+ try {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+ }
+ catch (e) {
+ alert("Permission to read local file was denied. " +
+ "Open about:config and check that " +
+ "signed.applets.codebase_principal_support is set to true.");
+ }
+
+ var localFile
+ = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
+ localFile.initWithPath(path);
+
+ var stream
+ = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
+ stream.init(localFile, 0x01, 00004, null);
+
+ var bstream
+ = Components.classes["@mozilla.org/network/buffered-input-stream;1"].getService();
+ bstream.QueryInterface(Components.interfaces.nsIBufferedInputStream);
+ bstream.init(stream, 1000);
+ bstream.QueryInterface(Components.interfaces.nsIInputStream);
+
+ var binary
+ = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
+ binary.setInputStream(stream);
+
+ return binary.readBytes(binary.available());
+ };
+
+ var selectFile_mozilla = function (title, mode) {
+ try {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+ }
+ catch (e) {
+ alert("Permission to select local file was denied. " +
+ "Open about:config and check that " +
+ "signed.applets.codebase_principal_support is set to true.");
+ }
+
+ var nsIFilePicker = Components.interfaces.nsIFilePicker;
+
+ var modeID;
+ if (mode == "open") {
+ modeID = nsIFilePicker.modeOpen;
+ }
+ else if (mode == "save") {
+ modeID = nsIFilePicker.modeSave;
+ }
+ else if (mode == "getFolder") {
+ modeID = nsIFilePicker.modeGetFolder;
+ }
+ else if (mode == "modeOpenMultiple") {
+ modeID = nsIFilePicker.modeOpenMultiple;
+ }
+ else {
+ throw new Error("Unknown file picker mode: " + mode);
+ }
+
+ var picker = Components
+ .classes["@mozilla.org/filepicker;1"]
+ .createInstance(nsIFilePicker);
+ picker.init(window, title, modeID);
+ picker.appendFilters(nsIFilePicker.filterAll);
+
+ var ret = picker.show();
+ if (ret == nsIFilePicker.returnOK || ret == nsIFilePicker.returnReplace) {
+ return picker.file.path;
+ }
+ else {
+ return null;
+ }
+ };
+
+ Rakka.selectFile = function (title, mode) {
+ if ($.browser.mozilla) {
+ return selectFile_mozilla(title, mode);
+ }
+ else {
+ throw new Error("It's not possible to select local files using JavaScript with your browser. Consider using Firefox.");
+ }
+ };
+
+ Rakka.loadLocalBinaryFile = function (path) {
+ if ($.browser.mozilla) {
+ return loadBin_mozilla(path);
+ }
+ else {
+ throw new Error("It's not possible to load local files using JavaScript with your browser. Consider using Firefox.");
+ }
+ };
+
})();
\ No newline at end of file