Thursday, March 7, 2019

Today 3/6/19

What is Agile?

“Agile is a set of values and principles for software development under which requirements and solutions evolve through the collaborative effort of self-organizing cross-functional teams.”

Agile is a set of practices to help you be adaptable, and ensure your team is always working on something important.

Agile is the process of breaking down a large project into smaller tasks (usually called stories) and prioritizing them.

Agile Workflow

It is very simple.
* Sprint Planning: At first you start with the ToDo List AKA Product Backlog - a prioritized list of items to deliver a product.
* Once you have the ToDo List, the next step is to have a planning meeting where you pick the most important user stories and place them in a current Sprint. The required efforts are estimated and agreed upon
* The user stories are then developed into one to three weeks of Sprint (development cycles), it includes, planning, testing, bug fixing and everything that goes into delivering that feature in that sprint
* The team goes through a brief daily standup meetings every day to understand what the team did yesterday, what it is doing today, and if their are any roadblocks
* At the end of the sprint, you do a sprint review where you see if the development adds any values to the customer/product, if yes, you ship it. If not, then you will have to repeat the entire process for another sprint
* At the end you will have a Sprint retrospective meeting where you see what went well, what can be changed, what needs to be kept and what can be removed. After this meeting, the team moves on a next sprint planning and the cycle repeats











Tuesday, March 5, 2019

Today 3/5/19

What are algorithms? 

An algorithm is a set of unambiguous instructions to solve any problem. For example, when you make some changes in a word document, the document is auto saved. The autosave feature is an algorithm, it follows an instruction of saving a document the moment when any edit happens on the document.

Another practical and most understandable example would be; consider you have 10 people in a room and you have to count the number of people in that room. All of us follow the simple human process and start counting people in that room by pointing fingers at each person. In this process, unknowingly, we follow the set algorithm of counting people. The same applies to every task we perform in our daily activities.


Agnostic Apps / device agnosticism 

The term agnostic apps is gaining more and more popularity these days. It's a big and scary word but if we actually look at the literal meaning of it, it simply means any application or device that works just fine with various systems without requiring any special device/adaptation. For example, a website that works fine on laptops as well as on mobiles, tv, wearables, refrigerators, IOTs etc. 


Agile Epic and User Story 

An Epic is a a long/big story as the name suggests. There can be multiple small user stories for that epic. For example, an epic for a travel websites can be I want to find holiday destinations and travel around the world. It's big and it is difficult to define, so, to do that we have to break this epic into multiple small user stories such as As a user I want to discover new destinations.

A user story is a short, simple description of a product feature. User stories define product backlog and a product backlog is a collection of user stories that are prioritized based on the user/business needs. A user story has three parts (1) persona (as a user) (2) the feature (I want...) (3) the need satisfied by the feature (so that I can achieve...) for example, As a user I want recommended destinations based on my current location.

Minimum Viable Product (MVP) 

It is a product with just enough features to test the concept and give feedback on the developed product. Most companies start working on the project without knowing if they can provide what is expected, and it is the reason why many of them fail. Imagine a situation that you have to deliver a banking product, you put in years of efforts and eventually you develop something that the customers don't want. That can be a big pain. To avoid it, it's best to give customers the MVP, start with the most important features first, make sure that feature works just as expected and once the customers are happy with what you have build then continue with other features and eventually a complete product.




Focus 

It's the motion of your mind and body (how you feel at the moment) helps you learn things faster. Information combined with Emotions becomes a long term memory.




Monday, July 30, 2018

Javascript ES6 - lexical scope of this

In Javascript every function brings its own 'this' context. The situation becomes difficult to work with when there are many functions inside function which complicates the context of 'this'. The ES6 fat arrow (=>) passes the lexical scope of parent 'this' to all child functions -

Example:
function parentFunction(){
    this.add = 0;
    this.addAnother = function(){
    this.addOne = setTimeout(function(){
        console.log(++this.add);
        }, 1000)
    }
} 

var funcObj = new parentFunction();
funcObj.addAnother(); // NaN  

It outputs to 'NaN' because the 'this' context here 'console.log(++this.add);' is scoped to setTimeout function.

To avoid this, the ES5 solution is to use the classic 'var that = this' -
function parentFunction(){
    this.add = 0;
    var that = this;
    this.addAnother = function(){
    this.addOne = setTimeout(function(){
        console.log(++that.add);
        }, 1000)
    }
} 

