<?php
/**
 * The kindeditor view of common module of ZDOO.
 *
 * @copyright   Copyright 2009-2018 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Chunsheng Wang <chunsheng@cnezsoft.com>
 * @package     common
 * @version     $Id: kindeditor.html.php 4029 2016-08-26 06:50:41Z liugang $
 * @link        http://www.zdoo.com
 */
/* Get current lang. */
$editorLangs = array('en' => 'en', 'zh-cn' => 'zh_CN', 'zh-tw' => 'zh_TW');
$editorLang  = isset($editorLangs[$app->getClientLang()]) ? $editorLangs[$app->getClientLang()] : 'en';
js::set('editorLang', $editorLang);

/* Import css and js for kindeditor. */
js::import($jsRoot . 'kindeditor/kindeditor.min.js');
js::import($jsRoot  . 'kindeditor/lang/' . $editorLang . '.js');
?>
<script>
var editorTools =
{
    simple: ['formatblock', 'fontsize', '|', 'bold', 'italic','underline', '|',
        'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|',
        'emoticons', 'image', 'link', '|', 'removeformat','undo', 'redo', 'source'],
    full: ['formatblock', 'fontsize', 'lineheight', '|', 'forecolor', 'hilitecolor', '|', 'bold', 'italic','underline', 'strikethrough', '|',
        'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|',
        'insertorderedlist', 'insertunorderedlist', '|',
        'emoticons', 'image', 'insertfile', 'hr', '|', 'link', 'unlink', '/',
        'undo', 'redo', '|', 'cut', 'copy', 'paste', '|', 'plainpaste', 'wordpaste', '|', 'removeformat', 'clearhtml','quickformat', '|',
        'indent', 'outdent', 'subscript', 'superscript', '|',
        'table', 'code', '|', 'pagebreak', 'anchor', '|',
        'fullscreen', 'source', 'about'
    ]
};

window.initKindEditor = function(afterInit)
{
    $(':input[type=submit]').after("<input type='hidden' id='uid' name='uid' value=" + v.uid + ">");

    if(typeof(v.editors.filterMode) == 'undefined') v.editors.filterMode = true;

    var editorDefaults  =
    {
        cssPath: [v.themeRoot + 'zui/css/min.css'],
        width: '100%',
        items: editorTools[v.editors.tools],
        filterMode: true,
        bodyClass: 'article-content',
        cssData: 'html,body {background: none}.article-content, .article-content table td, .article-content table th {line-height: 1.3846153846; font-size: 13px;}.article-content .table-auto {width: auto!important; max-width: 100%;}',
        urlType: 'absolute',
        uploadJson: createLink('file', 'ajaxUpload', 'uid=' + v.uid, 'json'),
        fileManagerJson: createLink('file', 'fileManager'),
        imageTabIndex: 1,
        filterMode: v.editors.filterMode,
        allowFileManager: true,
        langType: v.editorLang,
        placeholderStyle: {fontSize: '13px', color: '#888'},
        pasteImage: {postUrl: createLink('file', 'ajaxPasteImage', 'uid=' + v.uid)},
        syncAfterBlur: true,
        spellcheck: false,
    };

    window.editor = {};
    $.each(v.editors.id, function(key, editorID)
    {
        var $editor = $('#' + editorID);
        var options = $.extend({}, editorDefaults, $editor.data());
        try
        {
            var keditor = KindEditor.create('#' + editorID, options);
            window.editor['#'] = window.editor[editorID] = keditor;
            $editor.data('keditor', keditor);
        }
        catch(e){}
    });

    if($.isFunction(afterInit)) afterInit();
}
</script>
