-
Notifications
You must be signed in to change notification settings - Fork 0
/
$lib.coffee
41 lines (35 loc) · 1.14 KB
/
$lib.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(->
exports = this
###
# TODO - this doesn't work unless its paragraph text without
# and tags around the last space(s). It also doesn't
# work if there's more than one space before the last word.
# TODO - implement minWords.
# TODO - allow html string or element object as first argument.
# TODO - allow the first argument to be an array/collection of
# strings or objects.
###
preventWidow = (html, minWords) ->
return html.replace(/ ([^ ]*)$/,' $1')
###
# Create and export our $lib object
###
$lib = (->)
#$lib.preventWidow = preventWidow
exports.$lib = $lib
return $lib
###
# This is the original function that I'm using as a base for
# preventWidow. Stolen from
# http://www.webdevdoor.com/jquery/preventing-widows-websites-jquery/
# But I think this function needs a little help to allow specifying
# minumum number of words on the last line and allowing operation on
# either strings or elements.
#
$('p').each(function(){
var string = $(this).html();
string = string.replace(/ ([^ ]*)$/,' $1');
$(this).html(string);
});
###
).call(this)