Beispiel #1
0
    public function footer()
    {
        $nodetags = Forum_Common::allNodeTags();
        $topicNode = isset($this->currentTag['parent']) ? $this->currentTag['parent'] != 0 ? $this->currentTag['parent'] : $this->currentTag['mid'] : 0;
        $html = <<<EOT
<script src="{$this->options->themeUrl('codemirror/codemirror.js', 'default')}"></script>
<script src="{$this->options->themeUrl('codemirror/markdown.js', 'default')}"></script>
<script src="{$this->options->themeUrl('js/jquery.tagsinput.min.js', 'default')}"></script>
<script>
//编辑器
var pubEditor = CodeMirror.fromTextArea(document.getElementById("topic_content"), {
    lineNumbers: true,
    mode: "markdown",
    theme: "neo",
    indentUnit: 4,
    lineWrapping: true
});
//实时统计并控制内容字数
pubEditor.on('change', function(cm, change) {
    var text = cm.getValue();
    var max = 20000;
    var remaining = max - text.length;
    var r = \$("#content_remaining");
    r.html(remaining);
});
//实时统计并控制标题字数
\$("#topic_title").keyup(function(e) {
    var s = \$("#topic_title");
    var text = s.val()
    var max = 120;
    var remaining = max - text.length;
    var r = \$("#title_remaining");
    r.html(remaining);
});
//切换标签
\$('#topic-node').on('change',function(){
\tvar that = \$(this); mid = that.data('mid'),select = that.val();
\tif(select == mid){
\t    return false;
\t}
\tthat.data('mid',select);
\tsetRecTags(select);
});
function setRecTags(mid){
\tvar nodes = {$nodetags},html='<strong>推荐标签:</strong>';
\tif(nodes[mid]!==undefined){
\t\t\$.each(nodes[mid] ,function(id,tags){
\t\t    html += '<a class="tag" href="#'+tags.slug+'">'+tags.name+'</a>';
\t\t});
\t}else{
\t\t//html='<strong>暂无推荐</strong>'
\t}
\t\$('#topic-hot-tags').html(html);
}
//设置默认
\$('#topic-node').val({$topicNode});
setRecTags({$topicNode});

//标签
\$('#tagsInput').tagsInput({
\twidth:'auto',
\theight:'auto',
\tdefaultText : '请输入标签名'
});
\$(document).on('click','#topic-hot-tags a',function(){
\tvar tag = \$(this).text();
    \$('#tagsInput').addTag(tag);
    return false;
});

function prevTopic(){
\tvar box = \$("#topic_preview_box");
\tvar preview = \$("#topic_preview");
\tif (preview.length == 0) {
        box.append('<div class="inner" id="topic_preview"></div>');
        preview = \$("#topic_preview");
    }
\tvar md = pubEditor.getValue();
\tif(md=='') return false;
\t\$.post( window.siteUrl+"publish/preview", { 'md' : md }, function( data ) {
        preview.html('<div class="post-content">' + data + '</div>');
    });
}
</script>
EOT;
        echo $html;
    }