Fixed and improved spoiler bbcode
authorAlexander Ebert <ebert@woltlab.com>
Thu, 29 Jan 2015 22:17:26 +0000 (23:17 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 29 Jan 2015 22:17:26 +0000 (23:17 +0100)
com.woltlab.wcf/templates/spoilerBBCodeTag.tpl

index 2e15a949af8d238a1a3d0936b103fc2048384360..a4d4ee24b08eedebf649680b049b28451fbec4df 100644 (file)
@@ -1,7 +1,7 @@
 <!-- begin:parser_nonessential -->
 <div class="container containerPadding spoilerBox jsSpoilerBox">
        <header class="jsOnly">
-               <a class="button jsSpoilerToggle">{if $buttonTitle}{@$buttonTitle}{else}{lang}wcf.bbcode.spoiler.show{/lang}{/if}</a>
+               <a class="button jsSpoilerToggle"{if $buttonTitle} data-button-title="{$buttonTitle}"{/if}>{if $buttonTitle}{@$buttonTitle}{else}{lang}wcf.bbcode.spoiler.show{/lang}{/if}</a>
        </header>
        
        <div style="display: none">
@@ -9,30 +9,35 @@
        </div>
 </div>
 
-<script data-relocate="true">
-       //<![CDATA[
-       $(function() {
-               var $spoilerBox = $('.jsSpoilerBox').removeClass('jsSpoilerBox');
-               $spoilerBox.find('> header > .jsSpoilerToggle').click(function() {
-                       var $spoilerToggle = $(this);
-                       $spoilerToggle.toggleClass('active').parent().next().slideToggle({
-                               complete: function() {
-                                       if ($(this).is(':visible')) {
-                                               WCF.DOMNodeInsertedHandler.execute();
-                                       }
-                                       
-                                       {if !$buttonTitle}
-                                               if ($(this).is(':visible')) {
-                                                       $spoilerToggle.text('{lang}wcf.bbcode.spoiler.hide{/lang}');
+{if !$__wcfSpoilerBBCodeJavaScript|isset}
+       {assign var='__wcfSpoilerBBCodeJavaScript' value=true}
+       <script data-relocate="true">
+               //<![CDATA[
+               $(function() {
+                       $('.jsSpoilerBox').each(function(index, spoilerBox) {
+                               var $toggle = $(spoilerBox).removeClass('jsSpoilerBox').find('> header > .jsSpoilerToggle');
+                               $toggle.click(function() {
+                                       $toggle.toggleClass('active').parent().next().slideToggle({
+                                               complete: function() {
+                                                       var $container = $(this);
+                                                       if ($container.is(':visible')) {
+                                                               WCF.DOMNodeInsertedHandler.execute();
+                                                       }
+                                                       
+                                                       if (!$toggle.data('buttonTitle')) {
+                                                               if ($container.is(':visible')) {
+                                                                       $toggle.text('{lang}wcf.bbcode.spoiler.hide{/lang}');
+                                                               }
+                                                               else {
+                                                                       $toggle.text('{lang}wcf.bbcode.spoiler.show{/lang}');
+                                                               }
+                                                       }
                                                }
-                                               else {
-                                                       $spoilerToggle.text('{lang}wcf.bbcode.spoiler.show{/lang}');
-                                               }
-                                       {/if}
-                               }
+                                       });
+                               });
                        });
                });
-       });
-       //]]>
-</script>
+               //]]>
+       </script>
+{/if}
 <!-- end:parser_nonessential -->