]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dijit/tests/_testCommon.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dijit / tests / _testCommon.js
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 d = dojo;
20         var theme = false; var testMode;
21         if(window.location.href.indexOf("?") > -1){
22                 var str = window.location.href.substr(window.location.href.indexOf("?")+1).split(/#/);
23                 var ary  = str[0].split(/&/);
24                 for(var i=0; i<ary.length; i++){
25                         var split = ary[i].split(/=/),
26                                 key = split[0],
27                                 value = split[1];
28                         switch(key){
29                                 case "locale":
30                                         // locale string | null
31                                         dojo.config.locale = locale = value;
32                                         break;
33                                 case "dir":
34                                         // rtl | null
35                                         document.getElementsByTagName("html")[0].dir = value;
36                                         break;
37                                 case "theme":
38                                         // tundra | soria | noir | squid | nihilo | null
39                                         theme = value;
40                                         break;
41                                 case "a11y":
42                                         if(value){ testMode = "dijit_a11y"; }
43                         }
44                 }
45         }               
46
47         // always include the default theme files:
48         if(!theme){ theme = dojo.config.defaultTestTheme || 'tundra'; }
49         var themeCss = d.moduleUrl("dijit.themes",theme+"/"+theme+".css");
50         var themeCssRtl = d.moduleUrl("dijit.themes",theme+"/"+theme+"_rtl.css");
51         document.write('<link rel="stylesheet" type="text/css" href="'+themeCss+'"/>');
52         document.write('<link rel="stylesheet" type="text/css" href="'+themeCssRtl+'"/>');
53
54         if(dojo.config.parseOnLoad){ 
55                 dojo.config.parseOnLoad = false;
56                 dojo.config._deferParsing = true;
57         }
58
59         d.addOnLoad(function(){
60
61                 // set the classes
62                 if(!d.hasClass(d.body(),theme)){ d.addClass(d.body(),theme); }
63                 if(testMode){ d.addClass(d.body(),testMode); }
64                         
65                 // test-link matrix code:
66                 var node = document.createElement('div');
67                 node.id = "testNodeDialog";
68                 d.addClass(node,"dijitTestNodeDialog");
69                 d.body().appendChild(node);
70
71                 _populateTestDialog(node);
72
73                 d.connect(document,"onkeypress", function _testNodeShow(/* Event */evt){
74                         var key = (evt.charCode == d.keys.SPACE ? d.keys.SPACE : evt.keyCode);
75                         if(evt.ctrlKey && (key == d.keys.F9)){ // F9 is generic enough?
76                                 d.style('testNodeDialog',"top",(dijit.getViewport().t + 4) +"px");
77                                 d.toggleClass('testNodeDialog',"dijitTestNodeShowing");
78                         }
79                 });
80
81                 if(dojo.config._deferParsing){ d.parser.parse(d.body()); }
82
83         });
84
85         var _populateTestDialog = function(/* DomNode */node){
86                 // pseudo-function to populate our test-martix-link pop-up
87                 var base = window.location.pathname;
88                 var str = "";
89                 var themes = ["tundra",/*"noir", */ "soria", "nihilo" /* ,"squid" */ ];
90                 str += "<b>Tests:</b><br><table>";
91                 d.forEach(themes,function(t){
92                         str +=  '<tr><td><a hr'+'ef="'+base+'?theme='+t+'">'+t+'</'+'a></td>'+
93                                 '<td><a hr'+'ef="'+base+'?theme='+t+'&dir=rtl">rtl</'+'a></td>'+
94                                 '<td><a hr'+'ef="'+base+'?theme='+t+'&a11y=true">a11y</'+'a></td>'+
95                                 '<td><a hr'+'ef="'+base+'?theme='+t+'&a11y=true&dir=rtl">a11y+rtl</'+'a></td>'+
96                                 // too many potential locales to list, use &locale=[lang] to set
97                                 '</tr>';
98                 });
99                 str += '<tr><td colspan="4">jump to: <a hr'+'ef="'+(d.moduleUrl("dijit.themes","themeTester.html"))+'">themeTester</'+'a></td></tr>';
100                 str += '<tr><td colspan="4">or: <a hr'+'ef="'+(d.moduleUrl("dijit.tests"))+'">tests folder</'+'a></td></tr>';
101                 node.innerHTML = str + "</table>";
102         }
103 })();