var funcObj = new parentFunction();
funcObj.addAnother();  

Now, this works perfectly fine, but the new ES6 fat arrow works even better by passing the lexical scope of parent 'this' to all child functions -
function parentFunction(){
    this.add = 0;
    this.addAnother = () => {
    this.addOne = setTimeout(() => {
        console.log(++this.add);
        }, 1000)
    }
} 

var funcObj = new parentFunction();
funcObj.addAnother();  

The traditional ES5 'this' creates a new scope of 'this' in each function which is why we were getting the 'NaN' because the 'this' in setTimeout function was scoped to the setTimeout function alone.

With the fat arrow, the 'this' in setTimeout refers to the lexical scope of parent 'this'.




Friday, July 27, 2018

Javascript: Var vs Let vs Const

The var, let and const game is all about their scope (the location where they are available to the developers). Put it simply -
  • Var has a functional scope (local and global/window), also it goes all the way up till the window object to find the declaration. Var is also a function scope (they are available inside the function they are declared in)   
  • Let has a block level scope. It stays within the curly braces. Let allows re-assigning its values  
  • Const also has a block level scope. Use const if you do not need to change its value 

Let's go with examples:

Var:
for(var i = 0; i < 10; i++){
    console.log(i);
}
It's normal to consider that the scope of 'var i' would be available inside the curly braces of for loop. However, the 'var i' is also accessible outside of the for loop.
for(var i = 0; i < 10; i++){
    console.log(i);
}
console.log('After loop is over ' +i); //logs 10 

It's completely valid because of the concept of 'Hoisting'. All variables in JavaScript are hoisted on top of the function - something like this:
var i; 
for(i = 0; i < 10; i++){
    console.log(i);
}
console.log('After loop is over ' +i);   

This is because there is only one type of scope in ES5 - that is Function Scope
function func(){ 
    for(var i = 0; i < 10; i++){
        console.log(i);
    }
}
func();
console.log('After the function ' +i); // throws an error, because var i is not accessible     

And if you don't declare the var keyword inside the function, the JS will hoist the var at the window/global level and it will be accessible everywhere  -
var i; // hoists in global scope 
function func(){ 
    for(i = 0; i < 10; i++){ // if you don't mention 'var i'
        console.log(i);
    }
}
func();
console.log('After the function ' +i); // logs 10      

Let:
Let will never have the issues like var, because let has a block level scope which means it doesn't work outside of that block of code, or outside of those curly braces -
 
for(let i = 0; i < 10; i++){
    console.log(i);
}
console.log('After loop is over ' +i); // doesn't work     

But you can re-assign the values of let -
 
let i = 'hi';
i = 55; 
console.log(i); // logs 55 

Const:
Changing const value is not possible -
 
const i = 10;
i = 55; 
console.log(i); // throws typeError  

But, it allows a little flexibility to change the property of const object  -
 
const i = {
    k: 10
}
i.k = 55; 
console.log(i); // logs k:55   




Sunday, May 20, 2018

Get form fields value using jQuery

In jQuery the .val() method is used to get form field values from input, textarea, select etc. Use the :checked method for select, checkbox, and radio buttons.

Here’s a Fiddle:

Friday, December 4, 2015

JavaScript Constructor Prototype

At first it's important to understand that in JavaScript every function is an Object. Ok - then, what is a Constructor function?

The Construction function in javascript is just like any other function. Except, the convention it follows - Capitalization. The first character is in capital format. Another difference is that it uses the 'this' keword of javascript, which is the most important and confusing keyword of all.

This is how we create the constructor function:
function Student(name){
  this.name = name;
  this.getName = function(){
    return this.name;    
  }
}
var s1 = new Student("Leo");
var s2 = new Student("Lara");

console.log(s1.getName()); //Leo
console.log(s2.getName()); //Lara
This is not an appropriate way because if you create 500 Student objects then there will be 500 copies of the getName() function in memory.

Approach 2:
function Student(name){
  this.name = name;
}
var s1 = new Student("Leo");
s1.getName = function(){
  return this.name;
}
var s2 = new Student("Lara");

console.log(s1.getName()); //Leo
console.log(s2.getName()); //TypeError: s2.getName is not a function
The problem with this approach is that you have to repeat the same function for each object you create which will be arror prone.

Approach 3:
function Student(name){
  this.name = name;
}
Student.getName = function(){
  return this.name;
}
var s1 = new Student("Leo");
var s2 = new Student("Lara");

