<?php
$edit_id = $edit_id?:'remark';
// 默认文字
switch ($edit_id) {
    case 'stand_remark':
        $defaultText = '请输入业主心态，可从卖房原因、卖房紧迫度，是否可议价等方面进行描述';
        break;
    case 'service_remark':
        $defaultText = '请输入服务优势，可从行业经验、服务内容等方面进行描述';
        break;
    case 'remark':
    default:
        $defaultText = '请输入房源核心优势，可从【小区】、【户型】、【核心卖点】、【周边配套】等方面进行描述';
        break;
}
?>
<html>
<head>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
    </style>
    <script charset='gbk' src='<?= STATIC_SOURCE_URL ?>/common/js/jquery-1.8.3.min.js'></script>
    <script charset='utf-8' src='<?= STATIC_SOURCE_URL ?>/common/js/kindeditor-4.1.10/kindeditor-min.js'></script>
    <script charset='gbk' src='<?= STATIC_SOURCE_URL ?>/common/js/kindeditor-4.1.10/lang/zh_CN.js'></script>
</head>
<body style="backgroud:none;">
<textarea name="<?= $edit_id ?>" id="<?= $edit_id ?>" cols="0" rows="0"
          style="width:835px;height:155px;display:none;"></textarea>
<script>
  document.getElementById('<?=$edit_id?>').value = window.parent.document.getElementById('<?=$edit_id?>').value;
  var currText = $("#<?=$edit_id?>", window.parent.document).val();
  var editor;
  var defaultText = '<?=$defaultText?>';

  // 默认赋值
  $("#<?=$edit_id?>").val(currText);

  KindEditor.ready(function (K) {
    editor = K.create('#<?=$edit_id?>', {
      width: '<?= $width ?>px',
      height: '<?= $height ?>px',
      resizeType: 0,
      allowPreviewEmoticons: false,
      allowImageUpload: false,
      items: [<?=$items?>],
      //下面这行代码，当失去焦点时执行 this.sync();
      afterBlur: function () {
        this.sync();
        if (editor.html() === '') {
          editor.html(defaultText);
          $(".ke-edit-iframe").contents().find(".ke-content").css("color", "#777");
          //document.getElementsByClassName('ke-content')[0].style.color  = '#777';
          //console.log(document.getElementsByClassName('ke-content'))
        }
        //window.parent.document.getElementById('<?=$edit_id?>').value = document.getElementById('<?=$edit_id?>').value;
        window.parent.document.getElementById('<?=$edit_id?>').value = currText;
        // 赋值到父元素
        //$("#<?=$edit_id?>", window.parent.document).val = currText;
        //$("#jsErrorBox").html("");
        //$("#remark").blur();
        /*if($("#remark").val()!='<p>	&nbsp;</p>' && $("#remark").val()!='<br />')
        {
            alert("1")
            $("#remark2").val($("#remark").val());
         }else{
            $("#remark2").val("");
         }*/
      },
      afterFocus: function () {
        if (editor.html() === defaultText) {
          editor.html('');
          $(".ke-edit-iframe").contents().find(".ke-content").css("color", "black");
        }
      },
      afterCreate:function () {
        //为编辑框赋值
        setTimeout(function () {
          var default_text = currText;
          if(editor && default_text){
            editor.html(default_text)
          }
          if(default_text === ''){
            editor.html(defaultText);
            $(".ke-edit-iframe").contents().find(".ke-content").css("color","#777");
          }
        },1000)
      },
      afterChange:function () {
        if(editor){
          this.sync();
          currText = $.trim(editor.html());
          //$("#<?=$edit_id?>", window.parent.document).val = currText;
          //$("#<?=$edit_id?>", window.parent.document).css({"height":"333px;"});
          window.parent.document.getElementById('<?=$edit_id?>').value = currText;
        }
      }
    });
  });
</script>
</body>
</html>