1 | // module: |
---|
2 | // dijit/tests/_testCommon.js |
---|
3 | // description: |
---|
4 | // Deprecated, remove in 2.0. New test files should use boilerplate.html rather than this file, |
---|
5 | // and non-test files shouldn't be using either. |
---|
6 | |
---|
7 | require([ |
---|
8 | "require", |
---|
9 | "dojo/_base/array", |
---|
10 | "dojo/_base/config", |
---|
11 | "dojo/dom", |
---|
12 | "dojo/dom-attr", |
---|
13 | "dojo/dom-class", |
---|
14 | "dojo/dom-construct", |
---|
15 | "dojo/_base/kernel", |
---|
16 | "dojo/_base/lang", |
---|
17 | "dojo/query", |
---|
18 | "dojo/ready", |
---|
19 | "dojo/_base/window" |
---|
20 | ], function(require, array, config, dom, domAttr, domClass, domConstruct, kernel, lang, query, ready, win){ |
---|
21 | |
---|
22 | var dir = "", |
---|
23 | theme = false, |
---|
24 | themeModule = "dijit", |
---|
25 | testMode = null, |
---|
26 | defTheme = "claro", |
---|
27 | vars={}; |
---|
28 | |
---|
29 | if(window.location.href.indexOf("?") > -1){ |
---|
30 | var str = window.location.href.substr(window.location.href.indexOf("?")+1).split(/#/); |
---|
31 | var ary = str[0].split(/&/); |
---|
32 | for(var i=0; i<ary.length; i++){ |
---|
33 | var split = ary[i].split("="), |
---|
34 | key = split[0], |
---|
35 | value = (split[1]||'').replace(/[^\w]/g, ""); // replace() to prevent XSS attack |
---|
36 | switch(key){ |
---|
37 | case "locale": |
---|
38 | // locale string | null |
---|
39 | kernel.locale = config.locale = locale = value; |
---|
40 | break; |
---|
41 | case "dir": |
---|
42 | // rtl | null |
---|
43 | document.getElementsByTagName("html")[0].dir = value; |
---|
44 | dir = value; |
---|
45 | break; |
---|
46 | case "theme": |
---|
47 | // tundra | soria | nihilo | claro | null |
---|
48 | theme = value; |
---|
49 | break; |
---|
50 | case "a11y": |
---|
51 | if(value){ testMode = "dj_a11y"; } |
---|
52 | break; |
---|
53 | case "themeModule": |
---|
54 | // moduleName | null |
---|
55 | if(value){ themeModule = value; } |
---|
56 | } |
---|
57 | vars[key] = value; |
---|
58 | } |
---|
59 | } |
---|
60 | kernel._getVar = function(k, def){ // TODO: not sure what this is |
---|
61 | return vars[k] || def; |
---|
62 | }; |
---|
63 | |
---|
64 | // BIDI |
---|
65 | if(dir == "rtl"){ |
---|
66 | ready(0, function(){ |
---|
67 | // pretend all the labels are in an RTL language, because |
---|
68 | // that affects how they lay out relative to inline form widgets |
---|
69 | query("label").attr("dir", "rtl"); |
---|
70 | }); |
---|
71 | } |
---|
72 | |
---|
73 | // a11y |
---|
74 | if(testMode){ |
---|
75 | ready(0, function(){ |
---|
76 | var b = win.body(); |
---|
77 | if(testMode){ |
---|
78 | domClass.add(b, testMode); |
---|
79 | } |
---|
80 | }); |
---|
81 | } |
---|
82 | |
---|
83 | // If URL specifies a non-claro theme then pull in those theme CSS files and modify |
---|
84 | // <body> to point to that new theme instead of claro. |
---|
85 | // |
---|
86 | // Also defer parsing and any dojo.ready() calls that the test file makes |
---|
87 | // until the CSS has finished loading. |
---|
88 | if(theme){ |
---|
89 | // Wait until JS modules have finished loading so this doesn't confuse |
---|
90 | // AMD loader. |
---|
91 | ready(1, function(){ |
---|
92 | // Reset <body> to point to the specified theme |
---|
93 | var b = win.body(); |
---|
94 | domClass.replace(b, theme, defTheme); |
---|
95 | |
---|
96 | // Remove claro CSS |
---|
97 | query('link[href$="claro.css"]').orphan(); |
---|
98 | query('link[href$="claro/document.css"]').orphan(); |
---|
99 | |
---|
100 | // Load theme CSS. |
---|
101 | // Eventually would like to use [something like] |
---|
102 | // https://github.com/unscriptable/curl/blob/master/src/curl/plugin/css.js |
---|
103 | // to load the CSS and then know exactly when it finishes loading. |
---|
104 | var modules = [ |
---|
105 | require.toUrl(themeModule+"/themes/"+theme+"/"+theme+".css"), |
---|
106 | require.toUrl(themeModule+"/themes/"+theme+"/"+theme+"_rtl.css"), |
---|
107 | require.toUrl("dojo/resources/dojo.css") |
---|
108 | ]; |
---|
109 | var head = query("head")[0]; |
---|
110 | array.forEach(modules, function(css){ |
---|
111 | if(document.createStyleSheet){ |
---|
112 | // For IE |
---|
113 | document.createStyleSheet(css); |
---|
114 | }else{ |
---|
115 | // For other browsers |
---|
116 | domConstruct.place('<link rel="stylesheet" type="text/css" href="'+css+'"/>', |
---|
117 | head); |
---|
118 | } |
---|
119 | }); |
---|
120 | }); |
---|
121 | ready(2, function(){ |
---|
122 | // Delay parsing and other dojo.ready() callbacks (except ones in this file) |
---|
123 | // until the injected <link>'s above have finished loading. |
---|
124 | require(["dijit/tests/delay!320"]); |
---|
125 | }); |
---|
126 | } |
---|
127 | }); |
---|