@ -95,6 +95,11 @@ function ItemSet(body, options) {
axis : 20
axis : 20
} ,
} ,
tooltip : {
followMouse : false ,
overflowMethod : 'flip'
} ,
tooltipOnItemUpdateTime : false
tooltipOnItemUpdateTime : false
} ;
} ;
@ -250,6 +255,7 @@ ItemSet.prototype._create = function(){
this . body . dom . centerContainer . addEventListener ( 'mouseover' , this . _onMouseOver . bind ( this ) ) ;
this . body . dom . centerContainer . addEventListener ( 'mouseover' , this . _onMouseOver . bind ( this ) ) ;
this . body . dom . centerContainer . addEventListener ( 'mouseout' , this . _onMouseOut . bind ( this ) ) ;
this . body . dom . centerContainer . addEventListener ( 'mouseout' , this . _onMouseOut . bind ( this ) ) ;
this . body . dom . centerContainer . addEventListener ( 'mousemove' , this . _onMouseMove . bind ( this ) ) ;
// attach to the DOM
// attach to the DOM
this . show ( ) ;
this . show ( ) ;
@ -325,7 +331,7 @@ ItemSet.prototype.setOptions = function(options) {
var fields = [
var fields = [
'type' , 'rtl' , 'align' , 'order' , 'stack' , 'stackSubgroups' , 'selectable' , 'multiselect' , 'itemsAlwaysDraggable' ,
'type' , 'rtl' , 'align' , 'order' , 'stack' , 'stackSubgroups' , 'selectable' , 'multiselect' , 'itemsAlwaysDraggable' ,
'multiselectPerGroup' , 'groupOrder' , 'dataAttributes' , 'template' , 'groupTemplate' , 'visibleFrameTemplate' ,
'multiselectPerGroup' , 'groupOrder' , 'dataAttributes' , 'template' , 'groupTemplate' , 'visibleFrameTemplate' ,
'hide' , 'snap' , 'groupOrderSwap' , 'tooltipOnItemUpdateTime'
'hide' , 'snap' , 'groupOrderSwap' , 'tooltip' , 'tooltip OnItemUpdateTime'
] ;
] ;
util . selectiveExtend ( fields , this . options , options ) ;
util . selectiveExtend ( fields , this . options , options ) ;
@ -869,7 +875,8 @@ ItemSet.prototype.getGroups = function() {
* /
* /
ItemSet . prototype . removeItem = function ( id ) {
ItemSet . prototype . removeItem = function ( id ) {
var item = this . itemsData . get ( id ) ,
var item = this . itemsData . get ( id ) ,
dataset = this . itemsData . getDataSet ( ) ;
dataset = this . itemsData . getDataSet ( ) ,
itemObj = this . items [ id ] ;
if ( item ) {
if ( item ) {
// confirm deletion
// confirm deletion
@ -878,6 +885,12 @@ ItemSet.prototype.removeItem = function(id) {
// remove by id here, it is possible that an item has no id defined
// remove by id here, it is possible that an item has no id defined
// itself, so better not delete by the item itself
// itself, so better not delete by the item itself
dataset . remove ( id ) ;
dataset . remove ( id ) ;
// Remove it's popup
if ( itemObj . popup ) {
itemObj . popup . destroy ( ) ;
itemObj . popup = null ;
}
}
}
} ) ;
} ) ;
}
}
@ -1875,15 +1888,22 @@ ItemSet.prototype._onMouseOver = function (event) {
var item = this . itemFromTarget ( event ) ;
var item = this . itemFromTarget ( event ) ;
if ( ! item ) return ;
if ( ! item ) return ;
// Item we just left
var related = this . itemFromRelatedTarget ( event ) ;
if ( item === related ) {
// We haven't changed item, just element in the item
return ;
}
if ( item . getTitle ( ) ) {
if ( item . getTitle ( ) ) {
if ( item . popup == null ) {
if ( item . popup == null ) {
item . setPopup ( new Popup ( this . body . dom . root ) ) ;
item . setPopup ( new Popup ( this . body . dom . root , this . options . tooltip . overflowMethod || 'flip' ) ) ;
}
}
var container = this . body . dom . centerContainer ;
var container = this . body . dom . centerContainer ;
item . popup . setPosition (
item . popup . setPosition (
event . clientX - util . getAbsoluteLeft ( container ) ,
event . clientY - util . getAbsoluteTop ( container )
event . clientX - util . getAbsoluteLeft ( container ) + container . offsetLeft ,
event . clientY - util . getAbsoluteTop ( container ) + container . offsetTop
) ;
) ;
item . popup . show ( ) ;
item . popup . show ( ) ;
}
}
@ -1897,6 +1917,13 @@ ItemSet.prototype._onMouseOut = function (event) {
var item = this . itemFromTarget ( event ) ;
var item = this . itemFromTarget ( event ) ;
if ( ! item ) return ;
if ( ! item ) return ;
// Item we are going to
var related = this . itemFromRelatedTarget ( event ) ;
if ( item === related ) {
// We aren't changing item, just element in the item
return ;
}
if ( item . popup != null ) {
if ( item . popup != null ) {
item . popup . hide ( ) ;
item . popup . hide ( ) ;
}
}
@ -1906,6 +1933,23 @@ ItemSet.prototype._onMouseOut = function (event) {
event : util . elementsCensor ( event )
event : util . elementsCensor ( event )
} ) ;
} ) ;
} ;
} ;
ItemSet . prototype . _onMouseMove = function ( event ) {
var item = this . itemFromTarget ( event ) ;
if ( ! item ) return ;
if ( this . options . tooltip . followMouse ) {
if ( item . popup ) {
if ( ! item . popup . hidden ) {
var container = this . body . dom . centerContainer ;
item . popup . setPosition (
event . clientX - util . getAbsoluteLeft ( container ) + container . offsetLeft ,
event . clientY - util . getAbsoluteTop ( container ) + container . offsetTop
) ;
item . popup . show ( ) ; // Redraw
}
}
}
} ;
/ * *
/ * *
@ -2118,6 +2162,24 @@ ItemSet._getItemRange = function(itemsData) {
}
}
} ;
} ;
/ * *
* Find an item from an element :
* searches for the attribute 'timeline-item' in the element ' s tree
* @ param { HTMLElement } element
* @ return { Item | null } item
* /
ItemSet . prototype . itemFromElement = function ( element ) {
var cur = element ;
while ( cur ) {
if ( cur . hasOwnProperty ( 'timeline-item' ) ) {
return cur [ 'timeline-item' ] ;
}
cur = cur . parentNode ;
}
return null ;
} ;
/ * *
/ * *
* Find an item from an event target :
* Find an item from an event target :
* searches for the attribute 'timeline-item' in the event target ' s element tree
* searches for the attribute 'timeline-item' in the event target ' s element tree
@ -2125,15 +2187,17 @@ ItemSet._getItemRange = function(itemsData) {
* @ return { Item | null } item
* @ return { Item | null } item
* /
* /
ItemSet . prototype . itemFromTarget = function ( event ) {
ItemSet . prototype . itemFromTarget = function ( event ) {
var target = event . target ;
while ( target ) {
if ( target . hasOwnProperty ( 'timeline-item' ) ) {
return target [ 'timeline-item' ] ;
}
target = target . parentNode ;
}
return this . itemFromElement ( event . target ) ;
} ;
return null ;
/ * *
* Find an item from an event ' s related target :
* searches for the attribute 'timeline-item' in the related target ' s element tree
* @ param { Event } event
* @ return { Item | null } item
* /
ItemSet . prototype . itemFromRelatedTarget = function ( event ) {
return this . itemFromElement ( event . relatedTarget ) ;
} ;
} ;
/ * *
/ * *