Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Convert to 2-spaces for tabs because I like it.

  • Loading branch information...
commit 0c151e167feb5fb6cb24f059da387d3b2095fc72 1 parent 661c801
@zachleat authored
Showing with 353 additions and 355 deletions.
  1. +232 −232 bigtext.js
  2. +121 −123 test/bigtextTest.js
View
464 bigtext.js
@@ -1,264 +1,264 @@
;(function(window, $)
{
- var counter = 0,
- $headCache = $('head'),
- oldBigText = window.BigText,
- oldjQueryMethod = $.fn.bigtext,
- BigText = {
- DEFAULT_MIN_FONT_SIZE_PX: null,
- DEFAULT_MAX_FONT_SIZE_PX: 528,
- GLOBAL_STYLE_ID: 'bigtext-style',
- STYLE_ID: 'bigtext-id',
- LINE_CLASS_PREFIX: 'bigtext-line',
- EXEMPT_CLASS: 'bigtext-exempt',
- DEFAULT_CHILD_SELECTOR: '> div',
- childSelectors: {
- div: '> div',
- ol: '> li',
- ul: '> li'
- },
- noConflict: function(restore)
- {
- if(restore) {
- $.fn.bigtext = oldjQueryMethod;
- window.BigText = oldBigText;
- }
- return BigText;
- },
- init: function()
- {
- if(!$('#'+BigText.GLOBAL_STYLE_ID).length) {
- $headCache.append(BigText.generateStyleTag(BigText.GLOBAL_STYLE_ID, ['.bigtext * { white-space: nowrap; }',
- '.bigtext .' + BigText.EXEMPT_CLASS + ', .bigtext .' + BigText.EXEMPT_CLASS + ' * { white-space: normal; }']));
- }
- },
- bindResize: function(eventName, resizeFunction)
- {
- if($.throttle) {
- // https://github.com/cowboy/jquery-throttle-debounce
- $(window).unbind(eventName).bind(eventName, $.throttle(100, resizeFunction));
- } else {
- if($.fn.smartresize) {
- // https://github.com/lrbabe/jquery-smartresize/
- eventName = 'smartresize.' + eventName;
- }
- $(window).unbind(eventName).bind(eventName, resizeFunction);
- }
- },
- getStyleId: function(id)
- {
- return BigText.STYLE_ID + '-' + id;
- },
- generateStyleTag: function(id, css)
- {
- return $('<style>' + css.join('\n') + '</style>').attr('id', id);
- },
- clearCss: function(id)
- {
- var styleId = BigText.getStyleId(id);
- $('#' + styleId).remove();
- },
- generateCss: function(id, linesFontSizes, lineWordSpacings, minFontSizes)
- {
- var css = [];
+ var counter = 0,
+ $headCache = $('head'),
+ oldBigText = window.BigText,
+ oldjQueryMethod = $.fn.bigtext,
+ BigText = {
+ DEFAULT_MIN_FONT_SIZE_PX: null,
+ DEFAULT_MAX_FONT_SIZE_PX: 528,
+ GLOBAL_STYLE_ID: 'bigtext-style',
+ STYLE_ID: 'bigtext-id',
+ LINE_CLASS_PREFIX: 'bigtext-line',
+ EXEMPT_CLASS: 'bigtext-exempt',
+ DEFAULT_CHILD_SELECTOR: '> div',
+ childSelectors: {
+ div: '> div',
+ ol: '> li',
+ ul: '> li'
+ },
+ noConflict: function(restore)
+ {
+ if(restore) {
+ $.fn.bigtext = oldjQueryMethod;
+ window.BigText = oldBigText;
+ }
+ return BigText;
+ },
+ init: function()
+ {
+ if(!$('#'+BigText.GLOBAL_STYLE_ID).length) {
+ $headCache.append(BigText.generateStyleTag(BigText.GLOBAL_STYLE_ID, ['.bigtext * { white-space: nowrap; }',
+ '.bigtext .' + BigText.EXEMPT_CLASS + ', .bigtext .' + BigText.EXEMPT_CLASS + ' * { white-space: normal; }']));
+ }
+ },
+ bindResize: function(eventName, resizeFunction)
+ {
+ if($.throttle) {
+ // https://github.com/cowboy/jquery-throttle-debounce
+ $(window).unbind(eventName).bind(eventName, $.throttle(100, resizeFunction));
+ } else {
+ if($.fn.smartresize) {
+ // https://github.com/lrbabe/jquery-smartresize/
+ eventName = 'smartresize.' + eventName;
+ }
+ $(window).unbind(eventName).bind(eventName, resizeFunction);
+ }
+ },
+ getStyleId: function(id)
+ {
+ return BigText.STYLE_ID + '-' + id;
+ },
+ generateStyleTag: function(id, css)
+ {
+ return $('<style>' + css.join('\n') + '</style>').attr('id', id);
+ },
+ clearCss: function(id)
+ {
+ var styleId = BigText.getStyleId(id);
+ $('#' + styleId).remove();
+ },
+ generateCss: function(id, linesFontSizes, lineWordSpacings, minFontSizes)
+ {
+ var css = [];
- BigText.clearCss(id);
+ BigText.clearCss(id);
- for(var j=0, k=linesFontSizes.length; j<k; j++) {
- css.push('#' + id + ' .' + BigText.LINE_CLASS_PREFIX + j + ' {' +
- (minFontSizes[j] ? ' white-space: normal;' : '') +
- (linesFontSizes[j] ? ' font-size: ' + linesFontSizes[j] + 'px;' : '') +
- (lineWordSpacings[j] ? ' word-spacing: ' + lineWordSpacings[j] + 'px;' : '') +
- '}');
- }
+ for(var j=0, k=linesFontSizes.length; j<k; j++) {
+ css.push('#' + id + ' .' + BigText.LINE_CLASS_PREFIX + j + ' {' +
+ (minFontSizes[j] ? ' white-space: normal;' : '') +
+ (linesFontSizes[j] ? ' font-size: ' + linesFontSizes[j] + 'px;' : '') +
+ (lineWordSpacings[j] ? ' word-spacing: ' + lineWordSpacings[j] + 'px;' : '') +
+ '}');
+ }
- return BigText.generateStyleTag(BigText.getStyleId(id), css);
- },
- jQueryMethod: function(options)
+ return BigText.generateStyleTag(BigText.getStyleId(id), css);
+ },
+ jQueryMethod: function(options)
+ {
+ BigText.init();
+
+ options = $.extend({
+ minfontsize: BigText.DEFAULT_MIN_FONT_SIZE_PX,
+ maxfontsize: BigText.DEFAULT_MAX_FONT_SIZE_PX,
+ childSelector: '',
+ resize: true
+ }, options || {});
+
+ return this.each(function()
+ {
+ var $t = $(this).addClass('bigtext'),
+ childSelector = options.childSelector ||
+ BigText.childSelectors[this.tagName.toLowerCase()] ||
+ BigText.DEFAULT_CHILD_SELECTOR,
+ maxWidth = $t.width(),
+ id = $t.attr('id');
+
+ if(!id) {
+ id = 'bigtext-id' + (counter++);
+ $t.attr('id', id);
+ }
+
+ if(options.resize) {
+ BigText.bindResize('resize.bigtext-event-' + id, function()
{
- BigText.init();
-
- options = $.extend({
- minfontsize: BigText.DEFAULT_MIN_FONT_SIZE_PX,
- maxfontsize: BigText.DEFAULT_MAX_FONT_SIZE_PX,
- childSelector: '',
- resize: true
- }, options || {});
-
- return this.each(function()
- {
- var $t = $(this).addClass('bigtext'),
- childSelector = options.childSelector ||
- BigText.childSelectors[this.tagName.toLowerCase()] ||
- BigText.DEFAULT_CHILD_SELECTOR,
- maxWidth = $t.width(),
- id = $t.attr('id');
-
- if(!id) {
- id = 'bigtext-id' + (counter++);
- $t.attr('id', id);
- }
-
- if(options.resize) {
- BigText.bindResize('resize.bigtext-event-' + id, function()
- {
- BigText.jQueryMethod.call($('#' + id), options);
- });
- }
-
- BigText.clearCss(id);
-
- $t.find(childSelector).addClass(function(lineNumber, className)
- {
- // remove existing line classes.
- return [className.replace(new RegExp('\\b' + BigText.LINE_CLASS_PREFIX + '\\d+\\b'), ''),
- BigText.LINE_CLASS_PREFIX + lineNumber].join(' ');
- });
-
- var sizes = calculateSizes($t, childSelector, maxWidth, options.maxfontsize, options.minfontsize);
- $headCache.append(BigText.generateCss(id, sizes.fontSizes, sizes.wordSpacings, sizes.minFontSizes));
- });
- }
- };
-
- function testLineDimensions($line, maxWidth, property, size, interval, units)
- {
- var width;
- $line.css(property, size + units);
+ BigText.jQueryMethod.call($('#' + id), options);
+ });
+ }
+
+ BigText.clearCss(id);
+
+ $t.find(childSelector).addClass(function(lineNumber, className)
+ {
+ // remove existing line classes.
+ return [className.replace(new RegExp('\\b' + BigText.LINE_CLASS_PREFIX + '\\d+\\b'), ''),
+ BigText.LINE_CLASS_PREFIX + lineNumber].join(' ');
+ });
+
+ var sizes = calculateSizes($t, childSelector, maxWidth, options.maxfontsize, options.minfontsize);
+ $headCache.append(BigText.generateCss(id, sizes.fontSizes, sizes.wordSpacings, sizes.minFontSizes));
+ });
+ }
+ };
- width = $line.width();
+ function testLineDimensions($line, maxWidth, property, size, interval, units)
+ {
+ var width;
+ $line.css(property, size + units);
- if(width >= maxWidth) {
- $line.css(property, '');
+ width = $line.width();
- if(width == maxWidth) {
- return {
- match: 'exact',
- size: parseFloat((parseFloat(size) - 0.1).toFixed(3))
- };
- }
+ if(width >= maxWidth) {
+ $line.css(property, '');
- return {
- match: 'estimate',
- size: parseFloat((parseFloat(size) - interval).toFixed(3))
- };
- }
+ if(width == maxWidth) {
+ return {
+ match: 'exact',
+ size: parseFloat((parseFloat(size) - 0.1).toFixed(3))
+ };
+ }
- return false;
+ return {
+ match: 'estimate',
+ size: parseFloat((parseFloat(size) - interval).toFixed(3))
+ };
}
- function calculateSizes($t, childSelector, maxWidth, maxFontSize, minFontSize)
- {
- var $c = $t.clone(true)
- .addClass('bigtext-cloned')
- .css({
- fontFamily: $t.css('font-family'),
- 'min-width': parseInt(maxWidth, 10),
- width: 'auto',
- position: 'absolute',
- left: -9999,
- top: -9999
- }).appendTo(document.body);
+ return false;
+ }
- // font-size isn't the only thing we can modify, we can also mess with:
- // word-spacing and letter-spacing.
- // Note: webkit does not respect subpixel letter-spacing or word-spacing,
- // nor does it respect hundredths of a font-size em.
- var fontSizes = [],
- wordSpacings = [],
- minFontSizes = [],
- ratios = [];
+ function calculateSizes($t, childSelector, maxWidth, maxFontSize, minFontSize)
+ {
+ var $c = $t.clone(true)
+ .addClass('bigtext-cloned')
+ .css({
+ fontFamily: $t.css('font-family'),
+ 'min-width': parseInt(maxWidth, 10),
+ width: 'auto',
+ position: 'absolute',
+ left: -9999,
+ top: -9999
+ }).appendTo(document.body);
- $c.find(childSelector).css({
- 'float': 'left',
- 'clear': 'left'
- }).each(function(lineNumber) {
- var $line = $(this),
- intervals = [4,1,.4,.1],
- lineMax;
+ // font-size isn't the only thing we can modify, we can also mess with:
+ // word-spacing and letter-spacing.
+ // Note: webkit does not respect subpixel letter-spacing or word-spacing,
+ // nor does it respect hundredths of a font-size em.
+ var fontSizes = [],
+ wordSpacings = [],
+ minFontSizes = [],
+ ratios = [];
- if($line.hasClass(BigText.EXEMPT_CLASS)) {
- fontSizes.push(null);
- ratios.push(null);
- minFontSizes.push(false);
- return;
- }
+ $c.find(childSelector).css({
+ 'float': 'left',
+ 'clear': 'left'
+ }).each(function(lineNumber) {
+ var $line = $(this),
+ intervals = [4, 1, 0.4, 0.1],
+ lineMax;
+
+ if($line.hasClass(BigText.EXEMPT_CLASS)) {
+ fontSizes.push(null);
+ ratios.push(null);
+ minFontSizes.push(false);
+ return;
+ }
- // TODO we can cache this ratio?
- var autoGuessSubtraction = 20, // px
- currentFontSize = parseFloat($line.css('font-size')),
- lineWidth = $line.width(),
- ratio = (lineWidth / currentFontSize).toFixed(6),
- newFontSize = parseFloat(((maxWidth - autoGuessSubtraction) / ratio).toFixed(3));
+ // TODO we can cache this ratio?
+ var autoGuessSubtraction = 20, // px
+ currentFontSize = parseFloat($line.css('font-size')),
+ lineWidth = $line.width(),
+ ratio = (lineWidth / currentFontSize).toFixed(6),
+ newFontSize = parseFloat(((maxWidth - autoGuessSubtraction) / ratio).toFixed(3));
- outer: for(var m=0, n=intervals.length; m<n; m++) {
- inner: for(var j=1, k=4; j<=k; j++) {
- if(newFontSize + j*intervals[m] > maxFontSize) {
- newFontSize = maxFontSize;
- break outer;
- }
+ outer: for(var m=0, n=intervals.length; m<n; m++) {
+ inner: for(var j=1, k=4; j<=k; j++) {
+ if(newFontSize + j*intervals[m] > maxFontSize) {
+ newFontSize = maxFontSize;
+ break outer;
+ }
- lineMax = testLineDimensions($line, maxWidth, 'font-size', newFontSize + j*intervals[m], intervals[m], 'px');
- if(lineMax !== false) {
- newFontSize = lineMax.size;
+ lineMax = testLineDimensions($line, maxWidth, 'font-size', newFontSize + j*intervals[m], intervals[m], 'px');
+ if(lineMax !== false) {
+ newFontSize = lineMax.size;
- if(lineMax.match == 'exact') {
- break outer;
- }
- break inner;
- }
- }
+ if(lineMax.match == 'exact') {
+ break outer;
}
+ break inner;
+ }
+ }
+ }
- ratios.push(maxWidth / newFontSize);
+ ratios.push(maxWidth / newFontSize);
- if(newFontSize > maxFontSize) {
- fontSizes.push(maxFontSize);
- minFontSizes.push(false);
- } else if(!!minFontSize && newFontSize < minFontSize) {
- fontSizes.push(minFontSize);
- minFontSizes.push(true);
- } else {
- fontSizes.push(newFontSize);
- minFontSizes.push(false);
- }
- }).each(function(lineNumber) {
- var $line = $(this),
- wordSpacing = 0,
- interval = 1,
- maxWordSpacing;
+ if(newFontSize > maxFontSize) {
+ fontSizes.push(maxFontSize);
+ minFontSizes.push(false);
+ } else if(!!minFontSize && newFontSize < minFontSize) {
+ fontSizes.push(minFontSize);
+ minFontSizes.push(true);
+ } else {
+ fontSizes.push(newFontSize);
+ minFontSizes.push(false);
+ }
+ }).each(function(lineNumber) {
+ var $line = $(this),
+ wordSpacing = 0,
+ interval = 1,
+ maxWordSpacing;
- if($line.hasClass(BigText.EXEMPT_CLASS)) {
- wordSpacings.push(null);
- return;
- }
+ if($line.hasClass(BigText.EXEMPT_CLASS)) {
+ wordSpacings.push(null);
+ return;
+ }
- // must re-use font-size, even though it was removed above.
- $line.css('font-size', fontSizes[lineNumber] + 'px');
+ // must re-use font-size, even though it was removed above.
+ $line.css('font-size', fontSizes[lineNumber] + 'px');
- for(var m=1, n=5; m<n; m+=interval) {
- maxWordSpacing = testLineDimensions($line, maxWidth, 'word-spacing', m, interval, 'px');
- if(maxWordSpacing !== false) {
- wordSpacing = maxWordSpacing.size;
- break;
- }
- }
+ for(var m=1, n=5; m<n; m+=interval) {
+ maxWordSpacing = testLineDimensions($line, maxWidth, 'word-spacing', m, interval, 'px');
+ if(maxWordSpacing !== false) {
+ wordSpacing = maxWordSpacing.size;
+ break;
+ }
+ }
- $line.css('font-size', '');
- wordSpacings.push(wordSpacing);
- }).removeAttr('style');
+ $line.css('font-size', '');
+ wordSpacings.push(wordSpacing);
+ }).removeAttr('style');
- $c.remove();
+ $c.remove();
- return {
- fontSizes: fontSizes,
- wordSpacings: wordSpacings,
- ratios: ratios,
- minFontSizes: minFontSizes
- };
- }
+ return {
+ fontSizes: fontSizes,
+ wordSpacings: wordSpacings,
+ ratios: ratios,
+ minFontSizes: minFontSizes
+ };
+ }
- $.fn.bigtext = BigText.jQueryMethod;
- window.BigText = BigText;
+ $.fn.bigtext = BigText.jQueryMethod;
+ window.BigText = BigText;
})(this, jQuery);
View
244 test/bigtextTest.js
@@ -3,234 +3,232 @@ BigTextTest = TestCase('BigTextTest');
BigTextTest.prototype.tolerance = 6;
// If the lines of text are blocks, testing their width will tell us nothing.
-BigTextTest.prototype.init = function()
-{
- return this.css({
- float: 'left',
- clear: 'left'
- });
+BigTextTest.prototype.init = function() {
+ return this.css({
+ float: 'left',
+ clear: 'left'
+ });
};
-BigTextTest.prototype.testExists = function()
-{
- assertTrue(!!BigText);
- assertTrue(!!$.fn.bigtext);
+BigTextTest.prototype.testExists = function(){
+ assertTrue(!!BigText);
+ assertTrue(!!$.fn.bigtext);
};
BigTextTest.prototype.testStyleInjection = function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is a simple test.</div></div>');
- $('#test').bigtext();
+ $(document.body).append('<div id="test" style="width:600px"><div>This is a simple test.</div></div>');
+ $('#test').bigtext();
- assertTrue('Test to make sure the style tag was inserted.', $('#' + BigText.getStyleId('test')).length === 1);
+ assertTrue('Test to make sure the style tag was inserted.', $('#' + BigText.getStyleId('test')).length === 1);
};
BigTextTest.prototype.testDoubleStyleInjection = function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is a simple test.</div></div>');
- $('#test').bigtext().bigtext();
+ $(document.body).append('<div id="test" style="width:600px"><div>This is a simple test.</div></div>');
+ $('#test').bigtext().bigtext();
- // FIXME this jQuery result won't return more than one element.
- assertTrue('Test to make sure the style tag wasn\'t inserted twice.', $('#' + BigText.getStyleId('test')).length === 1);
+ // FIXME this jQuery result won't return more than one element.
+ assertTrue('Test to make sure the style tag wasn\'t inserted twice.', $('#' + BigText.getStyleId('test')).length === 1);
};
BigTextTest.prototype.testCleanup = function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is a simple test.</div></div>');
- $('#test').bigtext();
+ $(document.body).append('<div id="test" style="width:600px"><div>This is a simple test.</div></div>');
+ $('#test').bigtext();
- assertTrue('Clone should be deleted.', $('.bigtext-cloned').length === 0);
+ assertTrue('Clone should be deleted.', $('.bigtext-cloned').length === 0);
};
BigTextTest.prototype.linesTest = function(selector, expectedWidth, options)
{
- var tolerance = this.tolerance,
- minWidth = expectedWidth - tolerance,
- maxWidth = expectedWidth + tolerance,
- options = options || {},
- $test = $(selector),
- $lines = $test.find(options.childSelector || '> *'),
- startingFontSize = parseInt($lines.eq(0).css('font-size'), 10);
-
- this.init.call($lines);
-
- $lines.each(function(j)
- {
- var width = $(this).width();
- assertFalse('Line ' + j + ' is not max width (' + minWidth + ' < ' + width + ' < ' + maxWidth + ')', minWidth < width && width < maxWidth);
- });
-
- $test.bigtext(options);
-
-
- assertTrue('Class added.', $test.is('.bigtext'));
-
- $lines.each(function(j)
- {
- var $t = $(this),
- width = $t.width(),
- height = $t.height(),
- fontSize = parseFloat($t.css('font-size')),
- $heightElement = $('<div>A</div>').css({
- 'font-size': fontSize,
- position: 'absolute'
- }).appendTo(document.body),
- expectedHeight = $heightElement.height(),
- minHeight = expectedHeight - tolerance,
- maxHeight = expectedHeight + tolerance;
-
- assertTrue('Line ' + j + ' class added.', $t.is('.bigtext-line' + j));
- if($t.hasClass(BigText.EXEMPT_CLASS)) {
- // must be added to document to get font-size
- var defaultDocumentFontSize = parseInt($('<div/>').appendTo(document.body).css('font-size'), 10);
- assertEquals('Line ' + j + ' Font size must be unchanged', defaultDocumentFontSize, fontSize);
- } else {
- assertTrue('Line ' + j + ' Font size must be larger than the starting pixel size', fontSize > startingFontSize);
- assertTrue('Line ' + j + ' width should be about ' + expectedWidth + 'px (' + width + ')', minWidth < width && width < maxWidth);
- assertTrue('Line ' + j + ' height should be about ' + expectedHeight + 'px (' + minHeight + ' < ' + height + ' < ' + maxHeight + ')', minHeight < height && height < maxHeight);
- }
-
- $heightElement.remove();
- });
+ var tolerance = this.tolerance,
+ minWidth = expectedWidth - tolerance,
+ maxWidth = expectedWidth + tolerance,
+ options = options || {},
+ $test = $(selector),
+ $lines = $test.find(options.childSelector || '> *'),
+ startingFontSize = parseInt($lines.eq(0).css('font-size'), 10);
+
+ this.init.call($lines);
+
+ $lines.each(function(j)
+ {
+ var width = $(this).width();
+ assertFalse('Line ' + j + ' is not max width (' + minWidth + ' < ' + width + ' < ' + maxWidth + ')', minWidth < width && width < maxWidth);
+ });
+
+ $test.bigtext(options);
+
+
+ assertTrue('Class added.', $test.is('.bigtext'));
+
+ $lines.each(function(j)
+ {
+ var $t = $(this),
+ width = $t.width(),
+ height = $t.height(),
+ fontSize = parseFloat($t.css('font-size')),
+ $heightElement = $('<div>A</div>').css({
+ 'font-size': fontSize,
+ position: 'absolute'
+ }).appendTo(document.body),
+ expectedHeight = $heightElement.height(),
+ minHeight = expectedHeight - tolerance,
+ maxHeight = expectedHeight + tolerance;
+
+ assertTrue('Line ' + j + ' class added.', $t.is('.bigtext-line' + j));
+ if($t.hasClass(BigText.EXEMPT_CLASS)) {
+ // must be added to document to get font-size
+ var defaultDocumentFontSize = parseInt($('<div/>').appendTo(document.body).css('font-size'), 10);
+ assertEquals('Line ' + j + ' Font size must be unchanged', defaultDocumentFontSize, fontSize);
+ } else {
+ assertTrue('Line ' + j + ' Font size must be larger than the starting pixel size', fontSize > startingFontSize);
+ assertTrue('Line ' + j + ' width should be about ' + expectedWidth + 'px (' + width + ')', minWidth < width && width < maxWidth);
+ assertTrue('Line ' + j + ' height should be about ' + expectedHeight + 'px (' + minHeight + ' < ' + height + ' < ' + maxHeight + ')', minHeight < height && height < maxHeight);
+ }
+
+ $heightElement.remove();
+ });
};
BigTextTest.prototype.testOneLine = function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is a single line.</div></div>');
+ $(document.body).append('<div id="test" style="width:600px"><div>This is a single line.</div></div>');
- this.linesTest('#test', 600);
+ this.linesTest('#test', 600);
};
BigTextTest.prototype.testTwoLines = function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is</div><div>a longer second line</div></div>');
+ $(document.body).append('<div id="test" style="width:600px"><div>This is</div><div>a longer second line</div></div>');
- this.linesTest('#test', 600);
+ this.linesTest('#test', 600);
};
BigTextTest.prototype.testThreeLines = function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is</div><div>a longer second line</div><div>An even longer third line.</div></div>');
+ $(document.body).append('<div id="test" style="width:600px"><div>This is</div><div>a longer second line</div><div>An even longer third line.</div></div>');
- this.linesTest('#test', 600);
+ this.linesTest('#test', 600);
};
BigTextTest.prototype.testThreeLinesWithAList = function()
{
- $(document.body).append('<ol id="test" style="width:600px"><li>This is</li><li>a longer second line</li><li>An even longer third line.</li></ol>');
+ $(document.body).append('<ol id="test" style="width:600px"><li>This is</li><li>a longer second line</li><li>An even longer third line.</li></ol>');
- this.linesTest('#test', 600);
+ this.linesTest('#test', 600);
};
BigTextTest.prototype.testTwoElements = function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is</div><div>a longer second line</div></div><div id="test2" style="width:400px"><div>This is</div><div>a longer second line</div></div>');
+ $(document.body).append('<div id="test" style="width:600px"><div>This is</div><div>a longer second line</div></div><div id="test2" style="width:400px"><div>This is</div><div>a longer second line</div></div>');
- this.linesTest('#test', 600);
- this.linesTest('#test2', 400);
+ this.linesTest('#test', 600);
+ this.linesTest('#test2', 400);
- assertNotEquals('Line 1 of each is a different size.',
- $('#test').find('> div').eq(0).css('font-size'),
- $('#test2').find('> div').eq(0).css('font-size'));
+ assertNotEquals('Line 1 of each is a different size.',
+ $('#test').find('> div').eq(0).css('font-size'),
+ $('#test2').find('> div').eq(0).css('font-size'));
- assertNotEquals('Line 2 of each is a different size.',
- $('#test').find('> div').eq(1).css('font-size'),
- $('#test2').find('> div').eq(1).css('font-size'));
+ assertNotEquals('Line 2 of each is a different size.',
+ $('#test').find('> div').eq(1).css('font-size'),
+ $('#test2').find('> div').eq(1).css('font-size'));
};
BigTextTest.prototype.testPercentageWidth = function()
{
- $(document.body).append('<div style="width: 600px"><div id="test" style="width: 50%"><div>This is a single line.</div></div></div>');
+ $(document.body).append('<div style="width: 600px"><div id="test" style="width: 50%"><div>This is a single line.</div></div></div>');
- this.linesTest('#test', 300);
+ this.linesTest('#test', 300);
};
BigTextTest.prototype.testNoChildren = function()
{
- $(document.body).append('<div id="test" style="width: 600px">This is a single line.</div>');
+ $(document.body).append('<div id="test" style="width: 600px">This is a single line.</div>');
- this.linesTest('#test', 300);
+ this.linesTest('#test', 300);
};
BigTextTest.prototype.testMaxFontSize = function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>1</div></div>');
- $('#test').bigtext();
+ $(document.body).append('<div id="test" style="width:600px"><div>1</div></div>');
+ $('#test').bigtext();
- assertEquals('Font size should equal the maximum.', BigText.DEFAULT_MAX_FONT_SIZE_PX + 'px', $('#test > div').css('font-size'));
+ assertEquals('Font size should equal the maximum.', BigText.DEFAULT_MAX_FONT_SIZE_PX + 'px', $('#test > div').css('font-size'));
};
BigTextTest.prototype.testUnbrokenSingleWord = function()
{
- $(document.body).append('<div id="test" style="width:300px"><div>This</div></div>');
- var startingFontSize = parseInt($('#test > div').css('font-size'), 10);
- $('#test').bigtext();
+ $(document.body).append('<div id="test" style="width:300px"><div>This</div></div>');
+ var startingFontSize = parseInt($('#test > div').css('font-size'), 10);
+ $('#test').bigtext();
- assertTrue('Font size must be larger than the starting pixel size.', parseInt($('#test > div').css('font-size'), 10) > startingFontSize);
+ assertTrue('Font size must be larger than the starting pixel size.', parseInt($('#test > div').css('font-size'), 10) > startingFontSize);
};
BigTextTest.prototype.testTwoLinesButOneExempt = function()
{
- $(document.body).append('<div id="test" style="width:400px"><div>This is</div><div class="bigtext-exempt">a longer second line</div></div>');
+ $(document.body).append('<div id="test" style="width:400px"><div>This is</div><div class="bigtext-exempt">a longer second line</div></div>');
- this.linesTest('#test', 400);
+ this.linesTest('#test', 400);
};
BigTextTest.prototype.testExemptLineWithChild = function()
{
- $(document.body).append('<div id="test" style="width:400px"><div>This is</div><div class="bigtext-exempt">a longer <span>second</span> line</div></div>');
+ $(document.body).append('<div id="test" style="width:400px"><div>This is</div><div class="bigtext-exempt">a longer <span>second</span> line</div></div>');
- var defaultDocumentFontSize = $('<div/>').appendTo(document.body).css('font-size'),
- childFontSize = $('span').css('font-size');
- assertEquals('Exempt line\'s child font size must be unchanged', defaultDocumentFontSize, childFontSize);
+ var defaultDocumentFontSize = $('<div/>').appendTo(document.body).css('font-size'),
+ childFontSize = $('span').css('font-size');
+ assertEquals('Exempt line\'s child font size must be unchanged', defaultDocumentFontSize, childFontSize);
};
BigTextTest.prototype.testIdCssSelectorStyle = function()
{
- $(document.body).append('<style>#test { width: 600px; font-weight: bold; }</style><div id="test"><div>This is a single line.</div></div>');
+ $(document.body).append('<style>#test { width: 600px; font-weight: bold; }</style><div id="test"><div>This is a single line.</div></div>');
- this.linesTest('#test', 600);
+ this.linesTest('#test', 600);
};
BigTextTest.prototype.testMaxWidth = function()
{
- $(document.body).append('<div id="test" style="max-width:600px"><div>This is a single line.</div></div>');
+ $(document.body).append('<div id="test" style="max-width:600px"><div>This is a single line.</div></div>');
- this.linesTest('#test', 600);
+ this.linesTest('#test', 600);
};
BigTextTest.prototype.testNoConflict = function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is a single line.</div></div>');
+ $(document.body).append('<div id="test" style="width:600px"><div>This is a single line.</div></div>');
- var BT = BigText.noConflict();
- $.fn.bt = BT.jQueryMethod;
+ var BT = BigText.noConflict();
+ $.fn.bt = BT.jQueryMethod;
- $('#test').bt();
+ $('#test').bt();
- var defaultDocumentFontSize = $('<div/>').appendTo(document.body).css('font-size'),
- childFontSize = $('#test > div').css('font-size');
+ var defaultDocumentFontSize = $('<div/>').appendTo(document.body).css('font-size'),
+ childFontSize = $('#test > div').css('font-size');
- assertNotEquals('Font size must not equal the default.', defaultDocumentFontSize, childFontSize);
+ assertNotEquals('Font size must not equal the default.', defaultDocumentFontSize, childFontSize);
};
BigTextTest.prototype.testMinFontSize = function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is a super long line that will probably be too long for this single line. This is a super long line that will probably be too long for this single line.</div></div>');
- $('#test').bigtext({
- minfontsize: 16
- });
+ $(document.body).append('<div id="test" style="width:600px"><div>This is a super long line that will probably be too long for this single line. This is a super long line that will probably be too long for this single line.</div></div>');
+ $('#test').bigtext({
+ minfontsize: 16
+ });
- assertEquals('Font size should equal the minimum.', '16px', $('#test > div').css('font-size'));
- assertEquals('When minimum is set, word wrap should re-enable.', 'normal', $('#test > div').css('white-space'));
+ assertEquals('Font size should equal the minimum.', '16px', $('#test > div').css('font-size'));
+ assertEquals('When minimum is set, word wrap should re-enable.', 'normal', $('#test > div').css('white-space'));
};
BigTextTest.prototype.testChildClassReplace = function()
{
- $(document.body).append('<div id="test" style="width:600px"><div class="testbigtext-line1">This is a single line.</div></div>');
+ $(document.body).append('<div id="test" style="width:600px"><div class="testbigtext-line1">This is a single line.</div></div>');
- this.linesTest('#test', 600);
- assertTrue('First line should still have testbigtext-line1 class', $('#test > div').hasClass('testbigtext-line1'));
- assertFalse('First line should not have test class', $('#test > div').hasClass('test'));
+ this.linesTest('#test', 600);
+ assertTrue('First line should still have testbigtext-line1 class', $('#test > div').hasClass('testbigtext-line1'));
+ assertFalse('First line should not have test class', $('#test > div').hasClass('test'));
};
Please sign in to comment.
Something went wrong with that request. Please try again.