mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 07:01:12 +00:00
[file_rewrite] extracted file_content files, cleaned up code & rm unused files of pdf view
This commit is contained in:
25
templates/snippets/file_content_html.html
Normal file
25
templates/snippets/file_content_html.html
Normal file
@@ -0,0 +1,25 @@
|
||||
{%comment%}
|
||||
content of files that can be viewed online shows here.
|
||||
For details please refer to 'snippets/file_content_js.html'.
|
||||
{%endcomment%}
|
||||
<div id="file-view">
|
||||
{% if not err %}
|
||||
{% if filetype == 'Text' or filetype == 'Sf' %}
|
||||
{% ifnotequal file_content None %}
|
||||
{% if filetype == 'Text' %}
|
||||
<textarea id="docu-view" class="vh">{{ file_content|escape }}</textarea>
|
||||
{% else %}
|
||||
<div id="sf" class="article">{{ file_content|safe }}</div>
|
||||
{% endif %}
|
||||
{% endifnotequal %}
|
||||
{% endif %}
|
||||
|
||||
{% if filetype == 'Image' %}
|
||||
<img src="{{ raw_path }}" alt="{{ u_filename}}" id="image-view" />
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div id="file-view-tip">
|
||||
<p class="error">{{ err }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
111
templates/snippets/file_content_js.html
Normal file
111
templates/snippets/file_content_js.html
Normal file
@@ -0,0 +1,111 @@
|
||||
{% 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() {
|
||||
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('<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();
|
||||
$('#file-view').html('<div id="md-view" class="article">' + converter.makeHtml('{{ file_content|escapejs }}') + '</div>');
|
||||
$('#md-view').children(':first').css('margin-top', '0');
|
||||
{% endifnotequal %}
|
||||
{% endif %}
|
||||
|
||||
{% if filetype == 'Document' or filetype == 'PDF' %}
|
||||
$('#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) {
|
||||
if (data['error']) {
|
||||
$('#file-view').html('<div id="file-view-tip"><p class="error">' + data['error'] + '</p></div>');
|
||||
} else {
|
||||
var status = data['status'];
|
||||
if (status == 'QUEUED' || status == 'PROCESSING') {
|
||||
setTimeout(check_status, 2000);
|
||||
} else {
|
||||
load_flexpaper();
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function(xhr, ajaxOptions, thrownError) {
|
||||
var jsonVal = jQuery.parseJSON(xhr.responseText);
|
||||
$('#file-view').html('<div id="file-view-tip"><p class="error">' + jsonVal['error'] + '</p></div>');
|
||||
}
|
||||
});
|
||||
}
|
||||
check_status();
|
||||
{% endif %}
|
||||
{% 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 %}
|
@@ -1,14 +1,7 @@
|
||||
{% if filetype == 'Text' %}
|
||||
<script type="text/javascript" src="{{MEDIA_URL}}codemirror/codemirror-2.36.js"></script>
|
||||
{% endif %}
|
||||
{% if filetype == 'PDF' %}
|
||||
{% if pdf_use_flash %}
|
||||
<script type="text/javascript" src="{{MEDIA_URL}}flexpaper/js/flexpaper_flash.js"></script>
|
||||
{% else %}
|
||||
<script type="text/javascript" src="{{MEDIA_URL}}js/pdf.js"></script>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if filetype == 'Document' %}
|
||||
{% if filetype == 'Document' or filetype == 'PDF' %}
|
||||
<script type="text/javascript" src="{{MEDIA_URL}}flexpaper/js/flexpaper_flash.js"></script>
|
||||
{% endif %}
|
||||
{% if filetype == 'Markdown' %}
|
||||
|
@@ -8,11 +8,14 @@
|
||||
<style type="text/css">
|
||||
.CodeMirror-scroll { min-height:400px; }
|
||||
.CodeMirror { margin-bottom:40px; }
|
||||
{% if fileext == 'txt' or fileext == 'text' %}
|
||||
.CodeMirror {
|
||||
width:624px;
|
||||
padding:40px 96px;
|
||||
}
|
||||
{% if fileext == 'txt' or fileext == 'text' %}
|
||||
.CodeMirror { width:624px; padding:40px 96px; }
|
||||
{% endif %}
|
||||
</style>
|
||||
{% endif %}
|
||||
|
||||
{% if filetype == 'Image' %}
|
||||
<style type="text/css">
|
||||
#file-view { text-align:center; padding:30px 0; }
|
||||
</style>
|
||||
{% endif %}
|
||||
</style>
|
||||
{% endif %}
|
||||
|
@@ -1,177 +0,0 @@
|
||||
{% load i18n %}
|
||||
{% 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 %}
|
||||
|
||||
{% if err %}
|
||||
$('#file-view').html('<div id="file-view-tip"><p class="error">{{ err }}</p></div>');
|
||||
{% 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>{% trans "To view it online, you can use firefox, chrome or 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 == 'PDF' and not pdf_use_flash %}
|
||||
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 }}'));
|
||||
});
|
||||
});
|
||||
{% 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('<div id="file-view-tip"><p class="error">{{ err }}</p></div>');
|
||||
{% endif %}
|
||||
{% 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 %}
|
||||
|
||||
{% if filetype == 'Document' or filetype == 'PDF' and pdf_use_flash %}
|
||||
{% if err %}
|
||||
$('#file-view').html('<div id="file-view-tip"><p class="error">{{ err }}</p></div>');
|
||||
{% else %}
|
||||
$('#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 () {
|
||||
url = '{{ DOCUMENT_CONVERTOR_ROOT }}status';
|
||||
url += '?file_id={{ obj_id }}';
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
cache: false,
|
||||
dataType: 'jsonp',
|
||||
jsonpCallback: 'xx',
|
||||
crossDomain: true,
|
||||
success: function(data) {
|
||||
if (data['error']) {
|
||||
$('#file-view').html('<div id="file-view-tip"><p class="error">' + data['error'] + '</p></div>');
|
||||
} else {
|
||||
var status = data['status'];
|
||||
if (status == 'QUEUED' || status == 'PROCESSING') {
|
||||
setTimeout(check_status, 2000);
|
||||
} else {
|
||||
load_flexpaper();
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function(xhr, ajaxOptions, thrownError) {
|
||||
var jsonVal = jQuery.parseJSON(xhr.responseText);
|
||||
$('#file-view').html('<div id="file-view-tip"><p class="error">' + jsonVal['error'] + '</p></div>');
|
||||
}
|
||||
});
|
||||
}
|
||||
check_status();
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
Reference in New Issue
Block a user