aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-04-01 21:49:18 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-04-01 21:49:18 +0000
commitf00d92332b6261eb2bc22c712b9d039092022ae1 (patch)
tree102a035fcc7d035b5fd8ffb0e8fc8c352febec7a
parentc2afc5d4feb9174806d4e46604c2a0cc4d253ca1 (diff)
downloadelgg-f00d92332b6261eb2bc22c712b9d039092022ae1.tar.gz
elgg-f00d92332b6261eb2bc22c712b9d039092022ae1.tar.bz2
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
-rw-r--r--js/lib/elgglib.js25
-rw-r--r--js/lib/ui.js6
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');