Skip to content

Commit

Permalink
Merge pull request jschr#48 from tengyifei/master
Browse files Browse the repository at this point in the history
possible to specify options via data- attributes
  • Loading branch information
Jordan Schroter committed Jul 28, 2014
2 parents 2627c83 + 557dea3 commit 4d6914d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions jquery.textillate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,21 @@
if (!attrs.length) return data;

$.each(attrs, function (i, attr) {
if (/^data-in-*/.test(attr.nodeName)) {

function stringToBoolean(str) {
if (str !== "true" && str !== "false") return str;
return (str === "true");
}

var nodeName = attr.nodeName.replace(/delayscale/, 'delayScale');
if (/^data-in-*/.test(nodeName)) {
data.in = data.in || {};
data.in[attr.nodeName.replace(/data-in-/, '')] = attr.nodeValue;
} else if (/^data-out-*/.test(attr.nodeName)) {
data.in[nodeName.replace(/data-in-/, '')] = stringToBoolean(attr.nodeValue);
} else if (/^data-out-*/.test(nodeName)) {
data.out = data.out || {};
data.out[attr.nodeName.replace(/data-out-/, '')] = attr.nodeValue;
} else if (/^data-*/.test(attr.nodeName)) {
data[attr.nodeName] = attr.nodeValue;
data.out[nodeName.replace(/data-out-/, '')] =stringToBoolean(attr.nodeValue);
} else if (/^data-*/.test(nodeName)) {
data[nodeName] = stringToBoolean(attr.nodeValue);
}
})

Expand Down Expand Up @@ -135,7 +142,7 @@
index = index || 0;

var $elem = base.$texts.find(':nth-child(' + (index + 1) + ')')
, options = $.extend({}, base.options, getData($elem))
, options = $.extend(true, {}, base.options, $elem.length?getData($elem[0]):{})
, $chars;

$elem.addClass('current');
Expand Down Expand Up @@ -179,7 +186,7 @@
base.out = function (cb) {
var $elem = base.$texts.find(':nth-child(' + (base.currentIndex + 1) + ')')
, $chars = base.$current.find('[class^="char"]')
, options = $.extend({}, base.options, getData($elem));
, options = $.extend(true, {}, base.options, $elem.length?getData($elem[0]):{})

base.triggerEvent('outAnimationBegin');

Expand Down Expand Up @@ -271,4 +278,4 @@
callback: function () {}
};

}(jQuery));
}(jQuery));

0 comments on commit 4d6914d

Please sign in to comment.