console.log(s1.getName()); //TypeError: s1.getName is not a function
console.log(s2.getName()); // 
The problem with this approach is that our newly created objects don't have access to the getName function.

Let's use the prototype property to associate the function
function Student(name){
  this.name = name;
}
Student.prototype.getName = function(){
  return this.name;
}
var s1 = new Student("Leo");
var s2 = new Student("Lara");

console.log(s1.getName()); //Leo
console.log(s2.getName()); //Lara

1. The benefits of this approach is that no matter how many objects you create, functions are loaded only once in the memory.
2. It allows you to override the function if necessary



Thursday, December 3, 2015

JavaScript: Prototype Object Vs Reference Object Explained

What is an Object?
It is a set of key and value pairs. You can use any number of keys with any name as long as it is a String. And each key can be associated with any value, those values can be of any Types, such as: Primitive Types, Function Objects and object itself.
var myObject = {
  a: undefined, //Primitive
  b: null, //Primitive
  c: true, //Primitive
  d: "foo", //Primitive
  e: 4.33, //Primitive
  f: function bar() { /**/ }, //Object
  g: {
    h: baz
  } //Object
}

The difference:

In case of Objects - values are passed by reference, and the changes are bi-directional:
var a = { x: 1, y: 2}
var b = a;
console.log(b); // Object {x: 1, y: 2} 

//
b.x = 10;
console.log(a.x); // 10

//
a.y = 20;
console.log(b.y); //20

While in Primitive - the values are passed by value, and the changes are uni-directional:
//Prototype Object
var object1 = {x: 11, y: 22};
var object2 = Object.create(object1);
console.log(object2); //Object {}

//
object2.x = 100; 
console.log(object1.x); //11 
console.log(object2.x); //100 

//
object1.y = 200; 
console.log(object2.y); //200 
console.log(object1.y); //200 

Fiddle: http://jsfiddle.net/sL6q0742/



Sunday, December 28, 2014

Vertical text / tabs with CSS3 transform matrix

These days the UI trends are changing rapidly, everyone is trying to implement something different than regular. For a long time we have always implemented the tabs in horizontal format, we did try to keep the tabs in vertical format but it wasn't easily possible with creepy IE browsers. CSS3 transforms have made the web a lot different than before. Scaling, skewing, rotating, translates are doing beautiful magic with their capabilities.

Today, implementing vertical text / tabs is possible with CSS3 transform matrix. Here is the code -

Browser compatibility: IE 9+

HTML:
  • Tab 3
  • Tab 2
  • Tab 1

CSS:
.tabs-vertcal{ 
 transform-origin: 0% 0% 0px; 
 transform: matrix(0, -1, 1, 0, 0, 350); 
}
.tabs{
 list-style-type: none;
}
.tab{
 float: left; 
 width: 92px; 
 padding: 6px; 
 border: 1px solid pink; 
 background: indigo; 
 color: white;
 text-align: right;
}

Demo: http://jsfiddle.net/oy3gnuxr/1/



Note: It's just a vertical text for now, I'll add the tabs functionality with jQuery soon.


Thursday, November 20, 2014

CSS Tabs Navigation Tricks

Developing a tabs navigation with CSS holds some simple tricks, but most of the front-end guys end up getting the results in an inappropriate way. Here's what you need to know about it -
I. The margin-bottom: -1px to the <li> element
II. The border and background to the <a> element
III. Change in border and background in the <a> element when <li> has .active class

HTML: 

CSS: 
ul{ margin: 0; padding: 0; list-style: none; border-bottom: 1px solid #ddd; 
}
ul:before, ul:after{
    content: ""; display: table;
}
ul:after{
    clear: both;
}
/**/
ul li{ 
    float: left; 
    margin: 0 4px -1px 4px;                /*Trick 1*/
}
ul li a{ 
    display: block; 
    text-decoration: none; 
    padding: 10px 15px; 
    border: 1px solid transparent;         /*Trick 2*/
    background: transparent;               /*Trick 2*/ 
}
ul li a:hover{
    background: #eee;
}
ul li.active a{ 
    border-radius: 4px 4px 0 0;
    border: 1px solid #ddd; 
    border-bottom: 1px solid transparent; /*Trick 3*/ 
    background: #fff;                     /*Trick 3*/ 
}

