fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-05-25 09:26 am

[dw-free] Split context hover menu option

[commit: http://hg.dwscoalition.org/dw-free/rev/c0f1f41e95bd]

http://bugs.dwscoalition.org/show_bug.cgi?id=1679

Option to display hover menu is now: never, only for icons, only for
userheads, never.

Patch by [personal profile] yvi.

Files modified:
  • bin/upgrading/en.dat
  • cgi-bin/LJ/Setting/CtxPopup.pm
  • cgi-bin/LJ/User.pm
  • cgi-bin/weblib.pl
  • htdocs/js/contextualhover.js
--------------------------------------------------------------------------------
diff -r 2bc258cb57a7 -r c0f1f41e95bd bin/upgrading/en.dat
--- a/bin/upgrading/en.dat	Tue May 25 13:11:22 2010 +0800
+++ b/bin/upgrading/en.dat	Tue May 25 17:31:44 2010 +0800
@@ -2457,6 +2457,16 @@ setting.ctxpopup.label=Hover Menu
 
 setting.ctxpopup.option=Show menu when I hover over userhead images or userpics
 
+setting.ctxpopup.option2=Show the contextual menu when you hover over:
+
+setting.ctxpopup.option.both=Both
+
+setting.ctxpopup.option.icons=Icons
+
+setting.ctxpopup.option.none=Never
+
+setting.ctxpopup.option.userhead=Userhead graphic
+
 setting.cutdisable.label=Cut Tag Behavior
 
 setting.cutdisable.option=Display full content of cut entries?
diff -r 2bc258cb57a7 -r c0f1f41e95bd cgi-bin/LJ/Setting/CtxPopup.pm
--- a/cgi-bin/LJ/Setting/CtxPopup.pm	Tue May 25 13:11:22 2010 +0800
+++ b/cgi-bin/LJ/Setting/CtxPopup.pm	Tue May 25 17:31:44 2010 +0800
@@ -29,26 +29,32 @@ sub label {
 }
 
 sub option {
-    my ($class, $u, $errs, $args) = @_;
+    my ( $class, $u, $errs, $args ) = @_;
     my $key = $class->pkgkey;
 
-    my $ctxpopup = $class->get_arg($args, "ctxpopup") || $u->prop('opt_ctxpopup');
+    my $ctxpopup = $class->get_arg( $args, "ctxpopup" ) || $u->opt_ctxpopup;
 
-    my $ret = LJ::html_check({
+    my @options = (
+        I => $class->ml( 'setting.ctxpopup.option.icons' ),
+        U => $class->ml( 'setting.ctxpopup.option.userhead' ),
+        Y => $class->ml( 'setting.ctxpopup.option.both' ),
+        N => $class->ml( 'setting.ctxpopup.option.none' ),
+    );
+
+    my $ret = "<label for='${key}ctxpopup'>" . $class->ml( 'setting.ctxpopup.option2' ) . "</label> ";
+    $ret .= LJ::html_select({
         name => "${key}ctxpopup",
         id => "${key}ctxpopup",
-        value => 1,
-        selected => $ctxpopup ? 1 : 0,
-    });
-    $ret .= " <label for='${key}ctxpopup'>" . $class->ml('setting.ctxpopup.option') . "</label>";
+        selected => $ctxpopup,
+    }, @options );
 
     return $ret;
 }
 
 sub save {
-    my ($class, $u, $args) = @_;
+    my ( $class, $u, $args ) = @_;
 
-    my $val = $class->get_arg($args, "ctxpopup") ? "Y" : "N";
+    my $val = $class->get_arg( $args, "ctxpopup" );
     $u->set_prop( opt_ctxpopup => $val );
 
     return 1;
diff -r 2bc258cb57a7 -r c0f1f41e95bd cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm	Tue May 25 13:11:22 2010 +0800
+++ b/cgi-bin/LJ/User.pm	Tue May 25 17:31:44 2010 +0800
@@ -5072,7 +5072,17 @@ sub opt_ctxpopup {
     # if unset, default to on
     my $prop = $u->raw_prop('opt_ctxpopup') || 'Y';
 
-    return $prop eq 'Y';
+    return $prop;
+}
+
+# should contextual hover be displayed for icons
+sub opt_ctxpopup_icons {
+    return ( $_[0]->prop( 'opt_ctxpopup' ) eq "Y" || $_[0]->prop( 'opt_ctxpopup' ) eq "I" );
+}
+
+# should contextual hover be displayed for the graphical userhead
+sub opt_ctxpopup_userhead {
+    return ( $_[0]->prop( 'opt_ctxpopup' ) eq "Y" || $_[0]->prop( 'opt_ctxpopup' ) eq "U" );
 }
 
 
diff -r 2bc258cb57a7 -r c0f1f41e95bd cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl	Tue May 25 13:11:22 2010 +0800
+++ b/cgi-bin/weblib.pl	Tue May 25 17:31:44 2010 +0800
@@ -2446,8 +2446,10 @@ sub res_includes {
     my $hasremote = $remote ? 1 : 0;
 
     # ctxpopup prop
-    my $ctxpopup = 1;
-    $ctxpopup = 0 if $remote && ! $remote->prop("opt_ctxpopup");
+    my $ctxpopup_icons = 1;
+    my $ctxpopup_userhead = 1;
+    $ctxpopup_icons = 0 if $remote && ! $remote->opt_ctxpopup_icons;
+    $ctxpopup_userhead = 0 if $remote && ! $remote->opt_ctxpopup_userhead;
 
     # poll for esn inbox updates?
     my $inbox_update_poll = LJ::is_enabled('inbox_update_poll');
@@ -2465,7 +2467,9 @@ sub res_includes {
                 currentJournalBase => "$journal_base",
                 currentJournal => "$journal",
                 has_remote => $hasremote,
-                ctx_popup => $ctxpopup,
+                ctx_popup => ( $ctxpopup_icons || $ctxpopup_userhead ),
+                ctx_popup_icons => $ctxpopup_icons,
+                ctx_popup_userhead => $ctxpopup_userhead,
                 inbox_update_poll => $inbox_update_poll,
                 media_embed_enabled => $embeds_enabled,
                 esn_async => $esn_async,
diff -r 2bc258cb57a7 -r c0f1f41e95bd htdocs/js/contextualhover.js
--- a/htdocs/js/contextualhover.js	Tue May 25 13:11:22 2010 +0800
+++ b/htdocs/js/contextualhover.js	Tue May 25 17:31:44 2010 +0800
@@ -17,44 +17,48 @@ ContextualPopup.setup = function () {
     // don't do anything if no remote
     if (!Site || !Site.ctx_popup) return;
 
+    var userElements = [];
+
     // attach to all ljuser head icons
-    var ljusers = DOM.getElementsByTagAndClassName(document, 'span', "ljuser");
+    if (Site.ctx_popup_userhead) {
+        var ljusers = DOM.getElementsByTagAndClassName(document, 'span', "ljuser");
 
-    var userElements = [];
-    ljusers.forEach(function (ljuser) {
-        var nodes = ljuser.getElementsByTagName("img");
-        for (var i=0; i < nodes.length; i++) {
-            var node = nodes.item(i);
+        ljusers.forEach(function (ljuser) {
+            var nodes = ljuser.getElementsByTagName("img");
+            for (var i=0; i < nodes.length; i++) {
+                var node = nodes.item(i);
 
-            // if the parent (a tag with link to userinfo) has userid in its URL, then
-            // this is an openid user icon and we should use the userid
-            var parent = node.parentNode;
-            var userid;
-            if (parent && parent.href && (userid = parent.href.match(/\?userid=(\d+)/i)))
-                node.userid = userid[1];
-            else
-                node.username = ljuser.getAttribute("lj:user");
+                // if the parent (a tag with link to userinfo) has userid in its URL, then
+                // this is an openid user icon and we should use the userid
+                var parent = node.parentNode;
+                var userid;
+                if (parent && parent.href && (userid = parent.href.match(/\?userid=(\d+)/i)))
+                    node.userid = userid[1];
+                else
+                    node.username = ljuser.getAttribute("lj:user");
 
-            if (!node.username && !node.userid) continue;
+                if (!node.username && !node.userid) continue;
 
-            userElements.push(node);
-            DOM.addClassName(node, "ContextualPopup");
+                userElements.push(node);
+                DOM.addClassName(node, "ContextualPopup");
 
-        }
-    });
+            }
+        });
+    };
 
     // attach to all userpics
-    var images = document.getElementsByTagName("img") || [];
-    Array.prototype.forEach.call(images, function (image) {
-        // if the image url matches a regex for userpic urls then attach to it
-        if (image.src.match(/userpic\..+\/\d+\/\d+/) ||
-            image.src.match(/\/userpic\/\d+\/\d+/)) {
-            image.up_url = image.src;
-            DOM.addClassName(image, "ContextualPopup");
-            userElements.push(image);
-
-        }
-    });
+    if (Site.ctx_popup_icons) {
+        var images = document.getElementsByTagName("img") || [];
+        Array.prototype.forEach.call(images, function (image) {
+            // if the image url matches a regex for userpic urls then attach to it
+            if (image.src.match(/userpic\..+\/\d+\/\d+/) ||
+                image.src.match(/\/userpic\/\d+\/\d+/)) {
+                image.up_url = image.src;
+                DOM.addClassName(image, "ContextualPopup");
+                userElements.push(image);
+           }
+        });
+    };
 
     var ctxPopupId = 1;
     userElements.forEach(function (userElement) {
--------------------------------------------------------------------------------