Skip to content

Instantly share code, notes, and snippets.

View gpassarelli's full-sized avatar

Gabriel Passarelli gpassarelli

View GitHub Profile
@gpassarelli
gpassarelli / gist:2135131
Created March 20, 2012 12:59
jQuery: Display Last Tweet
$.getJSON("http://twitter.com/statuses/user_timeline/username.json?callback=?", function(data) {
$("#twitter").html(data[0].text);
});
@gpassarelli
gpassarelli / gist:2135120
Created March 20, 2012 12:58
jQuery: Plugin Template
(function($){
$.yourPluginName = function(el, radius, options){
// To avoid scope issues, use 'base' instead of 'this'
// to reference this class from internal events and functions.
var base = this;
// Access to jQuery and DOM versions of element
base.$el = $(el);
base.el = el;
@gpassarelli
gpassarelli / gist:2135111
Created March 20, 2012 12:58
jQuery: Equalize Heights of Divs
var maxHeight = 0;
$("div").each(function(){
if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
});
$("div").height(maxHeight);
@gpassarelli
gpassarelli / gist:2135098
Created March 20, 2012 12:57
jQuery: Disable Parent Links in Nested List Navigation
$("#navigation li:has(ul.sub-navigation)").hover(function () {
$(this).children("a").click(function () {
return false;
});
});
@gpassarelli
gpassarelli / gist:2135086
Created March 20, 2012 12:56
jQuery: Cycle Through a List
$(document).ready(function() {
var j = 0;
var delay = 2000; //millisecond delay between cycles
function cycleThru(){
var jmax = $("ul#cyclelist li").length -1;
$("ul#cyclelist li:eq(" + j + ")")
.animate({"opacity" : "1"} ,400)
.animate({"opacity" : "1"}, delay)
.animate({"opacity" : "0"}, 400, function(){
@gpassarelli
gpassarelli / gist:2135071
Created March 20, 2012 12:56
jQuery: Check if Checkbox is Checked
/* Find out if a single checkbox is checked or not, returns true or false:*/
$('#checkBox').attr('checked');
/* Find all checked checkboxes: */
$('input[type=checkbox]:checked');
@gpassarelli
gpassarelli / gist:2134986
Created March 20, 2012 12:50
jQuery: Zebra Stripe a Table
$("table#id tr:odd").addClass("odd");
@gpassarelli
gpassarelli / gist:2134976
Created March 20, 2012 12:49
jQuery: Fire Event When User is Idle
idleTimer = null;
idleState = false;
idleWait = 2000;
(function ($) {
$(document).ready(function () {
$('*').bind('mousemove keydown scroll', function () {
@gpassarelli
gpassarelli / gist:2134970
Created March 20, 2012 12:49
jQuery: Inputs That Remember Original Value
var origValue = [];
$('input.remember').each ( function (currentIndex)
{
origValue.push ( $(this).val () );
$(this).focus ( function ()
{
$(this).removeClass("unfocused");
var defaultText = $(this).val();
if ( $(this).val () == origValue [ currentIndex ] )
{
@gpassarelli
gpassarelli / gist:2134959
Created March 20, 2012 12:49
jQuery: Persistant Headers on Tables
function UpdateTableHeaders() {
$("div.divTableWithFloatingHeader").each(function() {
offset = $(this).offset();
scrollTop = $(window).scrollTop();
if ((scrollTop > offset.top) && (scrollTop < offset.top + $(this).height())) {
$(".tableFloatingHeader", this).css("visibility", "visible");
$(".tableFloatingHeader", this).css("top", Math.min(scrollTop - offset.top, $(this).height() - $(".tableFloatingHeader", this).height()) + "px");
}
else {
$(".tableFloatingHeader", this).css("visibility", "hidden");