Saturday, 22 November 2014

plugin for Multiline ellipsis which supports all browsers using Angular js in HTML5

                     In this post we are going to see about the multiline ellipses support in all browsers, normally when we have a huge text in a span or div, but we didn't have a space to display it, due to the overflow instead of displaying the full text we are decide to show a ellipses text with certain number of lines along with ... character, but normally ellipses supports in single line for all browsers. when overflow occurs.But for a multiline ellipses so many browsers doesnt have support especially IE, in Chrome we have a support for multiline ellipses. now we are going to see how to achieve a multiline ellipses in all browsers as common one. For this we have to use a angular plugin or module




rgClamp:
**********


/**
 * Created by Rajesh on 22-11-2014.
 */


angular.module('rgModule', []).directive('rgClamp', function () {

    return {

        scope: {

            rgClamp: '='

        },

        restrict: 'A',

        link: function (scope, element, attrs, cntrl) {

            var elementheight = 0;

            var lineheight = 0;

            var maxlines = 0;

            var prefferedHeight = 0;

            var truncatedHeight = 0;

            var originalData = element.text();

            var truncatedData = '';

            var datachunks = [];

            var chunkno = 0;


            elementHeight();

            getLineHeight();

            getMaxLines();

            getPreferredHeight();

            //setElementHeight();

            SplitData();

            ellipsisData();

            setEllipsis();

            truncatedHeight = elementheight;
            chunkno = datachunks.length;


            function setElementHeight() {

                element.css('height', prefferedHeight);

            }
            function getPreferredHeight() {

                prefferedHeight = Math.max(Math.round(scope.rgClamp * lineheight), 0);

            }



            function getMaxLines() {

                maxlines = Math.max(Math.floor(elementheight / lineheight), 0);

            }



            function getLineHeight() {

                lineheight = getProp('line-height');

                if (lineheight == 'normal') {

                    lineheight = parseInt(getProp('font-size')) * 1.2;

                } else {
                    lineheight = parseInt(lineheight);

                }
            }


            function getProp(prop) {
                return element.css(prop);
            }


            function elementHeight() {
            elementheight = element.height() || element.maxHeight || element.clientHeight;

            }


            function SplitData() {
                datachunks = originalData.split(' ');
            }


            function setEllipsis() {
                /* clamping words */
                while (truncatedHeight <= prefferedHeight) {

                    if (datachunks[chunkno] == undefined) {
                        break;

                    }

                    var clampedtext = element.text();
                    element.text(clampedtext + ' ' + datachunks[chunkno]);
                    elementHeight();
                    truncatedHeight = elementheight;

                    if (truncatedHeight > prefferedHeight) {

                        element.text(clampedtext);
                        break;

                    }
                    chunkno++;

                }



                /* clamping letters */

                var letterchunks = datachunks[chunkno].split('');

                var clampedtext = element.text();

                for (var j = 0; j < letterchunks.length; j++) {
                    element.text(clampedtext + letterchunks[j]);
                    elementHeight();
                    truncatedHeight = elementheight;

                    if (truncatedHeight > prefferedHeight) {
                      element.text(element.text().substring(0, element.text().length - 1));
                        break;

                    }
                }

                clampedtext = element.text();
                element.text(clampedtext.substring(0, clampedtext.length - 4) + '...');

            }



            /* truncated height must be equal or less than preffered height */

            function ellipsisData() {
                truncatedHeight = elementheight;
                chunkno = datachunks.length;

                while (truncatedHeight > prefferedHeight) {

                    if (prefferedHeight <= (truncatedHeight / 2)) {
                        chunkno = Math.max(Math.round(chunkno / 2), 0);
                    } else {

                        var interno = Math.max(Math.round(chunkno / 2), 0);
                        var interim = interno + Math.max(Math.round(interno / 2), 0);
                        if (interim == chunkno) {
                            chunkno = interim - 1;
                        }
                        else {
                            chunkno = interim;
                        }
                    }

                    truncatedData = '';
                    for (var i = 0; i < chunkno; i++) {
                        truncatedData += datachunks[i] + ' ';
                    }

                    element.text(truncatedData);
                    elementHeight();
                    truncatedHeight = elementheight;

                }
            }
        }
    }


});



rgModule :
****************

Download the plugin from the following link . Multiline Ellipsis plugin

1. Add the plugin in the angular module.
2. Refer the attribute rg-clamp="3"  in the element where we need ellipsis along with number of lines.

