Skip to content

Commit

Permalink
Update jquery.expander.js to include digits in wordEnd default.
Browse files Browse the repository at this point in the history
Fixes gh-107.
Closes gh-108.
  • Loading branch information
teo1978 authored and kswedberg committed Jun 9, 2015
1 parent 005f08a commit 7abe5eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jquery.expander.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
expandAfterSummary: false,

// Possible word endings to test against for when preserveWords: true
wordEnd: /(&(?:[^;]+;)?|[a-zA-Z\u00C0-\u0100]+|[^\u0000-\u007F]+)$/,
wordEnd: /(&(?:[^;]+;)?|[0-9a-zA-Z\u00C0-\u0100]+|[^\u0000-\u007F]+)$/,

// class names for summary element and detail element
summaryClass: 'summary',
Expand Down
3 changes: 3 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ <h2 id="qunit-userAgent"></h2>
<div id="wordcountesc">
They wake up every day dreading the sunrise. Knowing every time... the gap between us becomes &amp; is too small for &nbsp; -thier- &nbsp; comfort.
</div>
<div id="preserveNumbers">
Lorem ipsum ....... bla bla 1234567890 dolor sit amet
</div>
<div id="wordcountsp">
They wake up every day dreading the sunrise. Knowing that every time, the gap between us becomes greater , , , , , spaced , ~ , and . sparce ... - every day.
</div>
Expand Down
12 changes: 12 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,18 @@ module('odd html', {

$('#hidden-container').children('p').expander();
this.hiddenContainer = $('#hidden-container');
this.preserveNumbers = $('#preserveNumbers').expander({
slicePoint: 35,
preserveWords: true
});
},
teardown: function() {
this.endinghr.expander('destroy');
this.sametag.expander('destroy');
this.ampbr.expander('destroy');
this.htmlescape.expander('destroy');
this.preserveNumbers.expander('destroy');

$('#hidden-container').children('p').expander('destroy');
}
});
Expand Down Expand Up @@ -383,6 +389,12 @@ test('split html escapes', function() {
equal(( this.htmlescape.text().charAt(97) !== '&'), true, 'correctly shifts stray "nbsp;" out of detailText');
});

test('preserve numbers as words', function() {
equal(this.preserveNumbers.find('.details').length, 1, 'created detail');
this.preserveNumbers.find('.read-more, .details').remove();
equal( $.trim(this.preserveNumbers.text()).length, 27, 'split at 27 characters, preserving the long number');
});

/* PRESET ELEMENTS */
module('Preset Elements', {
setup: function() {
Expand Down

0 comments on commit 7abe5eb

Please sign in to comment.