Revert "Register as a CommonJS async module if in that kind of environment. Fixes...
[jquery.git] / test / data / testinit.js
1 var jQuery = this.jQuery || "jQuery", // For testing .noConflict()
2         $ = this.$ || "$",
3         originaljQuery = jQuery,
4         original$ = $;
5
6 /**
7  * Returns an array of elements with the given IDs, eg.
8  * @example q("main", "foo", "bar")
9  * @result [<div id="main">, <span id="foo">, <input id="bar">]
10  */
11 function q() {
12         var r = [];
13
14         for ( var i = 0; i < arguments.length; i++ ) {
15                 r.push( document.getElementById( arguments[i] ) );
16         }
17
18         return r;
19 }
20
21 /**
22  * Asserts that a select matches the given IDs * @example t("Check for something", "//[a]", ["foo", "baar"]);
23  * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baa
24 r'
25  */
26 function t(a,b,c) {
27         var f = jQuery(b).get(), s = "";
28
29         for ( var i = 0; i < f.length; i++ ) {
30                 s += (s && ",") + '"' + f[i].id + '"';
31         }
32
33         same(f, q.apply(q,c), a + " (" + b + ")");
34 }
35
36 /**
37  * Add random number to url to stop IE from caching
38  *
39  * @example url("data/test.html")
40  * @result "data/test.html?10538358428943"
41  *
42  * @example url("data/test.php?foo=bar")
43  * @result "data/test.php?foo=bar&10538358345554"
44  */
45 function url(value) {
46         return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000);
47 }