Now you can get a ellipsis text like below

Js:
**********
Add the module name in the controller rgModule and use the rg-clamp directive in the html

/**
 * Created by Rajesh on 22-11-2014.
 */

var clampModule = angular.module('clampModule', ['rgModule']);

clampModule.controller('clampController', function ($scope) {

});



HTML:
************


    <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link href="css/bootstrap.min.css" rel="stylesheet" />
</head>
<body data-ng-app="clampModule" class="bg-info">

<div ng-controller="clampController" style="margin-left:100px">

    <h1 class="well text-danger" rg-clamp="4">
The human species' use of technology began with the conversion of natural resources into simple tools. The prehistoric discovery of how to control fire increased the available sources of food and the invention of the wheel helped humans in travelling in and controlling their environment.
</h1>


    <div>
        <p class="well text-success" rg-clamp="3" style="">
Technology is the collection of tools, including machinery, modifications, arrangements and procedures used by humans. Engineering is the discipline that seeks to study and design new technologies. Technologies significantly affect human as well as other animal species' ability to control and adapt to their natural environments. The term can either be applied generally or to specific areas: examples include construction technology, medical technology and information technology
       .</p>

    </div>

</div>


<script type="application/javascript" src="js/jquery-2.0.0.min.js"></script>
<script type="application/javascript" src="js/bootstrap.min.js"></script>
<script type="application/javascript" src="js/angular.min.js"></script>
<script type="application/javascript" src="js/rgModule.js"></script>
<script src="ang/angClamp.js"></script>
<script>
</script>
</body>
</html>




Output:
******************

Text with specified lines along with ellipses ...



From this post you can see how to create a Multiline ellipses support for all browsers



Friday, 14 November 2014

Microsoft delivered a Patch for a Two decades old windows security Bug.

        Microsoft had given a patch for there customers, which consists of a patch for a security bug that exists for a two decades from the stage of when windows OS, reached the people.The Bug has been actually seen by anyone before, but now IBM research team find out the real big bug of that Microsoft products which is exists for a long term.



So What kind of Bug is this ? 
   An IBM find out a Bug earlier this year, IBM's describing this Bug has rare and unicorn-like both because it presents of all internet explorer's and windows. It is unseen for long time.

IBM team up with the Microsoft to fix, before all find it existence.This security based bug was discovered in May by IBM.

This Bug is used to remotely run a code on a computer. If a user views a malicious webpage using Internet explorer, then attackers start attacking the computer and take control the computer.

This Bug is existed in the all types of Operating systems of windows.IBM researcher Robert Freeman said in his blog post Tuesday.

Freeman is part of the IBM X-Force Research team that discovered the Bug. From the Microsoft point they had explained about this bug to the users. i.e 

A website is design to discover this Bug, This bug exploited website is visited through the IE,  then they convince the user to view the website an attacker convince user on taking action, make them to click  link in a email message , or make them to visit the website that they want to visit.

This Bug is based on IE, so the systems which uses the IE most predominantly may affect by this BUG , May be Servers, Terminal and workstations etc.


Few months back Microsoft launch the IE11 bug bounty.but now this kind of Bug makes the usage of IE in a question.






This Bug is fixed along with  others and released there patch in Tuesday earlier this Week. this Patch will install automatically for the users who make automatic updates enabled.



















Thursday, 13 November 2014

Introduction to Angular Js in HTML5

     In this Blog Post we are going to some really a interesting topic i.e Angular Js . Angular is one of the Pretty Good framework to design a single page applications quickly and more flexibly. what are single page applications ? a simple example is Gmail, you can see the Gmail it is a single page only the content can change . When i heard angular js, i see lot of keywords which is really a new keywords i.e is never heard before, when i go through the concepts it is very clearly seen that using angular we can create applications with all complex design.

what is  Angular ?
  Angular is a js , which is developed as Framework to build web applications. using angular we can create a web app with data binding in two way, importantly we can manipulate the dom at runtime, It is designed like supporting MVC , MVVM pattern in code standard.

In a Single Page Applications we have a single page as container and change the Views based on the requirement. like master page and child page in aspx.

In angular we have a cool separation of View and Code Logic, using angular we can do the following things.

1. Data Binding
2. Routing
3. Cahcing
4. Ajax/Promises
5. Dom manipulation
6. Resource Handling
7. Directives
8. Factory
9. Service
10. Provider
11. Templates
12. Controllers
13. Testing
14. Filters
15. Module

