angular-linkify
Advanced tools
Comparing version 0.4.0 to 1.0.0
@@ -13,9 +13,9 @@ angular.module('linkify', []); | ||
var _text = _str.replace( /(?:https?\:\/\/|www\.)+(?![^\s]*?")([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/ig, function(url) { | ||
var wrap = document.createElement('div'); | ||
var anch = document.createElement('a'); | ||
anch.href = url; | ||
anch.target = "_blank"; | ||
anch.innerHTML = url; | ||
wrap.appendChild(anch); | ||
return wrap.innerHTML; | ||
var wrap = document.createElement('div'); | ||
var anch = document.createElement('a'); | ||
anch.href = url; | ||
anch.target = "_blank"; | ||
anch.innerHTML = url; | ||
wrap.appendChild(anch); | ||
return wrap.innerHTML; | ||
}); | ||
@@ -30,5 +30,6 @@ | ||
if (type === 'twitter') { | ||
_text = _text.replace(/(|\s)*@(\w+)/g, '$1<a href="https://twitter.com/$2" target="_blank">@$2</a>'); | ||
_text = _text.replace(/(^|\s)*#(\w+)/g, '$1<a href="https://twitter.com/search?q=%23$2" target="_blank">#$2</a>'); | ||
_text = _text.replace(/(|\s)*@([a-zA-Z0-9àáâãäåçèéêëìíîïðòóôõöùúûüýÿñ_-]+)/g, '$1<a href="https://twitter.com/$2" target="_blank">@$2</a>'); | ||
_text = _text.replace(/(^|\s)*#([a-zA-Z0-9àáâãäåçèéêëìíîïðòóôõöùúûüýÿñ_-]+)/g, '$1<a href="https://twitter.com/search?q=%23$2" target="_blank">#$2</a>'); | ||
} | ||
@@ -35,0 +36,0 @@ // Github |
/* | ||
angular-linkify - v0.4.0 - 7/7/2014 | ||
angular-linkify - v1.0.0 - 9/16/2014 | ||
Angular filter to linkify urls, "@" usernames, and hashtags. | ||
Copyright (c) 2014 ; Licensed | ||
*/ | ||
angular.module("linkify",[]),angular.module("linkify").filter("linkify",function(){"use strict";function linkify(_str,type){if(_str){var _text=_str.replace(/(?:https?\:\/\/|www\.)+(?![^\s]*?")([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/gi,function(url){var wrap=document.createElement("div"),anch=document.createElement("a");return anch.href=url,anch.target="_blank",anch.innerHTML=url,wrap.appendChild(anch),wrap.innerHTML});return _text?("twitter"===type&&(_text=_text.replace(/(|\s)*@(\w+)/g,'$1<a href="https://twitter.com/$2" target="_blank">@$2</a>'),_text=_text.replace(/(^|\s)*#(\w+)/g,'$1<a href="https://twitter.com/search?q=%23$2" target="_blank">#$2</a>')),"github"===type&&(_text=_text.replace(/(|\s)*@(\w+)/g,'$1<a href="https://github.com/$2" target="_blank">@$2</a>')),_text):""}}return function(text,type){return linkify(text,type)}}).factory("linkify",["$filter",function($filter){"use strict";function _linkifyAsType(type){return function(str){return $filter("linkify")(str,type)}}return{twitter:_linkifyAsType("twitter"),github:_linkifyAsType("github"),normal:_linkifyAsType()}}]).directive("linkify",["$filter","$timeout","linkify",function($filter,$timeout,linkify){"use strict";return{restrict:"A",link:function(scope,element,attrs){var type=attrs.linkify||"normal";$timeout(function(){element.html(linkify[type](element.html()))})}}}]); | ||
angular.module("linkify",[]),angular.module("linkify").filter("linkify",function(){"use strict";function linkify(_str,type){if(_str){var _text=_str.replace(/(?:https?\:\/\/|www\.)+(?![^\s]*?")([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/gi,function(url){var wrap=document.createElement("div"),anch=document.createElement("a");return anch.href=url,anch.target="_blank",anch.innerHTML=url,wrap.appendChild(anch),wrap.innerHTML});return _text?("twitter"===type&&(_text=_text.replace(/(|\s)*@([a-zA-Z0-9àáâãäåçèéêëìíîïðòóôõöùúûüýÿñ_-]+)/g,'$1<a href="https://twitter.com/$2" target="_blank">@$2</a>'),_text=_text.replace(/(^|\s)*#([a-zA-Z0-9àáâãäåçèéêëìíîïðòóôõöùúûüýÿñ_-]+)/g,'$1<a href="https://twitter.com/search?q=%23$2" target="_blank">#$2</a>')),"github"===type&&(_text=_text.replace(/(|\s)*@(\w+)/g,'$1<a href="https://github.com/$2" target="_blank">@$2</a>')),_text):""}}return function(text,type){return linkify(text,type)}}).factory("linkify",["$filter",function($filter){"use strict";function _linkifyAsType(type){return function(str){return $filter("linkify")(str,type)}}return{twitter:_linkifyAsType("twitter"),github:_linkifyAsType("github"),normal:_linkifyAsType()}}]).directive("linkify",["$filter","$timeout","linkify",function($filter,$timeout,linkify){"use strict";return{restrict:"A",link:function(scope,element,attrs){var type=attrs.linkify||"normal";$timeout(function(){element.html(linkify[type](element.html()))})}}}]); |
{ | ||
"name": "angular-linkify", | ||
"version": "0.4.0", | ||
"version": "1.0.0", | ||
"main": "angular-linkify.js", | ||
@@ -5,0 +5,0 @@ "description": "Angular filter to linkify urls, \"@\" usernames, and hashtags.", |
{ | ||
"name": "angular-linkify", | ||
"version": "0.4.0", | ||
"version": "1.0.0", | ||
"description": "Angular filter to linkify urls, \"@\" usernames, and hashtags.", | ||
@@ -5,0 +5,0 @@ "main": "angular-linkify.js", |
@@ -1,2 +0,2 @@ | ||
# angular-linkify | ||
l# angular-linkify | ||
@@ -22,12 +22,2 @@ Angular filter, directive, and service to linkify text. As of **v0.3.0**, angular-linkify works for twitter/github mentions, twitter hashtags, and basic urls. | ||
```html | ||
<!-- As a filter --> | ||
<div ng-controller="SomeCtrl"> | ||
<div ng-bind-html-unsave="someValue | linkify"></div> <!-- linkified!! --> | ||
</div> | ||
<!-- As a filter, with twitter parsing --> | ||
<div ng-controller="SomeCtrl"> | ||
<div ng-bind-html-unsave="someValue | linkify:'twitter'"></div> <!-- linkified!! --> | ||
</div> | ||
<!-- As a directive, no twitter --> | ||
@@ -44,11 +34,13 @@ <div ng-bind="someModel" linkify></div> | ||
// Injected into controller | ||
angular.module('someModule').controller('SomeCtrl', function ($scope, linkify) { | ||
angular.module('someModule').controller('SomeCtrl', function ($scope, linkify, $sce) { | ||
var text = "@scottcorgan and http://github.com"; | ||
$scope.text = linkify.twitter(text); | ||
// Must use $sce.trustAsHtml() as of Angular 1.2.x | ||
$scope.text = $sce.trustAsHtmllinkify.twitter(text)); | ||
// outputs: <a href="https://twitter.com/scottcorgan" target="_blank">scottcorgan</a> and <a href="http://github.com" target="_blank">http://github.com</a> | ||
// Github | ||
$scope.text = linkify.github(text); | ||
// Must use $sce.trustAsHtml() as of Angular 1.2.x | ||
$scope.text = $sce.trustAsHtml(linkify.github(text)); | ||
// outputs: <a href="https://github.com/scottcorgan" target="_blank">scottcorgan</a> and <a href="http://github.com" target="_blank">http://github.com</a> | ||
@@ -55,0 +47,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8842
9
2
55