Skip to content

Commit

Permalink
parent height override as construction object added to constructor, a…
Browse files Browse the repository at this point in the history
…dded property test to defining two gloveboxes on the same element.
  • Loading branch information
Fil Maj committed Nov 1, 2010
1 parent 4a8b244 commit f14d42b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions GloveBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function GloveBox(elem, options)
par.addEventListener("mousedown",this,false);
}
par.addEventListener('click', this, true);
if (options && options.parentHeight) par.style.height = options.parentHeight;
// save parent coordinates for mouse events.
this.parentCoords = GloveBox.GetOffset(par);
window.addEventListener('resize', function() {
Expand Down
18 changes: 14 additions & 4 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,27 @@ Tests.prototype = {
var glovebox3 = new GloveBox('somerandomstring');
} catch(e) {
ok(true, 'Expected exception raised when wrong ID string provided on construction' + e.type);
// perhaps should throw its own exception?
equals(e.message, "Cannot read property 'parentNode' of null");
}
ok(glovebox2.scrollY, 'Default scrolling direction is vertical');
ok(!glovebox2.scrollX, 'Horizontal scrolling is off by default');
});
test('GloveBox destruction', function(){
// does it clean up after itself? any side effects from defining two gloveboxes on the same element?
// what about two gloveboxes on same element with different direction styles?
expect(1);
var g_one = new GloveBox('masterList', {scrollX:true, scrollY:false});
g_one.x = -200;
g_one.finishScrolling();
QUnit.chain([function() {
g_two = new GloveBox('masterList', {scrollY:true, scrollX:false});
g_two.y = -1*HALF_H;
g_two.finishScrolling();
}, function() {
equals(g_two.y, -1*HALF_H, 'New GloveBox instances on same element override instantiation parameters');
}], self.bounceTimeout);

})
test('GloveBox options configuration', function() {
expect(3);
Expand Down Expand Up @@ -96,15 +110,11 @@ Tests.prototype = {
glovebox.y = 1*HALF_H;
glovebox.finishScrolling();
QUnit.chain([function() {
console.log('first');
equals(glovebox.y, 0, 'Setting y to out-of-range positive value works');
glovebox.y = -10*HALF_H;
glovebox.finishScrolling();
}, function() {
console.log('second');
equals(glovebox.y, -1*(box.height-glovebox.parentCoords.height), 'Setting y to out-of-range negative value works');
}, function() {
console.log('third');
}], self.bounceTimeout);
});
}
Expand Down

0 comments on commit f14d42b

Please sign in to comment.