jQuery: 
$(function(){
    $('li a').on('click', function(e){
        e.preventDefault(); // to avoid page refresh because a elements have # in href 
        $('li').removeClass('active');
        $(this).parent('li').addClass('active');
    });
});


Demo: http://jsfiddle.net/dipaks2011/o35c8yxt/

Note: The fiddle demo is creating a ghost border on the right side of the tabs which doesn't appear in real HTML page.


Saturday, November 15, 2014

JavaScript text selection popover

Those who have read some articles on Medium.com are aware of how they can select text anywhere on a page and share it on Twitter or write a short comment about the selected text right on that page.

That's a nice popover to have, if the requirement is to select the text and show some information related to it on the same spot. I thought of posting a simple demo of it here, so that others can use it.

Here's the code –

HTML:
    
Having been in the field, most recently in India, I have seen that access to safe water is just a few dollars away for many people. A small loan can create a pathway to a household water tap. Making access to capital ubiquitous and affordable for those living in poverty would go a long way towards eliminating water stress.
CSS:
::selection{
  background: SeaGreen;
  color: White;
}
::-moz-selection{
  background: SeaGreen;
  color: White;
}
#textDescription{
  line-height:1.9em; font-size:16px; margin:10px; border:1px #333 solid; padding:5px; width: 450px;
 }
 .selectedText{
  position: relative;
  background-color: SeaGreen; color:#fff; line-height: 1.2em;
 } 
 .popDiv{
  background: ForestGreen; color: white; padding: 6px; width: 180px; height: 80px;  
  position: absolute; top: 18px; left: 0;
  border-radius: 4px; box-shadow: 2px 3px 4px #444;

  -webkit-animation: slideIn .5s;
  animation: slideIn .5s;
 }

 @-webkit-keyframes slideIn{
  from{
   top: 8px; opacity: 0; height: 40px;
  }
  to{
   top: 18px; opacity: 1; height: 80px;
  }
 }

 @-moz-keyframes slideIn{
  from{
   top: 8px; opacity: 0; height: 40px;
  }
  to{
   top: 18px; opacity: 1; height: 80px;
  }
 }

 @keyframes slideIn{
  from{
   top: 8px; opacity: 0; height: 40px;
  }
  to{
   top: 18px; opacity: 1; height: 80px;
  }
 }
JavaScript / jQuery:
 


 var parentContainerId = "textDescription"
  
 if(!window.CurrentSelection){
  CurrentSelection = {}
 }
 
 CurrentSelection.Selector = {}
 
 //get the current selection
 CurrentSelection.Selector.getSelected = function(){
  var sel = '';
  if(window.getSelection){
   sel = window.getSelection()
  }
  else if(document.getSelection){
   sel = document.getSelection()
  }
  else if(document.selection){
   sel = document.selection.createRange()
  }
  return sel
 }
 //function to be called on mouseup
 CurrentSelection.Selector.mouseup = function(){
  
  var st = CurrentSelection.Selector.getSelected()
  if(document.selection && !window.getSelection){
    var range = st
    range.pasteHTML("" + range.htmlText + "");   
  }
  else{
    var range = st.getRangeAt(0)    
    var newNode = document.createElement("span");
    newNode.setAttribute("class", "selectedText");
    range.surroundContents(newNode);
    //
    var getTitle = newNode.innerHTML;
    newNode.setAttribute("title", getTitle);

    //
    var popDiv = document.createElement('span');
    popDiv.setAttribute('class', 'popDiv');
    popDiv.innerHTML = getTitle;

    if(newNode.innerHTML.length > 0) {
     newNode.appendChild(popDiv);
    }     
    //Remove Selection: To avoid extra text selection in IE  
    if (window.getSelection) {
      window.getSelection().removeAllRanges();
    }
        else if (document.selection){ 
         document.selection.empty();
        }
        //
  }
 }
        
 $(function(){

  $("#"+parentContainerId).on('mouseup', function(){
    $('span.selectedText').contents().unwrap();
    $(this).find('span.popDiv').remove();
  });

  $("#"+parentContainerId).bind("mouseup",CurrentSelection.Selector.mouseup); 
 })        


Demo: http://jsfiddle.net/dipaks2011/uz0gsu8a/1/



Related Posts:

jQuery tab navigation:
http://dipaksblogonline.blogspot.in/2012/03/simple-jquery-tab-navigation.html

Defer third party scripts:
http://dipaksblogonline.blogspot.in/2012/06/defer-third-party-scriptsads-until.html

