Commit 2440b74f authored by Randall Leeds's avatar Randall Leeds

update other angular libs

parent b292384d
/** /**
* @license AngularJS v1.1.4 * @license AngularJS v1.2.0-rc.2
* (c) 2010-2012 Google, Inc. http://angularjs.org * (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT * License: MIT
*/ */
(function(window, angular, undefined) { (function(window, angular, undefined) {'use strict';
'use strict';
var $resourceMinErr = angular.$$minErr('$resource');
/** /**
* @ngdoc overview * @ngdoc overview
* @name ngResource * @name ngResource
* @description * @description
*
* # ngResource
*
* `ngResource` is the name of the optional Angular module that adds support for interacting with
* [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
* `ngReource` provides the {@link ngResource.$resource `$resource`} serivce.
*
* {@installModule resource}
*
* See {@link ngResource.$resource `$resource`} for usage.
*/ */
/** /**
...@@ -24,19 +35,18 @@ ...@@ -24,19 +35,18 @@
* The returned resource object has action methods which provide high-level behaviors without * The returned resource object has action methods which provide high-level behaviors without
* the need to interact with the low level {@link ng.$http $http} service. * the need to interact with the low level {@link ng.$http $http} service.
* *
* # Installation * Requires the {@link ngResource `ngResource`} module to be installed.
* To use $resource make sure you have included the `angular-resource.js` that comes in Angular
* package. You also can find this stuff in {@link http://code.angularjs.org/ code.angularjs.org}.
* Finally load the module in your application:
*
* angular.module('app', ['ngResource']);
*
* and you ready to get started!
* *
* @param {string} url A parametrized URL template with parameters prefixed by `:` as in * @param {string} url A parametrized URL template with parameters prefixed by `:` as in
* `/user/:username`. If you are using a URL with a port number (e.g. * `/user/:username`. If you are using a URL with a port number (e.g.
* `http://example.com:8080/api`), you'll need to escape the colon character before the port * `http://example.com:8080/api`), it will be respected.
* number, like this: `$resource('http://example.com\\:8080/api')`. *
* If you are using a url with a suffix, just add the suffix, like this:
* `$resource('http://example.com/resource.json')` or `$resource('http://example.com/:id.json')`
* or even `$resource('http://example.com/resource/:resource_id.:format')`
* If the parameter before the suffix is empty, :resource_id in this case, then the `/.` will be
* collapsed down to a single `.`. If you need this sequence to appear and not collapse then you
* can escape it with `/\.`.
* *
* @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in * @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in
* `actions` methods. If any of the parameter value is a function, it will be executed every time * `actions` methods. If any of the parameter value is a function, it will be executed every time
...@@ -82,12 +92,16 @@ ...@@ -82,12 +92,16 @@
* GET request, otherwise if a cache instance built with * GET request, otherwise if a cache instance built with
* {@link ng.$cacheFactory $cacheFactory}, this cache will be used for * {@link ng.$cacheFactory $cacheFactory}, this cache will be used for
* caching. * caching.
* - **`timeout`** – `{number}` – timeout in milliseconds. * - **`timeout`** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise} that
* should abort the request when resolved.
* - **`withCredentials`** - `{boolean}` - whether to to set the `withCredentials` flag on the * - **`withCredentials`** - `{boolean}` - whether to to set the `withCredentials` flag on the
* XHR object. See {@link https://developer.mozilla.org/en/http_access_control#section_5 * XHR object. See {@link https://developer.mozilla.org/en/http_access_control#section_5
* requests with credentials} for more information. * requests with credentials} for more information.
* - **`responseType`** - `{string}` - see {@link * - **`responseType`** - `{string}` - see {@link
* https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType requestType}. * https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType requestType}.
* - **`interceptor`** - `{Object=}` - The interceptor object has two optional methods -
* `response` and `responseError`. Both `response` and `responseError` interceptors get called
* with `http response` object. See {@link ng.$http $http interceptors}.
* *
* @returns {Object} A resource "class" object with methods for the default set of resource actions * @returns {Object} A resource "class" object with methods for the default set of resource actions
* optionally extended with custom `actions`. The default set contains these actions: * optionally extended with custom `actions`. The default set contains these actions:
...@@ -126,24 +140,27 @@ ...@@ -126,24 +140,27 @@
* - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])` * - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
* - non-GET instance actions: `instance.$action([parameters], [success], [error])` * - non-GET instance actions: `instance.$action([parameters], [success], [error])`
* *
* Success callback is called with (value, responseHeaders) arguments. Error callback is called
* with (httpResponse) argument.
* *
* The Resource instances and collection have these additional properties: * Class actions return empty instance (with additional properties below).
* Instance actions return promise of the action.
* *
* - `$then`: the `then` method of a {@link ng.$q promise} derived from the underlying * The Resource instances and collection have these additional properties:
* {@link ng.$http $http} call.
* *
* The success callback for the `$then` method will be resolved if the underlying `$http` requests * - `$promise`: the {@link ng.$q promise} of the original server interaction that created this
* succeeds. * instance or collection.
* *
* The success callback is called with a single object which is the {@link ng.$http http response} * On success, the promise is resolved with the same resource instance or collection object,
* object extended with a new property `resource`. This `resource` property is a reference to the * updated with data from server. This makes it easy to use in
* result of the resource action — resource object or array of resources. * {@link ngRoute.$routeProvider resolve section of $routeProvider.when()} to defer view rendering
* until the resource(s) are loaded.
* *
* The error callback is called with the {@link ng.$http http response} object when an http * On failure, the promise is resolved with the {@link ng.$http http response} object,
* error occurs. * without the `resource` property.
* *
* - `$resolved`: true if the promise has been resolved (either with success or rejection); * - `$resolved`: `true` after first server interaction is completed (either with success or rejection),
* Knowing if the Resource has been resolved is useful in data-binding. * `false` before that. Knowing if the Resource has been resolved is useful in data-binding.
* *
* @example * @example
* *
...@@ -264,7 +281,7 @@ ...@@ -264,7 +281,7 @@
</doc:example> </doc:example>
*/ */
angular.module('ngResource', ['ng']). angular.module('ngResource', ['ng']).
factory('$resource', ['$http', '$parse', function($http, $parse) { factory('$resource', ['$http', '$parse', '$q', function($http, $parse, $q) {
var DEFAULT_ACTIONS = { var DEFAULT_ACTIONS = {
'get': {method:'GET'}, 'get': {method:'GET'},
'save': {method:'POST'}, 'save': {method:'POST'},
...@@ -321,7 +338,7 @@ angular.module('ngResource', ['ng']). ...@@ -321,7 +338,7 @@ angular.module('ngResource', ['ng']).
} }
function Route(template, defaults) { function Route(template, defaults) {
this.template = template = template + '#'; this.template = template;
this.defaults = defaults || {}; this.defaults = defaults || {};
this.urlParams = {}; this.urlParams = {};
} }
...@@ -335,7 +352,7 @@ angular.module('ngResource', ['ng']). ...@@ -335,7 +352,7 @@ angular.module('ngResource', ['ng']).
var urlParams = self.urlParams = {}; var urlParams = self.urlParams = {};
forEach(url.split(/\W/), function(param){ forEach(url.split(/\W/), function(param){
if (param && (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) { if (!(new RegExp("^\\d+$").test(param)) && param && (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
urlParams[param] = true; urlParams[param] = true;
} }
}); });
...@@ -359,8 +376,14 @@ angular.module('ngResource', ['ng']). ...@@ -359,8 +376,14 @@ angular.module('ngResource', ['ng']).
} }
}); });
// set the url // strip trailing slashes and set the url
config.url = url.replace(/\/?#$/, '').replace(/\/*$/, ''); url = url.replace(/\/+$/, '');
// then replace collapse `/.` if found in the last URL path segment before the query
// E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
url = url.replace(/\/\.(?=\w+($|\?))/, '.');
// replace escaped `/\.` with `/.`
config.url = url.replace(/\/\\\./, '/.');
// set params - delegate param encoding to $http // set params - delegate param encoding to $http
forEach(params, function(value, key){ forEach(params, function(value, key){
...@@ -383,24 +406,24 @@ angular.module('ngResource', ['ng']). ...@@ -383,24 +406,24 @@ angular.module('ngResource', ['ng']).
actionParams = extend({}, paramDefaults, actionParams); actionParams = extend({}, paramDefaults, actionParams);
forEach(actionParams, function(value, key){ forEach(actionParams, function(value, key){
if (isFunction(value)) { value = value(); } if (isFunction(value)) { value = value(); }
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value; ids[key] = value && value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
}); });
return ids; return ids;
} }
function defaultResponseInterceptor(response) {
return response.resource;
}
function Resource(value){ function Resource(value){
copy(value || {}, this); copy(value || {}, this);
} }
forEach(actions, function(action, name) { forEach(actions, function(action, name) {
action.method = angular.uppercase(action.method); var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method);
var hasBody = action.method == 'POST' || action.method == 'PUT' || action.method == 'PATCH';
Resource[name] = function(a1, a2, a3, a4) { Resource[name] = function(a1, a2, a3, a4) {
var params = {}; var params = {}, data, success, error;
var data;
var success = noop;
var error = null;
var promise;
switch(arguments.length) { switch(arguments.length) {
case 4: case 4:
...@@ -432,33 +455,35 @@ angular.module('ngResource', ['ng']). ...@@ -432,33 +455,35 @@ angular.module('ngResource', ['ng']).
break; break;
case 0: break; case 0: break;
default: default:
throw "Expected between 0-4 arguments [params, data, success, error], got " + throw $resourceMinErr('badargs',
arguments.length + " arguments."; "Expected up to 4 arguments [params, data, success, error], got {0} arguments", arguments.length);
} }
var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data)); var isInstanceCall = data instanceof Resource;
var httpConfig = {}, var value = isInstanceCall ? data : (action.isArray ? [] : new Resource(data));
promise; var httpConfig = {};
var responseInterceptor = action.interceptor && action.interceptor.response || defaultResponseInterceptor;
var responseErrorInterceptor = action.interceptor && action.interceptor.responseError || undefined;
forEach(action, function(value, key) { forEach(action, function(value, key) {
if (key != 'params' && key != 'isArray' ) { if (key != 'params' && key != 'isArray' && key != 'interceptor') {
httpConfig[key] = copy(value); httpConfig[key] = copy(value);
} }
}); });
httpConfig.data = data; httpConfig.data = data;
route.setUrlParams(httpConfig, extend({}, extractParams(data, action.params || {}), params), action.url); route.setUrlParams(httpConfig, extend({}, extractParams(data, action.params || {}), params), action.url);
function markResolved() { value.$resolved = true; } var promise = $http(httpConfig).then(function(response) {
var data = response.data,
promise = $http(httpConfig); promise = value.$promise;
value.$resolved = false;
promise.then(markResolved, markResolved);
value.$then = promise.then(function(response) {
var data = response.data;
var then = value.$then, resolved = value.$resolved;
if (data) { if (data) {
if ( angular.isArray(data) != !!action.isArray ) {
throw $resourceMinErr('badcfg', 'Error in resource configuration. Expected response' +
' to contain an {0} but got an {1}',
action.isArray?'array':'object', angular.isArray(data)?'array':'object');
}
if (action.isArray) { if (action.isArray) {
value.length = 0; value.length = 0;
forEach(data, function(item) { forEach(data, function(item) {
...@@ -466,44 +491,47 @@ angular.module('ngResource', ['ng']). ...@@ -466,44 +491,47 @@ angular.module('ngResource', ['ng']).
}); });
} else { } else {
copy(data, value); copy(data, value);
value.$then = then; value.$promise = promise;
value.$resolved = resolved;
} }
} }
value.$resolved = true;
(success||noop)(value, response.headers); (success||noop)(value, response.headers);
response.resource = value; response.resource = value;
return response; return response;
}, error).then; }, function(response) {
value.$resolved = true;
return value; (error||noop)(response);
};
return $q.reject(response);
}).then(responseInterceptor, responseErrorInterceptor);
Resource.prototype['$' + name] = function(a1, a2, a3) {
var params = extractParams(this),
success = noop,
error;
switch(arguments.length) { if (!isInstanceCall) {
case 3: params = a1; success = a2; error = a3; break; // we are creating instance / collection
case 2: // - set the initial promise
case 1: // - return the instance / collection
if (isFunction(a1)) { value.$promise = promise;
success = a1; value.$resolved = false;
error = a2;
} else { return value;
params = a1; }
success = a2 || noop;
} // instance call
case 0: break; return promise;
default: };
throw "Expected between 1-3 arguments [params, success, error], got " +
arguments.length + " arguments.";
Resource.prototype['$' + name] = function(params, success, error) {
if (isFunction(params)) {
error = success; success = params; params = {};
} }
var data = hasBody ? this : undefined; var result = Resource[name](params, this, success, error);
Resource[name].call(this, params, data, success, error); return result.$promise || result;
}; };
}); });
......
/** /**
* @license AngularJS v1.1.4 * @license AngularJS v1.2.0-rc.2
* (c) 2010-2012 Google, Inc. http://angularjs.org * (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT * License: MIT
*/ */
(function(window, angular, undefined) { (function(window, angular, undefined) {'use strict';
'use strict';
var $sanitizeMinErr = angular.$$minErr('$sanitize');
/** /**
* @ngdoc overview * @ngdoc overview
* @name ngSanitize * @name ngSanitize
* @description * @description
*
* # ngSanitize
*
* The `ngSanitize` module provides functionality to sanitize HTML.
*
* {@installModule sanitize}
*
* See {@link ngSanitize.$sanitize `$sanitize`} for usage.
*/ */
/* /*
...@@ -48,68 +57,71 @@ ...@@ -48,68 +57,71 @@
<doc:example module="ngSanitize"> <doc:example module="ngSanitize">
<doc:source> <doc:source>
<script> <script>
function Ctrl($scope) { function Ctrl($scope, $sce) {
$scope.snippet = $scope.snippet =
'<p style="color:blue">an html\n' + '<p style="color:blue">an html\n' +
'<em onmouseover="this.textContent=\'PWN3D!\'">click here</em>\n' + '<em onmouseover="this.textContent=\'PWN3D!\'">click here</em>\n' +
'snippet</p>'; 'snippet</p>';
$scope.deliberatelyTrustDangerousSnippet = function() {
return $sce.trustAsHtml($scope.snippet);
};
} }
</script> </script>
<div ng-controller="Ctrl"> <div ng-controller="Ctrl">
Snippet: <textarea ng-model="snippet" cols="60" rows="3"></textarea> Snippet: <textarea ng-model="snippet" cols="60" rows="3"></textarea>
<table> <table>
<tr> <tr>
<td>Filter</td> <td>Directive</td>
<td>How</td>
<td>Source</td> <td>Source</td>
<td>Rendered</td> <td>Rendered</td>
</tr> </tr>
<tr id="html-filter"> <tr id="bind-html-with-sanitize">
<td>html filter</td> <td>ng-bind-html</td>
<td> <td>Automatically uses $sanitize</td>
<pre>&lt;div ng-bind-html="snippet"&gt;<br/>&lt;/div&gt;</pre> <td><pre>&lt;div ng-bind-html="snippet"&gt;<br/>&lt;/div&gt;</pre></td>
</td> <td><div ng-bind-html="snippet"></div></td>
<td> </tr>
<div ng-bind-html="snippet"></div> <tr id="bind-html-with-trust">
</td> <td>ng-bind-html</td>
<td>Bypass $sanitize by explicitly trusting the dangerous value</td>
<td><pre>&lt;div ng-bind-html="deliberatelyTrustDangerousSnippet()"&gt;<br/>&lt;/div&gt;</pre></td>
<td><div ng-bind-html="deliberatelyTrustDangerousSnippet()"></div></td>
</tr> </tr>
<tr id="escaped-html"> <tr id="bind-default">
<td>no filter</td> <td>ng-bind</td>
<td>Automatically escapes</td>
<td><pre>&lt;div ng-bind="snippet"&gt;<br/>&lt;/div&gt;</pre></td> <td><pre>&lt;div ng-bind="snippet"&gt;<br/>&lt;/div&gt;</pre></td>
<td><div ng-bind="snippet"></div></td> <td><div ng-bind="snippet"></div></td>
</tr> </tr>
<tr id="html-unsafe-filter">
<td>unsafe html filter</td>
<td><pre>&lt;div ng-bind-html-unsafe="snippet"&gt;<br/>&lt;/div&gt;</pre></td>
<td><div ng-bind-html-unsafe="snippet"></div></td>
</tr>
</table> </table>
</div> </div>
</doc:source> </doc:source>
<doc:scenario> <doc:scenario>
it('should sanitize the html snippet ', function() { it('should sanitize the html snippet by default', function() {
expect(using('#html-filter').element('div').html()). expect(using('#bind-html-with-sanitize').element('div').html()).
toBe('<p>an html\n<em>click here</em>\nsnippet</p>'); toBe('<p>an html\n<em>click here</em>\nsnippet</p>');
}); });
it('should inline raw snippet if bound to a trusted value', function() {
expect(using('#bind-html-with-trust').element("div").html()).
toBe("<p style=\"color:blue\">an html\n" +
"<em onmouseover=\"this.textContent='PWN3D!'\">click here</em>\n" +
"snippet</p>");
});
it('should escape snippet without any filter', function() { it('should escape snippet without any filter', function() {
expect(using('#escaped-html').element('div').html()). expect(using('#bind-default').element('div').html()).
toBe("&lt;p style=\"color:blue\"&gt;an html\n" + toBe("&lt;p style=\"color:blue\"&gt;an html\n" +
"&lt;em onmouseover=\"this.textContent='PWN3D!'\"&gt;click here&lt;/em&gt;\n" + "&lt;em onmouseover=\"this.textContent='PWN3D!'\"&gt;click here&lt;/em&gt;\n" +
"snippet&lt;/p&gt;"); "snippet&lt;/p&gt;");
}); });
it('should inline raw snippet if filtered as unsafe', function() {
expect(using('#html-unsafe-filter').element("div").html()).
toBe("<p style=\"color:blue\">an html\n" +
"<em onmouseover=\"this.textContent='PWN3D!'\">click here</em>\n" +
"snippet</p>");
});
it('should update', function() { it('should update', function() {
input('snippet').enter('new <b>text</b>'); input('snippet').enter('new <b onclick="alert(1)">text</b>');
expect(using('#html-filter').binding('snippet')).toBe('new <b>text</b>'); expect(using('#bind-html-with-sanitize').element('div').html()).toBe('new <b>text</b>');
expect(using('#escaped-html').element('div').html()).toBe("new &lt;b&gt;text&lt;/b&gt;"); expect(using('#bind-html-with-trust').element('div').html()).toBe('new <b onclick="alert(1)">text</b>');
expect(using('#html-unsafe-filter').binding("snippet")).toBe('new <b>text</b>'); expect(using('#bind-default').element('div').html()).toBe("new &lt;b onclick=\"alert(1)\"&gt;text&lt;/b&gt;");
}); });
</doc:scenario> </doc:scenario>
</doc:example> </doc:example>
...@@ -129,7 +141,7 @@ var START_TAG_REGEXP = /^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?: ...@@ -129,7 +141,7 @@ var START_TAG_REGEXP = /^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:
BEGING_END_TAGE_REGEXP = /^<\s*\//, BEGING_END_TAGE_REGEXP = /^<\s*\//,
COMMENT_REGEXP = /<!--(.*?)-->/g, COMMENT_REGEXP = /<!--(.*?)-->/g,
CDATA_REGEXP = /<!\[CDATA\[(.*?)]]>/g, CDATA_REGEXP = /<!\[CDATA\[(.*?)]]>/g,
URI_REGEXP = /^((ftp|https?):\/\/|mailto:|tel:|#)/, URI_REGEXP = /^((ftp|https?):\/\/|mailto:|tel:|#)/i,
NON_ALPHANUMERIC_REGEXP = /([^\#-~| |!])/g; // Match everything outside of normal chars and " (quote character) NON_ALPHANUMERIC_REGEXP = /([^\#-~| |!])/g; // Match everything outside of normal chars and " (quote character)
...@@ -256,7 +268,7 @@ function htmlParser( html, handler ) { ...@@ -256,7 +268,7 @@ function htmlParser( html, handler ) {
} }
if ( html == last ) { if ( html == last ) {
throw "Parse Error: " + html; throw $sanitizeMinErr('badparse', "The sanitizer was unable to parse the following block of html: {0}", html);
} }
last = html; last = html;
} }
...@@ -283,10 +295,10 @@ function htmlParser( html, handler ) { ...@@ -283,10 +295,10 @@ function htmlParser( html, handler ) {
var attrs = {}; var attrs = {};
rest.replace(ATTR_REGEXP, function(match, name, doubleQuotedValue, singleQoutedValue, unqoutedValue) { rest.replace(ATTR_REGEXP, function(match, name, doubleQuotedValue, singleQuotedValue, unquotedValue) {
var value = doubleQuotedValue var value = doubleQuotedValue
|| singleQoutedValue || singleQuotedValue
|| unqoutedValue || unquotedValue
|| ''; || '';
attrs[name] = decodeEntities(value); attrs[name] = decodeEntities(value);
...@@ -400,37 +412,16 @@ function htmlSanitizeWriter(buf){ ...@@ -400,37 +412,16 @@ function htmlSanitizeWriter(buf){
// define ngSanitize module and register $sanitize service // define ngSanitize module and register $sanitize service
angular.module('ngSanitize', []).value('$sanitize', $sanitize); angular.module('ngSanitize', []).value('$sanitize', $sanitize);
/**
* @ngdoc directive
* @name ngSanitize.directive:ngBindHtml
*
* @description
* Creates a binding that will sanitize the result of evaluating the `expression` with the
* {@link ngSanitize.$sanitize $sanitize} service and innerHTML the result into the current element.
*
* See {@link ngSanitize.$sanitize $sanitize} docs for examples.
*
* @element ANY
* @param {expression} ngBindHtml {@link guide/expression 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 ngBindHtmlWatchAction(value) {
value = $sanitize(value);
element.html(value || '');
});
};
}]);
/** /**
* @ngdoc filter * @ngdoc filter
* @name ngSanitize.filter:linky * @name ngSanitize.filter:linky
* @function * @function
* *
* @description * @description
* Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and * Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and
* plain email address links. * plain email address links.
*
* Requires the {@link ngSanitize `ngSanitize`} module to be installed.
* *
* @param {string} text Input text. * @param {string} text Input text.
* @param {string} target Window (_blank|_self|_parent|_top) or named frame to open links in. * @param {string} target Window (_blank|_self|_parent|_top) or named frame to open links in.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment