Skip to main content
CSS is fun and cool and I like it.
Snippet

Empty an Array

This is one of the fastest and easiest ways of emptying an array. Of course there are may other ways, but those usually include creation of a new array. This way you reuse the same array.

var myArray = ["one", "two", "three"];

// console.log( myArray ) => ["one", "two", "three"]

myArray.length = 0;

// console.log( myArray ) => []
Read article “Empty an Array”
Snippet

Disable Parent Links in Nested List Navigation

jQuery code that disables parent links for drop down menus. The menu should be built as nested lists, and the parent link is disabled. This helps eliminate a useless page to display only a list of links to the pages that your dropdown menu already displays.

jQuery

$("#navigation li:has(ul.sub-navigation)").hover(function () {
     $(this).children("a").click(function () {
        return false;
     });
  });

Reference HTML

<ul id="navigation">
  <li><a href="#your-link-here">Nav 1</a></li>
          <ul class="sub-navigation">
                <li><a href="#your-link-here">SubNav 1</a></li>
                <li><a href="#your-link-here">SubNav 2</a></li>
                <li><a href="#your-link-here">SubNav 3</a></li>
          </ul>
  <li><a href="#your-link-here">Nav 2</a></li>
  
Read article “Disable Parent Links in Nested List Navigation”
Snippet

Get File Last Updated Date

/*
 * @param string $file Filepath
 * @param string $format dateformat
 * @link http://www.php.net/manual/de/function.date.php
 * @link http://www.php.net/manual/de/function.filemtime.php
 * @return string|bool Date or Boolean
 */

function getFiledate($file, $format) {
       if (is_file($file)) {
               $filePath = $file;
               if (!realpath($filePath)) {
                       $filePath = $_SERVER["DOCUMENT_ROOT"].$filePath;
       }
               $fileDate = filemtime($filePath);
               if ($fileDate) {
                       $fileDate = date("$format",$fileDate);
                       return $fileDate;
               }
               return false;
       }
       return false;
}
Read article “Get File Last Updated Date”
Snippet

Get File Size

/*
 * @param string $file Filepath
 * @param int $digits Digits to display
 * @return string|bool Size (KB, MB, GB, TB) or boolean
 */

function getFilesize($file,$digits = 2) {
       if (is_file($file)) {
               $filePath = $file;
               if (!realpath($filePath)) {
                       $filePath = $_SERVER["DOCUMENT_ROOT"].$filePath;
       }
           $fileSize = filesize($filePath);
               $sizes = array("TB","GB","MB","KB","B");
               $total = count($sizes);
               while ($total-- && $fileSize > 1024) {
                       $fileSize /= 1024;
                       }
               return round($fileSize, $digits)." ".$sizes[$total];
       }
       return false;
}
Read article “Get File Size”