forked from dejan/jquery-auto_html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.auto_html.js
42 lines (37 loc) · 1.41 KB
/
jquery.auto_html.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(function($) {
$.fn.link = function() {
return this.each(function() {
var text = $(this).html();
var regex = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g;
var html = text.replace(regex, '<a href="$1">$1</a> ')
$(this).html(html);
});
}
$.fn.image = function(options) {
return this.each(function() {
var opts= $.extend({width: '200px'}, options);
var text = $(this).html();
var regex = /http:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/gi
var html = text.replace(regex, "<img src='$&' alt='' width='" + opts.width + "'/>");
$(this).html(html);
});
}
$.fn.youtube = function(options) {
return this.each(function() {
var opts= $.extend({width:390, height:250}, options);
var text = $(this).html();
var regex = /http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/
var html = text.replace(regex, '<iframe class="youtube-player" type="text/html" width="' + opts.width + '" height="' + opts.height + '" src="http://www.youtube.com/embed/$2" frameborder="0"></iframe>');
$(this).html(html);
});
}
$.fn.simpleFormat = function() {
return this.each(function() {
var text = $(this).html();
var text = text.replace(/\n{2,}/g, '</p><p>');
var text = text.replace(/\n/g, '<br/>');
var text = '<p>' + text + '</p>';
$(this).html(text);
});
}
})(jQuery);