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

Loop function / Active Class #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
19 changes: 17 additions & 2 deletions dist/morphext.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
animation: "bounceIn",
separator: ",",
speed: 2000,
activeClass: 'active',
Copy link
Owner

Choose a reason for hiding this comment

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

Can we use double quotes here for consistency? I think with the new ESLint configuration, this should be caught.

loop: 10, // loop n times around TBC
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure if I'm keen on including an out-of-the-box support for a loop limit. Seems like something that can be achieved by the complete callback.

complete: $.noop
};

Expand All @@ -36,22 +38,35 @@
Plugin.prototype = {
_init: function () {
var $that = this;
this.position = 0;
this.loops = 0;
this.phrases = [];

this.element.addClass("morphext");

$.each(this.element.text().split(this.settings.separator), function (key, value) {
$that.phrases.push($.trim(value));

});

this.loops = this.settings.loop * this.phrases.length;

this.index = -1;
this.animate();
this.start();
this.start();

},
animate: function () {
this.position++;
this.index = ++this.index % this.phrases.length;
this.element[0].innerHTML = "<span class=\"animated " + this.settings.animation + "\">" + this.phrases[this.index] + "</span>";
this.element[0].classList.add(this.settings.activeClass);
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure if it's necessary for us to add in every iteration. I feel like there should be a more elegant solution (e.g. setting a base class on the parent element, and having its style get overwritten by morphext on line 41/45).




//console.log(this.position);
Copy link
Owner

Choose a reason for hiding this comment

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

Possibly want to remove the comment here.

if(this.position == this.loops){
this.stop();
}
if ($.isFunction(this.settings.complete)) {
this.settings.complete.call(this);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/morphext.min.js

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