Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoint for public editor previews #71

Merged
merged 10 commits into from
Apr 16, 2018
5 changes: 5 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
'name' => 'FileHandling#save',
'url' => '/ajax/savefile',
'verb' => 'PUT'
],
[
'name' => 'PublicFileHandling#load',
'url' => '/public/{token}',
'verb' => 'GET'
]
]
];
87 changes: 0 additions & 87 deletions css/public-share.css

This file was deleted.

87 changes: 87 additions & 0 deletions css/public-share.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
.preview.formatted-text {
max-width: 810px;
padding: 0px 20px !important;
box-sizing: border-box;
font-size: 18px;
line-height: 1.6em;
min-height: 440px;
color: #333;
text-align: left;
margin-bottom: 170px !important;

h1,
h2,
h3 {
margin-top: 1em;
word-wrap: break-word;
}

h1 {
line-height: 1.1em;
margin-bottom: 1em;
text-align: center;
font-size: 3em;
}

h2 {
line-height: 1.1em;
margin-bottom: .5em;
font-size: 2em;
}

h3 {
line-height: 1.1em;
margin-bottom: .6em;
font-size: 1.4em;
}

p,
ul,
ol,
pre {
line-height: 1.45em;
}
p,
pre {
margin-bottom: 17.6px;
}
ul,
ol {
padding-left: 25px;
}

ul {
list-style-type: disc;
}

ul ul {
list-style-type: circle;
}

a {
color: #448ac9;
text-decoration: none;
}
a:hover,
a:focus,
a:active {
text-decoration: underline;
}

em {
opacity: 1;
font-style: italic;
}

code {
background-color: rgb(242, 242, 242);
border-radius: 3px;
padding: 0px 2px 2px 2px;
}
}

/* hide image preview during loading or if it renders fine */
.icon-loading .text-preview,
.preview .text-preview:not(.default-overridden) {
display: none !important;
}
53 changes: 48 additions & 5 deletions js/public-share.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// FIXME: Hack for single public file view since it is not attached to the fileslist
$(document).ready(function(){
if ($('#isPublic').val() &&
$('#mimetype').val() === 'text/markdown' &&
$('#filesize').val() < 524288) {
var isPublic = $('#isPublic').val();
var mimetype = $('#mimetype').val();
var filesize = $('#filesize').val();

if (isPublic &&
mimetype === 'text/markdown' &&
filesize < 524288) {

var sharingToken = $('#sharingToken').val();
var downloadUrl = OC.generateUrl('/s/{token}/download', {token: sharingToken});
Expand Down Expand Up @@ -40,12 +44,12 @@ $(document).ready(function(){

previewElement
.addClass('icon-loading')
.children().detach();
.children().remove();

$.get(downloadUrl).success(function(content) {
previewElement
.removeClass('icon-loading')
.addClass('preview')
.addClass('preview formatted-text')
.html(DOMPurify.sanitize(
marked(content, {
renderer: renderer,
Expand All @@ -64,5 +68,44 @@ $(document).ready(function(){
previewElement
.removeClass('icon-loading');
});
} else if (isPublic &&
mimetype.substr(0, mimetype.indexOf('/')) === 'text') {
// Based on default text previews from "files_sharing/js/public.js", but
// using the public endpoint from files_texteditor for better character
// encoding support.
var previewElement = $('#imgframe');
previewElement
.addClass('icon-loading')
.children().remove();

var bottomMargin = 350;
var previewHeight = $(window).height() - bottomMargin;
previewHeight = Math.max(200, previewHeight);

var sharingToken = $('#sharingToken').val();
$.ajax({
url: OC.generateUrl('/apps/files_texteditor/public/{token}', { token: sharingToken }),
headers: {
'Range': 'bytes=0-524288'
}
}).success(function(content) {
var textDiv = $('<div/>').addClass('text-preview default-overridden');
textDiv.text(content);

previewElement
.removeClass('icon-loading')
.addClass('preview')
.append(textDiv);

var divHeight = textDiv.height();
if (content.length > 50000) {
var ellipsis = $('<div/>').addClass('ellipsis');
ellipsis.html('(&#133;)');
ellipsis.appendTo('#imgframe');
}
if (divHeight > previewHeight) {
textDiv.height(previewHeight);
}
});
}
});
Loading