Skip to content

Commit

Permalink
Integrate PR#33; fix compressor bug
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmarabeas committed Mar 3, 2017
1 parent 5d60781 commit b430db6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngFitText",
"version": "4.2.1",
"version": "4.2.2",
"main": [
"dist/ng-FitText.min.js"
],
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-fittext",
"version": "4.2.1",
"version": "4.2.2",
"description": "An AngularJS directive for inflating web type",
"homepage": "https://github.com/patrickmarabeas/ng-FitText.js",
"bugs": "https://github.com/patrickmarabeas/ng-FitText.js/issues",
Expand All @@ -10,6 +10,9 @@
},
"license": "MIT",
"main": "dist/ng-FitText.min.js",
"scripts": {
"gulp": "gulp"
},
"devDependencies": {
"gulp": "3.8.8",
"gulp-rename": "^1.2.2",
Expand Down
29 changes: 24 additions & 5 deletions src/ng-FitText.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* ng-FitText.js v4.2.1
* ng-FitText.js v4.2.2
* https://github.com/patrickmarabeas/ng-FitText.js
*
* Original jQuery project: https://github.com/davatron5000/FitText.js
Expand All @@ -8,7 +8,7 @@
* Released under the MIT license
* http://opensource.org/licenses/mit-license.php
*
* Date: 12/06/2016
* Date: 03/03/2017
*/

(function(window, document, angular, undefined) {
Expand Down Expand Up @@ -44,14 +44,15 @@
, computed = window.getComputedStyle(element[0], null)
, newlines = element.children().length || 1
, loadDelay = attrs.fittextLoadDelay || config.loadDelay
, compressor = isNaN(attrs.fittext) ? config.compressor : attrs.fittext
, compressor = isNaN(parseInt(attrs.fittext)) ? config.compressor : attrs.fittext
, min = attrs.fittextMin || config.min
, max = attrs.fittextMax || config.max
, minFontSize = min ==='inherit'? computed['font-size'] : min
, maxFontSize = max ==='inherit'? computed['font-size'] : max
, lineHeight = computed['line-height']
, display = computed['display']
, calcSize = 10
, resizePromise
;

function calculate() {
Expand All @@ -64,7 +65,7 @@
)
}

function resizer() {
function resize() {
// Don't calculate for elements with no width or height
if (domElem.offsetHeight * domElem.offsetWidth === 0)
return;
Expand All @@ -80,9 +81,27 @@
domElemStyle.display = display;
}

function resizer() {
if(resizePromise)
$timeout.cancel(resizePromise);

resizePromise = $timeout(function() {
resizePromise = null;
resize();
}, 5);
}

$timeout( function() { resizer() }, loadDelay);

scope.$watch(attrs.ngBind, function() { resizer() });
scope.$watch(function() {
return [
scope.$eval(attrs.ngBind),
parent[0].offsetWidth,
element[0].offsetWidth
].join('_');
}, function() {
resizer();
});

config.debounce
? angular.element(window).bind('resize', config.debounce(function(){ scope.$apply(resizer)}, config.delay))
Expand Down

0 comments on commit b430db6

Please sign in to comment.