├── .gitignore ├── CONTRIBUTORS.md ├── LICENSE ├── README.md ├── bower.json ├── jquery-bigtext.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | /.project 2 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | David Barker 2 | 3 | Maxim Novoselov 4 | 5 | Jay Falco 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013 Daniel Hoffmann Bernardes, Icaro Technologies 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | jquery-bigtext 2 | ============== 3 | 4 | This project is no longer mantained, please refer to https://github.com/BrOrlandi/big-text.js 5 | 6 | jQuery plugin that makes HTML text tags as big as possible while still fitting on the parent. 7 | 8 | Requirements 9 | ============== 10 | jQuery 1.3.1 or higher 11 | 12 | Browser Compatibility 13 | ============== 14 | Internet Explorer 9 or higher (might work on older versions) 15 | 16 | Opera 17 | 18 | Firefox 19 | 20 | Google Chrome 21 | 22 | Safari 23 | 24 | 25 | Examples 26 | ============== 27 | 28 | ```html 29 |
30 | BigText 31 |
32 | ``` 33 | ```javascript 34 | $("#span").bigText(); 35 | ``` 36 | 37 | With one simple line the text "BigText" will now have its font-size increased but without overflowing the element parent div. 38 | 39 | See more examples in http://danielhoffmann.github.io/jquery-bigtext/ 40 | 41 | 42 | Usage 43 | ============== 44 | 45 | ```javascript 46 | $("#span").bigText({ 47 | rotateText: {Number}, (null) 48 | fontSizeFactor: {Number}, (0.8) 49 | maximumFontSize: {Number}, (null) 50 | limitingDimension: {Number}, ("both") 51 | horizontalAlign: {String}, ("center") 52 | verticalAlign: {String}, ("center") 53 | textAlign: {String}, ("center") 54 | }); 55 | ``` 56 | 57 | Options 58 | ============== 59 | rotateText: Rotates the text inside the element by X degrees. 60 | 61 | fontSizeFactor: This option is used to give some vertical spacing for letters that overflow the line-height (like 'g', 'Á' and most other accentuated uppercase letters). This does not affect the font-size if the limiting factor is the width of the parent div. The default is 0.8 62 | 63 | maximumFontSize: maximum font size to use. 64 | 65 | limitingDimension: In which dimension the font size should be limited. Possible values: "width", "height" or "both". Defaults to both. Using this option with values different than "both" overwrites the element parent width or height. 66 | 67 | horizontalAlign: Where to align the text horizontally. Possible values: "left", "center", "right". Defaults to "center". 68 | 69 | verticalAlign: Where to align the text vertically. Possible values: "top", "center", "bottom". Defaults to "center". 70 | 71 | textAlign: Sets the text align of the element. Possible values: "left", "center", "right". Defaults to "center". This option is only useful if there are linebreaks (
tags) inside the text. 72 | 73 | 74 | License 75 | ============== 76 | This project is released under the MIT license. 77 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-bigtext", 3 | "version": "1.3.0", 4 | "homepage": "https://github.com/DanielHoffmann/jquery-bigtext", 5 | "authors": [ 6 | "Daniel Hoffmann Bernardes" 7 | ], 8 | "description": "jQuery plugin that makes HTML text tags as big as possible while still fitting on the parent", 9 | "keywords": [ 10 | "jquery", 11 | "bigtext", 12 | "text" 13 | ], 14 | "main": "jquery-bigtext.js", 15 | "license": "MIT", 16 | "dependencies": { 17 | "jquery": ">=1.7.0" 18 | }, 19 | "ignore": [ 20 | "**/.*", 21 | "node_modules", 22 | "bower_components", 23 | "test", 24 | "tests", 25 | "bower.json", 26 | "CONTRIBUTORS.md", 27 | "LICENSE", 28 | "README.md" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /jquery-bigtext.js: -------------------------------------------------------------------------------- 1 | /* 2 | jQuery BigText v1.3.0, May 2014 3 | 4 | Usage: 5 | $("#div").bigText({ 6 | rotateText: {Number}, (null) 7 | fontSizeFactor: {Number}, (0.8) 8 | maximumFontSize: {Number}, (null) 9 | limitingDimension: {Number}, ("both") 10 | horizontalAlign: {String}, ("center") 11 | verticalAlign: {String}, ("center") 12 | textAlign: {String}, ("center") 13 | }); 14 | 15 | https://github.com/DanielHoffmann/jquery-bigtext 16 | 17 | Options: 18 | 19 | rotateText: Rotates the text inside the element by X degrees. 20 | 21 | fontSizeFactor: This option is used to give some vertical spacing for letters that overflow the line-height (like 'g', 'Á' and most other accentuated uppercase letters). This does not affect the font-size if the limiting factor is the width of the parent div. The default is 0.8 22 | 23 | maximumFontSize: maximum font size to use. 24 | 25 | limitingDimension: In which dimension the font size should be limited. Possible values: "width", "height" or "both". Defaults to both. Using this option with values different than "both" overwrites the element parent width or height. 26 | 27 | horizontalAlign: Where to align the text horizontally. Possible values: "left", "center", "right". Defaults to "center". 28 | 29 | verticalAlign: Where to align the text vertically. Possible values: "top", "center", "bottom". Defaults to "center". 30 | 31 | textAlign: Sets the text align of the element. Possible values: "left", "center", "right". Defaults to "center". This option is only useful if there are linebreaks (
tags) inside the text. 32 | 33 | whiteSpace: Sets whitespace handling. Possible values: "nowrap", "pre". Defaults to "nowrap". (Can also be set to enable wrapping but this doesn't work well.) 34 | 35 | Copyright (C) 2013 Daniel Hoffmann Bernardes, Ícaro Technologies 36 | 37 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 38 | 39 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 40 | 41 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 42 | */ 43 | 44 | 45 | (function($){ 46 | "use strict"; 47 | var defaultOptions= { 48 | rotateText: null, 49 | fontSizeFactor: 0.8, 50 | maximumFontSize: null, 51 | limitingDimension: "both", 52 | horizontalAlign: "center", 53 | verticalAlign: "center", 54 | textAlign: "center", 55 | whiteSpace: "nowrap" 56 | }; 57 | 58 | $.fn.bigText= function(options) { 59 | return this.each(function() { 60 | options= $.extend({}, defaultOptions, options); 61 | var $this= $(this); 62 | var $parent= $this.parent(); 63 | 64 | //hides the element to prevent "flashing" 65 | $this.css("visibility", "hidden"); 66 | 67 | $this.css({ 68 | display: "inline-block", 69 | clear: "both", 70 | 'float': "left", //the need to set this is very odd, its due to margin-collapsing. See https://developer.mozilla.org/en-US/docs/Web/CSS/margin_collapsing 71 | 'font-size': (1000 * options.fontSizeFactor) + "px", 72 | 'line-height': "1000px", 73 | 'white-space': options.whiteSpace, 74 | "text-align": options.textAlign, 75 | position: "relative", 76 | padding: 0, 77 | margin: 0, 78 | left: "50%", 79 | top: "50%" 80 | }); 81 | 82 | var parentPadding= { 83 | left: parseInt($parent.css('padding-left')), 84 | top: parseInt($parent.css('padding-top')), 85 | right: parseInt($parent.css('padding-right')), 86 | bottom: parseInt($parent.css('padding-bottom')) 87 | }; 88 | 89 | var box= { 90 | width: $this.outerWidth(), 91 | height: $this.outerHeight() 92 | }; 93 | var rotateCSS= {} 94 | if (options.rotateText !== null) { 95 | if (typeof options.rotateText !== "number") 96 | throw "bigText error: rotateText value must be a number"; 97 | var rotate= "rotate(" + options.rotateText + "deg)"; 98 | rotateCSS= { 99 | "-webkit-transform": rotate, 100 | "-ms-transform": rotate, 101 | "-moz-transform": rotate, 102 | "-o-transform": rotate, 103 | "transform": rotate 104 | }; 105 | $this.css(rotateCSS); 106 | //calculating bounding box of the rotated element 107 | var sin= Math.abs(Math.sin(options.rotateText * Math.PI / 180)); 108 | var cos= Math.abs(Math.cos(options.rotateText * Math.PI / 180)); 109 | box.width= $this.outerWidth() * cos + $this.outerHeight() * sin; 110 | box.height= $this.outerWidth() * sin + $this.outerHeight() * cos; 111 | } 112 | 113 | var widthFactor= ($parent.innerWidth() - parentPadding.left - parentPadding.right) / box.width; 114 | var heightFactor= ($parent.innerHeight() - parentPadding.top - parentPadding.bottom) / box.height; 115 | var lineHeight; 116 | 117 | if (options.limitingDimension.toLowerCase() === "width") { 118 | lineHeight= Math.floor(widthFactor * 1000); 119 | $parent.height(lineHeight); 120 | } else if (options.limitingDimension.toLowerCase() === "height") { 121 | lineHeight= Math.floor(heightFactor * 1000); 122 | } else if (widthFactor < heightFactor) 123 | lineHeight= Math.floor(widthFactor * 1000); 124 | else if (widthFactor >= heightFactor) 125 | lineHeight= Math.floor(heightFactor * 1000); 126 | 127 | var fontSize= lineHeight * options.fontSizeFactor; 128 | if (options.maximumFontSize !== null && fontSize > options.maximumFontSize) { 129 | fontSize= options.maximumFontSize; 130 | lineHeight= fontSize / options.fontSizeFactor; 131 | } 132 | 133 | 134 | $this.css({ 135 | 'font-size': Math.floor(fontSize) + "px", 136 | 'line-height': Math.ceil(lineHeight) + "px", 137 | 'margin-bottom': "0px", 138 | 'margin-right': "0px" 139 | }); 140 | 141 | if (options.limitingDimension.toLowerCase() === "height") { 142 | //this option needs the font-size to be set already so $this.width() returns the right size 143 | //this +4 is to compensate the rounding erros that can occur due to the calls to Math.floor in the centering code 144 | $parent.width(($this.width() + 4) + "px"); 145 | } 146 | var endCSS= {}; 147 | 148 | switch(options.verticalAlign.toLowerCase()) { 149 | case "top": 150 | endCSS['top']= "0%"; 151 | break; 152 | case "bottom": 153 | endCSS['top']= "100%"; 154 | endCSS['margin-top']= Math.floor(-$this.innerHeight()) + "px"; 155 | break; 156 | default: 157 | endCSS['margin-top']= Math.floor((-$this.innerHeight() / 2)) + "px"; 158 | break; 159 | } 160 | 161 | switch(options.horizontalAlign.toLowerCase()) { 162 | case "left": 163 | endCSS['left']= "0%"; 164 | break; 165 | case "right": 166 | endCSS['left']= "100%"; 167 | endCSS['margin-left']= Math.floor(-$this.innerWidth()) + "px"; 168 | break; 169 | default: 170 | endCSS['margin-left']= Math.floor((-$this.innerWidth() / 2)) + "px"; 171 | break; 172 | } 173 | 174 | 175 | $this.css(endCSS); 176 | //shows the element after the work is done 177 | $this.css("visibility", "visible"); 178 | }); 179 | } 180 | })(jQuery); 181 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-bigtext", 3 | "version": "1.3.0", 4 | "description": "jQuery plugin that makes HTML text tags as big as possible while still fitting on the parent", 5 | "main": "jquery-bigtext.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/DanielHoffmann/jquery-bigtext.git" 12 | }, 13 | "keywords": [ 14 | "jquery", 15 | "bigtext", 16 | "text" 17 | ], 18 | "author": "Daniel Hoffmann Bernardes", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/DanielHoffmann/jquery-bigtext/issues" 22 | }, 23 | "homepage": "https://github.com/DanielHoffmann/jquery-bigtext#readme" 24 | } 25 | --------------------------------------------------------------------------------