Friday, July 18, 2014

Creating the table structure using divs:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
.genral .table { display: table; width: 100%; border:1px solid #ff0000;  }
.genral .row {  display: table-row; }
.genral .tabledata { display: table-cell; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}
</style>

</head>

<body>

<table>
    <tr>
        <td></td>
        <td></td>
        <td></td>
    </tr>
</table>
<div class="genral">
    <div class="table">
        <div class="row">
            <div class="cell"></div>
            <div class="cell"></div>
            <div class="cell"></div>
            <div class="cell"></div>
        </div>
    </div>
</div>

</body>
</html>

Creating the forms using div with table structure side by side:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
.genral .table { display: table; width: 100%; border:1px solid #ff0000; border-radius:10px; }
.genral .row {  display: table-row; }
.genral .cell { display: table-cell; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}
.cell-1-width{ width:300px;}
.cell-2-width{ width:20px;}
.text-field-css{ border:1px solid #cccccc; width:250px; border-radius:5px; height:22px; margin-bottom:20px; background-color:#FFFFFF; margin-top:5px;}
</style>
</head>
<body>
<div class="genral">
    <div class="table">
        <div class="row">
            <div class="cell cell-1-width">User Name<br /><input name="" type="text" class="text-field-css" /></div>
            <div class="cell">password<br /><input name="" type="text" class="text-field-css" /></div>
        </div>
       
        <div class="row">
            <div class="cell cell-1-width">User Name<br /><input name="" type="text" class="text-field-css" /></div>
            <div class="cell">password<br /><input name="" type="text" class="text-field-css" /></div>
        </div>
       
        <div class="row">
            <div class="cell cell-1-width">User Name<br /><input name="" type="text" class="text-field-css" /></div>
            <div class="cell">password<br /><input name="" type="text" class="text-field-css" /></div>
        </div>
       
        <div class="row">
            <div class="cell cell-1-width">User Name<br /><input name="" type="text" class="text-field-css" /></div>
            <div class="cell">password<br /><input name="" type="text" class="text-field-css" /></div>
        </div>
           
       
       
  <!--     /*  <div class="row">
            <div class="cell"><input name="Submit" type="button" value="Submit" /></div>
        </div>
        */
        -->
       
       
    </div>
</div>
</body>
</html>

Creating the forms using div with table structure secondway:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
.genral .table { display: table; width: 100%; border:1px solid #ff0000; border-radius:10px; }
.genral .row {  display: table-row; }
.genral .cell { display: table-cell; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}
.cell-1-width{ width:90px;}
.cell-2-width{ width:20px;}
.text-field-css{ border:1px solid #cccccc; width:250px; border-radius:5px; height:22px; margin-bottom:20px; background-color:#FFFFFF; margin-top:5px;}
</style>
</head>
<body>
<div class="genral">
    <div class="table">
        <div class="row">
            <div class="cell cell-1-width">User Name</div>
        </div>
        <div class="row">
            <div class="cell"><input name="" type="text" class="text-field-css" /></div>
        </div>
       
         <div class="row">
            <div class="cell cell-1-width">Password</div>
        </div>
        <div class="row">
            <div class="cell"><input name="" type="text" class="text-field-css" /></div>
        </div>
       
         <div class="row">
            <div class="cell cell-1-width">Email Id</div>
        </div>
        <div class="row">
            <div class="cell"><input name="" type="text" class="text-field-css" /></div>
        </div>
       
         <div class="row">
            <div class="cell"><input name="Submit" type="button" value="Submit" /></div>
        </div>

    </div>
</div>
</body>
</html>

Creating the forms using div with table structure:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
.genral .table { display: table; width: 80%; border:1px solid #ff0000; border-radius:10px; margin:0 auto;}
.genral .row {  display: table-row; }
.genral .cell { display: table-cell; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; padding:5px 5px 5px 5px}
.genral .cell-1-width{ width:90px;}
.genral .cell-2-width{ width:20px;}
</style>
</head>
<body>
<div class="genral">
    <div class="table">
        <div class="row">
            <div class="cell cell-1-width">User Name</div>
            <div class="cell cell-2-width">:</div>
            <div class="cell"><input name="" type="text" /></div>
        </div>
       
        <div class="row">
            <div class="cell">Password</div>
            <div class="cell">:</div>
            <div class="cell"><input name="" type="text" /></div>
        </div>
       
        <div class="row">
            <div class="cell">Email Id</div>
            <div class="cell">:</div>
            <div class="cell"><input name="" type="text" /></div>
        </div>
       
        <div class="row">
            <div class="cell"></div>
            <div class="cell"></div>
            <div class="cell"><input name="Submit" type="button" value="Submit" /></div>
        </div>
    </div>
</div>
</body>
</html>

Friday, May 23, 2014

unit testing using karma in angularjs, steps to install karma to create the testcases in angularjs

open cmd prompt and paste the below command and click eneter

npm install -g karma   ---> to install the karma

after take the path of Test Folder created in our project above ( i.e copy the path of Test folder )

Then goto again cmd prompt...cd here pate the path and click enter

again cmd prompt paste the below command and click enter it will ask few qiestions like jsamine yes  require.js no then 3 times enter


karma init karma.conf.js  ---> here we it is used to create the configuration file, in this we need to specify the folder paths
                                angular.js, angular-mock.js ( this file also required to testing. )


then goto Test folder here karma.config.js file is created, inside this file,

find the filles:[  here we need to specify the paths of angular.js angular-mockup.js paths and our test files created by us ]

Then if we want to run our test cases in cmd prompt paste the below command and click enter it will automaticxally execute the test cases written by us.

karma start karma.conf.js  ---> to run karma i.e executing our test cases.


Note:
ng--sounds like angular that's why called ng

from html angle brackets name given angularjs

Monday, May 5, 2014

AngularJS Directives

Directive Properties
In the previous mySharedScope directive a single property named template was defined in the object literal returned from the function. This property is responsible for defining the template code (a data binding expression in this case) that should be used to generate HTML. What other properties are available to use?
Custom directives will typically return an object literal that is responsible for defining properties needed by the directive such as templates, a controller (if one is used), DOM manipulation code, and more. Several different properties can be used (you’ll find a complete list of them here). Here’s a look at a few of the key properties that you may come across and an example of using them:

angular.module('moduleName')
    .directive('myDirective', function () {
    return {
        restrict: 'EA', //E = element, A = attribute, C = class, M = comment         
        scope: {
            //@ reads the attribute value, = provides two-way binding, & works with functions
            title: '@'         },
        template: '<div>{{ myVal }}</div>',
        templateUrl: 'mytemplate.html',
        controller: controllerFunction, //Embed a custom controller in the directive
        link: function ($scope, element, attrs) { } //DOM manipulation
    }
});

A short explanation of each of the properties is shown next:

PropertyDescription
restrictDetermines where a directive can be used (as an element, attribute, CSS class, or comment).
scopeUsed to create a new child scope or an isolate scope.
templateDefines the content that should be output from the directive. Can include HTML, data binding expressions, and even other directives.
templateUrlProvides the path to the template that should be used by the directive. It can optionally contain a DOM element id when templates are defined in <script> tags.
controllerUsed to define the controller that will be associated with the directive template.
linkFunction used for DOM manipulation tasks.

Manipulating the DOM

In addition to performing data binding operations with templates (and there’s much more to that story that I’ll cover in future posts!), directives can also be used to manipulate the DOM. This is done using the link function shown earlier.
The link function normally accepts 3 parameters (although others can be passed in some situations) including the scope, the element that the directive is associated with, and the attributes of the target element. An example of a directive that handles click, mouseenter, and mouseleave events on an element is shown next:

app.directive('myDomDirective', function () {
    return {
        link: function ($scope, element, attrs) {
            element.bind('click', function () {
                element.html('You clicked me!');
            });
            element.bind('mouseenter', function () {
                element.css('background-color', 'yellow');
            });
            element.bind('mouseleave', function () {
                element.css('background-color', 'white');
            });
        }
    };
});

To use the directive you can add the following code into the view:

<div my-dom-directive>Click Me!</div>

As the mouse enters or leaves the <div> the background color will change between yellow and white (yes, embedded styles are used in this simple example but CSS classes can certainly be used as well). When the target element is clicked the inner HTML is changed to “You clicked me!”. There’s of course much, much more you can do when it comes to DOM manipulating but this should help get you started.

Structuring AngularJS Directive Code

Although the mySharedScope and myDomDirective directives work fine, I like to follow a specific pattern when defining directives and other AngularJS components. Here’s an example:

(function () {

    var directive = function () {
        return {

        };
    };

    angular.module('moduleName')
        .directive('directiveName', directive);

}());

This code wraps everything with an immediately invoked function to pull everything out of the global scope. It then defines the directive functionality in a function assigned to the directivevariable. Finally, a call is made to the module’s directive() function and the directive variable is passed in. There are several other techniques that can be used to structure code (see my previous post on the subject) but this is the general pattern I like to follow.

Summary

In this first post on AngularJS directives you’ve seen some of the fundamentals and learned how to create two basic directives. We’ve barely scratched the surface though! In the next post I’ll discuss isolate scope and different properties referred to as local scope properties that can be used for data binding and much more.

Increase decrease font size using jquery


http://tympanus.net/codrops/2013/08/09/building-a-circular-navigation-with-css-transforms/

http://www.programming-free.com/2013/12/increase-decrease-font-size-jquery.html

Angularjs Builtin Filters

Filters can be applied to an expression name followed by "|" symbol. You can apply multiple filters to the same expression.


<!DOCTYPE html>
<html ng-app="filterModule">
<head>
<script type="text/javascript"
  src="lib/angularjs.min.js"></script>
</head>
<body>
<div ng-controller="FilterController">
<h4>orderBy Filter</h4>
 <div class="filterDemos">
  <table>
   <thead>
   <th>Name</th>
   <th>Designation</th>
   </thead>
   <tbody>
   <tr ng-repeat="employee in employees | orderBy:'name'">
   <td>{{employee.name}}</td>
   <td>{{employee.designation}}</td>
   </tr>
   </tbody>
  </table>
 </div>
<h4>limitTo Filter</h4>
        <div class="filterDemos">
  <table>
   <thead>
   <th>Name</th>
   <th>Designation</th>
   </thead>
   <tbody>
   <tr ng-repeat="employee in employees | limitTo:5">
   <td>{{employee.name}}</td>
   <td>{{employee.designation}}</td>
   </tr>
   </tbody>
  </table>
 </div>
<h4>lowercase and uppercase Filter</h4>
        <div class="filterDemos">
  <table class="table table-hover table-bordered table-striped">
  <thead>
  <th>Name</th>
  <th>Designation</th>
  </thead>
  <tbody>
  <tr ng-repeat="employee in employees">
  <td>{{employee.name | uppercase}}</td>
  <td>{{employee.designation | lowercase}}</td>
  </tr>
  </tbody>
  </table>
  <img src="img/angularjs_filters_3.png"/>
  

 </div>
<h4>search Filter</h4>  
 <div class="filterDemos">
  <p>Search: <input type="text" ng-model="searchText"/></p>
  <table>
   <thead>
   <th>Name</th>
   <th>Designation</th>
   </thead>
   <tbody>
   <tr ng-repeat="employee in employees | filter:searchText">
   <td>{{employee.name}}</td>
   <td>{{employee.designation}}</td>
   </tr>
   </tbody>
  </table> 
 </div>
<h4>currency Filter</h4>
 <div class="filterDemos">
  <p>Enter Amount: <input type="text" ng-model="amount"/></p>  
  <p>Amount with default currency <span style="color:red">{{amount | currency}}</span></p>
  <p>Amount with Indian currency <span style="color:red">{{amount | currency: "Rs."}}</span></p>
 </div>
<h4>number Filter</h4>      
 <div class="filterDemos" style="text-align:center">
  <p>Enter Number: <input type="text" ng-model="number"/></p>
  <h5>Rounded number with no decimal places: <span style="color:red">{{number | number:0}}</span></h5>
  <h5>Number with 4 decimal places <span style="color:red">{{number | number:4}}</span></h5>
 </div>
<h4>date Filter</h4>
    <div class="filterDemos">
  <h5>Format equivalent to 'M/d/yy h:mm a' for en_US locale  <span style="color:red">{{ 1288323623006 | date:'short'}}</span></h5>
  <h5>Format equivalent to 'MM/dd/yyyy @ h:mma' <span style="color:red">{{ 1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span></h5>
 </div>     
</div>
<script type="text/javascript">
 var filterModule = angular.module('filterModule', []);
    filterModule.controller('FilterController', function($scope) {
  $scope.amount='100';
  $scope.number='1234.5678';
  $scope.employees=[{ name:'Priya',designation:'Manager'},
                    { name:'Naveen',designation:'Tester'},
        { name:'Anita',designation:'Programmer'},
        { name:'Mike',designation:'BA'},
        { name:'John',designation:'Admin'},
        { name:'Alice',designation:'Tester'},
                    { name:'Gracia',designation:'Senior Manager'}];
    });
</script>
</body>
</html>
We have a model with employee details and we have used angularjs filters to format the data being displayed in the view.

orderBy 

orderBy filter can be used to sort an array of items. 

1<!-- To sort in ascending order -->
2<tr ng-repeat="employee in employees | orderBy:'name'">
3<!-- To sort in descending order -->
4<tr ng-repeat="employee in employees | orderBy:'name':true">

limitTo

limitTo filter can be used to limit the number of items to be displayed in an array of items.

1<tr ng-repeat="employee in employees | limitTo:5">

lowercase & uppercase

Transforms text to lowercase or uppercase.

1<tr ng-repeat="employee in employees">
2  <td>{{employee.name | uppercase}}</td>
3  <td>{{employee.designation | lowercase}}</td>
4</tr>

filter

Enables search through an array of items. 

1<input type="text" ng-model="searchText"/>
2<tr ng-repeat="employee in employees | filter:searchText">

currency

Adds currency symbol to a given number. When no currency symbol is provided, the default symbol for current locale is used.
1<span>{{amount | currency}}</span>
2<span>{{amount | currency: "Rs."}}</span>

number

This can be used to format number values - rounds a decimal number, makes it a negative number, fix number of decimal places to display.

1<h5>Rounded number with no decimal places: {{number | number:0}}</h5>
2<h5>Number with 4 decimal places :{{number | number:4}}</h5>

date

Formats date in various formats. You can find various date formats here.

1<h5>Format equivalent to 'M/d/yy h:mm a' for en_US locale{{ 1288323623006 | date:'short'}}</h5>
2<h5>Format equivalent to 'MM/dd/yyyy @ h:mma'{{ 1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</h5>

json

Converts javascript objects to json.

1<pre>{{ {'name':'value'} | json }}</pre>

Output

{ "name": "value" }