davatron5000 / FitText.js

A jQuery plugin for inflating web type
http://fittextjs.com
6.76k stars 1.39k forks source link

Add optional support for matchMedia #126

Open jpederson opened 9 years ago

jpederson commented 9 years ago

Uses Paul Irish's original matchMedia function if it's available, and takes a string as a plugin option of the same name. Still runs if matchMedia isn't found. Added usage instructions to the readme and an example line in the demo file. I chose to accept all the same arguments as matchMedia because it was easy, and enables things like matchMedia: 'tv' and orientation-based fitText via matchMedia: 'all and (orientation:landscape)', etc.

jpederson commented 9 years ago

Had to make a couple quick updates to clean up my code. Let me know if there's anything else you see needing to be done in order for this to be included.

jpederson commented 9 years ago

Fixes made to readme to use single quotes.

davatron5000 commented 9 years ago

Hey! Just wanted to say I like this. Might be a bit before I have time to pull the branch, QA it and merge it all in. But this is a pretty sweet feature. That ternary + min/max super loop thing we have going on may need some cleaning up, but don't worry about it right now. Cleaning up that min/max stuff has been in the back of my brain for awhile.

Thanks! And hopefully I can get to this soon.

jpederson commented 9 years ago

Cool, glad you like it, Dave! By the way, love your podcast, long time listener!

jpederson commented 9 years ago

As far as the ternary, my initial commit has my logic a little more expanded so its more legible (before I made it all one line for file size sake). We can roll back to that version of that chunk of code if you like - it'd also provide the opportunity to output a console message to let devs know if/when matchMedia is asked for, but not found. That part is unnecessary, but convenient and wouldn't add a lot of file size. Up to you! It's a pretty small detail, and that line of code executes quite quickly and is pretty efficient (it's just not as easy/convenient for humans to read), so it may not need adjustment to be honest, but happy to revisit it - let me know your preference.