Using multiple iScrolls in one page:
http://dipaksblogonline.blogspot.in/2013/06/using-multiple-iscroll-in-one-page.html



Wednesday, September 17, 2014

HTML5 details element

Have you ever wondered if you could achieve that jQuery Accordion widget effect without jQuery or JavaScript? Did you think it will be ever possible to create it with just HTML? If no, well, you can achieve that with the HTML5 <details> element.

The details element is used as a widget to show/hide additional information.
Click me to toggle more information
The details element is used as a widget to show/hide additional information.
Demo: http://jsfiddle.net/8mthoj5g/

Attributes:

It comes with one additional attribute that is 'open'. By default it appears in closed state, but if you want to keep the hidden information visible on-load, you can use the 'open' attribute -
Click me to toggle more information
The details element is used as a widget to show/hide additional information.
Demo: http://jsfiddle.net/8mthoj5g/1/

Nesting:

Nesting multiple details in details is possible -
Click me to toggle more information
The details element is used as a widget to show/hide additional information.
More links to help
Demo: http://jsfiddle.net/8mthoj5g/2/

Styling:

This is the area where you can make the widget look beautiful with CSS. If you want to style the marker you can use ::-webkit-details-marker pseudo class  -
details{
    border: 1px solid #666; 
    border-radius: 4px; 
    margin: 0 0 4px 0;
}
summary{ 
    background: linear-gradient(to top, #f1efef 0%, #e8e9e9 50%, #e8e8e8 100%); 
    padding: 8px; 
    outline: none; 
}
.more-info{ 
    border-top: 1px solid #666; 
    padding: 8px; 
}
details[open] summary{ 
    background: none; 
}
summary::-webkit-details-marker {
  color: #818b94;
}
Demo: http://jsfiddle.net/czs29fd3/

To replace the default marker with some fancy icon, you can use the CSS :before and :after pseudo classes with summery element, but before using a replacement for marker you must hide it first -
summary::-webkit-details-marker {
  display: none; /*Hide the default marker*/
}
summary:after {  
  content: "+";   
  float: left; 
  font-size: 1em; 
  font-weight: bold;       
  width: 22px;
}
details[open] summary:after {
  content: "-";
}
What about the browsers that don't support details element?
Use this Bulletproof HTML5 <details> fallback using jQuery by @MathiasBynens

Browser Support:

You can see the latest browser support at caniuse.com




Monday, August 18, 2014

Understanding HTML5 Pattern Attribute

What is HTML5 Pattern?
The HTML5 pattern attribute is nothing but a JavaScript Regular Expression. It is used to match form field's value against the specified format. Patterns are used to validate email addresses, dates, credit card numbers, zip codes and so on.

For example, the following pattern requires one number and three uppercase character, if you didn't enter the said format it will prompt you with a message:
  pattern="[0-9][A-Z]{3}"
Demo: http://jsfiddle.net/aoq22s54/

Similarly, if you have a field to accept only five numeric values, use this pattern:
pattern="\d{5}" in this pattern the '\d' stands for numeric values and '{5}' to accept only five characters.
Demo: http://jsfiddle.net/fhcox947/

Let's validate a DD/MM/YYYY date format:
Here's the pattern we need to use for validating this date format - pattern="(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[0-2])\/\d{4}" 

The first section of this pattern (0[1-9]|[12][0-9]|3[01]) says - use 0 before the first value 1-9 except when the first value is 1/2, and use 0-9 after the first 1/2 value, and when the first values is 3 use only 0/1 after it. Sounds simple? I guess yes :)
Demo: http://jsfiddle.net/j8qpe3ca/

I hope you have understood how the patterns work—please refer this HTML5 pattern website for some common regular expression styles.


Monday, August 11, 2014

Language Specific CSS - The :lang attribute

Do you know the German words are much longer than English? And the Arabic language is read from right-to-left? How about using different font family for Chinese version of your website? Oh! That would be awesome! Can I achieve that via CSS?

Yes! With the help of the :lang(X) pseudo class and with the [lang="x"] attribute selector.
body{ 
 font: normal 14px/1.1em "Lucida Sans Unicode", "Lucida Sans", Arial, Verdana, sans-serif;
 color: RoyalBlue;
}

/*For German version*/
:lang(de) body{ /*or - html[lang="de"] body{}*/
  color: ForestGreen;
}
A demo without the lang attribute: http://jsfiddle.net/a5Ltfge0/
A demo with German version: http://jsfiddle.net/2nkmjzv6/

