public class jq
extends java.lang.Object
jq
function.
For example, jq('#id');
ZK 5 Client Engine is based on jQuery.
It inherits all functionality provided by jQuery. Refer to jQuery documentation
for complete reference. However, we use the global function called jq
to represent jQuery. Furthermore, for documentation purpose,
we use @{link jq} to represent the object returned by the jq
function.
Notice that there is no package called _
.
Rather, it represents the global namespace of JavaScript.
In other words, it is the namespace of the window
object
in a browser.
jq
jq(Object selector, Object context);
Refer jQuery as
jq
First of all, the jQuery class is referenced as
jq()
, and it is suggested to use jq instead of $ or jQuery when developing a widget, since it might be renamed later by an application (say, overridden by other client framework). Here is an example uses jq:jq(document.body).append("");
Dual Objects
To extend jQuery's functionally, each time
jq(...)
orzk(...)
is called, an instance ofjq
and an instance ofjqzk
are created. The former one provides the standard jQuery API plus some minimal enhancement as described below. The later is ZK's addions APIs.You can retrieve one of the other with
zk
andjqzk.jq
.jq('#abc').zk; //the same as zk('#abc') zk('#abc').jq; //the same as jq('#abc');
Extra Selectors
@tagName
jq
is extended to support the selection by use of ZK widget's tagName. For example,jq('@window');
Notice that it looks for the ZK widget tree to see if any widget whose className ends with
window
.If you want to search the widget in the nested tag, you can specify the selector after @. For example, the following searches the space owner named x, then y, and finally z
or search the element from the given attribute of the widget, you can specify the selector as follows. For example,jq('@x @y @z');
jq('@window[border="normal"]')
$id
jq
is extended to support the selection by use of widget's ID (Widget.id
), and then DOM element's ID. For example,jq('$xx');
Notice that it looks for any bound widget whose ID is xx, and select the associated DOM element if found.
If you want to search the widget in the inner ID space, you can specify the selector after $. For example, the following searches the space owner named x, then y, and finally z
or advanced search combine with CSS3 and @, you can specify like this.jq('$x $y $z');
jq('@window[border="normal"] > $x + div$y > @button:first');
A widget
jq
is extended to supportWidget
. If the selector is a widget,jq
will select the associated DOM element of the widget.jq(widget).after(''); //assume widget is an instance of
Widget
In other words, it is the same as
jq(widget.$n()).after('');
Extra Contexts
The
zk
contextjq('foo', zk);
With the zk context, the selector without any prefix is assumed to be the identifier of ID. In other words, you don't need to prefix it with '#'. Thus, the above example is the same as
jq('#foo')
Of course, if the selector is not a string or prefix with a non-alphnumeric letter, the zk context is ignored.
Extra Global Functions
The
zk
function
jq
zk(Object selector);It is the same as
jq(selector, zk).zk
. In other words, it assumes the zk context and returns an instance ofjqzk
rather than an instance ofjq
.Other Extension
jq
- DOM utilities (such as,innerX()
jqzk
- additional utilities tojq
.Event
- the event object passed to the event listenerNot override previous copy if any
Unlike the original jQuery behavior, ZK's jQuery doesn't override the previous copy, if any, so ZK can be more compatible with other frameworks that might use jQuery. For example, if you manually include a copy of jQuery before loading ZK Client Engine,
jQuery
will refer to the copy of jQuery you included explicitly. To refer ZK's copy, always usejq
.
Modifier and Type | Method and Description |
---|---|
static Array |
$$(String id,
String subId)
Returns an array of
DOMElement that matches. |
void |
after(java.lang.Object content,
Desktop desktop)
Insert content after each of the matched elements.
|
static void |
alert(String msg,
Map opts)
Shows up a message.
|
void |
append(java.lang.Object content,
Desktop desktop)
Append content to inside of every matched element.
|
void |
before(java.lang.Object content,
Desktop desktop)
Insert content before each of the matched elements.
|
static Map |
borders()
A map of the border style names: {l: 'border-left', t: 'border-top'...}.
|
static boolean |
clearSelection()
Clears the current selection in the browser window.
|
static boolean |
confirm()
It is the same as
window.confirm , except it will set
zk.alerting so widgets know to ignore onblur (since the focus will be back later). |
static String |
css(DOMElement elem,
String name,
String extra)
An override function that provide a way to get the style value where is
defined in the CSS file or the style object, rather than the computed value.
|
static String |
d2j(Date d)
Marshalls the Date object into a string such that it can be sent
back to the server.
|
static void |
doSyncScroll()
To invoke the
doSyncScroll method of the registered objects. |
jq |
empty()
Removes all children of the matched element from the DOM.
|
static java.lang.Object |
evalJSON(String s)
Decodes a JSON string to a JavaScript object.
|
static Map |
filterTextStyle(Map styles,
Array plus)
Returns the text-relevant style of the specified styles
(same as HTMLs.getTextRelevantStyle in Java).
|
static String |
filterTextStyle(String style,
Array plus)
Returns the text-relevant style of the specified style
(same as HTMLs.getTextRelevantStyle in Java).
|
static void |
focusOut()
Move the focus out of any element.
|
static DOMElement |
head()
Returns the head element of this document.
|
jq |
hide()
Hides all matched elements from the DOM.
|
static int |
innerHeight()
Returns the height of the viewport (visible part) of the browser window.
|
static int |
innerWidth()
Returns the width of the viewport (visible part) of the browser window.
|
static int |
innerX()
Returns the X coordination of the visible part of the browser window.
|
static int |
innerY()
Returns the Y coordination of the visible part of the browser window.
|
static boolean |
isAncestor(DOMElement p,
DOMElement c)
Tests if one element (p) is an ancestor of another (c).
|
static boolean |
isOverlapped(Offset ofs1,
Offset dim1,
Offset ofs2,
Offset dim2)
Returns if the specified rectangles are overlapped with each other.
|
static boolean |
isOverlapped(Offset ofs1,
Offset dim1,
Offset ofs2,
Offset dim2,
int the)
Returns if the specified rectangles are overlapped with each other.
|
static Date |
j2d(String s)
Unmarshalls the string back to a Date object.
|
static Map |
margins()
A map of the margin style names: {l: 'margin-left', t: 'margin-top'...}.
|
static DOMElement |
newFrame(String id,
String src,
String style)
Creates an IFRAME element with the specified ID, src and style.
|
static DOMElement |
newHidden(String name,
String value,
DOMElement parent)
Creates a HIDDEN element
|
static DOMElement |
newStackup(DOMElement el,
String id,
DOMElement anchor)
Creates a 'stackup' (actually, an iframe) that makes an element
(with position:absolute) shown above others.
|
static String |
nodeName(DOMElement el)
Returns the node name of the specified element in the lower case.
|
static boolean |
nodeName(DOMElement el,
String tag1)
Returns if the node name of the specified element is the same
as one of the specified name (case insensitive).
|
static void |
onSyncScroll(java.lang.Object wgt)
To register one object for the
doSyncScroll invocation. |
static void |
onzsync(java.lang.Object obj)
To register one object for the
zsync invocation. |
static Map |
paddings()
A map of the padding style names: {l: 'padding-left', t: 'padding-top'...}.
|
static Map |
parseStyle(String style)
Parses a string-type CSS style into a map of names and values of styles.
|
void |
prepend(java.lang.Object content,
Desktop desktop)
Prepend content to the inside of every matched element.
|
static String |
px(java.lang.Integer v)
Converting an integer to a string ending with "px".
|
static String |
px0(java.lang.Integer v)
Converting an integer a string ending with "px".
|
jq |
remove()
Removes all matched elements from the DOM.
|
jq |
replaceWith(Widget widget,
Desktop desktop,
Skipper skipper)
Replaces the match elements with the specified HTML, DOM or
Widget . |
static int |
scrollbarWidth()
Returns the width of the scrollbar
|
jq |
show()
Shows all matched elements from the DOM.
|
static void |
toJSON(java.lang.Object obj,
java.lang.Object replace)
Encodes a JavaScript object to a JSON string.
|
static void |
unSyncScroll(java.lang.Object wgt)
To unregister one object for the
doSyncScroll invocation. |
static void |
unzsync(java.lang.Object obj)
To unregister one object for the
zsync invocation. |
static void |
zsync()
To invoke the
zsync method of the registered objects. |
public jqzk zk
public static boolean nodeName(DOMElement el, String tag1)
el
- the element to testtag1
- the name to test. You can have any number
of names to test, such as jq.nodeName(el, "tr", "td", "span")
public static String nodeName(DOMElement el)
el
- the element to test.
If el is null, an empty string is returned.public static String px(java.lang.Integer v)
It is usually used for generating left or top.
v
- the number of pixelspx0(java.lang.Integer)
public static String px0(java.lang.Integer v)
Unlike px(java.lang.Integer)
, this method assumes 0 if v is negative.
It is usually used for generating width or height.
v
- the number of pixels. 0 is assumed if negative.px(java.lang.Integer)
public static Array $$(String id, String subId)
DOMElement
that matches.
It invokes document.getElementsByName
to retrieve
the DOM elements.id
- the identifiersubId
- [Optional] the identifier of the sub-element.
Example, jq.$$('_u_12', 'cave');
.DOMElement
that matches
the specified conditionpublic static boolean isAncestor(DOMElement p, DOMElement c)
Notice that, if you want to test widgets, please use
zUtl.isAncestor(java.lang.Object, java.lang.Object)
instead.
p
- the parent element to testc
- the child element to testzUtl.isAncestor(java.lang.Object, java.lang.Object)
public static int innerX()
public static int innerY()
public static int innerWidth()
public static int innerHeight()
public static int scrollbarWidth()
public static boolean isOverlapped(Offset ofs1, Offset dim1, Offset ofs2, Offset dim2, int the)
ofs1
- the offset of the first rectangledim1
- the dimension (size) of the first rectangleofs2
- the offset of the second rectangledim2
- the dimension (size) of the second rectanglethe
- tolerant value for the calculationpublic static boolean isOverlapped(Offset ofs1, Offset dim1, Offset ofs2, Offset dim2)
ofs1
- the offset of the first rectangledim1
- the dimension (size) of the first rectangleofs2
- the offset of the second rectangledim2
- the dimension (size) of the second rectanglepublic static boolean clearSelection()
Notice: jqzk.setSelectionRange(int, int)
is used for the input-type
elements, while this method is applied to the whole browser window.
jqzk.setSelectionRange(int, int)
,
jqzk.enableSelection()
,
jqzk.disableSelection()
public static Map filterTextStyle(Map styles, Array plus)
jq.filterTextStyle({width:"100px", fontSize: "10pt"});
//return {font-size: "10pt"}
styles
- the styles to filterplus
- an array of the names of the additional style to
include, such as ['width', 'height']
. Ignored if not specified or null.public static String filterTextStyle(String style, Array plus)
>
jq.filterTextStyle('width:100px;font-size:10pt;font-weight:bold');
//return 'font-size:10pt;font-weight:bold'
style
- the style to filterplus
- an array of the names of the additional style to
include, such as ['width', 'height']
. Ignored if not specified or null.public static Map parseStyle(String style)
style
- the style to parsepublic static DOMElement newFrame(String id, String src, String style)
id
- ID (required)src
- the source URL. If omitted, an one-pixel gif is assumed.style
- the CSS style. Ingored if omitted.public static DOMElement newStackup(DOMElement el, String id, DOMElement anchor)
Notice that you usually have to call jqzk.makeVParent()
before calling this, since DIV with relative or absolute position will crop the child element. In other words, you have to make the element as the top-level element before creating a stackup for it.
To remove the stackup, call remove()
.
If you want to create a shadow, you don't need to access this method since Shadow
has an option to create and maintain the stackup automatically.
el
- the element to retrieve the dimensions. If omitted, the stackup is not appended to the DOM tree.id
- ID of the stackup (iframe). If omitted and el is specified, it is el.id + '$ifrstk'. If both el and id are omitted, 'z_ifrstk' is assumed.anchor
- where to insert the DOM element before
(i.e., anchor will become the next sibling of the stackup, so anchor will be on top of the stackup if z-index is the same). If omitted, el is assumed.public static DOMElement newHidden(String name, String value, DOMElement parent)
name
- the name of the HIDDEN tag.value
- the value of the HIDDEN tag.parent
- the parent node. Ignored if not specified.public static DOMElement head()
public static boolean confirm()
window.confirm
, except it will set
zk.alerting
so widgets know to ignore onblur
(since the focus will be back later).
It is strongly suggested to use this method instead of window.confirm
.
public static void alert(String msg, Map opts)
zk.alerting
, so widgets (particularly input widgets) know to ignore onblur (since the focus will be back later).
It is strongly suggested to use this method instead of window.alert.
If opts is omitted or opts.mode is not os, it is similar to
org.zkoss.zul.Messagebox.show()
at the server.
jq.alert('Hi');
jq.alert('This is a popup message box', {mode:"popup", icon: "ERROR"});
jq.alert('With listener', {
button : {
YES: function () {jq.alert('Yes clicked')},
NO: function () {jq.alert('No clicked')}
}
});
msg
- the message to showopts
- the options.
Name | Allowed Values | Default Value | Description |
---|---|---|---|
icon | 'QUESTION', 'EXCLAMATION', 'INFORMATION', 'ERROR', 'NONE' | 'INFORMATION' | Specifies the icon to display. |
mode | 'overlapped', 'popup', 'modal' | 'modal' | Specifies which window mode to use. |
title | any string | 'ZK' | Specifies the message box's title. |
desktop | a desktop (Desktop ) or null
| The current desktop | Specifies which desktop this message box belongs to. You rarely need to specify it. |
button | a map (Map ) of buttons.
| If null or empty, OK is assumed | Specifies what buttons to display. The key is the button name,
and the value is a function (Function ) to execute when the button
is clicked.
The label is assumed to be msgzul[name.toUpperCase()]||name .
Localized labels include OK, Cancel, Yes, No, Retry, Abort, Ignore, Reload.
You can add your own labels by puttingit to msgzul .
|
public static void onzsync(java.lang.Object obj)
zsync
invocation.
For example,
jq.onzsync(obj1);
obj
- the object to registerzsync()
,
unzsync(java.lang.Object)
public static void unzsync(java.lang.Object obj)
zsync
invocation.
For example,
jq.unzsync(obj1);
obj
- the object to registerzsync()
,
onzsync(java.lang.Object)
public static void zsync()
zsync
method of the registered objects.
zsync
is called automatically when zWatch
fires onSize, onShow or onHide.
It is useful if you have a DOM element whose position is absolute.
Then, if you register the widget, the widget's zsync method will be called when some widget becomes visible, is added and so on.
For example, Window
uses DIV to simulate the shadow in IE,
then it can register itself in Widget.bind_(zk.Desktop, zk.Skipper, _global_.Array, boolean)
and then
synchronize the position and size of shadow (DIV) in zsync as follows.
bind_: function () {
if (zk.ie) jq.onzsync(this); //register
...
},
unbind_: function () {
if (zk.ie) jq.unzsync(this); //unregister
...
},
zsync: function () {
this._syncShadow(); //synchronize shadow
...
}
Notice that it is better not to use the absolute position for any child element, so the browser will maintain the position for you. After all, it runs faster and zsync won't be called if some 3rd-party library is used to create DOM element directly (without ZK).
public static void onSyncScroll(java.lang.Object wgt)
doSyncScroll
invocation.
For example,
onSyncScroll();
wgt
- the object to registerdoSyncScroll()
,
unSyncScroll(java.lang.Object)
public static void doSyncScroll()
doSyncScroll
method of the registered objects.
doSyncScroll
is called automatically when zWatch
fires onResponse, onShow or onHide.
It is useful if you have a Widget that using zul.Scrollbar.
Then, if you register the widget, the widget's doSyncScroll method will be called when widget add/remove/hide/show its child widget.
onSyncScroll(java.lang.Object)
,
unSyncScroll(java.lang.Object)
public static void unSyncScroll(java.lang.Object wgt)
doSyncScroll
invocation.
For example,
unSyncScroll(wgt);
wgt
- the object to registerdoSyncScroll()
,
onSyncScroll(java.lang.Object)
public static Map margins()
jqzk.sumStyles(_global_.String, _global_.Array)
to calculate the numbers specified
in these styles.margins()
,
paddings()
public static Map borders()
jqzk.sumStyles(_global_.String, _global_.Array)
to calculate the numbers specified
in these styles.margins()
,
paddings()
public static Map paddings()
jqzk.sumStyles(_global_.String, _global_.Array)
to calculate the numbers specified
in these styles.public static void focusOut()
Notice that you cannot simply use jq(window).focus()
or zk(window).focus()
,
because it has no effect for browsers other than IE.
public static String css(DOMElement elem, String name, String extra)
Note that the function is only applied to the width or height property, and the third argument must be 'styleonly'.
For example,
jq.css(elem, 'height', 'styleonly');
or
jq.css(elem, 'width', 'styleonly');
elem
- a Dom elementname
- the style nameextra
- an option in this case, it must be 'styleonly'public static java.lang.Object evalJSON(String s)
It is similar to jq.parseJSON (jQuery's default function), except 1) it doesn't check if the string is a valid JSON 2) it uses eval to evaluate
Thus, it might not be safe to invoke this if the string's source is not trustable (and then it is better to use jq.parseJSON)
s
- the JSON stringpublic static void toJSON(java.lang.Object obj, java.lang.Object replace)
You can provide an optional replacer method. It will be passed the key and value of each member, with this bound to the containing object. The value that is returned from your method will be serialized. If your method returns undefined, then the member will be excluded from the serialization. Values that do not have JSON representations, such as undefined or functions, will not be serialized. Such values in objects will be dropped; in arrays they will be replaced with null. You can use a replacer function to replace those with JSON values. JSON.stringify(undefined) returns undefined.
The optional space parameter produces a stringification of the value that is filled with line breaks and indentation to make it easier to read.
If the space parameter is a non-empty string, then that string will be used for indentation. If the space parameter is a number, then the indentation will be that many spaces.
Example:
text = jq.toJSON(['e', {pluribus: 'unum'}]);
// text is '["e",{"pluribus":"unum"}]'
text = jq.toJSON([new Date()], function (key, value) {
return this[key] instanceof Date ?
'Date(' + this[key] + ')' : value;
});
// text is '["Date(---current time---)"]'
obj
- any JavaScript objectreplace
- an optional parameter that determines how object values are stringified for objects. It can be a function.public static String d2j(Date d)
It works with org.zkoss.json.JSONs.d2j() to transfer data from client to server.
d
- the date object to marshall. If null, null is returnedpublic static Date j2d(String s)
It works with org.zkoss.json.JSONs.j2d() to transfer data from server to client.
s
- the string that is marshalled at the serverpublic jq replaceWith(Widget widget, Desktop desktop, Skipper skipper)
Widget
.
We extends jQuery's replaceWith
to allow replacing with an instance of Widget
.widget
- a widgetdesktop
- the desktop. It is optional.skipper
- the skipper. It is optional.public jq remove()
Unlike jQuery, it does nothing if nothing is matched.
public jq empty()
Unlike jQuery, it does nothing if nothing is matched.
public jq show()
Unlike jQuery, it does nothing if nothing is matched.
public jq hide()
Unlike jQuery, it does nothing if nothing is matched.
public void before(java.lang.Object content, Desktop desktop)
Notice that this method is extended to handle Widget
.
Refer to jQuery documentation for more information.
content
- If it is a string, it is assumed to be
a HTML fragment. If it is a widget, the widget will be insert beforedesktop
- [optional] the desktop. It is used only
if content is a widget.public void after(java.lang.Object content, Desktop desktop)
Notice that this method is extended to handle Widget
.
Refer to jQuery documentation for more information.
content
- If it is a string, it is assumed to be
a HTML fragment. If it is a widget, the widget will be insert afterdesktop
- [optional] the desktop. It is used only
if content is a widget.public void append(java.lang.Object content, Desktop desktop)
Notice that this method is extended to handle Widget
.
Refer to jQuery documentation for more information.
content
- If it is a string, it is assumed to be
a HTML fragment. If it is a widget, the widget will be appendeddesktop
- [optional] the desktop. It is used only
if content is a widget.public void prepend(java.lang.Object content, Desktop desktop)
Notice that this method is extended to handle Widget
.
Refer to jQuery documentation for more information.
content
- If it is a string, it is assumed to be
a HTML fragment. If it is a widget, the widget will be prependeddesktop
- [optional] the desktop. It is used only
if content is a widget.Copyright © 2005-2023 Potix Corporation. All Rights Reserved.