Sign up to create your own snipts, or login.

Public snipts » jquery The latest public jquery snipts.

showing 1-20 of 105 snipts for jquery
  • Manipulación JQuery con etiqueta div
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>
          Efectos de jQuery
        </title>
    <script src="../jquery/jquery.js" type="text/javascript"></script>
    </script>
    <script type="text/javascript">
    	$(document).click(function (){
    		//Aqui asignamos el click al elemento <a>
    		$("a").click(function (){
    			$("div").hide("fast");
    			$("div").show("fast");
    			$("div").slideUp("fast");
    			$("div").slideDown("fast");
    			$("div").fadeOut("fast");
    			$("div").fadeIn("fast");
    			$("div").animate({width:200, height:200}, "fast");
    			$("div").animate({top:60, left:100}, "fast");
    			$("div").animate({width:300, height:300}, "fast");
    			$("div").animate({top:20, left:50}, "fast");
    			$("div").animate({width:100, height:100}, "fast");
    			$("div").animate({top:0, left:0}, "fast");
    			$("div").animate({width:400, height:400}, "fast");
    		});
    	});
    </script>
    
      </head>
      <body>
    	<div style="width:400px;height:400px;background-color:#FC0;position:relative;">
    	    <a href="#" class="algo">Presioname!</a>
    	</div>
      </body>
    </html>
    

    copy | embed

    0 comments - tagged in  posted by rmondragon on Mar 12, 2010 at 12:57 p.m. EST
  • Bind facebox plugin on live()
    $('a[rel*=facebox]').live("mousedown", function() { 
      $(this).facebox(); // this should do, you don't need all links
    });
    

    copy | embed

    0 comments - tagged in  posted by cbeier on Mar 10, 2010 at 7:00 a.m. EST
  • New window jQuery
    $(function(){
        $('a.new-window').click(function(){
            window.open(this.href);
            return false;
        });
    });
    

    copy | embed

    0 comments - tagged in  posted by curosio on Mar 09, 2010 at 5:46 a.m. EST
  • tabs handler
    function initSetTabs() {
        $("#tabs").tabs({
            select: function(e,u){
            }
            
        });
        
    }
    
    function initHandleHash() {
        $(window).bind( 'hashchange', function(){
            var hash = location.hash;
        
            switch (hash) {
                case "":
                $("#tabs").tabs('select', 0);
                break;
                case "#Info":
                $("#tabs").tabs('select', 0);
                break;
                case "#_Details":
                $("#tabs").tabs('select', 1);
                break;
                case "#Documents":
                $("#tabs").tabs('select', 2);
                break;
                case "#Login":
                $("#tabs").tabs('select', 3);
                break;
                case "#Terms":
                $("#tabs").tabs('select', 4);
                break;               
            }
           
        })
      
        $(window).trigger( 'hashchange' );
    
    }
     
     
    // onloads here
    $(function() {
    	
        initSetTab();
        initHandleHash();    
        
     
    });
    

    copy | embed

    0 comments - tagged in  posted by idesignmotion on Mar 08, 2010 at 12:36 p.m. EST
  • textmate
    {    name = 'source.js.jquery.embedded.html';
                begin = '(?:^\s+)?(<)((?i:script))\b(?![^>]*/>)';
                end = '(?<=</(script|SCRIPT))(>)(?:\s*\n)?';
                beginCaptures = {
                    1 = { name = 'punctuation.definition.tag.html'; };
                    2 = { name = 'entity.name.tag.script.html'; };
                };
                endCaptures = { 2 = { name = 'punctuation.definition.tag.html'; }; };
                patterns = (
                    {    include = '#tag-stuff'; },
                    {    begin = '(?<!</(?:script|SCRIPT))(>)';
                        end = '(</)((?i:script))';
                        captures = {
                            1 = { name = 'punctuation.definition.tag.html'; };
                            2 = { name = 'entity.name.tag.script.html'; };
                        };
                        patterns = (
                            {    name = 'comment.line.double-slash.js';
                                match = '(//).*?((?=</script)|$\n?)';
                                captures = { 1 = { name = 'punctuation.definition.comment.js'; }; };
                            },
                            {    name = 'comment.block.js';
                                begin = '/\*';
                                end = '\*/|(?=</script)';
                                captures = { 0 = { name = 'punctuation.definition.comment.js'; }; };
                            },
                            {    include = '#php'; },
                            {    include = 'source.js'; },
                        );
                    },
                );
            },
    

    copy | embed

    0 comments - tagged in  posted by jsveron23 on Mar 06, 2010 at 2:08 a.m. EST
  • instant upgrade
    if (window['jQuery'] == undefined || window['jQuery']().jquery.match('1.2') || window['jQuery']().jquery.match('1.3') ) {
        scriptFile=document.createElement("SCRIPT");
        scriptFile.src="http://code.jquery.com/jquery-latest.pack.js"; //Upgrade a brotha
        document.getElementsByTagName("HEAD")[0].appendChild(scriptFile);
        }
    

    copy | embed

    1 comment - tagged in  posted by idesignmotion on Mar 05, 2010 at 3:26 p.m. EST
  • Light (4kb mini-jQuery)
    (function () {
    /**
     * Light
     *
     * This is an extreme small and easy JavaScript library. It can 
     * be used for small websites which won't be needing all the 
     * functionality of the bigger libraries around. Or use it to 
     * learn how to create your own library or framework.
     *
     * @author    Victor Villaverde Laan <info@freelancephp.net>
     * @link      http://www.freelancephp.net/light-4kb-min-jquery-light/
     * @license   Dual licensed under the MIT and GPL licenses
     */
    
    /**
     * Light function
     */
    window.Light = function ( selector, parent ) {
    	return new Light.core.init( selector, parent );
    };
    
    // if global $ is not set
    if ( ! window.$ )
    	window.$ = window.Light;
    
    /**
     * Light.core
     * Contains the core functions
     */
    Light.core = Light.prototype = {
    
    	// init function, set selected elements
    	init: function ( selector, parent ) {
    		var els;
    
    		selector = selector || window; // default is window
    		parent = parent || document; // default is document
    
    		els = ( typeof selector == 'string' )
    			? Light.selector( selector, parent ) // use selector method
    			: els = selector;
    
    		// reset elements
    		this.els = [];
    
    		if ( typeof els.length != 'undefined' ) {
    			// els is an array or object
    			for (var i = 0, max = els.length; i < max; i++)
    				this.els.push(els[i]);
    		} else {
    			// els is an element
    			this.els.push( els );
    		}
    
    		return this;
    	},
    
    	// get the element of given index (return all elements when no index given)
    	get: function ( index ) {
    		return ( typeof index == 'undefined' ) 
    				? this.els
    				: this.els[index];
    	},
    
    	// get number of selected elements
    	count: function () {
    		return this.els.length;
    	},
    
    	// set function to be run for each selected element
    	each: function ( fn ) {
    		for ( var x = 0, max = this.els.length; x < max; x++ )
    			fn.call( this, this.els[x] );
    
    		return this;
    	},
    
    	// set attribute value
    	attr: function ( name, value, type ) {
    		this.each(function( el ) {
    			if ( typeof type == 'undefined' ) {
    				el[name] = value;
    			} else {
    				el[type][name] = value;
    			}
    		});
    
    		return this;
    	},
    
    	// set styles
    	css: function ( styles ) {
    		var that = this;
    		this.each(function( el ) {
    			for ( var name in styles )
    				that.attr( name, styles[name], 'style' );
    		});
    
    		return this;
    	},
    
    	// add given className
    	addClass: function ( className ) {
    		this.each(function ( el ) {
    			el.className += ' ' + className;
    		});
    
    		return this;
    	},
    
    	// remove given className
    	removeClass: function ( className ) {
    		this.each(function ( el ) {
    			el.className = el.className.replace( className, '' );
    		});
    
    		return this;
    	},
    
    	// add event action
    	on: function ( event, fn ) {
    		var addEvent = function( el ) {
    			if ( window.addEventListener ) {
    				el.addEventListener( event, fn, false );
    			} else if ( window.attachEvent ) {
    				el.attachEvent( 'on'+ event, function() {
    					fn.call( el, window.event );
    				});
    			}
    		};
    
    		this.each(function( el ) {
    			addEvent( el );
    		});
    
    		return this;
    	},
    
    	// add function to be executed when the DOM is ready
    	ready: function ( fn ) {
    		DOMReady.add( fn );
    
    		return this;
    	},
    
    	// remove selected elements from the DOM
    	remove: function () {
    		this.each(function( el ) {
    			el.parentNode.removeChild( el );
    		});
    
    		return this;
    	}
    
    };
    
    // Selector, default support:
    // $('#id')        - get element by id
    // $('.className') - get element(s) by class-name
    // $('tagName')    - get element(s) by tag-name
    Light.selector = function ( selector, context ) {
    	var sels =  selector.split( ',' ),
    		el, op, s;
    
    	for ( var x = 0; x < sels.length; x++ ) {
    		// trim spaces
    		var sel = sels[x].replace(/ /g, '');
    
    		if ( typeof sel == 'string' ) {
    			op = sel.substr( 0, 1 ); // operator
    			s = sel.substr( 1 ); // name without operator
    			if ( op == '#' ) {
    				el = document.getElementById( s );
    				el = ( isDescendant( el, context ) ) ? el : null;
    			} else if ( op == '.' ) {
    				el = getElementsByClassName(s, context);
    			} else {
    				el = context.getElementsByTagName(sel);
    			}
    		}
    	}
    
    	return el;
    };
    
    // init gets core prototype
    Light.core.init.prototype = Light.core;
    
    
    /**
     * Helpers
     */
    
    // DOMReady, add functions to be executed when the DOM is ready
    var DOMReady = (function () {
    	var fns = [],
    		isReady = false,
    		ready = function () {
    			isReady = true;
    
    			// call all functions
    			for ( var x = 0; x < fns.length; x++ )
    				fns[x].call();
    		};
    
    	// public add method
    	this.add = function ( fn ) {
    		// eval string in a function
    		if ( fn.constructor == String ) {
    			var strFunc = fn;
    			fn = function () { eval( strFunc ); };
    		}
    
    		// call imediately when DOM is already ready
    		if ( isReady ) {
    			fn.call();
    		} else {
    			// add to the list
    			fns[fns.length] = fn;
    		}
    	};
    
    	// For all browsers except IE
    	if ( window.addEventListener )
    		document.addEventListener( 'DOMContentLoaded', function(){ ready(); }, false );
    
    	// For IE
    	// Code taken from http://ajaxian.com/archives/iecontentloaded-yet-another-domcontentloaded
    	(function(){
    		// check IE's proprietary DOM members
    		if ( ! document.uniqueID && document.expando ) return;
    
    		// you can create any tagName, even customTag like <document :ready />
    		var tempNode = document.createElement('document:ready');
    
    		try {
    			// see if it throws errors until after ondocumentready
    			tempNode.doScroll('left');
    
    			// call ready
    			ready();
    		} catch ( err ) {
    			setTimeout(arguments.callee, 0);
    		}
    	})();
    
    	return this;
    })();
    
    // create a static reference
    Light.ready = DOMReady.add;
    
    // Check wether an element is a descendant of the given ancestor
    function isDescendant( desc, anc ){
    	return ( ( desc.parentNode == anc ) || ( desc.parentNode != document ) && isDescendant( desc.parentNode, anc ) );
    };
    
    // Cross browser function for getting elements by className
    function getElementsByClassName( className, parent ) {
    	var a = [],
    		re = new RegExp('\\b' + className + '\\b'),
    		els = parent.getElementsByTagName( '*' );
    
    	parent = parent || document.getElementsByTagName( 'body' )[0];
    
    	for ( var i = 0, j = els.length; i < j; i++ )
    		if ( re.test( els[i].className ) )
    			a.push( els[i] );
    
    	return a;
    };
    
    })();
    

    copy | embed

    0 comments - tagged in  posted by freelancephp on Mar 01, 2010 at 6:41 p.m. EST
  • Some JS for Flot with some Rails to flavor
    /* Generate Graph of Weights for <%= @user.name %> as provided in @DataSet */
    var underweight = $("#bmi_underweight").css("background-color");
    var normalweight =  $("#bmi_normalweight").css("background-color");
    var overweight =  $("#bmi_overweight").css("background-color");
    var obese =  $("#bmi_obese").css("background-color");
    
    
    $.plot($("#weight_chart"),[{label: "Weight", data:<%= @DataSet.to_json %>}],
        {
          series: {
            color: "#000000",
            lines: {
              show: true,
              fill: false,
              lineWidth: 5
              },
            shadowSize: 10,
            points: { show: true }
          },
          grid: {
            hoverable: true, clickable: true ,
            backgroundColor: { colors: ["#fff", "#eee"] },
            markings: [
              { yaxis: { <%= @bmi_ranges["underweight"] %>}, color:underweight },
              { yaxis: {  <%= @bmi_ranges["normal"] %> }, color:normalweight },
              { yaxis: {  <%= @bmi_ranges["overweight"] %> }, color:overweight },
              { yaxis: {  <%= @bmi_ranges["obese"] %> }, color:obese }
              ]
          },
          xaxis: {
            mode: "time",
            timeformat: "%b %d, %y"
          }
      });
    

    copy | embed

    0 comments - tagged in  posted by lear64 on Feb 23, 2010 at 11:00 a.m. EST
  • jQuery Lint
    <script src="http://github.com/jamespadolsey/jQuery-Lint/raw/master/jquery.lint.js"></script>
    

    copy | embed

    0 comments - tagged in  posted by frontendcoder on Feb 17, 2010 at 2:50 p.m. EST
  • hide or close div with jq_link_to_remote, jquery, jq_visual_effect
    <div id="feedback" class="hide">feedback: </div>
    <?php echo jq_link_to_function('show secret div','$("#feedback").removeClass("hide")') ?>
    <?php echo jq_link_to_function('hide secret div','$("#feedback").addClass("hide")') ?>
    <?php echo jq_link_to_function('show secret div with effect',jq_visual_effect('fadeIn', '#feedback'),) ?>
    <?php echo jq_link_to_function('show secret div with effect',jq_visual_effect('fadeOut', '#feedback'),) ?>
    <?php echo jq_link_to_function('show secret div with effect','$("#feedback").fadeIn(1000)') ?>
    
    <?php echo jq_link_to_function('show secret div with effect','$("#feedback").fadeOut(1000)') ?>
    
    
    <?php echo jq_link_to_function('show secret div with effect',jq_visual_effect('slideDown', '#feedback'),) ?>
    
    <?php echo jq_link_to_function('hide secret div with effect',jq_visual_effect('slideUp', '#feedback'),) ?>
    

    copy | embed

    0 comments - tagged in  posted by toledot on Feb 13, 2010 at 2:07 p.m. EST
  • Get client IP through jquery
    $.getJSON("http://jsonip.appspot.com?callback=?",function(data){
        alert( "Your ip: " + data.ip);
    });
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Feb 10, 2010 at 11:31 p.m. EST
  • Definition List Toggler
    ;(function($) {
    	$.fn.dlToggle = function(settings) {
    		var opt = $.extend({}, $.fn.dlToggle.default, settings);
    
    		return this.each(function() {
    			var $dl = $(this);
    			if(!$dl.is('dl')) return;
    			$dt = $dl.find('dt')
    			$dt.css('cursor', 'pointer')
    			.each(function(){
    				var height,
    				$dt = $(this),
    				$dd = $dt.next();
    				if($dd.is('dd')) {
    					height = $dd.height();
    					$dd.hide().css({height : 0});
    				}
    				$dt.click(function(){
    					if($dd.is(':visible')) {
    						$dd.animate({height : 0}, {duration : opt.hideSpeed, easing : opt.hideEasing, complete: function(){
    							$dd.hide();
    						}})
    					} else {
    						if(opt.toggleAll) {
    							$dl.find('dd:visible').animate({height : 0}, {duration : opt.hideSpeed, easing : opt.hideEasing, complete: function(){
    								$(this).hide();
    							}})
    						};
    						$dd.show().animate({height : height}, {duration : opt.showSpeed, easing : opt.showEasing})
    					}
    				})
    			});
    		})
    	}
    
    	$.fn.dlToggle.default = {
    		showSpeed: 200,
    		hideSpeed: 200,
    		toggleAll: true,
    		showEasing: 'jswing',
    		hideEasing: 'jswing'
    	}
    })(jQuery);
    

    copy | embed

    0 comments - tagged in  posted by frontendcoder on Feb 10, 2010 at 4:51 p.m. EST
  • Add jQuery
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
    <script>
    
    </script>
    

    copy | embed

    0 comments - tagged in  posted by frontendcoder on Feb 10, 2010 at 4:42 p.m. EST
  • jquery plugin template
    ;(function($) {
    	$.fn.pluginName = function(settings) {
    		var o = $.extend({}, $.fn.pluginName.defaults, settings);
    
    		return this.each(function() {
    			var element = $(this);
    			//	Stick your functionality here, yo..
    		})
    	}
    
    	$.fn.pluginName.defaults = {}
    })(jQuery);
    

    copy | embed

    0 comments - tagged in  posted by frontendcoder on Feb 10, 2010 at 4:40 p.m. EST
  • ReplaceWith extended
    jQuery.fn.replaceWith2 = function(replacement) {
        return this.each (function() {
            element = $(this);
            $(this).after(replacement).next().html(element.html());
            for (var i = 0; i < this.attributes.length; i++) {
                element.next().attr(this.attributes[i].nodeName, this.attributes[i].nodeValue);
            }
            element.remove();
        });
    }
    

    copy | embed

    0 comments - tagged in  posted by CorPao on Feb 03, 2010 at 7:59 a.m. EST
  • Datepicker Generators
    /**
    	@Author: Matthew R Bungard (mrb3@uakron.edu)
    	@Date: 2010-02-01
    	Matt was generating date input fields on the fly, this handle datepicking for each of those fields
    */
    
    $(function()
    {
    	$('input').filter('.datefield').each(function(index)
    	{
    		$(this).attr("id","datepicker_" + index);
    		$(this).datepicker(
    		{
    			changeMonth: true,
    			changeYear: true,
    			showOn: 'button',
    			buttonImage: '/images/sm_calendar.png',
    			buttonImageOnly: true
    		});
    	});
    });
    

    copy | embed

    0 comments - tagged in  posted by fusion27 on Feb 02, 2010 at 7:04 a.m. EST
  • instant jquery 1.4
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function() {
        // Let the good times roll.
      });
    </script>
    

    copy | embed

    0 comments - tagged in  posted by idesignmotion on Jan 24, 2010 at 12:51 p.m. EST
  • jQuery Bookmarklet
    // jQuery Bookmarklet
    
    // References:
    // http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet
    // http://coder-zone.blogspot.com/2009/05/jquery-bookmarklet.html
    
    // Encapsulation
    (function() {
    	var debug = true && typeof window.console!='undefined';
    
    	// Loads a external javascript (based on jQuery getScript)
    	function getScript(url, success) {
    		var script = document.createElement('script');
    		script.src = url;
    
    		var head=document.getElementsByTagName('head')[0];
    		var done = false;
    
    		// Attach handlers for all browsers
    		script.onload = script.onreadystatechange = function() {
    			if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') ) {
    				done=true;
    				success();
    			}
    		};
    		head.appendChild(script);
    	}
    
    	// Extra functionality after load jQuery
    	function run() {
    		// WRITE YOUR CODE HERE
    	}
    
    	// Loads jQuery from an external source and run extra functionality
    	if(typeof window.jQuery != 'undefined') {
    		if (debug) console.log('jQuery already loaded: ' + jQuery.fn.jquery);
    		run();
    	} else {
    		getScript('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', function() {
    			if (typeof window.jQuery=='undefined') {
    				if (debug) console.log('jQuery not loaded. Script stopped'); 
    			} else {
    				if (debug) console.log('jQuery loaded: ' + jQuery.fn.jquery);
    				run();
    			}
    		});
    	}
    })();
    

    copy | embed

    0 comments - tagged in  posted by aanton on Jan 20, 2010 at 4:04 p.m. EST
  • slugify javascript
    function URLify(s, maxChars) {
    
    	if(maxChars === undefined) max_chars = 100;
    
        removelist = ["a", "an", "as", "at", "before", "but", "by", "for", "from",
                      "is", "in", "into", "like", "of", "off", "on", "onto", "per",
                      "since", "than", "the", "this", "that", "to", "up", "via",
                      "with"];
        
    	r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi');
        s = s.replace(r, '');
    	
        s = s.replace(/[^-\w\s]/g, '');  // remove unneeded chars
        s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces
        s = s.replace(/[-\s]+/g, '-');   // convert spaces to hyphens
        s = s.toLowerCase();             // convert to lowercase
        return s.substring(0, maxChars);// trim to first num_chars chars
    }
    
    // jQuery
    $(document).ready(function(){
    	$('#title').keyup(function(){
    
    		$('#slug').val(URLify($(this).val()));
    		
    	});
    
    // Mootools
    window.addEvent('load', function(){
    	$('title').addEvent('keyup', function(){
    		$('slug').set('value', URLify($(this).get('value')));
    	});
    });
    });*/
    

    copy | embed

    0 comments - tagged in  posted by jpartogi on Dec 23, 2009 at 4:17 a.m. EST
  • jQuery HTML template
    <!DOCTYPE html>
    
    <html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>Lektion 7</title>
        <link rel="stylesheet" type="text/css" href="style.css" />
        
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
        
        <script type="text/javascript">
                $(document).ready(function(){
                
                
                });
                
        </script>
    </head>
    
    <body>
        <h1 id="ueberschrift"></h1>    
    </body>
    </html>
    

    copy | embed

    0 comments - tagged in  posted by lenni on Dec 15, 2009 at 6:21 a.m. EST
Sign up to create your own snipts, or login.