vendor/assets/javascripts/angular-sanitize.js in angular-on-rails-1.0.5 vs vendor/assets/javascripts/angular-sanitize.js in angular-on-rails-1.1.3u

- old
+ new

@@ -1,7 +1,7 @@ /** - * @license AngularJS v1.0.5 + * @license AngularJS v1.1.3 * (c) 2010-2012 Google, Inc. http://angularjs.org * License: MIT */ (function(window, angular, undefined) { 'use strict'; @@ -127,11 +127,11 @@ ATTR_REGEXP = /([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g, BEGIN_TAG_REGEXP = /^</, BEGING_END_TAGE_REGEXP = /^<\s*\//, COMMENT_REGEXP = /<!--(.*?)-->/g, CDATA_REGEXP = /<!\[CDATA\[(.*?)]]>/g, - URI_REGEXP = /^((ftp|https?):\/\/|mailto:|#)/, + URI_REGEXP = /^((ftp|https?):\/\/|mailto:|tel:|#)/, NON_ALPHANUMERIC_REGEXP = /([^\#-~| |!])/g; // Match everything outside of normal chars and " (quote character) // Good source of info about elements and attributes // http://dev.w3.org/html5/spec/Overview.html#semantics @@ -430,10 +430,11 @@ * @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. + * @param {string} target Window (_blank|_self|_parent|_top) or named frame to open links in. * @returns {string} Html-linkified text. * * @usage <span ng-bind-html="linky_expression | linky"></span> * @@ -446,10 +447,11 @@ 'Pretty text with some links:\n'+ 'http://angularjs.org/,\n'+ 'mailto:us@somewhere.org,\n'+ 'another@somewhere.org,\n'+ 'and one more: ftp://127.0.0.1/.'; + $scope.snippetWithTarget = 'http://angularjs.org/'; } </script> <div ng-controller="Ctrl"> Snippet: <textarea ng-model="snippet" cols="60" rows="3"></textarea> <table> @@ -465,10 +467,19 @@ </td> <td> <div ng-bind-html="snippet | linky"></div> </td> </tr> + <tr id="linky-target"> + <td>linky target</td> + <td> + <pre>&lt;div ng-bind-html="snippetWithTarget | linky:'_blank'"&gt;<br>&lt;/div&gt;</pre> + </td> + <td> + <div ng-bind-html="snippetWithTarget | linky:'_blank'"></div> + </td> + </tr> <tr id="escaped-html"> <td>no filter</td> <td><pre>&lt;div ng-bind="snippet"&gt;<br>&lt;/div&gt;</pre></td> <td><div ng-bind="snippet"></div></td> </tr> @@ -497,33 +508,43 @@ 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.'); }); + + it('should work with the target property', function() { + expect(using('#linky-target').binding("snippetWithTarget | linky:'_blank'")). + toBe('<a target="_blank" href="http://angularjs.org/">http://angularjs.org/</a>'); + }); </doc:scenario> </doc:example> */ angular.module('ngSanitize').filter('linky', function() { var LINKY_URL_REGEXP = /((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s\.\;\,\(\)\{\}\<\>]/, MAILTO_REGEXP = /^mailto:/; - return function(text) { + return function(text, target) { if (!text) return text; var match; var raw = text; var html = []; // TODO(vojta): use $sanitize instead var writer = htmlSanitizeWriter(html); var url; var i; + var properties = {}; + if (angular.isDefined(target)) { + properties.target = target; + } 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}); + properties.href = url; + writer.start('a', properties); writer.chars(match[0].replace(MAILTO_REGEXP, '')); writer.end('a'); raw = raw.substring(i + match[0].length); } writer.chars(raw);