SeatMapAd = Class.create( Module, {
tlog: TMDebug.gen_tlog( 'isc-seatmap-ad' ),
initialize: function( $super, options ) {
$super( 'isc_seat_map_ad_1' );
this.options = Object.extend( {
show_hide_duration: 1,
toggle_duration: 0.7,
show_delay: options.isc.data.widget_ad_delay
}, options );
var e_cookie = new CookieTree( '_E' );
if ( e_cookie.get ( 'wad' ) == this.options.isc.edp.event.event_id ) {
return;
}
else {
e_cookie.remove( 'wad' );
}
this.call_ad();
},
call_ad: function() {
false;
click_track.log_datapoint( { ism_widget_ad_call:'' } );
this.sajax_call = new Sajax( this.options.ad_tag, this.load_ad.bind( this ) );
},
load_ad: function( sajax, data ) {
false;
if ( data.do_not_show )
return;
this.options = Object.extend( this.options, data );
if ( this.options.suppress_close_link ) {
this.$('close').hide();
}
this.load_images();
},
load_images: function() {
this.images = [];
this.image_handlers = [];
this.image_loaders = [];
this.load_image( this.options.images[0] );
this.load_image( this.options.images[1] );
},
load_image: function( url ) {
var image = new Image();
this.image_loaders.push( image );
var handler = this.on_image_ready.bind( this, image );
this.image_handlers.push( handler );
Event.observe( image, 'load', handler );
image.src = url;
},
on_image_ready: function( image ) {
false;
this.images.push( image );
false;
if ( this.images.length == 2 ) {
for ( var i = 0 ; i < this.image_loaders.length ; i ++ ) {
Event.stopObserving( this.image_loaders[i], 'load', this.image_handlers[i] );
}
var area0 = this.images[0].width * this.images[0].height;
var area1 = this.images[1].width * this.images[1].height;
if ( area0 > area1 ) {
this.images.push( this.images.shift() );
}
else if ( area0 == area1 ) {
this.images = this.image_loaders;
}
this.$('small_image').appendChild( this.images[0] );
this.$('large_image').appendChild( this.images[1] );
this.images_ready = true;
false;
Event.observe( this.$('small_ad'), 'click', this.on_expand.bind( this ) );
Event.observe( this.$('less'), 'click', this.on_collapse.bind( this ) );
Event.observe( this.$('close'), 'click', this.on_close.bind( this ) );
if ( Object.isString( this.options.url ) && this.options.url.length > 0 ) {
Event.observe( this.$('large_ad'), 'click', this.on_select.bind( this ) );
}
if ( this.setup_already_called ) {
this.prepare_to_show();
}
}
},
setup: function() {
false;
if ( !this.setup_already_called ) {
this.setup_polygon_selection_event();
this.setup_seat_selection_event();
this.setup_already_called = true;
this.prepare_to_show();
}
},
setup_polygon_selection_event: function() {
false;
this.polygon_selection_handler = this.on_polygon_select.bind( this );
Event.observe( this.options.isc.seat_map.conf.isc_div, this.options.isc.seat_map.conf.namespace + ':polygon_selection', this.polygon_selection_handler );
},
cancel_polygon_selection_event: function() {
false;
if ( this.polygon_selection_handler ) {
Event.stopObserving( this.options.isc.seat_map.conf.isc_div, this.options.isc.seat_map.conf.namespace + ':polygon_selection', this.polygon_selection_handler );
delete this.polygon_selection_handler;
}
},
setup_seat_selection_event: function() {
false;
this.seat_selection_handler = this.on_seat_selection.bind( this );
Event.observe( this.options.isc.seat_map.conf.isc_div, this.options.isc.seat_map.conf.namespace + ':seat_selection', this.seat_selection_handler );
},
cancel_seat_selection_event: function() {
false;
if ( this.seat_selection_handler ) {
Event.stopObserving( this.options.isc.seat_map.conf.isc_div, this.options.isc.seat_map.conf.namespace + ':polygon_selection', this.seat_selection_handler );
delete this.seat_selection_handler;
}
},
on_polygon_select: function() {
false;
if ( this.seat_view_visited ) {
this.cancel_polygon_selection_event();
this.cancel_seat_selection_event();
this.polygon_selection_made = false;
}
else {
this.polygon_selection_made = true;
this.seat_view_visited = true;
this.prepare_to_show();
}
},
on_seat_selection: function( event ) {
false;
var selection = this.options.isc.cart.get_selection_for_seat( event.memo );
if ( selection && this.polygon_selection_made ) {
if ( selection.is_ga ) {
false;
this.cancel_show();
this.seat_view_visited = false;
}
else {
this.cancel_polygon_selection_event();
this.cancel_seat_selection_event();
}
this.polygon_selection_made = false;
}
},
prepare_to_show: function() {
false;
if ( this.images_ready &&
!this.show_delay_timeout &&
(this.options.show_immediately || this.polygon_selection_made) ) {
false;
this.show_delay_timeout = window.setTimeout( this.show.bind( this ), this.options.show_delay * 1000 );
}
},
cancel_show: function() {
false;
window.clearTimeout( this.show_delay_timeout );
delete this.show_delay_timeout;
},
show: function( $super ) {
false;
this.cancel_show();
if ( this.options.show_immediately || this.seat_view_visited ) {
this.cancel_polygon_selection_event();
this.cancel_seat_selection_event();
this.active_ad = this.$('small_ad');
this.$('large_ad').hide();
this.$('small_ad').hide();
this.$('isc_seat_map_ad').show();
this._fade_in( this.$('small_ad'), this.options.show_hide_duration );
Effect.BlindDown( this.$('small_ad'), {
duration: this.options.show_hide_duration
} );
click_track.log_datapoint( { ism_widget_ad_shown:'' } );
}
},
hide: function() {
false;
this._fade_out( this.active_ad, this.options.show_hide_duration );
Effect.BlindUp( this.active_ad, {
duration: this.options.show_hide_duration
} );
new CookieTree( '_E' ).set ( 'wad', this.options.isc.edp.event.event_id );
},
_fade_out: function( target, duration ) {
Effect.Fade( target, {
duration: duration,
from: 1.0,
to: 0.0
} );
},
_fade_in: function( target, duration ) {
Effect.Fade( target, {
duration: duration,
from: 0.0,
to: 1.0
} );
},
toggle: function( old_ad, new_ad ) {
false;
this._fade_out( old_ad, this.options.toggle_duration );
Element.setOpacity( new_ad, 0.0 );
new_ad.show();
this._fade_in( new_ad, this.options.toggle_duration );
this.active_ad = new_ad;
},
on_close: function( event ) {
false;
this.hide();
click_track.log_datapoint( { ism_widget_ad_close:'' } );
Event.stop( event );
},
on_expand: function( event ) {
false;
this.toggle( this.$('small_ad'), this.$('large_ad') );
click_track.log_datapoint( { ism_widget_ad_expand:'' } );
Event.stop( event );
},
on_collapse: function( event ) {
false;
this.toggle( this.$('large_ad'), this.$('small_ad') );
click_track.log_datapoint( { ism_widget_ad_collapse:'' } );
Event.stop( event );
},
on_select: function() {
false;
click_track.log_datapoint( { ism_widget_ad_link:'' } );
window.open( this.options.url );
}
} );

