Skip to content
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
21 changes: 13 additions & 8 deletions dist/truncate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
(function (module, $, undefined) {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['jQuery'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('jQuery'));
} else {
root.Truncate = factory(root.jQuery);
}
}(this, function ($) {

var BLOCK_TAGS = ['table', 'thead', 'tbody', 'tfoot', 'tr', 'col', 'colgroup', 'object', 'embed', 'param', 'ol', 'ul', 'dl', 'blockquote', 'select', 'optgroup', 'option', 'textarea', 'script', 'style'];

Expand Down Expand Up @@ -489,11 +497,8 @@
* Returns nothing.
*/
expand: function () {
var includeShowLess = true;

if(this.isExplicitlyCollapsed) {
this.isExplicitlyCollapsed = false;
includeShowLess = false;
}

if (!this.isCollapsed) {
Expand All @@ -502,7 +507,7 @@

this.isCollapsed = false;

this.element.innerHTML = this.isTruncated ? this.original + (includeShowLess ? this.options.showLess : "") : this.original;
this.element.innerHTML = this.isTruncated ? this.original + this.options.showLess : this.original;
},

/* Public: Collapses the element to the truncated state.
Expand All @@ -514,7 +519,7 @@
*/
collapse: function (retruncate) {
this.isExplicitlyCollapsed = true;

if (this.isCollapsed) {
return;
}
Expand Down Expand Up @@ -543,6 +548,6 @@
});
};

module.Truncate = Truncate;
return Truncate;

})(this, jQuery);
}));
2 changes: 1 addition & 1 deletion dist/truncate.min.js

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

8 changes: 4 additions & 4 deletions test/chrome/truncate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ describe('truncate.js', function () {
assert.equal(this.$fixture.html(), "<div>Members, friends, adversaries… <a href=\"#\">More</a></div>");

this.$fixture.truncate('expand');
assert.equal(this.$fixture.html(), '<div>Members, friends, adversaries, competitors, and colleagues</div>');
assert.equal(this.$fixture.html(), "<div>Members, friends, adversaries, competitors, and colleagues</div><a href=\"#\">Less</a>");
});
});

Expand Down Expand Up @@ -320,14 +320,14 @@ describe('truncate.js', function () {
this.$fixture.truncate('collapse');
assert.equal(this.$fixture.html(), "<div>Members, friends, adversaries… <a href=\"#\">More</a></div>");
});

it('should keep the collapsed status after multiple update', function () {
this.$fixture.truncate('collapse');
assert.equal(this.$fixture.html(), "<div>Members, friends, adversaries… <a href=\"#\">More</a></div>");

this.$fixture.truncate('update', '<div>Members.</div>');
assert.equal(this.$fixture.html(), "<div>Members.</div>");

this.$fixture.truncate('update', '<div>Members, friends, adversaries, competitors, and colleagues</div>');
assert.equal(this.$fixture.html(), "<div>Members, friends, adversaries… <a href=\"#\">More</a></div>");
});
Expand Down Expand Up @@ -405,7 +405,7 @@ describe('truncate.js', function () {
assert.equal(this.$fixture.html(), "Lorem Ipsum is simply dummy text…");

this.$fixture.truncate('config', {lines: 2});
assert.equal(this.$fixture.html(), "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem");
assert.equal(this.$fixture.html(), "Lorem Ipsum is simply dummy text of the printing and typesetting industry");
});

it('should keep the collapsed after update options', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/phantomjs/truncate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ describe('truncate.js', function () {
assert.equal(this.$fixture.html(), "<div>Members, friends, adversaries,… <a href=\"#\">More</a></div>");

this.$fixture.truncate('expand');
assert.equal(this.$fixture.html(), '<div>Members, friends, adversaries, competitors, and colleagues</div>');
assert.equal(this.$fixture.html(), "<div>Members, friends, adversaries, competitors, and colleagues</div><a href=\"#\">Less</a>");
});
});

Expand Down
7 changes: 2 additions & 5 deletions truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,8 @@
* Returns nothing.
*/
expand: function () {
var includeShowLess = true;

if(this.isExplicitlyCollapsed) {
this.isExplicitlyCollapsed = false;
includeShowLess = false;
}

if (!this.isCollapsed) {
Expand All @@ -510,7 +507,7 @@

this.isCollapsed = false;

this.element.innerHTML = this.isTruncated ? this.original + (includeShowLess ? this.options.showLess : "") : this.original;
this.element.innerHTML = this.isTruncated ? this.original + this.options.showLess : this.original;
},

/* Public: Collapses the element to the truncated state.
Expand All @@ -522,7 +519,7 @@
*/
collapse: function (retruncate) {
this.isExplicitlyCollapsed = true;

if (this.isCollapsed) {
return;
}
Expand Down