Angular uses the Dependency Injection to invoke the code logic.we have the model-view-controller concept.


First download the angular js from the following link.Angular Js
Add the script in the page <script src="angular.min.js" />


Let see some basic syntax to use the angular. Here we have to learn some new concept directives
First we have to define a module and mention in the single page application. For example now our module name is  sampleModule , This module has to be defined as ng-app="sampleModule" in the html

create a separate file sampleModule.js and wrote the following code  "ng-app"

Example

var sampleModule = angular.module('sampleModule',[]);

Here [] is used to inject the dependents like ['$compile']

in HTML ng-app="sampleModule" have to mention

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="ang/sampleModule.js"></script>
</head>
<body ng-app="sampleModule">

</body>
</html>

a page can only have a single Module.So now we have to see the controller. controller are used to write the code logic. and then refer that controller in the HTML, that controller objects can only be scope that element,  "ng-controller"


JS:
***
var sampleModule = angular.module('sampleModule',[]);

sampleModule.controller('sampleController', function ($scope) {

});


HTML:
********
<body ng-app="sampleModule">
<div>
    <div ng-controller="sampleController">
        
    </div>
</div>
</body>

Here we are injecting the $scope to the controller, to get the scope of the element.Another important directive is "ng-model"

ng-model:
*********
    <div ng-controller="sampleController">
        <input type="text"  ng-model="name"  /> {{name}}
    </div>

From the above sample we can see that ng-model directive is used in the input text control, what ng-model directive do, actually it creates a variable in that name in the memory and copies the value of that control to that variable , if you heard about Viewmodel concept before then this ng-model do the same thing hear, when ever there is a change in the variable it will reflects the controls value, or when ever there is a change in the control it will change the value of the variable, Two way binding

From this post we can see some of the basic introduction to the angular.


Monday, 3 November 2014

Create a angular notification service using notification-rg.js, which will notify the user information in the corner's of the webpage including push mechanism

In this article we are going to see how to create a notification container which will notify the user information in the corner of the webpage like in facebook notification.



To do this first we have to follow few steps

1. Link to notification-rg.css <link href="notification-rg.css" rel="stylesheet"/>

2. Link to notification-rg.js <script src="notification-rg.js"></script>

3. Inject the angularNotification in the angular module and use the service $notification in controller, and use the method open to notify

use options as input parameter to display a required notification type, if options are doesnt mention then
default will be set as options. notification returns an object which is used to addtional opertaions.

 var result= $notification.open(
            {
                position:"bottom-left",
                title:'Document Approve',
                message:mess,
                notificationType:$notification.notificationType.success,
                color:'white',
                closebutton:true,
                showspeed:1000,
                hidespeed:20000
            });

result: {messageScope: k, containerId: "#notifycontainer", notificationId: "notificationid1", 
closeId: "closenotid1", messageId: "notifymsgid1"…} including angular container object 
and jquery container object

To do the simple version of call Just call the $notification.open with few parameters like

 var result= $notification.open(
            {               
                message:'Hi Message',
                notificationType:$notification.notificationType.success,             
            });

Above sample is simple version remaining parameters are taken from default.Now we see how to create a demo project .

First download the notification-rg.js and notification-rg.css from the following links.
Download link notification-rg    including the sample demo project.

Or from the Github copy paste the code in new file
notification-rg.js
notification-rg.css
demo.html
controller.js

After download the files , add the notification-rg.js and notification-rg.css in your project.
then inject the in your module "angularNotification" and use the service like $notification in your service by injecting it.

<link href="css/notification-rg.css" rel="stylesheet">

<script type="application/javascript" src="js/jquery-2.0.0.min.js"></script>
<script type="application/javascript" src="js/angular.min.js"></script>

<script type="application/javascript" src="ang/notification-rg.js"></script>

then inject in the angular module

var notificationmodule = angular.module('notificationmodule',['angularNotification']);

notificationmodule.controller('nController', function ($scope,$rootScope,$notification) {



 });

now $notification.open method will trigger the notification in the web page , send the message we have to use the option parameter.

now we are going to see a different kind of samples to notify the message in webpage.

Simple Notification:
In simple notification we are going to see how to notify a simple message with some settings




sample code:
*****************
$scope.launch = function () {
       var result=  $notification.open(
            {
                position:"bottom-left",
                title:'',
                message:'Data is update correctly sampel code testi sas aggh .',
                notificationType:$notification.notificationType.warning,
                color:'white',
                closebutton:false,
                showspeed:200,
                hidespeed:400000,
                showeasing:'linear'
            });
        console.log(result);
    }

});



