blob: 764767fe0ce8d19ef245b05654fb839fa4e0a8e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/**
* $Id: mxUrlConverter.js,v 1.3 2012-08-24 17:10:41 gaudenz Exp $
* Copyright (c) 2006-2010, JGraph Ltd
*/
/**
*
* Class: mxUrlConverter
*
* Converts relative and absolute URLs to absolute URLs with protocol and domain.
*/
var mxUrlConverter = function(root)
{
/**
* Variable: enabled
*
* Specifies if the converter is enabled. Default is true.
*/
var enabled = true;
/**
* Variable: baseUrl
*
* Specifies the base URL to be used as a prefix for relative URLs.
*/
var baseUrl = null;
/**
* Variable: baseDomain
*
* Specifies the base domain to be used as a prefix for absolute URLs.
*/
var baseDomain = null;
// Private helper function to update the base URL
var updateBaseUrl = function()
{
baseDomain = location.protocol + '//' + location.host;
baseUrl = baseDomain + location.pathname;
var tmp = baseUrl.lastIndexOf('/');
// Strips filename etc
if (tmp > 0)
{
baseUrl = baseUrl.substring(0, tmp + 1);
}
};
// Returns public interface
return {
/**
* Function: isEnabled
*
* Returns <enabled>.
*/
isEnabled: function()
{
return enabled;
},
/**
* Function: setEnabled
*
* Sets <enabled>.
*/
setEnabled: function(value)
{
enabled = value;
},
/**
* Function: getBaseUrl
*
* Returns <baseUrl>.
*/
getBaseUrl: function()
{
return baseUrl;
},
/**
* Function: setBaseUrl
*
* Sets <baseUrl>.
*/
setBaseUrl: function(value)
{
baseUrl = value;
},
/**
* Function: getBaseDomain
*
* Returns <baseDomain>.
*/
getBaseDomain: function()
{
return baseUrl;
},
/**
* Function: setBaseDomain
*
* Sets <baseDomain>.
*/
setBaseDomain: function(value)
{
baseUrl = value;
},
/**
* Function: convert
*
* Converts the given URL to an absolute URL with protol and domain.
* Relative URLs are first converted to absolute URLs.
*/
convert: function(url)
{
if (enabled && url.indexOf('http://') != 0 && url.indexOf('https://') != 0 && url.indexOf('data:image') != 0)
{
if (baseUrl == null)
{
updateBaseUrl();
}
if (url.charAt(0) == '/')
{
url = baseDomain + url;
}
else
{
url = baseUrl + url;
}
}
return url;
}
};
};
|