small fixes to the $location services

* fixing the jsdoc format
* rewriting updateHash() method to be easier to read and so that
  it minifies better
This commit is contained in:
Igor Minar 2010-10-18 22:24:44 -07:00
parent ffb968b08b
commit a1fa23397f

View file

@ -46,7 +46,7 @@ angularServiceInject("$location", function(browser) {
* scope.$location.update({host: 'www.google.com', protocol: 'https'}); * scope.$location.update({host: 'www.google.com', protocol: 'https'});
* scope.$location.update({hashPath: '/path', hashSearch: {a: 'b', x: true}}); * scope.$location.update({hashPath: '/path', hashSearch: {a: 'b', x: true}});
* *
* @param {String | Object} Full href as a string or hash object with properties * @param {(string|Object)} href Full href as a string or hash object with properties
*/ */
function update(href) { function update(href) {
if (isString(href)) { if (isString(href)) {
@ -80,21 +80,26 @@ angularServiceInject("$location", function(browser) {
* scope.$location.updateHash('/hp', {a: true}) * scope.$location.updateHash('/hp', {a: true})
* ==> update({hashPath: '/hp', hashSearch: {a: true}}) * ==> update({hashPath: '/hp', hashSearch: {a: true}})
* *
* @param {String | Object} hashPath as String or hashSearch as Object * @param {(string|Object)} path A hashPath or hashSearch object
* @param {String | Object} hashPath as String or hashSearch as Object [optional] * @param {Object=} search A hashSearch object
*/ */
function updateHash() { function updateHash(path, search) {
var hash = {}; var hash = {};
for (var i = 0; i < Math.min(arguments.length, 2); i++) {
hash[isString(arguments[i]) ? 'hashPath' : 'hashSearch'] = arguments[i]; if (isString(path)) {
} hash.hashPath = path;
if (isDefined(search))
hash.hashSearch = search;
} else
hash.hashSearch = path;
update(hash); update(hash);
} }
/** /**
* Returns string representation - href * Returns string representation - href
* *
* @return {String} Location's href property * @return {string} Location's href property
*/ */
function toString() { function toString() {
updateLocation(); updateLocation();
@ -141,8 +146,8 @@ angularServiceInject("$location", function(browser) {
/** /**
* Compose href string from a location object * Compose href string from a location object
* *
* @param {Object} Location object with all properties * @param {Object} loc The location object with all properties
* @return {String} Composed href * @return {string} Composed href
*/ */
function composeHref(loc) { function composeHref(loc) {
var url = toKeyValue(loc.search); var url = toKeyValue(loc.search);
@ -156,8 +161,8 @@ angularServiceInject("$location", function(browser) {
/** /**
* Compose hash string from location object * Compose hash string from location object
* *
* @param {Object} Object with hashPath and hashSearch properties * @param {Object} loc Object with hashPath and hashSearch properties
* @return {String} Hash string * @return {string} Hash string
*/ */
function composeHash(loc) { function composeHash(loc) {
var hashSearch = toKeyValue(loc.hashSearch); var hashSearch = toKeyValue(loc.hashSearch);
@ -167,8 +172,8 @@ angularServiceInject("$location", function(browser) {
/** /**
* Parse href string into location object * Parse href string into location object
* *
* @param {String} Href * @param {string} href
* @return {Object} Location * @return {Object} The location object
*/ */
function parseHref(href) { function parseHref(href) {
var loc = {}; var loc = {};
@ -192,8 +197,7 @@ angularServiceInject("$location", function(browser) {
/** /**
* Parse hash string into object * Parse hash string into object
* *
* @param {String} Hash * @param {string} hash
* @param {Object} Object with hashPath and hashSearch properties
*/ */
function parseHash(hash) { function parseHash(hash) {
var h = {}; var h = {};
@ -209,6 +213,7 @@ angularServiceInject("$location", function(browser) {
} }
}, ['$browser'], EAGER_PUBLISHED); }, ['$browser'], EAGER_PUBLISHED);
angularServiceInject("$log", function($window){ angularServiceInject("$log", function($window){
var console = $window.console || {log: noop, warn: noop, info: noop, error: noop}, var console = $window.console || {log: noop, warn: noop, info: noop, error: noop},
log = console.log || noop; log = console.log || noop;