Tag: PukiWiki

整形済みテキストを畳む

  • 畳んであるのを示す画像を置く(skin/folding.png)
  • プラグイン(folding.inc.php)
    <?php
    function plugin_folding_convert()
    {
        $param = func_get_args();
        $bgcolor = empty($param[0]) ? 'lightyellow' : $param[0];
    
        $res = <<< EOS
    <script type="text/javascript">  
        (function(d, j, b){
            if (j) return b(j);
            var s = d.createElement('script');
            s.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
            d.body.appendChild(s).onload = b;
        })(document, this.jQuery, function(){
            $('pre').each(function() {
                var t = $(this).text().split("\\n", 1)[0].replace('<', '&lt;');
                $(this).before('<div class="folding"><pre>' + t + '</pre></div>');
            });
            $('div.folding>pre').css({background: 'url(skin/folding.png) no-repeat top right', backgroundColor: '{$bgcolor}', cursor: 'pointer'});
            $('div.folding').click(function(){
                $(this).next('pre').show();
                $(this).hide();
            });
            $('div.folding').next('pre').hide();
        });
    </script>
    EOS;
    
        return $res;
    }
    ?>

Last-modified: 2012-10-03 (水) 10:37:37 (1842d)