define([], function() { function CallToAction(dispatcher, height, width, message, ctaImage, effectDuration, visibility, ctaImageID, ctaLeft, ctaTop) { // constructor // private variables this._dispatcher = dispatcher; this._height = height; this._width = width; this._message = message; this._ctaImage = ctaImage; this._effectDuration = effectDuration; this._visibility = visibility; this._ctaImageID = ctaImageID; this._ctaLeft = ctaLeft; this._ctaTop = ctaTop; this._ctaTrigger = "zoomin.zoombehavior"; this._state = null; this._viewerID = ''; // privileged functions // private functions this.bindCallToActionEvents = function () { if ( this._visibility == 'showOnLoad' ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID).bind("mouseover", RICHFX.jQuery.proxy(function(event){ // Note // This looks ridiculous as a piece of code but is required to handle the difference between // Zoom and Rotate states for the rotation viewer // The mouseover has to be on the _dispatcher but can't be un-bound as it will break everything else // This is the only usuable course when trying to mix 'showOnLoad' in one state and 'Show Always' on the other if (this._visibility != 'showAlways') { RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').fadeOut("slow"); } }, this)); RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID).bind("touchstart", RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').fadeOut("slow"); }, this)); //RICHFX.jQuery('#' + this._dispatcher.id + '_cta').show(); } else if ( this._visibility == 'showOnMouseover') { RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID).bind("mouseover", RICHFX.jQuery.proxy(function(event){ this.handleShowOnMouseover(); }, this)); } else if ( this._visibility == 'showOnInitialZoom') { RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID).bind("assetstate.zoom.changed", RICHFX.jQuery.proxy(function(event){ this.handleZoomChange(); }, this)); } if ( this._ctaTrigger != "" ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').unbind("click"); RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').unbind("touchstart"); if ( Modernizr.touch ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').bind("touchstart", RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID).trigger(this._ctaTrigger); return false; }, this)); } else { RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').bind("click", RICHFX.jQuery.proxy(function(event){ console.log('Fired _ctaTrigger: ' + this._ctaTrigger); RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID).trigger(this._ctaTrigger); return false; }, this)); } } return false; }; this.handleShowOnMouseover = function(event){ RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID).unbind("mouseover"); RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID).bind("mouseout", RICHFX.jQuery.proxy(function(event){ this.handleHideOnMouseout();}, this)); RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').fadeIn("slow").delay(2000).fadeOut(2000); return false; }; this.handleHideOnMouseout = function(event){ RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID).unbind("mouseout"); RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID).bind("mouseover", RICHFX.jQuery.proxy(function(event){ this.handleShowOnMouseover();}, this)); return false; }; this.handleZoomChange = function(event){ var zoomLevel = this._state.getZoomLevel(); if ( zoomLevel == 0 ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').show(); } else { RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').hide(); } return false; }; }; CallToAction.prototype = { // variables //functions callToActionInit:function(){ }, callToActionReady:function(){ this.bindCallToActionEvents(); }, setMessageText: function(message) { if ( this._ctaImageID == "" ) { var contents = ''; this._message = message; if ( this._message != '' ) { contents = '
 ' + this._message; } RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').html(contents); } }, setVisibility: function(setting) { this._visibility = setting; }, setCustomCTA: function(imageID, top, left, trigger) { if ( this._visibility == "showOnLoad" || this._visibility == "showOnInitialZoom" || this._visibility == "showAlways" ) { this._ctaImageID = imageID; this._ctaLeft = left; this._ctaTop = top; this._ctaTrigger = trigger; var contents = ''; if ( this._message != '' ) { contents = '
 ' + this._message; } var posTop = ((this._height/2) - 25); var posLeft = ((this._width/2) - 60); if ( this._ctaImageID != "" ) { var imgSrc = RICHFX.settings.sImageServiceURL + '?profileid='+RICHFX.settings.sProfileID+'&'+this._ctaImageID; imgSrc = RICHFX.media.buildRequiredUrl(imgSrc); contents = ''; posTop = ((this._height * this._ctaTop)/100); posLeft = ((this._width * this._ctaLeft)/100); } RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').html(contents); RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').css('display', 'block'); RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').css('z-index', 26050); RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').css('top', posTop +'px'); RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID + '_cta').css('left', posLeft +'px'); this.bindCallToActionEvents(); } }, setState: function(assetState, viewerID) { this._state = assetState; this._viewerID = viewerID; var display = 'none'; if ( this._visibility == 'showOnLoad' || this._visibility == "showOnInitialZoom" || this._visibility == "showAlways" ) { display = 'block'; } var contents = ''; if ( this._message != '' ) { contents = '
 ' + this._message; } var posTop = ((this._height/2) - 25); var posLeft = ((this._width/2) - 60); var style = "background-color:#EEEEEE; opacity: 0.6;"; if ( this._ctaImageID != "" ) { var imgSrc = RICHFX.settings.sImageServiceURL + '?profileid='+RICHFX.settings.sProfileID+'&'+this._ctaImageID; imgSrc = RICHFX.media.buildRequiredUrl(imgSrc); contents = ''; posTop = ((this._height * this._ctaTop)/100); posLeft = ((this._width * this._ctaLeft)/100); style = "z-index: 26050"; } this._cta = RICHFX.jQuery('#RICHFXViewerContainer_'+this._viewerID).append('
' + contents + '
'); } }; return CallToAction; });