Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS 

Helper to Display Rails Flash Messages

A simple code snippet for displaying your flash[:warning] = "Warning Message" messages in rails.

   1  
   2  def flash_helper
   3    
   4      f_names = [:notice, :warning, :message]
   5      fl = ''
   6      
   7      for name in f_names
   8        if flash[name]
   9          fl = fl + "<div class=\"notice\" id=\"#{name}\">#{flash[name]}</div>"
  10        end
  11        flash[name] = nil;
  12      end
  13      return fl
  14    end

Wordpress HTML Outline

// Basic HTML structure for a wordpress page
   1  <body>
   2  	<div id="wrap">
   3  		<div id="top">
   4  		</div>
   5  
   6  		<div id="content" class="single">
   7  			<div class="post-wrap" id="post-6">
   8  				<h1 class="post-title">The Title Of Your Post</h1>
   9  				<div class="story-content">
  10  				</div>
  11  				
  12  				<div class="metawrap">
  13  				</div>
  14  			</div>
  15  
  16  			<div id="commentwrap">
  17  				<h3 id="respond">Leave Your Comment</h3>
  18  				<form>
  19  				</form>
  20  			</div>
  21  		</div>
  22  
  23  		<div id="side">
  24  			<ul>
  25  				<li><!-- One side bar item --></li>
  26  			</ul>
  27  		</div>
  28  
  29  		<div id="bottom"></div>
  30  		
  31  	</div><!-- end wrap -->
  32  </body>

Move multiple options from one select to another

// Theis code requires you include prototype.js
   1  
   2  
   3  function copyOptions(from , to)
   4  {
   5  	for (var i=0; i < $(from).options.length; i++) 
   6  	{
   7          if ($(from).options[i].selected) 
   8          {
   9              var optionName = new Option($(from).options[i].text, 
  10              	$(from).options[i].value);
  11              $(to).options[$(to).length] = optionName;
  12          }
  13      }
  14      remove($(from));
  15  }
  16  
  17  function remove(theSel)
  18  {
  19    	var selIndex = theSel.selectedIndex;
  20    	if (selIndex != -1) 
  21    	{
  22  	    for(i=theSel.length-1; i>=0; i--)
  23  	    {
  24  		      if(theSel.options[i].selected)
  25  		      	theSel.options[i] = null;
  26  	    }
  27      	if (theSel.length > 0) 
  28        		theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
  29    	}
  30  }

Place Timezone information into a cookie

Set a cookie with the users timezone

   1  
   2  //By default, getTimezoneOffset returns the time zone offset in minutes
   3  setCookie("timezone", new Date().getTimezoneOffset()/60);
   4  
   5  function setCookie(name, value, expires, path, domain, secure) 
   6  {
   7      document.cookie= name + "=" + escape(value) +
   8          ((expires) ? "; expires=" + expires.toGMTString() : "") +
   9          ((path) ? "; path=" + path : "") +
  10          ((domain) ? "; domain=" + domain : "") +
  11          ((secure) ? "; secure" : "");
  12  }
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS