lunedì 3 marzo 2014

Responsive HTML5 menu

I need a menu that is adaptative, so much that if I open it from a laptop that it is already exploded but if I open it from a mobile device, then it needs to be clicked and exploded.

Such tool I used on my web site. If I see my resume section:
http://marcoandolfi.eu5.org/cv.html

you have this view from your laptop:

Instead if you open it from your iPhone you should have a view like this:

First view:



When Opened:



Ok, nice! How? 

First of all you need a JS which is the main engine 
(on my website is a separate file "dropdown-menu.js"): 
   
 if(window.addEventListener){   
      window.addEventListener("load", doLoad, false);  
 }else if(window.attachEvent){   
      window.attachEvent("onload", doLoad);  
 }else if(window.onLoad){  
   window.onload = doLoad;  
 }  
   
function doLoad(){  
        var nav = document.getElementsByTagName("NAV")[0];  
        var childs = nav.childNodes;  
        for(var i = 0; i < childs.length; i++){  
        var child = childs[i];  
        if(child.tagName === "H2"){  
          child.onclick = function(){toogleMenu(nav)};  
          child.onfocus = function(){toogleMenu(nav)};  
          break;  
        }  
}  
   
      var elClass = nav.className;  
      var arrClasses = elClass.split(" ");  
      for(var i = 0; i < arrClasses.length; i++){  
         if(arrClasses[i] === "expanded") arrClasses.splice(i, 1);  
      }  
      nav.className = arrClasses.join(" ");  
      nav.className += " non-expanded";  
      return false;  
 };  
   
 function toogleMenu(el){  
      var elClass = el.className;  
      var arrClasses = elClass.split(" ");  
      for(var i = 0; i < arrClasses.length; i++){  
        if(arrClasses[i] === "expanded"){  
          arrClasses.splice(i, 1);  
          arrClasses[length + 1] = "non-expanded";  
        }  else if(arrClasses[i] === "non-expanded"){  
          arrClasses.splice(i, 1);  
          arrClasses[length + 1] = "expanded";  
        }  
      }  
      el.className = arrClasses.join(" ");  
      return false;  
 }  




Then a bit of CSS 
   
 nav h2, aside h2{  
      position: absolute;  
      left: -999em;  
 }  
   
 nav {  
      clear: left;  
      margin: 0 0 2em;  
 }  
   
 nav ol{  
      border: 1px solid #e6e6e6;  
      padding-left: 0;  
 }  
   
 nav li {  
      border-bottom: 1px solid #eee;  
      line-height: 2em;  
      list-style: none;  
      margin-left: 0;  
 }  
   
 nav li:last-child {  
   border-bottom: 0;  
 }  
   
 nav a {  
      color: #999;  
      display: block;  
      padding: .5em .8em;  
      text-decoration: none;  
 }  
   
 nav .current {  
      font-weight: bold;  
 }  
   
 .dropdown-header {  
      font-size: 14px;  
      font-weight: bold;  
      color: #000000;  
 }  
   
 @media screen and (max-width: 37.499em){ /* base: 16px -> [< 600px] */  
   
      nav {  
           margin: 0 0 1.5em;  
           overflow: hidden;  
           position: relative;  
      }  
   
      nav h2 {  
           cursor: pointer;  
           font-size: 0.5em;  
           height: 4.2em;   
           left: auto;  
           margin: 0;  
           right: 0;  
           position: absolute;  
           text-indent: -999em;  
           top: 0;  
           width: 4em;  
      }  
   
      nav.non-expanded h2 {  
           background: #ccc url(../img/check_icon.png) no-repeat -35px 45%;  
      }  
   
      nav.expanded h2 {  
           background: #ccc url(../img/check_icon.png) no-repeat 0px 45%;  
      }  
   
      nav h2{  
           background: none;  
      }  
   
      nav a {  
           padding-right: 3em;  
      }  
   
      nav li {  
           clear: left;  
           line-height: 1em;  
      }  
   
      nav.non-expanded li{  
           display: none;  
      }  
   
      nav.expanded li{  
           display: block;  
      }  
   
      nav li.current {  
           border-bottom-width: 0;  
           display: block;  
      }  
   
      nav.expanded li.current {  
           border-bottom-width: 1px;  
      }  
   
 }  
(on my website is a separate file "dropdown-menu.css"): 





