IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » ritcheyer's snipts » javascript The latest javascript snipts from ritcheyer.

showing 1-4 of 4 snipts for javascript
  • Clear Input Using Prototype, Part II
    <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" charset="utf-8">
    	document.observe('dom:loaded', function() {
    
    		// Get all input elements with input class;
    		var blurElements = $$('input.input');
    
    		// Create global scope for storing default values;
    		var scope = {};
    
    		// Iterate through all targeted elements;
    		for (var idx = 0, len = blurElements.length; idx < len; idx++) {
    			var el = blurElements[idx];
    			scope[el.identify()] = el.value;
    			el.observe('blur', function(event) {
    				var e = event.element();
    				var defaultValue = this[e.identify()];
    				if(e.value == '' || e.value == defaultValue) {
    					e.value = defaultValue;
    				}
    			}.bindAsEventListener(scope));
    
    			el.observe('focus', function(event) {
    				var e = event.element();
    				if (e.value == this[e.identify()]) {
    					e.clear();
    				}
    			}.bindAsEventListener(scope));
    		}
    	});
    </script>
    

    copy | embed

    0 comments - tagged in  posted by ritcheyer on Dec 28, 2009 at 6:35 p.m. EST
  • Clear Input using Prototype
    <script type="text/javascript" charset="utf-8">
    	/* -------------------------------------------------------------------------------
    	As it turns out, this way isn't as efficient as initially thought. Yes, the code
    	is small and light (not as light as jQuery, but that's another topic entirely. As
    	I understand it, the 'click' and 'blur' will always fire regardless of where you
    	click on the page. If you are concerned about how many times users click on your
    	page, I suggest looking at Part II:
    	http://snipt.net/ritcheyer/clear-input-using-prototype-part-ii
    	------------------------------------------------------------------------------ */
    
    	document.observe('click',function(event) {
    		var e = event.element();
    		var defaultValue = e.value;
    		if(e.match('input[class="input"]')) {
    
    			// -- clear input field
    			e.clear();
    
    		}
    	
    		// -- if input looses focus replace value
    		e.observe('blur', function() {
    			if(e.value == '' || e.value == defaultValue) {
    				e.value = defaultValue;
    			}
    		});
    	});
    </script>
    

    copy | embed

    0 comments - tagged in  posted by ritcheyer on Dec 28, 2009 at 6:04 p.m. EST
  • stupid little script to compile a simple coffee order
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html>
    	<head>
    		<title>do you need coffee this morning?</title>
    		<script type="text/javascript" charset="utf-8">
    			// if person is tired and coffee is a pick me up
    			// ask how many lumps of sugar
    			// ask how much creamer
    			// provide coffee plus creamer
    			var sugar,sugarAmt,creamer,creamerAmt;
    
    
    			// ask for how much sugar
    			function askForSugar(){
    				sugar = prompt('How much sugar would you like to put in your cup \'o joe?');
    				sugarConfirm(sugar);
    			}
    			
    			// confirm sugar amount
    			function sugarConfirm(amount) {
    				var confirmIt = confirm('You entered ' + amount + ' lumps. is that correct?');
    				if(confirmIt) {
    					sugarAmt = amount;
    					return sugarAmt;
    				} else {
    					askForSugar();
    				}
    			}
    			
    			// ask for how much creamer
    			function askForCreamer(){
    				creamer = prompt('Awesome. Now that we have your sugar, we need to know how much creamer you want?');
    				creamerConfirm(creamer);
    			}
    
    			// confirm creamer amount
    			function creamerConfirm(amount) {
    				var confirmIt = confirm('You entered ' + amount + ' creamer. is that correct?');
    				if(confirmIt) {
    					creamerAmt = amount;
    					return creamerAmt;
    				} else {
    					askForCreamer();
    				}
    			}
    			
    			// return order
    			function yourOrder(sugar,creamer) {
    				alert('Schweet. Now we\'ve got both your cream and sugar levels. :c) Time to brew up some joe.');
    				document.write("So far, we've recieved an order for a coffee with " + sugar + " lumps of sugar and " + creamer + " creamers.\n\nIf this order is incorrect, we want to help you wake up, so... let's <a href=\"orderCoffee.html\">start over</a>.. :)");
    			}
    			
    			askForSugar();
    			if(sugarAmt) {
    				askForCreamer();
    				if(sugarAmt && creamerAmt) {
    					yourOrder(sugarAmt,creamerAmt)
    				}
    			}
    		</script>
    	</head>
    	<body>
    	</body>
    </html>
    

    copy | embed

    0 comments - tagged in  posted by ritcheyer on Sep 04, 2009 at 12:57 p.m. EDT
  • using javascript to emulate target="_blank"
    (function ($) {
    	function handleExternalLink (e) {
    		var t	= e.target;
    		// the target may not be an 'a' tag, so we climb the dom to find a link
    		while (t && t.tagName.toLowerCase() !== 'a') {
    			t = t.parentNode;
    		}
    		// no target?, target doesn't have a 'ext' class?, or 'external' role set?
    		if (!t ||
    			!($(t).hasClass('ext') ||
    			$(t).attr('rel').indexOf('external'))
    		) {
    			return;
    		}
    
    		if (!$.browser.msie) {
    			// If this isn't IE 6, use native browser functionality
    			$(t).attr('target', '_blank');
    		} else {
    			// otherwise, do it for 'em
    			window.open( t.href, (new Date()).getTime(), [
    			// array joining is faster than string concatenation
    				['height=', document.body.clientHeight].join(''),
    				['width=', document.body.clientWidth].join(''),
    				'top=0',
    				'left=0',
    				'scollbars=yes',
    				'resizeable=yes',
    				'status=yes',
    				'titlebar=yes',
    				'toolbar=yes'
    			].join(',') );
    			e.preventDefault();
    		}
    	}
    	// We watch the document container for click events
    	// Our function above will handle those clicks
    	$('#content-contain').click( handleExternalLink );
    
    }(jQuery))
    

    copy | embed

    0 comments - tagged in  posted by ritcheyer on Sep 04, 2009 at 12:56 p.m. EDT
Sign up to create your own snipts, or login.