Merge "Updated cssjanus to v1.1.3"
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.Uri.js
index 9d29b4c..95263ec 100644 (file)
  * @class mw.Uri
  */
 
+/* eslint-disable no-use-before-define */
+
 ( function ( mw, $ ) {
+       var parser, properties;
+
        /**
         * Function that's useful when constructing the URI string -- we frequently encounter the pattern
         * of having to add something to the URI as we go, but only if it's present, and to include a
@@ -68,9 +72,8 @@
                if ( val === undefined || val === null || val === '' ) {
                        return '';
                }
-               /* jshint latedef:false */
+
                return pre + ( raw ? val : mw.Uri.encode( val ) ) + post;
-               /* jshint latedef:true */
        }
 
        /**
         * @static
         * @property {Object} parser
         */
-       var parser = {
+       parser = {
                strict: mw.template.get( 'mediawiki.Uri', 'strict.regexp' ).render(),
                loose: mw.template.get( 'mediawiki.Uri', 'loose.regexp' ).render()
-       },
+       };
 
        /**
         * The order here matches the order of captured matches in the `parser` property regexes.
         * @param {string|Function} documentLocation A full url, or function returning one.
         *  If passed a function, the return value may change over time and this will be honoured. (T74334)
         * @member mw
+        * @return {Function} Uri class
         */
        mw.UriRelative = function ( documentLocation ) {
                var getDefaultUri = ( function () {
                }() );
 
                /**
-                * @class mw.Uri
-                * @constructor
-                *
                 * Construct a new URI object. Throws error if arguments are illegal/impossible, or
                 * otherwise don't parse.
                 *
+                * @class mw.Uri
+                * @constructor
                 * @param {Object|string} [uri] URI string, or an Object with appropriate properties (especially
                 *  another URI object to clone). Object must have non-blank `protocol`, `host`, and `path`
                 *  properties. If omitted (or set to `undefined`, `null` or empty string), then an object
                 * @param {boolean} [options.overrideKeys=false] Whether to let duplicate query parameters
                 *  override each other (`true`) or automagically convert them to an array (`false`).
                 */
-               /* jshint latedef:false */
                function Uri( uri, options ) {
-                       var prop,
+                       var prop, hrefCur,
+                               hasOptions = ( options !== undefined ),
                                defaultUri = getDefaultUri();
 
                        options = typeof options === 'object' ? options : { strictMode: !!options };
                                                this.query = {};
                                        }
                                }
+                       } else if ( hasOptions ) {
+                               // We didn't get a URI in the constructor, but we got options.
+                               hrefCur = typeof documentLocation === 'string' ? documentLocation : documentLocation();
+                               this.parse( hrefCur, options );
                        } else {
-                               // If we didn't get a URI in the constructor, use the default one.
+                               // We didn't get a URI or options in the constructor, use the default instance.
                                return defaultUri.clone();
                        }