Skip to content

Also run resizeText at window.onload #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions jquery-responsive-headlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ into responsive headlines:

$('h1').responsiveHeadlines();

There are also a handfull of options that you can use to customize
There are also a handful of options that you can use to customize
the behaviour of the plugin. The easiest way to understand what they
do is read the comments in the source code below and do some experimentation
on your own using the HTML demo page which accompanies this code in the
Expand All @@ -34,15 +34,15 @@ just to get you started:
JQUERY THROTTLE/DEBOUNCE
jQuery Responsive Headlines works best if you use it together with
Ben Alman's jquery-throttle-debounce plugin. It's a plugin for
controling/limiting the number of calls to a function.
controlling/limiting the number of calls to a function.
In this case it's very useful since the window resize event is triggered
very often and the function that determines the size of the text is
bound to this event.

Ben Alman's project page: http://benalman.com/projects/jquery-throttle-debounce-plugin/
Ben Alman's repository on GitHub: https://github.com/cowboy/jquery-throttle-debounce

Per default jquery-trottle-debounce is used (the option useThrottleDebounce
Per default jquery-throttle-debounce is used (the option useThrottleDebounce
is set to true) and therefore I have included a copy of it in this repository.
As I said, for performance reasons I recommend that you use it, but if you
for some reason don't want it just set the option useThrottleDebounce to false.
Expand Down Expand Up @@ -101,6 +101,13 @@ for some reason don't want it just set the option useThrottleDebounce to false.
// Run the resize function
self.resizeText();

// Event handler when all page assets are loaded
// This handles cases where this was triggered at DOMReady, but fonts/css/etc.
// load later that change the layout of the page
$(window).on("load", function() {
self.resizeText();
});

// Event handler when the window is resized.
// To avoid too many calls to the resizeText function, which
// will lead to bad performance, I use Ben Almans jquery-throttle-debounce
Expand All @@ -110,9 +117,9 @@ for some reason don't want it just set the option useThrottleDebounce to false.
// Is jquery-throttle-debounce used?
if(o.useThrottleDebounce) {

if(o.throttleDebounceParams.method === 'trottle') {
if(o.throttleDebounceParams.method === 'throttle') {
// Throttle method
$(window).on('resize', $.trottle(o.throttleDebounceParams.delay, o.throttleDebounceParams.no_trailing, function() {
$(window).on('resize', $.throttle(o.throttleDebounceParams.delay, o.throttleDebounceParams.no_trailing, function() {
self.resizeText();
}));
} else {
Expand Down
2 changes: 1 addition & 1 deletion jquery-responsive-headlines.min.js

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