and now the HTML:

 <!DOCTYPE html>  
 <html lang="en">  
  <head>  
   [...]  
   <!-- Bootstrap core CSS -->  
   <link href="css/bootstrap.min.css" rel="stylesheet">  
   <!-- CSS for drop down menú adaptive -->  
   <link href="css/dropdown-menu.css" rel="stylesheet">  
   [...]  
  </head>  
  <body>  
    [...]          
       <nav>  
        <h2>Documents</h2>  
         <ol>  
           <li class="dropdown-header"> Professional </li>  
           <li class="selectable" id="CV"><a href="javascript:loadFrame('CV');">Curriculum Vitae</a></li>  
           <li class="selectable" id="ProjectList"><a href="javascript:loadFrame('ProjectList');">Project List</a></li>  
           <li class="selectable" id="Recommendation"><a href="javascript:loadFrame('Recommendation');">Recommendation</a></li>  
           <li class="dropdown-header"> Education </li>  
           <li class="selectable" id="HighSchoolDiploma"><a href="javascript:loadFrame('HighSchoolDiploma');">High School Diploma</a></li>  
           <li class="selectable" id="Bachelor"><a href="javascript:loadFrame('Bachelor');">Bachelor Degree</a></li>  
           <li class="selectable" id="Master"><a href="javascript:loadFrame('Master');">Master Degree</a></li>  
           <li class="selectable" id="Paper"><a href="javascript:loadFrame('Paper');">Scientific publication</a></li>  
           <li class="dropdown-header"> Certification </li>  
           <li class="selectable" id="TUV"><a href="javascript:loadFrame('TUV');">PM Certification</a></li>  
           <li class="selectable" id="Scrum"><a href="javascript:loadFrame('Scrum');">Scrum Master Certification</a></li>  
           <li class="selectable" id="HTML5"><a href="javascript:loadFrame('HTML5');">HTML5 Certification</a></li>  
           <li class="selectable" id="SAPHANA"><a href="javascript:loadFrame('SAPHANA');">SAP HANA Certification</a></li>  
         </ol>  
       </nav>  
   [...]  
   <!-- Bootstrap core JavaScript  
   ================================================== -->  
   <!-- Placed at the end of the document so the pages load faster -->  
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>  
   <script src="js/dropdown-menu.js"></script>  
   <script src="js/bootstrap.min.js"></script>  
   [...]  
  </body>  
 </html>  

eh voilá!


Constraint: 
The JS is based on the search of the tag <nav>.
This means: if you have more than one <nav> tag potentially it will not work. You need to have only one <nav>. It is easy to extend to code and change the search of the tag not on the tag type, but on the tag id.

sabato 1 marzo 2014

Clear comunication

"A contract company out here was asked to stencil on the side of a fuel tanker: 'Diesel Fuel' in Arabic and 'No Smoking' in Arabic. This is what came back..."



Source: 
http://www.huffingtonpost.co.uk/2012/02/06/arabic-fuel-tanker-fail_n_1256624.html

venerdì 28 febbraio 2014

Compile Java in Oracle




Have you ever tried to compile a java class in Oracle? Have you understood why it was not compiling?
In order to properly compile java, you can use the "show errors option":

 ALTER JAVA CLASS "com/organization/project/MyClass" COMPILE;  
 show errors java class "com/organization/project/MyClass";  


Especially the last line - I hate how Oracle handles Java compilation, with the last line it will output the error. Having such option permits to have some more verbose output message. Like:

 0/0      com/organization/project/MyClass:19: cannot find symbol  
 0/0      symbol : class Logger  
 0/0      location: package org.apache.log4j  
 0/0      import org.apache.log4j.Logger;  
 0/0                  ^  
 0/0      com/organization/project/MyClass:29: cannot find symbol  
 0/0      symbol : class Logger  
 0/0      location: class com.organization.project.MyClass  
 0/0       private static Logger log = Logger.getLogger(MyClass.class);  
 0/0                  ^  
 0/0      com/organization/project/MyClass:29: cannot find symbol  
 0/0      symbol : variable Logger  
 0/0      location: class com.organization.project.MyClass  
 0/0       private static Logger log = Logger.getLogger(MyClass.class);  
 0/0                        ^  
 0/0      com/organization/project/MyClass:253: cannot find symbol  
 0/0      symbol : method getXmlFilePath()  
 0/0      location: class com.organization.project.MyClass  
 0/0           File xmlfile = formXmlFile(getXmlFilePath());  
 0/0                            ^  
 0/0      com/organization/project/MyClass:259: cannot find symbol  
 0/0      symbol : variable trFileobj  
 0/0      location: class com.organization.project.MyClass  
 0/0        insertXrunId(con,trFileobj);  
 0/0                 ^  
 0/0      5 errors  

