Skip to content

Commit

Permalink
add new roundedEquals helper
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkettner committed Feb 26, 2015
1 parent b8ea91c commit 072f3bd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
4 changes: 2 additions & 2 deletions feature-detects/css/vmaxunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}]
}
!*/
define(['Modernizr', 'docElement', 'testStyles'], function( Modernizr, docElement, testStyles ) {
define(['Modernizr', 'docElement', 'testStyles', 'roundedEquals'], function( Modernizr, docElement, testStyles, roundedEquals ) {
testStyles('#modernizr1{width: 50vmax}#modernizr2{width:50px;height:50px;overflow:scroll}', function() {
var elem = document.getElementById('modernizr1');
var scroller = document.getElementById('modernizr2');
Expand All @@ -27,6 +27,6 @@ define(['Modernizr', 'docElement', 'testStyles'], function( Modernizr, docElemen
getComputedStyle(elem, null) :
elem.currentStyle)['width'],10);

Modernizr.addTest('cssvmaxunit', expectedWidth === compWidth || expectedWidth === compWidth - scrollbarWidth);
Modernizr.addTest('cssvmaxunit', roundedEquals(expectedWidth, compWidth) || roundedEquals(expectedWidth, compWidth - scrollbarWidth));
}, 2);
});
4 changes: 2 additions & 2 deletions feature-detects/css/vminunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}]
}
!*/
define(['Modernizr', 'docElement', 'testStyles'], function( Modernizr, docElement, testStyles ) {
define(['Modernizr', 'docElement', 'testStyles', 'roundedEquals'], function( Modernizr, docElement, testStyles, roundedEquals ) {
testStyles('#modernizr1{width: 50vmin}#modernizr2{width:50px;height:50px;overflow:scroll}', function() {
var elem = document.getElementById('modernizr1');
var scroller = document.getElementById('modernizr2');
Expand All @@ -27,6 +27,6 @@ define(['Modernizr', 'docElement', 'testStyles'], function( Modernizr, docElemen
getComputedStyle(elem, null) :
elem.currentStyle)['width'],10);

Modernizr.addTest('cssvminunit', expectedWidth === compWidth || expectedWidth === compWidth - scrollbarWidth);
Modernizr.addTest('cssvminunit', roundedEquals(expectedWidth, compWidth) || roundedEquals(expectedWidth, compWidth - scrollbarWidth));
}, 2);
});
8 changes: 8 additions & 0 deletions src/roundedEquals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define(function() {
// Change the function's scope.
function roundedEquals(a, b) {
return a - 1 === b || a === b || a + 1 === b;
}

return roundedEquals;
});
28 changes: 28 additions & 0 deletions test/browser/src/roundedEquals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
describe('roundedEquals', function() {
var roundedEquals;
var cleanup;

before(function(done) {

requirejs.config({
baseUrl: '../src',
paths: { cleanup: '../test/cleanup' }
});

requirejs(['roundedEquals', 'cleanup'], function(_roundedEquals, _cleanup) {
roundedEquals = _roundedEquals;
cleanup = _cleanup;
done();
});
});

it('works', function() {
expect(roundedEquals(1, 2)).to.be(true);
expect(roundedEquals(2, 2)).to.be(true);
expect(roundedEquals(3, 2)).to.be(true);
});

after(function() {
cleanup();
});
});

0 comments on commit 072f3bd

Please sign in to comment.