Advance Notification:
In advance notification we are going to set a some additional attributes as settings



sample code:
*****************
    var mess = '<div>Password :- <input type="password" id="pswd"                                           style="color:#000000;margin-bottom:4px;margin-top:5px"/></div>' +
                '<div style="margin-left:70px;"><button id="acceptbtn" type="button"                                 class="btn btn-primary">Accept</button>' +

                '<button type="button" class="btn btn-info" id="rejectbtn" style="margin: 0                  8px 0 8px">Reject</button></div>';



 $scope.advancelaunch = function () {
       
       var result= $notification.open(
            {
                position:"bottom-left",
                title:'Document Approve',
                message:mess,
                notificationType:$notification.notificationType.success,
                color:'white',
                closebutton:true,
                showspeed:1000,
                hidespeed:20000
            });

        var jobj = result.jObjectContainer;

        jobj.find('#acceptbtn').click(function () {
            var password = $('#pswd').val();
            console.log('Password is : '+password);
            console.log('Accepted');

        });

        jobj.find('#rejectbtn').click(function () {
            var password = $('#pswd').val();
            console.log('Password is :'+password);
            console.log('Rejected');
        });

        console.log(result);
    };


In this sample click event are called by assign the click event in the result of create notification method result using jObjectcontainer

Event Notification:
In event notification we are going to trigger an click event from the messages. using the angular and jquery





sample code:
*****************


    var ent = '<div>&nbsp; Document send for Review' +
                '<div style="float:left">Approve :- </div>' +
                '<div style="margin-left:70px">' +
                    '<div class="btn btn-xs btn-primary" ng-click="approve(\'yes\')"                                 style="margin-right:10px;margin-left:10px">Yes</div>' +
                    '<div class="btn btn-xs btn-warning" ng-                                                         click="approve(\'no\')">No</div>' +
                '</div>' +

              '</div>';

$scope.eventlaunch = function () {
        var result = $notification.open(
            {
                position:"bottom-right",
                title:'Verification',
                message:ent,
                notificationType:$notification.notificationType.information,
                color:'white',
                closebutton:true,
                hidespeed:40000
            });

        var $retscope = result.messageScope;

        $retscope.approve = function (data) {
            console.log(result);
            console.log(data);
        };

    };

In this sample click event is bind to the button by using the return object $scope value


No close button:
A notification with out close button




sample code:
*****************
   $scope.noclosebtn = function () {
        var result=  $notification.open(
            {
                position:"bottom-left",
                title:'No Close Button',
                message:'There is no correct way of declaring a object',
                notificationType:$notification.notificationType.dark,
                color:'white',
                closebutton:false,
                showspeed:2000,
                hidespeed:40000,
                showeasing:'linear'
            });

    };



No Title message
A notification with our title



Parameters in Options:

sample code:
*****************

    $scope.notitle  = function () {
        var result=  $notification.open(
            {
                position:"bottom-left",
                title:'',
                message:'Sample text to show the message of user',
                notificationType:$notification.notificationType.error,
                color:'white',
                closebutton:true,
                showspeed:500,
                hidespeed:40000,
                showeasing:'linear'
            });
    };


Output:
************


So for different kind of output, different input options , now we can see the options in detailed.
{}

position: 
*********
Defines the position of the notificaiton from where the popup will comes, sample values are  "bottom-right", "bottom-left", "top-left","top-right".

title:
*******
Define the Title of the notificatin {title:'sample title'}

message:
********
  Define the user messge to notify {message :'sample mesage'}

notificationType :
******************
  To define this we can use the predefind set of types like $notification.notificationType.error, notificationType have many values like

success,  error,  information, warning, alert, normal, dark,light,primary 

Instead of user set there own background color by sepcifying {notificationType:'#ffce34'}


color:
********
To set the fore color of the notification. {color:'white'}

closebutton:  To set whether the close button needs to visible or not {closebutton:true}
showspeed:  To set the speed , when the notification shows timeinterval
hidespeed:   To set the speed , when the notification hides time interval
showeasing:  Easing style on the showing context


For handling the events now we can see the returned object in detailed and how we can use that.
on creating a notification each one will return a object which consists of following properties
result = {}

       result.messageScope = $scope of that container
        result.containerId =  container id
        result.notificationId = notification id
        result.closeId =  close button id
        result.messageId = message container id
        result.jObjectContainer = container in jobject
        result.angularContainer = container in angular object





