Added xAFFE's noscript wrapper.
[conkeror.git] / modules / rc.js
blobee0a2565fc41a613c3dbd7b3a3fbde2f72a92d9a
1 /**
2  * (C) Copyright 2004-2007 Shawn Betts
3  * (C) Copyright 2007-2008 John J. Foerch
4  * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
5  *
6  * Use, modification, and distribution are subject to the terms specified in the
7  * COPYING file.
8 **/
10 function load_rc_file(file)
12     try {
13         var name;
14         if (typeof file == "string")
15             name = file;
16         else
17             name = file.path;
19         subscript_loader.loadSubScript("file://" + name, conkeror);
20     } catch (e) {
21         dump_error(e);
22     }
25 function load_rc_directory (file_o) {
26     var entries = file_o.directoryEntries;
27     var files = [];
28     while (entries.hasMoreElements ()) {
29         var entry = entries.getNext ();
30         entry.QueryInterface (Ci.nsIFile);
31         if (entry.leafName.match(/^[^.].*\.js$/i)) {
32             files.push(entry);
33         }
34     }
35     files.sort(function (a, b) {
36             if (a.leafName < b.leafName) {
37                 return -1;
38             } else if (a.leafName > b.leafName) {
39                 return 1;
40             } else {
41                 return 0;
42             }
43         });
44     for (var i = 0; i < files.length; i++) {
45         load_rc_file(files[i]);
46     }
51  * path_s: string path to load.  may be a file, a directory, or null.
52  *   if it is a file, that file will be loaded.  if it is a directory,
53  *   all `.js' files in that directory will be loaded.  if it is null,
54  *   the preference `conkeror.rcfile' will be read for the default.
55  */
56 function load_rc(path_s)
58     if (! path_s)
59     {
60         if (pref_has_user_value("conkeror.rcfile")) {
61             var rcfile = get_pref("conkeror.rcfile");
62             if (rcfile.length)
63                 path_s = rcfile;
64             else
65                 return;
66         } else {
67             var default_rc = get_home_directory();
68             default_rc.appendRelativePath(".conkerorrc");
69             if (default_rc.exists())
70                 path_s = default_rc.path;
71             else
72                 return;
73         }
74     }
76     var file_o = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
77     file_o.initWithPath(path_s);
78     if (file_o.isDirectory()) {
79         load_rc_directory (file_o);
80     } else {
81         load_rc_file (path_s);
82     }