Debian Codegraph @

dojox/mobile/tests/doh/expandingtextarea/ExpandingTextAreaTests.html

raw symbols SCIP
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
5 <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
6 <meta name="apple-mobile-web-app-capable" content="yes" />
7 <title>ExpandingTextArea Tests</title>
8 <script type="text/javascript" src="../../../deviceTheme.js"></script>
9 <script type="text/javascript" src="../../../../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true"></script>
10 <script language="JavaScript" type="text/javascript">
11 var TEXTAREA_ROWS = 3;
12 var TEXTAREA_COLS = 20;
13 var TEXTAREA_INNERHTML = "ExpandingTextArea";
14 var TEXTAREA_NEW_VALUE = "This is mobile ExpandingTextArea.\nThis text area is automaticaly Expanding.\nHello dojox.mobile";
15 var WIDGET_CLASSNAME1 = "mblTextArea";
16 var WIDGET_CLASSNAME2 = "mblExpandingTextArea";
17 var WIDGET_HEIGHT1 = "15px";
18 var WIDGET_HEIGHT1_FF = "30px";
19 var WIDGET_HEIGHT1_FF19 = "30px";
20 // var WIDGET_HEIGHT1_IE6 = "24px";
21 var WIDGET_HEIGHT1_IE10 = "16px"; // IE10+ and WP8
22 // var WIDGET_HEIGHT1_IE8 = "26px";
23 var WIDGET_HEIGHT1_IE = "25px"; // IE9
24 var WIDGET_OFFSETHEIGHT1 = 25;
25 var WIDGET_OFFSETHEIGHT1_FF = 40;
26 var WIDGET_OFFSETHEIGHT1_FF19 = 40;
27 var WIDGET_OFFSETHEIGHT1_IE = 35; // IE9
28 var WIDGET_OFFSETHEIGHT1_IE10 = 20; // IE10+ and WP8
29 var WIDGET_OFFSETHEIGHT2 = 85;
30 // var WIDGET_OFFSETHEIGHT2_IE8 = "133";
31 var WIDGET_OFFSETHEIGHT2_IE = "125"; // IE9
32 var WIDGET_OFFSETHEIGHT2_IE10 = "52";
33
34 require([
35 "dojo/_base/connect",
36 "dojo/sniff",
37 "dojo/dom-construct", // dojo.place
38 "dojo/dom-class", // dojo.hasClass
39 "dojo/ready", // dojo.ready
40 "dijit/registry", // dijit.byId
41 "doh/runner", //doh functions
42 "dojox/mobile/ExpandingTextArea",
43 "dojox/mobile", // This is a mobile app.
44 "dojox/mobile/View", // This mobile app uses mobile view
45 "dojox/mobile/compat", // This mobile app supports running on desktop browsers
46 "dojox/mobile/parser" // This mobile app uses declarative programming with fast mobile parser
47 ], function(connect, has, domConst, domClass, ready, registry, runner, ExpandingTextArea){
48 function _createExpandingTextAreaDeclaratively(widgetId) {
49 return registry.byId(widgetId);
50 }
51 function _createExpandingTextAreaProgrammatically(placeHolderId, widgetId, rows, cols, innerHTML){
52 var r = new ExpandingTextArea({id:widgetId, rows:rows, cols:cols, innerHTML:innerHTML});
53 runner.assertNotEqual(null, r);
54 domConst.place(r.domNode, placeHolderId, "replace");
55 r.startup();
56
57 return r;
58 }
59 function _createExpandingTextAreaProgrammaticallyWithSourceNodeReference(widgetId){
60 // Create IconContainer
61 var r = new ExpandingTextArea({}, widgetId);
62
63 r.startup();
64 return r;
65 }
66 function _assertCorrectExpandingTextArea(widget, styleHeight, offsetHeight1, offsetHeight2){
67 if(styleHeight < 0){
68 return; // Skip for IE<9 (a negative styleHeight is the convention we use for skipping)
69 }
70 runner.assertNotEqual(null, widget, "IconItem: Did not instantiate.");
71 runner.assertTrue(domClass.contains(widget.domNode, WIDGET_CLASSNAME1), WIDGET_CLASSNAME1 + " id=" + widget.domNode.id);
72 runner.assertTrue(domClass.contains(widget.domNode, WIDGET_CLASSNAME2), WIDGET_CLASSNAME2 + " id=" + widget.domNode.id);
73 runner.assertTrue(widget.domNode.style.height.slice(0,2) >= styleHeight.slice(0,2), "domNode height [" + widget.domNode.style.height + "] >= expected min height[" + styleHeight + "]? style.height id=" + widget.domNode.id);
74 runner.assertTrue(widget.domNode.offsetHeight >= offsetHeight1,
75 "domNode offsetHeight[" + widget.domNode.offsetHeight + "] >= expected min offsetHeight1[" + offsetHeight1 + "]? " +
76 "offsetHeight1 id=" + widget.domNode.id);
77 runner.assertEqual(TEXTAREA_INNERHTML, widget.textbox.value, 'textbox value');
78 runner.assertEqual(TEXTAREA_INNERHTML, widget.get('value'), 'widget value');
79 widget.set('value', TEXTAREA_NEW_VALUE);
80 runner.assertTrue(widget.domNode.offsetHeight >= offsetHeight2,
81 "domNode offsetHeight[" + widget.domNode.offsetHeight + "] >= expected min offsetHeight2[" + offsetHeight2 + "]? " +
82 "offsetHeight2 id=" + widget.domNode.id);
83 runner.assertEqual(TEXTAREA_NEW_VALUE, widget.textbox.value.replace(/\r\n/g, "\n"), 'textbox new value');
84 runner.assertEqual(TEXTAREA_NEW_VALUE, widget.get('value').replace(/\r\n/g, "\n"), 'widget new value');
85 }
86 function _showView2(){
87 var view1 = registry.byId("view1");
88 view1.performTransition("view2", 1, "none");
89 }
90 ready(function(){
91 var styleHeight = has("ie") ? (has("ie") === 10 ? WIDGET_HEIGHT1_IE10 : WIDGET_HEIGHT1_IE) : has("ff") ?
92 (has("ff") >= 19 ? WIDGET_HEIGHT1_FF19 : WIDGET_HEIGHT1_FF) :
93 (has("trident") > 6) ? WIDGET_HEIGHT1_IE10 : WIDGET_HEIGHT1;
94 var offsetHeight1 = has("ie") ? (has("ie") === 10 ? WIDGET_OFFSETHEIGHT1_IE10 : WIDGET_OFFSETHEIGHT1_IE) : has("ff") ?
95 (has("ff") >= 19 ? WIDGET_OFFSETHEIGHT1_FF19 : WIDGET_OFFSETHEIGHT1_FF) :
96 (has("trident") > 6) ? WIDGET_OFFSETHEIGHT1_IE10 : WIDGET_OFFSETHEIGHT1;
97 var offsetHeight2 = has("ie") ? (has("ie") === 10 ? WIDGET_OFFSETHEIGHT2_IE10 : WIDGET_OFFSETHEIGHT2_IE) :
98 (has("trident") > 6) ? WIDGET_OFFSETHEIGHT2_IE10 : WIDGET_OFFSETHEIGHT2;
99 // Skip the checks for IE<9
100 if(has("ie") < 9){
101 styleHeight = -1; // negative value as convention for skipping tests
102 }
103 runner.register("dojox.mobile.test.doh.ExpandingTextArea", [
104 {
105 name: "ExpandingTextArea Verification1",
106 timeout: 4000,
107 runTest: function(){
108 var widget1 = _createExpandingTextAreaDeclaratively("dojox_mobile_ExpandingTextArea_0");
109 var widget2 = _createExpandingTextAreaProgrammatically("view1-ExpandingTextArea2place", "view1-ExpandingTextArea2", TEXTAREA_ROWS, TEXTAREA_COLS, TEXTAREA_INNERHTML);
110 var widget3 = _createExpandingTextAreaProgrammaticallyWithSourceNodeReference("view1-ExpandingTextArea3");
111
112 var d = new runner.Deferred();
113 setTimeout(d.getTestCallback(function(){
114 var widget1 = registry.byId("dojox_mobile_ExpandingTextArea_0");
115 var widget2 = registry.byId("view1-ExpandingTextArea2");
116 var widget3 = registry.byId("view1-ExpandingTextArea3");
117 _assertCorrectExpandingTextArea(widget1, styleHeight, offsetHeight1, offsetHeight2);
118 _assertCorrectExpandingTextArea(widget2, styleHeight, offsetHeight1, offsetHeight2);
119 _assertCorrectExpandingTextArea(widget3, styleHeight, offsetHeight1, offsetHeight2);
120 }), 2000);
121 return d;
122 }
123 },
124 {
125 name: "ExpandingTextArea Verification2",
126 timeout: 4000,
127 runTest: function(){
128 var widget1 = _createExpandingTextAreaDeclaratively("dojox_mobile_ExpandingTextArea_1");
129 var widget2 = _createExpandingTextAreaProgrammatically("view2-ExpandingTextArea2place", "view2-ExpandingTextArea2", TEXTAREA_ROWS, TEXTAREA_COLS, TEXTAREA_INNERHTML);
130 var widget3 = _createExpandingTextAreaProgrammaticallyWithSourceNodeReference("view2-ExpandingTextArea3");
131
132 _showView2();
133 var d = new runner.Deferred();
134 setTimeout(d.getTestCallback(function(){
135 var widget1 = registry.byId("dojox_mobile_ExpandingTextArea_1");
136 var widget2 = registry.byId("view2-ExpandingTextArea2");
137 var widget3 = registry.byId("view2-ExpandingTextArea3");
138 _assertCorrectExpandingTextArea(widget1, styleHeight, offsetHeight1, offsetHeight2);
139 _assertCorrectExpandingTextArea(widget2, styleHeight, offsetHeight1, offsetHeight2);
140 _assertCorrectExpandingTextArea(widget3, styleHeight, offsetHeight1, offsetHeight2);
141 }), 2000);
142 return d;
143 }
144 }
145 ]);
146 runner.run();
147 });
148 })
149 </script>
150 </head>
151 <body style="visibility:hidden;">
152 <div id="view1" data-dojo-type="dojox.mobile.View" selected="true">
153 <h1>View 1</h1>
154 <textarea data-dojo-type="dojox.mobile.ExpandingTextArea" rows="3" cols="20">ExpandingTextArea</textarea><br>
155 <div id="view1-ExpandingTextArea2place"></div><br>
156 <textarea id="view1-ExpandingTextArea3" rows="3" cols="20">ExpandingTextArea</textarea><br>
157 </div>
158 <div id="view2" data-dojo-type="dojox.mobile.View">
159 <h1>View 2</h1>
160 <textarea data-dojo-type="dojox.mobile.ExpandingTextArea" rows="3" cols="20">ExpandingTextArea</textarea><br>
161 <div id="view2-ExpandingTextArea2place"></div><br>
162 <textarea id="view2-ExpandingTextArea3" rows="3" cols="20">ExpandingTextArea</textarea><br>
163 </div>
164 </body>
165 </html>