remove rss reference, update todo
[mkgallery.git] / include / urlparser.js
1 \r
2 \r
3 /**************************************************************\r
4 \r
5         Script          : URL Parser\r
6         Version         : 1.0\r
7         Authors         : Steven Levithan\r
8         Desc            : Splits any well-formed URL\r
9 \r
10 **************************************************************/\r
11 \r
12 function parseUrl(sourceUrl){\r
13     var urlPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];\r
14     var urlParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUrl);\r
15     var url = {};\r
16     \r
17     for(var i = 0; i < 10; i++){\r
18         url[urlPartNames[i]] = (urlParts[i] ? urlParts[i] : "");\r
19     }\r
20     \r
21     // Always end directoryPath with a trailing backslash if a path was present in the source URI\r
22     // Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key\r
23     if(url.directoryPath.length > 0){\r
24         url.directoryPath = url.directoryPath.replace(/\/?$/, "/");\r
25     }\r
26     \r
27     return url;\r
28 }\r
29 \r
30 /*************************************************************/\r