diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2013-09-17 19:10:46 +0200 |
---|---|---|
committer | Jörn Friedrich Dreyer <jfd@butonic.de> | 2013-09-17 19:10:46 +0200 |
commit | b59ce403d8ea80ba7aac5683f667853218757502 (patch) | |
tree | 2e657117cc3e9fd7a8dfe032945cb1e9a63edc46 /apps/files/js | |
parent | 2c9b3d32efa466b655a7f24c5022a42045ef482f (diff) | |
parent | 9d18e16c77e8c2690dd23dd19ca1f8e1968161c8 (diff) | |
download | nextcloud-server-b59ce403d8ea80ba7aac5683f667853218757502.tar.gz nextcloud-server-b59ce403d8ea80ba7aac5683f667853218757502.zip |
Merge branch 'master' into fix_3728_with_file_exists_dialog
Conflicts:
apps/files/css/files.css
apps/files/js/file-upload.js
apps/files/js/filelist.js
apps/files/js/files.js
apps/files_sharing/js/public.js
core/js/jquery.ocdialog.js
core/js/oc-dialogs.js
Diffstat (limited to 'apps/files/js')
-rw-r--r-- | apps/files/js/file-upload.js | 13 | ||||
-rw-r--r-- | apps/files/js/fileactions.js | 5 | ||||
-rw-r--r-- | apps/files/js/filelist.js | 265 | ||||
-rw-r--r-- | apps/files/js/files.js | 208 |
4 files changed, 351 insertions, 140 deletions
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index e5b3f807580..28270f13938 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -298,8 +298,15 @@ $(document).ready(function() { start: function(e) { OC.Upload.logStatus('start', e, null); }, - submit: function (e, data) { + submit: function(e, data) { OC.Upload.rememberUpload(data); + if ( ! data.formData ) { + // noone set update parameters, we set the minimum + data.formData = { + requesttoken: oc_requesttoken, + dir: $('#dir').val() + }; + } }, fail: function(e, data) { OC.Upload.logStatus('fail', e, data); @@ -421,9 +428,7 @@ $(document).ready(function() { // http://stackoverflow.com/a/6700/11236 var size = 0, key; for (key in obj) { - if (obj.hasOwnProperty(key)) { - size++; - } + if (obj.hasOwnProperty(key)) size++; } return size; }; diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 703e543bf4b..af7c757276e 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -196,13 +196,12 @@ FileActions.register('all', 'Rename', OC.PERMISSION_UPDATE, function () { FileList.rename(filename); }); - FileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename) { - var dir = $('#dir').val(); + var dir = $('#dir').val() || '/'; if (dir !== '/') { dir = dir + '/'; } - window.location = OC.linkTo('files', 'index.php') + '?dir=' + encodeURIComponent(dir + filename); + FileList.changeDirectory(dir + filename); }); FileActions.setDefault('dir', 'Open'); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 49d7afa9b5c..ffdbe5ef01e 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1,7 +1,28 @@ var FileList={ useUndo:true, + postProcessList: function(){ + $('#fileList tr').each(function(){ + //little hack to set unescape filenames in attribute + $(this).attr('data-file',decodeURIComponent($(this).attr('data-file'))); + }); + }, update:function(fileListHtml) { - $('#fileList').empty().html(fileListHtml); + var $fileList = $('#fileList'), + permissions = $('#permissions').val(), + isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0; + $fileList.empty().html(fileListHtml); + $('#emptycontent').toggleClass('hidden', !isCreatable || $fileList.find('tr').length > 0); + $fileList.find('tr').each(function () { + FileActions.display($(this).children('td.filename')); + }); + $fileList.trigger(jQuery.Event("fileActionsReady")); + FileList.postProcessList(); + // "Files" might not be loaded in extending apps + if (window.Files){ + Files.setupDragAndDrop(); + } + FileList.updateFileSummary(); + $fileList.trigger(jQuery.Event("updated")); }, createRow:function(type, name, iconurl, linktarget, size, lastModified, permissions){ var td, simpleSize, basename, extension; @@ -24,20 +45,20 @@ var FileList={ "href": linktarget }); //split extension from filename for non dirs - if (type !== 'dir' && name.indexOf('.')!==-1) { - basename = name.substr(0,name.lastIndexOf('.')); - extension = name.substr(name.lastIndexOf('.')); + if (type != 'dir' && name.indexOf('.')!=-1) { + basename=name.substr(0,name.lastIndexOf('.')); + extension=name.substr(name.lastIndexOf('.')); } else { - basename = name; - extension = false; + basename=name; + extension=false; } - var name_span = $('<span></span>').addClass('nametext').text(basename); + var name_span=$('<span></span>').addClass('nametext').text(basename); link_elem.append(name_span); if(extension){ name_span.append($('<span></span>').addClass('extension').text(extension)); } //dirs can show the number of uploaded files - if (type === 'dir') { + if (type == 'dir') { link_elem.append($('<span></span>').attr({ 'class': 'uploadtext', 'currentUploads': 0 @@ -47,10 +68,10 @@ var FileList={ tr.append(td); //size column - if (size!==t('files', 'Pending')) { + if(size!=t('files', 'Pending')){ simpleSize = humanFileSize(size); - } else { - simpleSize = t('files', 'Pending'); + }else{ + simpleSize=t('files', 'Pending'); } var sizeColor = Math.round(160-Math.pow((size/(1024*1024)),2)); var lastModifiedTime = Math.round(lastModified.getTime() / 1000); @@ -101,9 +122,9 @@ var FileList={ ); FileList.insertElement(name, 'file', tr); - if (loading) { + if(loading){ tr.data('loading',true); - } else { + }else{ tr.find('td.filename').draggable(dragOptions); } if (hidden) { @@ -134,20 +155,109 @@ var FileList={ FileActions.display(tr.find('td.filename')); return tr; }, - refresh:function(data) { - var result = jQuery.parseJSON(data.responseText); - if(typeof(result.data.breadcrumb) !== 'undefined'){ - updateBreadcrumb(result.data.breadcrumb); + /** + * @brief Changes the current directory and reload the file list. + * @param targetDir target directory (non URL encoded) + * @param changeUrl false if the URL must not be changed (defaults to true) + */ + changeDirectory: function(targetDir, changeUrl, force){ + var $dir = $('#dir'), + url, + currentDir = $dir.val() || '/'; + targetDir = targetDir || '/'; + if (!force && currentDir === targetDir){ + return; + } + FileList.setCurrentDir(targetDir, changeUrl); + FileList.reload(); + }, + linkTo: function(dir){ + return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/'); + }, + setCurrentDir: function(targetDir, changeUrl){ + $('#dir').val(targetDir); + if (changeUrl !== false){ + if (window.history.pushState && changeUrl !== false){ + url = FileList.linkTo(targetDir); + window.history.pushState({dir: targetDir}, '', url); + } + // use URL hash for IE8 + else{ + window.location.hash = '?dir='+ encodeURIComponent(targetDir).replace(/%2F/g, '/'); + } + } + }, + /** + * @brief Reloads the file list using ajax call + */ + reload: function(){ + FileList.showMask(); + if (FileList._reloadCall){ + FileList._reloadCall.abort(); + } + FileList._reloadCall = $.ajax({ + url: OC.filePath('files','ajax','list.php'), + data: { + dir : $('#dir').val(), + breadcrumb: true + }, + error: function(result){ + FileList.reloadCallback(result); + }, + success: function(result) { + FileList.reloadCallback(result); + } + }); + }, + reloadCallback: function(result){ + var $controls = $('#controls'); + + delete FileList._reloadCall; + FileList.hideMask(); + + if (!result || result.status === 'error') { + OC.Notification.show(result.data.message); + return; + } + + if (result.status === 404){ + // go back home + FileList.changeDirectory('/'); + return; + } + + if (result.data.permissions){ + FileList.setDirectoryPermissions(result.data.permissions); + } + + if(typeof(result.data.breadcrumb) != 'undefined'){ + $controls.find('.crumb').remove(); + $controls.prepend(result.data.breadcrumb); + + var width = $(window).width(); + Files.initBreadCrumbs(); + Files.resizeBreadcrumbs(width, true); + + // in case svg is not supported by the browser we need to execute the fallback mechanism + if(!SVGSupport()) { + replaceSVG(); + } } + FileList.update(result.data.files); - resetFileActionPanel(); + }, + setDirectoryPermissions: function(permissions){ + var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0; + $('#permissions').val(permissions); + $('.creatable').toggleClass('hidden', !isCreatable); + $('.notCreatable').toggleClass('hidden', isCreatable); }, remove:function(name){ $('tr').filterAttr('data-file',name).find('td.filename').draggable('destroy'); $('tr').filterAttr('data-file',name).remove(); FileList.updateFileSummary(); - if($('tr[data-file]').length===0){ - $('#emptycontent').show(); + if($('tr[data-file]').length==0){ + $('#emptycontent').removeClass('hidden'); } }, insertElement:function(name,type,element){ @@ -165,19 +275,19 @@ var FileList={ } } if(fileElements.length){ - if(pos===-1){ + if(pos==-1){ $(fileElements[0]).before(element); }else{ $(fileElements[pos]).after(element); } - }else if(type==='dir' && $('tr[data-file]').length>0){ + }else if(type=='dir' && $('tr[data-file]').length>0){ $('tr[data-file]').first().before(element); - } else if(type==='file' && $('tr[data-file]').length>0) { + } else if(type=='file' && $('tr[data-file]').length>0) { $('tr[data-file]').last().before(element); }else{ $('#fileList').append(element); } - $('#emptycontent').hide(); + $('#emptycontent').addClass('hidden'); FileList.updateFileSummary(); }, loadingDone:function(name, id){ @@ -185,7 +295,7 @@ var FileList={ tr.data('loading',false); mime=tr.data('mime'); tr.attr('data-mime',mime); - if (id) { + if (id != null) { tr.attr('data-id', id); } var path = getPathForPreview(name); @@ -221,7 +331,7 @@ var FileList={ var newname=input.val(); if (!Files.isFileNameValid(newname)) { return false; - } else if (newname !== name) { + } else if (newname != name) { if (FileList.checkName(name, newname, false)) { newname = name; } else { @@ -269,14 +379,14 @@ var FileList={ tr.attr('data-file', newname); var path = td.children('a.name').attr('href'); td.children('a.name').attr('href', path.replace(encodeURIComponent(name), encodeURIComponent(newname))); - if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') { + if (newname.indexOf('.') > 0 && tr.data('type') != 'dir') { var basename=newname.substr(0,newname.lastIndexOf('.')); } else { var basename=newname; } td.find('a.name span.nametext').text(basename); - if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') { - if (td.find('a.name span.extension').length === 0 ) { + if (newname.indexOf('.') > 0 && tr.data('type') != 'dir') { + if (td.find('a.name span.extension').length == 0 ) { td.find('a.name span.nametext').append('<span class="extension"></span>'); } td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.'))); @@ -286,7 +396,7 @@ var FileList={ return false; }); input.keyup(function(event){ - if (event.keyCode === 27) { + if (event.keyCode == 27) { tr.data('renaming',false); form.remove(); td.children('a.name').show(); @@ -312,7 +422,7 @@ var FileList={ html.attr('data-oldName', oldName); html.attr('data-newName', newName); html.attr('data-isNewFile', isNewFile); - OC.Notification.showHtml(html); + OC.Notification.showHtml(html); return true; } else { return false; @@ -351,13 +461,13 @@ var FileList={ FileList.finishReplace(); }; if (!isNewFile) { - OC.Notification.showHtml(t('files', 'replaced {new_name} with {old_name}', {new_name: newName}, {old_name: oldName})+'<span class="undo">'+t('files', 'undo')+'</span>'); + OC.Notification.showHtml(t('files', 'replaced {new_name} with {old_name}', {new_name: newName}, {old_name: oldName})+'<span class="undo">'+t('files', 'undo')+'</span>'); } }, finishReplace:function() { if (!FileList.replaceCanceled && FileList.replaceOldName && FileList.replaceNewName) { $.ajax({url: OC.filePath('files', 'ajax', 'rename.php'), async: false, data: { dir: $('#dir').val(), newname: FileList.replaceNewName, file: FileList.replaceOldName }, success: function(result) { - if (result && result.status === 'success') { + if (result && result.status == 'success') { $('tr').filterAttr('data-replace', 'true').removeAttr('data-replace'); } else { OC.dialogs.alert(result.data.message, 'Error moving file'); @@ -386,7 +496,7 @@ var FileList={ $.post(OC.filePath('files', 'ajax', 'delete.php'), {dir:$('#dir').val(),files:fileNames}, function(result){ - if (result.status === 'success') { + if (result.status == 'success') { $.each(files,function(index,file){ var files = $('tr').filterAttr('data-file',file); files.remove(); @@ -427,7 +537,7 @@ var FileList={ var infoVars = { dirs: '<span class="dirinfo">'+directoryInfo+'</span><span class="connector">', files: '</span><span class="fileinfo">'+fileInfo+'</span>' - }; + } var info = t('files', '{dirs} and {files}', infoVars); @@ -508,6 +618,31 @@ var FileList={ $connector.show(); } } + }, + showMask: function(){ + // in case one was shown before + var $mask = $('#content .mask'); + if ($mask.length){ + return; + } + + $mask = $('<div class="mask transparent"></div>'); + + $mask.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')'); + $mask.css('background-repeat', 'no-repeat'); + $('#content').append($mask); + + // block UI, but only make visible in case loading takes longer + FileList._maskTimeout = window.setTimeout(function(){ + // reset opacity + $mask.removeClass('transparent'); + }, 250); + }, + hideMask: function(){ + var $mask = $('#content .mask').remove(); + if (FileList._maskTimeout){ + window.clearTimeout(FileList._maskTimeout); + } } }; @@ -696,16 +831,16 @@ $(document).ready(function(){ FileList.replaceIsNewFile = null; } FileList.lastAction = null; - OC.Notification.hide(); + OC.Notification.hide(); }); $('#notification:first-child').on('click', '.replace', function() { - OC.Notification.hide(function() { - FileList.replace($('#notification > span').attr('data-oldName'), $('#notification > span').attr('data-newName'), $('#notification > span').attr('data-isNewFile')); - }); + OC.Notification.hide(function() { + FileList.replace($('#notification > span').attr('data-oldName'), $('#notification > span').attr('data-newName'), $('#notification > span').attr('data-isNewFile')); + }); }); $('#notification:first-child').on('click', '.suggest', function() { $('tr').filterAttr('data-file', $('#notification > span').attr('data-oldName')).show(); - OC.Notification.hide(); + OC.Notification.hide(); }); $('#notification:first-child').on('click', '.cancel', function() { if ($('#notification > span').attr('data-isNewFile')) { @@ -723,5 +858,55 @@ $(document).ready(function(){ $(window).trigger('beforeunload'); }); + function parseHashQuery(){ + var hash = window.location.hash, + pos = hash.indexOf('?'), + query; + if (pos >= 0){ + return hash.substr(pos + 1); + } + return ''; + } + + function parseCurrentDirFromUrl(){ + var query = parseHashQuery(), + params, + dir = '/'; + // try and parse from URL hash first + if (query){ + params = OC.parseQueryString(query); + } + // else read from query attributes + if (!params){ + params = OC.parseQueryString(location.search); + } + return (params && params.dir) || '/'; + } + + // fallback to hashchange when no history support + if (!window.history.pushState){ + $(window).on('hashchange', function(){ + FileList.changeDirectory(parseCurrentDirFromUrl(), false); + }); + } + window.onpopstate = function(e){ + var targetDir; + if (e.state && e.state.dir){ + targetDir = e.state.dir; + } + else{ + // read from URL + targetDir = parseCurrentDirFromUrl(); + } + if (targetDir){ + FileList.changeDirectory(targetDir, false); + } + } + + if (parseInt($('#ajaxLoad').val(), 10) === 1){ + // need to initially switch the dir to the one from the hash (IE8) + FileList.changeDirectory(parseCurrentDirFromUrl(), false, true); + } + FileList.createFileSummary(); }); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 4a6c9c78900..afbb14c5e00 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -1,6 +1,6 @@ Files={ updateMaxUploadFilesize:function(response) { - if(response === undefined) { + if(response == undefined) { return; } if(response.data !== undefined && response.data.uploadMaxFilesize !== undefined) { @@ -9,7 +9,7 @@ Files={ $('#usedSpacePercent').val(response.data.usedSpacePercent); Files.displayStorageWarnings(); } - if(response[0] === undefined) { + if(response[0] == undefined) { return; } if(response[0].uploadMaxFilesize !== undefined) { @@ -25,7 +25,7 @@ Files={ OC.Notification.show(t('files', '\'.\' is an invalid file name.')); return false; } - if (name.length === 0) { + if (name.length == 0) { OC.Notification.show(t('files', 'File name cannot be empty.')); return false; } @@ -33,7 +33,7 @@ Files={ // check for invalid characters var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*']; for (var i = 0; i < invalid_characters.length; i++) { - if (name.indexOf(invalid_characters[i]) !== -1) { + if (name.indexOf(invalid_characters[i]) != -1) { OC.Notification.show(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.")); return false; } @@ -67,29 +67,106 @@ Files={ OC.Notification.show(t('files_encryption', 'Encryption was disabled but your files are still encrypted. Please go to your personal settings to decrypt your files.')); return; } + }, + + setupDragAndDrop: function(){ + var $fileList = $('#fileList'); + + //drag/drop of files + $fileList.find('tr td.filename').each(function(i,e){ + if ($(e).parent().data('permissions') & OC.PERMISSION_DELETE) { + $(e).draggable(dragOptions); + } + }); + + $fileList.find('tr[data-type="dir"] td.filename').each(function(i,e){ + if ($(e).parent().data('permissions') & OC.PERMISSION_CREATE){ + $(e).droppable(folderDropOptions); + } + }); + }, + + lastWidth: 0, + + initBreadCrumbs: function () { + Files.lastWidth = 0; + Files.breadcrumbs = []; + + // initialize with some extra space + Files.breadcrumbsWidth = 64; + if ( document.getElementById("navigation") ) { + Files.breadcrumbsWidth += $('#navigation').get(0).offsetWidth; + } + Files.hiddenBreadcrumbs = 0; + + $.each($('.crumb'), function(index, breadcrumb) { + Files.breadcrumbs[index] = breadcrumb; + Files.breadcrumbsWidth += $(breadcrumb).get(0).offsetWidth; + }); + + $.each($('#controls .actions>div'), function(index, action) { + Files.breadcrumbsWidth += $(action).get(0).offsetWidth; + }); + + // event handlers for breadcrumb items + $('#controls .crumb a').on('click', onClickBreadcrumb); + }, + + resizeBreadcrumbs: function (width, firstRun) { + if (width != Files.lastWidth) { + if ((width < Files.lastWidth || firstRun) && width < Files.breadcrumbsWidth) { + if (Files.hiddenBreadcrumbs == 0) { + Files.breadcrumbsWidth -= $(Files.breadcrumbs[1]).get(0).offsetWidth; + $(Files.breadcrumbs[1]).find('a').hide(); + $(Files.breadcrumbs[1]).append('<span>...</span>'); + Files.breadcrumbsWidth += $(Files.breadcrumbs[1]).get(0).offsetWidth; + Files.hiddenBreadcrumbs = 2; + } + var i = Files.hiddenBreadcrumbs; + while (width < Files.breadcrumbsWidth && i > 1 && i < Files.breadcrumbs.length - 1) { + Files.breadcrumbsWidth -= $(Files.breadcrumbs[i]).get(0).offsetWidth; + $(Files.breadcrumbs[i]).hide(); + Files.hiddenBreadcrumbs = i; + i++ + } + } else if (width > Files.lastWidth && Files.hiddenBreadcrumbs > 0) { + var i = Files.hiddenBreadcrumbs; + while (width > Files.breadcrumbsWidth && i > 0) { + if (Files.hiddenBreadcrumbs == 1) { + Files.breadcrumbsWidth -= $(Files.breadcrumbs[1]).get(0).offsetWidth; + $(Files.breadcrumbs[1]).find('span').remove(); + $(Files.breadcrumbs[1]).find('a').show(); + Files.breadcrumbsWidth += $(Files.breadcrumbs[1]).get(0).offsetWidth; + } else { + $(Files.breadcrumbs[i]).show(); + Files.breadcrumbsWidth += $(Files.breadcrumbs[i]).get(0).offsetWidth; + if (Files.breadcrumbsWidth > width) { + Files.breadcrumbsWidth -= $(Files.breadcrumbs[i]).get(0).offsetWidth; + $(Files.breadcrumbs[i]).hide(); + break; + } + } + i--; + Files.hiddenBreadcrumbs = i; + } + } + Files.lastWidth = width; + } } }; $(document).ready(function() { + // FIXME: workaround for trashbin app + if (window.trashBinApp){ + return; + } Files.displayEncryptionWarning(); Files.bindKeyboardShortcuts(document, jQuery); - $('#fileList tr').each(function(){ - //little hack to set unescape filenames in attribute - $(this).attr('data-file',decodeURIComponent($(this).attr('data-file'))); - }); + + FileList.postProcessList(); + Files.setupDragAndDrop(); $('#file_action_panel').attr('activeAction', false); - //drag/drop of files - $('#fileList tr td.filename').each(function(i,e){ - if ($(e).parent().data('permissions') & OC.PERMISSION_DELETE) { - $(e).draggable(dragOptions); - } - }); - $('#fileList tr[data-type="dir"] td.filename').each(function(i,e){ - if ($(e).parent().data('permissions') & OC.PERMISSION_CREATE){ - $(e).droppable(folderDropOptions); - } - }); $('div.crumb:not(.last)').droppable(crumbDropOptions); $('ul#apps>li:first-child').data('dir',''); if($('div.crumb').length){ @@ -127,7 +204,7 @@ $(document).ready(function() { var rows = $(this).parent().parent().parent().children('tr'); for (var i = start; i < end; i++) { $(rows).each(function(index) { - if (index === i) { + if (index == i) { var checkbox = $(this).children().children('input:checkbox'); $(checkbox).attr('checked', 'checked'); $(checkbox).parent().parent().addClass('selected'); @@ -145,7 +222,7 @@ $(document).ready(function() { $(checkbox).attr('checked', 'checked'); $(checkbox).parent().parent().toggleClass('selected'); var selectedCount=$('td.filename input:checkbox:checked').length; - if (selectedCount === $('td.filename input:checkbox').length) { + if (selectedCount == $('td.filename input:checkbox').length) { $('#select_all').attr('checked', 'checked'); } } @@ -192,7 +269,7 @@ $(document).ready(function() { var rows = $(this).parent().parent().parent().children('tr'); for (var i = start; i < end; i++) { $(rows).each(function(index) { - if (index === i) { + if (index == i) { var checkbox = $(this).children().children('input:checkbox'); $(checkbox).attr('checked', 'checked'); $(checkbox).parent().parent().addClass('selected'); @@ -205,7 +282,7 @@ $(document).ready(function() { if(!$(this).attr('checked')){ $('#select_all').attr('checked',false); }else{ - if(selectedCount === $('td.filename input:checkbox').length){ + if(selectedCount==$('td.filename input:checkbox').length){ $('#select_all').attr('checked',true); } } @@ -242,72 +319,15 @@ $(document).ready(function() { //do a background scan if needed scanFiles(); - var lastWidth = 0; - var breadcrumbs = []; - var breadcrumbsWidth = 0; - if ( document.getElementById("navigation") ) { - breadcrumbsWidth = $('#navigation').get(0).offsetWidth; - } - var hiddenBreadcrumbs = 0; - - $.each($('.crumb'), function(index, breadcrumb) { - breadcrumbs[index] = breadcrumb; - breadcrumbsWidth += $(breadcrumb).get(0).offsetWidth; - }); - - - $.each($('#controls .actions>div'), function(index, action) { - breadcrumbsWidth += $(action).get(0).offsetWidth; - }); - - function resizeBreadcrumbs(firstRun) { - var width = $(this).width(); - if (width !== lastWidth) { - if ((width < lastWidth || firstRun) && width < breadcrumbsWidth) { - if (hiddenBreadcrumbs === 0) { - breadcrumbsWidth -= $(breadcrumbs[1]).get(0).offsetWidth; - $(breadcrumbs[1]).find('a').hide(); - $(breadcrumbs[1]).append('<span>...</span>'); - breadcrumbsWidth += $(breadcrumbs[1]).get(0).offsetWidth; - hiddenBreadcrumbs = 2; - } - var i = hiddenBreadcrumbs; - while (width < breadcrumbsWidth && i > 1 && i < breadcrumbs.length - 1) { - breadcrumbsWidth -= $(breadcrumbs[i]).get(0).offsetWidth; - $(breadcrumbs[i]).hide(); - hiddenBreadcrumbs = i; - i++; - } - } else if (width > lastWidth && hiddenBreadcrumbs > 0) { - var i = hiddenBreadcrumbs; - while (width > breadcrumbsWidth && i > 0) { - if (hiddenBreadcrumbs === 1) { - breadcrumbsWidth -= $(breadcrumbs[1]).get(0).offsetWidth; - $(breadcrumbs[1]).find('span').remove(); - $(breadcrumbs[1]).find('a').show(); - breadcrumbsWidth += $(breadcrumbs[1]).get(0).offsetWidth; - } else { - $(breadcrumbs[i]).show(); - breadcrumbsWidth += $(breadcrumbs[i]).get(0).offsetWidth; - if (breadcrumbsWidth > width) { - breadcrumbsWidth -= $(breadcrumbs[i]).get(0).offsetWidth; - $(breadcrumbs[i]).hide(); - break; - } - } - i--; - hiddenBreadcrumbs = i; - } - } - lastWidth = width; - } - } + Files.initBreadCrumbs(); $(window).resize(function() { - resizeBreadcrumbs(false); + var width = $(this).width(); + Files.resizeBreadcrumbs(width, false); }); - resizeBreadcrumbs(true); + var width = $(this).width(); + Files.resizeBreadcrumbs(width, true); // display storage warnings setTimeout ( "Files.displayStorageWarnings()", 100 ); @@ -382,17 +402,13 @@ scanFiles.scanning=false; function boolOperationFinished(data, callback) { result = jQuery.parseJSON(data.responseText); Files.updateMaxUploadFilesize(result); - if(result.status === 'success'){ + if(result.status == 'success'){ callback.call(); } else { alert(result.data.message); } } -function updateBreadcrumb(breadcrumbHtml) { - $('p.nav').empty().html(breadcrumbHtml); -} - var createDragShadow = function(event){ //select dragged file var isDragSelected = $(event.target).parents('tr').find('td input:first').prop('checked'); @@ -436,7 +452,7 @@ var createDragShadow = function(event){ }); return dragshadow; -}; +} //options for file drag/drop var dragOptions={ @@ -446,7 +462,7 @@ var dragOptions={ stop: function(event, ui) { $('#fileList tr td.filename').addClass('ui-draggable'); } -}; +} // sane browsers support using the distance option if ( $('html.ie').length === 0) { dragOptions['distance'] = 20; @@ -489,7 +505,7 @@ var folderDropOptions={ }); }, tolerance: 'pointer' -}; +} var crumbDropOptions={ drop: function( event, ui ) { @@ -655,3 +671,9 @@ function checkTrashStatus() { } }); } + +function onClickBreadcrumb(e){ + var $el = $(e.target).closest('.crumb'); + e.preventDefault(); + FileList.changeDirectory(decodeURIComponent($el.data('dir'))); +} |