You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
trace("Warning, could not make URL relative because base URL is relative and should be absolute - could not find pattern \"://\" in "+base+". Now returns "+initialUrl);
67
+
returninitialUrl;
68
+
}
69
+
else
70
+
{
71
+
base=base.substr(idx+3);
72
+
}
73
+
varidx=url.indexOf("://");
74
+
// check that we have absolute urls
75
+
if (idx==-1)
76
+
{
77
+
trace("Warning, could not make URL relative because it is relative already - could not find pattern \"://\". Now returns "+initialUrl);
78
+
returninitialUrl;
79
+
}
80
+
else
81
+
{
82
+
url=url.substr(idx+3);
83
+
}
84
+
85
+
86
+
// split base url
87
+
varbaseArray=base.split("/");
88
+
// split url
89
+
varurlArray=url.split("/");
90
+
91
+
// check that there is a common domain name
92
+
if (baseArray[0] !=urlArray[0])
93
+
{
94
+
trace("Warning, could not make URL relative because the url is absolute external url - "+urlArray[0]+" != "+baseArray[0]+". Now returns initial URL "+initialUrl);
95
+
// the url is absolute external url
96
+
returninitialUrl;
97
+
}
98
+
99
+
// **
100
+
// find the common parts in both base and url
101
+
vardiffIdx=0;
102
+
for (idxin0...baseArray.length)
103
+
{
104
+
if (urlArray.length<idx||baseArray[idx] !=urlArray[idx]){
105
+
//trace("abs2rel found differenciation idx = "+idx+" ("+urlArray[idx]+" != "+baseArray[idx]+")");
106
+
// at this point, URLs are different
107
+
diffIdx=idx;
108
+
break;
109
+
}
110
+
}
111
+
// **
112
+
// build the final result
113
+
varresUrl="";
114
+
// add "../"
115
+
if (baseArray.length>diffIdx+1)
116
+
{
117
+
for (idxindiffIdx...baseArray.length-1){
118
+
resUrl+="../";
119
+
}
120
+
}
121
+
// add everything after the common part
122
+
for (idxindiffIdx...urlArray.length){
123
+
resUrl+=urlArray[idx];
124
+
// only if it is not the file name
125
+
if (idx!=urlArray.length-1)
126
+
{
127
+
resUrl+="/";
128
+
}
129
+
}
130
+
returnresUrl;
131
+
132
+
133
+
// remove path to the publication folder
134
+
/* var pubUrl = "publications/";
135
+
var idxPubFolder = url.indexOf(pubUrl);
136
+
if (idxPubFolder >= 0){
137
+
// remove all the common parts
138
+
url = url.substr(idxPubFolder + pubUrl.length);
139
+
// remove publication name if it is the current publication or add the relative path "../"
140
+
var pubUrl = PublicationModel.getInstance().currentName + "/";
141
+
var idxPubFolder = url.indexOf(pubUrl);
142
+
if (idxPubFolder >= 0){
143
+
// remove all the common parts
144
+
url = url.substr(idxPubFolder + pubUrl.length);
145
+
}
146
+
else{
147
+
// add the relative path to publication folder
148
+
url = "../"+url;
149
+
}
150
+
}
151
+
return url;
152
+
*/ }
153
+
/**
154
+
* convert into absolute url
155
+
* duplicated from cocktail.core.history.History
156
+
*
157
+
* handle the .. in relative urls, take the base tag into account
158
+
* todo: do it right like described here http://dev.w3.org/html5/spec/single-page.html#fallback-base-url
trace("set base tag "+href+" -> "+DomTools.rel2abs(href));
563
+
href=DomTools.rel2abs(href);
407
564
if (baseNodes.length>0){
408
565
trace("Warning: base tag already set in the head section. Current value (\""+baseNodes[0].getAttribute("href")+"\") will be replaced by \""+href+"\"");
409
566
baseNodes[0].setAttribute("href", href);
@@ -418,5 +575,19 @@ class DomTools
418
575
head.appendChild(node);
419
576
}
420
577
}
421
-
578
+
/**
579
+
* compute the base url of the document
580
+
* handle base tag if any, otherwise take the documentlocation
0 commit comments