InterMine JavaScript API Loader
Note See also GitHub repo for source code.
Note If you are loading JavaScript libraries on a page, you should use a loader (count of 1). Why not use ours?
#
PurposeTo simplify loading of CSS and JS libraries. The API Loader automatically works out the order the libraries should be loaded based on dependencies between them. It also skips libraries that already exist on a page or that pass a specific check.
#
How to useNote If you are passing a string or an array as the first parameter into the library, these are @deprecated but still working for backwards compatibility.
First you require the API Loader. You can, for example, use the following shorthand notation that always points to the latest version.
Now, you can use the loader by passing in an object that looks for example like so:
The object works like so:
- You pass in either a
js
or acss
object based on whether you are requesting JavaScript or CSS libraries (or both). - The key inside the object, like
jQuery
then refers to your library. If this key is on awindow
object (as is the case with jQuery library), we won't load the library since it already exists. - If you do not like the previous check and want something more robust, pass a sync function under the
test
key. Returntrue
if a library should NOT be loaded. path
represents the URL pointing to the library.- Use
depends
key, passing an array if a library depends on other libraries in your list. In the example, you can see thatBackbone
depends onjQuery
and_
(underscore.js). The appropriate loading order will be worked out from this. - Check the
err
variable passed in the callback function (second parameter).