@ -1,5 +1,7 @@
var Hammer = require ( '../../../module/hammer' ) ;
var util = require ( '../../../util' ) ;
var moment = require ( '../../../module/moment' ) ;
/ * *
* @ constructor Item
@ -16,8 +18,7 @@ function Item (data, conversion, options) {
this . data = data ;
this . dom = null ;
this . conversion = conversion || { } ;
this . options = options || { } ;
this . options = options || { } ;
this . selected = false ;
this . displayed = false ;
this . dirty = true ;
@ -179,6 +180,89 @@ Item.prototype._repaintDeleteButton = function (anchor) {
}
} ;
/ * *
* Repaint a onChange tooltip on the top right of the item when the item is selected
* @ param { HTMLElement } anchor
* @ protected
* /
Item . prototype . _repaintOnItemUpdateTimeTooltip = function ( anchor ) {
if ( ! this . options . tooltipOnItemUpdateTime ) return ;
var editable = ( this . options . editable . updateTime ||
this . data . editable === true ) &&
this . data . editable !== false ;
if ( this . selected && editable && ! this . dom . onItemUpdateTimeTooltip ) {
// create and show tooltip
var me = this ;
var onItemUpdateTimeTooltip = document . createElement ( 'div' ) ;
onItemUpdateTimeTooltip . className = 'vis-onUpdateTime-tooltip' ;
anchor . appendChild ( onItemUpdateTimeTooltip ) ;
this . dom . onItemUpdateTimeTooltip = onItemUpdateTimeTooltip ;
} else if ( ! this . selected && this . dom . onItemUpdateTimeTooltip ) {
// remove button
if ( this . dom . onItemUpdateTimeTooltip . parentNode ) {
this . dom . onItemUpdateTimeTooltip . parentNode . removeChild ( this . dom . onItemUpdateTimeTooltip ) ;
}
this . dom . onItemUpdateTimeTooltip = null ;
}
// position onChange tooltip
if ( this . dom . onItemUpdateTimeTooltip ) {
// only show when editing
this . dom . onItemUpdateTimeTooltip . style . visibility = this . parent . itemSet . touchParams . itemIsDragging ? 'visible' : 'hidden' ;
// position relative to item's content
if ( this . options . rtl ) {
this . dom . onItemUpdateTimeTooltip . style . right = this . dom . content . style . right ;
} else {
this . dom . onItemUpdateTimeTooltip . style . left = this . dom . content . style . left ;
}
// position above or below the item depending on the item's position in the window
var tooltipOffset = 50 ; // TODO: should be tooltip height (depends on template)
var scrollTop = this . parent . itemSet . body . domProps . scrollTop ;
// TODO: this.top for orientation:true is actually the items distance from the bottom...
// (should be this.bottom)
var itemDistanceFromTop
if ( this . options . orientation . item == 'top' ) {
itemDistanceFromTop = this . top ;
} else {
itemDistanceFromTop = ( this . parent . height - this . top - this . height )
}
var isCloseToTop = itemDistanceFromTop + this . parent . top - tooltipOffset < - scrollTop ;
if ( isCloseToTop ) {
this . dom . onItemUpdateTimeTooltip . style . bottom = "" ;
this . dom . onItemUpdateTimeTooltip . style . top = this . height + 2 + "px" ;
} else {
this . dom . onItemUpdateTimeTooltip . style . top = "" ;
this . dom . onItemUpdateTimeTooltip . style . bottom = this . height + 2 + "px" ;
}
// handle tooltip content
var content ;
var templateFunction ;
if ( this . options . tooltipOnItemUpdateTime && this . options . tooltipOnItemUpdateTime . template ) {
templateFunction = this . options . tooltipOnItemUpdateTime . template . bind ( this ) ;
content = templateFunction ( this . data ) ;
} else {
content = 'start: ' + moment ( this . data . start ) . format ( 'MM/DD/YYYY hh:mm' ) ;
if ( this . data . end ) {
content += '<br> end: ' + moment ( this . data . end ) . format ( 'MM/DD/YYYY hh:mm' ) ;
}
}
this . dom . onItemUpdateTimeTooltip . innerHTML = content ;
}
} ;
/ * *
* Set HTML contents for the item
* @ param { Element } element HTML element to fill with the contents