fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-03-28 09:19 am

[dw-free] jQuerify journals

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

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

Add a jQuerified version of the control strip JS injection, for styles that
don't support the control strip directly.

Patch by [personal profile] fu.

Files modified:
  • cgi-bin/DW/BetaFeatures/journaljquery.pm
  • cgi-bin/LJ/S2.pm
  • cgi-bin/weblib.pl
  • htdocs/tools/endpoints/controlstrip.bml
--------------------------------------------------------------------------------
diff -r f310efdb82bb -r 8ab1c432d0a0 cgi-bin/DW/BetaFeatures/journaljquery.pm
--- a/cgi-bin/DW/BetaFeatures/journaljquery.pm	Mon Mar 28 16:31:21 2011 +0800
+++ b/cgi-bin/DW/BetaFeatures/journaljquery.pm	Mon Mar 28 17:19:46 2011 +0800
@@ -20,6 +20,7 @@ sub args_list {
     my @implemented = (
         "Logging in",
         "Screen/freeze/delete",
+        "Control strip injection for non-supporting journals",
     );
 
     my @notimplemented = (
@@ -27,7 +28,6 @@ sub args_list {
         "Quick reply",
         "Cut expand and collapse",
         "Media embed placeholder expansion",
-        "Control strip injection for non-supporting journals",
         "Same-page poll submission",
         "Thread expander",
         "Icon browser",
diff -r f310efdb82bb -r 8ab1c432d0a0 cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm	Mon Mar 28 16:31:21 2011 +0800
+++ b/cgi-bin/LJ/S2.pm	Mon Mar 28 17:19:46 2011 +0800
@@ -207,8 +207,8 @@ sub make_journal
     $page->{head_content} .= $extra_js;
 
     # inject the control strip JS, but only after any libraries have been injected
-    $page->{head_content} .= LJ::control_strip_js_inject( user => $u->user )
-        if $show_control_strip && ! $beta_jquery;
+    $page->{head_content} .= LJ::control_strip_js_inject( user => $u->user, jquery => $beta_jquery )
+        if $show_control_strip;
 
     s2_run($r, $ctx, $opts, $entry, $page);
 
diff -r f310efdb82bb -r 8ab1c432d0a0 cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl	Mon Mar 28 16:31:21 2011 +0800
+++ b/cgi-bin/weblib.pl	Mon Mar 28 17:19:46 2011 +0800
@@ -3131,6 +3131,7 @@ sub control_strip_js_inject
 {
     my %opts = @_;
     my $user = delete $opts{user} || '';
+    my $jquery = delete $opts{jquery};
 
     my $ret;
 
@@ -3140,25 +3141,44 @@ sub control_strip_js_inject
     my $args = LJ::eurl( $r->query_string ) || '';
     my $view = $r->note( 'view' ) || '';
 
-    $ret .= qq{
-<script type='text/javascript'>
-    function controlstrip_init() {
-        if (! \$('lj_controlstrip') ){
-            HTTPReq.getJSON({
-              url: "/$user/__rpc_controlstrip?user=$user&host=$host&uri=$uri&args=$args&view=$view",
-              onData: function (data) {
-                  var body = document.getElementsByTagName("body")[0];
-                  var div = document.createElement("div");
-                  div.innerHTML = data;
-                      body.appendChild(div);
-              },
-              onError: function (msg) { }
-            });
+    # FIXME: remove argument
+    if ( $jquery ) {
+        $ret .= qq{
+    <script type='text/javascript'>
+    jQuery(function(jQ){
+        if (jQ("#lj_controlstrip").length == 0) {
+            jQ.getJSON("/$user/__rpc_controlstrip?user=$user&host=$host&uri=$uri&args=$args&view=$view", {},
+                function(data) {
+                    jQ("<div></div>").html(data.control_strip).appendTo("body");
+                }
+            );
         }
+    })
+    </script>
+        };
+
+    } else {
+        $ret .= qq{
+    <script type='text/javascript'>
+        function controlstrip_init() {
+            if (! \$('lj_controlstrip') ){
+                HTTPReq.getJSON({
+                  url: "/$user/__rpc_controlstrip?user=$user&host=$host&uri=$uri&args=$args&view=$view",
+                  onData: function (data) {
+                      var body = document.getElementsByTagName("body")[0];
+                      var div = document.createElement("div");
+                      div.innerHTML = data.control_strip;
+                          body.appendChild(div);
+                  },
+                  onError: function (msg) { }
+                });
+            }
+        }
+        DOM.addEventListener(window, "load", controlstrip_init);
+    </script>
+        };
     }
-    DOM.addEventListener(window, "load", controlstrip_init);
-</script>
-    };
+
     return $ret;
 }
 
diff -r f310efdb82bb -r 8ab1c432d0a0 htdocs/tools/endpoints/controlstrip.bml
--- a/htdocs/tools/endpoints/controlstrip.bml	Mon Mar 28 16:31:21 2011 +0800
+++ b/htdocs/tools/endpoints/controlstrip.bml	Mon Mar 28 17:19:46 2011 +0800
@@ -16,6 +16,7 @@ _c?>
 {
     use strict;
     use vars qw(%GET);
+    use JSON;
 
     my $control_strip;
     my $user = $GET{'user'};
@@ -28,6 +29,6 @@ _c?>
 
     sleep 1 if $LJ::IS_DEV_SERVER;
 
-    return LJ::js_dumper($control_strip);
+    return JSON::objToJson( { control_strip => $control_strip } );
 }
 _code?>
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org