Skip to content

Commit

Permalink
Merge pull request #9 from JSteunou/issue-8
Browse files Browse the repository at this point in the history
Add UMD loader + return boxfit
  • Loading branch information
michikono committed Aug 25, 2014
2 parents 9413228 + d9d3548 commit 754bd2f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"trailing": true,
"smarttabs": true,
"globals": {
"define": false,
"after": false,
"afterEach": false,
"before": false,
Expand All @@ -32,4 +33,4 @@
"jQuery": false,
"spyOn": false
}
}
}
27 changes: 22 additions & 5 deletions dist/jquery.boxfit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -92,4 +107,6 @@
}
});
};
})(jQuery);
$.fn.boxfit = function(options) { return boxfit(this, options); };
return boxfit;
}));
2 changes: 1 addition & 1 deletion dist/jquery.boxfit.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions src/jquery.boxfit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -94,4 +107,6 @@
}
});
};
})(jQuery);
$.fn.boxfit = function(options) { return boxfit(this, options); };
return boxfit;
}));

0 comments on commit 754bd2f

Please sign in to comment.