Skip to content
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

add data-trunk8-* support #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
20 changes: 16 additions & 4 deletions trunk8.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
width = settings.width,
side = settings.side,
fill = settings.fill,
parseHTML = settings.parseHTML,
parseHTML = settings.parseHTML && settings.parseHTML !== 'false',
line_height = utils.getLineHeight(this) * settings.lines,
str = data.original_text,
length = str.length,
Expand Down Expand Up @@ -202,7 +202,7 @@
/* Display the biggest bite. */
this.html(max_bite);

if (settings.tooltip) {
if (settings.tooltip && settings.tooltip !== 'false') {
this.attr('title', text);
}
}
Expand All @@ -213,7 +213,7 @@

this.html(bite);

if (settings.tooltip) {
if (settings.tooltip && settings.tooltip !== 'false') {
this.attr('title', str);
}
}
Expand All @@ -226,15 +226,27 @@

methods = {
init: function (options) {
// data-trunk8-* config prefix
var trunk8DataAttributeName = 'data-trunk8-';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved into the return function with the other vars (elementAttributes, attributes).

return this.each(function () {
var $this = $(this),
data = $this.data('trunk8');

if (!data) {
$this.data('trunk8', (data = new trunk8(this)));
}

// add data-trunk8-* support
var elementAttributes = {};
var attributes = this.attributes;
if (attributes) {
$.each(attributes,function (index,attribute) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing:

$.each(attributes, function(index, attribute) {

if (attribute.name.indexOf(trunk8DataAttributeName) == 0) {
elementAttributes[attribute.name.substring(trunk8DataAttributeName.length)] = attribute.value;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line has gotten to be very long. Could you set attribute.name.substring(trunk8DataAttributeName.length) to a local variable "optionName"?

}
});
}
data.updateSettings(options);
data.updateSettings(elementAttributes);

truncate.call($this);
});
Expand Down