DataView refactoring: add alwaysVisibleScrollbar parameter

This commit is contained in:
Julia Radzhabova 2018-03-16 13:07:18 +03:00
parent 66f6dacc05
commit e51c72052e
2 changed files with 20 additions and 11 deletions

View file

@ -197,6 +197,7 @@ define([
emptyText: '',
listenStoreEvents: true,
allowScrollbar: true,
scrollAlwaysVisible: false,
showLast: true,
useBSKeydown: false
},
@ -239,6 +240,7 @@ define([
me.emptyText = me.options.emptyText || '';
me.listenStoreEvents= (me.options.listenStoreEvents!==undefined) ? me.options.listenStoreEvents : true;
me.allowScrollbar = (me.options.allowScrollbar!==undefined) ? me.options.allowScrollbar : true;
me.scrollAlwaysVisible = me.options.scrollAlwaysVisible || false;
if (me.parentMenu)
me.parentMenu.options.restoreHeight = (me.options.restoreHeight>0);
me.rendered = false;
@ -308,7 +310,8 @@ define([
el: $(this.el).find('.inner').addBack().filter('.inner'),
useKeyboard: this.enableKeyEvents && !this.handleSelect,
minScrollbarLength : 40,
wheelSpeed: 10
wheelSpeed: 10,
alwaysVisibleY: this.scrollAlwaysVisible
});
}
@ -361,11 +364,12 @@ define([
if (suspendEvents)
this.resumeEvents();
return record;
},
selectByIndex: function(index, suspendEvents) {
if (this.store.length > 0 && index > -1 && index < this.store.length) {
this.selectRecord(this.store.at(index), suspendEvents);
return this.selectRecord(this.store.at(index), suspendEvents);
}
},
@ -480,7 +484,8 @@ define([
el: $(this.el).find('.inner').addBack().filter('.inner'),
useKeyboard: this.enableKeyEvents && !this.handleSelect,
minScrollbarLength : 40,
wheelSpeed: 10
wheelSpeed: 10,
alwaysVisibleY: this.scrollAlwaysVisible
});
}
@ -568,6 +573,7 @@ define([
},
scrollToRecord: function (record) {
if (!record) return;
var innerEl = $(this.el).find('.inner'),
inner_top = innerEl.offset().top,
idx = _.indexOf(this.store.models, record),
@ -576,7 +582,7 @@ define([
var div_top = div.offset().top,
div_first = $(this.dataViewItems[0].el),
div_first_top = (div_first.length>=0) ? div_first[0].offsetTop : 0;
div_first_top = (div_first.length>0) ? div_first[0].offsetTop : 0;
if (div_top < inner_top + div_first_top || div_top+div.outerHeight() > inner_top + innerEl.height()) {
if (this.scroller && this.allowScrollbar) {
this.scroller.scrollTop(innerEl.scrollTop() + div_top - inner_top - div_first_top, 0);
@ -718,14 +724,16 @@ define([
margins = parseInt(parent.css('margin-top')) + parseInt(parent.css('margin-bottom')) + parseInt(menuRoot.css('margin-top')),
paddings = parseInt(menuRoot.css('padding-top')) + parseInt(menuRoot.css('padding-bottom')),
menuH = menuRoot.outerHeight(),
top = parseInt(menuRoot.css('top'));
top = parseInt(menuRoot.css('top')),
props = {minScrollbarLength : 40};
this.scrollAlwaysVisible && (props.alwaysVisibleY = this.scrollAlwaysVisible);
if (top + menuH > docH ) {
innerEl.css('max-height', (docH - top - paddings - margins) + 'px');
if (this.allowScrollbar) this.scroller.update({minScrollbarLength : 40});
if (this.allowScrollbar) this.scroller.update(props);
} else if ( top + menuH < docH && innerEl.height() < this.options.restoreHeight ) {
innerEl.css('max-height', (Math.min(docH - top - paddings - margins, this.options.restoreHeight)) + 'px');
if (this.allowScrollbar) this.scroller.update({minScrollbarLength : 40});
if (this.allowScrollbar) this.scroller.update(props);
}
},

View file

@ -158,6 +158,7 @@ define([
handleSelect: true,
showLast: true,
allowScrollbar: true,
scrollAlwaysVisible: true,
emptyItemText: ''
},
@ -245,24 +246,24 @@ define([
var isExpanded = !record.get('isExpanded');
record.set('isExpanded', isExpanded);
this.store[(isExpanded) ? 'expandSubItems' : 'collapseSubItems'](record);
this.scroller.update({minScrollbarLength: 40});
this.scroller.update({minScrollbarLength: 40, alwaysVisibleY: this.scrollAlwaysVisible});
} else
Common.UI.DataView.prototype.onClickItem.call(this, view, record, e);
},
expandAll: function() {
this.store.expandAll();
this.scroller.update({minScrollbarLength: 40});
this.scroller.update({minScrollbarLength: 40, alwaysVisibleY: this.scrollAlwaysVisible});
},
collapseAll: function() {
this.store.collapseAll();
this.scroller.update({minScrollbarLength: 40});
this.scroller.update({minScrollbarLength: 40, alwaysVisibleY: this.scrollAlwaysVisible});
},
expandToLevel: function(expandLevel) {
this.store.expandToLevel(expandLevel);
this.scroller.update({minScrollbarLength: 40});
this.scroller.update({minScrollbarLength: 40, alwaysVisibleY: this.scrollAlwaysVisible});
}
}
})());