require
require is a library for asynchronous reference to Javascript, html, css.
Building & Testing
Current build process uses Gulp, and Karma related repos.
build
$ npm i -g gulp-cli karma-cli
$ npm install
$ gulp # or
$ gulp build # to only build the source, or
$ gulp demo # to only build the demo
test
$ npm run test
Sample
add "script" tag in your html file:
require a javascript modue:
require;
require a css modue:
//load css for documentrequire; //load css for domrequire; //load css with domnode;
remove a css modue:
requirecss;
require a html modue:
//load html for domrequire; //load html with domnode;
require js,html,css modue:
;
API
◆ require.js(modules, [options, callback])
require one or more javascript files.
parameters
modules:string
or array
the javascript path
options: object
-noCache:
boolean
default isfalse
-reload:
boolean
default isfalse
-sequence:
boolean
default isfalse
. if this value istrue
and modules isarray
, they will load in order, otherwise the load order is not guaranteed.
-doc:
HTMLDocument
default isdocument
callback: function
this Callback function, Receives the modules array as arguments.
-modules[i].module: this javascript path
-modules[i].id: a uuid for this module
example
require; require;
◆ require.css(modules, [options, callback])
require one or more css files.
parameters
modules:string
or array
the css path
options: object
-noCache:
boolean
default isfalse
-reload:
boolean
default isfalse
-sequence:
boolean
default isfalse
. if this value istrue
and modules isarray
, they will load in order, otherwise the load order is not guaranteed.
-dom:
HTMLElement
orstring
orarray
default isnull
, this value can be HTMLElement or css selector. If this value is supplied, css will take effect on this dom object.
-doc:
HTMLDocument
default isdocument
callback: function
this Callback function, Receives the modules array as arguments.
-modules[i].module: this css path
-modules[i].id: a uuid for this css module
-modules[i].style: a HTMLStyleElement
example
require; require; document;
◆ require.css.remove(modules, [doc])
remove a css (required by "require.css") from document
parameters
module:string
the css path, same as require.css; or thie css module uuid (received in the callback function when require.css).
doc:HTMLDocument
default is document
.
◆ require.html(modules, [options, callback])
require one or more html files.
parameters
modules:string
or array
the html path
options: object
-noCache:
boolean
default isfalse
-reload:
boolean
default isfalse
-sequence:
boolean
default isfalse
. if this value istrue
and modules isarray
, they will load in order, otherwise the load order is not guaranteed.
-dom:
HTMLElement
orstring
orarray
default isnull
, this value can be HTMLElement or css selector. If this value is supplied, Html content will be append to these doms
-doc:
HTMLDocument
default isdocument
-position:
string
default isbeforeend
. where this html appended. this value can bebeforebegin
afterbegin
beforeend
afterend
callback: function
this Callback function, Receives the modules array as arguments.
-modules[i].module: this html path
-modules[i].id: a uuid for this html module
-modules[i].data: thie html text
example
require; require; document;
◆ require(modules, [options, callback])
require one or more html, css, javascript files.
parameters
modules:object
the html, css, javascript path.
-html:
string
orarray
the html path, like require.html modules
-css:
string
orarray
the css path, like require.css modules
-js:
string
orarray
the javascript path, like require.js modules
options: object
see require.html options
callback: function
this Callback function, Receives the htmls array, styles array and modules array as arguments.
-htmls: see require.html callback
-styles: see require.css callback
-modules: see require.js callback