This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ngSanitize): extract $sanitize, ngBindHtml, linkyFilter into a …
…module Create build for other modules as well (ngResource, ngCookies): - wrap into a function - add license - add version Breaks `$sanitize` service, `ngBindHtml` directive and `linky` filter were moved to the `ngSanitize` module. Apps that depend on any of these will need to load `angular-sanitize.js` and include `ngSanitize` in their dependency list: `var myApp = angular.module('myApp', ['ngSanitize']);`
- Loading branch information
Showing
20 changed files
with
301 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @license AngularJS v"NG_VERSION_FULL" | ||
* (c) 2010-2012 AngularJS http://angularjs.org | ||
* License: MIT | ||
*/ | ||
(function(angular) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
})(window.angular); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -439,110 +439,3 @@ var lowercaseFilter = valueFn(lowercase); | |
* @see angular.uppercase | ||
*/ | ||
var uppercaseFilter = valueFn(uppercase); | ||
|
||
|
||
/** | ||
* @ngdoc filter | ||
* @name angular.module.ng.$filter.linky | ||
* @function | ||
* | ||
* @description | ||
* Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and | ||
* plain email address links. | ||
* | ||
* @param {string} text Input text. | ||
* @returns {string} Html-linkified text. | ||
* | ||
* @example | ||
<doc:example> | ||
<doc:source> | ||
<script> | ||
function Ctrl($scope) { | ||
$scope.snippet = | ||
'Pretty text with some links:\n'+ | ||
'http://angularjs.org/,\n'+ | ||
'mailto:[email protected],\n'+ | ||
'[email protected],\n'+ | ||
'and one more: ftp://127.0.0.1/.'; | ||
} | ||
</script> | ||
<div ng-controller="Ctrl"> | ||
Snippet: <textarea ng-model="snippet" cols="60" rows="3"></textarea> | ||
<table> | ||
<tr> | ||
<td>Filter</td> | ||
<td>Source</td> | ||
<td>Rendered</td> | ||
</tr> | ||
<tr id="linky-filter"> | ||
<td>linky filter</td> | ||
<td> | ||
<pre><div ng-bind-html="snippet | linky"><br></div></pre> | ||
</td> | ||
<td> | ||
<div ng-bind-html="snippet | linky"></div> | ||
</td> | ||
</tr> | ||
<tr id="escaped-html"> | ||
<td>no filter</td> | ||
<td><pre><div ng-bind="snippet"><br></div></pre></td> | ||
<td><div ng-bind="snippet"></div></td> | ||
</tr> | ||
</table> | ||
</doc:source> | ||
<doc:scenario> | ||
it('should linkify the snippet with urls', function() { | ||
expect(using('#linky-filter').binding('snippet | linky')). | ||
toBe('Pretty text with some links: ' + | ||
'<a href="http://angularjs.org/">http://angularjs.org/</a>, ' + | ||
'<a href="mailto:[email protected]">[email protected]</a>, ' + | ||
'<a href="mailto:[email protected]">[email protected]</a>, ' + | ||
'and one more: <a href="ftp://127.0.0.1/">ftp://127.0.0.1/</a>.'); | ||
}); | ||
it ('should not linkify snippet without the linky filter', function() { | ||
expect(using('#escaped-html').binding('snippet')). | ||
toBe("Pretty text with some links:\n" + | ||
"http://angularjs.org/,\n" + | ||
"mailto:[email protected],\n" + | ||
"[email protected],\n" + | ||
"and one more: ftp://127.0.0.1/."); | ||
}); | ||
it('should update', function() { | ||
input('snippet').enter('new http://link.'); | ||
expect(using('#linky-filter').binding('snippet | linky')). | ||
toBe('new <a href="http://link">http://link</a>.'); | ||
expect(using('#escaped-html').binding('snippet')).toBe('new http://link.'); | ||
}); | ||
</doc:scenario> | ||
</doc:example> | ||
*/ | ||
function linkyFilter() { | ||
var LINKY_URL_REGEXP = /((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s\.\;\,\(\)\{\}\<\>]/, | ||
MAILTO_REGEXP = /^mailto:/; | ||
|
||
return function(text) { | ||
if (!text) return text; | ||
var match; | ||
var raw = text; | ||
var html = []; | ||
var writer = htmlSanitizeWriter(html); | ||
var url; | ||
var i; | ||
while ((match = raw.match(LINKY_URL_REGEXP))) { | ||
// We can not end in these as they are sometimes found at the end of the sentence | ||
url = match[0]; | ||
// if we did not match ftp/http/mailto then assume mailto | ||
if (match[2] == match[3]) url = 'mailto:' + url; | ||
i = match.index; | ||
writer.chars(raw.substr(0, i)); | ||
writer.start('a', {href:url}); | ||
writer.chars(match[0].replace(MAILTO_REGEXP, '')); | ||
writer.end('a'); | ||
raw = raw.substring(i + match[0].length); | ||
} | ||
writer.chars(raw); | ||
return html.join(''); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
|
||
|
||
/** | ||
* @ngdoc directive | ||
* @name angular.module.ngSanitize.directive.ngBindHtml | ||
* | ||
* @description | ||
* Creates a binding that will sanitize the result of evaluating the `expression` with the | ||
* {@link angular.module.ng.$sanitize $sanitize} service and innerHTML the result into the current | ||
* element. | ||
* | ||
* See {@link angular.module.ng.$sanitize $sanitize} docs for examples. | ||
* | ||
* @element ANY | ||
* @param {expression} ngBindHtml {@link guide/dev_guide.expressions Expression} to evaluate. | ||
*/ | ||
angular.module('ngSanitize').directive('ngBindHtml', ['$sanitize', function($sanitize) { | ||
return function(scope, element, attr) { | ||
element.addClass('ng-binding').data('$binding', attr.ngBindHtml); | ||
scope.$watch(attr.ngBindHtml, function(value) { | ||
value = $sanitize(value); | ||
element.html(value || ''); | ||
}); | ||
}; | ||
}]); |
Oops, something went wrong.