Skip to content

Commit

Permalink
chore($urlRouter): whitespace & formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nateabele committed Mar 24, 2014
1 parent 08b4636 commit 3a03042
Showing 1 changed file with 53 additions and 65 deletions.
118 changes: 53 additions & 65 deletions src/urlRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
*
* @return {object} $urlRouterProvider - $urlRouterProvider instance
*/
this.rule =
function (rule) {
if (!isFunction(rule)) throw new Error("'rule' must be a function");
rules.push(rule);
return this;
};
this.rule = function (rule) {
if (!isFunction(rule)) throw new Error("'rule' must be a function");
rules.push(rule);
return this;
};

/**
* @ngdoc object
Expand Down Expand Up @@ -101,16 +100,15 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
*
* @return {object} $urlRouterProvider - $urlRouterProvider instance
*/
this.otherwise =
function (rule) {
if (isString(rule)) {
var redirect = rule;
rule = function () { return redirect; };
}
else if (!isFunction(rule)) throw new Error("'rule' must be a function");
otherwise = rule;
return this;
};
this.otherwise = function (rule) {
if (isString(rule)) {
var redirect = rule;
rule = function () { return redirect; };
}
else if (!isFunction(rule)) throw new Error("'rule' must be a function");
otherwise = rule;
return this;
};


function handleIfMatch($injector, handler, match) {
Expand Down Expand Up @@ -156,52 +154,49 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
* @param {string|object} what The incoming path that you want to redirect.
* @param {string|object} handler The path you want to redirect your user to.
*/
this.when =
function (what, handler) {
var redirect, handlerIsString = isString(handler);
if (isString(what)) what = $urlMatcherFactory.compile(what);

if (!handlerIsString && !isFunction(handler) && !isArray(handler))
throw new Error("invalid 'handler' in when()");
this.when = function (what, handler) {
var redirect, handlerIsString = isString(handler);
if (isString(what)) what = $urlMatcherFactory.compile(what);

var strategies = {
matcher: function (what, handler) {
if (handlerIsString) {
redirect = $urlMatcherFactory.compile(handler);
handler = ['$match', function ($match) { return redirect.format($match); }];
}
return extend(function ($injector, $location) {
return handleIfMatch($injector, handler, what.exec($location.path(), $location.search()));
}, {
prefix: isString(what.prefix) ? what.prefix : ''
});
},
regex: function (what, handler) {
if (what.global || what.sticky) throw new Error("when() RegExp must not be global or sticky");
if (!handlerIsString && !isFunction(handler) && !isArray(handler))
throw new Error("invalid 'handler' in when()");

if (handlerIsString) {
redirect = handler;
handler = ['$match', function ($match) { return interpolate(redirect, $match); }];
}
return extend(function ($injector, $location) {
return handleIfMatch($injector, handler, what.exec($location.path()));
}, {
prefix: regExpPrefix(what)
});
var strategies = {
matcher: function (what, handler) {
if (handlerIsString) {
redirect = $urlMatcherFactory.compile(handler);
handler = ['$match', function ($match) { return redirect.format($match); }];
}
};

var check = { matcher: $urlMatcherFactory.isMatcher(what), regex: what instanceof RegExp };
return extend(function ($injector, $location) {
return handleIfMatch($injector, handler, what.exec($location.path(), $location.search()));
}, {
prefix: isString(what.prefix) ? what.prefix : ''
});
},
regex: function (what, handler) {
if (what.global || what.sticky) throw new Error("when() RegExp must not be global or sticky");

for (var n in check) {
if (check[n]) {
return this.rule(strategies[n](what, handler));
if (handlerIsString) {
redirect = handler;
handler = ['$match', function ($match) { return interpolate(redirect, $match); }];
}
return extend(function ($injector, $location) {
return handleIfMatch($injector, handler, what.exec($location.path()));
}, {
prefix: regExpPrefix(what)
});
}

throw new Error("invalid 'what' in when()");
};

var check = { matcher: $urlMatcherFactory.isMatcher(what), regex: what instanceof RegExp };

for (var n in check) {
if (check[n]) return this.rule(strategies[n](what, handler));
}

throw new Error("invalid 'what' in when()");
};

/**
* @ngdoc object
* @name ui.router.router.$urlRouter
Expand Down Expand Up @@ -234,9 +229,7 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
function check(rule) {
var handled = rule($injector, $location);

if (!handled) {
return false;
}
if (!handled) return false;
if (isString(handled)) $location.replace().url(handled);
return true;
}
Expand Down Expand Up @@ -287,20 +280,15 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
location = $location.url();
return;
}
if ($location.url() === location) {
return;
}
if ($location.url() === location) return;

$location.url(location);
$location.replace();
},

push: function(urlMatcher, params, options) {
$location.url(urlMatcher.format(params));
options = options || {};

if (options.replace) {
$location.replace();
}
if (options && options.replace) $location.replace();
},

href: function(urlMatcher, params, options) {
Expand Down

0 comments on commit 3a03042

Please sign in to comment.