From 8d3f88cf16f86212861db996023dadf1fb3e310f Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Thu, 16 Apr 2015 15:28:04 +0200 Subject: Show a text preview instead of a bitmap preview of text + fix the preview height --- apps/files_sharing/js/public.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'apps/files_sharing/js/public.js') 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 -- cgit v1.2.3 From e113d67430c0433e96c0de83e989bd6284fd0d63 Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Thu, 16 Apr 2015 19:23:42 +0200 Subject: Cache the token value --- apps/files_sharing/js/public.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'apps/files_sharing/js/public.js') diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 59ef971ae67..cfb6569529f 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -87,6 +87,7 @@ OCA.Sharing.PublicApp = { // dynamically load image previews + var token = $('#sharingToken').val(); var bottomMargin = 350; var previewWidth = $(window).width() * window.devicePixelRatio; var previewHeight = $(window).height() - bottomMargin * window.devicePixelRatio; @@ -96,7 +97,7 @@ OCA.Sharing.PublicApp = { y: previewHeight, a: 'true', file: encodeURIComponent(this.initialDir + $('#filename').val()), - t: $('#sharingToken').val(), + t: token, scalingup: 0 }; @@ -144,7 +145,6 @@ OCA.Sharing.PublicApp = { filename = JSON.stringify(filename); } var path = dir || FileList.getCurrentDirectory(); - var token = $('#sharingToken').val(); var params = { path: path, files: filename @@ -154,12 +154,11 @@ OCA.Sharing.PublicApp = { this.fileList.getAjaxUrl = function (action, params) { params = params || {}; - params.t = $('#sharingToken').val(); + params.t = token; return OC.filePath('files_sharing', 'ajax', action + '.php') + '?' + OC.buildQueryString(params); }; this.fileList.linkTo = function (dir) { - var token = $('#sharingToken').val(); var params = { dir: dir }; -- cgit v1.2.3 From 530c290555cb326e6a6bda867e16931ff4ae7df5 Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Thu, 16 Apr 2015 19:46:26 +0200 Subject: Use webDAV to have access to HTTP byte ranges --- apps/files_sharing/js/public.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'apps/files_sharing/js/public.js') diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index cfb6569529f..f80d5e15de9 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -111,8 +111,11 @@ OCA.Sharing.PublicApp = { img.attr('src', $('#downloadURL').val()); img.appendTo('#imgframe'); } else if (mimetype.substr(0, mimetype.indexOf('/')) === 'text') { + // Undocumented Url to public WebDAV endpoint + var url = parent.location.protocol + '//' + + token + '@' + location.host + OC.linkTo('', 'public.php/webdav'); $.ajax({ - url: $('#downloadURL').val(), + url: url, headers: {Range: "bytes=0-1000"} }).then(function (data) { var textDiv = $('').addClass('text-preview'); -- cgit v1.2.3 From a968877a8b0454861dc27b763023ce52429a39dc Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Sat, 18 Apr 2015 22:11:36 +0200 Subject: An idea to suggest that this is just a sample of the full text --- apps/files_sharing/css/public.css | 11 +++++++++++ apps/files_sharing/js/public.js | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'apps/files_sharing/js/public.js') diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css index b3d2aae3fd9..7aa898b489d 100644 --- a/apps/files_sharing/css/public.css +++ b/apps/files_sharing/css/public.css @@ -29,6 +29,7 @@ #imgframe .text-preview { display: inline-block; + position: relative; text-align: left; white-space: pre-wrap; overflow-y: auto; @@ -41,6 +42,16 @@ -moz-user-select: none; -ms-user-select: none; user-select: none; + z-index: 1; +} + +#imgframe .watermark { + color: #E3E3E3; + font-size: 75pt; + position: absolute; + width: 80%; + top: 100px; + z-index: 0; } /* fix multiselect bar offset on shared page */ diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index f80d5e15de9..c08b7c7859c 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -118,7 +118,7 @@ OCA.Sharing.PublicApp = { url: url, headers: {Range: "bytes=0-1000"} }).then(function (data) { - var textDiv = $('').addClass('text-preview'); + var textDiv = $('
').addClass('text-preview'); textDiv.text(data); textDiv.appendTo('#imgframe'); var divHeight = textDiv.height(); @@ -129,6 +129,9 @@ OCA.Sharing.PublicApp = { if (divHeight > previewHeight) { textDiv.height(previewHeight); } + var watermark = $('
').addClass('watermark'); + watermark.text('SAMPLE'); + watermark.appendTo('#imgframe'); }); } else if (previewSupported === 'true' || mimetype.substr(0, mimetype.indexOf('/')) === 'image' && -- cgit v1.2.3 From 58a87d0babcb91aab75b45e630d2fc2fee15691e Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Mon, 20 Apr 2015 17:44:41 +0200 Subject: Use authorization headers for better compatibility + add ellipsis + fix OC.generateUrl calls --- apps/files_sharing/js/public.js | 47 ++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'apps/files_sharing/js/public.js') diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index c08b7c7859c..cf049411c9b 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -112,26 +112,15 @@ OCA.Sharing.PublicApp = { img.appendTo('#imgframe'); } else if (mimetype.substr(0, mimetype.indexOf('/')) === 'text') { // Undocumented Url to public WebDAV endpoint - var url = parent.location.protocol + '//' + - token + '@' + location.host + OC.linkTo('', 'public.php/webdav'); + var url = parent.location.protocol + '//' + location.host + OC.linkTo('', 'public.php/webdav'); $.ajax({ url: url, - 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); + headers: { + Authorization: 'Basic ' + btoa(token + ':'), + Range: 'bytes=0-1000' } - var watermark = $('
').addClass('watermark'); - watermark.text('SAMPLE'); - watermark.appendTo('#imgframe'); + }).then(function (data) { + self._showTextPreview(data, previewHeight); }); } else if (previewSupported === 'true' || mimetype.substr(0, mimetype.indexOf('/')) === 'image' && @@ -155,7 +144,7 @@ OCA.Sharing.PublicApp = { path: path, files: filename }; - return OC.generateUrl('/s/' + token + '/download') + '?' + OC.buildQueryString(params); + return OC.generateUrl('/s/' + token + '/download', params); }; this.fileList.getAjaxUrl = function (action, params) { @@ -165,10 +154,7 @@ OCA.Sharing.PublicApp = { }; this.fileList.linkTo = function (dir) { - var params = { - dir: dir - }; - return OC.generateUrl('/s/' + token + '') + '?' + OC.buildQueryString(params); + return OC.generateUrl('/s/' + token + '', {dir: dir}); }; this.fileList.generatePreviewUrl = function (urlSpec) { @@ -240,6 +226,23 @@ OCA.Sharing.PublicApp = { window.FileList = this.fileList; }, + _showTextPreview: function (data, previewHeight) { + 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); + } + var watermark = $('
').addClass('watermark'); + watermark.text('SAMPLE'); + watermark.appendTo('#imgframe'); + }, + _onDirectoryChanged: function (e) { OC.Util.History.pushState({ // arghhhh, why is this not called "dir" !? -- cgit v1.2.3 From 0729fc2fbc46880901c0bbbab7985b0a14fb2a03 Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Thu, 23 Apr 2015 18:15:11 +0200 Subject: Remove overflow+watermark --- apps/files_sharing/css/public.css | 12 +++--------- apps/files_sharing/js/public.js | 8 +++----- 2 files changed, 6 insertions(+), 14 deletions(-) (limited to 'apps/files_sharing/js/public.js') diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css index 7aa898b489d..fc78ced0b76 100644 --- a/apps/files_sharing/css/public.css +++ b/apps/files_sharing/css/public.css @@ -32,7 +32,7 @@ position: relative; text-align: left; white-space: pre-wrap; - overflow-y: auto; + overflow-y: hidden; height: auto; min-height: 200px; max-height: 800px; @@ -42,16 +42,10 @@ -moz-user-select: none; -ms-user-select: none; user-select: none; - z-index: 1; } -#imgframe .watermark { - color: #E3E3E3; - font-size: 75pt; - position: absolute; - width: 80%; - top: 100px; - z-index: 0; +#imgframe .ellipsis { + font-size: 1.2em; } /* fix multiselect bar offset on shared page */ diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index cf049411c9b..79bd0bb0c47 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -232,15 +232,13 @@ OCA.Sharing.PublicApp = { textDiv.appendTo('#imgframe'); var divHeight = textDiv.height(); if (data.length > 999) { - textDiv.append('

(…)'); - divHeight += 50; + var ellipsis = $('
').addClass('ellipsis'); + ellipsis.html('(…)'); + ellipsis.appendTo('#imgframe'); } if (divHeight > previewHeight) { textDiv.height(previewHeight); } - var watermark = $('
').addClass('watermark'); - watermark.text('SAMPLE'); - watermark.appendTo('#imgframe'); }, _onDirectoryChanged: function (e) { -- cgit v1.2.3