diff --git a/.jshintrc b/.jshintrc
index 6652a20..a6215f1 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -19,6 +19,7 @@
"trailing": true,
"smarttabs": true,
"globals": {
+ "define": false,
"after": false,
"afterEach": false,
"before": false,
@@ -32,4 +33,4 @@
"jQuery": false,
"spyOn": false
}
-}
\ No newline at end of file
+}
diff --git a/dist/jquery.boxfit.js b/dist/jquery.boxfit.js
index 000c776..f763a74 100644
--- a/dist/jquery.boxfit.js
+++ b/dist/jquery.boxfit.js
@@ -5,11 +5,24 @@
To use: $('#target-div').boxFit()
Will make the *text* content inside the div (or whatever tag) scale to fit that tag
*/
-'use strict';
-(function ($) {
- $.fn.boxfit = function (options) {
- return this.each(function () {
+
+(function (root, factory) {
+ 'use strict';
+ if (typeof define === 'function' && define.amd) {
+ // AMD
+ define(['jquery'], function($) { return factory(root, $); });
+ } else if (typeof exports === 'object') {
+ // CommonJS
+ module.exports = factory(root, require('jquery'));
+ } else {
+ // Browser globals
+ factory(root, jQuery);
+ }
+}(this, function (window, $) {
+ 'use strict';
+ var boxfit = function ($nodes, options) {
+ return $nodes.each(function () {
var current_step, inner_span, next_font_size, original_height, original_text, original_width, settings, span;
settings = {
// manually set a width/height if you haven't set one explicitly via CSS
@@ -74,6 +87,8 @@
}
// fixing issue where custom line-heights would break wrapped text
inner_span.css('line-height', '100%');
+
+ // keep growing the target so long as we haven't exceeded the width or height
inner_span.css('font-size', settings.minimum_font_size);
while ($(this).width() <= original_width && $(this).height() <= original_height) {
if (current_step++ > settings.step_limit) {
@@ -92,4 +107,6 @@
}
});
};
-})(jQuery);
+ $.fn.boxfit = function(options) { return boxfit(this, options); };
+ return boxfit;
+}));
diff --git a/dist/jquery.boxfit.min.js b/dist/jquery.boxfit.min.js
index 8b06001..fd99e5f 100644
--- a/dist/jquery.boxfit.min.js
+++ b/dist/jquery.boxfit.min.js
@@ -1 +1 @@
-"use strict";!function(a){a.fn.boxfit=function(b){return this.each(function(){var c,d,e,f,g,h,i,j;if(i={width:null,height:null,step_size:1,step_limit:200,align_middle:!0,align_center:!0,multiline:!1,minimum_font_size:5,maximum_font_size:null},a.extend(i,b),i.width?(h=i.width,a(this).width(h+"px")):h=a(this).width(),i.height?(f=i.height,a(this).height(f+"px")):f=a(this).height(),h&&f){for(i.multiline||a(this).css("white-space","nowrap"),g=a(this).html(),0===a("
"+g+"
").find("span.boxfitted").length?(j=a(a("").addClass("boxfitted").html(g)),a(this).html(j)):j=a(a(this).find("span.boxfitted")[0]),c=0,d=j,a(this).css("display","table"),d.css("display","table-cell"),i.align_middle&&d.css("vertical-align","middle"),i.align_center&&(a(this).css("text-align","center"),d.css("text-align","center")),d.css("line-height","100%"),d.css("font-size",i.minimum_font_size);a(this).width()<=h&&a(this).height()<=f&&!(c++>i.step_limit)&&(e=parseInt(d.css("font-size"),10),!(i.maximum_font_size&&e>i.maximum_font_size));)d.css("font-size",e+i.step_size);return d.css("font-size",parseInt(d.css("font-size"),10)-i.step_size),a(this)}return null!==window.console?console.info("Set static height/width on target DIV before using boxfit! Detected width: "+h+" height: "+f):void 0})}}(jQuery);
\ No newline at end of file
+!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["jquery"],function(c){return b(a,c)}):"object"==typeof exports?module.exports=b(a,require("jquery")):b(a,jQuery)}(this,function(a,b){"use strict";var c=function(c,d){return c.each(function(){var c,e,f,g,h,i,j,k;if(j={width:null,height:null,step_size:1,step_limit:200,align_middle:!0,align_center:!0,multiline:!1,minimum_font_size:5,maximum_font_size:null},b.extend(j,d),j.width?(i=j.width,b(this).width(i+"px")):i=b(this).width(),j.height?(g=j.height,b(this).height(g+"px")):g=b(this).height(),i&&g){for(j.multiline||b(this).css("white-space","nowrap"),h=b(this).html(),0===b(""+h+"
").find("span.boxfitted").length?(k=b(b("").addClass("boxfitted").html(h)),b(this).html(k)):k=b(b(this).find("span.boxfitted")[0]),c=0,e=k,b(this).css("display","table"),e.css("display","table-cell"),j.align_middle&&e.css("vertical-align","middle"),j.align_center&&(b(this).css("text-align","center"),e.css("text-align","center")),e.css("line-height","100%"),e.css("font-size",j.minimum_font_size);b(this).width()<=i&&b(this).height()<=g&&!(c++>j.step_limit)&&(f=parseInt(e.css("font-size"),10),!(j.maximum_font_size&&f>j.maximum_font_size));)e.css("font-size",f+j.step_size);return e.css("font-size",parseInt(e.css("font-size"),10)-j.step_size),b(this)}return null!==a.console?console.info("Set static height/width on target DIV before using boxfit! Detected width: "+i+" height: "+g):void 0})};return b.fn.boxfit=function(a){return c(this,a)},c});
\ No newline at end of file
diff --git a/src/jquery.boxfit.js b/src/jquery.boxfit.js
index b6ab516..f763a74 100644
--- a/src/jquery.boxfit.js
+++ b/src/jquery.boxfit.js
@@ -5,11 +5,24 @@
To use: $('#target-div').boxFit()
Will make the *text* content inside the div (or whatever tag) scale to fit that tag
*/
-'use strict';
-(function ($) {
- $.fn.boxfit = function (options) {
- return this.each(function () {
+
+(function (root, factory) {
+ 'use strict';
+ if (typeof define === 'function' && define.amd) {
+ // AMD
+ define(['jquery'], function($) { return factory(root, $); });
+ } else if (typeof exports === 'object') {
+ // CommonJS
+ module.exports = factory(root, require('jquery'));
+ } else {
+ // Browser globals
+ factory(root, jQuery);
+ }
+}(this, function (window, $) {
+ 'use strict';
+ var boxfit = function ($nodes, options) {
+ return $nodes.each(function () {
var current_step, inner_span, next_font_size, original_height, original_text, original_width, settings, span;
settings = {
// manually set a width/height if you haven't set one explicitly via CSS
@@ -94,4 +107,6 @@
}
});
};
-})(jQuery);
+ $.fn.boxfit = function(options) { return boxfit(this, options); };
+ return boxfit;
+}));