Skip to content

Commit

Permalink
New data attributes: data-hybicon-animtime, data-hybicon-animease
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaretailoring committed Dec 6, 2015
1 parent 6832290 commit 20996ab
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 34 deletions.
53 changes: 39 additions & 14 deletions js/hybicon.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ hybicon = function (divId) {
this.icon2AnimSettings = null;
this.icon2Anim = new this.hybiconSettings();

this.animateTime = 200;
this.animateEffect = "linear";
this.animateTime = null;
this.animateEasing = null;
this.hoverMode = null;
this.clickMode = null;
this.hovered = false;
Expand Down Expand Up @@ -162,6 +162,8 @@ hybicon.prototype.createIcon = function () {
}

this.raphael = new Raphael(this.holderId);
this.raphael.canvas.id = this.getSvgId();

this.raphael.setViewBox(0, 0, iconWidth, iconHeight, true);

// Set style of svg
Expand Down Expand Up @@ -224,7 +226,7 @@ hybicon.prototype.createIcon = function () {
this.info.id = this.getInfoId();
this.info.node.id = this.info.id;
this.infotext.id = this.getInfoTextId();
this.infotext.node.id = this.infotext.id;
this.infotext.node.childNodes[0].id = this.infotext.id;
}
}

Expand Down Expand Up @@ -293,15 +295,15 @@ hybicon.prototype.createIcon = function () {

hybicon.prototype.hoverHandler = function (hovered) {
if (hovered === true) {
this.icon1.animate({ path: this.icon1PathAnim, transform: this.icon1TransformAnim }, this.animateTime, this.animateEffect);
this.icon1.animate({ path: this.icon1PathAnim, transform: this.icon1TransformAnim }, this.animateTime, this.animateEasing);
if (this.icon2PathAnim !== null) {
this.icon2.animate({ path: this.icon2PathAnim, transform: this.icon2TransformAnim }, this.animateTime, this.animateEffect);
this.icon2.animate({ path: this.icon2PathAnim, transform: this.icon2TransformAnim }, this.animateTime, this.animateEasing);
}
}
else {
this.icon1.animate({ path: this.icon1Path, transform: this.icon1Transform }, this.animateTime, this.animateEffect);
this.icon1.animate({ path: this.icon1Path, transform: this.icon1Transform }, this.animateTime, this.animateEasing);
if (this.icon2Path !== null) {
this.icon2.animate({ path: this.icon2Path, transform: this.icon2Transform }, this.animateTime, this.animateEffect);
this.icon2.animate({ path: this.icon2Path, transform: this.icon2Transform }, this.animateTime, this.animateEasing);
}
}
};
Expand Down Expand Up @@ -447,6 +449,20 @@ hybicon.prototype.parseIcon = function () {
this.icon2AnimSettings = hybiconIcon2Anim;
}

//data-hybicon-animtime
var hybiconAnimatetime = this.holderDiv.getAttribute("data-hybicon-animtime");
if (hybiconAnimatetime !== null &&
hybiconAnimatetime !== "") {
this.animateTime = hybiconAnimatetime;
}

//data-hybicon-animease
var hybiconAnimateeasing = this.holderDiv.getAttribute("data-hybicon-animease");
if (hybiconAnimateeasing !== null &&
hybiconAnimateeasing !== "") {
this.animateEasing = hybiconAnimateeasing;
}

this.createIcon();
}

Expand Down Expand Up @@ -519,7 +535,7 @@ hybicon.prototype.setDefaultProps = function () {
icon1CenterYDefault = 50;
icon2CenterXDefault = 50;
icon2CenterYDefault = 50;
icon2SizeDefault = 50;
icon2SizeDefault = 44;
}

if (this.icon1Init.size === null) { this.icon1Init.size = icon1SizeDefault; }
Expand Down Expand Up @@ -564,8 +580,6 @@ hybicon.prototype.setDefaultProps = function () {
else {
if (this.icon1Anim.rotate === null) { this.icon1Anim.rotate = rotatedeg; }
}

if (this.hoverMode === "rotate") { this.animateTime = 400; }
}

// set width and height
Expand Down Expand Up @@ -618,6 +632,13 @@ hybicon.prototype.setDefaultProps = function () {
this.icon2XAnim = sizeTransform2Anim.iconX;
this.icon2YAnim = sizeTransform2Anim.iconY;
}

// Animation
if (this.animateTime === null) {
if (this.hoverMode === "rotate") { this.animateTime = 400; }
else { this.animateTime = 200; }
}
if (this.animateEasing === null) { this.animateEasing = "linear"; }
};

hybicon.prototype.setIconSettings = function (iconSet, iconSettings) {
Expand Down Expand Up @@ -682,20 +703,24 @@ hybicon.prototype.getTransformString = function (x, y, scale, rotate) {
};

//Identifiers
hybicon.prototype.getSvgId = function () {
return this.holderId + "-svg";
};

hybicon.prototype.getIcon1Id = function () {
return "hybicon-" + this.holderId + "-icon1";
return this.holderId + "-icon1";
};

hybicon.prototype.getIcon2Id = function () {
return "hybicon-" + this.holderId + "-icon2";
return this.holderId + "-icon2";
};

hybicon.prototype.getInfoId = function () {
return "hybicon-" + this.holderId + "-info";
return this.holderId + "-info";
};

hybicon.prototype.getInfoTextId = function () {
return "hybicon-" + this.holderId + "-infotext";
return this.holderId + "-infotext";
};

//Automatic parse
Expand Down
2 changes: 1 addition & 1 deletion js/hybicon.core.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 20996ab

Please sign in to comment.