[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
fu.
Files modified:
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]](https://www.dreamwidth.org/img/silk/identity/user.png)
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?> --------------------------------------------------------------------------------