{include file="mifenlei/admin/view/header.html"}
  <link rel="stylesheet" type="text/css" href="/mifenlei/file/public/css/reset.css"/>
  <link rel="stylesheet" href="/mifenlei/file/public/codemirror/lib/codemirror.css">
  <link rel="stylesheet" href="/mifenlei/file/public/codemirror/theme/monokai.css">
  <link rel="stylesheet" href="/mifenlei/file/public/codemirror/theme/cobalt.css">
  <script src="/mifenlei/file/public/codemirror/lib/codemirror.js"></script>
  <script src="/mifenlei/file/public/codemirror/addon/edit/closetag.js"></script>
  <script src="/mifenlei/file/public/codemirror/mode/xml/xml.js"></script>
  <script src="/mifenlei/file/public/codemirror/mode/javascript/javascript.js"></script>
  <script src="/mifenlei/file/public/codemirror/mode/css/css.js"></script>
  <script src="/mifenlei/file/public/codemirror/mode/htmlmixed/htmlmixed.js"></script>
  <script src="/mifenlei/file/public/codemirror/mode/php/php.js"></script>
  <script src="/mifenlei/file/public/codemirror/mode/clike/clike.js"></script>
  <script src="/mifenlei/file/public/js/jquery.min.js"></script>
  <script src="/mifenlei/file/public/js/pageEvent2.js"></script>
  <style>
  button{background: linear-gradient(to left, #96b97d, #4CAF50);line-height: 30px;z-index: 999;width: 100px;height: 30px;margin: 5px;font-family: 'Krona One',sans-serif;font-size: 16px;color: rgba(255,255,255,0.9);text-shadow: 1px 1px 2px rgba(0,0,0,0.5);cursor: pointer;border: none;border-radius: 2px;transition: 300ms;}
  #xiugaiadmin{background: #a2a1a1;position: fixed;top: 0;right: 0px;}
  </style> 
  <button class="button" id="xiugaiadmin">保存修改</button>
  <xmp id="gethtmladmin" style="display:none;"><?php
		$filename = $id;
		if(!filesize ($filename)==0){
		    $handle = fopen($filename, "r"); 
		    $contents = fread($handle, filesize ($filename));
		    echo  $contents;
		    fclose($handle);
	    }
	?>
  </xmp>
  
<script>
function decodeEntities(encodedString) {
    var textArea = document.createElement('textarea');
    textArea.innerHTML = encodedString;
    return textArea.value;
}
var gethtmladmin = decodeEntities($("#gethtmladmin").html());
var myTextArea = CodeMirror(document.body, {
	lineNumbers: true,
	mode: "application/x-httpd-php",
// 	theme: 'monokai',
	lineWrapping: true,
	indentUnit: 2,
	firstLineNumber: 1,
	styleActiveLine: true,
	matchBrackets: true,
	autofocus: true,
	tabSize : 4,  // Tab缩进，默认4
	value: gethtmladmin,
	autoCloseTags: true,
	readOnly : false,  // 是否只读，默认false
	lineNumbers : true  // 是否显示行号
	});
var getValue = myTextArea.getValue();//获取编辑器内容 
$(document).ready(function(){
  $("#xiugaiadmin").click(function(){
  	$.ajax({
  		url: '{:url('file/index/updata')}',
  		type: "POST",
  		dataType: "json",
  		data: {"id": "<?php echo $id;?>","content": ""+myTextArea.getValue()+"" },
  		success: function(data) {
  			if(data.code==1){
  				layer.msg(data.msg, {icon: 1, anim: 2, time: 1000});
  			} else {
  				layer.msg(data.msg, {icon: 2, anim: 2, time: 1000});
  			}
  		},
  		error : function() {
  			layer.msg('异常', {icon: 2, anim: 2, time: 1000});
  		}
  	});
  });
});
document.addEventListener('keydown', function(e) {
  if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey))      {
        e.preventDefault();
		$.ajax({
	  		url: '{:url('file/index/updata')}',
	  		type: "POST",
	  		dataType: "json",
	  		data: {"id": "<?php echo $id;?>","content": ""+myTextArea.getValue()+"" },
	  		success: function(data) {
	  			if(data.code==1){
	  				layer.msg(data.msg, {icon: 1, anim: 2, time: 1000});
	  			} else {
	  				layer.msg(data.msg, {icon: 2, anim: 2, time: 1000});
	  			}
	  		},
	  		error : function() {
	  			layer.msg('异常', {icon: 2, anim: 2, time: 1000});
	  		}
	  	});
      }
});
</script>
{include file="mifenlei/admin/view/footer.html"}