By using this plugin we can convert normal text to HTML feed like Facebook and  with links and Encoded format to avoid XSS attack. This plugin was inspired by jquery-linkify plugin and XSS prevention cheat sheet

Features :

  1. Converting URL's to Links
  2. Add user link to the words specified as '@...'
  3. Add search links to the words specified as '#...'
  4. Encode data to display as HTML  to avoid XSS attack

How it works ? : 

Installation :

<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script type='text/javascript' src='/js/jQuery.feedify.js'></script>

Usage :

var text = 'Hi my twitter account is @SodhanaLibrary #Contact me at admin@sodhanalibrary.com <script>alert("hi")</script>';

var feedified= $.feedify(text);

The output will be 

Hi my twitter account is @SodhanaLibrary #Contact me at admin@sodhanalibrary.com <script>alert("hi")</script>

Disable Features :

If you don't want to search hash links then you can disable it 
var text = "i like #jQuery";
var options = {
    hash: false
}
var feedified = $.feedify(text, options);

Add your own regular expressions to replace Text pattern :

var text = "My name is srinivas and i was born on 1990/08/25";
var options = {
    dates: {
        regex: /(^|\s)(\d{4})([- /.])(\d{2})([- /.])(\d{2})/i,
        template: '$1<span class="date">$6-$4-$2</span>'
    }
}
var feedified = $.feedify(text, options);


The output will be :

My name is srinivas and i was born on 26-08-1990

See the Pen Demo for Feedify jQuery Plugin by srinivas (@srinivasD) on CodePen.

0 comments:

Search This Blog

Loading...

Blogroll

Srinivas Dasari
find me on facebook
follow me on twitter

Follow this blog by Email

Popular Posts