Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
custom:javascript:lib:modopts.js [2019/07/16 23:47] – [modopts.js] Documented digital mancustom:javascript:lib:modopts.js [2019/07/17 00:25] (current) – Use syntax highlighting digital man
Line 11: Line 11:
  
 For example: For example:
-<file>+<file ini>
 [yourmodule] [yourmodule]
 good_thing = true good_thing = true
Line 24: Line 24:
 Example: Example:
  
-<code>+<code javascript>
 var options = load({}, "modopts.js", "yourmodule"); var options = load({}, "modopts.js", "yourmodule");
 </code> </code>
Line 30: Line 30:
 Now if there is any problem reading the ''[yourmodule]'' section from the ''modopts.ini'' file, ''load()'' may return ''null'' or ''undefined''. Referencing ''options.anything'' in your module may result in a JavaScript exception: ''options is null''. To handle this case, assign ''options'' to an empty object: Now if there is any problem reading the ''[yourmodule]'' section from the ''modopts.ini'' file, ''load()'' may return ''null'' or ''undefined''. Referencing ''options.anything'' in your module may result in a JavaScript exception: ''options is null''. To handle this case, assign ''options'' to an empty object:
  
-<code>+<code javascript>
 var options = load({}, "modopts.js", "yourmodule"); var options = load({}, "modopts.js", "yourmodule");
 if(!options) if(!options)
Line 38: Line 38:
 Now you can safely reference ''options.anything'' and while that may result in an undefined value and exception, depending on use, you won't get an exception because ''options'' itself was undefined. So you can then use ''options.anything'' in your module script: Now you can safely reference ''options.anything'' and while that may result in an undefined value and exception, depending on use, you won't get an exception because ''options'' itself was undefined. So you can then use ''options.anything'' in your module script:
  
-<code>+<code javascript>
 if(options.good_thing == true) if(options.good_thing == true)
    do_good_thing();    do_good_thing();
Line 50: Line 50:
 If you want to assign default option values, you can assign them right after you ''load({}, "modopts.js", ...)'', like so: If you want to assign default option values, you can assign them right after you ''load({}, "modopts.js", ...)'', like so:
  
-<code>+<code javascript>
 var options = load({}, "modopts.js", "yourmodule"); var options = load({}, "modopts.js", "yourmodule");
 if(!options) if(!options)
Line 64: Line 64:
 Or with string values, you can easily specify defaults //in-line// using the ''||'' operator: Or with string values, you can easily specify defaults //in-line// using the ''||'' operator:
  
-<code>+<code javascript>
 print(options.other_thing || "some text"); print(options.other_thing || "some text");
 </code> </code>
Line 80: Line 80:
 For example, to load a //Date// option value: For example, to load a //Date// option value:
  
-<code>+<code javascript>
 var date_option = load({}, "modopts.js", "yourmodule", "date", new Date()); var date_option = load({}, "modopts.js", "yourmodule", "date", new Date());
 </code> </code>
Line 86: Line 86:
 For example, to load a //String// option (even when it's a valid //Number// or //Boolean// value): For example, to load a //String// option (even when it's a valid //Number// or //Boolean// value):
  
-<code>+<code javascript>
 var str_option = load({}, "modopts.js", "yourmodule", "str", ""); var str_option = load({}, "modopts.js", "yourmodule", "str", "");
 </code> </code>
Line 101: Line 101:
 ===== See Also ===== ===== See Also =====
   * [[:custom:javascript:lib:|JavaScript Libraries]]   * [[:custom:javascript:lib:|JavaScript Libraries]]
 +  * [[:config:ini_files|.ini files]]
 +  * [[:module:|Modules]]
  
 {{tag>javascript modopts}} {{tag>javascript modopts}}
  
custom/javascript/lib/modopts.js.txt · Last modified: 2019/07/17 00:25 by digital man
Back to top
CC Attribution 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0