Class Logger is missing, also method getXmlFilePath(), I would also say class MyClass.




CSS Checklist effect

You want to achieve in HTML such effect using only CSS. 




Thanks to www.cssflow.com ! They made a great tutorial. 
Basically you can find everything needed here: http://www.cssflow.com/snippets/simple-to-do-list



mercoledì 26 febbraio 2014

Responsive picture resizer

You are building your website and you have a pretty heavy picture. You would like to have a picture which is small for small device and large for normal laptop.
I just did on my website, for my main picture:

(1014 x 490) to be used on laptop


(792 x 400) to be used on tablets


(300 x 253) to be used on mobile devices



How do you do that?
There is a great a very lightweight script fully supporting you (thanks to Koen Vendrik, please visit his website: http://kvendrik.com)


 /*  
 // @name: Responsive-img.js  
 // @version: 1.1  
 //   
 // Copyright 2013-2014 Koen Vendrik, http://kvendrik.com  
 // Licensed under the MIT license  
 */  
 function makeImagesResponsive() {  
   var e = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,  
     t = document.getElementsByTagName("body")[0].getElementsByTagName("img");  
   if (t.length === 0) return;  
   var n;  
   t[0].hasAttribute ? n = function (e, t) {  
     return e.hasAttribute(t)  
   } : n = function (e, t) {  
     return e.getAttribute(t) !== null  
   };  
   var r = window.devicePixelRatio ? window.devicePixelRatio >= 1.2 ? 1 : 0 : 0;  
   for (var i = 0; i < t.length; i++) {  
     var s = t[i],  
       o = r && n(s, "data-src2x") ? "data-src2x" : "data-src",  
       u = r && n(s, "data-src-base2x") ? "data-src-base2x" : "data-src-base";  
     if (!n(s, o)) continue;  
     var a = n(s, u) ? s.getAttribute(u) : "",  
       f = s.getAttribute(o),  
       l = f.split(",");  
     for (var c = 0; c < l.length; c++) {  
       var h = l[c].replace(":", "||").split("||"),  
         p = h[0],  
         d = h[1],  
         v, m;  
       if (p.indexOf("<") !== -1) {  
         v = p.split("<");  
         if (l[c - 1]) {  
           var g = l[c - 1].split(/:(.+)/),  
             y = g[0].split("<");  
           m = e <= v[1] && e > y[1]  
         } else m = e <= v[1]  
       } else {  
         v = p.split(">");  
         if (l[c + 1]) {  
           var b = l[c + 1].split(/:(.+)/),  
             w = b[0].split(">");  
           m = e >= v[1] && e < w[1]  
         } else m = e >= v[1]  
       } if (m) {  
         var E = d.indexOf("//") !== -1 ? 1 : 0,  
           S;  
         E === 1 ? S = d : S = a + d;  
         s.src !== S && s.setAttribute("src", S);  
         break  
       }  
     }  
   }  
 }  
 if (window.addEventListener) {  
   window.addEventListener("load", makeImagesResponsive, !1);  
   window.addEventListener("resize", makeImagesResponsive, !1)  
 } else {  
   window.attachEvent("onload", makeImagesResponsive);  
   window.attachEvent("onresize", makeImagesResponsive)  
 };  


Here comes the HTML code:


 <!DOCTYPE html>  
 <html lang="en">  
  <head>  
   [...]   
  </head>  
  <body>  
   [...]  
     <figure>  
      <img width="100%"  
       src="img/Marco_andolfi_1024.png"   
       alt="Marco Andolfi"   
       data-src-base='img/'   
       data-src='<600:Marco_Andolfi_600.png,   
            <800:Marco_Andolfi_800.png,   
            >800:Marco_Andolfi_1024.png'>  
     </figure>   
   [...]   
   <script src="js/responsive-img.js"></script>  
  </body>  
 </html>