We can also use it with any container element such as: div, section, article, span and so on. For example
German Content
span[lang="de"]{
  color: red;
}

Sunday, July 13, 2014

Installing Grunt and Plugins

Installing Grunt Task Runner is simple enough when you know how to install it, but it's quite frustrating when you are installing it the first time. Once you started using grunt, you will never leave it. Here are some simple steps to install and run.

1. Download and install NodeJS from here.
Once you are done with the installation of NodeJS, create folder somewhere on your hard-drive and name it as first-grunt-project. Now, create a project structure inside the first-grunt-project folder as:
-first-grunt-project
  -- dev
     -- js 
     -- styles
        -- less 
           -- variables.less 
           -- colors.less 
           -- style.less /*we need to import all less files in this file with @import "variables.less" and so on
     -- css 
        -- style.css 
     -- index.html 
Now right click inside the root folder that is first-grunt-project and select the option Open command window here. Since you have already installed NodeJS just verify the version with a command node --version that should show you the NodeJS version you have installed.

2. Create a new file called package.json and save it at the root directory:
first-grunt-project
  -- package.json
Add this code in package.json file and save it. You can check the current version of package.json here. More information on package.json can be read at the npm website.
{
  "name": "grunt-project", 
  "version": "1.2.5" 
}
3. Go to command window and type npm install -g grunt-cli, this will install the cli for you.
Note: npm stands for Node Package Manager.
And cli stands for Command Line Interface

4. Create a new js file and save it as Gruntfile.js. Add the following code in it. This code is to compile LESS files to CSS. Refer the video below for installing JavaScript plugins.
module.exports = function(grunt) {

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    less: {
      development: {
        options: {
          compress: true,
          yuicompress: true,
          optimization: 2
        },
        files: {
          // target.css file: source.less file
          "styles/style.css": "styles/less/styles.less"
        }
      }
    },
    watch: {
      styles: {
        files: ['styles/less/**/*.less'], // which files to watch
        tasks: ['less'],
        options: {
          nospawn: true
        }
      }
    }
});

//plugins
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');

//tasks
grunt.registerTask('default', ['less','watch']);
};
5. Go to command window and type npm install grunt --save-dev this will install grunt for you.

You are ready with the installation of grunt, you can confirm that by running grunt --version command. After installing grunt, install the two plugins we are using in the gruntfile.js above for compiling LESS file - that are contrib less and contrib watch.

Videos:
All about packge.json and gruntfile.js:


All about creating a basic project with Grunt:


Create another folder and try with installing grunt first and the cli and then the next steps from here - http://ericnish.io/blog/compile-less-files-with-grunt and see the effect


Saturday, June 21, 2014

Need a candidate who can control DOM

Document Object Model (DOM) is an Application Programming Interface (API) for HTML and XML. I was reading this article at Mozilla Developer Network (MDN) and it has mentioned that DOM is a fully object-oriented representation of web page and we can modify its content and control the visual representation (CSS/styling) by using client side scripting languages like JavaScript.

If the DOM can be controlled by JavaScript for both modifying the content and to control its visual appearance then why a front-end developer is always deprived from writing JavaScript? You may say: No. He/she writes JavaScript for showing/hiding elements, and to create a modal dialog, or to develop some widgets like tabs and accordions. But, we never let him/her write business logic. Wait. That’s the point where you are under-utilizing your resources. Let them write the business logic. Everyone can learn, everyone can improve, and everyone can contribute. Just give them that opportunity—start with small.  

A front-end developer whose job is to create DOM is not allowed to control it with JavaScript and the JavaScript developer who knows very less about DOM is allowed to control it. Isn't it strange? Are we actually letting the right people do the right job, or we are making the working system more complex? Wouldn't it be great if all front-end developers know JavaScript and all JavaScript developers understand the DOM as a first step in development?

It is absolutely necessary to create such all-rounder developers in the organization itself instead of separating these two essential parts of DOM.

The requirements are changing in IT industry today. Most of the companies are looking for the candidates who have in-depth knowledge of the DOM and JavaScript. A few people succeed in it and the majority settles for the one half of it compromising the other. How can we expect such a blend when we haven’t created one?


Monday, June 16, 2014

Basic HTML structure/skeleton with CSS Flexbox Layout

