]> source.dussan.org Git - nextcloud-server.git/commitdiff
Show a text preview instead of a bitmap preview of text
authorOlivier Paroz <github@oparoz.com>
Thu, 16 Apr 2015 13:28:04 +0000 (15:28 +0200)
committerOlivier Paroz <github@oparoz.com>
Thu, 23 Apr 2015 16:19:07 +0000 (18:19 +0200)
+ fix the preview height

apps/files_sharing/css/public.css
apps/files_sharing/js/public.js

index ef013ca07d7a5606d6473112ed08728dc6d1523b..b3d2aae3fd97602641bf6a0370daff914ddd2932 100644 (file)
@@ -2,7 +2,6 @@
        background: #fff;
        text-align: center;
        margin: 45px auto 0;
-       min-height: 600px;
 }
 
 #preview .notCreatable {
        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;
index 41bfeba031fafc5b9cf0d384a42681d054254880..59ef971ae679f6a959675c9fea180f5af812b9a9 100644 (file)
@@ -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 = $('<span/>').addClass('text-preview');
+                               textDiv.text(data);
+                               textDiv.appendTo('#imgframe');
+                               var divHeight = textDiv.height();
+                               if (data.length > 999) {
+                                       textDiv.append('</br></br><strong>(...)</strong>');
+                                       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