Skip to content

Instantly share code, notes, and snippets.

View ChrisMBarr's full-sized avatar
👨‍💻

Chris Barr ChrisMBarr

👨‍💻
View GitHub Profile
@ChrisMBarr
ChrisMBarr / RemoveGroovesharkAds.js
Created December 3, 2010 16:54
Add this code as the URL of a new browser bookmark and it removes the extra space taken by the ads
javascript:function r(){$("#page_content,#page_wrapper").width($("#page_wrapper").width()+$("#capital").width());$("#application").css("margin-right",0); $("#capital").remove();return false;} r();void(0);
@ChrisMBarr
ChrisMBarr / UpdatePanelLoaders.js
Created May 19, 2011 06:08
Add loading overlays to ASP.NET WebForms UpdatePanels
$(function(){
//Get all the update panel requests
var requests = Sys.WebForms.PageRequestManager.getInstance();
//When an update panel begins to update
requests.add_beginRequest(ShowPageLoader);
//When an update panel completes loading
requests.add_endRequest(HidePageLoader);
};
@ChrisMBarr
ChrisMBarr / equalHeight.js
Created May 25, 2011 22:04
Match the height of any number of elements.
(function($){
$.fn.equalHeight = function(ignorePadding) {
//Matches the height of all the passed in items
if(this.length){
var tallest = 0;
var tallestPadding = 0;
var paddings=[];
//loop through the items, save the paddings for each and get the tallest height
this.each(function(i) {
@ChrisMBarr
ChrisMBarr / ZoomDetect.htm
Created July 1, 2011 20:10
Detects if the browser zoom is set to the default or not. (Not working for Opera, Firefox 3.6, and anything below Firefox 3.5)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Calculating zoom using Javascript</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script>
function hasPageBeenResized() {
var isResized;
@ChrisMBarr
ChrisMBarr / includeCSS.js
Last active September 26, 2015 12:47
Add a CSS stylesheet to the head of a document
$.extend({
includeCss: function(cssLink, isPrint, callbackFn) {
var $head = $("head");
//Make sure it's a valid string and not already included in the head
if (typeof cssLink === "string" && cssLink.length > 1 && $head.find("link[href='" + cssLink + "']").length <= 0) {
//Create a new link element
var $newLinkTag;
var mediaType = (isPrint) ? 'print' : 'all';
//Needed for IE8 and lower
@ChrisMBarr
ChrisMBarr / ESPN Score Numbers
Created December 8, 2011 23:18
Get all the score numbers from ESPN and sort them
var scores=[];
jQuery(".scores").each(function(i){
jQuery.each(jQuery(this).text().split("-"), function(key,value){
scores.push(parseInt(value));
})
});
console.log(scores.sort(function(a,b){return a-b;}));
@ChrisMBarr
ChrisMBarr / gist:3230548
Created August 1, 2012 20:42
Total up the cost of all items in an Amazon wishlist
var list = $$("#item-page-wrapper .list-items table tbody .lineItemMainInfo .lineItemPart strong");
var total=0;
for(i=0; i<list.length;i++){
total += parseFloat(list[i].innerText.replace("$",""));
}
alert(list.length+" items for a total of: $"+total.toFixed(2));
@ChrisMBarr
ChrisMBarr / isTouchDevice.js
Created November 18, 2012 21:06
Detect Touch Support
function isTouchDevice(){
try{
document.createEvent("TouchEvent");
return true;
}catch(e){
return false;
}
}
@ChrisMBarr
ChrisMBarr / basic-mission-clock.js
Created March 3, 2013 20:44
Mission Clock Code Samples
(function(){
//Numbers
var num = 0;
var perMinute = 75;
var perSecond = perMinute / 60;
//Element selection
var count = document.getElementById("count");
function update(){
@ChrisMBarr
ChrisMBarr / 1-header.php
Last active December 15, 2015 05:39
Wordpress Menu Navigation
<nav class="container_12">
<?php
//Counter
$i=0;
//An array that will eventually contain the correct top-level navigation items in it
$menu_arr = array();
//Loop though all the nav items in Wordpress
foreach ( wp_get_nav_menu_items('Nav') as $key => $item ) {