001/* 002 * Copyright 2014 Cristian Rinaldi & Andres Testi. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package gwt.material.design.jquery.client.api; 017 018/* 019 * #%L 020 * GwtMaterial 021 * %% 022 * Copyright (C) 2015 - 2017 GwtMaterialDesign 023 * %% 024 * Licensed under the Apache License, Version 2.0 (the "License"); 025 * you may not use this file except in compliance with the License. 026 * You may obtain a copy of the License at 027 * 028 * http://www.apache.org/licenses/LICENSE-2.0 029 * 030 * Unless required by applicable law or agreed to in writing, software 031 * distributed under the License is distributed on an "AS IS" BASIS, 032 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 033 * See the License for the specific language governing permissions and 034 * limitations under the License. 035 * #L% 036 */ 037 038import com.google.gwt.core.client.ScriptInjector; 039import com.google.gwt.dom.client.Element; 040import com.google.gwt.dom.client.Node; 041import com.google.gwt.user.client.ui.UIObject; 042import gwt.material.design.jquery.client.api.Functions.Func; 043import gwt.material.design.jquery.client.api.Functions.Func2; 044import gwt.material.design.jquery.client.api.Functions.Func3; 045import gwt.material.design.jquery.client.api.Functions.FuncRet2; 046import jsinterop.annotations.JsMethod; 047import jsinterop.annotations.JsOverlay; 048import jsinterop.annotations.JsPackage; 049import jsinterop.annotations.JsType; 050 051/** 052 * Represent a JQuery access model. 053 * 054 * @author Ben Dol 055 */ 056@JsType(isNative = true) 057public class JQuery { 058 059 @JsOverlay 060 public static Element window() { 061 return ScriptInjector.TOP_WINDOW.cast(); 062 } 063 064 // Plain Object Query 065 066 @JsMethod(namespace = JsPackage.GLOBAL) 067 public static native JQueryElement $(); 068 069 @JsMethod(namespace = JsPackage.GLOBAL) 070 public static native JQueryElement $(Object plainObject); 071 072 @JsMethod(namespace = JsPackage.GLOBAL) 073 public static native JQueryElement $(Object plainObject, Element context); 074 075 @JsMethod(namespace = JsPackage.GLOBAL) 076 public static native JQueryElement $(Object plainObject, gwt.material.design.jscore.client.api.core.Element context); 077 078 @JsMethod(namespace = JsPackage.GLOBAL) 079 public static native JQueryElement $(Object plainObject, JQueryElement context); 080 081 @JsOverlay 082 public static JQueryElement $(Object plainObject, UIObject context) { 083 return $(plainObject, context.getElement()); 084 } 085 086 // String Selector Query 087 088 @JsMethod(namespace = JsPackage.GLOBAL) 089 public static native JQueryElement $(String selector); 090 091 @JsMethod(namespace = JsPackage.GLOBAL) 092 public static native JQueryElement $(String selector, Element context); 093 094 @JsMethod(namespace = JsPackage.GLOBAL) 095 public static native JQueryElement $(String selector, gwt.material.design.jscore.client.api.core.Element context); 096 097 @JsMethod(namespace = JsPackage.GLOBAL) 098 public static native JQueryElement $(String selector, JQueryElement context); 099 100 @JsOverlay 101 public static JQueryElement $(String selector, UIObject context) { 102 return $(selector, context.getElement()); 103 } 104 105 // JQueryElement Query 106 107 @JsMethod(namespace = JsPackage.GLOBAL) 108 public static native JQueryElement $(JQueryElement element); 109 110 @JsMethod(namespace = JsPackage.GLOBAL) 111 public static native JQueryElement $(JQueryElement element, Element context); 112 113 @JsMethod(namespace = JsPackage.GLOBAL) 114 public static native JQueryElement $(JQueryElement element, gwt.material.design.jscore.client.api.core.Element context); 115 116 @JsMethod(namespace = JsPackage.GLOBAL) 117 public static native JQueryElement $(JQueryElement element, JQueryElement context); 118 119 @JsOverlay 120 public static JQueryElement $(JQueryElement element, UIObject context) { 121 return $(element, context.getElement()); 122 } 123 124 // Element Query 125 126 @JsMethod(namespace = JsPackage.GLOBAL) 127 public static native JQueryElement $(Element element); 128 129 @JsMethod(namespace = JsPackage.GLOBAL) 130 public static native JQueryElement $(Element element, Element context); 131 132 @JsMethod(namespace = JsPackage.GLOBAL) 133 public static native JQueryElement $(Element element, gwt.material.design.jscore.client.api.core.Element context); 134 135 @JsMethod(namespace = JsPackage.GLOBAL) 136 public static native JQueryElement $(Element element, JQueryElement context); 137 138 @JsOverlay 139 public static JQueryElement $(Element element, UIObject context) { 140 return $(element, context.getElement()); 141 } 142 143 // Node Query 144 145 @JsMethod(namespace = JsPackage.GLOBAL) 146 public static native JQueryElement $(Node element); 147 148 @JsMethod(namespace = JsPackage.GLOBAL) 149 public static native JQueryElement $(Node element, Element context); 150 151 @JsMethod(namespace = JsPackage.GLOBAL) 152 public static native JQueryElement $(Node element, gwt.material.design.jscore.client.api.core.Element context); 153 154 @JsMethod(namespace = JsPackage.GLOBAL) 155 public static native JQueryElement $(Node element, JQueryElement context); 156 157 @JsOverlay 158 public static JQueryElement $(Node element, UIObject context) { 159 return $(element, context.getElement()); 160 } 161 162 // Generic UIObject Query 163 164 @JsOverlay 165 @SuppressWarnings("unchecked") 166 public static <T extends UIObject> JQueryElement $(T uiObject) { 167 return $(uiObject.getElement()); 168 } 169 170 @JsOverlay 171 @SuppressWarnings("unchecked") 172 public static <T extends UIObject> JQueryElement $(T uiObject, Element context) { 173 return $(uiObject.getElement(), context); 174 } 175 176 @JsOverlay 177 @SuppressWarnings("unchecked") 178 public static <T extends UIObject> JQueryElement $(T uiObject, gwt.material.design.jscore.client.api.core.Element context) { 179 return $(uiObject.getElement(), context); 180 } 181 182 @JsOverlay 183 @SuppressWarnings("unchecked") 184 public static <T extends UIObject> JQueryElement $(T uiObject, JQueryElement context) { 185 return $(uiObject.getElement(), context); 186 } 187 188 @JsOverlay 189 @SuppressWarnings("unchecked") 190 public static <T extends UIObject> JQueryElement $(T uiObject, UIObject context) { 191 return $(uiObject.getElement(), context.getElement()); 192 } 193 194 // JQuery Global Functions 195 196 /** 197 * Get arbitrary data associated with the element. 198 * @return self {@link JQueryElement} 199 */ 200 @JsMethod(namespace = "$") 201 public static native JQueryElement _data(JQueryElement element, String key); 202 203 /** 204 * Check to see if a DOM element is a descendant of another DOM element. 205 * @param container The DOM element that may contain the other element. 206 * @param contained The DOM element that may be contained by (a descendant of) the other element. 207 * @return returns true if the DOM element provided by the second argument is a descendant of the DOM 208 * element provided by the first argument, whether it is a direct child or nested more deeply 209 */ 210 @JsMethod(namespace = "$") 211 public static native boolean contains(Element container, Element contained); 212 213 /** 214 * Execute the next function on the queue for the matched element. 215 * @param element A DOM element from which to remove and execute a queued function. 216 */ 217 @JsMethod(namespace = "$") 218 public static native void dequeue(Element element); 219 220 /** 221 * Execute the next function on the queue for the matched element. 222 * @param element A DOM element from which to remove and execute a queued function. 223 * @param queueName A string containing the name of the queue. Defaults to fx, the standard effects queue. 224 */ 225 @JsMethod(namespace = "$") 226 public static native void dequeue(Element element, String queueName); 227 228 /** 229 * A generic iterator function, which can be used to seamlessly iterate over both objects and arrays. 230 * Arrays and array-like objects with a length property (such as a function's arguments object) are 231 * iterated by numeric index, from 0 to length-1. Other objects are iterated via their named properties. 232 * @param array The array to iterate over. 233 * @param callback The function that will be executed on every object. 234 */ 235 @JsMethod(namespace = "$") 236 public static native Object each(Object[] array, Func2<Integer, Object> callback); 237 238 /** 239 * A generic iterator function, which can be used to seamlessly iterate over both objects and arrays. 240 * Arrays and array-like objects with a length property (such as a function's arguments object) are 241 * iterated by numeric index, from 0 to length-1. Other objects are iterated via their named properties. 242 * @param object The object to iterate over. 243 * @param callback The function that will be executed on every object. 244 */ 245 @JsMethod(namespace = "$") 246 public static native Object each(Object object, Func2<Integer, Object> callback); 247 248 /** 249 * Takes a string and throws an exception containing it. 250 * @param message The message to send out. 251 */ 252 @JsMethod(namespace = "$") 253 public static native void error(String message); 254 255 /** 256 * Load JSON-encoded data from the server using a GET HTTP request. 257 * @param url A string containing the URL to which the request is sent. 258 */ 259 @JsMethod(namespace = "$") 260 public static native Object getJSON(String url); 261 262 /** 263 * Load JSON-encoded data from the server using a GET HTTP request. 264 * @param url A string containing the URL to which the request is sent. 265 * @param success A callback function that is executed if the request succeeds. 266 */ 267 @JsMethod(namespace = "$") 268 public static native Object getJSON(String url, Func3<Object, String, Object> success); 269 270 /** 271 * Load JSON-encoded data from the server using a GET HTTP request. 272 * @param url A string containing the URL to which the request is sent. 273 * @param data A plain object or string that is sent to the server with the request. 274 */ 275 @JsMethod(namespace = "$") 276 public static native Object getJSON(String url, String data); 277 278 /** 279 * Load JSON-encoded data from the server using a GET HTTP request. 280 * @param url A string containing the URL to which the request is sent. 281 * @param data A plain object or string that is sent to the server with the request. 282 * @param success A callback function that is executed if the request succeeds. 283 */ 284 @JsMethod(namespace = "$") 285 public static native Object getJSON(String url, String data, Func3<Object, String, Object> success); 286 287 /** 288 * Load a JavaScript file from the server using a GET HTTP request, then execute it. 289 * @param url A string containing the URL to which the request is sent. 290 */ 291 @JsMethod(namespace = "$") 292 public static native Object getScript(String url); 293 294 /** 295 * Load a JavaScript file from the server using a GET HTTP request, then execute it. 296 * @param url A string containing the URL to which the request is sent. 297 * @param success A callback function that is executed if the request succeeds. 298 */ 299 @JsMethod(namespace = "$") 300 public static native Object getScript(String url, Func3<Object, String, Object> success); 301 302 /** 303 * Execute some JavaScript code globally. 304 * @param code The JavaScript code to execute. 305 */ 306 @JsMethod(namespace = "$") 307 public static native void globalEval(String code); 308 309 /** 310 * Finds the elements of an array which satisfy a filter function. The original array is not affected. 311 * @param array The array-like object to search through. 312 * @param function The function to process each item against. The first argument to the function is the 313 * item, and the second argument is the index. The function should return a Boolean value. 314 * this will be the global window object. 315 * @return an array of objects 316 */ 317 @JsMethod(namespace = "$") 318 public static native Object[] grep(Object[] array, FuncRet2<Object, Integer> function); 319 320 /** 321 * Finds the elements of an array which satisfy a filter function. The original array is not affected. 322 * @param array The array-like object to search through. 323 * @param function The function to process each item against. The first argument to the function is the 324 * item, and the second argument is the index. The function should return a Boolean value. 325 * this will be the global window object. 326 * @param invert If "invert" is false, or not provided, then the function returns an array consisting of 327 * all elements for which "callback" returns true. If "invert" is true, then the function 328 * returns an array consisting of all elements for which "callback" returns false. 329 * @return an array of objects 330 */ 331 @JsMethod(namespace = "$") 332 public static native Object[] grep(Object[] array, FuncRet2<Object, Integer> function, boolean invert); 333 334 /** 335 * Determine whether an element has any jQuery data associated with it. 336 * @param element A DOM element to be checked for data. 337 * @return If no data is associated with an element (there is no data object at all or the data 338 * object is empty), the method returns false; otherwise it returns true. 339 */ 340 @JsMethod(namespace = "$") 341 public static native boolean hasData(Element element); 342 343 /** 344 * Holds or releases the execution of jQuery's ready event. 345 * @param hold Indicates whether the ready hold is being requested or released 346 */ 347 @JsMethod(namespace = "$") 348 public static native void holdReady(boolean hold); 349 350 /** 351 * Search for a specified value within an array and return its index (or -1 if not found). 352 * @param value The value to search for. 353 * @param array An array through which to search. 354 * @return similar to JavaScript's native .indexOf() method in that it returns -1 when it doesn't 355 * find a match. If the first element within the array matches value, $.inArray() returns 0. 356 */ 357 @JsMethod(namespace = "$") 358 public static native int inArray(Object value, Object[] array); 359 360 /** 361 * Search for a specified value within an array and return its index (or -1 if not found). 362 * @param value The value to search for. 363 * @param array An array through which to search. 364 * @param fromIndex The index of the array at which to begin the search. The default is 0, 365 * which will search the whole array. 366 * @return similar to JavaScript's native .indexOf() method in that it returns -1 when it doesn't 367 * find a match. If the first element within the array matches value, $.inArray() returns 0. 368 */ 369 @JsMethod(namespace = "$") 370 public static native int inArray(Object value, Object[] array, double fromIndex); 371 372 /** 373 * Determine whether the argument is an array. 374 * @param obj Object to test whether or not it is an array. 375 * @return returns a Boolean indicating whether the object is a JavaScript 376 * array (not an array-like object, such as a jQuery object). 377 */ 378 @JsMethod(namespace = "$") 379 public static native boolean isArray(Object obj); 380 381 /** 382 * Check to see if an object is empty (contains no enumerable properties). 383 * @param obj The object that will be checked to see if it's empty. 384 */ 385 @JsMethod(namespace = "$") 386 public static native boolean isEmptyObject(Object obj); 387 388 /** 389 * Determine if the argument passed is a JavaScript function object. 390 * @param obj Object to test whether or not it is a function. 391 */ 392 @JsMethod(namespace = "$") 393 public static native boolean isFunction(Object obj); 394 395 /** 396 * Determines whether its argument is a number. 397 * @param value The value to be tested. 398 * @return The $.isNumeric() method checks whether its argument represents a numeric value. 399 * If so, it returns true. Otherwise it returns false. The argument can be of any type. 400 */ 401 @JsMethod(namespace = "$") 402 public static native boolean isNumeric(Object value); 403 404 /** 405 * Check to see if an object is a plain object (created using "{}" or "new Object"). 406 * @param object The object that will be checked to see if it's a plain object. 407 */ 408 @JsMethod(namespace = "$") 409 public static native boolean isPlainObject(Object object); 410 411 /** 412 * Determine whether the argument is a window. This is used in a number of places in 413 * jQuery to determine if we're operating against a browser window 414 * (such as the current window or an iframe). 415 * @param object Object to test whether or not it is a window. 416 */ 417 @JsMethod(namespace = "$") 418 public static native boolean isWindow(Object object); 419 420 /** 421 * Check to see if a DOM node is within an XML document (or is an XML document). 422 * @param node The DOM node that will be checked to see if it's in an XML document. 423 */ 424 @JsMethod(namespace = "$") 425 public static native boolean isXMLDoc(Element node); 426 427 /** 428 * Convert an array-like object into a true JavaScript array. 429 * @param object Any object to turn into a native Array. 430 */ 431 @JsMethod(namespace = "$") 432 public static native Object[] makeArray(Object object); 433 434 /** 435 * Translate all items in an array or object to new array of items. 436 * @param array The Array to translate. 437 * @param callback The function to process each item against. The first argument to the 438 * function is the array item, the second argument is the index in array 439 * The function can return any value. A returned array will be flattened 440 * into the resulting array. Within the function, this refers to the global 441 * (window) object. Must return an Object type. 442 * @return The final mapped array. 443 */ 444 @JsMethod(namespace = "$") 445 public static native Object[] map(Object[] array, FuncRet2<Object, Integer> callback); 446 447 /** 448 * Translate all items in an array or object to new array of items. 449 * @param object The Object to translate. 450 * @param callback The function to process each item against. The first argument to the 451 * function is the array item, the second argument is the index in array 452 * The function can return any value. A returned array will be flattened 453 * into the resulting array. Within the function, this refers to the global 454 * (window) object. Must return an Object type. 455 * @return The final mapped array. 456 */ 457 @JsMethod(namespace = "$") 458 public static native Object[] map(Object object, FuncRet2<Object, Integer> callback); 459 460 /** 461 * Merge the contents of two arrays together into the first array. 462 * @param first The first array-like object to merge, the elements of second added. 463 * @param second The second array-like object to merge into the first, unaltered. 464 * @return The final merged array. 465 */ 466 @JsMethod(namespace = "$") 467 public static native Object[] merge(Object[] first, Object[] second); 468 469 /** 470 * Relinquish jQuery's control of the $ variable. 471 * @param removeAll A Boolean indicating whether to remove all jQuery variables from the 472 * global scope (including jQuery itself). 473 */ 474 @JsMethod(namespace = "$") 475 public static native Object noConflict(boolean removeAll); 476 477 /** 478 * An empty function. 479 */ 480 @JsMethod(namespace = "$") 481 public static native void noop(); 482 483 /** 484 * Return a number representing the current time. 485 * The $.now() method is a shorthand for the number returned by the expression 486 * (new Date).getTime(). 487 */ 488 @JsMethod(namespace = "$") 489 public static native double now(); 490 491 /** 492 * Create a serialized representation of an array, a plain object, or a jQuery object suitable 493 * for use in a URL query string or Ajax request. In case a jQuery object is passed, it should 494 * contain input elements with name/value properties. 495 * @param obj An array to serialize. 496 * @return Serialized object result. 497 */ 498 @JsMethod(namespace = "$") 499 public static native String param(Object[] obj); 500 501 /** 502 * Create a serialized representation of an array, a plain object, or a jQuery object suitable 503 * for use in a URL query string or Ajax request. In case a jQuery object is passed, it should 504 * contain input elements with name/value properties. 505 * @param obj An object to serialize. 506 * @return Serialized object result. 507 */ 508 @JsMethod(namespace = "$") 509 public static native String param(Object obj); 510 511 /** 512 * Create a serialized representation of an array, a plain object, or a jQuery object suitable 513 * for use in a URL query string or Ajax request. In case a jQuery object is passed, it should 514 * contain input elements with name/value properties. 515 * @param obj A jQuery element to serialize. 516 * @return Serialized object result. 517 */ 518 @JsMethod(namespace = "$") 519 public static native String param(JQueryElement obj); 520 521 /** 522 * Create a serialized representation of an array, a plain object, or a jQuery object suitable 523 * for use in a URL query string or Ajax request. In case a jQuery object is passed, it should 524 * contain input elements with name/value properties. 525 * @param obj An array to serialize. 526 * @param traditional A Boolean indicating whether to perform a traditional "shallow" serialization. 527 * @return Serialized object result. 528 */ 529 @JsMethod(namespace = "$") 530 public static native String param(Object[] obj, boolean traditional); 531 532 /** 533 * Create a serialized representation of an array, a plain object, or a jQuery object suitable 534 * for use in a URL query string or Ajax request. In case a jQuery object is passed, it should 535 * contain input elements with name/value properties. 536 * @param obj An object to serialize. 537 * @param traditional A Boolean indicating whether to perform a traditional "shallow" serialization. 538 * @return Serialized object result. 539 */ 540 @JsMethod(namespace = "$") 541 public static native String param(Object obj, boolean traditional); 542 543 /** 544 * Create a serialized representation of an array, a plain object, or a jQuery object suitable 545 * for use in a URL query string or Ajax request. In case a jQuery object is passed, it should 546 * contain input elements with name/value properties. 547 * @param obj A jQuery element to serialize. 548 * @param traditional A Boolean indicating whether to perform a traditional "shallow" serialization. 549 * @return Serialized object result. 550 */ 551 @JsMethod(namespace = "$") 552 public static native String param(JQueryElement obj, boolean traditional); 553 554 /** 555 * Parses a string into an array of DOM nodes. 556 * @param data HTML string to be parsed 557 * @return Array of DOM nodes from parsed HTML string. 558 */ 559 @JsMethod(namespace = "$") 560 public static native Object[] parseHTML(String data); 561 562 /** 563 * Parses a string into an array of DOM nodes. 564 * @param data HTML string to be parsed 565 * @param context Document element to serve as the context in which the HTML fragment will be created 566 * @return Array of DOM nodes from parsed HTML string. 567 */ 568 @JsMethod(namespace = "$") 569 public static native Object[] parseHTML(String data, Element context); 570 571 /** 572 * Parses a string into an array of DOM nodes. 573 * @param data HTML string to be parsed 574 * @param keepScripts A Boolean indicating whether to include scripts passed in the HTML string 575 * @return Array of DOM nodes from parsed HTML string. 576 */ 577 @JsMethod(namespace = "$") 578 public static native Object[] parseHTML(String data, boolean keepScripts); 579 580 /** 581 * Parses a string into an array of DOM nodes. 582 * @param data HTML string to be parsed 583 * @param context Document element to serve as the context in which the HTML fragment will be created 584 * @param keepScripts A Boolean indicating whether to include scripts passed in the HTML string 585 * @return Array of DOM nodes from parsed HTML string. 586 */ 587 @JsMethod(namespace = "$") 588 public static native Object[] parseHTML(String data, Element context, boolean keepScripts); 589 590 /** 591 * Takes a well-formed JSON string and returns the resulting JavaScript value. 592 * @param json The JSON string to parse. 593 * @return String, Number, Object, Array or Boolean. 594 */ 595 @JsMethod(namespace = "$") 596 public static native Object parseJSON(String json); 597 598 /** 599 * Parses a string into an XML document. 600 * @param data a well-formed XML string to be parsed 601 * @return XMLDocument 602 */ 603 @JsMethod(namespace = "$") 604 public static native Object parseXML(String data); 605 606 /** 607 * Load data from the server using a HTTP POST request. 608 * @param url A string containing the URL to which the request is sent. 609 */ 610 @JsMethod(namespace = "$") 611 public static native Object post(String url); 612 613 /** 614 * Load data from the server using a HTTP POST request. 615 * @param url A string containing the URL to which the request is sent. 616 * @param data A plain object or string that is sent to the server with the request. 617 */ 618 @JsMethod(namespace = "$") 619 public static native Object post(String url, String data); 620 621 /** 622 * Load data from the server using a HTTP POST request. 623 * @param url A string containing the URL to which the request is sent. 624 * @param data A plain object or string that is sent to the server with the request. 625 * @param success A callback function that is executed if the request succeeds. Required if 626 * dataType is provided, but can be null in that case. 627 */ 628 @JsMethod(namespace = "$") 629 public static native Object post(String url, String data, Func3<Object, String, Object> success); 630 631 /** 632 * Load data from the server using a HTTP POST request. 633 * @param url A string containing the URL to which the request is sent. 634 * @param data A plain object or string that is sent to the server with the request. 635 * @param success A callback function that is executed if the request succeeds. Required if 636 * dataType is provided, but can be null in that case. 637 * @param dataType The type of data expected from the server. Default: Intelligent Guess 638 * (xml, json, script, text, html). 639 */ 640 @JsMethod(namespace = "$") 641 public static native Object post(String url, String data, Func3<Object, String, Object> success, String dataType); 642 643 /** 644 * Load data from the server using a HTTP POST request. 645 * @param settings A set of key/value pairs that configure the Ajax request. All properties 646 * except for url are optional. A default can be set for any option with 647 * $.ajaxSetup(). See jQuery.ajax( settings ) for a complete list of all 648 * settings. Type will automatically be set to POST. 649 */ 650 @JsMethod(namespace = "$") 651 public static native Object post(Object settings); 652 653 /** 654 * Takes a function and returns a new one that will always have a particular context. 655 * @param function The function whose context will be changed. 656 * @param context The object to which the context (this) of the function should be set. 657 * @return The new function proxied. 658 */ 659 @JsMethod(namespace = "$") 660 public static native Func proxy(Func function, Object context); 661 662 /** 663 * Takes a function and returns a new one that will always have a particular context. 664 * @param function The function whose context will be changed. 665 * @param context The object to which the context (this) of the function should be set. 666 * @param additionalArguments Any number of arguments to be passed to the function referenced 667 * in the function argument. 668 * @return The new function proxied. 669 */ 670 @JsMethod(namespace = "$") 671 public static native Func proxy(Func function, Object context, Object... additionalArguments); 672 673 /** 674 * Takes a function and returns a new one that will always have a particular context. 675 * @param context The object to which the context of the function should be set. 676 * @param name The name of the function whose context will be changed (should be a property 677 * of the context object). 678 * @return The new function proxied. 679 */ 680 @JsMethod(namespace = "$") 681 public static native Func proxy(Object context, String name); 682 683 /** 684 * Takes a function and returns a new one that will always have a particular context. 685 * @param context The object to which the context of the function should be set. 686 * @param name The name of the function whose context will be changed (should be a property 687 * of the context object). 688 * @param additionalArguments Any number of arguments to be passed to the function referenced 689 * in the function argument. 690 * @return The new function proxied. 691 */ 692 @JsMethod(namespace = "$") 693 public static native Func proxy(Object context, String name, Object... additionalArguments); 694 695 /** 696 * Remove a previously-stored piece of data. 697 * @param element A DOM element from which to remove data. 698 */ 699 @JsMethod(namespace = "$") 700 public static native JQueryElement removeData(Element element); 701 702 /** 703 * Remove a previously-stored piece of data. 704 * @param element A DOM element from which to remove data. 705 * @param name A string naming the piece of data to remove. 706 */ 707 @JsMethod(namespace = "$") 708 public static native JQueryElement removeData(Element element, String name); 709 710 /** 711 * Remove the whitespace from the beginning and end of a string. 712 * @param str The string to trim. 713 */ 714 @JsMethod(namespace = "$") 715 public static native String trim(String str); 716 717 /** 718 * Determine the internal JavaScript [[Class]] of an object. 719 * @param obj Object to get the internal JavaScript [[Class]] of. 720 */ 721 @JsMethod(namespace = "$") 722 public static native String type(Object obj); 723 724 /** 725 * Sorts an array of DOM elements, in place, with the duplicates removed. Note that 726 * this only works on arrays of DOM elements, not strings or numbers. 727 * @param array The Array of DOM elements. 728 */ 729 @JsMethod(namespace = "$") 730 public static native Element[] unique(Element[] array); 731}