1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-04 02:36:59 +00:00
seahub/templates/snippets/repo_file_get.html

182 lines
8.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{% if filetype == 'Text' %}
{% ifnotequal file_content None %}
$('#file-view').html('<div id="docu-view" class="vh">' + '</div>');
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('{{ file_content|escapejs }}');
$('#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
{% endifnotequal %}
{% if err %}
$('#file-view').html('<p class="error">{{ err }}</p>').addClass('file-view-tip');
{% endif %}
{% endif %}
{% if filetype == 'Image' %}
$('#file-view').html('<img src="{{ raw_path }}" alt="{{ u_filename}}" id="image-view" />').css({'text-align':'center', 'padding':'30px 0'});
window.onload = function() {
if ($('#image-view').width() > $('#file-view').width()) {
$('#image-view').css('width', $('#file-view').width() - 4);
}
}
{% endif %}
{% if filetype == 'SVG' %}
if (!$.browser.mozilla && !$.browser.safari && !($.browser.msie && parseInt($.browser.version) > 8)) {
$('#file-view').html('<p>在线查看请使用firefox, chrome 或 IE 9。</p>').addClass('file-view-tip');
} else {
$('#file-view').html('<div><iframe src="{{ raw_path }}" frameborder="0" id="svg-view"></iframe></div>');
}
{% 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('<div><iframe src="' + data[0]['doc_src'] + '" frameborder="0" id="doc-view"></iframe></div>').attr('class', '');
}
},
error: function(xhr, ajaxOptions, thrownError) {
var jsonVal = jQuery.parseJSON(xhr.responseText);
$('#file-view').html('<p class="error">' + jsonVal[0]['error'] + '</p>');
}
});
}
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('<p class="msg">' + '文档转换任务正在排队,请稍后...' + '</p>');
setTimeout(check_status, 1000);
} else if (status == 'PROCESSING') {
$('#file-view').html('<p class="msg">' + '文档正在转换,请稍候...' + '</p>');
setTimeout(check_status, 1000);
} else {
$('#file-view').html('<p class="msg">' + '文档转换成功。正在打开...' + '</p>');
create_session();
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
var jsonVal = jQuery.parseJSON(xhr.responseText);
$('#file-view').html('<p class="error">' + jsonVal[0]['error'] + '</p>');
}
});
}
if (!$.browser.mozilla && !$.browser.safari) {
$('#file-view').html('<p>在线查看请使用firefox 或 chrome。</p>').addClass('file-view-tip');
} 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('<p class="msg">文档内容读取成功,开始转换...</p>').addClass('file-view-tip');
check_status();
}
},
error: function(xhr, ajaxOptions, thrownError) {
var jsonVal = jQuery.parseJSON(xhr.responseText);
$('#file-view').html('<p class="error">' + jsonVal[0]['error'] + '</p>').addClass('file-view-tip');
}
});
}
{% endif %}
{% if filetype == 'PDF' %}
if (!$.browser.mozilla && !$.browser.safari) {
$('#file-view').html('<p>在线查看请使用firefox 或 chrome。</p>').addClass('file-view-tip');
} else {
PDFJS.workerSrc = '{{MEDIA_URL}}js/pdf.js';
$('#file-view').html('<div id="pdf"><img src="{{ MEDIA_URL }}pdf_full_view/images/loading-icon.gif" alt="加载中..." id="pdf-loading" style="margin-top:20px;" /><div id="pdf-op-bar" class="vh"><button id="prev">上一页</button><button id="next">下一页</button><span id="pdf-page"><label for="page-number"></label> <input type="number" id="page-number" value="1" min="1"></input> / <span id="page-nums"></span></span><button id="full-screen">全屏</button></div><canvas data="{{ raw_path }}" id="pdf-view" class="vh"></canvas></div>').css({'text-align':'center'});
$('#pdf-op-bar').append($('#file-op').html());
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);
$('#file-op, #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' %}
{% ifnotequal file_content None %}
var converter = new Showdown.converter();
$('#file-view').html('<div id="md-view" class="article">' + converter.makeHtml('{{ file_content|escapejs }}') + '</div>');
$('#md-view').children(':first').css('margin-top', '0');
{% endifnotequal %}
{% if err %}
$('#file-view').html('<p class="error">{{ err }}</p>').addClass('file-view-tip');
{% endif %}
{% endif %}
{% if filetype == 'Unknown' %}
$('#file-view').html('<p>该类型文件无法在线查看。</p>').addClass('file-view-tip');
{% endif %}