|
Page Updated: June 16, 2005
Latest Version: 0.1.359 |
|
Debug |
Install | File
I/O |
RDF |
Network |
Sound | Utils |
XUL | Zip
|
|
|
Home | Mailing List |
Install |
Source Code |
Downloads | Bugs
| docs
| clients |
- Introduction
- Where JSLib is installed on your system
- Using JSLIb in your application
- Using JSLIb in xpcshell
- Module Idenifiers
- Installing jslib w/ your application
- JSLib samples
- Turning SDTOUT Dump On and Off
- XPCOM Methods
- Using jsLib from a local "file://"
Introduction JSLib is an evolving project still currently under development. It has one simple goal:
"Make life easier for Mozilla Application Development by creating logical, easy to use API's for general purpose routines that lend themselves to living in library code."The JSLib javascript library wraps Mozilla's scriptable xpcom interfaces with easy to use methods. The sole purpose of the library is for applications based on the Mozilla application framework. So as a Mozilla author, you install jslib with your application as a dependency and then use the libraries in your application logic just as you would libraries in other languages. The most complete module in this library is the I/O module. But development is continuous and there are many other valuable modules currently available for MAD authors to use. These are modules that implement date, prefs settings, windows, and dialogs, sound, etc. Each modules function list is documented independently. The current module groups are:
debug install io network rdf samples sound utils xbl xul zipJSLib is reasonably small in file size about 100K and new builds are posted often. So as you develop your Mozilla application, it is a good idea to always install the latest version of jslib.
Where JSLib is installed on your system JSLib is usually installed into your Mozilla global chrome dir if it has permission to do so, otherwise it will fall back and install in your user profile folder. This is to avoid any permission problems that may come from a shared system wide installation of mozilla. The Mozilla profile directories reside in different locations on defferent systems. For example: Linux/Unix Systems
~/.mozilla/profile_name/generated.slt/chromeOn my system it is:
/home/petejc/.mozilla/default/m84bwsx3.slt/chrome/Windows Systems
c:\WINDOWS\Application Data\Mozilla\Profiles\default\generated.slt\chrome\Mac Classic Systems
I forget need to double checkMac OSX systems
/Users/uname/Library/Application Support/Firefox/Profiles/default.dcc/extensions/JSLib installs one of two ways depending on the package you choose to install. The two current distribtions are:
jar file - Best for production installs
eg:
~/.mozilla/profile_name/generated.slt/chrome/jslib.jar
normal directory/file archive - Best for a development environment
eg:
~/.mozilla/profile_name/generated.slt/chrome/jslib/
Using JSLIb in your application
To use from a xul page, just paste in the code below:
<script type="application/x-javascript" src="chrome://jslib/content/jslib.js" />This loads the required
jslib.js root library file. This is only a minimal amount of code.
This must be placed on the top of any other scripts used in your application document.
A sample xul page:
<script type="application/x-javascript" src="chrome://jslib/content/jslib.js" />
include method:
<script type="application/x-javascript" src="chrome://jslib/content/jslib.js" />;
Using JSLib in xpcshell
Module Identifiers The curent jslib module identifiers to use when including library modules are:
// io library modules
jslib_io
jslib_filesystem
jslib_file
jslib_fileutils
jslib_dir
jslib_dirutils
// xul dom library modules
jslib_dialog
jslib_window
jslib_routines
// sound library modules
jslib_sound
// utils library modules
jslib_date
jslib_prefs
Example xpcshell session using the date module identifier:
Installing jslib w/ your application The sample code below is for a mozdev project where your xpi file is located in
/downloads/xpi/.
Your xpi file name is called myproject.xpi. You will need to modify this sample to suite your
specific needs.
Here is some sample code you can paste in your application html install page:
JSLib Samples The sample code above can be found in
/jslib/content/libraries/samples
To see the samples in action just launch jslib as shown below.
Launching jslib from a shell or command prompt.
Linux/Unix/OSX
# from mozilla bin dir ./mozilla -chrome chrome://jslib/content/samples/test.xul
Windows
# from mozilla bin dir mozilla.exe -chrome chrome://jslib/content/samples/test.xul
Turning Dump On and Off If you are using a non-debug version of Mozilla and want to see debug output from methods such as
jslibDebug(), jslibPrint, or dump(), you can use
jslib_turnDumpOn() and jslib_turnDumpOff. These methods will
on the fly turn dump on or off.
eg:
// to turn dump on
jslib_turnDumpOn();
jslibDebug("Hello, this is my debug message")
jslibPrint("Hello, this is my print message")
// to now turn dump off
jslib_turnDumpOff();
XPCOM Methods JSLib provides some useful methods to easily instantiate xpconnect wrapped xpcom classes. The methods are
jslibCreateInstance(), jslibGetService, and
jslibQI().
eg:
// create an nsIFile instance
var obj = jslibCreateInstance("@mozilla.org/file/local;1", "nsIFile");
jslibPrint(obj);
// QI class for nsILocalFile
obj = jslibQI(obj, "nsILocalFile");
jslibPrint(obj);
// get nsIWindowMediator service
var wm = jslibGetService("@mozilla.org/appshell/window-mediator;1",
"nsIWindowMediator");
jslibPrint(wm);
Using jsLib from a local "file://" To use jsLib from a local file. you need to set two user_prefs in your "prefs.js" file.
pref("capability.principal.codebase.p0.granted", "UniversalXPConnect");
pref("capability.principal.codebase.p0.id", "file:///");
then you should be able to run jslib out of the box from a local ".xul" file.
eg: ./mozilla file:///tmp/file.xul