Latest 100 public
snipts » js
showing 1-20 of 73 snipts for js
-
∞ JS: onfocus and onblur
$("#email").focus(function() { if ($(this).val() == $(this).attr('rel')) $(this).val(''); }); $("#email").blur(function() { if ($(this).val() == '') $(this).val($(this).attr("rel")); });
-
∞ JS: onload fix for resetting when back button is used
<script> // reset fix for selectbox when the back button is used // place this code in the body, not the head. window.onload = function(){ $('#selectbox1').val(''); $('#selectobx2').val(''); }; </script>
-
∞ jquery external liks
<!--JQUERY LINKS--> <!--LATEST FROM JQUERY--> <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script> <!--VERSION 1.4.2 FROM GOOGLE--> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <!--LATEST VERSION 1.X.X FROM GOOGLE--> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script> <!--This is the official jQuery Tools UI library and after the inclusion you will have the following tools available: jQuery 1.4.2 Tabs Tooltip Scrollable Overlay--> <script src="http://cdn.jquerytools.org/1.2.3/jquery.tools.min.js"></script>
-
∞ javascript back
<a href="javascript:history.back()">Back</a>
-
∞ alternate way to deal with hiding modal boxes when clicking anywhere outside
// attach the general handler for all clicks $(document).bind("click.hidepopups", function(ev){ $(".modal").fadeOut(200, function(){ $(this).remove(); }); }); // set up the trigger to show the modal box/menu $(trigger).click(function(e){ $(document).trigger("click.hidepopups"); // hide existing modals var div = $("<div class=\"box modal\">This is a box</div>"); div.bind('click', function(ev){ ev.stopPropagation(); }); $(document.body).append(div.fadeIn(200)); // make new modal e.stopPropagation(); });
-
∞ pseudo-code to handle ignoring JS modal boxes by clicking outside the box
/* trigger: whatever triggers the modal box * modalBoxTopmostWrapper: the root wrapper of the modal box */ $(trigger).click(function(event){ /* show modal box */ $(document).bind("click.confirmation", function(e){ if( $(e.target).parents(modalBoxTopmostWrapper).length ) // stop if clicking the confirmation box return; /* close modal box */ $(document).unbind("click.confirmation"); }); event.stopPropagation(); // to prevent click.confirmation from firing immediately });
-
∞ JS: prepend ajax text to url
function addAjax(origHref) { //var origHref = $('.add-student').attr('href'); var urlArray = origHref.split(/[\/]/); if (urlArray.length > 1) { var filename = urlArray.pop(); // if there's a trailing slash, get the next iteration if (filename.length < 1) filename = urlArray.pop(); filename = "/ajax-" + filename; return urlArray.join("/") + filename; } return origHref; }
-
∞ js
$('#numberedNutmeg').addAnnotations(function(annotation){ return $(document.createElement('span')). addClass('black circle note').html(annotation.position); },[ {x: 0.3875, y: 0.3246, position: 4}, {x: 0.57, y: 0.329, position: 2} ] );
-
∞ Asyhcronous Google Analytics Code
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXX-X']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga); })(); </script>
-
∞ companion cube
$('#emergencyIntelligenceIncinerator').bind('textchange', function () { if ($(this).val().indexOf('companion cube') !== -1) { $('#continue').removeClass('disabled').attr('disabled', false); } });
-
∞ AJAX save
var timeout; $('#ajaxSave').bind('textchange', function () { clearTimeout(timeout); $('#ajaxFired').html('<strong>Typing...</strong>'); var self = this; timeout = setTimeout(function () { $('#ajaxFired').html('<strong>Saved</strong>: ' + $(self).val()); }, 1000); });
-
∞ twitter text change
$('#twitter').bind('textchange', function (event, previousText) { $('#charactersLeft').html( 140 - parseInt($(this).val().length) ); });
-
∞ exhibitb
$('#exhibitb').bind('textchange', function (event, previousText) { $('#output').append('<p>Text changed from <strong>' + previousText + '</strong> to <strong>' + $(this).val() + '</strong> </p>'); });
-
∞ textchange link
<script src="/javascripts/plugins/jquery.textchange.js"></script>
-
∞ exhibita
$('#exhibita').bind('hastext', function () { $('#exhibitaButton').removeClass('disabled').attr('disabled', false); }); $('#exhibita').bind('notext', function () { $('#exhibitaButton').addClass('disabled').attr('disabled', true); });
-
∞ Highlight all div elements on page
javascript:var%20eL=document.getElementsByTagName('div');for(i=0;i%3CeL.length;i++)%7Bvoid(eL%5Bi%5D.style.border='solid%201px%20red')%7D
-
∞ Toggle all checkboxes on page
javascript:var%20fR=document.getElementsByTagName('frame');if(fR.length%3E0)for(f=0;f%3CfR.length;f++)%7Bvar%20eL=top.frames%5Bf%5D.document.getElementsByTagName('input');for(i=0;i%3CeL.length;i++)%7Bif(eL%5Bi%5D.checked==false)void(eL%5Bi%5D.checked=true);else%7Bvoid(eL%5Bi%5D.checked=false);%7D%7D%7Delse%7Bvar%20eL=document.getElementsByTagName('input');for(i=0;i%3CeL.length;i++)%7Bif(eL%5Bi%5D.checked==false)void(eL%5Bi%5D.checked=true);else%7Bvoid(eL%5Bi%5D.checked=false);%7D%7D%7D
-
∞ fizz buzz
<script type="text/javascript"> $(document).ready(function(){ var i = 1; do { if(i%3 == 0){ $('#container').append("Fizz"); } if(i%5 == 0){ $('#container').append("Buzz"); } $('#container').append(i); i++; } while ( i <= 100); }); </script>
-
∞ include annotate
<script src="/javascripts/plugins/jquery.js"></script> <script src="/javascripts/plugins/jquery.annotate.js"></script>
-
∞ serialize
$('#nutmeg span.note').seralizeAnnotations();


