<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: auto code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 15:57:22 GMT</pubDate>
    <description>DZone Snippets: auto code</description>
    <item>
      <title>Automatically Create a Page Index</title>
      <link>http://snippets.dzone.com/posts/show/3765</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;First create your HTML.  You can style it however you want but the division names must remain the same.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;div id='indexDiv'&gt;&lt;br /&gt;   &lt;div id='indexContents'&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Next place the following code at the end of your content.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;els=document.getElementsByTagName('h4');&lt;br /&gt;idx='';&lt;br /&gt;for (i=0; i&lt;els.length; i++) {&lt;br /&gt;  idx += '&lt;a href="#quickIDX'+i+'"&gt;'+els[i].innerHTML+'&lt;/a&gt;&lt;BR&gt;';&lt;br /&gt;  els[i].innerHTML='&lt;a name="quickIDX'+i+'"&gt;&lt;/a&gt;'+els[i].innerHTML;&lt;br /&gt;}&lt;br /&gt;if (!els.length) {&lt;br /&gt;  document.getElementById('indexDiv').style.display='none';&lt;br /&gt;} else {&lt;br /&gt;  document.getElementById('indexContents').innerHTML=idx;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Any H4 tag on the page will now be indexed and a link to the element placed in the index the script built.   Place the index anywhere on your page and style it however you wish.</description>
      <pubDate>Thu, 05 Apr 2007 03:19:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3765</guid>
      <author>pcx99 (Patrick)</author>
    </item>
    <item>
      <title>Gmail-Like Incremental Search //JavaScript Class</title>
      <link>http://snippets.dzone.com/posts/show/684</link>
      <description>&lt;a href="http://www.jsfromhell.com/dhtml/incremental-search"&gt;&lt;br /&gt;Implements a GMail-like auto-complete.&lt;br /&gt;&lt;br /&gt;[UPDATED CODE AND HELP CAN BE FOUND HERE]&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;@REQUIRES &lt;a href="http://www.jsfromhell.com/geral/event-listener"&gt;Event-Listener&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//Requires http://www.jsfromhell.com/geral/event-listener&lt;br /&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com/dhtml/incremental-search [v1.0]&lt;br /&gt;&lt;br /&gt;IncrementalSearch = function( input, callback, className ){&lt;br /&gt;	var i, o = ( o = this, o.l = [], o.i = input, o.c = null, o.s = { e: null, i: -1 }, o.f = callback || function(){}, o.n = className || "", o );&lt;br /&gt;	for( i in { keydown: 0, focus: 0, blur: 0, keyup: 0, keypress: 0 } )&lt;br /&gt;		addEventListener( o.i, i, function( e ){ o.handler.call( o, e ); } );&lt;br /&gt;};&lt;br /&gt;with( { p: IncrementalSearch.prototype } ){&lt;br /&gt;	(p.constructor.fadeAway = function( o ){&lt;br /&gt;		o instanceof Object ? ( this.trash = this.trash || [] ).push( o ) &amp;&amp; setTimeout( this.fadeAway, 200 ) : arguments.callee.c.trash.pop().hide();&lt;br /&gt;	}).c = p.constructor;&lt;br /&gt;	p.callEvent = function( e ){ this[e] &amp;&amp; this[e].apply( this, [].slice.call( arguments, 1 ) ); };&lt;br /&gt;	p.highlite = function( e ){ ( this.s.e &amp;&amp; ( this.s.e.className = "normal" ), ( this.s = { e: e, i: e.listindex } ).e.className += " highlited", this.callEvent( "onhighlite", this.l[ this.s.i ], this.s.e.d ) ); };&lt;br /&gt;	p.select = function(){ this.s.i + 1 &amp;&amp; ( this.i.value = this.l[ this.s.i ], this.callEvent( "onselect", this.i.value, this.s.e.d ), this.hide() ); };&lt;br /&gt;	p.hide = function(){ ( this.c &amp;&amp; this.c.parentNode.removeChild( this.c ), this.c = null, this.l = [], this.s = { e: null, i: -1 }, this.callEvent( "onhide" ) ); };&lt;br /&gt;	p.next = function(){ var e = ( e = this.s.e ) ? e.nextSibling || e.parentNode.firstChild : null; e &amp;&amp; this.highlite( e ); };&lt;br /&gt;	p.previous = function(){ var e = ( e = this.s.e ) ? e.previousSibling || e.parentNode.lastChild : null; e &amp;&amp; this.highlite( e ); };&lt;br /&gt;	p.handler = function( evt ){&lt;br /&gt;		var o = this, t = evt.type, k = evt.key, e = /span/i.test( ( e = evt.target ).tagName ) ? e.parentNode : e;&lt;br /&gt;		t == "keyup" ? k != 40 &amp;&amp; k != 38 &amp;&amp; k != 13 &amp;&amp; o.show()&lt;br /&gt;		: t == "keydown" ? ( k == 40 &amp;&amp; o.next() ) || ( k == 38 &amp;&amp; o.previous() )&lt;br /&gt;		: t == "keypress" ? k == 13 &amp;&amp; !evt.preventDefault() &amp;&amp; o.select()&lt;br /&gt;		: t == "blur" ? o.constructor.fadeAway( o )&lt;br /&gt;		: t == "click" ? o.select()&lt;br /&gt;		: t == "focus" ? o.show()&lt;br /&gt;		: o.highlite( e );&lt;br /&gt;	};&lt;br /&gt;	p.show = function(){&lt;br /&gt;		var cS, found = 0, o = this, i = o.i, iV = i.value, d = document, c = ( o.hide(), o.c = d.body.appendChild( d.createElement( "div" ) ) );&lt;br /&gt;		( c.className = o.n, cS = c.style, cS.display = "none", cS.position = "absolute", o.callEvent( "onshow" ) );&lt;br /&gt;		o.f.call( function( s, x, data ){&lt;br /&gt;			if( !( x.length == undefined ? ( x = [x] ) : x ).length )&lt;br /&gt;				return;&lt;br /&gt;			var j, l = 0, i = o.l.length, e = c.appendChild( d.createElement( "div" ) );&lt;br /&gt;			for( j in ( o.l[i] = s, e.className = "normal", e.d = data, e.listindex = i, !found &amp;&amp; i == o.s.i &amp;&amp; ++found &amp;&amp; o.highlite( e ), x ) )&lt;br /&gt;				e.appendChild( d.createTextNode( s.substring( l, x[j] ) ) ).parentNode.appendChild( d.createElement( "span" ) ).appendChild( d.createTextNode( s.substring( x[j], l = x[j] + iV.length ) ) ).parentNode.className = "selectedText";&lt;br /&gt;			for( x in ( e.appendChild( d.createTextNode( s.substr( l ) ) ), { click: 0, mouseover: 0 } ) )&lt;br /&gt;				addEventListener( e, x, function( e ){ o.handler.call( o, e ); } );&lt;br /&gt;		}, iV );&lt;br /&gt;		if( !c.childNodes.length )&lt;br /&gt;			return o.hide();&lt;br /&gt;		for( var x = i.offsetLeft, y = i.offsetTop + i.offsetHeight; i = i.offsetParent; x += i.offsetLeft, y += i.offsetTop );&lt;br /&gt;		( cS.display = "block", cS.left = x + "px", cS.top = y + "px", !found &amp;&amp; o.highlite( c.firstChild ) );&lt;br /&gt;	};&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Example&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;style type="text/css"&gt;&lt;br /&gt;/*container da lista*/&lt;br /&gt;.autocomplete{&lt;br /&gt;	cursor: pointer;&lt;br /&gt;	border: 1px solid #999;&lt;br /&gt;	border-top: none;&lt;br /&gt;	background: #eee;&lt;br /&gt;}&lt;br /&gt;/*caracteres que combinaram*/&lt;br /&gt;.autocomplete .selectedText{ font-weight: bold; color: #008; }&lt;br /&gt;/*items n&#227;o selecionados*/&lt;br /&gt;.autocomplete .normal{ border-top: 1px solid #999; overflow: hidden; white-space: pre; }&lt;br /&gt;/*item selecionado*/&lt;br /&gt;.autocomplete .highlited{ background: #ddf; }&lt;br /&gt;&lt;/style&gt;&lt;br /&gt;&lt;br /&gt;&lt;form action=""&gt;&lt;br /&gt;	&lt;fieldset&gt;&lt;br /&gt;		&lt;legend&gt;Preenchimento din&#226;mico&lt;/legend&gt;&lt;br /&gt;		&lt;label for="list" &gt;Emails&lt;/label&gt;&lt;br /&gt;		&lt;input autocomplete="0" type="text" name="list" id="list" /&gt;&lt;br /&gt;		&lt;br /&gt;&lt;br /&gt;		&lt;label for="ip" &gt;Lista de IPs&lt;/label&gt;&lt;br /&gt;		&lt;textarea name="ip" rows="3" cols="20" id="ip"&gt;&lt;/textarea&gt;&lt;br /&gt;		&lt;br /&gt;&lt;br /&gt;	&lt;/fieldset&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;//&lt;![CDATA[&lt;br /&gt;&lt;br /&gt;var list = [ "192.168.0.1", "192.168.0.2", "192.168.0.3", "192.168.1.1", "192.168.1.2", "192.168.1.3", "200.168.0.1", "200.168.0.2", "200.168.0.3", "200.168.1.1", "200.168.1.2", "200.168.1.3" ];&lt;br /&gt;new IncrementalSearch( document.forms[0].ip, function( search ){&lt;br /&gt;	for( var i in list )&lt;br /&gt;		if( !list[i].indexOf( search ) )&lt;br /&gt;			this( list[i], 0 );&lt;br /&gt;}, "autocomplete" );&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;var names = [ "Jo&#227;o Alves &lt;joao@123.com&gt;", "Jonas Raoni Soares Silva &lt;jonas@abc.com&gt;", "Roberto &lt;rob@net.net&gt;", "Maria Fernanda &lt;mariaf@i.tu&gt;" ];&lt;br /&gt;&lt;br /&gt;function retrieveNames( search ){&lt;br /&gt;	search = search.toLowerCase();&lt;br /&gt;	for( var i in names ){&lt;br /&gt;		if( search ){&lt;br /&gt;			for( var j = 0, indices = []; j = names[i].toLowerCase().indexOf( search, j ) + 1; indices[indices.length] = j - 1 );&lt;br /&gt;			this( names[i], indices, i );&lt;br /&gt;		}&lt;br /&gt;		else&lt;br /&gt;			this( names[i], 0, i );&lt;br /&gt;&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;x = new IncrementalSearch( document.forms[0].list, retrieveNames, "autocomplete" );&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;//]]&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Fri, 09 Sep 2005 07:41:46 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/684</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
    <item>
      <title>Auto Tab //JavaScript Function</title>
      <link>http://snippets.dzone.com/posts/show/676</link>
      <description>&lt;a href="http://www.jsfromhell.com/forms/auto-tab"&gt;&lt;br /&gt;Auto tabulation of text inputs with maxlength setted&lt;br /&gt;&lt;br /&gt;Usage: just add the code on the end of your page or call it on the onload event (worse solution) and "the enter tabulation" will be added for all fields enclosed by the &lt;form&gt; tag.&lt;br /&gt;&lt;br /&gt;[UPDATED CODE AND HELP CAN BE FOUND HERE]&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;@REQUIRES &lt;a href="http://www.jsfromhell.com/geral/event-listener"&gt;Event-Listener&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//Requires http://www.jsfromhell.com/Geral/event-listener&lt;br /&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com/forms/auto-tab [v1.0]&lt;br /&gt;&lt;br /&gt;autoTab = function(){&lt;br /&gt;	for( var d, f = ( d = document ).forms, i = f.length; i; addEventListener( f[--i], "keyup", function( e ){&lt;br /&gt;		var el, k = String.fromCharCode( e.key ), l = ( e = e.target ).value.length;&lt;br /&gt;		if ( l &gt;= ( e.getAttribute( "maxlength" ) || l + 1 ) &amp;&amp; /[\w&#192;-&#255; ]/.test( k ) ){&lt;br /&gt;			for( l = k = ( el = e.form.elements ).length; el[--k] != e; );&lt;br /&gt;			while( !(e = el[ k = ++k * ( k &lt; l ) ]).type || e.disabled );&lt;br /&gt;			e.focus();&lt;br /&gt;		}&lt;br /&gt;	} ) );&lt;br /&gt;};&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 09 Sep 2005 05:11:24 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/676</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
  </channel>
</rss>
