]> www.average.org Git - mkgallery.git/blobdiff - include/urlparser.js
WIP on migratin to phatfusion slideshow
[mkgallery.git] / include / urlparser.js
diff --git a/include/urlparser.js b/include/urlparser.js
new file mode 100644 (file)
index 0000000..cbcdda9
--- /dev/null
@@ -0,0 +1,30 @@
+\r
+\r
+/**************************************************************\r
+\r
+       Script          : URL Parser\r
+       Version         : 1.0\r
+       Authors         : Steven Levithan\r
+       Desc            : Splits any well-formed URL\r
+\r
+**************************************************************/\r
+\r
+function parseUrl(sourceUrl){\r
+    var urlPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];\r
+    var urlParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUrl);\r
+    var url = {};\r
+    \r
+    for(var i = 0; i < 10; i++){\r
+        url[urlPartNames[i]] = (urlParts[i] ? urlParts[i] : "");\r
+    }\r
+    \r
+    // Always end directoryPath with a trailing backslash if a path was present in the source URI\r
+    // Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key\r
+    if(url.directoryPath.length > 0){\r
+        url.directoryPath = url.directoryPath.replace(/\/?$/, "/");\r
+    }\r
+    \r
+    return url;\r
+}\r
+\r
+/*************************************************************/\r