Post by Lynx on Feb 27, 2017 14:26:54 GMT -8
I'm working on an update for one of my plugins (Navbar Links) to have text and BG color changes on hover. I was going to use a CSS component to handle this - but I've noticed that the CSS template doesn't take plugin variables. Is there another way to do this? Here's what I have for my code update so far:
The linkHvText and linkHvBG are for the link text and BG colors on hover (set in the UI as, respectively, settings.msg_navlink[z].hover_text and settings.msg_navlink[z].hover_bg).
I've thought about adding a class to the <li> in the append, but then realized that it would probably change all colors of added navbar links when hovering over just 1. Is this possible to do? If so, could someone please help me on that?
Thanks!
// Navbar Links
// Version: 1.0.1
// Author: MSG
// This header is to remain intact.
function navlinks() {
var settings = pb.plugin.get('msg_navbar_links').settings;
var linkName = "";
var linkColor = "";
var linkBGColor = "";
var linkHvText = "";
var linkHvBG = "";
var linkDest = "";
var linkTarget = "";
var linkBold = "";
if (settings.msg_navlink.length) {
for (z = 0; z < settings.msg_navlink.length; z++) {
if (!settings.msg_navlink[z].link_name) {
pb.window.alert('Plugin: Navbar Links says - Missing Link Name','You must provide a link name for the navbar link.<br /><br />Error at UI Entry: ' + (z + 1),{
minHeight: 200,
minWidth: 600
});
return;
}
else {
linkName = settings.msg_navlink[z].link_name;
}
if (!settings.msg_navlink[z].text_color) {
linkColor = "#ffffff";
}
else {
linkColor = '#' + settings.msg_navlink[z].text_color;
}
if (!settings.msg_navlink[z].bg_color) {
linkBGColor = "transparent";
}
else {
linkBGColor = '#' + settings.msg_navlink[z].bg_color;
}
if (!settings.msg_navlink[z].hover_text) {
linkHvText = linkColor;
}
else {
linkHvText = '#' + settings.msg_navlink[z].hover_text;
}
if (!settings.msg_navlink[z].hover_bg) {
linkHvBG = linkBGColor;
}
else {
linkHvBG = '#' + settings.msg_navlink[z].hover_bg;
}
if (!settings.msg_navlink[z].dest_link) {
pb.window.alert('Plugin: Navbar Links says - Missing Destination','You must provide a destination link.<br /><br />Error at UI Entry: ' + (z + 1),{
minHeight: 200,
minWidth: 600
});
return;
}
else {
linkDest = settings.msg_navlink[z].dest_link;
}
if (!settings.msg_navlink[z].tab_type) {
linkTarget = "_self";
}
else {
linkTarget = settings.msg_navlink[z].tab_type;
}
if (!settings.msg_navlink[z].do_bold) {
linkBold = "normal";
}
else {
linkBold = settings.msg_navlink[z].do_bold;
}
$('#navigation-menu > ul').append('<li><a href="' + linkDest + '" style="color: ' + linkColor + ' !important; background-color: ' + linkBGColor + ' !important; font-weight: ' + linkBold + '" target="' + linkTarget + '">' + linkName + '</a></li>');
}
}
};
$(document).ready(function() {
navlinks();
});
The linkHvText and linkHvBG are for the link text and BG colors on hover (set in the UI as, respectively, settings.msg_navlink[z].hover_text and settings.msg_navlink[z].hover_bg).
I've thought about adding a class to the <li> in the append, but then realized that it would probably change all colors of added navbar links when hovering over just 1. Is this possible to do? If so, could someone please help me on that?
Thanks!