Skip to content

Instantly share code, notes, and snippets.

View lizardking8610's full-sized avatar

Robert lizardking8610

View GitHub Profile
@lizardking8610
lizardking8610 / linkshighlight.js
Created May 18, 2017 17:04
jQuery: highlight links to current page
$(function(){
$("a").each(function(){
if ($(this).attr("href") == window.location.pathname){
$(this).addClass("selected");
}
});
});
@lizardking8610
lizardking8610 / stickyfooter.css
Created May 18, 2017 17:05
jQuery: sticky footer
#footer { height: 100px; }
@lizardking8610
lizardking8610 / konami.js
Created May 18, 2017 17:07
jQuery: Konami code easter egg
var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
$(document).keydown(function(e) {
kkeys.push( e.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ) {
$(document).unbind('keydown',arguments.callee);
@lizardking8610
lizardking8610 / notpresentLoad.js
Created May 18, 2017 17:09
jQuery: if not present then load jQuery
//using async loading
// Only do anything if jQuery isn't defined
if (typeof jQuery == 'undefined') {
if (typeof $ == 'function') {
// warning, global var
thisPageUsingOtherJSLibrary = true;
}
function getScript(url, success) {
@lizardking8610
lizardking8610 / triggerclick.js
Created May 18, 2017 17:12
jQuery: click trigger on input when label clicked
var labelID;
$('label').click(function() {
labelID = $(this).attr('for');
$('#'+labelID).trigger('click');
});
//All browsers except IE will do this when you code it this way below:
@lizardking8610
lizardking8610 / smoothscroll.js
Created May 18, 2017 17:14
jQuery: smooth scrolling
// Scroll to specific values
// scrollTo is the same
window.scroll({
top: 2500,
left: 0,
behavior: 'smooth'
});
// Scroll certain amounts from current position
window.scrollBy({
@lizardking8610
lizardking8610 / .htaccess
Created May 18, 2017 17:23
HTAccess: 301 redirect
Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/
@lizardking8610
lizardking8610 / onpageload.js
Created May 18, 2017 17:25
jQuery: run javascript only after entire page load
$(window).bind("load", function() {
// code here
});
@lizardking8610
lizardking8610 / partialpagerefresh.js
Created May 18, 2017 17:27
jQuery: partial page refresh
$('#button1').click(function() {
var url = "http:www.your-url.com?ID=" + Math.random(); //create random number
setTimeout(function() {
$("#elementName").load(url+" #elementName>*","");
}, 1000); //wait one second to run function
});
@lizardking8610
lizardking8610 / passwordstrength.js
Created May 18, 2017 17:33
jQuery: password strength for membership sites
$('#pass').keyup(function(e) {
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
if (false == enoughRegex.test($(this).val())) {
$('#passstrength').html('More Characters');
} else if (strongRegex.test($(this).val())) {
$('#passstrength').className = 'ok';
$('#passstrength').html('Strong!');
} else if (mediumRegex.test($(this).val())) {