diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/lib/elgglib.js | 25 | ||||
-rw-r--r-- | js/lib/ui.js | 6 |
2 files changed, 23 insertions, 8 deletions
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 diff --git a/js/lib/ui.js b/js/lib/ui.js index 3a69e4bfc..0e6634020 100644 --- a/js/lib/ui.js +++ b/js/lib/ui.js @@ -63,7 +63,7 @@ elgg.ui.popsUp = function(event) { event.preventDefault(); event.stopPropagation(); - var target = elgg.getUrlFragment($(this).toggleClass('elgg-state-active').attr('href')); + var target = elgg.getSelectorFromUrlFragment($(this).toggleClass('elgg-state-active').attr('href')); var $target = $(target); // emit a hook to allow plugins to position and control popups @@ -113,7 +113,7 @@ elgg.ui.popupClose = function(event) { // if the click event target isn't in a popup target, fade all of them out. $popups.each(function(i, e) { - var target = elgg.getUrlFragment($(e).attr('href')) + ':visible'; + var target = elgg.getSelectorFromUrlFragment($(e).attr('href')) + ':visible'; var $target = $(target); if (!$target.is(':visible')) { @@ -130,7 +130,7 @@ elgg.ui.popupClose = function(event) { if (!inTarget) { $popups.each(function(i, e) { var $e = $(e); - var $target = $(elgg.getUrlFragment($e.attr('href')) + ':visible'); + var $target = $(elgg.getSelectorFromUrlFragment($e.attr('href')) + ':visible'); if ($target.length > 0) { $target.fadeOut(); $e.removeClass('elgg-state-active'); |