The core of My Library consists of one main file and three optional extensions. The main file must appear first and is typically included in the head element. The main file may be downloaded in minified form or tailored to specific needs with the online builder. The optional extensions are downloaded separately and are typically included just before the end of body element. See the downloads page for more information.
This is an example of the typical structure:
<html> <head> ... <script type="text/javascript" src="mylib-min.js"></script> ... </head> <body> ... <script type="text/javascript" src="mylib-unclip.js"></script> <script type="text/javascript" src="mylib-fix.js"></script> <script type="text/javascript" src="mylib-domready.js"></script> </body> </html>
Note that the unclip and fix extensions are for the slide/clip effects and fixed positioning respectively.
The preceding example assumes that functions of the API will be called during page load. If this is not the case, then it is preferable to use this structure:
<html> <head> ... </head> <body> ... <script type="text/javascript" src="mylib-min.js"></script> <script type="text/javascript" src="mylib-unclip.js"></script> <script type="text/javascript" src="mylib-fix.js"></script> <script type="text/javascript" src="mylib-domready.js"></script> </body> </html>
Add-ons are downloaded separately and extend the functionality of My Library. The files must be included after the main file.
This example shows the structure of a document that makes use of the Debug add-on:
<html> <head> ... <script type="text/javascript" src="mylib-min.js"></script> <script type="text/javascript" src="mylib-debug.js"></script> ... </head> <body> ... <script type="text/javascript" src="mylib-unclip.js"></script> <script type="text/javascript" src="mylib-domready.js"></script> </body> </html>
This example assumes that functions added by the Debug add-on will be required during page load.
The API is simply a collection of functions. The functions are encapsulated as properties of a global API object to prevent namespace collisions with other scripts. For reasons of performance, the structure of the API object is largely flat. See the API Reference for more information.
The optional object wrappers adds several global constructor functions that provide an OOP interface for My Library and enable the chaining of API functions. See the Object Reference for more information.
Calling applications should always detect methods of the API as the interface adapts to its environment, though it is not strictly necessary in many cases (most features degrade only in very old browsers). Leaving API feature detection out will likely do no worse (and likely better) than other libraries and frameworks, which have no capabilities to deal with older or otherwise lacking environments (and must be constantly rewritten to appear to work in the latest ones). However, with a small amount of additional effort, applications can be made to withstand even the harshest and most unexpected environments, safely bailing out when required features are unavailable (or lacking). There are no guarantees, but applications that utilize appropriate feature testing have the best chance to hold up in the future.
For example, an application that requires the setOpacity and addStyleRule functions would be wrapped in a conditional utilizing the areFeatures like this:
var API; // In case library script failed to load
if (API && API.areFeatures('setOpacity', 'addStyleRule')) {
// Application
}
...which is equivalent to:
var API; // In case library script failed to load
if (API && API.setOpacity && API.addStyleRule) {
// Application
}
var D, E; // In case library script failed to load
if (D && D().areFeatures('addStyleRule') && E && E().areFeatures('setOpacity')) {
// Application
}
...which is equivalent to:
var D, E; // In case library script failed to load
if (D && D.prototype.addStyleRule && E && E.prototype.setOpacity) {
// Application
}
There are three types of features: immediate, deferred and hybrid.
Immediate functions and methods may be feature detected and called during page load.
Deferred functions and methods may not be feature detected or called until the document is ready. See the attachDocumentReadyListener function for more information.
Hybrid functions and methods are rare. An example is the changeImage function. These functions and methods are created immediately, but may be replaced with augmented versions when the document is ready. It is recommended that these function and methods be treated as if they were deferred as they will likely be changed to such in the future.