MCPcopy Create free account
hub / github.com/KDAB/codebrowser / computeRelativeUrlTo

Function computeRelativeUrlTo

data/codebrowser.js:279–299  ·  view source on GitHub ↗
(source, dest)

Source from the content-addressed store, hash-verified

277 }
278
279 function computeRelativeUrlTo(source, dest) {
280 var src_splitted = source.split("/");
281 if (src_splitted.length > 0 && src_splitted[src_splitted.length-1] == "")
282 src_splitted.pop();
283 var dst_splitted = dest.split("/");
284 var maxMatch = Math.min(src_splitted.length, dst_splitted.length);
285 var pre = 0;
286 while (++pre < maxMatch) {
287 if (src_splitted[pre] != dst_splitted[pre])
288 break;
289 }
290 // make sure the host is the same (http://xxx/ is 3 parts)
291 if (pre < 3)
292 return dest;
293
294 var stack = [];
295 for (i = 0; i < src_splitted.length - pre; ++i) {
296 stack.push("..");
297 }
298 return stack.concat(dst_splitted.slice(pre)).join('/');
299 }
300 /*// Test
301 function test_cmp(a, b) { if (a!=b) { console.log("ASSERT", a, b); alert("FAIL! \n" + a + " != " + b); } }
302 test_cmp(computeRelativeUrlTo("", ""), "");

Callers 1

computeTooltipContentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected