Fixed computation and removed unwanted scripts

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2017-11-04 09:45:29 +01:00
parent 9616074f58
commit 6ee75e16af
No known key found for this signature in database
GPG Key ID: FB5ACEED51955BF8
3 changed files with 55 additions and 101 deletions

View File

@ -136,7 +136,6 @@
$crumb.on('click', this.onClick);
}
}
$crumb.addClass('last');
_.each(this._detailViews, function(view) {
view.render({
@ -160,8 +159,7 @@
hoverClass: 'canDrop'
});
}
this._updateTotalWidth();
this._resize();
},
/**
@ -197,55 +195,36 @@
return crumbs;
},
/**
* Calculate the total breadcrumb width when
* all crumbs are expanded
*/
_updateTotalWidth: function () {
this.totalWidth = 0;
for (var i = 0; i < this.breadcrumbs.length; i++ ) {
var $crumb = $(this.breadcrumbs[i]);
this.totalWidth += $crumb.width();
}
this._resize();
},
/**
* Hide the middle crumb
*/
_hideCrumb: function() {
var length = this.$el.find('.crumb:not(.hidden)').length;
// Get the middle one floored down
var elmt = Math.floor(length / 2 - 0.5);
this.$el.find('.crumb:not(.hidden):eq('+elmt+')').addClass('hidden');
},
/**
* Show/hide breadcrumbs to fit the given width
*
* @param {int} availableWidth available width
*/
setMaxWidth: function (availableWidth) {
if (this.availableWidth !== availableWidth) {
this.availableWidth = availableWidth;
this._resize();
}
},
/**
* Return the number of items to hide
*/
_toShrink: function() {
var maxWidth = this.$el.parent().width();
console.log('Available width:' +maxWidth);
var smallestWidth = 50;
// 50px by default for the ellipsis crumb
return Math.ceil((this.totalWidth + 50 - maxWidth) / smallestWidth);
},
/**
* Hide the desired number of items
*
* @param {int} number to hide
*/
_hideCrumbs: function(toHide) {
var min = Math.round(this.breadcrumbs.length/2 - toHide/2);
var max = Math.round(this.breadcrumbs.length/2 + toHide/2 - 1);
console.log('toShrink: '+toHide);
this.$el.find('.crumb').removeClass('hidden')
.slice(min, max).addClass('hidden');
/**
* Get the crumb to show
*/
_getCrumbElement: function() {
var length = this.$el.find('.crumb.hidden').length;
// Get the outer one with priority to the highest
var elmt = (length % 2) * (length - 1);
return this.$el.find('.crumb.hidden:eq('+elmt+')');
},
/**
* Show the middle crumb
*/
_showCrumb: function() {
if(this.$el.find('.crumb.hidden').length === 1) {
this.$el.find('.crumb.hidden').removeClass('hidden');
}
this._getCrumbElement().removeClass('hidden');
},
_resize: function() {
var i, $crumb, $ellipsisCrumb;
@ -256,9 +235,17 @@
if (this.breadcrumbs.length <= 1) {
return;
}
this._hideCrumbs(this._toShrink());
// If container is smaller than content
while (this.$el.width() > this.$el.parent().width()) {
this._hideCrumb();
}
// If container is bigger than content + element to be shown
// AND if there is at least one hidden crumb
while (this.$el.find('.crumb.hidden').length > 0
&& this.$el.width() + this._getCrumbElement().width() < this.$el.parent().width()) {
this._showCrumb();
}
}
};

View File

@ -322,7 +322,7 @@
this.$el.find('thead th .columntitle').click(_.bind(this._onClickHeader, this));
this._onResize = _.debounce(_.bind(this._onResize, this), 100);
this._onResize = _.debounce(_.bind(this._onResize, this), 250);
$('#app-content').on('appresized', this._onResize);
$(window).resize(this._onResize);
@ -555,7 +555,7 @@
// subtract app navigation toggle when visible
containerWidth -= $('#app-navigation-toggle').width();
this.breadcrumb.setMaxWidth(containerWidth - actionsWidth - 10);
this.breadcrumb._resize();
this.$table.find('>thead').width($('#app-content').width() - OC.Util.getScrollBarWidth());
},

View File

@ -1625,39 +1625,6 @@ function initCore() {
// initial call
toggleSnapperOnSize();
// adjust controls bar width
var adjustControlsWidth = function() {
if($('#controls').length) {
var controlsWidth;
// if there is a scrollbar …
if($('#app-content').get(0).scrollHeight > $('#app-content').height()) {
if($(window).width() > 768) {
controlsWidth = $('#content').width() - $('#app-navigation').width() - getScrollBarWidth();
if (!$('#app-sidebar').hasClass('hidden') && !$('#app-sidebar').hasClass('disappear')) {
controlsWidth -= $('#app-sidebar').width();
}
} else {
controlsWidth = $('#content').width() - getScrollBarWidth();
}
} else { // if there is none
if($(window).width() > 768) {
controlsWidth = $('#content').width() - $('#app-navigation').width();
if (!$('#app-sidebar').hasClass('hidden') && !$('#app-sidebar').hasClass('disappear')) {
controlsWidth -= $('#app-sidebar').width();
}
} else {
controlsWidth = $('#content').width();
}
}
$('#controls').css('width', controlsWidth);
$('#controls').css('min-width', controlsWidth);
}
};
$(window).resize(_.debounce(adjustControlsWidth, 250));
$('body').delegate('#app-content', 'apprendered appresized', _.debounce(adjustControlsWidth, 150));
}
// Update live timestamps every 30 seconds