001 
002 /*
003  *  JScripter Standard 1.0 - To Script In Java
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package jsx.client;
021 
022 import js.*;
023 import js.core.*;
024 import js.user.*;
025 
026 /**
027  * <p>A utility class accessing the functions of JavaScript with a full client-side support.</p>
028  * <p>Users are encouraged to use the utilities provided in this class instead of the 
029  * <b>opaque</b> methods of the {@link js.core.JsGlobal}, {@link js.user.JsWindow} or 
030  * {@link js.user.JsWin} classes in consideration of the reuse benefit for re-compilation 
031  * results.</p>
032  * 
033  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
034  */
035 public final class Win extends Client
036 {
037     private Win() {}
038 
039     /**
040      * <p>Displays a simple message in a dialog box.</p>
041      * <p>In JavaScript, this method displays the specified <tt>message</tt> to the 
042      * user in a dialog box. The dialog box contains an OK button the user can click to 
043      * dismiss it. The dialog box is typically modal, and the call to this function 
044      * typically blocks until the dialog is dismissed.</p>
045      * <p>Perhaps the most common use of this method is to display error messages when the 
046      * user's input to some form element is invalid in some way. The alert dialog box can 
047      * inform the user of the problem and explain what needs to be corrected to avoid the 
048      * problem in the future</p>
049      * <p>The appearance of the dialog box is platform-dependent, but it generally contains 
050      * graphics that indicate an error, warning, or alert message of some kind. While it can 
051      * display any desired message, the alert graphics of the dialog box mean that this 
052      * method is not appropriate for simple informational messages like "Welcome to my blog"</p>
053      * <p>Note that the <tt>message</tt> displayed in the dialog box is a string of 
054      * plain text, not formatted HTML. You can use the newline character "\n" in your strings 
055      * to break your message across multiple lines. You can also do some rudimentary 
056      * formatting using spaces and can approximate horizontal rules with underscore characters, 
057      * but the results depend greatly on the font used in the dialog box and thus are 
058      * system-dependent.</p>
059      * @param message The plain-text (not HTML) string to display in a dialog box popped up 
060      * over the current window.
061      * @since 1.0
062      * @see Js#alert(Object)
063      * @see Global#alert(Object)
064      * @see JsWindow#alert(Object)
065      */
066     public static final void alert(Object message) {
067         Js.win().alert(message);
068     }
069     /**
070      * <p>Asks a yes-or-no question with a dialog box.</p>
071      * <p>In JavaScript, this method displays the specified question in a dialog box. The 
072      * dialog box contains OK and Cancel buttons that the user can use to answer the 
073      * question. If the user clicks the OK button, it returns <tt>true</tt>. If the 
074      * user clicks Cancel, it returns <tt>false</tt>.</p>
075      * <p>The dialog box that is displayed by the this method is modal. That is, it blocks 
076      * all user input to the main browser window until the user dismisses the dialog box 
077      * by clicking on the OK or Cancel buttons. Since this method returns a value depending 
078      * on the user's response to the dialog box, JavaScript execution pauses in the call to 
079      * this method, and subsequent statements are not executed until the user responds to 
080      * the dialog box.</p>
081      * <p>There is no way to change the labels that appear in the buttons of the dialog box 
082      * (to make them read Yes and No, for example). Therefore, you should take care to 
083      * phrase your question or message so that OK and Cancel are suitable responses.</p>
084      * @param question The plain-text (not HTML) string to be displayed in the dialog box. 
085      * It should generally express a question you want the user to answer.
086      * @return <tt>true</tt> if the user clicks the OK button; <tt>false</tt> if 
087      * the user clicks the Cancel button.
088      * @since 1.0
089      * @see Js#confirm(Object)
090      * @see Global#confirm(Object)
091      * @see JsWindow#confirm(Object)
092      */
093     public static final boolean confirm(Object question) {
094         return Js.win().confirm(question);
095     }
096     /**
097      * <p>Asks for simple string input with a dialog box.</p>
098      * <p>This method displays text input field and OK and Cancel buttons in a dialog box. 
099      * Platform-dependent graphics in the dialog box help indicate to the user that an 
100      * input is desired.</p>
101      * <p>If the user clicks the Cancel button, the method returns <tt>null</tt>. If 
102      * the user clicks the OK button, it returns the text currently displayed in the 
103      * input field.</p>
104      * <p>The dialog box that is displayed by this method is modal. That is, it blocks all 
105      * user input to the main browser window until the user dismisses the dialog box by 
106      * clicking on the OK or Cancel buttons. Since this method returns a value depending 
107      * on the user's response to the dialog box, JavaScript execution pauses in the call 
108      * to this method, and subsequent statements are not executed until the user responds 
109      * to the dialog box.</p>
110      * @param message The plain-text (not HTML) string to be displayed in the dialog box. 
111      * It should ask the user to enter the information you want.
112      * @return The string entered by the user, the empty string if the user did not enter 
113      * a string, or <tt>null</tt> if the user clicked Cancel.
114      * @since 1.0
115      * @see #prompt(Object, Object)
116      * @see Js#prompt(Object)
117      * @see Global#prompt(Object)
118      * @see JsWindow#prompt(Object)
119      */
120     public static final String prompt(Object message) {
121         return Js.win().prompt(message);
122     }
123     /**
124      * <p>Asks for simple string input with a dialog box.</p>
125      * <p>This method displays the specified message in a dialog box that also contains a 
126      * text input field and OK and Cancel buttons. Platform-dependent graphics in the 
127      * dialog box help indicate to the user that an input is desired.</p>
128      * <p>If the user clicks the Cancel button, the method returns <tt>null</tt>. If 
129      * the user clicks the OK button, it returns the text currently displayed in the 
130      * input field.</p>
131      * <p>The dialog box that is displayed by this method is modal. That is, it blocks all 
132      * user input to the main browser window until the user dismisses the dialog box by 
133      * clicking on the OK or Cancel buttons. Since this method returns a value depending 
134      * on the user's response to the dialog box, JavaScript execution pauses in the call 
135      * to this method, and subsequent statements are not executed until the user responds 
136      * to the dialog box.</p>
137      * @param message The plain-text (not HTML) string to be displayed in the dialog box. 
138      * It should ask the user to enter the information you want.
139      * @param defaultInput A string that is displayed as the default input in the dialog 
140      * box. Pass the empty string ("") to make the method display an empty input box.
141      * @return The string entered by the user, the empty string if the user did not enter 
142      * a string, or <tt>null</tt> if the user clicked Cancel.
143      * @since 1.0
144      * @see #prompt(Object)
145      * @see Js#prompt(Object, Object)
146      * @see Global#prompt(Object, Object)
147      * @see JsWindow#prompt(Object, Object)
148      */
149     public static final String prompt(Object message, Object defaultInput) {
150         return Js.win().prompt(message, defaultInput);
151     }
152     /**
153      * <p>Cancels periodic execution of code.</p>
154      * <p>This method stops the repeated execution of code that was started by a call to 
155      * {@link #setInterval(JsFunction, Object)}. <tt>intervalId</tt> must be the value 
156      * that was returned by a call to {@link #setInterval(JsFunction, Object)}.</p>
157      * @param intervalId The value returned by the corresponding call to {@link #setInterval(JsFunction, Object)}.
158      * @since 1.0
159      * @see #setInterval(JsFunction, Object)
160      * @see Js#clearInterval(Object)
161      * @see Global#clearInterval(Object)
162      * @see JsWindow#clearInterval(Object)
163      * @see jsx.Interval
164      */
165     public static final void clearInterval(Object intervalId) {
166         Js.win().clearInterval(intervalId);
167     }
168     /**
169      * <p>Cancels a pending timeout operation.</p>
170      * <p>This method cancels the execution of code that has been deferred with the 
171      * {@link #setTimeout(JsFunction, Object)} method. The <tt>timeoutId</tt> argument 
172      * is a value returned by the call to {@link #setTimeout(JsFunction, Object)} and 
173      * identifies which deferred code to cancel.</p>
174      * @param timeoutId A value returned by {@link #setTimeout(JsFunction, Object)} that 
175      * identifies the timeout to be canceled.
176      * @since 1.0
177      * @see #clearTimeout(Object)
178      * @see Js#clearTimeout(Object)
179      * @see Global#clearTimeout(Object)
180      * @see JsWindow#clearTimeout(Object)
181      * @see jsx.Timeout
182      */
183     public static final void clearTimeout(Object timeoutId ) {
184         Js.win().clearTimeout(timeoutId);
185     }
186     /**
187      * <p>Executes code at periodic intervals.</p>
188      * <p>Note that the specified function is executed in the context of the Window object, 
189      * that is, the Window object is the value of the <tt>this</tt> keyword of the 
190      * executing context of the function. This is <tt>true</tt> even if the call to 
191      * {@link #setTimeout(JsFunction, Object)} occurred within a function with a longer 
192      * scope chain.</p>
193      * @param f A function to be periodically invoked.
194      * @param interval The interval, in milliseconds, between invocations of the function.
195      * @return A value that can be passed to {@link #clearInterval(Object)} method to 
196      * cancel the periodic execution of the function.
197      * @since 1.0
198      * @see #clearInterval(Object)
199      * @see Js#setInterval(JsFunction, Number)
200      * @see Global#setInterval(JsFunction)
201      * @see Global#setInterval(JsFunction, Number)
202      * @see JsWindow#setInterval(JsFunction, Object)
203      * @see jsx.Interval
204      */
205     public static final Object setInterval(JsFunction<?> f, Object interval) {
206         return Js.win().setInterval(f, interval);
207     }
208     /**
209      * <p>Executes code at periodic intervals.</p>
210      * <p>Note that the specified function is executed in the context of the Window object, 
211      * that is, the Window object is the value of the <tt>this</tt> keyword of the 
212      * executing context of the function. This is <tt>true</tt> even if the call to 
213      * {@link #setTimeout(JsFunction, Number)} occurred within a function with a longer 
214      * scope chain.</p>
215      * @param f A function to be periodically invoked.
216      * @return A value that can be passed to {@link #clearInterval(Object)} method to 
217      * cancel the periodic execution of the function.
218      * @since 1.0
219      * @see #setInterval(JsFunction, Number)
220      * @see #clearInterval(Object)
221      * @see Js#setInterval(JsFunction)
222      * @see Js#setInterval(JsFunction, Number)
223      * @see Global#setInterval(JsFunction)
224      * @see Global#setInterval(JsFunction, Number)
225      * @see JsWindow#setInterval(JsFunction, Object)
226      * @see jsx.Interval
227      */
228     public static final Object setInterval(JsFunction<?> f) {
229         return Js.win().setInterval(f, 1);
230     }
231     /**
232      * <p>Executes code after a specified amount of time elapses.</p>
233      * <p>Note that this method executes the specified function only once. The function is 
234      * executed in the context of the Window object, that is, the Window object is the 
235      * value of the <tt>this</tt> keyword of the executing context of the function. 
236      * This is <tt>true</tt> even if the call to {@link #setTimeout(JsFunction, Object)} 
237      * occurred within a function with a longer scope chain.</p>
238      * @param f A function to be invoked after the <tt>delay</tt> has elapsed.
239      * @param delay The amount of time, in milliseconds, before the function should be executed.
240      * @return A value that can be passed to the {@link #clearTimeout(Object)} method to 
241      * cancel the execution of the function.
242      * @since 1.0
243      * @see #clearTimeout(Object)
244      * @see Js#setTimeout(JsFunction, Number)
245      * @see Global#setTimeout(JsFunction)
246      * @see Global#setTimeout(JsFunction, Number)
247      * @see JsWindow#setTimeout(JsFunction, Object)
248      * @see jsx.Timeout
249      */
250     public static final Object setTimeout(JsFunction<?> f, Object delay) {
251         return Js.win().setTimeout(f, delay);
252     }
253     /**
254      * <p>Executes code after an amount of time elapses, 
255      * simulating the JavaScript global function of the same name.</p>
256      * <p>Note that this method executes the specified function only once. The function is 
257      * executed in the context of the Window object, that is, the Window object is the 
258      * value of the <tt>this</tt> keyword of the executing context of the function. 
259      * This is <tt>true</tt> even if the call to {@link #setTimeout(JsFunction, Number)} 
260      * occurred within a function with a longer scope chain.</p>
261      * @param f A function to be invoked after the <tt>delay</tt> has elapsed.
262      * @return A value that can be passed to the {@link #clearTimeout(Object)} method to 
263      * cancel the execution of the function.
264      * @since 1.0
265      * @see #setTimeout(JsFunction, Object)
266      * @see #clearTimeout(Object)
267      * @see Js#setTimeout(JsFunction)
268      * @see Js#setTimeout(JsFunction, Number)
269      * @see Global#setTimeout(JsFunction)
270      * @see Global#setTimeout(JsFunction, Number)
271      * @see JsWindow#setTimeout(JsFunction, Object)
272      * @see jsx.Timeout
273      */
274     public static final Object setTimeout(JsFunction<?> f) {
275         return Js.win().setTimeout(f, 1);
276     }
277     /**
278      * <p>Adds an event handler function to the set of event handlers for the current {@link JsWindow#window} object. 
279      * This is a DOM-standard method supported by all modern browsers except IE.</p>
280      * <p>This method adds the specified event <tt>listener</tt> function to the set of 
281      * listeners registered on this node to handle events of the specified <tt>type</tt>. 
282      * If <tt>useCapture</tt> is <tt>true</tt>, the <tt>listener</tt> is registered as 
283      * a capturing event listener. If <tt>useCapture</tt> is <tt>false</tt>, it is 
284      * registered as a normal event listener.</p>
285      * <p>This method may be called multiple times to register multiple event handlers 
286      * for the same type of event on the same node. Note, however, that the DOM 
287      * Specification makes no guarantees about the order in which multiple event handlers 
288      * are invoked.</p>
289      * <p>If the same event listener function is registered twice on the same node with 
290      * the same <tt>type</tt> and <tt>useCapture</tt> arguments, the second registration 
291      * is simply ignored. If a new event listener is registered on this node while an 
292      * event is being handled at this node, the new event listener is not invoked for 
293      * that event.</p>
294      * <p>When a node is duplicated with {@link JsNode#cloneNode(Boolean)} or {@link JsDocument#importNode(JsNode, Boolean)}, 
295      * the event listeners registered for the original node are not copied.</p>
296      * <p>The same method is also defined by, and works analogously on, the {@link JsElement} 
297      * and {@link JsWindow} objects</p>
298      * @param type The type of event for which the event listener is to be invoked.
299      * @param listener The event listener function that is invoked when an event of the 
300      * specified type is dispatched to this node. When invoked, the listener function 
301      * is passed an {@link JsEvent} object and is invoked as a method of the node on 
302      * which it is registered.
303      * @param useCapture If <tt>true</tt>, the specified <tt>listener</tt> is to be 
304      * invoked only during the capturing phase of event propagation. The more common 
305      * value of <tt>false</tt> means that the <tt>listener</tt> is not invoked during 
306      * the capturing phase but instead is invoked when this node is the actual event 
307      * target or when the event bubbles up to this node from its original target.
308      * @since 1.0
309      * @see #attachEvent(String, JsFunction)
310      * @see #removeEventListener(String, JsFunction, Boolean)
311      * @see JsWindow#addEventListener(String, JsFunction, Boolean)
312      * @see Document#addEventListener(String, JsFunction, Boolean)
313      * @see JsDocument#addEventListener(String, JsFunction, Boolean)
314      * @see JsElement#addEventListener(String, JsFunction, Boolean)
315      */
316     public static final void addEventListener(String type, JsFunction<?> listener, Boolean useCapture) {
317         Js.win().addEventListener(type, listener, useCapture);
318     }
319     /**
320      * <p>Removes an event handler function from the set of handlers for the current {@link JsWindow#window} object. 
321      * This is a standard DOM method implemented by all modern browsers except IE.</p>
322      * <p>This method removes the specified event <tt>listener</tt> function. The <tt>type</tt> 
323      * and <tt>useCapture</tt> arguments must be the same as they are in the 
324      * corresponding call to {@link #addEventListener(String, JsFunction, Boolean)}. If 
325      * no event listener is found that matches the specified arguments, this method does 
326      * nothing.</p>
327      * <p>Once an event <tt>listener</tt> function has been removed by this method, it 
328      * will no longer be invoked for the specified <tt>type</tt> of event on this node. 
329      * This is true even if the event <tt>listener</tt> is removed by another event 
330      * listener registered for the same type of event on the same node.</p>
331      * <p>The same method is also defined by, and works analogously on, the {@link JsElement} 
332      * and {@link JsWindow} objects</p>
333      * @param type The type of event for which the event listener is to be deleted.
334      * @param listener The event listener function that is to be removed.
335      * @param useCapture <tt>true</tt> if a capturing event listener is to be removed; 
336      * <tt>false</tt> if a normal event listener is to be removed.
337      * @since 1.0
338      * @see #detachEvent(String, JsFunction)
339      * @see #addEventListener(String, JsFunction, Boolean)
340      * @see JsWindow#removeEventListener(String, JsFunction, Boolean)
341      * @see Document#removeEventListener(String, JsFunction, Boolean)
342      * @see JsDocument#removeEventListener(String, JsFunction, Boolean)
343      * @see JsElement#removeEventListener(String, JsFunction, Boolean)
344      */
345     public static final void removeEventListener(String type, JsFunction<?> listener, Boolean useCapture) {
346         Js.win().removeEventListener(type, listener, useCapture);
347     }
348     /**
349      * <p>Adds an event handler function to the set of handlers for the current {@link JsWindow#window} object. 
350      * This is the IE-specific alternative to {@link #addEventListener(String, JsFunction, Boolean)}.</p>
351      * <p>This method is an IE-specific event registration method. It serves the same 
352      * purpose as the standard {@link #addEventListener(String, JsFunction, Boolean)} 
353      * method, which IE does not support, but is different from that function in several 
354      * important ways:
355      * <ul>
356      * <li>Since the IE event model does not support event capturing, this method and 
357      * {@link #detachEvent(String, JsFunction)} expect only two arguments: the event 
358      * type and the handler function.</li>
359      * <li>The event handler names passed to the IE methods should include the "on" 
360      * prefix.</li>
361      * <li>Functions registered with this method are invoked with no {@link JsEvent} 
362      * object argument. Instead, they must read the {@link JsWindow#event} property of 
363      * the {@link JsWindow#window} object.</li>
364      * <li>Functions registered with this method are invoked as global functions, rather 
365      * than as methods of the node on which the event occurred. That is, when an event 
366      * handler registered with this method executes, the <tt>this</tt> keyword refers to 
367      * the {@link JsWindow#window} object, not to the event's target node.</li>
368      * <li>This method allows the same event handler function to be registered more than 
369      * once. When an event of the specified type occurs, the registered function is 
370      * invoked as many times as it is registered.</li>
371      * </ul>
372      * </p>
373      * <p>The same method is also defined by, and works analogously on, the {@link JsElement} 
374      * and {@link JsWindow} objects</p>
375      * @param type The type of event for which the event listener is to be invoked, with 
376      * a leading "on" prefix.
377      * @param listener The event listener function that is invoked when an event of the 
378      * specified type is dispatched to this node. This function is not passed any 
379      * arguments but can obtain the {@link JsEvent} object from the {@link JsWindow#event} 
380      * property of the {@link JsWindow} object.
381      * @since 1.0
382      * @see #addEventListener(String, JsFunction, Boolean)
383      * @see #detachEvent(String, JsFunction)
384      * @see JsWindow#attachEvent(String, JsFunction)
385      * @see Document#attachEvent(String, JsFunction)
386      * @see JsDocument#attachEvent(String, JsFunction)
387      * @see JsElement#attachEvent(String, JsFunction)
388      */
389     public static final void attachEvent(String type, JsFunction<?> listener) {
390         Js.win().attachEvent(type, listener);
391     }
392     /**
393      * <p>Removes an event handler function from the current {@link JsWindow#window} object. This is the IE-specific 
394      * alternative to the standard {@link #removeEventListener(String, JsFunction, Boolean)} 
395      * method.</p>
396      * <p>This method undoes the event handler function registration performed by the 
397      * {@link #attachEvent(String, JsFunction)} method. It is the IE-specific analog to 
398      * the standard {@link #removeEventListener(String, JsFunction, Boolean)}. To remove 
399      * an event handler function for a node, simply invoke this method with the same 
400      * arguments you originally passed to {@link #attachEvent(String, JsFunction)}.</p>
401      * <p>The same method is also defined by, and works analogously on, the {@link JsElement} 
402      * and {@link JsWindow} objects</p>
403      * @param type The type of event for which the event listener is to be invoked, with 
404      * a leading "on" prefix.
405      * @param listener The event listener function that is to be removed.
406      * @since 1.0
407      * @see #removeEventListener(String, JsFunction, Boolean)
408      * @see #attachEvent(String, JsFunction)
409      * @see JsWindow#detachEvent(String, JsFunction)
410      * @see Document#detachEvent(String, JsFunction)
411      * @see JsDocument#detachEvent(String, JsFunction)
412      * @see JsElement#detachEvent(String, JsFunction)
413      */
414     public static final void detachEvent(String type, JsFunction<?> listener) {
415         Js.win().detachEvent(type, listener);
416     }
417     public static final void yield() {
418         setTimeout(function());
419     }
420     /**
421      * <p>Decodes a string escaped with {@link #encodeURI(Object)}.</p>
422      * @param s A string that contains an encoded URI or other text to be decoded.
423      * @return A copy of <tt>s</tt>, with any hexadecimal escape sequences replaced with 
424      * the characters they represent.
425      * @throws RuntimeException JavaScript throws a <tt>URIError</tt> if one or more of the 
426      * escape sequences in <tt>s</tt> is malformed and cannot be correctly decoded. See 
427      * {@link Js#err(Object)} and {@link js.core.JsURIError} for JS Simulation.
428      * @since 1.0
429      * @see #encodeURI(Object)
430      * @see Js#decodeURI(Object)
431      * @see Global#decodeURI(Object)
432      * @see JsGlobal#decodeURI(Object)
433      */
434     public static final String decodeURI(Object s) {
435         return Js.core().decodeURI(s);
436     }
437     /**
438      * <p>Decodes a string escaped with {@link #encodeURIComponent(Object)}.</p>
439      * @param s A string that contains an encoded URI component or other text to be decoded.
440      * @return A copy of <tt>s</tt>, with any hexadecimal escape sequences replaced 
441      * with the characters they represent.
442      * @throws RuntimeException JavaScript throws a <tt>URIError</tt> if one or more of the 
443      * escape sequences in <tt>s</tt> is malformed and cannot be correctly decoded. See 
444      * {@link Js#err(Object)} and {@link js.core.JsURIError} for JS Simulation.
445      * @since 1.0
446      * @see #encodeURIComponent(Object)
447      * @see Js#decodeURIComponent(Object)
448      * @see Global#decodeURIComponent(Object)
449      * @see JsGlobal#decodeURIComponent(Object)
450      */
451     public static final String decodeURIComponent(Object s) {
452         return Js.core().decodeURIComponent(s);
453     }
454     /**
455      * <p>Encodes a URI by escaping certain characters.</p>
456      * @param uri A string that contains the URI or other text to be encoded.
457      * @return A copy of <tt>uri</tt>, with any hexadecimal escape sequences replaced 
458      * with the characters they represent..
459      * @throws RuntimeException JavaScript throws a <tt>URIError</tt> if <tt>s</tt> 
460      * contains malformed unicode surrogate pairs and cannot be encoded. See 
461      * {@link Js#err(Object)} and {@link js.core.JsURIError} for JS Simulation.
462      * @since 1.0
463      * @see #decodeURI(Object)
464      * @see Js#encodeURI(Object)
465      * @see Global#encodeURI(Object)
466      * @see JsGlobal#encodeURI(Object)
467      */
468     public static final String encodeURI(Object uri) {
469         return Js.core().encodeURI(uri);
470     }
471     /**
472      * <p>Encodes a URI component by escaping certain characters.</p>
473      * @param uri A string that contains a portion of a URI or other text to be encoded.
474      * @return A copy of <tt>uri</tt>, with certain characters replaced by hexadecimal escape sequences.
475      * @throws RuntimeException JavaScript throws a <tt>URIError</tt> if <tt>s</tt> 
476      * contains malformed unicode surrogate pairs and cannot be encoded. See 
477      * {@link Js#err(Object)} and {@link js.core.JsURIError} for JS Simulation.
478      * @since 1.0
479      * @see #decodeURIComponent(Object)
480      * @see Js#encodeURIComponent(Object)
481      * @see Global#encodeURIComponent(Object)
482      * @see JsGlobal#encodeURIComponent(Object)
483      */
484     public static final String encodeURIComponent(Object uri) {
485         return Js.core().encodeURIComponent(uri);
486     }
487     /**
488      * <p>Encodes a string by replacing certain characters with escape sequences.</p>
489      * @param s The string that is to be "escaped" or encoded.
490      * @return An encoded copy of <tt>s</tt> in which certain characters have been 
491      * replaced by hexadecimal escape sequences.
492      * @since 1.0
493      * @see #unescape(Object)
494      * @see Js#escape(Object)
495      * @see Global#escape(Object)
496      * @see JsGlobal#escape(Object)
497      */
498     public static final String escape(Object s) {
499         return Js.core().escape(s);
500     }
501     /**
502      * <p>Decodes a string encoded with {@link #escape(Object)}.</p>
503      * @param s The string that is to be decoded or "unescaped".
504      * @return A decoded copy of <tt>s</tt>.
505      * @see #escape(Object)
506      * @see Js#unescape(Object)
507      * @see Global#unescape(Object)
508      * @see JsGlobal#unescape(Object)
509      * @since 1.0
510      */
511     public static final String unescape(Object s) {
512         return Js.core().unescape(s);
513     }
514     /**
515      * <p>Evaluates the argument string as JavaScript code and returns the result.</p>
516      * <p>In JavaScript, <tt>eval()</tt> is a global method that evaluates a string of 
517      * JavaScript code in the current lexical scope. If the code contains an expression, 
518      * eval evaluates the expression and returns its value. If the code contains a 
519      * JavaScript statement or statements, it executes those statements and returns the 
520      * value, if any, returned by the last statement. If the code does not return any 
521      * value, <tt>eval()</tt> returns undefined. Finally, if code throws an exception, 
522      * <tt>eval()</tt> passes that exception on to the caller.</p>
523      * <p>The global function <tt>eval()</tt> provides a very powerful capability to 
524      * the JavaScript language, but its use is infrequent in real-world programs. 
525      * Obvious uses are to write programs that act as recursive JavaScript interpreters 
526      * and to write programs that dynamically generate and evaluate JavaScript code.</p>
527      * <p>Most JavaScript functions and methods that expect string arguments accept 
528      * arguments of other types as well and simply convert those argument values to 
529      * strings before proceeding. <tt>eval()</tt> does not behave like this. If the 
530      * code argument is not a primitive string, it is simply returned unchanged. Be 
531      * careful, therefore, that you do not inadvertently pass a String object to 
532      * <tt>eval()</tt> when you intended to pass a primitive string value.</p>
533      * <p>For purposes of implementation efficiency, the ECMAScript v3 standard places 
534      * an unusual restriction on the use of <tt>eval()</tt>. An ECMAScript implementation 
535      * is allowed to throw an <tt>EvalError</tt> exception if you attempt to overwrite 
536      * the <tt>eval</tt> property or if you assign the <tt>eval()</tt> method to another 
537      * property and attempt to invoke it through that property.</p>
538      * @param s A string of JavaScript code.
539      * @return The return value of the evaluated code, if any.
540      * @throws RuntimeException JavaScript throws a <tt>SyntaxError</tt> if the argument string 
541      * does not contain legal JavaScript, a <tt>EvalError</tt> if the <tt>eval</tt> function 
542      * was called illegally, through an identifier other than "eval", or other JavaScript error 
543      * generated by the code passed. See {@link Js#err(Object)}, {@link js.core.JsSyntaxError}, 
544      * {@link js.core.JsEvalError}, and {@link js.core.JsError} for JS Simulation.
545      * @since 1.0
546      * @see Js#eval(Object)
547      * @see Global#eval(Object)
548      * @see JsGlobal#eval(Object)
549      */
550     public static final Object eval(Object s) {
551         return Js.core().eval(s);
552     }
553     /**
554      * <p>Tests whether a value is a finite number.</p>
555      * @param v The number to be tested.
556      * @return <tt>true</tt> if <tt>v</tt> is (or can be converted to) a finite 
557      * number, or <tt>false</tt> if <tt>v</tt> is <tt>NaN</tt> (not a number) 
558      * or positive or negative infinity.
559      * @since 1.0
560      * @see Js#isFinite(Object)
561      * @see Global#isFinite(Object)
562      * @see JsGlobal#isFinite(Object)
563      */
564     public static final boolean isFinite(Object v) {
565         return Js.core().isFinite(v);
566     }
567     /**
568      * <p>Tests whether a value is the not-a-number value.</p>
569      * <p>In JavaScript, This function tests its argument to determine whether it is the 
570      * value <tt>NaN</tt>, which represents an illegal number (such as the result of 
571      * division by zero). This function is required because comparing a <tt>NaN</tt> 
572      * with any value, including itself, always returns <tt>false</tt>, so it is not 
573      * possible to test for <tt>NaN</tt> with the == or === operators.</p>
574      * <p>A common use in JavaScript of this function is to test the results of {@link #parseFloat(Object)} 
575      * and {@link #parseInt(Object)} to determine if they represent legal numbers. You can 
576      * also use {@link #isNaN(Object)} to check for arithmetic errors, such as division by 
577      * zero</p>
578      * @param v The value to be tested.
579      * @return <tt>true</tt> if <tt>v</tt> is (or can be converted to) the special 
580      * not-a-number value; <tt>false</tt> if <tt>v</tt> is any other value.
581      * @since 1.0
582      * @see Js#isNaN(Object)
583      * @see Global#isNaN(Object)
584      * @see JsGlobal#isNaN(Object)
585      */
586     public static final boolean isNaN(Object v) {
587         return Js.core().isNaN(v);
588     }
589     /**
590      * <p>Parses a number from a string.</p>
591      * <p>In JavaScript, this function parses and returns the first number that occurs in 
592      * <tt>value</tt>. Parsing stops, and the value is returned, when it encounters a 
593      * character in <tt>value</tt> that is not a valid part of the number. If <tt>value</tt> 
594      * does not begin with a number that it can parse, the function returns the not-a-number 
595      * value <tt>NaN</tt>. Test for this return value with the {@link #isNaN(Object)} 
596      * function. If you want to parse only the integer portion of a number, use {@link #parseInt(Object)} 
597      * or {@link #parseInt(Object, Object)} instead of this one.</p>
598      * @param value The string to be parsed and converted to a number.
599      * @return The parsed number, or <tt>NaN</tt> if <tt>value</tt> does not begin 
600      * with a valid number. In JavaScript 1.0, this function returns 0 instead of <tt>NaN</tt> 
601      * when <tt>value</tt> cannot be parsed as a number.
602      * @since 1.0
603      * @see #parseInt(Object)
604      * @see Js#parseFloat(Object)
605      * @see Global#parseFloat(Object)
606      * @see JsGlobal#parseFloat(Object)
607      */
608     public static final Double parseFloat(Object value) {
609         return (Double)Js.core().parseFloat(value);
610     }
611     /**
612      * <p>Parses an integer from a string.</p>
613      * <p>In JavaScript, this function parses and returns the first number (with an 
614      * optional leading minus sign) that occurs in <tt>value</tt>. Parsing stops, and 
615      * the value is returned, when it encounters a character in <tt>value</tt> that is 
616      * not a valid digit for the specified radix. If <tt>value</tt> does not begin with 
617      * a number that it can parse, the function returns the not-a-number value <tt>NaN</tt>. 
618      * Use the {@link #isNaN(Object)} function to test for this return value.</p>
619      * @param value The string to be parsed.
620      * @return The parsed number, or <tt>NaN</tt> if <tt>value</tt> does not begin with 
621      * a valid integer. In JavaScript 1.0, this function returns 0 instead of <tt>NaN</tt> 
622      * when it cannot parse <tt>value</tt>.
623      * @since 1.0
624      * @see #parseFloat(Object)
625      * @see #parseInt(Object, Object)
626      * @see Js#parseInt(Object)
627      * @see Global#parseInt(Object)
628      * @see JsGlobal#parseInt(Object)
629      */
630     public static final Integer parseInt(Object value) {
631         return (Integer)Js.core().parseInt(value);
632     }
633     /**
634      * <p>Parses an integer from a string in a base specified.</p>
635      * <p>In JavaScript, this function parses and returns the first number (with an 
636      * optional leading minus sign) that occurs in <tt>value</tt>. Parsing stops, and 
637      * the value is returned, when it encounters a character in <tt>value</tt> that is 
638      * not a valid digit for the specified radix. If <tt>value</tt> does not begin with 
639      * a number that it can parse, the function returns the not-a-number value <tt>NaN</tt>. 
640      * Use the {@link #isNaN(Object)} function to test for this return value.</p>
641      * <p>The <tt>radix</tt> argument specifies the base of the number to be parsed. 
642      * Specifying 10 makes this function parse a decimal number. The value 8 specifies that 
643      * an octal number (using digits 0 through 7) is to be parsed. The value 16 specifies 
644      * a hexadecimal value, using digits 0 through 9 and letters A through F. <tt>radix</tt> 
645      * can be any value between 2 and 36.</p>
646      * <p>If <tt>radix</tt> is 0 or is undefined, this function tries to determine the 
647      * radix of the number from <tt>value</tt>. If <tt>value</tt> begins (after an 
648      * optional minus sign) with 0x, it parses the remainder of <tt>value</tt> as a 
649      * hexadecimal number. If <tt>value</tt> begins with a 0, the ECMAScript v3 standard 
650      * allows an implementation of this function to interpret the following characters as 
651      * an octal number or as a decimal number. Otherwise, if <tt>value</tt> begins with 
652      * a digit from 1 through 9, it parses it as a decimal number</p>
653      * @param value The string to be parsed.
654      * @param radix An optional integer argument that represents the radix (or base) of the 
655      * number to be parsed. If this argument is undefined or is 0, the number is parsed in 
656      * base 10 or in base 16 if it begins with 0x or 0X. If this argument is less than 2 or 
657      * greater than 36, <tt>NaN</tt> is returned.
658      * @return The parsed number, or <tt>NaN</tt> if <tt>value</tt> does not begin with 
659      * a valid integer. In JavaScript 1.0, this function returns 0 instead of <tt>NaN</tt> 
660      * when it cannot parse <tt>value</tt>.
661      * @since 1.0
662      * @see #parseInt(Object)
663      * @see Js#parseInt(Object, int)
664      * @see Global#parseInt(Object, int)
665      * @see JsGlobal#parseInt(Object, Object)
666      */
667     public static final Integer parseInt(Object value, Object radix) {
668         return (Integer)Js.core().parseInt(value, radix);
669     }
670     public static final JsObject getComputedStyle(JsHTMLElement elt) {
671         return Js.win().getComputedStyle(elt, "");
672     }
673     public static final JsObject getComputedStyle(JsHTMLElement elt, String pseudoElt) {
674         return Js.win().getComputedStyle(elt, pseudoElt);
675     }
676     /**
677      * <p>Statically accesses the JavaScript global object of the name of this field. 
678      * @see JsClient
679      * @since 1.0
680      */
681     public final static Var<JsDocument> document = new Static<JsDocument>(new Field<JsDocument>(JsWindow.document));
682     /**
683      * <p>Statically accesses the JavaScript global object of the name of this field. 
684      * @see JsClient
685      * @since 1.0
686      */
687     public final static Var<JsLocation> location = new Static<JsLocation>(new Field<JsLocation>(JsWindow.location));
688     /**
689      * <p>Statically accesses the JavaScript global object of the name of this field. 
690      * @see JsClient
691      * @since 1.0
692      */
693     public final static Var<JsNavigator> navigator = new Static<JsNavigator>(new Field<JsNavigator>(JsWindow.navigator));
694     /**
695      * <p>Statically accesses the JavaScript global object of the name of this field. 
696      * @see JsClient
697      * @since 1.0
698      */
699     public final static Var<JsWindow> window = new Static<JsWindow>(new Field<JsWindow>(JsWindow.window));
700 
701     public final static Number clientWidth() {
702         return jsx.client.Browser.isIE ? (
703                 jsx.client.Document.isStrict ?
704                         JsHTMLElement.clientWidth.with(
705                                 JsDocument.documentElement.with(
706                                         Win.document.var()
707                                 )
708                         ) : JsHTMLElement.clientWidth.with(
709                                 jsx.client.Document.body.var()
710                         )
711         ) : JsWindow.innerWidth.with();
712     }
713 
714     public final static Number clientHeight() {
715         return jsx.client.Browser.isIE ? (
716                 jsx.client.Document.isStrict ?
717                         JsHTMLElement.clientHeight.with(
718                                 JsDocument.documentElement.with(
719                                         Win.document.var()
720                                 )
721                         ) : JsHTMLElement.clientHeight.with(
722                                 jsx.client.Document.body.var()
723                         )
724         ) : JsWindow.innerHeight.with();
725     }
726 
727     public final static JsNode documentElement() {
728         return jsx.client.Browser.isIE && !jsx.client.Document.isStrict ?
729                 jsx.client.Document.body.var() : jsx.client.Document.documentElement.var();
730     }
731 
732     public final static Number scrollLeft() {
733         return JsHTMLElement.scrollLeft.with(documentElement());
734     }
735 
736     public final static Number scrollTop() {
737         return JsHTMLElement.scrollTop.with(documentElement());
738     }
739 }