Skip to content

Instantly share code, notes, and snippets.

@digitup
digitup / GetURLParameters.js
Created February 25, 2013 12:33
JavaScript - Get URL Parameters
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
@digitup
digitup / windowWidth.html
Last active December 10, 2015 02:29
jQuery - windowWidth
<script>
$(window).resize(function() {
var windowWidth = $(window).width();
$('.screen-width').text(windowWidth + 'px');
});
</script>
<div id="debug" style="position:fixed;padding:0.3em 0.6em;background:#f1f1f1;font-size:0.6em;bottom:0;left:50%;">
<span class="screen-width">0</span>
</div>
@digitup
digitup / jquery-onChange.js
Created December 19, 2012 08:36
jQuery - onChange
$(function(){
// bind change event to select
$('.countrySiteDropdown').bind('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
@digitup
digitup / Switch.Statement.js
Created November 19, 2012 09:58
JavaScript - Switch statement
var jsLang = 'jquery';
switch (jsLang) {
    case 'jquery':
        alert('jQuery Wins!');
        break;
    case 'prototype':
        alert('prototype Wins!');
        break;
    case 'mootools':
        alert('mootools Wins!');
@digitup
digitup / bootsrtap.sticky.navbar.html
Created November 11, 2012 10:07
Bootstrap - Sticky navigation bar
<h1>Lorem ipsum</h1>
<br>
<div class="subnav navbar">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li><a href="#one">One</a></li>
<li><a href="#two">Two</a></li>
<li><a href="#three">Three</a></li>
<li><a href="#four">Four</a></li>
@digitup
digitup / jQuery.HTML.lang.param.js
Created November 9, 2012 15:25
jQuery - Get the HTML lang param
$('html')[0].lang
alert($('html').attr('lang'));
@digitup
digitup / Fetch.sublime-settings
Created November 7, 2012 16:16 — forked from dustinhorton/Fetch.sublime-settings
Sublime - fetch settings for sublime text 2
{
"files":
{
"jquery" : "http://code.jquery.com/jquery.min.js",
"jquery-ui-effects" : "https://raw.github.com/jquery/jquery-ui/master/ui/jquery.effects.core.js",
"jquery-mobile-vmouse" : "https://raw.github.com/jquery/jquery-mobile/master/js/jquery.mobile.vmouse.js",
"jquery-flexslider" : "https://raw.github.com/mbmufffin/FlexSlider/master/jquery.flexslider-min.js",
"jquery-mediaelement" : "https://raw.github.com/johndyer/mediaelement/master/build/mediaelement-and-player.js",
"jquery-url" : "https://raw.github.com/allmarkedup/jQuery-URL-Parser/master/jquery.url.js",
"jquery-dotimeout" : "https://raw.github.com/cowboy/jquery-dotimeout/master/jquery.ba-dotimeout.min.js",
@digitup
digitup / Fetch.sublime-settings
Created November 7, 2012 16:17
sublime: fetch settings for sublime text 2
{
"files":
{
"jquery": "http://code.jquery.com/jquery.min.js",
"jquery-dotimeout": "https://raw.github.com/cowboy/jquery-dotimeout/master/jquery.ba-dotimeout.min.js",
"jquery-extra-selectors": "https://raw.github.com/keithclark/JQuery-Extended-Selectors/master/jquery-extra-selectors.js",
"jquery-flexslider": "https://raw.github.com/mbmufffin/FlexSlider/master/jquery.flexslider-min.js",
"jquery-mediaelement": "https://raw.github.com/johndyer/mediaelement/master/build/mediaelement-and-player.js",
"jquery-mobile-vmouse": "https://raw.github.com/jquery/jquery-mobile/master/js/jquery.mobile.vmouse.js",
"jquery-mousewheel": "https://raw.github.com/brandonaaron/jquery-mousewheel/master/jquery.mousewheel.js",
@digitup
digitup / jQuery.fixed.menu.after.scroll.js
Created November 3, 2012 19:35
jQuery - Fixed menu after scrolling
$(window).scroll(function () {
if (!docked && (menu.offsetTop - scrollTop() < 0)) {
menu.style.top = 0;
menu.style.position = 'fixed';
menu.className = 'docked';
docked = true;
} else if (docked && scrollTop() <= init) {
menu.style.position = 'absolute';
menu.style.top = init + 'px';
menu.className = menu.className.replace('docked', '');
@digitup
digitup / add.active.class.js
Created November 2, 2012 10:25
jQuery - add an active class to the current URL
var url = document.URL;
$('#menu a[href="'+url+'"]').addClass('active');