| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 /* 2 * dialog_options.js 3 */ 4 (function($) { 5 6 module("dialog: options"); 7 8 test("autoOpen", function() { 9 expect(2); 10 11 el = $('<div></div>').dialog({ autoOpen: false }); 12 isNotOpen('.dialog({ autoOpen: false })'); 13 el.remove(); 14 15 el = $('<div></div>').dialog({ autoOpen: true }); 16 isOpen('.dialog({ autoOpen: true })'); 17 el.remove(); 18 }); 19 20 test("buttons", function() { 21 expect(17); 22 23 var buttons = { 24 "Ok": function(ev, ui) { 25 ok(true, "button click fires callback"); 26 equals(this, el[0], "context of callback"); 27 equals(ev.target, btn[0], "event target"); 28 }, 29 "Cancel": function(ev, ui) { 30 ok(true, "button click fires callback"); 31 equals(this, el[0], "context of callback"); 32 equals(ev.target, btn[1], "event target"); 33 } 34 }; 35 36 el = $('<div></div>').dialog({ buttons: buttons }); 37 var btn = $("button", dlg()); 38 equals(btn.length, 2, "number of buttons"); 39 40 var i = 0; 41 $.each(buttons, function(key, val) { 42 equals(btn.eq(i).text(), key, "text of button " + (i+1)); 43 i++; 44 }); 45 46 ok(btn.parent().hasClass('ui-dialog-buttonpane'), "buttons in container"); 47 btn.trigger("click"); 48 49 var newButtons = { 50 "Close": function(ev, ui) { 51 ok(true, "button click fires callback"); 52 equals(this, el[0], "context of callback"); 53 equals(ev.target, btn[0], "event target"); 54 } 55 }; 56 57 equals(el.data("buttons.dialog"), buttons, '.data("buttons.dialog") getter'); 58 el.data("buttons.dialog", newButtons); 59 equals(el.data("buttons.dialog"), newButtons, '.data("buttons.dialog", ...) setter'); 60 61 btn = $("button", dlg()); 62 equals(btn.length, 1, "number of buttons after setter"); 63 btn.trigger('click'); 64 65 i = 0; 66 $.each(newButtons, function(key, val) { 67 equals(btn.eq(i).text(), key, "text of button " + (i+1)); 68 i += 1; 69 }); 70 71 el.remove(); 72 }); 73 74 test("closeOnEscape", function() { 75 ok(false, 'missing test - untested code is broken code'); 76 }); 77 78 test("closeText", function() { 79 expect(3); 80 81 el = $('<div></div>').dialog(); 82 equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'close', 83 'default close text'); 84 el.remove(); 85 86 el = $('<div></div>').dialog({ closeText: "foo" }); 87 equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'foo', 88 'closeText on init'); 89 el.remove(); 90 91 el = $('<div></div>').dialog().dialog('option', 'closeText', 'bar'); 92 equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'bar', 93 'closeText via option method'); 94 el.remove(); 95 }); 96 97 test("dialogClass", function() { 98 expect(4); 99 100 el = $('<div></div>').dialog(); 101 equals(dlg().is(".foo"), false, 'dialogClass not specified. foo class added'); 102 el.remove(); 103 104 el = $('<div></div>').dialog({ dialogClass: "foo" }); 105 equals(dlg().is(".foo"), true, 'dialogClass in init. foo class added'); 106 el.remove(); 107 108 el = $('<div></div>').dialog({ dialogClass: "foo bar" }); 109 equals(dlg().is(".foo"), true, 'dialogClass in init, two classes. foo class added'); 110 equals(dlg().is(".bar"), true, 'dialogClass in init, two classes. bar class added'); 111 el.remove(); 112 }); 113 114 test("draggable", function() { 115 expect(4); 116 117 el = $('<div></div>').dialog({ draggable: false }); 118 shouldnotmove(); 119 el.data('draggable.dialog', true); 120 shouldmove(); 121 el.remove(); 122 123 el = $('<div></div>').dialog({ draggable: true }); 124 shouldmove(); 125 el.data('draggable.dialog', false); 126 shouldnotmove(); 127 el.remove(); 128 }); 129 130 test("height", function() { 131 expect(3); 132 133 el = $('<div></div>').dialog(); 134 equals(dlg().height(), dialog_defaults.minHeight, "default height"); 135 el.remove(); 136 137 el = $('<div></div>').dialog({ height: 437 }); 138 equals(dlg().height(), 437, "explicit height"); 139 el.remove(); 140 141 el = $('<div></div>').dialog(); 142 el.data('height.dialog', 438); 143 equals(dlg().height(), 438, "explicit height set after init"); 144 el.remove(); 145 }); 146 147 test("maxHeight", function() { 148 expect(3); 149 150 el = $('<div></div>').dialog({ maxHeight: 400 }); 151 drag('.ui-resizable-s', 1000, 1000); 152 equals(heightAfter, 400, "maxHeight"); 153 el.remove(); 154 155 el = $('<div></div>').dialog({ maxHeight: 400 }); 156 drag('.ui-resizable-n', -1000, -1000); 157 equals(heightAfter, 400, "maxHeight"); 158 el.remove(); 159 160 el = $('<div></div>').dialog({ maxHeight: 400 }).data('maxHeight.dialog', 600); 161 drag('.ui-resizable-n', -1000, -1000); 162 equals(heightAfter, 600, "maxHeight"); 163 el.remove(); 164 }); 165 166 test("maxWidth", function() { 167 expect(3); 168 169 el = $('<div></div>').dialog({ maxWidth: 400 }); 170 drag('.ui-resizable-e', 1000, 1000); 171 equals(widthAfter, 400, "maxWidth"); 172 el.remove(); 173 174 el = $('<div></div>').dialog({ maxWidth: 400 }); 175 drag('.ui-resizable-w', -1000, -1000); 176 equals(widthAfter, 400, "maxWidth"); 177 el.remove(); 178 179 el = $('<div></div>').dialog({ maxWidth: 400 }).data('maxWidth.dialog', 600); 180 drag('.ui-resizable-w', -1000, -1000); 181 equals(widthAfter, 600, "maxWidth"); 182 el.remove(); 183 }); 184 185 test("minHeight", function() { 186 expect(3); 187 188 el = $('<div></div>').dialog({ minHeight: 10 }); 189 drag('.ui-resizable-s', -1000, -1000); 190 equals(heightAfter, 10, "minHeight"); 191 el.remove(); 192 193 el = $('<div></div>').dialog({ minHeight: 10 }); 194 drag('.ui-resizable-n', 1000, 1000); 195 equals(heightAfter, 10, "minHeight"); 196 el.remove(); 197 198 el = $('<div></div>').dialog({ minHeight: 10 }).data('minHeight.dialog', 30); 199 drag('.ui-resizable-n', 1000, 1000); 200 equals(heightAfter, 30, "minHeight"); 201 el.remove(); 202 }); 203 204 test("minWidth", function() { 205 expect(3); 206 207 el = $('<div></div>').dialog({ minWidth: 10 }); 208 drag('.ui-resizable-e', -1000, -1000); 209 equals(widthAfter, 10, "minWidth"); 210 el.remove(); 211 212 el = $('<div></div>').dialog({ minWidth: 10 }); 213 drag('.ui-resizable-w', 1000, 1000); 214 equals(widthAfter, 10, "minWidth"); 215 el.remove(); 216 217 el = $('<div></div>').dialog({ minWidth: 30 }).data('minWidth.dialog', 30); 218 drag('.ui-resizable-w', 1000, 1000); 219 equals(widthAfter, 30, "minWidth"); 220 el.remove(); 221 }); 222 223 test("modal", function() { 224 ok(false, 'missing test - untested code is broken code'); 225 }); 226 227 test("position", function() { 228 ok(false, 'missing test - untested code is broken code'); 229 }); 230 231 test("resizable", function() { 232 expect(4); 233 234 el = $('<div></div>').dialog(); 235 shouldresize("[default]"); 236 el.data('resizable.dialog', false); 237 shouldnotresize('disabled after init'); 238 el.remove(); 239 240 el = $('<div></div>').dialog({ resizable: false }); 241 shouldnotresize("disabled in init options"); 242 el.data('resizable.dialog', true); 243 shouldresize('enabled after init'); 244 el.remove(); 245 }); 246 247 test("stack", function() { 248 ok(false, 'missing test - untested code is broken code'); 249 }); 250 251 test("title", function() { 252 expect(5); 253 254 function titleText() { 255 return dlg().find(".ui-dialog-title").html(); 256 } 257 258 el = $('<div></div>').dialog(); 259 equals(titleText(), " ", "[default]"); 260 el.remove(); 261 262 el = $('<div title="foo"/>').dialog(); 263 equals(titleText(), "foo", "title in element attribute"); 264 el.remove(); 265 266 el = $('<div></div>').dialog({ title: 'foo' }); 267 equals(titleText(), "foo", "title in init options"); 268 el.remove(); 269 270 el = $('<div title="foo"/>').dialog({ title: 'bar' }); 271 equals(titleText(), "bar", "title in init options should override title in element attribute"); 272 el.remove(); 273 274 el = $('<div></div>').dialog().data('title.dialog', 'foo'); 275 equals(titleText(), 'foo', 'title after init'); 276 el.remove(); 277 }); 278 279 test("width", function() { 280 expect(3); 281 282 el = $('<div></div>').dialog(); 283 equals(dlg().width(), dialog_defaults.width, "default width"); 284 el.remove(); 285 286 el = $('<div></div>').dialog({width: 437 }); 287 equals(dlg().width(), 437, "explicit width"); 288 el.data('width.dialog', 438); 289 equals(dlg().width(), 438, 'explicit width after init'); 290 el.remove(); 291 }); 292 293 })(jQuery);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |