2150 |
mathias |
1 |
/*
|
|
|
2 |
_testCommon.js - a simple module to be included in dijit test pages to allow
|
|
|
3 |
for easy switching between the many many points of the test-matrix.
|
|
|
4 |
|
|
|
5 |
in your test browser, provides a way to switch between available themes,
|
|
|
6 |
and optionally enable RTL (right to left) mode, and/or dijit_a11y (high-
|
|
|
7 |
constrast/image off emulation) ... probably not a genuine test for a11y.
|
|
|
8 |
|
|
|
9 |
usage: on any dijit test_* page, press ctrl-f9 to popup links.
|
|
|
10 |
|
|
|
11 |
there are currently (2 themes * 4 tests) * (10 variations of supported browsers)
|
|
|
12 |
not including testing individual locale-strings
|
|
|
13 |
|
|
|
14 |
you should not be using this in a production enviroment. include
|
|
|
15 |
your css and set your classes manually. for test purposes only ...
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
(function(){
|
|
|
19 |
var theme = false; var testMode;
|
|
|
20 |
if(window.location.href.indexOf("?") > -1){
|
|
|
21 |
var str = window.location.href.substr(window.location.href.indexOf("?")+1);
|
|
|
22 |
var ary = str.split(/&/);
|
|
|
23 |
for(var i=0; i<ary.length; i++){
|
|
|
24 |
var split = ary[i].split(/=/),
|
|
|
25 |
key = split[0],
|
|
|
26 |
value = split[1];
|
|
|
27 |
switch(key){
|
|
|
28 |
case "locale":
|
|
|
29 |
// locale string | null
|
|
|
30 |
djConfig.locale = locale = value;
|
|
|
31 |
break;
|
|
|
32 |
case "dir":
|
|
|
33 |
// rtl | null
|
|
|
34 |
document.getElementsByTagName("html")[0].dir = value;
|
|
|
35 |
break;
|
|
|
36 |
case "theme":
|
|
|
37 |
// tundra | soria | noir | squid | null
|
|
|
38 |
theme = value;
|
|
|
39 |
break;
|
|
|
40 |
case "a11y":
|
|
|
41 |
if(value){ testMode = "dijit_a11y"; }
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
// always include the default theme files:
|
|
|
47 |
if(!theme){ theme = djConfig.defaultTestTheme || 'tundra'; }
|
|
|
48 |
var themeCss = dojo.moduleUrl("dijit.themes",theme+"/"+theme+".css");
|
|
|
49 |
var themeCssRtl = dojo.moduleUrl("dijit.themes",theme+"/"+theme+"_rtl.css");
|
|
|
50 |
document.write('<link rel="stylesheet" type="text/css" href="'+themeCss+'"/>');
|
|
|
51 |
document.write('<link rel="stylesheet" type="text/css" href="'+themeCssRtl+'"/>');
|
|
|
52 |
|
|
|
53 |
if(djConfig.parseOnLoad){
|
|
|
54 |
djConfig.parseOnLoad = false;
|
|
|
55 |
djConfig._deferParsing = true;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
dojo.addOnLoad(function(){
|
|
|
59 |
|
|
|
60 |
// set the classes
|
|
|
61 |
|
|
|
62 |
if(!dojo.hasClass(dojo.body(),theme)){ dojo.addClass(dojo.body(),theme); }
|
|
|
63 |
if(testMode){ dojo.addClass(dojo.body(),testMode); }
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
// test-link matrix code:
|
|
|
67 |
var node = document.createElement('div');
|
|
|
68 |
node.id = "testNodeDialog";
|
|
|
69 |
dojo.addClass(node,"dijitTestNodeDialog");
|
|
|
70 |
dojo.body().appendChild(node);
|
|
|
71 |
|
|
|
72 |
_populateTestDialog(node);
|
|
|
73 |
dojo.connect(document,"onkeypress","_testNodeShow");
|
|
|
74 |
|
|
|
75 |
if(djConfig._deferParsing){ dojo.parser.parse(dojo.body()); }
|
|
|
76 |
|
|
|
77 |
});
|
|
|
78 |
|
|
|
79 |
_testNodeShow = function(/* Event */evt){
|
|
|
80 |
var key = (evt.charCode == dojo.keys.SPACE ? dojo.keys.SPACE : evt.keyCode);
|
|
|
81 |
if(evt.ctrlKey && (key == dojo.keys.F9)){ // F9 is generic enough?
|
|
|
82 |
dojo.style(dojo.byId('testNodeDialog'),"top",(dijit.getViewport().t + 4) +"px");
|
|
|
83 |
dojo.toggleClass(dojo.byId('testNodeDialog'),"dijitTestNodeShowing");
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
_populateTestDialog = function(/* DomNode */node){
|
|
|
88 |
// pseudo-function to populate our test-martix-link pop-up
|
|
|
89 |
var base = window.location.pathname;
|
|
|
90 |
var str = "";
|
|
|
91 |
var themes = ["tundra",/*"noir", */ "soria" /* ,"squid" */ ];
|
|
|
92 |
str += "<b>Tests:</b><br><table>";
|
|
|
93 |
dojo.forEach(themes,function(t){
|
|
|
94 |
str += '<tr><td><a hr'+'ef="'+base+'?theme='+t+'">'+t+'</'+'a></td>'+
|
|
|
95 |
'<td><a hr'+'ef="'+base+'?theme='+t+'&dir=rtl">rtl</'+'a></td>'+
|
|
|
96 |
'<td><a hr'+'ef="'+base+'?theme='+t+'&a11y=true">a11y</'+'a></td>'+
|
|
|
97 |
'<td><a hr'+'ef="'+base+'?theme='+t+'&a11y=true&dir=rtl">a11y+rtl</'+'a></td>'+
|
|
|
98 |
// too many potential locales to list, use &locale=[lang] to set
|
|
|
99 |
'</tr>';
|
|
|
100 |
});
|
|
|
101 |
str += '<tr><td colspan="4">jump to: <a hr'+'ef="'+(dojo.moduleUrl("dijit.themes","themeTester.html"))+'">themeTester</'+'a></td></tr>';
|
|
|
102 |
str += '<tr><td colspan="4">or: <a hr'+'ef="'+(dojo.moduleUrl("dijit.tests"))+'">tests folder</'+'a></td></tr>';
|
|
|
103 |
node.innerHTML = str + "</table>";
|
|
|
104 |
}
|
|
|
105 |
})();
|