Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r21212: LJSUP-11031 (<lj-spoiler> tag)

Committer: ailyin
LJSUP-11031 (<lj-spoiler> tag)
U   trunk/cgi-bin/cleanhtml.pl
U   trunk/htdocs/js/livejournal.js
U   trunk/htdocs/stc/lj_base.css
Modified: trunk/cgi-bin/cleanhtml.pl
===================================================================
--- trunk/cgi-bin/cleanhtml.pl	2012-02-17 12:41:19 UTC (rev 21211)
+++ trunk/cgi-bin/cleanhtml.pl	2012-02-17 13:37:50 UTC (rev 21212)
@@ -316,6 +316,8 @@
     my $text_a_link = 0;
     my $text_b_link = 0;
 
+    my $ljspoilers_open = 0;
+
   TOKEN:
     while (my $token = $p->get_token)
     {
@@ -462,6 +464,19 @@
                 $newdata .= Encode::decode_utf8(LJ::WishElement->check_and_expand_entry($userid, $wishid));
             }
 
+            if ( $tag eq 'lj-spoiler' ) {
+                my $title = $attr->{'title'} ||
+                    $attr->{'text'} ||
+                    Encode::decode_utf8(
+                        LJ::Lang::ml('fcklang.ljspoiler.prompt.text') );
+
+                $title = LJ::ehtml($title);
+
+                $newdata .= qq{<div class="lj-spoiler"><p class="lj-spoiler-open"><a href="#">$title</a></p><div class="lj-spoiler-content">};
+                $ljspoilers_open++;
+                next TOKEN;
+            }
+
             # Capture object and embed tags to possibly transform them into something else.
             if ($tag eq "object" || $tag eq "embed") {
                 if (LJ::are_hooks("transform_embed") && !$noexpand_embedded) {
@@ -1405,6 +1420,11 @@
                 # ignore it
             } elsif ( $tag eq 'lj-lang-container' ) {
                 shift @lj_lang_otherwise;
+            } elsif ( $tag eq 'lj-spoiler' ) {
+                if ($ljspoilers_open) {
+                    $newdata .= qq{</div></div>};
+                    $ljspoilers_open--;
+                }
             } else {
                 if ($mode eq "allow") {
                     $allow = 1;
@@ -1602,6 +1622,10 @@
         }
     }
 
+    if ($ljspoilers_open) {
+        $newdata .= qq{</div></div>} x $ljspoilers_open;
+    }
+
     # extra-paranoid check
     1 while $newdata =~ s/<script\b//ig;
 

Modified: trunk/htdocs/js/livejournal.js
===================================================================
--- trunk/htdocs/js/livejournal.js	2012-02-17 12:41:19 UTC (rev 21211)
+++ trunk/htdocs/js/livejournal.js	2012-02-17 13:37:50 UTC (rev 21212)
@@ -639,3 +639,13 @@
 	return function() { return forceMobile || isMobile; }
 }();
 
+jQuery(function($) {
+    $(document.body).click(function(e) {
+        var target = $(e.target);
+        if (!target.is(".lj-spoiler > p.lj-spoiler-open > a")) return;
+
+        e.preventDefault();
+        target.parent().parent().toggleClass("lj-spoiler-opened");
+    });
+});
+

Modified: trunk/htdocs/stc/lj_base.css
===================================================================
--- trunk/htdocs/stc/lj_base.css	2012-02-17 12:41:19 UTC (rev 21211)
+++ trunk/htdocs/stc/lj_base.css	2012-02-17 13:37:50 UTC (rev 21212)
@@ -3926,3 +3926,7 @@
 	.b-mediaplaceholder-external .b-mediaplaceholder-inner {
 		display: none !important;
 		}
+
+.lj-spoiler .lj-spoiler-content { display: none; }
+.lj-spoiler-opened .lj-spoiler-content { display: block; }
+

Tags: ailyin, andy, css, js, livejournal, pl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments