From: Igor Minar Date: Fri, 1 Apr 2011 20:45:32 +0000 (-0700) Subject: upgrading angular to 0.9.14 key-maker X-Git-Tag: 0.4~162 X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=d671a5519b18b787c073a85379b6e3430a06da49;p=angular-drzb upgrading angular to 0.9.14 key-maker --- diff --git a/app/lib/angular/angular.js b/app/lib/angular/angular.js index 5345078..f9750f2 100644 --- a/app/lib/angular/angular.js +++ b/app/lib/angular/angular.js @@ -76,9 +76,7 @@ if ('i' !== 'I'.toLowerCase()) { function fromCharCode(code) { return String.fromCharCode(code); } -var _undefined = undefined, - _null = null, - $$element = '$element', +var $$element = '$element', $$update = '$update', $$scope = '$scope', $$validate = '$validate', @@ -339,7 +337,7 @@ function isDefined(value){ return typeof value != $undefined; } * @param {*} value Reference to check. * @returns {boolean} True if `value` is an `Object` but not `null`. */ -function isObject(value){ return value!=_null && typeof value == $object;} +function isObject(value){ return value!=null && typeof value == $object;} /** @@ -487,12 +485,14 @@ function map(obj, iterator, context) { * @function * * @description - * Determines the number of elements in an array or number of properties of an object. + * Determines the number of elements in an array, number of properties of an object or string + * length. * * Note: this function is used to augment the Object type in angular expressions. See * {@link angular.Object} for more info. * - * @param {Object|Array} obj Object or array to inspect. + * @param {Object|Array|string} obj Object, array or string to inspect. + * @param {boolean} [ownPropsOnly=false] Count only "own" properties in an object * @returns {number} The size of `obj` or `0` if `obj` is neither an object or an array. * * @example @@ -509,18 +509,21 @@ function map(obj, iterator, context) { * * */ -function size(obj) { +function size(obj, ownPropsOnly) { var size = 0, key; - if (obj) { - if (isNumber(obj.length)) { - return obj.length; - } else if (isObject(obj)){ - for (key in obj) + + if (isArray(obj) || isString(obj)) { + return obj.length; + } else if (isObject(obj)){ + for (key in obj) + if (!ownPropsOnly || obj.hasOwnProperty(key)) size++; - } } + return size; } + + function includes(array, obj) { for ( var i = 0; i < array.length; i++) { if (obj === array[i]) return true; @@ -723,10 +726,19 @@ function isRenderableElement(element) { return name && name.charAt(0) != '#' && !includes(['TR', 'COL', 'COLGROUP', 'TBODY', 'THEAD', 'TFOOT'], name); } + function elementError(element, type, error) { + var parent; + while (!isRenderableElement(element)) { - element = element.parent() || jqLite(document.body); + parent = element.parent(); + if (parent.length) { + element = element.parent(); + } else { + return; + } } + if (element[0]['$NG_ERROR'] !== error) { element[0]['$NG_ERROR'] = error; if (error) { @@ -832,20 +844,44 @@ function toKeyValue(obj) { /** * we need our custom mehtod because encodeURIComponent is too agressive and doesn't follow - * http://www.ietf.org/rfc/rfc2396.txt with regards to the character set (pchar) allowed in path - * segments + * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path + * segments: + * segment = *pchar + * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" + * pct-encoded = "%" HEXDIG HEXDIG + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + * / "*" / "+" / "," / ";" / "=" */ function encodeUriSegment(val) { + return encodeUriQuery(val, true). + replace(/%26/gi, '&'). + replace(/%3D/gi, '='). + replace(/%2B/gi, '+'); +} + + +/** + * This method is intended for encoding *key* or *value* parts of query component. We need a custom + * method becuase encodeURIComponent is too agressive and encodes stuff that doesn't have to be + * encoded per http://tools.ietf.org/html/rfc3986: + * query = *( pchar / "/" / "?" ) + * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * pct-encoded = "%" HEXDIG HEXDIG + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + * / "*" / "+" / "," / ";" / "=" + */ +function encodeUriQuery(val, pctEncodeSpaces) { return encodeURIComponent(val). replace(/%40/gi, '@'). replace(/%3A/gi, ':'). - replace(/%26/gi, '&'). - replace(/%3D/gi, '='). - replace(/%2B/gi, '+'). replace(/%24/g, '$'). - replace(/%2C/gi, ','); + replace(/%2C/gi, ','). + replace((pctEncodeSpaces ? null : /%20/g), '+'); } + /** * @workInProgress * @ngdoc directive @@ -1053,11 +1089,11 @@ function assertArg(arg, name, reason) { if (window.console) window.console.log(error.stack); throw error; } -}; +} function assertArgFn(arg, name) { assertArg(isFunction(arg, name, 'not a function')); -}; +} var array = [].constructor; /** @@ -1075,7 +1111,7 @@ var array = [].constructor; */ function toJson(obj, pretty) { var buf = []; - toJsonArray(buf, obj, pretty ? "\n " : _null, []); + toJsonArray(buf, obj, pretty ? "\n " : null, []); return buf.join(''); } @@ -1147,7 +1183,7 @@ function toJsonArray(buf, obj, pretty, stack) { } stack.push(obj); } - if (obj === _null) { + if (obj === null) { buf.push($null); } else if (obj instanceof RegExp) { buf.push(angular['String']['quoteUnicode'](obj.toString())); @@ -1188,7 +1224,7 @@ function toJsonArray(buf, obj, pretty, stack) { var childPretty = pretty ? pretty + " " : false; var keys = []; for(var k in obj) { - if (obj[k] === _undefined) + if (obj[k] === undefined) continue; keys.push(k); } @@ -1546,7 +1582,7 @@ Compiler.prototype = { template.addChild(i, self.templatize(child, i, priority)); }); } - return template.empty() ? _null : template; + return template.empty() ? null : template; } }; @@ -1590,7 +1626,7 @@ function getter(instance, path, unboundFn) { if (isUndefined(instance) && key.charAt(0) == '$') { var type = angular['Global']['typeOf'](lastInstance); type = angular[type.charAt(0).toUpperCase()+type.substring(1)]; - var fn = type ? type[[key.substring(1)]] : _undefined; + var fn = type ? type[[key.substring(1)]] : undefined; if (fn) { instance = bind(lastInstance, fn, lastInstance); return instance; @@ -2294,7 +2330,7 @@ function createInjector(providerScope, providers, cache) { } function injectService(services, fn) { - return extend(fn, {$inject:services});; + return extend(fn, {$inject:services}); } function injectUpdateView(fn) { @@ -2333,9 +2369,9 @@ function injectionArgs(fn) { }); } return fn.$inject; -}; +} var OPERATORS = { - 'null':function(self){return _null;}, + 'null':function(self){return null;}, 'true':function(self){return true;}, 'false':function(self){return false;}, $undefined:noop, @@ -2698,7 +2734,6 @@ function parser(text, json){ var token = expect(); var formatter = angularFormatter[token.text]; var argFns = []; - var token; if (!formatter) throwError('is not a valid formatter.', token); while(true) { if ((token = expect(':'))) { @@ -2902,7 +2937,7 @@ function parser(text, json){ function (self){ var o = obj(self); var i = indexFn(self); - return (o) ? o[i] : _undefined; + return (o) ? o[i] : undefined; }, { assign:function(self, value){ return obj(self)[indexFn(self)] = value; @@ -3031,14 +3066,14 @@ Route.prototype = { params = params || {}; forEach(this.urlParams, function(_, urlParam){ - encodedVal = encodeUriSegment(params[urlParam] || self.defaults[urlParam] || "") + encodedVal = encodeUriSegment(params[urlParam] || self.defaults[urlParam] || ""); url = url.replace(new RegExp(":" + urlParam + "(\\W)"), encodedVal + "$1"); }); url = url.replace(/\/?#$/, ''); var query = []; forEachSorted(params, function(value, key){ if (!self.urlParams[key]) { - query.push(encodeUriSegment(key) + '=' + encodeUriSegment(value)); + query.push(encodeUriQuery(key) + '=' + encodeUriQuery(value)); } }); url = url.replace(/\/*$/, ''); @@ -3109,13 +3144,15 @@ ResourceFactory.prototype = { data, function(status, response, clear) { if (status == 200) { - if (action.isArray) { - value.length = 0; - forEach(response, function(item){ - value.push(new Resource(item)); - }); - } else { - copy(response, value); + if (response) { + if (action.isArray) { + value.length = 0; + forEach(response, function(item){ + value.push(new Resource(item)); + }); + } else { + copy(response, value); + } } (callback||noop)(value); } else { @@ -3140,7 +3177,7 @@ ResourceFactory.prototype = { default: throw "Expected between 1-2 arguments [params, callback], got " + arguments.length + " arguments."; } - var data = isPostOrPut ? this : _undefined; + var data = isPostOrPut ? this : undefined; Resource[name].call(this, params, data, callback); }; }); @@ -3244,7 +3281,7 @@ function Browser(window, document, body, XHR, $log) { var script = jqLite('