We need some kind of miracle to get rid of IE8 and IE9 and start development with the IE 10+ version. I do understand—It will take some more years for it to happen. But, if you are working on a project that needs compatibility only for the latest and greatest browsers—you can start with flexbox layout right now. Most of the flexbox properties work very well in IE 10 with -ms- prefixes. Here's more on Flexible box ("Flexbox") layout in Internet Explorer 10.

Keeping the restriction in mind I thought of putting up a plain HTML page skeleton with CSS Flexbox which works as a liquid layout without any width and height properties specified.

My previous post [ CSS Flexbox explained with examples ] focuses on the real-world scenarios where the flexbox properties work as life-saver. With it, I can proudly say No to the floats, widths and heights. Also, to the overflow in some cases so that I don’t have to worry about the elements overlapping or adjusting the widths pixel-by-pixel to keep them aligned. Flexbox does it for me.

Here is a Fiddle: http://jsfiddle.net/KKp2c/5/



Related articles:
- CSS Flexbox explained with examples


Saturday, May 24, 2014

CSS Flexbox explained with examples

The CSS flexbox layout is the widely discussed/suggested/encouraged/used layout of these days. You must be wondering why? Why is that many developers give that ah! look when they are advised to use flexbox? Well, it's because it provides the most efficient way of aligning, resizing, stretching the elements in the most appropriate way. It is a big help in laying out the dynamic layouts, because it stretches and shrinks depending on the available space. No JavaScript required.

Browser Support to flexbox: http://caniuse.com/#search=flex

Here are some examples with the use cases:

1. Vertically center align content with CSS flexbox: (align-items: center | justify-content: center; )
Demo: http://jsfiddle.net/k72uf/

Vertically center aligning the content with CSS has been always a big issue for developers. From IE8 and above they could use display: table-cell; property, but the new and fancy flexbox gives more flexible way of vertically center aligning content. Here is the code:
.flex-container{
  display: flex; 
  justify-content: center; 
  align-items: center; 
  height: 350px; 
  background: LightSeaGreen; 
}
2. Flex Directions: (flex-direction: row | row-reverse | column | column-reverse;)

flex-direction: row; Demo: http://jsfiddle.net/x83Pu/ 
.flex-container{ 
  display: flex;
  flex-direction: row;
  border: 2px solid SaddleBrown; 
}
.flex-container div{
  width: 100px; 
  height: 100px; 
  margin: 4px; 
  background: chocolate;
}
.wrap{
  flex-wrap: wrap; 
  flex-flow: row wrap;
}
flex-direction: row-reverse; Demo: http://jsfiddle.net/7UBTL/1/
.flex-container{
  display: flex; 
  flex-direction: row-reverse;
}
flex-direction: column; Demo: http://jsfiddle.net/C3rdD/
.flex-container{ 
  display: flex; 
  flex-direction: column; 
  height: 350px;
  border: 2px solid SaddleBrown; 
}
.flex-container div{
  width: 50px; 
  height: 50px; 
  margin: 4px; 
  background: chocolate; 
}
.wrap{
  flex-wrap: wrap; 
  align-content: flex-start;
}
The reverse property for columns works same as the row-reverse.

3. Item orders: (order: integer)
By default the flex items are placed in source code order. The order property helps in controlling the order by which the child elements are placed in the flex container.
Demo: http://jsfiddle.net/z96C7/
.container{
  display: flex; 
  flex-direction: row; 
  border: 2px solid SaddleBrown;
}
.container *{ 
  background: ForestGreen; 
  color: white; 
  margin: 4px;
  flex-basis: 100px;
}
.container header{ order: 3; } 
.container nav{ order: 1; }
.container article{ order: 2; }

4. Alignments: (justify-content | align-items | align-self)

justify-content: (flex-start | flex-end | center | space-between | space-around | inherit)
Demo: http://jsfiddle.net/Kj9KY/
.flex{
  display: flex; 
  margin: 0 0 30px 0;
  border: 2px solid ForestGreen;
}
.flex div{ 
  background: OliveDrab; 
  color: white; 
  width: 50px; 
  height: 50px; 
  margin: 4px; 
}

.start{ justify-content: flex-start; }
.end{ justify-content: flex-end; }
.center{ justify-content: center; }
.space-between{ justify-content: space-between; }
.space-around{ justify-content: space-around; }
align-items: (flex-start | flex-end | center | baseline | stretch)
Demo: http://jsfiddle.net/2x4Xq/1/
.flex{
  display: flex; 
  flex-direction: column;
  margin: 0 0 30px 0; 
  height: 300px;
  border: 2px solid ForestGreen;
}
.flex div{  
  background: OliveDrab; 
  color: white; 
  height: 50px; 
  width: 50px; 
  margin: 4px; 
}

