I have an icon name tag-icon-arrow i have onclick and hover events on it.
But since i hover over the icon the hover is active and when clicked both are active which i don't want, I know before clicking it will hover here,but if i click on the icon it should turn off.
bindViewEvents: function () {
let me = this
, window = this.$window
, $tagArrow = window.find(".tag-icon-arrow");
$tagArrow.off().on('click', function (e) {
me.highlight(e, true, true);
});
$tagArrow.hover(
function (e) {me.highlight(e, true);},
function (e) {me.highlight(e, false);}
);
$tagArrow.on('click', function (e) {
me.selectRole(e);
});
},
selectRole: function (e) {
let me = this;
let $target = $(e.currentTarget);
let hasRole = $target.is("[data-role]");
let tagid = hasRole ? $target.attr("data-tagid") : null;
me.api.xyz(tagid);
},
highlight: function (e, canHighlight, clicked) {
let me = this
, $target = $(e.currentTarget)
, _id = $target.attr('data-id')
, tagid = $target.attr("data-tagid")
, tbId = me.isZone ? $target.attr("data-M") : "";
if (canHighlight) {
clicked ? $target.addClass("active") :
$target.removeClass("active");
if (tbId === undefined) tbId = "";
let objData = [{"_id": _id, "tagid": tagid,}];
Common.Gateway.onEventsToXYZ({
"event": "xyz",
"fids": me.isZone ? [] : objData,
"rids": me.isZone ? objData : []
});
me.api.xyz(tagid);
} else {
if ($target.is(".active"))
return;
Common.Gateway.onEventsToXYZ({
"event": "xyz"
});
me.api.xyz(null);
$target.removeClass("active");
}
},
selectRole and highLight functions are custom functions to call based on the event triggered. How can improve this so that both work properly? as they are expected to.
Just don't turn off highlighting when the role is selected:
But better use CSS: