From fe33cd2a6d3082323d1ddedde834608d5102c963 Mon Sep 17 00:00:00 2001 From: Fabrice Cipolla Date: Thu, 4 Aug 2016 20:00:19 +0200 Subject: [PATCH 1/8] preview path for the copy and select functions + use preview for image --- scripts/filemanager.js | 44 ++++++++++++++++++++++++++++++-------- scripts/filemanager.min.js | 4 ++-- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/scripts/filemanager.js b/scripts/filemanager.js index 39316736..978fe4e7 100644 --- a/scripts/filemanager.js +++ b/scripts/filemanager.js @@ -22,6 +22,29 @@ $.urlParam = function(name) { } }; +// function to normalize a path (source: https://github.com/dfkaye/simple-path-normalize) +var normalizePath = function(path){ + var BLANK = ''; var SLASH = '/'; var DOT = '.';var DOTS = DOT.concat(DOT); + if (!path || path === SLASH) { + return SLASH; + } + + var src = path.split(SLASH); + var target = (path[0] === SLASH || path[0] === DOT) ? [BLANK] : []; + var i, len, token; + for (i = 0, len = src.length; i < len; ++i) { + token = src[i] || BLANK; + if (token === DOTS) { + if (target.length > 1) { + target.pop(); + } + } else if (token !== BLANK && token !== DOT) { + target.push(token); + } + } + return target.join(SLASH).replace(/[\/]{2, }/g, SLASH) || SLASH; +}; + /*--------------------------------------------------------- Setup, Layout, and Status Functions ---------------------------------------------------------*/ @@ -513,9 +536,13 @@ var isDocumentFile = function(filename) { } }; -// Build url to preview office and media files +// Build url to preview files var createPreviewUrl = function(path) { - return location.origin + location.pathname + path; + // already an absolute path + if(path.substr(0,4) === 'http' || path.substr(0,3) === 'ftp') + return path; + + return location.origin + normalizePath(location.pathname + path); }; // Return HTML video player @@ -842,7 +869,6 @@ var createFileTree = function() { }); }; - /*--------------------------------------------------------- Item Actions ---------------------------------------------------------*/ @@ -855,9 +881,9 @@ var createFileTree = function() { // NOTE: closes the window when finished. var selectItem = function(data) { if(config.options.baseUrl !== false ) { - var url = smartPath(baseUrl, data['Path'].replace(fileRoot, "")); + var url = smartPath(baseUrl, data['Preview'].replace(fileRoot, "")); } else { - var url = data['Path']; + var url = createPreviewUrl(data['Preview']); } if(window.opener || window.tinyMCEPopup || $.urlParam('field_name') || $.urlParam('CKEditorCleanUpFuncNum') || $.urlParam('CKEditor') || $.urlParam('ImperaviElementId')) { @@ -1836,7 +1862,7 @@ var getFileInfo = function(file) { $fileinfo.find('#main-title > h1').text(data['Filename']).attr('title', file); - $fileinfo.find('img').attr('src', data['Thumbnail']); + $fileinfo.find('img').attr('src', data["Preview"] ? createPreviewUrl(data["Preview"]) : data['Thumbnail']); if(isVideoFile(data['Filename']) && config.videos.showVideoPlayer == true) { getVideoPlayer(data); } @@ -1854,9 +1880,9 @@ var getFileInfo = function(file) { } if(config.options.baseUrl !== false ) { - var url = smartPath(baseUrl, data['Path'].replace(fileRoot, "")); + var url = smartPath(baseUrl, data['Preview'].replace(fileRoot, "")); } else { - var url = data['Path']; + var url = createPreviewUrl(data['Preview']); } if(data['Protected']==0) { $fileinfo.find('div#tools').append(' ' + lg.copy_to_clipboard + ''); @@ -2876,4 +2902,4 @@ if (!window.location.origin) { $(window).load(function() { $('#fileinfo').css({'left':$('#splitter .vsplitbar').width() + $('#filetree').width()}); -}); \ No newline at end of file +}); diff --git a/scripts/filemanager.min.js b/scripts/filemanager.min.js index 97d13cc8..f5be75ea 100644 --- a/scripts/filemanager.min.js +++ b/scripts/filemanager.min.js @@ -1,2 +1,2 @@ -!function(a){function b(b,c){return j.indexOf(c)!==-1&&(("dir"!=b["File Type"]||"replace"!=c)&&("dir"==b["File Type"]&&"download"==c?f.security.allowFolderDownload===!0:"undefined"==typeof b.Capabilities||a.inArray(c,b.Capabilities)>-1))}function c(c){var d={select:{name:y.select,className:"select"},download:{name:y.download,className:"download"},rename:{name:y.rename,className:"rename"},move:{name:y.move,className:"move"},replace:{name:y.replace,className:"replace"},separator1:"-----","delete":{name:y.del,className:"delete"}},e=c.data("itemdata");return b(e,"download")||delete d.download,b(e,"rename")&&f.options.browseOnly!==!0||delete d.rename,b(e,"delete")&&f.options.browseOnly!==!0||delete d["delete"],b(e,"move")&&f.options.browseOnly!==!0||delete d.move,b(e,"select")&&(window.opener||window.tinyMCEPopup||a.urlParam("field_name"))||delete d.select,delete d.replace,d}a.urlParam=function(a){var b=new RegExp("[\\?&]"+a+"=([^&#]*)").exec(window.location.href);return b?b[1]:0};var d=function(b){var c=null,d=".";if(b="undefined"==typeof b?"user":b,window._FMConfig&&window._FMConfig.pluginPath&&(d=window._FMConfig.pluginPath),"user"==b)if(0!=a.urlParam("config")){var e=d+"/scripts/"+a.urlParam("config");userconfig=a.urlParam("config")}else{var e=d+"/scripts/filemanager.config.json";userconfig="filemanager.config.json"}else var e=d+"/scripts/filemanager.config.default.json";return a.ajax({async:!1,url:e,dataType:"json",cache:!1,success:function(a){c=a}}),"default"==b&&(c.globals={pluginPath:d}),c},e=d("default"),f=d();if(null!==f&&delete f.version,f=a.extend({},e,f),f.options.logger){(new Date).getTime()}var g=[],h="/",i=f.options.fileConnector||f.globals.pluginPath+"/connectors/"+f.options.lang+"/filemanager."+f.options.lang,j=f.options.capabilities||["upload","select","download","rename","move","delete","replace"],k=null,l={},m=[];f.options.fileSorting&&(m=f.options.fileSorting.toLowerCase().split("_"));var n=m[0]||"name",o=m[1]||"asc",p=function(b){if(b=f.globals.pluginPath+b,a.inArray(b,g)==-1){var c=a("");a("head").append(c),g.push(b)}},q=function(b){if(b=f.globals.pluginPath+b,a.inArray(b,g)==-1){var c=a("