ldcvmgr v0.0.20
ldcvmgr
ldcover manager.
Installation
npm install --save ldcvmgrUsage
include required js file, and create a ldcvmgr instance:
ldcvmgr = new ldcvmgr({ ... });
ldcvmgr.get("some-cover-name").then( ... );constructor options:
path: where to find cache-missed ldcover html files. default/modules/cover- more information in the section below.
loader: ldLoader compatible object for loading indicator when ldcvmgr is fetching remote ldcover html files.- default to a fullscreen ldLoader spinner, with class
ldld full.
- default to a fullscreen ldLoader spinner, with class
autoInit: default false.initcalled automatically when set to truemanager: block manager for loading@/plotdb/blockstyle ldcovererrorCover: customized cover for error handler. can either be a string or a@plotdb/blockdefinition object.baseZ:baseZforldcover. if omitted, will bemodalifzmgris provided; otherwise will be3000.zmgr: optional.zmgrforldcover. see thezmgrpackage for more information.
API
get(name, param): popup a ldcovername, and expect return value from it.- when
nameis a string, look up a ldcover namednamein local cache or in "#{@path}/#name"- will also lookup up in local DOM for name in this selector:
.ldcvmgr[data-name]
- will also lookup up in local DOM for name in this selector:
- when
nameis an object, load it by@plotdb/blockmanager.- interface of the loaded block should be a
ldcoverobject. - when available,
{zmgr, baseZ}will be passed as block data, which should be used to maintain z-index.
- interface of the loaded block should be a
- when
paramis provided, it will be sent toonevent as params.
- when
set(name, param): resolve popped ldcovernamewithparamon(name, callback({...})): listen tonameevent. Following events are available:on: fired when some ldcover is toggled on. callback params:- node: ldcover dom root.
- params: additional parameters provided when
getis called. - name: toggled ldcover name
off: fired when some ldcover is toggled off. similar params withon.
lock(name): popup a ldcovernamewithget, and force lock to prevent dismissing.purge(name): clear cache for ldcovername.toggle(name,value,param): toggle ldcovernamewith state based on the value (true or false)- optional
parampassed toonevent, just likeget.
- optional
getcover(name): returnldcoverinstance of ldcovername.getdom(name): return DOM root of ldcovername.is-on(name): return true if ldcovernameis on.
Customizing Path
The path option in constructor options should be either
- a string, representing the relative root of all ldcover html
- a function accepting a string
you can set path as function to make a more customizable behavior of ldcvmgr. For example, you can define name as:
locale@variant@nameand invoke ldcvmgr.get like this:
zh-tw@depart-1024@logoutthis is an abstract name and there is nothing to do with server file structure, however you can convert it with path function into something like this:
/ldcv/zh-tw/depart-1024/logout.htmlfurthermore, you can also config your reverse proxy to lookup files ( nginx config for example ):
location /ldcv/(?<lc>.+)/(?<dep>.+)/(?<name>.+) {
try_files /intl/$lc/ldcv/$dep/$name.html /intl/$lc/ldcv/generic/$name.html /ldcv/generic/$name.html =404;
}Toggling without scripting
By auto-init and adding data-ldcvmgr-toggle attributes, you can toggle ldcover automatically when the node with required attribute clicked. Content of the attribute will be used to look up ldcover, which can be either:
- a string, doesn't contain
:- will be treated as a plain ldcover name. - a string, contains
:- will be treated as an id of a block, and converted back to a block definition object.
LICENSE
MIT
9 months ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago