Skip to content

Instantly share code, notes, and snippets.

@JeffAspen
Forked from ericrallen/gist:3220635
Last active August 29, 2015 14:24
Show Gist options
  • Save JeffAspen/c8d7e42e0e8d31603245 to your computer and use it in GitHub Desktop.
Save JeffAspen/c8d7e42e0e8d31603245 to your computer and use it in GitHub Desktop.
//the next few lines strip "or Create an Account" from the log-in menu option
//I usually set the overall navigation to display:none; in my CSS if I know js is enabled
//I use Modernizr and check for the js class on the <html> tag with the style selector for my menu
//like: .js #navigation { display: none; }
//You'll want to add a class or ID to the <div> containing the log-in/log-out link
//usual output (with added ID):
//<li>
// <div id="log_in_options">
// <a onclick="" href="[url]">Sign in</a> or <a onclick="" href="[url]">Create an account</a>
// </div>
//</li>
//adds slashes to string
function addslashes(a) {
a = a.replace(/\\/g, "\\\\");
a = a.replace(/\'/g, "\\'");
a = a.replace(/\"/g, '\\"');
a = a.replace(/\0/g, "\\0");
return a
}
//removes slashes from string
function stripslashes(a) {
a = a.replace(/\\'/g, "'");
a = a.replace(/\\"/g, '"');
a = a.replace(/\\0/g, "\0");
a = a.replace(/\\\\/g, "\\");
return a
}
$(function() {
//get current value
var sign_in_orig = $("#log_in_options").html();
//add slashes because we'll be dealing with HTML elements, too
sign_in_orig = addslashes(sign_in_orig);
//create array by splitting original on spaces
var sign_in_seg = sign_in_orig.split(" ");
//check for the presence of "Sign In or Create an Account" and remove everything after the Sign In link
//if the user is already signed in this link will only say Sign Out, so we can ignore it
if(sign_in_seg.length > 3) {
var sign_in_new = stripslashes(sign_in_seg[0]) + ' ' + stripslashes(sign_in_seg[1]) + stripslashes(sign_in_seg[2]) + ' ' + stripslashes(sign_in_seg[3]);
$("#log_in_options").html(sign_in_new);
}
//show the navigation after the Log In stripping has finished
$("#navigation").show();
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment