elgg.ajax = function(url, options) {\r
options = elgg.ajax.handleOptions(url, options);\r
\r
- options.url = elgg.extendUrl(options.url);\r
+ options.url = elgg.normalize_url(options.url);\r
return $.ajax(options);\r
};\r
/**\r
* elgg.package = elgg.package || {};\r
* elgg.package.subpackage = elgg.package.subpackage || {};\r
* </pre>\r
+ * \r
+ * @example elgg.provide('elgg.config.translations')\r
+ * \r
+ * @param {string} pkg The package name.\r
*/\r
elgg.provide = function(pkg) {\r
elgg.assertTypeOf('string', pkg);\r
* @return {String} The extended url\r
* @private\r
*/\r
-elgg.extendUrl = function(url) {\r
+elgg.normalize_url = function(url) {\r
url = url || '';\r
- if(url.indexOf(elgg.config.wwwroot) == -1) {\r
- url = elgg.config.wwwroot + url;\r
+ elgg.assertTypeOf('string', url);\r
+ \r
+ if(/(^(https?:)?\/\/)/.test(url)) {\r
+ return url;\r
}\r
\r
- return url;\r
+ return elgg.config.wwwroot + url;\r
};\r
\r
/**\r
* @param {String} url The url to forward to\r
*/\r
elgg.forward = function(url) {\r
- location.href = elgg.extendUrl(url);\r
+ location.href = elgg.normalize_url(url);\r
};
\ No newline at end of file
};\r
\r
ElggLibTest.prototype.testExtendUrl = function() {\r
- var url;\r
- elgg.config.wwwroot = "http://www.elgg.org/";\r
+ elgg.config.wwwroot = "http://elgg.org/";\r
\r
- url = '';\r
- assertEquals(elgg.config.wwwroot, elgg.extendUrl(url));\r
- \r
- url = 'pg/test';\r
- assertEquals('http://www.elgg.org/pg/test', elgg.extendUrl(url));\r
+ var inputs = [\r
+ [elgg.config.wwwroot, ''],\r
+ [elgg.config.wwwroot + 'pg/test', 'pg/test'],\r
+ ['http://google.com', 'http://google.com'],\r
+ ['//example.com', '//example.com'],\r
+ ];\r
+\r
+ for (var i in inputs) {\r
+ assertEquals(inputs[i][0], elgg.normalize_url(inputs[i][1]));\r
+ }\r
};
\ No newline at end of file
}
if (!$new_entity) {
+ //@todo Make this into a function
switch ($row->type) {
case 'object' :
$new_entity = new ElggObject($row);