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.

def flash_helper
  
    f_names = [:notice, :warning, :message]
    fl = ''
    
    for name in f_names
      if flash[name]
        fl = fl + "<div class=\"notice\" id=\"#{name}\">#{flash[name]}</div>"
      end
      flash[name] = nil;
    end
    return fl
  end

Wordpress HTML Outline

// Basic HTML structure for a wordpress page
<body>
	<div id="wrap">
		<div id="top">
		</div>

		<div id="content" class="single">
			<div class="post-wrap" id="post-6">
				<h1 class="post-title">The Title Of Your Post</h1>
				<div class="story-content">
				</div>
				
				<div class="metawrap">
				</div>
			</div>

			<div id="commentwrap">
				<h3 id="respond">Leave Your Comment</h3>
				<form>
				</form>
			</div>
		</div>

		<div id="side">
			<ul>
				<li><!-- One side bar item --></li>
			</ul>
		</div>

		<div id="bottom"></div>
		
	</div><!-- end wrap -->
</body>

Move multiple options from one select to another

// Theis code requires you include prototype.js

function copyOptions(from , to)
{
	for (var i=0; i < $(from).options.length; i++) 
	{
        if ($(from).options[i].selected) 
        {
            var optionName = new Option($(from).options[i].text, 
            	$(from).options[i].value);
            $(to).options[$(to).length] = optionName;
        }
    }
    remove($(from));
}

function remove(theSel)
{
  	var selIndex = theSel.selectedIndex;
  	if (selIndex != -1) 
  	{
	    for(i=theSel.length-1; i>=0; i--)
	    {
		      if(theSel.options[i].selected)
		      	theSel.options[i] = null;
	    }
    	if (theSel.length > 0) 
      		theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
  	}
}

Place Timezone information into a cookie

Set a cookie with the users timezone

//By default, getTimezoneOffset returns the time zone offset in minutes
setCookie("timezone", new Date().getTimezoneOffset()/60);

function setCookie(name, value, expires, path, domain, secure) 
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS