Skip to content

adamjgrant/Buddy-System

Repository files navigation

BuddySystem

Avoids single words breaking onto the last line of text.

Usage

Without jQuery

Use buddysystem.js and simply pass in an array of objects into buddySystem()

objs = document.getElementsByClassName('corrected')
buddySystem(objs)

With jQuery

Use buddysystem.jquery.js after jQuery and $.buddySystem() on any element or elements.

$('.corrected').buddySystem()

How it works

Because you don't need yet another library in your app to do something so simple, this code snippet has been golfed to be as small as possible.

BuddySystem looks for the last space in a phrase like this one

The rain in Spain falls mainly on the plains

And replaces it with  , causing the last two words to be parsed as one...holding hands together, the buddy system.

The rain in Spain falls mainly on the plains

Of course, because   is unicode markup for a non-breaking space, the text will appear as:

"The rain in Spain falls mainly on
the plains"

If the line breaks after the last "the".

About

Avoids single words breaking onto the last line of text.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published