web: include the right unminified version of jquery.url.js (1.1) to avoid js breakage
This commit is contained in:
		
							parent
							
								
									94add086b2
								
							
						
					
					
						commit
						d9370d72d8
					
				@ -1,164 +1,181 @@
 | 
				
			|||||||
// JQuery URL Parser plugin - https://github.com/allmarkedup/jQuery-URL-Parser
 | 
					// JQuery URL Parser
 | 
				
			||||||
// Written by Mark Perkins, mark@allmarkedup.com
 | 
					// Written by Mark Perkins, mark@allmarkedup.com
 | 
				
			||||||
// License: http://unlicense.org/ (i.e. do what you want with it!)
 | 
					// License: http://unlicense.org/ (i.e. do what you want with it!)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;(function($, undefined) {
 | 
					jQuery.url = function()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						var segments = {};
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
    var tag2attr = {
 | 
						var parsed = {};
 | 
				
			||||||
        a       : 'href',
 | 
						
 | 
				
			||||||
        img     : 'src',
 | 
						/**
 | 
				
			||||||
        form    : 'action',
 | 
					    * Options object. Only the URI and strictMode values can be changed via the setters below.
 | 
				
			||||||
        base    : 'href',
 | 
					    */
 | 
				
			||||||
        script  : 'src',
 | 
					  	var options = {
 | 
				
			||||||
        iframe  : 'src',
 | 
						
 | 
				
			||||||
        link    : 'href'
 | 
							url : window.location, // default URI is the page in which the script is running
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							strictMode: false, // 'loose' parsing by default
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
							key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], // keys available to query 
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							q: {
 | 
				
			||||||
 | 
								name: "queryKey",
 | 
				
			||||||
 | 
								parser: /(?:^|&|;)([^&=;]*)=?([^&;]*)/g
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	key = ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","fragment"], // keys available to query
 | 
							parser: {
 | 
				
			||||||
	
 | 
								strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,  //less intuitive, more accurate to the specs
 | 
				
			||||||
	aliases = { "anchor" : "fragment" }, // aliases for backwards compatability
 | 
								loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs
 | 
				
			||||||
 | 
					 | 
				
			||||||
	parser = {
 | 
					 | 
				
			||||||
		strict  : /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,  //less intuitive, more accurate to the specs
 | 
					 | 
				
			||||||
		loose   :  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs
 | 
					 | 
				
			||||||
	},
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	querystring_parser = /(?:^|&|;)([^&=;]*)=?([^&;]*)/g, // supports both ampersand and semicolon-delimted query string key/value pairs
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	fragment_parser = /(?:^|&|;)([^&=;]*)=?([^&;]*)/g; // supports both ampersand and semicolon-delimted fragment key/value pairs
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	function parseUri( url, strictMode )
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		var str = decodeURI( url ),
 | 
					 | 
				
			||||||
		    res   = parser[ strictMode || false ? "strict" : "loose" ].exec( str ),
 | 
					 | 
				
			||||||
		    uri = { attr : {}, param : {}, seg : {} },
 | 
					 | 
				
			||||||
		    i   = 14;
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		while ( i-- )
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			uri.attr[ key[i] ] = res[i] || "";
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// build query and fragment parameters
 | 
						};
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
		uri.param['query'] = {};
 | 
					    /**
 | 
				
			||||||
		uri.param['fragment'] = {};
 | 
					     * Deals with the parsing of the URI according to the regex above.
 | 
				
			||||||
		
 | 
					 	 * Written by Steven Levithan - see credits at top.
 | 
				
			||||||
		uri.attr['query'].replace( querystring_parser, function ( $0, $1, $2 ){
 | 
					     */		
 | 
				
			||||||
			if ($1)
 | 
						var parseUri = function()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
				uri.param['query'][$1] = $2;
 | 
							str = decodeURI( options.url );
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							var m = options.parser[ options.strictMode ? "strict" : "loose" ].exec( str );
 | 
				
			||||||
 | 
							var uri = {};
 | 
				
			||||||
 | 
							var i = 14;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							while ( i-- ) {
 | 
				
			||||||
 | 
								uri[ options.key[i] ] = m[i] || "";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							uri[ options.q.name ] = {};
 | 
				
			||||||
 | 
							uri[ options.key[12] ].replace( options.q.parser, function ( $0, $1, $2 ) {
 | 
				
			||||||
 | 
								if ($1) {
 | 
				
			||||||
 | 
									uri[options.q.name][$1] = $2;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		uri.attr['fragment'].replace( fragment_parser, function ( $0, $1, $2 ){
 | 
					 | 
				
			||||||
			if ($1)
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				uri.param['fragment'][$1] = $2;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
		// split path and fragement into segments
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
        uri.seg['path'] = uri.attr.path.replace(/^\/+|\/+$/g,'').split('/');
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        uri.seg['fragment'] = uri.attr.fragment.replace(/^\/+|\/+$/g,'').split('/');
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // compile a 'base' domain attribute
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        uri.attr['base'] = uri.attr.host ? uri.attr.protocol+"://"+uri.attr.host + (uri.attr.port ? ":"+uri.attr.port : '') : '';
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
		return uri;
 | 
							return uri;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	function getAttrName( elm )
 | 
					    /**
 | 
				
			||||||
 | 
					     * Returns the value of the passed in key from the parsed URI.
 | 
				
			||||||
 | 
					  	 * 
 | 
				
			||||||
 | 
						 * @param string key The key whose value is required
 | 
				
			||||||
 | 
					     */		
 | 
				
			||||||
 | 
						var key = function( key )
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		var tn = elm.tagName;
 | 
							if ( jQuery.isEmptyObject(parsed) )
 | 
				
			||||||
		if ( tn !== undefined ) return tag2attr[tn.toLowerCase()];
 | 
							{
 | 
				
			||||||
		return tn;
 | 
								setUp(); // if the URI has not been parsed yet then do this first...	
 | 
				
			||||||
		} 
 | 
							} 
 | 
				
			||||||
	
 | 
							if ( key == "base" )
 | 
				
			||||||
	$.fn.url = function( strictMode )
 | 
					 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
	    var url = '';
 | 
								if ( parsed.port !== null && parsed.port !== "" )
 | 
				
			||||||
	    
 | 
					 | 
				
			||||||
	    if ( this.length )
 | 
					 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
	        url = $(this).attr( getAttrName(this[0]) ) || '';
 | 
									return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/";	
 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	    
 | 
					 | 
				
			||||||
        return $.url({ url : url, strict : strictMode });
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	$.url = function( opts )
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
	    var url     = '',
 | 
					 | 
				
			||||||
	        strict  = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	    if ( typeof opts === 'string' )
 | 
					 | 
				
			||||||
	    {
 | 
					 | 
				
			||||||
	        url = opts;
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else
 | 
								else
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
	        opts = opts || {};
 | 
									return parsed.protocol+"://"+parsed.host+"/";
 | 
				
			||||||
	        strict = opts.strict || strict;
 | 
					 | 
				
			||||||
            url = opts.url === undefined ? window.location.toString() : opts.url;
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
							return ( parsed[key] === "" ) ? null : parsed[key];
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
					     * Returns the value of the required query string parameter.
 | 
				
			||||||
 | 
					  	 * 
 | 
				
			||||||
 | 
						 * @param string item The parameter whose value is required
 | 
				
			||||||
 | 
					     */		
 | 
				
			||||||
 | 
						var param = function( item )
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							if ( jQuery.isEmptyObject(parsed) )
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								setUp(); // if the URI has not been parsed yet then do this first...	
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if ( item === undefined )
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
					            return parsed.queryKey;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return ( parsed.queryKey[item] === null ) ? null : parsed.queryKey[item];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 'Constructor' (not really!) function.
 | 
				
			||||||
 | 
					     *  Called whenever the URI changes to kick off re-parsing of the URI and splitting it up into segments. 
 | 
				
			||||||
 | 
					     */	
 | 
				
			||||||
 | 
						var setUp = function()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							parsed = parseUri();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							getSegments();	
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Splits up the body of the URI into segments (i.e. sections delimited by '/')
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
						var getSegments = function()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							var p = parsed.path;
 | 
				
			||||||
 | 
							segments = []; // clear out segments array
 | 
				
			||||||
 | 
							segments = parsed.path.length == 1 ? {} : ( p.charAt( p.length - 1 ) == "/" ? p.substring( 1, p.length - 1 ) : path = p.substring( 1 ) ).split("/");
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	return {
 | 
						return {
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
            data : parseUri(url, strict),
 | 
						    /**
 | 
				
			||||||
            
 | 
						     * Sets the parsing mode - either strict or loose. Set to loose by default.
 | 
				
			||||||
            // get various attributes from the URI
 | 
						     *
 | 
				
			||||||
            attr : function( attr )
 | 
						     * @param string mode The mode to set the parser to. Anything apart from a value of 'strict' will set it to loose!
 | 
				
			||||||
 | 
						     */
 | 
				
			||||||
 | 
							setMode : function( mode )
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
                attr = aliases[attr] || attr;
 | 
								options.strictMode = mode == "strict" ? true : false;
 | 
				
			||||||
                return attr !== undefined ? this.data.attr[attr] : this.data.attr;
 | 
								return this;
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
            // return query string parameters
 | 
							/**
 | 
				
			||||||
            param : function( param )
 | 
						     * Sets URI to parse if you don't want to to parse the current page's URI.
 | 
				
			||||||
 | 
							 * Calling the function with no value for newUri resets it to the current page's URI.
 | 
				
			||||||
 | 
						     *
 | 
				
			||||||
 | 
						     * @param string newUri The URI to parse.
 | 
				
			||||||
 | 
						     */		
 | 
				
			||||||
 | 
							setUrl : function( newUri )
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
                return param !== undefined ? this.data.param.query[param] : this.data.param.query;
 | 
								options.url = newUri === undefined ? window.location : newUri;
 | 
				
			||||||
 | 
								setUp();
 | 
				
			||||||
 | 
								return this;
 | 
				
			||||||
		},		
 | 
							},		
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
            // return fragment parameters
 | 
							/**
 | 
				
			||||||
            fparam : function( param )
 | 
						     * Returns the value of the specified URI segment. Segments are numbered from 1 to the number of segments.
 | 
				
			||||||
 | 
							 * For example the URI http://test.com/about/company/ segment(1) would return 'about'.
 | 
				
			||||||
 | 
							 *
 | 
				
			||||||
 | 
							 * If no integer is passed into the function it returns the number of segments in the URI.
 | 
				
			||||||
 | 
						     *
 | 
				
			||||||
 | 
						     * @param int pos The position of the segment to return. Can be empty.
 | 
				
			||||||
 | 
						     */	
 | 
				
			||||||
 | 
							segment : function( pos )
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
                return param !== undefined ? this.data.param.fragment[param] : this.data.param.fragment;
 | 
								if ( jQuery.isEmptyObject(parsed) )
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									setUp(); // if the URI has not been parsed yet then do this first...	
 | 
				
			||||||
 | 
								} 
 | 
				
			||||||
 | 
								if ( pos === undefined )
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									return segments.length;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return ( segments[pos] === "" || segments[pos] === undefined ) ? null : segments[pos];
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
            // return path segments
 | 
							attr : key, // provides public access to private 'key' function - see above
 | 
				
			||||||
            segment : function( seg )
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                if ( seg === undefined )
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    return this.data.seg.path;                    
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                else
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    seg = seg < 0 ? this.data.seg.path.length + seg : seg - 1; // negative segments count from the end
 | 
					 | 
				
			||||||
                    return this.data.seg.path[seg];                    
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
            // return fragment segments
 | 
							param : param // provides public access to private 'param' function - see above
 | 
				
			||||||
            fsegment : function( seg )
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                if ( seg === undefined )
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    return this.data.seg.fragment;                    
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                else
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    seg = seg < 0 ? this.data.seg.fragment.length + seg : seg - 1; // negative segments count from the end
 | 
					 | 
				
			||||||
                    return this.data.seg.fragment[seg];                    
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	};
 | 
					}();
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
})(jQuery);
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user