|
5 | 5 |
|
6 | 6 | (function( $ ){
|
7 | 7 |
|
8 |
| - var defaults = $.mobile.panel.prototype.options, |
9 |
| - classes = defaults.classes; |
| 8 | + var count, |
| 9 | + defaults = $.mobile.panel.prototype.options, |
| 10 | + classes = defaults.classes, |
| 11 | + originalWidget = $.mobile.panel.prototype; |
10 | 12 |
|
11 | 13 | function getPageFromPanel( $panel ) {
|
12 | 14 | return $panel.closest( ":jqmData(role='page')" );
|
|
353 | 355 | start
|
354 | 356 | ]);
|
355 | 357 | });
|
| 358 | + module( "wrapper generation", { |
| 359 | + setup: function() { |
| 360 | + count = 0; |
| 361 | + $.widget( "mobile.panel", $.mobile.panel, { |
| 362 | + _getWrapper: function() { |
| 363 | + this._super(); |
| 364 | + count++; |
| 365 | + } |
| 366 | + }); |
| 367 | + }, |
| 368 | + teardown: function() { |
| 369 | + $.mobile.panel.prototype = originalWidget; |
| 370 | + } |
| 371 | + }); |
| 372 | + asyncTest( "overlay panel should not call getWrapper", function(){ |
| 373 | + expect( 5 ); |
| 374 | + var testPanel = $( "#panel-test-get-wrapper-overlay" ); |
| 375 | + |
| 376 | + testPanel.panel({ |
| 377 | + "display": "overlay" |
| 378 | + }); |
| 379 | + ok( count === 0, "getWrapper only called once durring create" ); |
| 380 | + testPanel.panel( "open" ); |
| 381 | + testPanel.one( "panelopen", function(){ |
| 382 | + ok( count === 0, "getWrapper not called on open" ); |
| 383 | + }); |
| 384 | + testPanel.panel( "close" ); |
| 385 | + testPanel.one( "panelclose", function(){ |
| 386 | + ok( count === 0, "getWrapper not called on close" ); |
| 387 | + $.mobile.changePage( "#page2" ); |
| 388 | + }); |
| 389 | + $( "body" ).one( "pagechange", function(){ |
| 390 | + ok( count === 0, "getWrapper not called on pagechange" ); |
| 391 | + $.mobile.changePage( "#page1" ); |
| 392 | + $( "body" ).one( "pagechange", function(){ |
| 393 | + ok( count === 0, "getWrapper not called on pagechange back to inital page" ); |
| 394 | + start(); |
| 395 | + }); |
| 396 | + }); |
| 397 | + |
| 398 | + }); |
| 399 | + asyncTest( "push should call getWrapper only once on create", function(){ |
| 400 | + expect( 5 ); |
| 401 | + var testPanel = $( "#panel-test-get-wrapper-push" ); |
| 402 | + |
| 403 | + testPanel.panel({ |
| 404 | + "display": "push" |
| 405 | + }); |
| 406 | + ok( count === 1, "getWrapper only called once durring create" ); |
| 407 | + testPanel.panel( "open" ); |
| 408 | + testPanel.one( "panelopen", function(){ |
| 409 | + ok( count === 1, "getWrapper not called on open" ); |
| 410 | + }); |
| 411 | + testPanel.panel( "close" ); |
| 412 | + testPanel.one( "panelclose", function(){ |
| 413 | + ok( count === 1, "getWrapper not called on close" ); |
| 414 | + $.mobile.changePage( "#page2" ); |
| 415 | + }); |
| 416 | + $( "body" ).one( "pagechange", function(){ |
| 417 | + ok( count === 1, "getWrapper not called on pagechange" ); |
| 418 | + $.mobile.changePage( "#page1" ); |
| 419 | + $( "body" ).one( "pagechange", function(){ |
| 420 | + ok( count === 1, "getWrapper not called on pagechange back to inital page" ); |
| 421 | + start(); |
| 422 | + }); |
| 423 | + }); |
| 424 | + |
| 425 | + }); |
| 426 | + asyncTest( "reveal panel should call getWrapper only once on create", function(){ |
| 427 | + expect( 5 ); |
| 428 | + var testPanel = $( "#panel-test-get-wrapper" ); |
| 429 | + |
| 430 | + testPanel.panel(); |
| 431 | + ok( count === 1, "getWrapper only called once durring create" ); |
| 432 | + testPanel.panel( "open" ); |
| 433 | + testPanel.one( "panelopen", function(){ |
| 434 | + ok( count === 1, "getWrapper not called on open" ); |
| 435 | + }); |
| 436 | + testPanel.panel( "close" ); |
| 437 | + testPanel.one( "panelclose", function(){ |
| 438 | + ok( count === 1, "getWrapper not called on close" ); |
| 439 | + $.mobile.changePage( "#page2" ); |
| 440 | + }); |
| 441 | + $( "body" ).one( "pagechange", function(){ |
| 442 | + ok( count === 1, "getWrapper not called on pagechange" ); |
| 443 | + $.mobile.changePage( "#page1" ); |
| 444 | + $( "body" ).one( "pagechange", function(){ |
| 445 | + ok( count === 1, "getWrapper not called on pagechange back to inital page" ); |
| 446 | + start(); |
| 447 | + }); |
| 448 | + }); |
| 449 | + |
| 450 | + }); |
| 451 | + asyncTest( "external panel should call panel once on create and on page changes", function(){ |
| 452 | + expect( 5 ); |
| 453 | + var testPanel = $( "#external-panel-test" ); |
| 454 | + |
| 455 | + testPanel.panel(); |
| 456 | + ok( count === 1, "getWrapper only called once durring create" ); |
| 457 | + testPanel.panel( "open" ); |
| 458 | + testPanel.one( "panelopen", function(){ |
| 459 | + ok( count === 1, "getWrapper not called on open" ); |
| 460 | + }); |
| 461 | + testPanel.panel( "close" ); |
| 462 | + testPanel.one( "panelclose", function(){ |
| 463 | + ok( count === 1, "getWrapper not called on close" ); |
| 464 | + $.mobile.changePage( "#page2" ); |
| 465 | + $( "body" ).one( "pageshow", function(){ |
| 466 | + window.setTimeout( function(){ |
| 467 | + ok( count === 2, "getWrapper called on pagechange" ); |
| 468 | + }, 0 ); |
| 469 | + |
| 470 | + $( "body" ).one( "pageshow", function(){ |
| 471 | + window.setTimeout( function(){ |
| 472 | + ok( count === 3, "getWrapper called on pagechange back to inital page" ); |
| 473 | + start(); |
| 474 | + }, 0 ); |
| 475 | + }); |
| 476 | + $.mobile.changePage( "#page1" ); |
| 477 | + }); |
| 478 | + }); |
| 479 | + }); |
356 | 480 |
|
357 | 481 | }( jQuery ));
|
0 commit comments