diff --git a/src/js/coverflow.js b/src/js/coverflow.js index 57c68d0..c09b86c 100644 --- a/src/js/coverflow.js +++ b/src/js/coverflow.js @@ -200,7 +200,7 @@ .each(function(){ var $this = $(this); $this.data("origstyle", $this.attr("style") || ""); - }) + }); this.element .addClass( "ui-coverflow" ) diff --git a/tests/qunit/methods.js b/tests/qunit/methods.js index 2d6de24..3c3d78a 100644 --- a/tests/qunit/methods.js +++ b/tests/qunit/methods.js @@ -1,4 +1,11 @@ (function($) { + function getAttributes( $elem ) { + var attrs = {}; + $.each( $elem[ 0 ].attributes, function () { + attrs[ this.nodeName ] = this.nodeValue; + }); + return attrs; + } module( 'CoverflowJS: methods', { setup: function() { @@ -11,5 +18,36 @@ deepEqual( this.el, this.el.coverflow(), 'method is chainable' ); deepEqual( this.el.get( 0 ), this.el.coverflow( 'widget' ).get( 0 ), 'widget method' ); }); + + test( 'destroy', 9, function () { + var originalAttrs = getAttributes( this.el ), + parentOriginalAttrs = getAttributes( this.el.parent() ), + endAttrs, parentEndAttrs; + + ok( ! this.el.hasClass( "ui-coverflow" ), "Element does not have coverflow class" ); + ok( ! this.el.parent().hasClass( "ui-coverflow-wrapper" ), "Element's parent does not have coverflow wrapper class" ); + + this.el.coverflow(); + + ok( this.el.hasClass( "ui-coverflow" ), "Element has coverflow class" ); + ok( this.el.parent().hasClass( "ui-coverflow-wrapper" ), "Element's parent has coverflow wrapper class" ); + + this.el.coverflow( "destroy" ); + + ok( ! this.el.hasClass( "ui-coverflow" ), "Element does not have coverflow class" ); + ok( ! this.el.parent().hasClass( "ui-coverflow-wrapper" ), "Element's parent does not have coverflow wrapper class" ); + + endAttrs = getAttributes( this.el ); + + // Have to compare each attribute since the original element may not have had any styling, leading to a comparison of "" to undefined + $.each( endAttrs, function ( n, v ) { + strictEqual ( v, ( originalAttrs[ n ] || ""), "Element attribute " + n + " matches original after destroy" ); + }); + + parentEndAttrs = getAttributes( this.el.parent() ); + + deepEqual( parentOriginalAttrs, parentEndAttrs, "Element's parent attributes match originals after destroy" ); + + }); })( jQuery );