Test Html:
****************
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>

    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/notification-rg.css" rel="stylesheet">

</head>
<body data-ng-app="notificationmodule">


<div  style="margin-top:100px;margin-left:100px">
    <div data-ng-controller="nController">
        <div class="btn btn-info" ng-click="launch()">Simple notification</div>
        <div class="btn btn-info" ng-click="advancelaunch()">Advance notification</div>
        <div class="btn btn-info" ng-click="eventlaunch()">Event notification</div>
        <div class="btn btn-info" ng-click="noclosebtn()">No Close Button</div>
        <div class="btn btn-info" ng-click="notitle()">No Title</div>
    </div>
</div>

<script type="application/javascript" src="js/jquery-2.0.0.min.js"></script>
<script type="application/javascript" src="js/angular.min.js"></script>
<script type="application/javascript" src="ang/notification-rg.js"></script>

<script type="application/javascript" src="ang/tst.js"></script>

</body>

</html>

Test Controller:
*****************


/**
 * Created by Rajesh on 01-11-2014.
 */

var notificationmodule = angular.module('notificationmodule',['angularNotification']);

notificationmodule.controller('nController', function ($scope,$rootScope,$notification) {


    var mess = '<div>Password :- <input type="password" id="pswd"                                               style="color:#000000;margin-bottom:4px;margin-top:5px"/></div>' +
                '<div style="margin-left:70px;"><button id="acceptbtn" type="button"                          class="btn btn-primary">Accept</button>' +
                '<button type="button" class="btn btn-info" id="rejectbtn" style="margin: 0                     8px 0 8px">Reject</button></div>';

    var ent = '<div>&nbsp; Document send for Review' +
                '<div style="float:left">Approve :- </div>' +
                '<div style="margin-left:70px">' +
                    '<div class="btn btn-xs btn-primary" ng-click="approve(\'yes\')"                                style="margin-right:10px;margin-left:10px">Yes</div>' +
                    '<div class="btn btn-xs btn-warning" ng-                                                        click="approve(\'no\')">No</div>'   +
                '</div>' +
              '</div>';

    $scope.advancelaunch = function () {
       var result= $notification.open(
            {
                position:"bottom-left",
                title:'Document Approve',
                message:mess,
                notificationType:$notification.notificationType.success,
                color:'white',
                closebutton:true,
                showspeed:1000,
                hidespeed:20000
            });

        var jobj = result.jObjectContainer;

        jobj.find('#acceptbtn').click(function () {
            var password = $('#pswd').val();
            console.log('Password is : '+password);
            console.log('Accepted');

        });

        jobj.find('#rejectbtn').click(function () {
            var password = $('#pswd').val();
            console.log('Password is :'+password);
            console.log('Rejected');
        });

        console.log(result);
    };

    $scope.eventlaunch = function () {
        var result = $notification.open(
            {
                position:"bottom-right",
                title:'Verification',
                message:ent,
                notificationType:$notification.notificationType.information,
                color:'white',
                closebutton:true,
                hidespeed:40000
            });

        var $retscope = result.messageScope;

        $retscope.approve = function (data) {
            console.log(result);
            console.log(data);
        };

    };

    $scope.noclosebtn = function () {
        var result=  $notification.open(
            {
                position:"bottom-left",
                title:'No Close Button',
                message:'There is no correct way of declaring a object',
                notificationType:$notification.notificationType.dark,
                color:'white',
                closebutton:false,
                showspeed:2000,
                hidespeed:40000,
                showeasing:'linear'
            });

    };

    $scope.notitle  = function () {
        var result=  $notification.open(
            {
                position:"bottom-left",
                title:'',
                message:'Sample text to show the message of user',
                notificationType:$notification.notificationType.error,
                color:'white',
                closebutton:true,
                showspeed:500,
                hidespeed:40000,
                showeasing:'linear'
            });
    };

    $scope.launch = function () {
       var result=  $notification.open(
            {
                position:"bottom-left",
                title:'',
                message:'Data is update correctly sampel code testi sas aggh .',
                notificationType:$notification.notificationType.warning,
                color:'white',
                closebutton:false,
                showspeed:200,
                hidespeed:400000,
                showeasing:'linear'
            });
        console.log(result);
    }

});




From this post you can see how to trigger an notification in an webpage using notification-rg.js