EventDetailBox = Class.create( Module, {
source: [ 'event_detail_box_source', { inside: true, removeParent: true } ]
});
EventInfo = Class.create( Module, {
source: [ 'info_item', { removeParent: true } ],
unique_ids: [ 'info_item', 'info_item_link' ],
initialize: function ( $super, ei_display, item_info ) {
$super();
this.ei_display = ei_display;
this.content = new InfoContent( ei_display, item_info.resize_images );
this.$('info_item_link').innerHTML = item_info.tab_text;
this.visited = false;
this.expand_on_select = item_info.expand_on_select || "never";
this.webtrend = item_info.webtrend;
this.enable();
},
enable: function() {
this.$('info_item').className = "infoModule-item";
this.event_handler = this.select_item.bind( this );
Event.observe( this.$('info_item'), 'click', this.event_handler );
if (this.webtrend) {
Event.observe( this.$('info_item'), 'click', function() {
dcsMultiTrack( 'DCS.dcsuri', this.webtrend, "WT.ti", this.webtrend );
}.bind(this));
}
},
disable: function() {
this.$('info_item').className = "infoModule-item-disabled";
Event.stopObserving( this.$('info_item'), 'click' );
delete this.event_handler;
},
is_disabled: function() {
if ( this.event_handler )
return false;
return true;
},
select_item: function() {
if( !this.is_selected && this.event_handler ) {
for ( var i = 0 ; i < this.ei_display.items.length ; i ++ ) {
var item = this.ei_display.items[i];
if ( item != this ) {
if ( item.event_handler )
item.$('info_item').className = "infoModule-item";
else
item.$('info_item').className = "infoModule-item-disabled";
item.is_selected = false;
}
}
this.ei_display.save_state( this );
var is_expanded = new CookieTree( '_E', this.ei_display.event_id, 'ei' ).get( this.item_index );
this.$('info_item').className="highlight-border infoModule-item-on highlight";
this.is_selected = true;
this.content.make_active();
if( this.expand_on_select == "always" ||
( ( typeof(is_expanded) == 'undefined' || is_expanded ) && this.expand_on_select == "first" && !this.visited ) )
this.expand_content();
else
this.collapse_content();
this.visited = true;
}
},
expand_content: function() {
this.ei_display.expand_content();
},
collapse_content: function() {
this.ei_display.collapse_content();
}
});
InfoHeading = Class.create( Module, {
source: [ 'info_heading', { removeParent: true } ],
unique_ids: [ 'info_heading', 'info_heading_text' ],
initialize: function( $super, heading ) {
$super();
this.$('info_heading_text').innerHTML = heading;
}
} );
InfoContentText = Class.create( Module, {
source: [ 'info_content_text', { removeParent: true } ],
unique_ids: [ 'info_content_text' ],
initialize: function( $super, content ) {
$super();
this.$('info_content_text').innerHTML = content;
}
} );
ExpandableInfo = Class.create( Module, {
source: [ 'expandable_info', { removeParent: true } ],
unique_ids: [ 'expandable_info', 'expandos_link', 'expandos_heading', 'expandos_text' ],
initialize: function( $super, heading, content, link_text, link_url, info_content ) {
$super();
this.info_content = info_content;
this.$('expandable_info').style.display = "";
this.$('expandos_heading').innerHTML = heading;
var temp = new Element("div").update(content);
if (link_url) {
temp.insert("<br/><br/>");
temp.insert(new Element('a', { href: link_url, 'target': '_blank' }).update(link_text + "&nbsp;&raquo"));
}
this.$('expandos_text').update( temp );
Event.observe( this.$('expandos_link'), 'click', this.toggle.bind( this ) );
this.collapse();
},
toggle: function () {
if( this.$('expandos_link').className == 'expandosLink' ) {
this.expand();
}
else {
this.collapse();
}
},
expand: function() {
this.$('expandos_link').className = 'expandosLink-open';
this.$('expandos_text').className = 'expandos-open';
if (this.info_content)
this.info_content.content_display.expand_content();
},
collapse: function() {
this.$('expandos_link').className = 'expandosLink';
this.$('expandos_text').className = 'expandos-closed';
if (this.info_content)
this.info_content.content_display.collapse_display();
}
} );
InfoContent = Class.create( Module, {
source: [ 'info_content', { removeParent: true } ],
unique_ids: [ 'info_content' ],
initialize: function ( $super, content_display, resize_images ) {
$super();
this.content_display = content_display;
this.expands = [];
this.resize_images = resize_images;
},
_resize_images: function( el ) {
el = el ? el : this.$('info_content');
if ( el.nodeName.toUpperCase() == 'IMG' ) {
var image_width = Element.getWidth( el );
var content_width = Element.getWidth( this.$('info_content') );
if ( image_width > content_width ) {
var new_width = content_width;
var new_height = Math.floor( (image_width / content_width) * Element.getHeight( el ) );
el.style.width = new_width + "px";
el.style.height = new_height + "px";
}
}
else {
if ( el.hasChildNodes() ) {
for ( var i = 0 ; i < el.childNodes.length ; i ++ ) {
this._resize_images( el.childNodes[i] );
}
}
}
},
make_active: function() {
this.content_display.set_content( this );
if ( this.resize_images )
this._resize_images();
},
add_heading: function( heading ) {
new InfoHeading( heading ).attach( this.id( 'info_content' ) );
},
add_expandable: function( heading, content, link_text, link_url ) {
var info = new ExpandableInfo( heading, content, link_text, link_url, this );
info.attach( this.id( 'info_content' ) );
this.expands.push( info );
},
add_content: function( content ) {
new InfoContentText( content ).attach( this.id( 'info_content' ) );
},
expand_all: function() {
for( var i = 0 ; i < this.expands.length ; i ++ ) {
this.expands[i].expand();
}
},
collapse_all: function() {
for( var i = 0 ; i < this.expands.length ; i ++ ) {
this.expands[i].collapse();
}
}
} );
EventInfoDisplay = Class.create( Module, {
source: [ 'event_info_module', { removeParent: true } ],
unique_ids: [ 'event_info_module', 'event_info_content', 'event_info_frame', 'event_info_item_list', 'moreLink', 'lessLink', 'viewLinks', 'info_content_body' ],
initialize: function ( $super, data ) {
$super();
this.event_id = data.event_id;
this.$('event_info_content').style.display = "";
Event.observe( this.$('moreLink'), 'click', this.expand_content.bind( this ) );
Event.observe( this.$('lessLink'), 'click', this.collapse_content.bind( this ) );
this.items = [];
},
attach: function( $super, element ) {
$super( element );
this.set_content( this.current_content );
},
add_item: function( item_info ) {
var item = new EventInfo( this, item_info );
item.attach( this.id('event_info_item_list') );
this.items.push( item );
this.$('event_info_module').style.height = this.get_height() + "px";
item.item_index = this.items.length;
return item;
},
set_content: function( info_content ) {
if( this.current_content )
this.current_content.detach();
this.current_content = info_content;
this.current_content.collapse_all();
this.current_content.attach( this.id('info_content_body') );
this.$('event_info_module').style.height = this.get_height() + "px";
this.update_view_link();
this.$('event_info_module').hide().show();
},
update_view_link: function() {
this.$('lessLink').style.display = "none";
this.$('viewLinks').style.display = 'none';
this.$('info_content_body').style.height = "auto";
if ( this.current_content ) {
var height = this.get_height() - Element.getHeight( this.$('viewLinks') ) + 2;
if ( Element.getHeight( this.current_content.$('info_content') ) > height ) {
if ( this.is_expanded ) {
this.$('event_info_frame').style.height = "auto";
this.$('lessLink').style.display = "";
}
else {
this.$('event_info_frame').style.height = height + "px";
this.$('viewLinks').style.display = '';
this.$('info_content_body').style.height = height + "px";
}
}
else
this.$('event_info_frame').style.height = height + "px";
}
if ( this.current_item ) {
cookie = new CookieTree( '_E', this.event_id, 'ei' ).set( this.current_item.item_index, (this.is_expanded ? 1 : 0) );
EventState.touch( this.event_id );
}
this.$('info_content_body').hide().show();
},
save_state: function ( item ) {
cookie = new CookieTree( '_E', this.event_id, 'ei' ).set( 'i', item.item_index );
EventState.touch( this.event_id );
this.current_item = item;
},
select_first: function ( item_list ) {
var saved_state = new CookieTree( '_E', this.event_id ).get( 'ei' );
if ( $H(saved_state).keys().length ) {
var is_expanded = saved_state[saved_state.i];
this.current_item = this.items[saved_state.i-1];
if ( !this.current_item.is_disabled() ) {
this.current_item.select_item();
if ( typeof(is_expanded) != 'undefined' ) {
if ( is_expanded )
this.current_item.expand_content();
else
this.current_item.collapse_content();
}
return;
}
}
for ( var i = 0 ; i < item_list.length ; i ++ ) {
if ( !item_list[i].is_disabled() ) {
this.current_item = item_list[i];
item_list[i].select_item();
return;
}
}
},
get_height: function() {
return Element.getHeight( this.$('event_info_item_list') );
},
expand_content: function() {
this.$('info_content_body').style.overflow = "";
this.is_expanded = true;
this.update_view_link();
},
collapse_content: function() {
if( this.current_content )
this.current_content.collapse_all();
this.is_expanded = false;
this.$('info_content_body').style.overflow = "hidden";
this.update_view_link();
},
collapse_display: function() {
this.$('info_content_body').style.overflow = "hidden";
this.update_view_link();
}
});
