From f00d92332b6261eb2bc22c712b9d039092022ae1 Mon Sep 17 00:00:00 2001 From: brettp Date: Fri, 1 Apr 2011 21:49:18 +0000 Subject: Refs #3098. Changed elgg.getUrlFragment to elgg.getSelectorFromUrlFragment to allow for better selectors. git-svn-id: http://code.elgg.org/elgg/trunk@8897 36083f99-b078-4883-b0ff-0f9b5a30f544 --- js/lib/elgglib.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'js/lib/elgglib.js') diff --git a/js/lib/elgglib.js b/js/lib/elgglib.js index f6d5f51ce..5ba80fc06 100644 --- a/js/lib/elgglib.js +++ b/js/lib/elgglib.js @@ -353,15 +353,30 @@ elgg.forward = function(url) { }; /** - * Returns the fragment part of the URL, including the #. Returns '' if no fragment. + * Returns a jQuery selector from a URL's fragement. Defaults to expecting an ID. * - * @param {String} url The URL. + * Examples: + * http://elgg.org/download.php returns '' + * http://elgg.org/download.php#id returns #id + * http://elgg.org/download.php#.class-name return .class-name + * http://elgg.org/download.php#a.class-name return a.class-name + * + * @param {String} url The URL + * @return {String} The selector */ -elgg.getUrlFragment = function(url) { +elgg.getSelectorFromUrlFragment = function(url) { var fragment = url.split('#')[1]; - + if (fragment) { - return '#' + fragment; + // this is a .class or a tag.class + if (fragment.indexOf('.') > -1) { + return fragment; + } + + // this is an id + else { + return '#' + fragment; + } } return ''; } \ No newline at end of file -- cgit v1.2.3