@ -168,20 +168,18 @@ Timeline.prototype.setGroups = function(groups) {
/ * *
/ * *
* Set selected items by their id . Replaces the current selection
* Set selected items by their id . Replaces the current selection
* Unknown id ' s are silently ignored .
* Unknown id ' s are silently ignored .
* @ param { Array } [ ids ] An array with zero or more id ' s of the items to be
* selected . If ids is an empty array , all items will be
* unselected .
* @ param { Object } [ options ] Available options :
* ` focus: boolean ` If true , focus will be set
* to the selected item ( s )
* @ param { string [ ] | string } [ ids ] An array with zero or more id ' s of the items to be
* selected . If ids is an empty array , all items will be
* unselected .
* @ param { Object } [ options ] Available options :
* ` focus: boolean ` If true , focus will be set
* to the selected item ( s )
* /
* /
Timeline . prototype . setSelection = function ( ids , options ) {
Timeline . prototype . setSelection = function ( ids , options ) {
this . itemSet && this . itemSet . setSelection ( ids ) ;
this . itemSet && this . itemSet . setSelection ( ids ) ;
if ( ids && options ) {
if ( options . focus ) {
this . focus ( ids ) ;
}
if ( options && options . focus ) {
this . focus ( ids ) ;
}
}
} ;
} ;
@ -199,27 +197,24 @@ Timeline.prototype.getSelection = function() {
* @ param { String | String [ ] } id An item id or array with item ids
* @ param { String | String [ ] } id An item id or array with item ids
* /
* /
Timeline . prototype . focus = function ( id ) {
Timeline . prototype . focus = function ( id ) {
if ( ! this . itemsData ) return ;
if ( ! this . itemsData || id == undefined ) return ;
var ids = Array . isArray ( id ) ? id : [ id ] ;
// get the specified item(s)
// get the specified item(s)
var itemsData = this . itemsData . getDataSet ( ) . get ( id , {
var itemsData = this . itemsData . getDataSet ( ) . get ( ids , {
type : {
type : {
start : 'Date' ,
start : 'Date' ,
end : 'Date'
end : 'Date'
}
}
} ) ;
} ) ;
// turn into an array in case of a single item
if ( ! Array . isArray ( itemsData ) ) {
itemsData = [ itemsData ] ;
}
// calculate minimum start and maximum end of specified items
// calculate minimum start and maximum end of specified items
var start = null ;
var start = null ;
var end = null ;
var end = null ;
itemsData . forEach ( function ( itemData ) {
itemsData . forEach ( function ( itemData ) {
var s = itemData . start . valueOf ( ) ;
var s = itemData . start . valueOf ( ) ;
var e = 'end' in itemData ? itemData . end . valueOf ( ) : itemData . start . valueOf ( ) ;
var e = 'end' in itemData ? itemData . end . valueOf ( ) : itemData . start . valueOf ( ) ;
if ( start === null || s < start ) {
if ( start === null || s < start ) {
start = s ;
start = s ;