{% if filetype == 'Text' %} $.ajax({ url: url, dataType: 'json', cache: false, success: function(data) { $('#file-view').html('
' + '
'); var editor = ace.edit("docu-view"); $('#docu-view').removeClass('vh'); editor.setReadOnly(true); editor.setHighlightActiveLine(false); $('#docu-view .ace_cursor-layer').hide(); // rm cursor editor.setShowPrintMargin(false); // rm the vertical line in the center editor.renderer.scrollBar.element.style.display = "none"; // hide right scrollbar editor.renderer.scrollBar.width = 0; // enlarge ace_content width editor.setTheme("ace/theme/chrome"); {% include "snippets/editor_set_mode.html" %} editor.session.getDocument().setValue(data['content']); $('#docu-view').css({'position': 'relative', 'height': (editor.session.getScreenLength() + 1) * parseInt($('#docu-view').css('line-height'))}); // '+ 1': offer space for bottom scrollbar editor.session.setScrollLeft(0); // make bottom scrollbar start from the left-most editor.resize(); // fix some problem for showing some file in ie8 }, error: function(xhr, ajaxOptions, thrownError) { var jsonVal = jQuery.parseJSON(xhr.responseText); $('#file-view').html('

' + jsonVal['error'] + '

'); } }); {% endif %} {% if filetype == 'Image' %} $('#file-view').html('{{ u_filename}}').css({'text-align':'center', 'padding':'30px 0'}); {% endif %} {% if filetype == 'SVG' %} if (!$.browser.mozilla && !$.browser.safari && !($.browser.msie && parseInt($.browser.version) > 8)) { $('#file-view').html('

在线查看:请使用firefox, chrome 或 IE 9。

'); } else { $('#file-view').html('
'); } {% endif %} {% if filetype == 'Document' %} var uuid = '', obj_id = ''; function create_session() { $.ajax({ url: '{{ SITE_ROOT }}crocodoc/session/?uuid=' + uuid, cache: false, contentType: 'application/json; charset=utf-8', success: function(data) { if (data.length > 0) { $('#file-view').html('
'); } }, error: function(xhr, ajaxOptions, thrownError) { var jsonVal = jQuery.parseJSON(xhr.responseText); $('#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'] + '

'); } }); } if (!$.browser.mozilla && !$.browser.safari) { $('#file-view').html('

在线查看:请使用firefox 或 chrome。

'); } else { $.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' %} if (!$.browser.mozilla && !$.browser.safari) { $('#file-view').html('

在线查看:请使用firefox 或 chrome。

'); } else { PDFJS.workerSrc = '{{MEDIA_URL}}js/pdf.js'; $('#file-view').html('
加载中...
/
').css({'text-align':'center'}); var seahub_getPage = function (pdf, page_number) { pdf.getPage(page_number).then(function(page) { var scale = 1.5; var viewport = page.getViewport(scale); var canvas = $('#pdf-view')[0]; var context = canvas.getContext('2d'); canvas.height = viewport.height; canvas.width = viewport.width; var renderContext = { canvasContext: context, viewport: viewport }; page.render(renderContext); }); }; PDFJS.getDocument($('#pdf-view').attr('data')).then(function(pdf) { $('#page-nums').html(pdf.numPages); $('#page-number').attr('max', pdf.numPages).css('width', String(pdf.numPages).length * 6 + 10); seahub_getPage(pdf, 1); $('#pdf-loading').addClass('hide'); $('#pdf-op-bar, #pdf-view').removeClass('vh'); $('#page-number').change(function() { seahub_getPage(pdf, $(this).val()); }); $('#prev').click(function() { var current = $('#page-number').val(); if (current > 1) { seahub_getPage(pdf, --current); $('#page-number').val(current); } }); $('#next').click(function() { var current = $('#page-number').val(); if (current < pdf.numPages) { seahub_getPage(pdf, ++current); $('#page-number').val(current); } }); $('#full-screen').click(function() { window.open('{{ SITE_ROOT }}pdf_full_view/?repo_id={{ repo.id }}&obj_id={{obj_id}}&file_name=' + e('{{ file_name }}')); }); }); } {% endif %} {% if filetype == 'Markdown' %} $.ajax({ url: url, dataType: 'json', cache: false, success: function(data) { var converter = new Showdown.converter(); $('#file-view').html('
' + converter.makeHtml(data['content']) + '
'); $('#md-view').children(':first').css('margin-top', '0'); } }); {% endif %} {% if filetype == 'Unknown' %} $('#file-view').html('

该类型文件无法在线查看。下载

'); {% endif %}