lint mediawiki.Uri.js

* remove dangling _
* var hosting
* whitespace conventions

Change-Id: I7c78059f640dfdf52020018425026cb714bcdbfa
This commit is contained in:
Timo Tijhof 2012-06-07 18:13:19 +02:00 committed by Antoine Musso
parent 9348e0c1ef
commit 6bd6e4581e

View file

@ -56,7 +56,7 @@
*
*/
( function( $, mw ) {
( function ( mw, $ ) {
/**
* Function that's useful when constructing the URI string -- we frequently encounter the pattern of
@ -70,9 +70,8 @@
function cat( pre, val, post, raw ) {
if ( val === undefined || val === null || val === '' ) {
return '';
} else {
return pre + ( raw ? val : mw.Uri.encode( val ) ) + post;
}
return pre + ( raw ? val : mw.Uri.encode( val ) ) + post;
}
// Regular expressions to parse many common URIs.
@ -98,7 +97,8 @@
* We use a factory to inject a document location, for relative URLs, including protocol-relative URLs.
* so the library is still testable & purely functional.
*/
mw.UriRelative = function( documentLocation ) {
mw.UriRelative = function ( documentLocation ) {
var defaultUri;
/**
* Constructs URI object. Throws error if arguments are illegal/impossible, or otherwise don't parse.
@ -119,11 +119,11 @@
if ( uri !== undefined && uri !== null || uri !== '' ) {
if ( typeof uri === 'string' ) {
this._parse( uri, options );
this.parse( uri, options );
} else if ( typeof uri === 'object' ) {
var _this = this;
$.each( properties, function( i, property ) {
_this[property] = uri[property];
var uriObj = this;
$.each( properties, function ( i, property ) {
uriObj[property] = uri[property];
} );
if ( this.query === undefined ) {
this.query = {};
@ -159,7 +159,7 @@
* @param {String} string
* @return {String} encoded for URI
*/
Uri.encode = function( s ) {
Uri.encode = function ( s ) {
return encodeURIComponent( s )
.replace( /!/g, '%21').replace( /'/g, '%27').replace( /\(/g, '%28')
.replace( /\)/g, '%29').replace( /\*/g, '%2A')
@ -171,7 +171,7 @@
* @param {String} string encoded for URI
* @return {String} decoded string
*/
Uri.decode = function( s ) {
Uri.decode = function ( s ) {
return decodeURIComponent( s.replace( /\+/g, '%20' ) );
};
@ -183,23 +183,25 @@
* @param {Object} options
* @return {Boolean} success
*/
_parse: function( str, options ) {
var matches = parser[ options.strictMode ? 'strict' : 'loose' ].exec( str );
var uri = this;
$.each( properties, function( i, property ) {
parse: function ( str, options ) {
var q,
uri = this,
matches = parser[ options.strictMode ? 'strict' : 'loose' ].exec( str );
$.each( properties, function ( i, property ) {
uri[ property ] = matches[ i+1 ];
} );
// uri.query starts out as the query string; we will parse it into key-val pairs then make
// that object the "query" property.
// we overwrite query in uri way to make cloning easier, it can use the same list of properties.
var q = {};
q = {};
// using replace to iterate over a string
if ( uri.query ) {
uri.query.replace( /(?:^|&)([^&=]*)(?:(=)([^&]*))?/g, function ($0, $1, $2, $3) {
var k, v;
if ( $1 ) {
var k = Uri.decode( $1 );
var v = ( $2 === '' || $2 === undefined ) ? null : Uri.decode( $3 );
k = Uri.decode( $1 );
v = ( $2 === '' || $2 === undefined ) ? null : Uri.decode( $3 );
// If overrideKeys, always (re)set top level value.
// If not overrideKeys but this key wasn't set before, then we set it as well.
@ -227,7 +229,7 @@
* Returns user and password portion of a URI.
* @return {String}
*/
getUserInfo: function() {
getUserInfo: function () {
return cat( '', this.user, cat( ':', this.password, '' ) );
},
@ -235,7 +237,7 @@
* Gets host and port portion of a URI.
* @return {String}
*/
getHostPort: function() {
getHostPort: function () {
return this.host + cat( ':', this.port, '' );
},
@ -244,7 +246,7 @@
* In most real-world URLs, this is simply the hostname, but it is more general.
* @return {String}
*/
getAuthority: function() {
getAuthority: function () {
return cat( '', this.getUserInfo(), '@' ) + this.getHostPort();
},
@ -253,12 +255,12 @@
* Does not preserve the order of arguments passed into the URI. Does handle escaping.
* @return {String}
*/
getQueryString: function() {
getQueryString: function () {
var args = [];
$.each( this.query, function( key, val ) {
var k = Uri.encode( key );
var vals = val === null ? [ null ] : $.makeArray( val );
$.each( vals, function( i, v ) {
$.each( this.query, function ( key, val ) {
var k = Uri.encode( key ),
vals = val === null ? [ null ] : $.makeArray( val );
$.each( vals, function ( i, v ) {
args.push( k + ( v === null ? '' : '=' + Uri.encode( v ) ) );
} );
} );
@ -269,7 +271,7 @@
* Returns everything after the authority section of the URI
* @return {String}
*/
getRelativePath: function() {
getRelativePath: function () {
return this.path + cat( '?', this.getQueryString(), '', true ) + cat( '#', this.fragment, '' );
},
@ -277,7 +279,7 @@
* Gets the entire URI string. May not be precisely the same as input due to order of query arguments.
* @return {String} the URI string
*/
toString: function() {
toString: function () {
return this.protocol + '://' + this.getAuthority() + this.getRelativePath();
},
@ -285,7 +287,7 @@
* Clone this URI
* @return {Object} new URI object with same properties
*/
clone: function() {
clone: function () {
return new Uri( this );
},
@ -294,13 +296,13 @@
* @param {Object} query parameters in key-val form to override or add
* @return {Object} this URI object
*/
extend: function( parameters ) {
extend: function ( parameters ) {
$.extend( this.query, parameters );
return this;
}
};
var defaultUri = new Uri( documentLocation );
defaultUri = new Uri( documentLocation );
return Uri;
};
@ -310,4 +312,4 @@
mw.Uri = mw.UriRelative( document.location.href );
}
} )( jQuery, mediaWiki );
}( mediaWiki, jQuery ) );