|
|
|
@ -20,21 +20,42 @@
@@ -20,21 +20,42 @@
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
"use strict"; |
|
|
|
|
define([ |
|
|
|
|
], function() { |
|
|
|
|
define(["underscore"], function(_) { |
|
|
|
|
|
|
|
|
|
// restURL
|
|
|
|
|
return ["globalContext", "$window", function(context, $window) { |
|
|
|
|
return { |
|
|
|
|
room: function(id) { |
|
|
|
|
id = $window.encodeURIComponent(id); |
|
|
|
|
return $window.location.protocol + '//' + $window.location.host + context.Cfg.B + id; |
|
|
|
|
}, |
|
|
|
|
buddy: function(id) { |
|
|
|
|
return $window.location.protocol + '//' + $window.location.host + context.Cfg.B + "static/img/buddy/s46/" + id; |
|
|
|
|
}, |
|
|
|
|
api: function(path) { |
|
|
|
|
return (context.Cfg.B || "/") + "api/v1/" + path; |
|
|
|
|
var RestURL = function() {}; |
|
|
|
|
RestURL.prototype.room = function(name) { |
|
|
|
|
var url = this.encodeRoomURL(name); |
|
|
|
|
return $window.location.protocol + '//' + $window.location.host + context.Cfg.B + url; |
|
|
|
|
}; |
|
|
|
|
RestURL.prototype.buddy = function(id) { |
|
|
|
|
return $window.location.protocol + '//' + $window.location.host + context.Cfg.B + "static/img/buddy/s46/" + id; |
|
|
|
|
}; |
|
|
|
|
RestURL.prototype.api = function(path) { |
|
|
|
|
return (context.Cfg.B || "/") + "api/v1/" + path; |
|
|
|
|
}; |
|
|
|
|
RestURL.prototype.encodeRoomURL = function(name, prefix) { |
|
|
|
|
// Split parts so slashes are allowed.
|
|
|
|
|
var parts = name.split("/"); |
|
|
|
|
var url = []; |
|
|
|
|
if (typeof prefix !== "undefined") { |
|
|
|
|
url.push(prefix); |
|
|
|
|
} |
|
|
|
|
// Allow some thing in room name parts.
|
|
|
|
|
_.each(parts, function(p) { |
|
|
|
|
p = $window.encodeURIComponent(p); |
|
|
|
|
p = p.replace(/^%40/, "@"); |
|
|
|
|
p = p.replace(/^%24/, "$"); |
|
|
|
|
p = p.replace(/^%2B/, "+"); |
|
|
|
|
url.push(p); |
|
|
|
|
}); |
|
|
|
|
if (url.length > 1 && url[url.length-1] === "") { |
|
|
|
|
// Remove trailing slash if any.
|
|
|
|
|
url.pop(); |
|
|
|
|
} |
|
|
|
|
return url.join("/"); |
|
|
|
|
}; |
|
|
|
|
return new RestURL(); |
|
|
|
|
}]; |
|
|
|
|
}); |
|
|
|
|