diff options
author | Michael Gapczynski <mtgap@owncloud.com> | 2012-08-04 23:50:10 +0400 |
---|---|---|
committer | Michael Gapczynski <mtgap@owncloud.com> | 2012-08-04 23:50:32 +0400 |
commit | 207ca3ec06f642477632c3b79ed50820cf3d324a (patch) | |
tree | 6eaf78fbe999cc2b49bb3e8af7aa96690c4e1fae /apps/files | |
parent | 3b37181550c822b4a06a05680cc184f2c1fb0c5f (diff) |
Dynamically resize breadcrumbs, fix for bug oc-468
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/js/files.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/apps/files/js/files.js b/apps/files/js/files.js index a4e2361feeb..d003dab3dd2 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -533,6 +533,65 @@ $(document).ready(function() { scanFiles(); } }, "json"); + + var lastWidth = 0; + var breadcrumbs = []; + var breadcrumbsWidth = $('#navigation').get(0).offsetWidth + $('#controls .actions').get(0).offsetWidth; + var hiddenBreadcrumbs = 0; + + $.each($('.crumb'), function(index, breadcrumb) { + breadcrumbs[index] = breadcrumb; + breadcrumbsWidth += $(breadcrumb).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; + } + } + + $(window).resize(function() { + resizeBreadcrumbs(false); + }); + + resizeBreadcrumbs(true); }); function scanFiles(force,dir){ |