Closed ktryndchrs closed 10 years ago
Thanks for the suggestion! We just added two namedspaced resize methods resize.fittext orientationchange.fittext
, and I wonder if they fit into this. It could be "destroyed" with 2 lines of jQuery.
$(window).off('resize.fittext orientationchange.fittext');
$('.myElems').css('font-size', '');
I guess I'm waffling on whether it makes sense to add a method to core or if it makes more sense to document the hack to turn it off. I'm going to leave this open for awhile and if people really want the "Destroy" feature, they can :thumbsup: it if they're interested. Sound good?
I was just looking for a feature to destroy. I'll try implementing this, but, yes, thumbs up.
@davatron5000's destroy method works perfectly for me :) Thanks folks
Works like a charm for removing fittext on certain screen sizes.
I'm happy people like it! :)
I came up with an alternative fix, playing off of the original namespaced resize event. Humbly, it's a much simpler alteration than Katryn's impressive rewrite. Changes to code as follows:
Add an ID property to the SETTINGS objects (default to global)
settings = $.extend({
'minFontSize' : Number.NEGATIVE_INFINITY,
'maxFontSize' : Number.POSITIVE_INFINITY,
'id' : 'global'
}, options);
Extend the namespaced resizer event to include the ID
$(window).on('resize.fittext.' + settings.id + ' orientationchange.fittext.' + settings.id, resizer);
Optionally pass an ID with your invoked fitText function
$('#example).fitText(3, { minFontSize: '10px', maxFontSize: '20px', id: 'example' });
When you want to destroy a certain invocation, you apply Davatron's hack, but with the included namespace you wish to destroy (or global if you wish to destroy all non-namespaced invocations)
$(window).off('resize.fittext.example orientationchange.fittext.example');
$('#example').css('font-size', '');
Neat! :+1:
Here's my leaner version to @ktryndchrs's solution:
(function( $ ){
$.fn.fitText = function( kompressor, options ) {
if (kompressor === 'destroy') {
$(window).off('resize.fittext orientationchange.fittext', $(this).css('fontSize', '').data('fittext.resizer'));
return this;
}
// Setup options
var compressor = kompressor || 1,
settings = $.extend({
'minFontSize' : Number.NEGATIVE_INFINITY,
'maxFontSize' : Number.POSITIVE_INFINITY
}, options);
return this.each(function(){
// Store the object
var $this = $(this);
// Resizer() resizes items based on the object width divided by the compressor * 10
$(this).data('fittext.resizer', function () {
$this.css('font-size', Math.max(Math.min($this.width() / (compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize)));
});
// Call once to set.
$(this).data('fittext.resizer').call(this);
// Call on resize. Opera debounces their resize by default.
$(window).on('resize.fittext orientationchange.fittext', $(this).data('fittext.resizer'));
});
return this;
};
})( jQuery );
then just call $(element).fitText('destroy')
Hello there!
I wanted to be able to destroy fitText.js in certain case but instead of asking you to do it, I created another code and I think it might be useful for you or other people
Then in the html It work that way:
cheers, Catherine