From 8d3f88cf16f86212861db996023dadf1fb3e310f Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Thu, 16 Apr 2015 15:28:04 +0200 Subject: [PATCH] Show a text preview instead of a bitmap preview of text + fix the preview height --- apps/files_sharing/css/public.css | 17 ++++++++++++++++- apps/files_sharing/js/public.js | 31 ++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css index ef013ca07d7..b3d2aae3fd9 100644 --- a/apps/files_sharing/css/public.css +++ b/apps/files_sharing/css/public.css @@ -2,7 +2,6 @@ background: #fff; text-align: center; margin: 45px auto 0; - min-height: 600px; } #preview .notCreatable { @@ -28,6 +27,22 @@ max-width:100%; } +#imgframe .text-preview { + display: inline-block; + text-align: left; + white-space: pre-wrap; + overflow-y: auto; + height: auto; + min-height: 200px; + max-height: 800px; + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + /* fix multiselect bar offset on shared page */ thead { left: 0 !important; diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 41bfeba031f..59ef971ae67 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -87,9 +87,13 @@ OCA.Sharing.PublicApp = { // dynamically load image previews + var bottomMargin = 350; + var previewWidth = $(window).width() * window.devicePixelRatio; + var previewHeight = $(window).height() - bottomMargin * window.devicePixelRatio; + previewHeight = Math.max(200, previewHeight); var params = { - x: $(document).width() * window.devicePixelRatio, - y: $(document).height() * window.devicePixelRatio, + x: previewWidth, + y: previewHeight, a: 'true', file: encodeURIComponent(this.initialDir + $('#filename').val()), t: $('#sharingToken').val(), @@ -105,6 +109,23 @@ OCA.Sharing.PublicApp = { (maxGifSize === -1 || fileSize <= (maxGifSize * 1024 * 1024))) { img.attr('src', $('#downloadURL').val()); img.appendTo('#imgframe'); + } else if (mimetype.substr(0, mimetype.indexOf('/')) === 'text') { + $.ajax({ + url: $('#downloadURL').val(), + headers: {Range: "bytes=0-1000"} + }).then(function (data) { + var textDiv = $('').addClass('text-preview'); + textDiv.text(data); + textDiv.appendTo('#imgframe'); + var divHeight = textDiv.height(); + if (data.length > 999) { + textDiv.append('

(...)'); + divHeight += 50; + } + if (divHeight > previewHeight) { + textDiv.height(previewHeight); + } + }); } else if (previewSupported === 'true' || mimetype.substr(0, mimetype.indexOf('/')) === 'image' && mimetype !== 'image/svg+xml') { @@ -128,7 +149,7 @@ OCA.Sharing.PublicApp = { path: path, files: filename }; - return OC.generateUrl('/s/'+token+'/download') + '?' + OC.buildQueryString(params); + return OC.generateUrl('/s/' + token + '/download') + '?' + OC.buildQueryString(params); }; this.fileList.getAjaxUrl = function (action, params) { @@ -142,7 +163,7 @@ OCA.Sharing.PublicApp = { var params = { dir: dir }; - return OC.generateUrl('/s/'+token+'') + '?' + OC.buildQueryString(params); + return OC.generateUrl('/s/' + token + '') + '?' + OC.buildQueryString(params); }; this.fileList.generatePreviewUrl = function (urlSpec) { @@ -225,7 +246,7 @@ OCA.Sharing.PublicApp = { this.fileList.changeDirectory(params.path || params.dir, false, true); }, - _saveToOwnCloud: function(remote, token, owner, name, isProtected) { + _saveToOwnCloud: function (remote, token, owner, name, isProtected) { var location = window.location.protocol + '//' + window.location.host + OC.webroot; var url = remote + '/index.php/apps/files#' + 'remote=' + encodeURIComponent(location) // our location is the remote for the other server -- 2.39.5