ng-FitText.js icon indicating copy to clipboard operation
ng-FitText.js copied to clipboard

Force refreshing

Open piwel opened this issue 8 years ago • 7 comments

Is it possible to have a way to manually refresh the font-size calculation ?

Maybe via a custom event that we could trigger when we want, or by watching another special attribute, or both...

We need to use ngBindHtml , and not ngBind (that is [watched](ngBind watch) by the directive). It may also help people using the {{ ... }} notation, or after having resized the parent container.

piwel avatar Feb 19 '16 01:02 piwel

I've been mulling the idea of giving the fitTextConfigProvider an array of things to watch. Won't be able to implement this for the next ~month though unfortunately, so feel free to make a PR if you get something working in the meantime.

patrickmarabeas avatar Feb 19 '16 02:02 patrickmarabeas

I use this workaround,

    <div id="containerdiv">
        <h1 data-fittext> Ciao Ciao!<h1>
    </div>

in the event resize

$compile($('#containerdiv'))($scope);

It's worked for me

andreadompe avatar Apr 22 '16 07:04 andreadompe

Hi, I have been trying to create my own speeddial thing and use fittext to change the font size of the tile titles. However I've created some sliders to change to width and height of each tile. I would now like to update/trigger the directive to resize the text when i change the size of the tile. Using the above solution from andreadompe works just fine however the more it's used(the more times you change the tile size) the slower the rendering of the browser becomes. Sliding several times makes the window very laggy until you refresh the page. Is there still no other method to trigger the directive through in other ways? Thank in advance.

devidation avatar Jul 17 '16 19:07 devidation

@devidation: Debounce the call your slider makes. Have a look at how ngFitText handles the resize event if a debounce function is supplied.

patrickmarabeas avatar Jul 18 '16 08:07 patrickmarabeas

Ok, I solved this by simply doing a $(window).trigger('resize'), which the plugins listens to, to update itself, after changing the content.

On a side note, for others that might run into this, on angular 1.5+, when updating the scope itself, I was running into the "$scope.digest already in progress" errors... I solved it by removing the scope.apply and just calling resizer() on its own: config.debounce ? angular.element(window).bind('resize', config.debounce(function(){ scope.$apply(resizer)}, config.delay)) : angular.element(window).bind('resize', function(){ resizer()}); }

jmartinezuk avatar Jul 28 '16 09:07 jmartinezuk

If you can create a demo on codepen illustrating the digest issue I'll look at fixing.

patrickmarabeas avatar Mar 03 '17 01:03 patrickmarabeas

ran into this issue and solved it by doing small changes in the directive added if (attrs.fittextMax != undefined && maxFontSize !== attrs.fittextMax) { maxFontSize = attrs.fittextMax; } in the caclulate() function

and added scope.$eval(attrs.fittextMax), to the watch

Now I can dynamically adjust the size by adjusting it in the model and using it in the html data-fittext-max="{{vm.maxSize}}"

mos379 avatar Jul 25 '21 17:07 mos379