1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-17 22:47:59 +00:00
seahub/templates/snippets/file_content_js.html

212 lines
8.3 KiB
HTML

{% load i18n %}
{% if not err %}
{% if filetype == 'Text' %}
{% ifnotequal file_content None %}
var editor = CodeMirror.fromTextArea($('#docu-view')[0], {
{% include 'snippets/editor_set_mode.html' %}
theme: 'default',
indentUnit: 4,
{% if fileext != 'txt' and fileext != 'text' %}
lineNumbers: true,
{% endif %}
lineWrapping: true,
readOnly: true
});
{% endifnotequal %}
{% endif %}
{% if filetype == 'Image' %}
window.onload = function () {
var img = $('#image-view');
var img_h = img.outerHeight();
var file_view_h = parseInt($('#file-view').css('min-height'));
{% if img_prev or img_next %}
var prev_next_h = $('#img-prev-next').outerHeight(true);
{% else %}
var prev_next_h = 0;
{% endif %}
if (img_h < file_view_h - prev_next_h) {
img.css({'margin-top':(file_view_h - img_h - prev_next_h)/2});
}
if (img.width() > 946) {
img.width(946);
}
img.removeClass('vh');
}
{% endif %}
{% if filetype == 'SVG' %}
if (!$.browser.mozilla && !$.browser.safari && !($.browser.msie && parseInt($.browser.version) > 8)) {
$('#file-view').html('<div id="file-view-tip"><p>{% trans "To view it online, you can use firefox, chrome or IE 9." %}</p></div>');
} else {
$('#file-view').html('<iframe src="{{ raw_path }}" frameborder="0" id="svg-view"></iframe>');
}
{% endif %}
{% if filetype == 'Markdown' %}
{% ifnotequal file_content None %}
var converter = new Showdown.converter();
$('#md-view').html(converter.makeHtml('{{ file_content|escapejs }}')).children(':first').css('margin-top', '0');
{% endifnotequal %}
{% endif %}
{% if filetype == 'Document' or filetype == 'PDF' and not use_pdfjs %}
$('#file-view').html('<div id="flash"></div>');
function load_flexpaper() {
var swf_url = '{{ DOCUMENT_CONVERTOR_ROOT }}swf/{{ obj_id }}';
var fp = new FlexPaperViewer(
'{{MEDIA_URL}}flexpaper/FlexPaperViewer',
'flash', { config : {
SwfFile : escape(swf_url),
Scale : 1.0,
ZoomTransition : 'easeOut',
ZoomTime : 0.5,
ZoomInterval : 0.2,
FitPageOnLoad : false,
FitWidthOnLoad : true,
FullScreenAsMaxWindow : false,
ProgressiveLoading : false,
MinZoomSize : 0.2,
MaxZoomSize : 5,
SearchMatchAll : false,
InitViewMode : 'Portrait',
PrintPaperAsBitmap : false,
ViewModeToolsVisible : true,
ZoomToolsVisible : true,
NavToolsVisible : true,
CursorToolsVisible : true,
SearchToolsVisible : true,
localeChain: 'en_US'
}});
}
{% if swf_exists %}
load_flexpaper();
{% else %}
function check_status () {
$.ajax({
url: '{{ DOCUMENT_CONVERTOR_ROOT }}status?file_id={{ obj_id }}',
cache: false,
dataType: 'jsonp',
jsonpCallback: 'xx',
crossDomain: true,
success: function(data) {
var status = data['status'];
if (status == 'QUEUED' || status == 'PROCESSING') {
setTimeout(check_status, 2000);
} else {
load_flexpaper();
}
},
error: function(xhr, textStatus, errorThrown) {
var str;
if (xhr.responseText) {
str = '{% trans "Document convertion failed." %}';
} else {
str = '{% trans "Failed. Please check the network." %}';
}
$('#file-view').html('<div id="file-view-tip"><p class="error">' + str + '</p></div>');
}
});
}
check_status();
{% endif %}
{% endif %}
{% if filetype == 'PDF' and use_pdfjs %}
if (!($.browser.msie && parseInt($.browser.version) < 10)) {
PDFJS.workerSrc = '{{MEDIA_URL}}js/pdf.js';
$('#file-view').html('<div id="pdf"><div id="pdf-op-bar" class="vh"><span id="pdf-page-left"><button id="prev">{% trans "Previous" %}</button></span>{% blocktrans %}<span id="pdf-page"><label for="page-number">Page</label> <input type="number" id="page-number" value="1" min="1"></input> / <span id="page-nums"></span></span>{% endblocktrans %}<span id="pdf-page-right"><button id="next" style="margin-right:15px;">{% trans "Next" %}</button><button id="full-screen">{% trans "Full Screen" %}</button></span></div><img src="{{ MEDIA_URL }}pdf_full_view/images/loading-icon.gif" alt="{% trans "loading..." %}" id="pdf-loading" style="margin:20px 0;" /><canvas data="{{ raw_path }}" id="pdf-view" class="hide"></canvas></div>').css({'text-align':'center'});
$('#pdf-page-left, #pdf-page-right').css('display', 'inline-block');
$('#pdf-page-left').css({'text-align':'right', 'width': $('#pdf-page-right').width()});
$('#pdf-op-bar').removeClass('vh');
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-view').removeClass('hide');
$('#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 }}'));
});
});
} else {
$('#file-view').html('<div id="file-view-tip"><p>{% trans "You can use IE 10 or other browsers, for example, firefox, to view it online." %}</p></div>');
}
{% endif %}
{% if filetype == 'Video' %}
$('#file-view').html('<div class="video-container"><video src="{{raw_path}}" width="800" height="400"></video></div>');
$('video').mediaelementplayer(/* Options */);
{% endif %}
{% if filetype == 'Audio' %}
$('#file-view').html('<div class="audio-container"><audio src="{{raw_path}}" width="500" height="30"></audio></div>');
$('audio').mediaelementplayer(/* Options */);
{% endif %}
{% if filetype == 'Unknown' %}
$('#file-view').html('<div id="file-view-tip"><p>{% trans "This type of file cannot be viewed online." %}</p></div>');
{% endif %}
{% endif %}{# 'if not err' ends here. #}
{% if filetype == 'Text' or filetype == 'Sf' or filetype == 'Markdown' %}
$('#file-enc').change(function() {
var file_enc = $(this).val();
var s = location.search;
if (s.indexOf('?') == -1) {
location.search = '?file_enc=' + file_enc;
} else {
if (s.indexOf('file_enc') == -1) {
location.search += '&file_enc=' + file_enc;
} else {
var params = s.substr(1).split('&');
var param;
for (var i = 0, len = params.length; i < len; i++) {
param = params[i].split('=');
if (param[0] == 'file_enc') {
param[1] = file_enc;
params[i] = param.join('=');
break;
}
}
location.search = '?' + params.join('&');
}
}
})
{% endif %}