Skip to content

Commit

Permalink
feat: configure the long press time (#245)
Browse files Browse the repository at this point in the history
* Attempt at configuring the long press time

The default is 251 since I beleive that is the default of hammer
Added it to the documentation
I had to set it at Core and ItemSet

* Add the type

* Update index.html

* Change the variable to longSelectPressTime

Did some testing against the default and 251 does seem to be the default right now

* Merge branch 'master' of https://github.com/fras2560/vis-timeline.git

Conflicts:
	docs/timeline/index.html

* Remove the logging I was using during debugging

Co-authored-by: Yotam Berkowitz <[email protected]>
  • Loading branch information
fras2560 and yotamberk committed Jan 25, 2020
1 parent 2861085 commit dad6123
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
9 changes: 9 additions & 0 deletions docs/timeline/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,15 @@ <h2 id="Configuration_Options">Configuration Options</h2>
<td>A map with i18n locales. See section <a href="#Localization">Localization</a> for more information.</td>
</tr>

<tr>
<td>longSelectPressTime</td>
<td>number</td>
<td><code>251</code></td>
<td>
The minimal press time in ms for an event to be considered a (long) press.
</td>
</tr>

<tr>
<td>moment</td>
<td>function</td>
Expand Down
11 changes: 8 additions & 3 deletions lib/timeline/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ class Core {
const fields = [
'width', 'height', 'minHeight', 'maxHeight', 'autoResize',
'start', 'end', 'clickToUse', 'dataAttributes', 'hiddenDates',
'locale', 'locales', 'moment', 'preferZoom', 'rtl', 'zoomKey', 'horizontalScroll', 'verticalScroll'
'locale', 'locales', 'moment', 'preferZoom', 'rtl', 'zoomKey',
'horizontalScroll', 'verticalScroll', 'longSelectPressTime'
];
util.selectiveExtend(fields, this.options, options);

util.selectiveExtend(fields, this.options, options);
this.dom.rollingModeBtn.style.visibility = 'hidden';

if (this.options.rtl) {
Expand Down Expand Up @@ -1050,6 +1050,11 @@ class Core {
direction: contentsOverflow ? Hammer.DIRECTION_ALL : Hammer.DIRECTION_HORIZONTAL
});

// set the long press time
this.hammer.get('press').set({
time: this.options.longSelectPressTime
});

// redraw all components
this.components.forEach(component => {
resized = component.redraw() || resized;
Expand Down
1 change: 1 addition & 0 deletions lib/timeline/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class Timeline extends Core {
const me = this;
this.defaultOptions = {
autoResize: true,
longSelectPressTime: 251,
orientation: {
axis: 'bottom', // axis orientation: 'bottom', 'top', or 'both'
item: 'bottom' // not relevant
Expand Down
5 changes: 4 additions & 1 deletion lib/timeline/component/ItemSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ItemSet extends Component {

selectable: true,
multiselect: false,
longSelectPressTime: 251,
itemsAlwaysDraggable: {
item: false,
range: false,
Expand Down Expand Up @@ -392,7 +393,7 @@ class ItemSet extends Component {
// copy all options that we know
const fields = [
'type', 'rtl', 'align', 'order', 'stack', 'stackSubgroups', 'selectable', 'multiselect', 'sequentialSelection',
'multiselectPerGroup', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'visibleFrameTemplate',
'multiselectPerGroup', 'longSelectPressTime', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'visibleFrameTemplate',
'hide', 'snap', 'groupOrderSwap', 'showTooltips', 'tooltip', 'tooltipOnItemUpdateTime', 'groupHeightMode', 'onTimeout'
];
util.selectiveExtend(fields, this.options, options);
Expand Down Expand Up @@ -870,6 +871,8 @@ class ItemSet extends Component {
this.dom.axis.style.left = '0';
}

this.hammer.get('press').set({time: this.options.longSelectPressTime});

this.initialItemSetDrawn = true;
// check if this component is resized
resized = this._isResized() || resized;
Expand Down
2 changes: 2 additions & 0 deletions lib/timeline/optionsTimeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ let allOptions = {
__any__: {any},
__type__: {object}
},
longSelectPressTime: {number},
margin: {
axis: {number},
item: {
Expand Down Expand Up @@ -235,6 +236,7 @@ let configureOptions = {
height: '',
//hiddenDates: {object, array},
locale: '',
longSelectPressTime: 251,
margin: {
axis: [20, 0, 100, 1],
item: {
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export interface TimelineOptions {
itemsAlwaysDraggable?: TimelineOptionsItemsAlwaysDraggableType;
locale?: string;
locales?: any; // TODO
longSelectPressTime?: number,
moment?: MomentConstructor;
margin?: TimelineOptionsMarginType;
max?: DateType;
Expand Down

0 comments on commit dad6123

Please sign in to comment.