.start{ align-items: flex-start; }
.end{ align-items: flex-end; }
.center{ align-items: center; }
.baseline{ align-items: baseline; }
.stretch{ align-items: stretch; }
5. flex-basis:
It specifies the initial size of the flex items. But, its behavior depends on the flex-direction property. If the flex-direction is set to row--the initial size works as width, and if the direction is set to column--the initial size works as column.
Demo: http://jsfiddle.net/3Lamd/
.flex{
  display: flex; /*flex-direction: row;*/
  border: 2px solid ForestGreen; 
  margin: 0 0 30px 0;
}
.flex div{  
  flex-basis: 100px;
  background: OliveDrab;
  color: white; 
  margin: 4px; 
}
.column{ flex-direction: column;  }
6. flex-grow:
Demo: http://jsfiddle.net/V7hA3/
.flex{
  display: flex; 
  border: 2px solid ForestGreen;
}
.flex div{  
  flex-basis: 50px;
  background: OliveDrab; 
  color: white; 
  margin: 4px; 
}
.grow{ flex-grow: 3; }
7. flex-shrink:
Demo: http://jsfiddle.net/GyBjQ/
.flex{
  display: flex; 
  border: 2px solid ForestGreen;
}
.flex div{  
  flex-basis: 200px;
  background: OliveDrab; 
  color: white; 
  margin: 4px;
}
.shrink{ flex-shrink: 3; }
There are a few more properties like: align-self | flex-wrap | flex-flow. I have used some of these properties in the examples above, I will put some examples of these soon possible.

Monday, April 21, 2014

Best shorthand to CSS border property

When I started coding CSS I coded the border property as:
.box{ 
  border-width: 1px;
  border-style: solid;
  border-color: blue;
}
And after a few months later I improved in coding the same property as shorthand:
.box{
  border: 1px solid blue;
}
If the border colors needed to be different, or if the requirement is like - I need left, right, and top borders but not the bottom border. To this, I used the property as:
.box{ 
  border-top: 1px solid blue;
  border-left: 1px solid blue;
  border-right: 1px solid blue;
  border-bottom: 0 none;
}
The above method can be improved with the new/unknown CSS border shorthand:
.box{
  border-color: blue;
  border-style: solid;
  border-width: 1px 1px 0 1px; /*top right bottom left*/
}
Check the demo: http://jsfiddle.net/X3QHc/

Here's how it works: 
.box{
  border-color: red green blue black; /*top right bottom left*/
  border-style: solid dotted dashed double;
  border-width: 6px 4px 2px 10px;
}
Check the demo: http://jsfiddle.net/X3QHc/1/

Related Articles: 
- Styling input type file
- IE 7/8 stretching background image to 100% width and height
- Change parent elements background image position on child mouseover


Thursday, April 10, 2014

jQuery modal dialog popup window without plugin

I just googled for jQuery Modal dialog window and to my surprise, I saw some links that redirected me to some jQuery plugins which is not necessary for such a small task. I didn't see a pain and easy to understand solution to it. So I decided to put it up in this post.
 
Here's a simple jQuery Modal Dialog Popup Window that even works in IE7: Demo



Related Articles:
- IE 7/8 stretching background image to 100% width and height
- HTML - DIV vertically center align image/elements
- jQuery increase/decrease number in input field

Tuesday, April 8, 2014

AngularJS show hide html elements

AngularJS is becoming more popular in web application development day by day. And it is not as simple as jQuery. Its main focus is not DOM manipulation, but it's more in Data manipulation, and is more logical. It teaches all jQuery developers a more sophisticated way of coding where the developers understand the next level of OOP.

I miss jQuery a lot. Especially, the handy methods like show() hide(). If we want to get the same effect with AngularJS, we have to put some logic in controllers and implement it with ng-click, ng-class, ng-show, ng-hide. In this post I will write some simple and easy to understand examples for this most needed ng-hide and ng-show methods .

Show Hide DIV on Click: Demo



Toggle DIV : Demo 



Toggle DIV with Animations: Demo



Related Articles:
- AngularJS Add Class and Toggle Class
- AngularJS Toggle Class with Animation