Monthly Archives: February 2011

YUI – Define anonymous function

Defining an anonymous function in order to keep all variables out of the global scope. Inside the anonymous function, define some shortcuts to utils that will be used frequently (Dom and Event).

(function () {
    var Event = YAHOO.util.Event,
    Dom = YAHOO.util.Dom;
}());

Inside the the anonymous function, use the onDOMReady method of the Event utility to instantiate an Overlay and a Button when the page’s DOM is ready to be scripted.

Event.onDOMReady(function () {
    var oCalendarMenu;

    // Create an Overlay instance to house the Calendar instance
    oCalendarMenu = new YAHOO.widget.Overlay("calendarmenu", { visible: false });

    // Create a Button instance of type "menu"

    var oButton = new YAHOO.widget.Button({
       type: "menu",
       id: "calendarpicker",
       label: "Choose A Date",
       menu: oCalendarMenu,
       container: "datefields" });
});

WordPress – Dynamic Highlight Menu

This allows you to theme/style and control the currently selected menu tab in CSS by adding a class=”current” on it.

<ul id="nav">
  <li<?php if ( is_home() || is_category() || is_archive() || is_search() || is_single() || is_date() ) { echo ' class="current"'; } ?>><a href="#">Gallery</a></li>
  <li<?php if ( is_page('about') ) { echo ' class="current"'; } ?>><a href="#">About</a></li>
  <li<?php if ( is_page('submit') ) { echo ' class="current"'; } ?>><a href="#">Submit</a></li>
</ul>

Line 2:

If Home, or Category, or Archive, or Search or Single page is selected, class=”current” will be included in

  • Line 3,4:

    If Page with page slug about or submit is highlighted, class=”current” is added.

    If you are looking at putting categories as menu tabs, here’s how to make the menu dynamic:

    <ul id="nav">
      <li<?php if ( is_category('css') ) { echo ' class="current"'; } ?>><a href="#">CSS</a></li>
      <li<?php if ( is_category(showcase) ) { echo ' class="current"'; } ?>><a href="#">Showcase</a></li>
    </ul>
    

    If category with category slug of css or showcase, class=”current” is added.

  • Ubuntu – Merge avi (mpg or mpeg) files

    We will merge the files using cat and mencoder. For that purpose we will first install the appropriate software to use mencoder, then we will concatenate our files and last we will repair some out-of-sync due to the concatenation.
    We need to do the following:

       1. sudo apt-get install mencoder mplayer
           install the appropriate software
       2. cat file1.avi file2.avi ...filen.avi > file.avi
           we are concatenating files 1 to n
       3. mencoder -forceidx -oac copy -ovc copy file.avi -o file_final.avi
          to repair some possible break in sync between video and sound due to cat command.