public class zk
extends java.lang.Object
$extends(zk.Class, _global_.Map, _global_.Map)
and $package(_global_.String)
.
Refer to jq
for DOM related utilities.
Modifier and Type | Field and Description |
---|---|
static String |
agent
The user agent of the browser.
|
static java.lang.Boolean |
air
Whether it is Adobe AIR.
|
static boolean |
alerting
Indicates whether an OS-level modal dialog is opened.
|
static String |
appName
The application's name, which will be initialized as server-side's
WebApp.getAppName() . |
static boolean |
booted
Indicates whether ZK Client Engine has been booted and created the initial widgets.
|
static String |
build
The build of ZK, such as '08113021'
|
static int |
busy
Indicates if the application is busy.
|
static Offset |
clickPointer
The last position that the mouse was clicked (including left and right clicks).
|
static java.lang.Boolean |
css3
Whether it supports CSS3.
|
static Widget |
currentFocus
The widget that gains the focus now, or null if no one gains focus now.
|
static Window |
currentModal
The topmost modal window, or null if no modal window at all.
|
static Offset |
currentPointer
The position of the mouse (including mouse move and click).
|
static char |
DECIMAL
The character used for decimal sign.
|
static java.lang.Double |
ff
Returns the version as double (only the first two part of the version, such as 3.6) if it is Firefox,
such as Firefox.
|
static java.lang.Double |
gecko
Returns the version as double (only the first two part of the version, such as 3.5)
if it is Gecko-based browsers,
such as Firefox.
|
static char |
GROUPING
The character used for thousands separator.
|
static java.lang.Double |
ie
Returns the DOM API's version
if the browser is Internet Explorer, or null if not.
|
static java.lang.Boolean |
ie9
Whether it is Internet Exploer 9 or later.
|
static java.lang.Double |
iex
Returns the browser's version as double (only the first two part of the version, such as 8)
if the browser is Internet Explorer, or null if not.
|
static Widget |
keyCapture
The widget that captures the keystrokes.
|
static int |
loading
The number of widget packages (i.e., JavaScript files) being loaded
(and not yet complete).
|
static char |
MINUS
The character used to represent minus sign.
|
static boolean |
mounting
Whether ZK Client Engine has been mounting the peer widgets.
|
static Widget |
mouseCapture
The widget that captures the mouse events.
|
static java.lang.Double |
opera
Returns the version as double (only the first two part of the version, such as 10.1) if it is Opera, or null if not.
|
static char |
PER_MILL
The character used for mille percent sign.
|
static char |
PERCENT
The character used for percent sign.
|
static int |
procDelay
The delay before showing the processing prompt (unit: milliseconds).
|
static boolean |
processing
Whether Client Engine is processing something, such as processing
an AU response.
|
static int |
resendTimeout
The timeout for re-sending AU request (unit: milliseconds).
|
static java.lang.Double |
safari
Returns the version as double (only the first two part of the version, such as 533.1) if it is Safari-based, or null if not.
|
static boolean |
spaceless
Indicates whether
Widget.id is always the same
as Widget.uuid . |
static boolean |
tabletUIEnabled
Indicates whether to enable the tablet UI.
|
static int |
tipDelay
The delay before showing a tooltip (unit: milliseconds).
|
static boolean |
touchEnabled
Indicates whether to apply touch mode.
|
static boolean |
unloading
Indicates whether the browser is unloading this document.
|
static String |
version
The version of ZK, such as '5.0.0'
|
Modifier and Type | Method and Description |
---|---|
static Widget |
$()
A shortcut of
Widget.$() function. |
static Map |
$default(Map opts,
Map defaults)
Provides the default values for the specified options.
|
static Class |
$extends(Class sueprclass,
Map members,
Map staticMembers)
Defines a class.
|
static java.lang.Object |
$import(String name)
Imports a class or a package.
|
static java.lang.Object |
$import(String name,
Function fn)
Imports a package or class, and load it if
fn is specified. |
static void |
$intercepts(Class targetClass,
java.lang.Object interceptor)
Intercepts a widget, when specific method has been called, the interceptor would be called first.
|
static Package |
$package(String name)
Defines a package.
|
static void |
$void()
A does-nothing-but-returns-false function.
|
static void |
addDataHandler(String name,
String script)
Adds data attribute handler
|
static boolean |
afterAnimate(Function fn,
int delay)
Executes a function only when no animation is taking place.
|
static void |
afterAuResponse(Function fn)
Adds a function that will be executed after onResponse events are done.
|
static boolean |
afterLoad(Function func)
Declares a function that shall be executed after all requested packages are loaded (i.e.,
loading is 0). |
static void |
afterLoad(String pkgs,
Function func)
Declares a function that shall be executed only if the specified
package(s) are loaded (and
loading is 0). |
static boolean |
afterMount(Function fn,
int delay)
Adds a function that will be executed after the mounting is done.
|
static void |
afterResize(Function fn)
Adds a function that will be executed after all of the onSize events are done.
|
static String |
ajaxResourceURI(String uri,
String version,
Map opts)
Encodes and returns the resource URI from Class-Web Resources (CWR).
|
static String |
ajaxURI(String uri,
Map opts)
Encodes and returns the URI to communicate with the server.
|
static boolean |
animating()
Returns whether there is some animation taking place.
|
static void |
beforeUnload(Function fn,
Map opts)
Adds a function that will be executed when the browser is about to unload the document.
|
static void |
classes()
A map of all classes,
Map<int oid, zk.Class cls> . |
static java.lang.Object |
copy(java.lang.Object dst,
java.lang.Object src)
Copies a map of properties (or options) from one object to another.
|
static java.lang.Object |
copy(java.lang.Object dst,
java.lang.Object src,
Map backup)
Copies a map of properties (or options) from one object to another
and copies the original value to another map.
|
static java.lang.Object |
cut(Map props,
String nm)
Retrieves and removes the value of the specified name of the given map.
|
static void |
debugLog(String msg)
If in debug-js, use console log to display an log message to indicate an debug log.
|
static Class |
define(Class klass,
Map props)
Defines the setter and getter methods.
|
static void |
depends(String a,
String b)
Declare a package that must be loaded when loading another package.
|
static void |
disableESC()
Disable the default behavior of ESC.
|
static void |
enableESC()
Enables the default behavior of ESC (i.e., stop loading from the server).
|
static void |
endProcessing()
Clears a flag,
processing , to indicate that it the processing has done. |
static void |
error(String msg)
Display an error message to indicate an error.
|
static void |
errorDismiss()
Closes all error messages shown by
error(_global_.String) . |
static java.lang.Object |
get(java.lang.Object o,
String name)
Retrieves a value from the specified property.
|
static java.lang.Object |
getDataHandler()
Returns the dataHandler from the given name
|
static String |
getHost(String pkg,
boolean js)
Returns the URI of the server (so called host) for the specified package.
|
static String |
getVersion(String pkg)
Returns the version of the specified package, or null if not available.
|
static boolean |
hasDataHandler()
Test whether the name of the data attribute exists.
|
static void |
isClass(java.lang.Object cls)
Returns if the given JS object is a class (
Class ). |
static boolean |
isLoaded(String pkg,
boolean loading)
Tests if a package is loaded (or being loaded).
|
static void |
isObject(java.lang.Object o)
Returns whether the given JS object is a ZK object (
Object ). |
static boolean |
load(String pkg,
Desktop dt,
Function func)
Loads the specified package(s).
|
static boolean |
load(String pkg,
Function func)
Loads the specified package(s).
|
static zk |
loadCSS(String href,
String id,
String media,
Function the)
Loads a CSS file.
|
static zk |
loadScript(String src,
String name,
String charset,
boolean force,
Function the)
Loads a JavaScript file.
|
static void |
log(java.lang.Object... detailed)
Logs an message for debugging purpose.
|
static Function |
override(Function oldfunc,
Function newfunc)
Overrides a particular method.
|
static java.lang.Object |
override(java.lang.Object dst,
Map backup,
Map src)
Overrides the properties of a map.
|
static java.lang.Object |
override(java.lang.Object dst,
String nm,
java.lang.Object val)
Overrides a particular method or data member.
|
static double |
parseFloat(String v)
Parses a string to a floating number.
|
static int |
parseInt(String v,
int b)
Parses a string to an integer.
|
static java.lang.Object |
set(java.lang.Object dst,
java.lang.Object src,
Array props,
boolean ignoreUndefined)
Sets the given properties from one object to another.
|
static java.lang.Object |
set(java.lang.Object o,
String name,
java.lang.Object value,
java.lang.Object extra)
Assigns a value to the specified property.
|
static void |
setHost(String host,
String resURI,
Array pkgs)
Defines the URL of the host for serving the specified packages.
|
static void |
setScriptLoaded(String name)
Notify ZK that the name of the JavaScript file is loaded.
|
static void |
setVersion(String pkg,
String ver)
Sets the version of the specified package.
|
static void |
stamp()
Logs the information of all stamps made by
stamp(String, boolean) . |
static void |
stamp(String name,
boolean noAutoLog)
Make a time stamp for this momemt; used for performance tuning.
|
static void |
startProcessing(int timeout)
Set a flag,
processing , to indicate that it starts a processing. |
static Desktop |
stateless(String dtid,
String contextURI,
String updateURI,
String reqURI)
Declares the desktop is used for the stateless context.
|
public static int procDelay
Default: 900 (depending on the server's configuration)
public static int tipDelay
public static int resendTimeout
public static Offset clickPointer
public static Offset currentPointer
public static int loading
When the JavaScript files of widgets are loading, you shall not create
any widget. Rather, you can use afterLoad(_global_.String, _global_.Function)
to execute the creation
and other tasks after all required JavaScript files are loaded.
public static int busy
AuCmd0.showBusy(String)
is called,
and decreased when AuCmd0.clearBusy()
is called.
In other words, it is set by the application, and used to
indicate the application (rather than ZK) is busy.public static String appName
WebApp.getAppName()
.
It will be used as title of jq.alert(_global_.String, _global_.Map)
.public static Widget currentFocus
public static Window currentModal
public static boolean mounting
afterMount(_global_.Function, int)
afterMount(_global_.Function, int)
,
processing
,
loading
,
booted
public static boolean processing
startProcessing(int)
is called, and cleaned when endProcessing()
is called.startProcessing(int)
,
loading
,
mounting
public static boolean booted
public static boolean unloading
beforeUnload(_global_.Function, _global_.Map)
is called, this flag is not set yet.public static String version
public static String build
public static String agent
public static java.lang.Double ie
Note: it is DOM API's version, not the browser version.
In other words, it depends on if the browser is running in a compatible mode.
FOr the browser's version, please use iex
instead.
public static java.lang.Double iex
Notice that this is the browser's version, which might not be the
version of DOM API. For DOM API's version, please use ie
instead.
public static java.lang.Boolean ie9
public static java.lang.Double gecko
public static java.lang.Double ff
public static java.lang.Double safari
public static java.lang.Double opera
public static java.lang.Boolean air
public static java.lang.Boolean css3
public static char DECIMAL
public static char GROUPING
public static char MINUS
public static char PER_MILL
public static char PERCENT
public static boolean alerting
public static boolean spaceless
Widget.id
is always the same
as Widget.uuid
.
By default, it is false.
You could enable it if the pure-client approach is taken, since it is more convenient. However, it also means the concept of ID space is no longer valid.
public static boolean tabletUIEnabled
public static boolean touchEnabled
public static Widget keyCapture
doKeyDown_: function () {
zk.keyCapture = this;
this.$supers('doKeyDown_', arguments);
}
Notice that the key capture is reset automatically after processing onKeyUp_.
mouseCapture
public static Widget mouseCapture
doMouseDown_: function () {
zk.mouseCapture = this;
this.$supers('doMouseDown_', arguments);
}
Notice that the mouse capture is reset automatically after processing onMouseUp_.
keyCapture
public static void isClass(java.lang.Object cls)
Class
).cls
- the object to test whether it is a class (aka., a ZK class)public static void isObject(java.lang.Object o)
Object
).o
- the object to test whether it is a ZK objectpublic static java.lang.Object cut(Map props, String nm)
props
- a map of propertiesnm
- the name to retrieve the valuepublic static Package $package(String name)
Notice the package is usually defined automatically by use of WPD, so you're rarely need to use this method.
Example:
var foo = zk.$package('com.foo');
foo.Cool = zk.$extends(zk.Object);
name
- the name of the package.$import(String)
,
load(_global_.String, zk.Desktop, _global_.Function)
public static Class $extends(Class sueprclass, Map members, Map staticMembers)
Example:
zul.Label = zk.$extends(zk.Widget, {
_value: '',
getValue() {
return this._value;
},
setValue(value) {
this._value = value;
}
});
$define
is introduced. It is shortcut to invoke define. For example,
foo.Widget = zk.$extends(zk.Widget, {
_value: '',
$define: {
name: null,
value: null
},
bind_: function () {
//
}
});
is equivalent to
foo.Widget = zk.$extends(zk.Widget, {
_value: '',
bind_: function () {
//
}
});
zk.define(foo.Widget, {
name: null,
value: null
});
is equivalent to
foo.Widget = zk.$extends(zk.Widget, {
_value: '',
getName: function () {
return this._name;
},
setName: function (v) {
this._name = v;
return this;
},
getValue: function () {
return this._value;
},
setValue: function (v) {
this._value = v;
return this;
},
bind_: function () {
//
}
});
sueprclass
- the super class to extend frommembers
- a map of non-static membersstaticMembers
- a map of static members. Ignored if omitted.define(zk.Class, _global_.Map)
,
override(java.lang.Object, _global_.String, java.lang.Object)
public static Map $default(Map opts, Map defaults)
Example:
process: function (opts, defaultOptions) {
opts = zk.$default(opts, defaultOptions);
}
opts = zk.$default(opts, {timeout: 100, max: true});
//timeout and max are assigned to opts only if no such property found in opts
opts
- a map of options to which default options will be added
If null, an empty map is created automatically.defaults
- a map of default optionscopy(java.lang.Object, java.lang.Object, _global_.Map)
public static java.lang.Object override(java.lang.Object dst, String nm, java.lang.Object val)
zk.override(zul.inp.Combobox.prototype, "open",
function () {
this.$open.apply(this, arguments);
//do whatever you want
});
dst
- the destination object to overridenm
- the method name to overrideval
- the value of the method. To override a method, it has
to be an instance of Function
.override(Function, Function)
,
override(Object, Map, Map)
public static Function override(Function oldfunc, Function newfunc)
var superopen = zk.override(zul.inp.Combobox.prototype.open,
function () {
superopen.apply(this, arguments);
//do whatever you want
});
oldfunc
- the old function that will be replacednewfunc
- the new function that will replace the old functionoverride(Object, Map, Map)
public static java.lang.Object override(java.lang.Object dst, Map backup, Map src)
copy(java.lang.Object, java.lang.Object, _global_.Map)
, except
$extends(zk.Class, _global_.Map, _global_.Map)
) well.
For example, the members of all deriving classes will be overriden too,
if necessary.Example,
var _xCombobox = {}
zk.override(zul.inp.Combobox.prototype, _xCombobox, {
redrawpp_: function (out) {
if (!_redrawpp(this, out))
_xCombobox.redrawpp_.apply(this, arguments); //call the original method
},
open: function () {
_renderpp(this);
_xCombobox.open.apply(this, arguments); //call the original method
}
});
dst
- the destination object to overridebackup
- the map used to store the original members (or properties)src
- the source map providing the new membersoverride(Function, Function)
,
override(Object, String, Object)
public static Class define(Class klass, Map props)
Notice that you rarely need to invoke this method directly. Rather, you can specify them in a property named $define, when calling #$extends.
For example, the following code snippet
zk.define(zul.wgt.Button, {
disabled: null
});
is equivalent to define three methods, isDisabled, getDisabled and setDisabled, as follows:
zul.wgt.Button = zk.$extends(zk.Widget, {
isDisabled: _zkf = function () {
return this._disabled;
},
isDisabled: _zkf,
setDisabled: function (v) {
this._disabled = v;
return this;
}
});
If you want to do something when the value is changed in the setter, you can specify a function as the value in the props argument. For example,
zk.define(zul.wgt.Button, {
disabled: function () {
if (this.desktop) this.rerender();
}
});
will cause the setter to be equivalent to
setDisabled: function (v, opts) {
this._disabled = v;
if (this._disabled !== v || (opts && opts.force))
if (this.desktop) this.rerender();
return this;
}
If you want to pre-process the value, you can specify a two-element array. The first element is the function to pre-process the value, while the second is to post-process if the value is changed, as described above. For example,
zk.define(zul.wgt.Button, {
disabled: [
function (v) {
return v != null && v != false;
},
function () {
if (this.desktop) this.rerender();
}
]
});
will cause the setter to equivalent to
setDisabled: function (v) {
v = v != null && v != false;
this._disabled = v;
if (this._disabled !== v || (opts && opts.force))
if (this.desktop) this.rerender();
return this;
}
Notice that when the function (specified in props) is called, the arguments are the same as the arguments passed to the setter (including additional arguments. For example, if button.setDisabled(true, false) is called, then the specified function is called with two arguments, true and false. In additions, as shown above, you can enforce the invocation of the function by passing a map with force as true.
wgt.setSomething(somevalue, {force:true});
klass
- the class to define the membersprops
- the map of members (aka., properties)$extends(zk.Class, _global_.Map, _global_.Map)
public static void $void()
public static int parseInt(String v, int b)
It is the same as the built-in parseInt method except it never return NaN (rather, it returns 0).
v
- the text to parseb
- represent the base of the number in the string. 10 is assumed if omitted.public static double parseFloat(String v)
It is the same as the built-in parseFloat method except it never return NaN (rather, it returns 0).
v
- the text to parsepublic static java.lang.Object set(java.lang.Object dst, java.lang.Object src, Array props, boolean ignoreUndefined)
zk.set(dst, src, ["foo", "mike"]);
If dst has a method called setFoo and src has method called getMike,
then it is equivalent to
dst.setFoo("foo", src["foo"]);
dst["mike"] = src.getMike();
dst
- the destination object to copy properties tosrc
- the source object to copy properties fromprops
- an array of property names (String)ignoreUndefined
- whether to ignore undefined.
Optional (if not specified, false is assumed).
If true and src[name] is undefined, then dst[name] won't be assigned.copy(java.lang.Object, java.lang.Object, _global_.Map)
public static java.lang.Object set(java.lang.Object o, String name, java.lang.Object value, java.lang.Object extra)
For example, zk.set(obj, "x", 123)
:
If setX is defined in obj, obj.setX(123) is called.
If not defined, obj.x = 123 is called.
Anotehr example:
zk.set(o, 'value', true); //set a single property
o
- the object to assign values toname
- the property's namevalue
- the property's valueextra
- an extra argument to pass to the setX method
as the extra argument (the second argument).
For example, zk.set(obj, 'x', 123, true)
invokes obj.setX(123, true)
.get(java.lang.Object, _global_.String)
public static java.lang.Object get(java.lang.Object o, String name)
For example, zk.get(obj, "x")
:
If getX or isX is defined in obj, obj.isX() or obj.getX() is returned.
If not defined, obj.x is returned.
Another example:
zk.get(o, 'value');
o
- the object to retreive value fromname
- the namepublic static void startProcessing(int timeout)
processing
, to indicate that it starts a processing. It also shows a message to indicate "processing" after the specified timeout.
Example:
zk.startProcessing(1000); //do the lengthy operation zk.endProcessing();
timeout
- the delay before showing a message to indicate "processing".processing
,
endProcessing()
public static void endProcessing()
processing
, to indicate that it the processing has done. It also removes a message, if any, that indicates "processing".
Example:
zk.startProcessing(1000);
//do the lengthy operation
zk.endProcessing();
startProcessing(int)
public static void disableESC()
To enable ESC, you have to invoke enableESC()
and the number
of invocations shall be the same.
enableESC()
public static void enableESC()
disableESC()
public static void error(String msg)
zk.error('Oops! Something wrong:(');
msg
- the error messageerrorDismiss()
,
log(java.lang.Object...)
,
stamp(String, boolean)
public static void debugLog(String msg)
zk.debugLog('Oops! Something wrong:(');
msg
- the warning messagepublic static void errorDismiss()
error(_global_.String)
.
Example:
zk.errorDismiss();
error(_global_.String)
public static void log(java.lang.Object... detailed)
zk.log('reach here');
zk.log('value is", value);
detailed
- varient number of arguments to logstamp(String, boolean)
public static void stamp()
stamp(String, boolean)
.
After the invocation, all stamps are reset.public static void stamp(String name, boolean noAutoLog)
log(java.lang.Object...)
).name
- the unique name to represent a time stampnoAutoLog
- whehter not to auto log the result.
If omitted or false, stamp()
will be invoked automatically
to log the info and clean up all stamps after mounting is completed.
Turn it off, if you prefer to invoke it manually.public static String ajaxURI(String uri, Map opts)
document.createElement("script").src = zk.ajaxURI('/web/js/com/foo/mine.js',{au:true});
uri
- - the URI related to the AU engine. If null, the base URI is returned.opts
- [optional] the options. Allowed values:public static String ajaxResourceURI(String uri, String version, Map opts)
var res = zk.ajaxResourceURI('/js/my/path/res.css');
uri
- the resource URI.version
- [optional] the version string to build the cache-friendly URI. If none is set, use zk.build by default.opts
- [optional] the options. Allowed values:public static Desktop stateless(String dtid, String contextURI, String updateURI, String reqURI)
dtid
- the ID of the desktop to createcontextURI
- the context URI, such as /zkdemoupdateURI
- the update URI, such as /zkdemo/zkaureqURI
- the URI of the request path.public static void addDataHandler(String name, String script)
name
- the attribute namescript
- the JS contentpublic static boolean hasDataHandler()
public static java.lang.Object getDataHandler()
public static void $intercepts(Class targetClass, java.lang.Object interceptor)
Example,
zk.$intercepts(zul.inp.Combobox, {
open: function () {
var context = this.$getInterceptorContext$();
console.log('open');
context.stop = false;
}
});
In the interceptor function, you could call this.$getInterceptorContext$() to get the context object. The context object has several properties, it would help you the deal with the interceptor:
targetClass
- the destination object to overrideinterceptor
- the interceptor map corresponds to the widget methodspublic static void classes()
Map<int oid, zk.Class cls>
.public static java.lang.Object $import(String name, Function fn)
fn
is specified.
It returns null if the package or class is not defined yet and
fn
is null.
If an additional function, fn
is specified,
this method assumes name
is a class and it will load the package of the class first.
If not found. Then, invoke the function after the class is loaded.
For example, the following creates a Listbox widget after loading
the package.
zk.$import('zul.sel.Listbox', function (cls) {new cls();});
name
- The name of the package or the class.fn
- The function to call after the class is loaded.
If specified, it assumes name
is a class, and it will
load the package of the class automatically.
In additions, the function is called with the class as the argument.Package
) or a class (Class
)$package(_global_.String)
,
$import(String)
,
load(_global_.String, zk.Desktop, _global_.Function)
public static java.lang.Object $import(String name)
Example:
var foo = zk.$import('com.foo');
var cool = new foo.Cool();
var Cool = zk.$import('com.foo.Cooler');
var cooler = new Cooler();
name
- The name of the package or the class.Package
) or a class (Class
)$package(_global_.String)
,
load(_global_.String, zk.Desktop, _global_.Function)
,
$import(String, Function)
public static java.lang.Object copy(java.lang.Object dst, java.lang.Object src, Map backup)
var backup = {};
zk.copy(n.style, {
visibility: 'hidden',
position: 'absolute',
display: 'block'
}, backup);
try {
//do whatever
} finally {
zk.copy(n.style, backup);
}
Notice that copy(java.lang.Object, java.lang.Object, _global_.Map)
copies the properties directly regardless
if the target object has a setter or not. It is fast but if you want
to go thru the setter, if any, use set(Object, Object, Array, boolean)
instead.
dst
- the destination object to copy properties tosrc
- the source object to copy properties frombackup
- the map to stor the original valuepublic static java.lang.Object copy(java.lang.Object dst, java.lang.Object src)
zk.copy(Array.prototoype, {
$addAll: function (o) {
return this.push.apply(this, o);
}
});
Notice that copy(java.lang.Object, java.lang.Object, _global_.Map)
copies the properties directly regardless
if the target object has a setter or not. It is fast but if you want
to go thru the setter, if any, use set(Object, Object, Array, boolean)
instead.
dst
- the destination object to copy properties tosrc
- the source object to copy properties frompublic static boolean animating()
afterMount(_global_.Function, int)
.afterAnimate(_global_.Function, int)
public static boolean afterAnimate(Function fn, int delay)
If the delay argument is not specified and no animation is taking place,
the function is executed with setTimeout(fn, 0)
.
fn
- the function to executedelay
- how many milliseconds to wait before execute if
there is no animation is taking place. If omitted, 0 is assumed.
If negative, the function is executed immediately.animating()
public static Widget $()
Widget.$()
function.
Note: Widget is the same as zk.Widget
.Widget.$(Object, Map)
public static boolean isLoaded(String pkg, boolean loading)
pkg
- the package nameloading
- [Optional; default: false]
If true is specified, this method returns true if the package is loaded or being loaded. If false or omitted, it returns true only if the package is loaded.load(_global_.String, zk.Desktop, _global_.Function)
public static boolean load(String pkg, Desktop dt, Function func)
The loading of a package is asynchronous, so you cannot create the widget immediately. Rather, use the func
argument, func, or use #afterLoad to execute.
pkg
- the package namedt
- [optional] the desktop used to get URI of the JavaScript file (ajaxURI(_global_.String, _global_.Map)
). If null, the first desktop is assumed.func
- [optional] the function to execute after all packages are loaded. Ignored if omitted. Notice that func won't be executed until all requested packages are loaded; not just what are specified here.load(String, Function)
public static boolean load(String pkg, Function func)
The loading of a package is asynchronous, so you cannot create the widget immediately. Rather, use the func
argument, func, or use #afterLoad to execute.
zk.load('zul.utl', function () {
new zul.utl.Timer();
});
pkg
- the package namefunc
- [optional] the function to execute after all packages are loaded. Ignored if omitted. Notice that func won't be executed until all requested packages are loaded; not just what are specified here.public static zk loadScript(String src, String name, String charset, boolean force, Function the)
src
- the URL of the JavaScript file.name
- the name to shown up in the progressing dialog.
Specify a non-empty string if you want ZK not to create widgets until
this file is loaded. Ignored if not specified or null.
If you specify a name here, you have to call setScriptLoaded(_global_.String)
when the script is loaded. Otherwise, @{link zk#loading} won't be zero
and ZK Client Engine is halted.charset
- the charset. UTF-8 is assumed if null.force
- the script to be loaded. (no matter it is loading or loaded)the
- function to execute after the JavaScript file loaded. (since 9.6.3)public static zk loadCSS(String href, String id, String media, Function the)
href
- the URL of the CSS file.id
- the identifier. Ignored if not specified.media
- the media attribute. Ignored if not specified.the
- function to execute after the CSS file loaded. (since 9.6.3)public static String getVersion(String pkg)
pkg
- the package namepublic static void setVersion(String pkg, String ver)
pkg
- the package namever
- the versionpublic static void depends(String a, String b)
Notice that it doesn't guarantee the loading order of the two packages. Thus, it is better to do in #afterLoad if a code snippet depends on both packages.
a
- the name of the package that depends another package. In other words, calling #loading against this package will cause dependedPkgnn being loaded.b
- the name of the package that shall be loaded if another package is being loaded.
In other words, it reads "a depends on b".afterLoad(_global_.String, _global_.Function)
public static void afterLoad(String pkgs, Function func)
loading
is 0). Notice that it won't cause the package(s) to execute. Rather, it defers the execution of the specified function until someone else loads the package (by use of load(_global_.String, zk.Desktop, _global_.Function)
).
See also JavaScript Packaging
To know whether all requested packages are loaded (i.e., ZK is not loading any package), you can check loading
if it is 0.
Notice that functions specified in the second format execute before those specified in the first format.
Example
zk.afterLoad('foo', function() {new foo.Foo();});
zk.afterLoad('foo1,foo2', function() {new foo1.Foo(foo2.Foo);});
zk.afterLoad(function() {});
pkgs
- the package(s) that the specified function depends on. In other words, the function is evaluated only if the package(s) are loaded. If you want to specify multiple packages, separate them with comma.func
- the function to executeafterLoad(Function)
,
depends(_global_.String, _global_.String)
,
load(_global_.String, zk.Desktop, _global_.Function)
public static boolean afterLoad(Function func)
loading
is 0).
If all packages has been loaded, the function is executed immediately
and this method returns true.func
- the function to executeafterLoad(String, Function)
,
depends(_global_.String, _global_.String)
,
load(_global_.String, zk.Desktop, _global_.Function)
public static String getHost(String pkg, boolean js)
ZK Client Engine loads the packages from the same server that returns the HTML page. If a package might be loaded from a different server, you can invoke #setHost to specify it and then #getHost will return the correct URL for the specified package.
pkg
- the package namejs
- whether the returned URL is used to load the JavaScript file.
load(_global_.String, zk.Desktop, _global_.Function)
will pass true to this argument to indicate the URI is used to load the JavaScript file. However, if you just want the URL to send the request back (such as json-p with jQuery's json), don't pass anything (or pass false) to this argument.setHost(_global_.String, _global_.String, _global_.Array)
public static void setHost(String host, String resURI, Array pkgs)
host
- the host, such as http://www.zkoss.org.resURI
- the resource URI, such as /zkdemo/zkau,
that is used to load the JavaScript filespkgs
- an array of pckage names (String)getHost(_global_.String, boolean)
public static void setScriptLoaded(String name)
loadScript(_global_.String, _global_.String, _global_.String, boolean, _global_.Function)
, such
that ZK Client knows if a JavaScript file is loaded.name
- the name of the JavaScript file.
It must be the same as the one passed to loadScript(_global_.String, _global_.String, _global_.String, boolean, _global_.Function)
.public static void beforeUnload(Function fn, Map opts)
To remove the function, invoke this method by specifying remove to the opts argument.
zk.beforeUnload(fn, {remove: true});
fn
- the function to execute.
The function shall return null if it is OK to close, or a message (String) if it wants to show it to the end user for confirmation.opts
- [optional] a map of options. Allowed vlaues:public static boolean afterMount(Function fn, int delay)
By mounting we mean the creation of the peer widgets under the control of the server. To run after the mounting of the peer widgets,
If the delay argument is not specified and no mounting is taking place,
the function is executed with setTimeout(fn, 0)
.
fn
- the function to execute after mounteddelay
- (since 5.0.6) how many milliseconds to wait before execute if
there is no mounting taking place. If omitted, 0 is assumed.
If negative, the function is executed immediately (if no mounting is taking place).mounting
,
afterLoad(_global_.String, _global_.Function)
,
afterAnimate(_global_.Function, int)
public static void afterResize(Function fn)
Here lists the execution phases:
fn
- the function to execute after resizedpublic static void afterAuResponse(Function fn)
fn
- the function to execute after au responsesCopyright © 2005-2023 Potix Corporation. All Rights Reserved.