{% if filetype == 'Text' %} $.ajax({ url: url, dataType: 'json', cache: false, success: function(data) { if (data.length > 0) { $('#file-view').html('
' + data[0]['content'] + ''); $('#docu-view').css({'position': 'relative', 'width': $('#docu-view').width(), 'height': $('#docu-view').height()}).html($('#docu-view').html()); var editor = ace.edit("docu-view"); $('#docu-view').removeClass('vh'); editor.setReadOnly(true); editor.setHighlightActiveLine(false); editor.setShowPrintMargin(false);//rm the vertical line in the center $('#docu-view .ace_cursor-layer').hide();//rm cursor $('#docu-view .ace_sb').hide();//rm right scrollbar editor.setTheme("ace/theme/chrome"); {% if fileext = 'html' or fileext == 'xhtml' or fileext == 'htm' %} editor.session.setMode('ace/mode/html'); {% endif %} {% if fileext = 'css' %} editor.session.setMode('ace/mode/css'); {% endif %} {% if fileext = 'java' %} editor.session.setMode('ace/mode/java'); {% endif %} {% if fileext = 'js' %} editor.session.setMode('ace/mode/javascript'); {% endif %} {% if fileext = 'c' or fileext == 'cpp' or fileext == 'cc' %} editor.session.setMode('ace/mode/c_cpp'); {% endif %} {% if fileext = 'tex' %} editor.session.setMode('ace/mode/latex'); {% endif %} {% if fileext = 'pl' %} editor.session.setMode('ace/mode/perl'); {% endif %} {% if fileext = 'php' %} editor.session.setMode('ace/mode/php'); {% endif %} {% if fileext = 'py' %} editor.session.setMode('ace/mode/python'); {% endif %} {% if fileext = 'rb' %} editor.session.setMode('ace/mode/ruby'); {% endif %} {% if fileext = 'sh' %} editor.session.setMode('ace/mode/sh'); {% endif %} {% if fileext = 'xml' %} editor.session.setMode('ace/mode/xml'); {% endif %} } }, error: function(xhr, ajaxOptions, thrownError) { var jsonVal = jQuery.parseJSON(xhr.responseText); $('#file-view').html('
' + jsonVal[0]['error'] + '
'); } }); {% endif %} {% if filetype == 'Image' %} $('#file-view').html('' + jsonVal[0]['error'] + '
'); } }); } function check_status () { $.ajax({ url: '{{ SITE_ROOT }}crocodoc/status/?uuids='+ uuid + '&obj_id=' + obj_id, cache: false, contentType: 'application/json; charset=utf-8', success: function(data) { if (data.length > 0) { var status = data[0]['status']; if (status == 'QUEUED') { $('#file-view').html('' + '文档转换任务正在排队,请稍后...' + '
'); setTimeout(check_status, 1000); } else if (status == 'PROCESSING') { $('#file-view').html('' + '文档正在转换,请稍候...' + '
'); setTimeout(check_status, 1000); } else { $('#file-view').html('' + '文档转换成功。正在打开...' + '
'); create_session(); } } }, error: function(xhr, ajaxOptions, thrownError) { var jsonVal = jQuery.parseJSON(xhr.responseText); $('#file-view').html('' + jsonVal[0]['error'] + '
'); } }); } $.ajax({ url: '{{ SITE_ROOT }}crocodoc/upload/?raw_path={{ raw_path|urlencode }}', cache: false, contentType: 'application/json; charset=utf-8', success: function(data) { if (data.length > 0) { uuid = data[0]['uuid']; obj_id = data[0]['obj_id']; $('#file-view').html('文档内容读取成功,开始转换...
'); check_status(); } }, error: function(xhr, ajaxOptions, thrownError) { var jsonVal = jQuery.parseJSON(xhr.responseText); $('#file-view').html('' + jsonVal[0]['error'] + '
'); } }); {% endif %} {% if filetype == 'PDF' %} PDFJS.workerSrc = '{{MEDIA_URL}}js/pdf.js'; $('#file-view').html('该类型文件无法在线查看。下载
'); {% endif %}