Post by Lynx on Sept 4, 2017 12:27:32 GMT -8
I'm working on an update for my Navbar Links plugin. Here's the code:
Here's the UI:
I've added using Member Groups, but I've got to be doing something wrong - as nothing shows in the navbar and no errors. I did have this line:
like this:
but no luck. The for loop for the y variable was added in, thinking I would need a separate loop to check that. Before I added the for loop for the y variable, I had 2 instances of Test 1 showing in the navbar, when there should have been a Test 1 and a Test 2:
If nothing is added into the Who Can Use? column, the link should show for everyone. Any advice / assistance would be appreciated.
Thanks!
// Navbar Links
// Version: 1.0.1
// Author: MSG
// This header is to remain intact.
function navlinks() {
var user = pb.data('user');
var groups = pb.data('user').group_ids;
var settings = pb.plugin.get('msg_navbar_links').settings;
var linkName = "";
var linkColor = "";
var linkBGColor = "";
var linkDest = "";
var linkTarget = "";
var linkBold = "";
var whoCanUse = [];
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].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;
}
if (settings.msg_navlink.length) {
for (z = 0; z < settings.msg_navlink.length; z++) {
for (y = 0; y < settings.msg_navlink[z].who_can_use.length; y++) {
if ($.inArrayLoose(groups, settings.msg_navlink[z].who_can_use[y] != -1) || settings.msg_navlink[z].who_can_use[0] == undefined) {
$('#navigation-menu > ul').append('<li><a class="msg-navlnk" href="' + linkDest + '" style="color: ' + linkColor + ' !important; background-color: ' + linkBGColor + ' !important; font-weight: ' + linkBold + '" target="' + linkTarget + '">' + linkName + '</a></li>');
}
}
}
}
}
}
};
$(document).ready(function() {
navlinks();
});
Here's the UI:
I've added using Member Groups, but I've got to be doing something wrong - as nothing shows in the navbar and no errors. I did have this line:
if ($.inArrayLoose(groups, settings.msg_navlink[z].who_can_use[y] != -1) || settings.msg_navlink[z].who_can_use[0] == undefined) {
like this:
if ($.inArrayLoose(groups, settings.msg_navlink[z][y].who_can_use != -1) || settings.msg_navlink[z][0].who_can_use == undefined) {
but no luck. The for loop for the y variable was added in, thinking I would need a separate loop to check that. Before I added the for loop for the y variable, I had 2 instances of Test 1 showing in the navbar, when there should have been a Test 1 and a Test 2:
If nothing is added into the Who Can Use? column, the link should show for everyone. Any advice / assistance would be appreciated.
Thanks!