ctx_old attribute removed (we will use ctx_old_len only), url_complete js function...
[xynt.git] / web / xynt / xynt-commons.js
index 45b5c85..550cc28 100644 (file)
@@ -169,4 +169,45 @@ function url_append_args(url)
     }
 
     return (ret);
-}
\ No newline at end of file
+}
+
+function url_complete(parent, url)
+{
+    var p, p2, rest;
+    var host = "", path = "";
+
+    // host extraction
+    p = parent.indexOf("://");
+    if (p > -1) {
+        rest = parent.substring(p+3);
+        p2 = rest.indexOf("/");
+        if (p2 > -1) {
+            host = parent.substring(0, p+3+p2);
+            rest = parent.substring(p+3+p2);
+        }
+        else {
+            host = rest;
+            rest = "";
+        }
+    }
+    else {
+        rest = parent;
+    }
+
+    // path extraction
+    p = rest.lastIndexOf("/");
+    if (p > -1) {
+        path = rest.substring(0, p+1);
+    }
+
+    // alert("host: ["+host+"]  path: ["+path+"]");
+    if (url.substring(0,6) == 'http:/' || url.substring(0,7) == 'https:/') {
+        return (url);
+    }
+    else if (url.substring(0,1) == '/') {
+        return (host+url);
+    }
+    else {
+        return (host+path+url);
+    }
+}