var ImageColorChange = function(){ }; ImageColorChange.prototype = { oSettings: {}, oUnPackedSettings: {}, iVWidth: 0, iVHeight: 0, oHeroElement: null, sElementID: '', sViewerID: '', unPackedViewerID: '', sMediaID: '', sName: 'ImageColorChange', sViewsID: 'RICHFXViews', sSwatchesID: 'RICHFXSwatches', //Keep track of the current view - view can be set through the Hero, config and XMT sCurrentView: null, sCurrentSwatch: null, sCurrentSwatchInternalName: null, sCurrentSwatchExternalName: null, sHeroView: null, sHeroSwatch: null, sCurrFocusedElement: '', sLastFocusedElement: '', sPreviousView: null, sDefaultView: null, // Use the XMT ordering for the views/swatches bUseDefaultOrdering: false, oZoomInfo: {}, swatchList: {}, oSwatchImages: {}, oSwatchViews: {}, viewImages: {}, sBindingEvent: 'click', sSwatchBindingEvent: 'click', sAltViewBindingEvent: 'click', //aAvailableSwatches: [], sAvailableSwatches: "", bSingleAltView: false, oPreviousData: {}, sBindingCallback: null, oViewOrder: {}, oSwatchOrder: {}, sExternalSwatchControl: undefined, sExternalViewControl: undefined, sExternalSwatchControlAttr: undefined, sExternalViewControlAttr: undefined, sTooltip: false, iSwatchTooltipTopPosition: 0, iSwatchTooltipLeftPosition: 0, iViewTooltipTopPosition: 0, iViewTooltipLeftPosition: 0, sSwatchLabelID: "RICHFXSwatchLabel", sSwatchFunctionName: null, oCycleEffect: {}, sRemoteMediaURL: "", bDefaultToPrimaryView: false, sNewAltView: undefined, sLoadingType: RICHFX.oOpts.oLoading.type, iLoadingDistance: RICHFX.oOpts.oLoading.distance, bReadyToInitialize: false, bInitialized: false, oPXmlSwatchOrder: [], oPXmlViewOrder: [], sOriginalView: "", sHeroSwatchID: "", sHeroViewID: "", iZIndex: 20000, sRfxCcGroup: "", sRfxCcSwatch: "", sRfxCcView: "", bRotationSettings: false, bUseRotationOverlay: false, sRotationViewName: '360', sRotationOverlayImgMetadata: '', bRotationViewLast: true, bFoundRotationView: false, bAltViewsVertical: true, bVideoSettings: false, bUseVideoOverlay: false, sVideoViewName: 'video', sVideoOverlayImgMetadata: '', bVideoViewLast: true, bShowVideoforAllSwatches: true, bExternalVideoShow: false, bTriggerVideo: false, bFoundVideoView: false, bFlipToAltView: false, bSlideAltView: false, bFadeAltView: false, bSwatchEventFired: false, bViewEventFired: false, touchStartX: null, touchStartY: null, bSetupNextPrevImages: false, bShowPrevNextImages: false, sPrevImageID: '', sNextImageID: '', iPrevPercLeft: 5, iPrevPercTop: 70, iNextPercLeft: 90, iNextPercTop: 70, currentViewPos: 0, prevNextTransiton: false, bAllowSelectionOfAltView: true, bUseAltViewIndicators: false, sIndicatorMetadataActive: '', sIndicatorMetadataInActive: '', bFloatVideoView: false, sVideoImageID: '', iVideoPercLeft: 85, iVideoPercTop: 85, bFloatRotationView: false, sRotateImageID: '', iRotatePercLeft: 85, iRotatePercTop: 85, sEffectAltView: '', sSingleAltTransition: '', hasBadgingRecipe: false, badgingRecipeId: 0, badgingRecipeName: '', bShowAltViewAltText: true, bShowSwatchAltText: true, bShowSingleSwatchDiv: true, bShowSingleAltViewDiv: true, bIgnoreDefaultFlag: false, iAltViewHeight: 0, iAltViewWidth: 0, iInitialisedCount: 0, // Add Slider Settings bUseSlider: false, oSliderSettings: {}, sliderIDs: [], bSliderVertical: false, sSliderSkin: "rfx1", iSliderStart: 1, iSliderScroll: 1, sSliderAnimation: "fast", sSliderEasing: "linear", iSliderAuto: 0, sSliderWrap: null, sSliderButtonPrevEvent: 'click', sSliderButtonNextEvent: 'click', sSliderNextImageMetadata: '', sSliderPrevImageMetadata: '', SliderControlImageWidth: 32, SliderControlImageHeight: 32, SliderItemWidth: 65, SliderItemHeight: 65, SliderApplyTo: [], sSliderName: 'imageSlider', bSliderIsDependent: false, sSliderViewerID: '', sSliderElementID: '', oSliderSliders: {}, iSliderMinImages: 0, SliderEmbedStarted: false, iSliderScriptsRequestTime: 0, // sImageServiceURL: RICHFX.settings.sImageServiceURL + '?profileid='+RICHFX.settings.sProfileID+'&', init: function(oSettings) { //console.log('imageCC recieved settings: ', oSettings); // unpack Settings Object //this._unpackSettings(oSettings); // Setup variables etc... //this.oSettings = RICHFX.jQuery.extend(true, {}, this.oUnPackedSettings); //var unPackedSettings = RICHFX.settings.unpackViewerSettings(oSettings); this.oSettings = RICHFX.settings.unpackViewerSettings(oSettings); // + RICHFX.settings.viewerSettings[unPackedViewerID].element.id + '|' //console.log('imageCC element: ' + unPackedSettings.element.id + '|' + this.oSettings.element.id +'|', this.oSettings.element); // Avoid empty lookups if ( this.oSettings.element.id == '' ) return; this.oHeroElement = RICHFX.jQuery('#'+this.oSettings.element.id); this.sElementID = this.oSettings.element.id; // Keep the width and height because we remove the element from the page if we are injecting on top of an image this.iVWidth = RICHFX.jQuery(this.oHeroElement).width(); this.iVHeight = RICHFX.jQuery(this.oHeroElement).height(); this.sViewerID = this.oSettings.element.__richfx_id; // Added fpr Proximity work .. needs review for registerViewer viewerID is not set /* //console.log('Checking for viewer: ' + this.sElementID + '|' + this.sName + '|' + this.sViewerID); if ( RICHFX.controller.aLoadedComponents[this.sElementID] != undefined && RICHFX.controller.aLoadedComponents[this.sElementID][this.sName] != undefined && RICHFX.controller.aLoadedComponents[this.sElementID][this.sName] == this.sViewerID ) { //console.log('Already Loaded - exiting!'); return; } else if ( RICHFX.media.aRegViewers[this.sElementID] != undefined && RICHFX.media.aRegViewers[this.sElementID][this.sViewerID+'_imageColorChange'] != undefined ) { //console.log('Already Registered - exiting!'); return; } else { console.log('ImageColorChange registerViewer: ' + this.sElementID + '|' + this.sViewerID); RICHFX.controller.registerViewer('imageColorChange', this.sElementID); RICHFX.controller.register(this.sViewerID, this.oHeroElement, this.sName); } */ if (this.oSettings.viewsID !== undefined) { this.sViewsID = this.oSettings.viewsID; } if (this.oSettings.swatchesID !== undefined) { this.sSwatchesID = this.oSettings.swatchesID; } if (this.oSettings.defaultView !== undefined && this.oSettings.defaultView !== "null") { this.sCurrentView = this.oSettings.defaultView; this.sDefaultView = this.oSettings.defaultView; } if (this.oSettings.defaultSwatch !== undefined && this.oSettings.defaultSwatch !== "null") { this.sCurrentSwatch = this.oSettings.defaultSwatch; this.sCurrentSwatchInternalName = this.oSettings.defaultSwatch; this.sCurrentSwatchExternalName = this.oSettings.defaultSwatch; } if (this.oSettings.availableSwatches !== undefined && this.oSettings.availableSwatches !== "null") { this.sAvailableSwatches = this.oSettings.availableSwatches; } if (this.oSettings.singleAltView !== undefined && this.oSettings.singleAltView !== "null") { this.bSingleAltView = this.oSettings.singleAltView; } if (this.oSettings.externalSwatchControl !== undefined && this.oSettings.externalSwatchControl !== "null") { this.sExternalSwatchControl = this.oSettings.externalSwatchControl; } if (this.oSettings.externalSwatchControlAttribute !== undefined && this.oSettings.externalSwatchControlAttribute !== "null") { this.sExternalSwatchControlAttr = this.oSettings.externalSwatchControlAttribute; } if (this.oSettings.externalViewControl !== undefined && this.oSettings.externalViewControl !== "null") { this.sExternalViewControl = this.oSettings.externalViewControl; } if (this.oSettings.externalViewControlAttribute !== undefined && this.oSettings.externalViewControlAttribute !== "null") { this.sExternalViewControlAttr = this.oSettings.externalViewControlAttribute; } if (this.oSettings.swatchTooltipTopPosition !== undefined && this.oSettings.swatchTooltipTopPosition !== "null") { this.iSwatchTooltipTopPosition = this.oSettings.swatchTooltipTopPosition; } if (this.oSettings.swatchTooltipLeftPosition !== undefined && this.oSettings.swatchTooltipLeftPosition !== "null") { this.iSwatchTooltipLeftPosition = this.oSettings.swatchTooltipLeftPosition; } if (this.oSettings.viewTooltipTopPosition !== undefined && this.oSettings.viewTooltipTopPosition !== "null") { this.iViewTooltipTopPosition = this.oSettings.viewTooltipTopPosition; } if (this.oSettings.viewTooltipLeftPosition !== undefined && this.oSettings.viewTooltipLeftPosition !== "null") { this.iViewTooltipLeftPosition = this.oSettings.viewTooltipLeftPosition; } if (this.oSettings.tooltip !== undefined && this.oSettings.tooltip !== "null") { this.sTooltip = this.oSettings.tooltip; } if (this.oSettings.swatchLabelID !== undefined && this.oSettings.swatchLabelID !== "null") { this.sSwatchLabelID = this.oSettings.swatchLabelID; } if (this.oSettings.swatchFunctionName !== undefined && this.oSettings.swatchFunctionName !== "null") { this.sSwatchFunctionName = this.oSettings.swatchFunctionName; } if ( this.oSettings.defaultToPrimaryView !== undefined && this.oSettings.defaultToPrimaryView !== "null") { this.bDefaultToPrimaryView = this.oSettings.defaultToPrimaryView; } if ( this.oSettings.ignoreDefaultFlag !== undefined && this.oSettings.ignoreDefaultFlag !== "null") { this.bIgnoreDefaultFlag = this.oSettings.ignoreDefaultFlag; } if (this.oSettings.cycleEffect !== undefined && this.oSettings.cycleEffect !== "null") { this.oCycleEffect.effect = this.oSettings.cycleEffect; } if (this.oCycleEffect.effect === "fade") { RICHFX.settings.bFadeEnabled = true; } if (this.oSettings.speedIn !== undefined && this.oSettings.speedIn !== "null") { this.oCycleEffect.speedIn = this.oSettings.speedIn; } else { this.oCycleEffect.speedIn = "slow"; } if (this.oSettings.speedOut !== undefined && this.oSettings.speedOut !== "null") { this.oCycleEffect.speedOut = this.oSettings.speedOut; } else { this.oCycleEffect.speedOut = "slow"; } if (this.oSettings.changeEvent !== undefined && this.oSettings.changeEvent !== "null") { this.sBindingEvent = this.oSettings.changeEvent; if ( this.sBindingEvent == 'hover' ) { RICHFX.settings.bFadeEnabled = false; } } if (this.oSettings.swatchChangeEvent !== undefined && this.oSettings.swatchChangeEvent !== "null") { this.sSwatchBindingEvent = this.oSettings.swatchChangeEvent; if ( this.sSwatchBindingEvent == 'hover' ) { RICHFX.settings.bFadeEnabled = false; } } if (this.oSettings.altViewChangeEvent !== undefined && this.oSettings.altViewChangeEvent !== "null") { this.sAltViewBindingEvent = this.oSettings.altViewChangeEvent; if ( this.sAltViewBindingEvent == 'hover' ) { RICHFX.settings.bFadeEnabled = false; } } // Reset the default view/swatch so we force the viewer to sort by the XMT if (this.oSettings.useDefaultOrdering !== undefined && this.oSettings.useDefaultOrdering !== "null") { this.bUseDefaultOrdering = this.oSettings.useDefaultOrdering; if (this.bUseDefaultOrdering == true) { this.sCurrentView = false; this.sCurrentSwatch = false; this.sCurrentSwatchInternalName = false; this.sCurrentSwatchExternalName = false; } } if ( this.oSettings.zIndexLimit !== undefined && this.oSettings.zIndexLimit !== "null" ) { this.iZIndex = this.oSettings.zIndexLimit; } if (this.oSettings.loadingType !== undefined && this.oSettings.loadingType !== "null") { this.sLoadingType = this.oSettings.loadingType; } if (this.oSettings.loadingDistance !== undefined && this.oSettings.loadingDistance !== "null") { this.iLoadingDistance = this.oSettings.loadingDistance; if ( RICHFX.load.proximitySettings != undefined ) { RICHFX.load.proximitySettings.distance = this.iLoadingDistance; } } if (this.oSettings.useRotationOverlay !== undefined && this.oSettings.useRotationOverlay !== "null") { this.bUseRotationOverlay = this.oSettings.useRotationOverlay; } if (this.oSettings.rotationViewName !== undefined && this.oSettings.rotationViewName !== "null") { this.sRotationViewName = this.oSettings.rotationViewName; this.bRotationSettings = true; } if (this.oSettings.rotationOverlayImgMetadata !== undefined && this.oSettings.rotationOverlayImgMetadata !== "null") { this.sRotationOverlayImgMetadata = this.oSettings.rotationOverlayImgMetadata; } if (this.oSettings.rotationViewLast !== undefined && this.oSettings.rotationViewLast !== "null") { this.bRotationViewLast = this.oSettings.rotationViewLast; } if (this.oSettings.showAltViewsVertically !== undefined && this.oSettings.showAltViewsVertically !== "null") { this.bAltViewsVertical = this.oSettings.showAltViewsVertically; } if (this.oSettings.useVideoOverlay !== undefined && this.oSettings.useVideoOverlay !== "null") { this.bUseVideoOverlay = this.oSettings.useVideoOverlay; } if (this.oSettings.videoViewName !== undefined && this.oSettings.videoViewName !== "null") { this.sVideoViewName = this.oSettings.videoViewName; this.bVideoSettings = true; } if (this.oSettings.videoOverlayImgMetadata !== undefined && this.oSettings.videoOverlayImgMetadata !== "null") { this.sVideoOverlayImgMetadata = this.oSettings.videoOverlayImgMetadata; } if (this.oSettings.videoViewLast !== undefined && this.oSettings.videoViewLast !== "null") { this.bVideoViewLast = this.oSettings.videoViewLast; } if (this.oSettings.alwaysShowVideo !== undefined && this.oSettings.alwaysShowVideo !== "null") { this.bShowVideoforAllSwatches = this.oSettings.alwaysShowVideo; } if (this.oSettings.setupPrevNextImages !== undefined && this.oSettings.setupPrevNextImages !== "null") { this.bSetupNextPrevImages = this.oSettings.setupPrevNextImages; } if (this.oSettings.showPrevNextImages !== undefined && this.oSettings.showPrevNextImages !== "null") { this.bShowPrevNextImages = this.oSettings.showPrevNextImages; } if (this.oSettings.prevImageMetadata !== undefined && this.oSettings.prevImageMetadata !== "null") { this.sPrevImageID = this.oSettings.prevImageMetadata; } if (this.oSettings.nextImageMetadata !== undefined && this.oSettings.nextImageMetadata !== "null") { this.sNextImageID = this.oSettings.nextImageMetadata; } if (this.oSettings.prevImagePercLeft !== undefined && this.oSettings.prevImagePercLeft !== "null") { this.iPrevPercLeft = this.oSettings.prevImagePercLeft; } if (this.oSettings.prevImagePercTop !== undefined && this.oSettings.prevImagePercTop !== "null") { this.iPrevPercTop = this.oSettings.prevImagePercTop; } if (this.oSettings.nextImagePercLeft !== undefined && this.oSettings.nextImagePercLeft !== "null") { this.iNextPercLeft = this.oSettings.nextImagePercLeft; } if (this.oSettings.nextImagePercTop !== undefined && this.oSettings.nextImagePercTop !== "null") { this.iNextPercTop = this.oSettings.nextImagePercTop; } if (this.oSettings.floatVideoImage !== undefined && this.oSettings.floatVideoImage !== "null") { this.bFloatVideoView = this.oSettings.floatVideoImage; } if (this.oSettings.floatVideoImageMetadata !== undefined && this.oSettings.floatVideoImageMetadata !== "null") { this.sVideoImageID = this.oSettings.floatVideoImageMetadata; } if (this.oSettings.floatVideoPercTop !== undefined && this.oSettings.floatVideoPercTop !== "null") { this.iVideoPercTop = this.oSettings.floatVideoPercTop; } if (this.oSettings.floatVideoPercLeft !== undefined && this.oSettings.floatVideoPercLeft !== "null") { this.iVideoPercLeft = this.oSettings.floatVideoPercLeft; } if (this.oSettings.floatRotationImage !== undefined && this.oSettings.floatRotationImage !== "null") { this.bFloatRotationView = this.oSettings.floatRotationImage; } if (this.oSettings.floatRotationImageMetadata !== undefined && this.oSettings.floatRotationImageMetadata !== "null") { this.sRotateImageID = this.oSettings.floatRotationImageMetadata; } if (this.oSettings.floatRotationPercTop !== undefined && this.oSettings.floatRotationPercTop !== "null") { this.iRotatePercTop = this.oSettings.floatRotationPercTop; } if (this.oSettings.floatRotationPercLeft !== undefined && this.oSettings.floatRotationPercLeft !== "null") { this.iRotatePercLeft = this.oSettings.floatRotationPercLeft; } if (this.oSettings.allowSelectionOfAltView !== undefined && this.oSettings.allowSelectionOfAltView !== "null") { this.bAllowSelectionOfAltView = this.oSettings.allowSelectionOfAltView; } if (this.oSettings.useAltViewIndicatorImages !== undefined && this.oSettings.useAltViewIndicatorImages !== "null") { this.bUseAltViewIndicators = this.oSettings.useAltViewIndicatorImages } if (this.oSettings.indicatorMetadataActive !== undefined && this.oSettings.indicatorMetadataActive !== "null") { this.sIndicatorMetadataActive = this.oSettings.indicatorMetadataActive; } if (this.oSettings.indicatorMetadataInActive !== undefined && this.oSettings.indicatorMetadataInActive !== "null") { this.sIndicatorMetadataInActive = this.oSettings.indicatorMetadataInActive; } if (this.oSettings.showAltViewAltText !== undefined && this.oSettings.showAltViewAltText !== "null") { this.bShowAltViewAltText = this.oSettings.showAltViewAltText; } if (this.oSettings.showSwatchAltText !== undefined && this.oSettings.showSwatchAltText !== "null") { this.bShowSwatchAltText = this.oSettings.showSwatchAltText; } if (this.oSettings.showSingleSwatchDiv !== undefined && this.oSettings.showSingleSwatchDiv !== "null") { this.bShowSingleSwatchDiv = this.oSettings.showSingleSwatchDiv; } if (this.oSettings.showSingleAltViewDiv !== undefined && this.oSettings.showSingleAltViewDiv !== "null") { this.bShowSingleAltViewDiv = this.oSettings.showSingleAltViewDiv; } if (this.oSettings.singleAltTransition !== undefined && this.oSettings.singleAltTransition !== "null") { this.sSingleAltTransition = this.oSettings.singleAltTransition; } if (this.oSettings.transitionAltName !== undefined && this.oSettings.transitionAltName !== "null") { this.sEffectAltView = this.oSettings.transitionAltName; } if (this.oSettings.singleAltViewID !== undefined && this.oSettings.singleAltViewID !== "null") { this.sEffectAltView = this.oSettings.singleAltViewID; } if ( this.sSingleAltTransition != '' ) { if ( this.sSingleAltTransition == 'flip' ) { this.bFlipToAltView = true; } else if ( this.sSingleAltTransition == 'slide' ) { this.bSlideAltView = true; } else if ( this.sSingleAltTransition == 'fade' ) { this.bFadeAltView = true; } } // tmp for testing //this.bSlideAltView = true; // Initialise Slider settings if (this.oSettings.useSlider !== undefined && this.oSettings.useSlider !== "null") { if ( this.oSettings.useSlider == true ) { this.bUseSlider = true; } } // tmp //this.bUseSlider = false; if ( oSettings.ImageColorChangeSliderSettings !== undefined && oSettings.ImageColorChangeSliderSettings !== "null" ) { this.oSliderSettings = oSettings.ImageColorChangeSliderSettings; } /* if (this.oSettings.sliderSettings !== undefined && this.oSettings.sliderSettings !== "null") { this.oSliderSettings = this.oSettings.sliderSettings; } */ if (this.oSliderSettings.vertical !== undefined && this.oSliderSettings.vertical !== "null") { this.bSliderVertical = this.oSliderSettings.vertical; } if (this.oSliderSettings.skin !== undefined && this.oSliderSettings.skin !== "null") { this.sSliderSkin = this.oSliderSettings.skin; } if (this.oSliderSettings.start !== undefined && this.oSliderSettings.start !== "null") { this.iSliderStart = this.oSliderSettings.start; } if (this.oSliderSettings.scroll !== undefined && this.oSliderSettings.scroll !== "null") { this.iSliderScroll = this.oSliderSettings.scroll; } if (this.oSliderSettings.animation !== undefined && this.oSliderSettings.animation !== "null") { this.sSliderAnimation = this.oSliderSettings.animation; } if (this.oSliderSettings.easing !== undefined && this.oSliderSettings.easing !== "null") { this.sSliderEasing = this.oSliderSettings.easing; } if (this.oSliderSettings.auto !== undefined && this.oSliderSettings.auto !== "null") { this.iSliderAuto = this.oSliderSettings.auto; } if (this.oSliderSettings.wrap !== undefined && this.oSliderSettings.wrap !== "null") { this.sSliderWrap = this.oSliderSettings.wrap; } if (this.oSliderSettings.buttonPrevEvent !== undefined && this.oSliderSettings.buttonPrevEvent !== "null") { this.sSliderButtonPrevEvent = this.oSliderSettings.buttonPrevEvent; } if (this.oSliderSettings.buttonNextEvent !== undefined && this.oSliderSettings.buttonNextEvent !== "null") { this.sSliderButtonNextEvent = this.oSliderSettings.buttonNextEvent; } if (this.oSliderSettings.applyTo !== undefined && this.oSliderSettings.applyTo !== "null") { var applyToDiv = this.oSliderSettings.applyTo; if ( applyToDiv == "rfxccswatches" ) { applyToDiv = RICHFX.jQuery(this.oSliderSettings.element).attr('rfxCcSwatches'); } else if ( applyToDiv == "rfxccviews" ) { applyToDiv = RICHFX.jQuery(this.oSliderSettings.element).attr('rfxCcViews'); } //applyToDiv = '632586_productSwatches'; //applyToDiv = '631585_productSwatches'; this.SliderApplyTo[this.SliderApplyTo.length] = applyToDiv; } if (this.oSliderSettings.isDependent !== undefined && this.oSliderSettings.isDependent !== "null") { this.bSliderIsDependent = this.oSliderSettings.isDependent; } if (this.oSliderSettings.prevImageMetadata !== undefined && this.oSliderSettings.prevImageMetadata !== "null") { this.sSliderPrevImageMetadata = this.oSliderSettings.prevImageMetadata; } if (this.oSliderSettings.nextImageMetadata !== undefined && this.oSliderSettings.nextImageMetadata !== "null") { this.sSliderNextImageMetadata = this.oSliderSettings.nextImageMetadata; } if (this.oSliderSettings.minImageCount !== undefined && this.oSliderSettings.minImageCount !== "null") { this.iSliderMinImages = this.oSliderSettings.minImageCount; } if (this.oSliderSettings.controlImageWidth !== undefined && this.oSliderSettings.controlImageWidth !== "null") { this.SliderControlImageWidth = this.oSliderSettings.controlImageWidth; } if (this.oSliderSettings.controlImageHeight !== undefined && this.oSliderSettings.controlImageHeight !== "null") { this.SliderControlImageHeight = this.oSliderSettings.controlImageHeight; } if (this.oSliderSettings.itemWidth !== undefined && this.oSliderSettings.itemWidth !== "null") { this.SliderItemWidth = this.oSliderSettings.itemWidth; } if (this.oSliderSettings.itemHeight !== undefined && this.oSliderSettings.itemHeight !== "null") { this.SliderItemHeight = this.oSliderSettings.itemHeight; } // // // Check for badging recipe id and save it // var heroSrc = RICHFX.jQuery(this.oHeroElement).attr('src'); if ( heroSrc != undefined && heroSrc.indexOf('adgeRecipeId=') != -1 ) { this.hasBadgingRecipe = true; var badgeParts = heroSrc.split('adgeRecipeId='); // remove 'b' from the start in case of capitalization badgeParts = badgeParts[1].split('&'); this.badgingRecipeId = badgeParts[0]; } if ( heroSrc != undefined && heroSrc.indexOf('adgeRecipeName=') != -1 ) { this.hasBadgingRecipe = true; var badgeParts = heroSrc.split('adgeRecipeName='); // remove 'b' from the start in case of capitalization badgeParts = badgeParts[1].split('&'); this.badgingRecipeName = badgeParts[0]; } //console.log('setting sCurrentSwatchInternalName to ' + this.sCurrentSwatchInternalName); if ( this.sCurrentSwatchInternalName == null ) { this.sCurrentSwatchInternalName = false; } RICHFX.settings.sCurrentSwatch = this.sCurrentSwatchInternalName; RICHFX.settings.sCurrentView = this.sCurrentView; this.register(); this.require(); }, require: function() { // Check if we need to add the imageSlider dependencies, load as necessary and attach to the body RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName).css('visibility', 'hidden'); this._listenForAttachedComponents(true); if (this.bUseSlider) { // Load files required by slider RICHFX.helpers.getCSS(RICHFX.settings.sJsDepsUrl + "skins/"+this.sSliderSkin+"/imageSlider.css"); // TODO: Need to read in the client CSS so that it over-rides the default RICHFX.helpers.getScripts([RICHFX.settings.sJsDepsUrl + "jquery.jcarousel.js", RICHFX.settings.sJsDepsUrl + "jquery.easing.1.3.js"], RICHFX.jQuery.proxy(function(){ //console.log('(1) triggering carousel.dependencies.loaded: ' + this.sElementID); RICHFX.helpers.triggeredEvents['carousel.dependencies.loaded'] = this.sElementID; RICHFX.jQuery('#'+this.sElementID).trigger('carousel.dependencies.loaded'); }, this)); /* // TODO: Write a component load method that can load any viewer dependently RICHFX.helpers.getScripts([RICHFX.settings.sJsDepsUrl + "richfx.imageSlider.js"], RICHFX.jQuery.proxy(function(){ this.oSliderSettings.element = RICHFX.jQuery(this.oHeroElement); // Combine the settings for the viewer - settings can be supplied on a viewer basis (multiple imageEnlarges with the same settings for example) //RICHFX.jQuery.extend(this.oSliderSettings, this.oSliderSettings, RICHFX.settings.oComponents['imageSlider']); RICHFX.jQuery.extend(true, this.oSliderSettings, RICHFX.settings.oComponents['imageSlider']); // tmp - Force dependence this.oSliderSettings.isDependent = true; console.log('altView Dimensions: ' + this.iAltViewWidth + '|' + this.iAltViewHeight); this.oSliderSettings.itemWidth = this.iAltViewWidth; this.oSliderSettings.itemHeight = this.iAltViewHeight; var viewers = []; if ( this.sViewerID != undefined ) { RICHFX.media.aAttachedComponents[this.sViewerID].push('imageSlider'); //this.oSliderSettings.elementID = RICHFX.helpers.getElementId(this.oSliderSettings.element); this.oSliderSettings.elementID = this.sElementID; this.sliderIDs[this.sElementID] = this.sElementID; RICHFX.jQuery(this.oSliderSettings.element).data('data', {id: this.oSliderSettings.elementID}); //console.log('Calling createViewer from imageCC'); viewers.push(viewerFactory.createViewer('imageSlider', this.oSliderSettings)); RICHFX.jQuery.extend(RICHFX.jQuery('body').data('data'), RICHFX.jQuery('body').data('data', {viewers: viewers})); this._getProductInfo(); } }, this)); */ this._getProductInfo(); //Color Change is not attached to the slider } else { this._getProductInfo(); } }, embed: function() { // Check for the RichFX container, create it if it doesn't exist if (!RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).length ) { var elementHTML = RICHFX.jQuery(this.oHeroElement).parent().html(); var heroEvents = RICHFX.jQuery('#'+this.sElementID).data('events'); RICHFX.jQuery(this.oHeroElement).replaceWith('
'+elementHTML+'
'); this.resyncEvents(heroEvents); } // update 'src' to include badging recipe where needed var ccSrc = RICHFX.jQuery(this.oHeroElement).attr('src'); if ( this.hasBadgingRecipe ) { if ( this.badgingRecipeId != 0 ) { // Ensure that the badgeRecipe detals are not added twice if ( ccSrc.indexOf('badgeRecipeId') == -1 ) { ccSrc += '&badgeRecipeId=' + this.badgingRecipeId; } } else { // Ensure that the badgeRecipe detals are not added twice if ( ccSrc.indexOf('badgeRecipeName') == -1 ) { ccSrc += '&badgeRecipeName=' + this.badgingRecipeName; } } } ccSrc = RICHFX.media.buildRequiredUrl(ccSrc); RICHFX.jQuery('
').appendTo('#RICHFXViewerContainer_'+this.sViewerID); RICHFX.jQuery('').appendTo('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName); this._createControls(); if ( this.bFlipToAltView || this.bSlideAltView || this.bFadeAltView ) { if ( this.oViewOrder[this.sCurrentSwatch][this.sEffectAltView] != undefined ) { //var altView = this.oViewOrder[this.sCurrentSwatch][this.sEffectAltView].largeImage; //var altSrc = RICHFX.jQuery(altView).attr('src'); var altSrc = this.oViewOrder[this.sCurrentSwatch][this.sEffectAltView].largeImagePath; altSrc = RICHFX.media.buildRequiredUrl(altSrc); RICHFX.jQuery('
').appendTo('#RICHFXViewerContainer_'+this.sViewerID); RICHFX.jQuery('').appendTo('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'); } } var altZIndex = RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName).css('z-index'); if ( this.bFlipToAltView ) { // TODO: needs to be moved to a more appropriate file var flipCSS = ""; RICHFX.jQuery(flipCSS).appendTo("head"); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).addClass('flip'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName).addClass('side'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').addClass('side'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').addClass('back'); if(Modernizr != undefined && Modernizr.touch) { var targetImg = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName; var targetAlt = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'; // Swipe Left to show alt view RICHFX.jQuery('#'+targetImg).bind('touchstart', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; this.touchStartX = touch.touches[0].pageX; RICHFX.jQuery('#'+targetImg).bind('touchmove', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; if ( touch.touches[1] == undefined ) { touchEndX = touch.touches[0].pageX; if ( this.touchStartX - touchEndX > 50 ) { var targetImg = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName; RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).addClass('swipe'); RICHFX.jQuery('#'+targetImg).unbind('touchmove'); } } return false; }, this)); return false; }, this)); targetAlt = 'RICHFXViewerContainer_'+this.sViewerID; //targetAlt = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt img'; // Swipe Right to show original view RICHFX.jQuery('#'+targetAlt).parent().bind('touchstart', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; this.touchStartX = touch.touches[0].pageX; //var targetAlt = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'; var targetAlt = 'RICHFXViewerContainer_'+this.sViewerID; RICHFX.jQuery('#'+targetAlt).parent().bind('touchmove', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; if ( touch.touches[1] == undefined ) { touchEndX = touch.touches[0].pageX; if ( touchEndX - this.touchStartX > 50 ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).removeClass('swipe'); RICHFX.jQuery('#'+targetAlt).parent().unbind('touchmove'); } } return false; }, this)); return false; }, this)); } /* else { //var targetImg = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName; //var targetAlt = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'; // Swipe Left to show alt view RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).bind('mouseover', RICHFX.jQuery.proxy(function(event) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).addClass('swipe'); }, this)); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).bind('mouseout', RICHFX.jQuery.proxy(function(event) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).removeClass('swipe'); }, this)); } */ } if ( this.bSlideAltView ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).css('overflow', 'hidden'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').css('left', this.iVWidth); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').css('z-index', (altZIndex + 10)); //RICHFX.jQuery('#logo').html('attaching hammer'); if(Modernizr != undefined && Modernizr.touch) { var targetImg = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName; var targetAlt = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'; // Swipe Left to show alt view RICHFX.jQuery('#'+targetImg).bind('touchstart', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; this.touchStartX = touch.touches[0].pageX; RICHFX.jQuery('#'+targetImg).bind('touchmove', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; if ( touch.touches[1] == undefined ) { touchEndX = touch.touches[0].pageX; if ( this.touchStartX - touchEndX > 50 ) { var targetImg = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName; var targetAlt = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'; RICHFX.jQuery('#'+targetAlt).animate({left: '0px'}, 600); RICHFX.jQuery('#'+targetImg).unbind('touchmove'); } } return false; }, this)); return false; }, this)); // Swipe Right to show original view RICHFX.jQuery('#'+targetAlt).bind('touchstart', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; this.touchStartX = touch.touches[0].pageX; var targetAlt = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'; RICHFX.jQuery('#'+targetAlt).bind('touchmove', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; if ( touch.touches[1] == undefined ) { touchEndX = touch.touches[0].pageX; if ( touchEndX - this.touchStartX > 50 ) { var targetAlt = '#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'; RICHFX.jQuery(targetAlt).animate({left: this.iVWidth+'px'}, 600); RICHFX.jQuery('#'+targetAlt).unbind('touchmove'); } } return false; }, this)); return false; }, this)); } else { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName).bind('mouseover', RICHFX.jQuery.proxy(function(){ RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').animate({left: '0px'}, 600, RICHFX.jQuery.proxy(function(){ // make sure that the mouse is still over the correct viewer RICHFX.jQuery(document).bind('mousemove', RICHFX.jQuery.proxy(function(event){ if ( (event.target.id != this.sViewerID+"_"+this.sName) && (event.target.id != this.sViewerID+"_"+this.sName+'_alt')) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').trigger('mouseout'); } RICHFX.jQuery(document).unbind('mousemove'); return false; }, this)); }, this)); return false; }, this)); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').bind('mouseout', RICHFX.jQuery.proxy(function(){ RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').fadeOut(1200, RICHFX.jQuery.proxy(function(){ RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').css('left', this.iVWidth); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').show(); }, this)); return false; }, this)); } } if ( this.bFadeAltView ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).css('overflow', 'hidden'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').css('left', this.iVWidth); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').css('z-index', (altZIndex + 10)); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').css('opacity', 0); RICHFX.jQuery('#logo').html('checking touch'); if(Modernizr != undefined && Modernizr.touch) { var targetImg = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName; var targetAlt = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'; // Swipe Left to show alt view RICHFX.jQuery('#'+targetImg).bind('touchstart', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; this.touchStartX = touch.touches[0].pageX; RICHFX.jQuery('#'+targetImg).bind('touchmove', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; if ( touch.touches[1] == undefined ) { touchEndX = touch.touches[0].pageX; if ( this.touchStartX - touchEndX > 50 ) { var targetImg = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName; var targetAlt = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'; RICHFX.jQuery('#'+targetAlt).css('left', '0px'); RICHFX.jQuery('#'+targetAlt).animate({opacity: 1}, 600, function(){}); RICHFX.jQuery('#'+targetImg).unbind('touchmove'); } } return false; }, this)); return false; }, this)); // Swipe Right to show original view RICHFX.jQuery('#'+targetAlt).bind('touchstart', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; this.touchStartX = touch.touches[0].pageX; var targetAlt = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'; RICHFX.jQuery('#'+targetAlt).bind('touchmove', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; if ( touch.touches[1] == undefined ) { touchEndX = touch.touches[0].pageX; if ( touchEndX - this.touchStartX > 50 ) { var targetAlt = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'; RICHFX.jQuery('#'+targetAlt).fadeOut(1200, RICHFX.jQuery.proxy(function(){ var targetAlt = 'RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt'; RICHFX.jQuery('#'+targetAlt).css('left', this.iVWidth); RICHFX.jQuery('#'+targetAlt).show(); RICHFX.jQuery('#'+targetAlt).css('opacity', 0); }, this)); RICHFX.jQuery('#'+targetAlt).unbind('touchmove'); } } return false; }, this)); return false; }, this)); } else { // bind mouseover RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName).bind('mouseover', RICHFX.jQuery.proxy(function(){ RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').css('left', '0px'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').animate({opacity: 1}, 600, RICHFX.jQuery.proxy(function(){ // make sure that the mouse is still over the correct viewer RICHFX.jQuery(document).bind('mousemove', RICHFX.jQuery.proxy(function(event){ if ( (event.target.id != this.sViewerID+"_"+this.sName) && (event.target.id != this.sViewerID+"_"+this.sName+'_alt')) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').trigger('mouseout'); } RICHFX.jQuery(document).unbind('mousemove'); return false; }, this)); }, this)); return false; }, this)); // bind mouseout RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').bind('mouseout', RICHFX.jQuery.proxy(function(){ RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').fadeOut(1200, RICHFX.jQuery.proxy(function(){ RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').css('left', this.iVWidth); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').show(); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_alt').css('opacity', 0); }, this)); return false; }, this)); } } this.loadData(); /* //setTimeout(RICHFX.jQuery.proxy(function() { var sliderID = this.sliderIDs[this.sElementID]; //RICHFX.jQuery('#RICHFXViewerContainer_'+sliderID).trigger('carousel.dependencies.loaded'); console.log('(1) Could trigger slider ' + sliderID + '|' + this.bInitialized + '|' + RICHFX.helpers.triggeredEvents['carousel.dependencies.loaded-'+sliderID]); if ( RICHFX.helpers.triggeredEvents["carousel.dependencies.loaded"] == undefined && !this.bInitialized) { console.log('(1) triggering carousel.dependencies.loaded: ' + this.sElementID); RICHFX.helpers.triggeredEvents['carousel.dependencies.loaded'] = this.sElementID; RICHFX.jQuery('#'+this.sElementID).trigger('carousel.dependencies.loaded', [this.iAltViewWidth, this.iAltViewHeight]); } //}, this), 100); */ // BuildSlider //console.log('checking if carousel is ready'); if ( this.bUseSlider ) { if ( RICHFX.helpers.triggeredEvents["carousel.dependencies.loaded"] !== undefined ) { this.addSlider(); } else { // Attach events - this fires when the colorchange has loaded RICHFX.jQuery('#'+this.sElementID).bind('carousel.dependencies.loaded', RICHFX.jQuery.proxy(function(event, itemWidth, itemHeight) { this.addSlider(); }, this)); } } }, resyncEvents: function(heroEvents) { if ( heroEvents ) { for ( var eventType in heroEvents ) { for ( var idx in heroEvents[eventType] ) { var namespace = heroEvents[eventType][idx].namespace; var eventData = heroEvents[eventType][idx].data; var namespaceParts = namespace.split('.'); var bindType = ""; // reverse namespace to get orgininal value for ( var i = (namespaceParts.length - 1); i >= 0; i-- ) { if ( bindType == "" ) { bindType = namespaceParts[i]; } else { bindType = bindType + '.' + namespaceParts[i]; } } bindType = eventType + '.' + bindType; if ( eventData == undefined ) { RICHFX.jQuery('#' + this.sElementID).bind(bindType, heroEvents[eventType][idx].handler); } else { RICHFX.jQuery('#' + this.sElementID).bind(bindType, {data: eventData}, heroEvents[eventType][idx].handler); } } } } }, _unpackSettings: function(oSettings) { this.oUnPackedSettings = {}; // Unpack other objects var settingsClone = RICHFX.jQuery.extend(true, {}, oSettings); //console.log('settingsClone: ', settingsClone); for ( var setting in settingsClone ) { if ( typeof(settingsClone[setting]) == "object" ) { if ( setting == "element" ) { //console.log('element setting: ', settingsClone[setting]); //console.log('element viewerID: ' + settingsClone[setting].__richfx_id); unPackedViewerID = settingsClone[setting].__richfx_id; this.oUnPackedSettings["element"] = settingsClone[setting]; } else { var settingObj = settingsClone[setting]; for ( var subSetting in settingObj ) { this.oUnPackedSettings[subSetting] = settingObj[subSetting]; } } } else { this.oUnPackedSettings[setting] = settingsClone[setting]; } } //this.sViewerID = this.oSettings.element.__richfx_id; RICHFX.settings.viewerSettings[unPackedViewerID] = RICHFX.jQuery.extend(true, {}, this.oUnPackedSettings); }, _createControls: function() { RICHFX.jQuery(document).bind('richmedia.views.created, richmedia.swatches.created', RICHFX.jQuery.proxy(function(event){ // Kick off the ImageSlider - if slider is not linked then nothing listens for this event var sliderID = this.sliderIDs[this.sElementID]; /* if ( RICHFX.helpers.triggeredEvents["carousel.dependencies.loaded"] == undefined ) { RICHFX.helpers.triggeredEvents['carousel.dependencies.loaded'] = this.iAltViewWidth + '|' + this.iAltViewHeight; RICHFX.jQuery('#'+this.sElementID).trigger('carousel.dependencies.loaded', [this.iAltViewWidth, this.iAltViewHeight]); } */ }, this)); // Build Controls this._createViews(); this._createSwatches(); // Add binding functions //Image Color change by itself or with slider if (RICHFX.media.aAttachedComponents[this.sViewerID] != undefined && ((RICHFX.media.aAttachedComponents[this.sViewerID].length == 2 && this.bUseSlider) || RICHFX.media.aAttachedComponents[this.sViewerID].length == 1)) { // If there are no other components attached, then make this the top-most viewer RICHFX.jQuery('#'+this.sViewerID+'_'+this.sName).topZIndex(); this._initialized(); } else { if ( this.bReadyToInitialize ) { this._initialized(); } else { this._listenForAttachedComponents(false); } } // backup event data RICHFXcontainerEvents = RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).data('events'); if ( !this.bInitialized ) { if ( RICHFX.settings.bMissingJsDepsURL) { this._initialized(); } else if ( RICHFX.settings.sJsDepsUrl == undefined || RICHFX.settings.sJsDepsUrl == "undefined" || RICHFX.settings.sJsDepsUrl == "./") { this._initialized(); } } }, _listenForAttachedComponents: function(earlyBind) { if (RICHFX.media.aAttachedComponents) { for (var v in RICHFX.media.aAttachedComponents[this.sViewerID]) { var viewer = RICHFX.media.aAttachedComponents[this.sViewerID][v]; if (viewer !== "imageColorChange") { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName).css('visibility', 'hidden'); if ( earlyBind ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).bind(viewer+'.initialized', RICHFX.jQuery.proxy(function(event){ //RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName).css('visibility', 'hidden'); this.iInitialisedCount++; var checkadjustment = 1; if ( this.bUseSlider ) { checkadjustment = 2; } if ( this.iInitialisedCount == (RICHFX.media.aAttachedComponents[this.sViewerID].length - checkadjustment) ) { this.bReadyToInitialize = true; } }, this)); } else { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).bind(viewer+'.initialized', RICHFX.jQuery.proxy(function(event){ //RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName).css('visibility', 'hidden'); this.iInitialisedCount++; var checkadjustment = 1; if ( this.bUseSlider ) { checkadjustment = 2; } if ( this.iInitialisedCount == (RICHFX.media.aAttachedComponents[this.sViewerID].length - checkadjustment) ) { this._initialized(); } }, this)); } } } } }, // This is only used to initially show views - the views can be updated by the call to createSwatches _createViews: function() { // Output the views - first check if the relevant views ID exists if ( this.sViewsID == "RICHFXViews" ) { var rfxCcViews = RICHFX.jQuery(this.oHeroElement).attr('rfxCcViews'); if ( rfxCcViews != null && rfxCcViews != undefined && rfxCcViews.length > 0 ) { this.sViewsID = rfxCcViews; } else { return; } } if ( this.bShowSingleAltViewDiv || (!this.bShowSingleAltViewDiv && this.oPXmlViewOrder.length > 1) ) { if ( this.sViewsID != "null" && !RICHFX.jQuery('#'+this.sViewsID).attr('id')) { // Add new overlay container if (!RICHFX.jQuery('#RICHFXViewerOverlayContainer_'+this.sViewerID).length ) { var containerPos = RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).offset(); RICHFX.jQuery('
').appendTo('#RICHFXViewerContainer_'+this.sViewerID); } RICHFX.jQuery('
').appendTo('#RICHFXViewerOverlayContainer_'+this.sViewerID); RICHFX.settings.bColorChangeOverlayEnabled = true; } } if ( this.bUseSlider ) { //RICHFX.jQuery('#'+this.oSliderSettings.applyTo).css('opacity', '0'); //RICHFX.jQuery('#'+this.oSliderSettings.applyTo).css('position', 'absolute'); //RICHFX.jQuery('#'+this.oSliderSettings.applyTo).css('float', 'left'); } }, _createSwatches: function() { // verify SwatchesID before creating any relevant div if ( this.sSwatchesID == "RICHFXSwatches" ) { var rfxCcSwatches = RICHFX.jQuery(this.oHeroElement).attr('rfxCcSwatches'); if ( rfxCcSwatches != null && rfxCcSwatches != undefined && rfxCcSwatches.length > 0 ) { this.sSwatchesID = rfxCcSwatches; } else { return; } } // Output the swatches for the default view - default view can be passed in or we just take the first view if (!this.sCurrentView && this.bUseDefaultOrdering) { this.sCurrentView = RICHFX.helpers.getKey(this.oSwatchImages); } if ( this.bShowSingleSwatchDiv || (!this.bShowSingleSwatchDiv && this.oPXmlSwatchOrder.length > 1) ) { if ( this.sSwatchesID != "null" && !RICHFX.jQuery('#'+this.sSwatchesID).attr('id')) { // positioning var swatchLeft = 0; var swatchTop = this.iVHeight - 25; if (!RICHFX.jQuery('#RICHFXViewerOverlayContainer_'+this.sViewerID).length ) { var containerPos = RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).offset(); RICHFX.jQuery('
').insertAfter('#RICHFXViewerContainer_'+this.sViewerID); } RICHFX.jQuery('
').appendTo('#RICHFXViewerOverlayContainer_'+this.sViewerID); RICHFX.settings.bColorChangeOverlayEnabled = true; } var lastSwatch = null; for ( var swatchIdx in this.oPXmlSwatchOrder ) { var swatchID = this.oPXmlSwatchOrder[swatchIdx]; var sv = this.oSwatchImages[this.sOriginalView][swatchID]; if (sv != undefined && sv.swatchSrc != null && sv.swatchSrc != undefined && sv.swatchSrc != 'undefined' ) { RICHFX.jQuery('#'+this.sSwatchesID).append(sv.swatchImage); lastSwatch = sv; } } } if ( !this.bSwatchEventFired ) { this.bSwatchEventFired = true; RICHFX.jQuery(document).trigger('richmedia.swatches.created'); this._fireNativeTrigger('richmedia.swatches.created'); } }, _initialized: function() { if ( !this.bInitialized ) { // Set the imageColorCHange to initialized this.bInitialized = true; RICHFX.jQuery('#'+this.sViewerID+'_videoOverlay').closest('div').css('display', 'none'); RICHFX.jQuery(document).bind('imageVideo.initialized', RICHFX.jQuery.proxy(function(){ if ( this.bAltViewsVertical ) { RICHFX.jQuery('#'+this.sViewerID+'_videoOverlay').closest('div').css('display', 'block'); } else { RICHFX.jQuery('#'+this.sViewerID+'_videoOverlay').closest('div').css('display', 'inline'); } }, this)); RICHFX.controller.register(this.sViewerID, this.oHeroElement, this.sName); if (this.sExternalSwatchControl !== undefined){ var custSwatchControl = RICHFX.jQuery('#'+this.sExternalSwatchControl); if (custSwatchControl !== undefined ){ custSwatchControl.bind('change', RICHFX.jQuery.proxy(function(event){ this.changeSwatchUsingCustomControl(); }, this)); RICHFX.jQuery('#'+this.sViewerID+'_'+this.sName).bind('change', RICHFX.jQuery.proxy(function(event){ this.changeCustomControlSwatch(); }, this)); } } if (this.sExternalViewControl !== undefined) { var custViewControl = RICHFX.jQuery('#'+this.sExternalViewControl); if (custViewControl !== undefined ){ RICHFX.jQuery(custViewControl).bind('change', RICHFX.jQuery.proxy(function(event){ this.changeViewUsingCustomControl(); }, this)); RICHFX.jQuery('#'+this.sViewerID+'_'+this.sName).bind('change', RICHFX.jQuery.proxy(function(event){ this.changeCustomControlView(); }, this)); } } //Create the Tooltip if (this.sTooltip == 'both' || this.sTooltip == 'swatches' || this.sTooltip == 'views') { this.buildTooltip(); } // Set the initial CSS for the selected views/swatches RICHFX.helpers.addCSSRule('.RICHFXColorChangeView.RICHFXColorChangeViewSelected', 'border: 1px solid #555555; margin: 1px;'); RICHFX.helpers.addCSSRule('.RICHFXColorChangeSwatch.RICHFXColorChangeSwatchSelected', 'border: 1px solid #555555;'); RICHFX.helpers.addCSSRule('.RICHFXColorChangeViewHover', 'border: 1px solid #888888;'); RICHFX.helpers.addCSSRule('.RICHFXColorChangeSwatchHover', 'border: 1px solid #888888;'); RICHFX.helpers.addCSSRule('.RICHFXColorChangeView', 'border: 0 none; padding: 2px; display: inline; margin-left: 5px; margin: 1px;'); RICHFX.helpers.addCSSRule('.RICHFXColorChangeSwatch', 'border: 1px solid #ffffff; padding: 2px;'); //width: 45px; height: 27px; RICHFX.helpers.addCSSRule('.RICHFXColorChangeLink', 'border: 0px;'); RICHFX.helpers.timer('Loaded '+this.sName+':'); if ( this.sHeroViewID != '' && this.sHeroSwatchID != '') { var currSwatch = this.oSwatchImages[this.sHeroViewID][this.sHeroSwatchID]; if ( currSwatch == undefined ) { if ( this.oSwatchImages[this.sHeroViewID] ) { for ( var swatch in this.oSwatchImages[this.sHeroViewID] ) { currSwatch = this.oSwatchImages[this.sHeroViewID][swatch]; this.sHeroSwatchID = swatch; break; } } else { for ( var view in this.oSwatchImages ) { currView = this.oSwatchImages[view]; this.sHeroViewID = view; break; } for ( var swatch in this.oSwatchImages[this.sHeroViewID] ) { currSwatch = this.oSwatchImages[this.sHeroViewID][swatch]; this.sHeroSwatchID = swatch; break; } } } var evt = {'data': currSwatch}; //console.log('current details (1585) : ' + this.sHeroViewID +'|'+ this.sCurrentView +'|'+ this.sHeroSwatchID +'|'+ this.sCurrentSwatch + ' ', currSwatch); if ( !this.bIgnoreDefaultFlag && ( (this.sHeroViewID != this.sCurrentView) || (this.sHeroSwatchID != this.sCurrentSwatch) ) ) { this.changeSwatch(evt); } else { //console.log('setting swatchView (1593): ' + evt.data.swatchData.swatch, this.oViewOrder); var sv = this.oViewOrder[evt.data.swatchData.swatch]; this.manageSwatchBindings(evt); this.manageViewsDiv(sv); this.manageViewBindings(sv, evt); this.manageViewCSS(sv); } //console.log('checking currentSwatch: ' + RICHFX.settings.sCurrentSwatch); if ( RICHFX.settings.sCurrentSwatch == false ) { //console.log('2 setting currentSwatch to ' + currSwatch.swatchData.internalName, currSwatch); RICHFX.settings.sCurrentSwatch = currSwatch.swatchData.internalName; } } //console.log('Checking if video: ' + this.bExternalVideoShow +'|'+ this.sCurrentView +'|'+ this.sVideoViewName); if ( !this.bExternalVideoShow && (this.sCurrentView == this.sVideoViewName) ) { this.bExternalVideoShow = true; //console.log('1621 - Triggering RichMedia.ExternalVideo.Show'); RICHFX.jQuery(document).trigger('RichMedia.ExternalVideo.Show'); this._fireNativeTrigger('RichMedia.ExternalVideo.Show'); document.addEventListener("richmedia.state.loaded", function () { //console.log('1628 - Triggering RichMedia.ExternalVideo.Show'); RICHFX.jQuery(document).trigger('RichMedia.ExternalVideo.Show'); var evt = document.createEvent("CustomEvent"); evt.initCustomEvent('RichMedia.ExternalVideo.Show', true, true, { detail: { 'RMEvent' : 'RichMedia.ExternalVideo.Show' } }); document.dispatchEvent(evt); }); } // fire video events if necessary if ( RICHFX.media.aVideoViewViewers[this.sViewerID] && this.bVideoSettings ) { if ( this.bTriggerVideo ) { //console.log('rfxvideo.show'); RICHFX.jQuery(document).trigger('rfxVideo.show'); } else { RICHFX.jQuery(document).trigger('rfxVideo.quickhide'); } } // If using Overlay swatches or views ensure top Zindex if ( RICHFX.settings.bColorChangeOverlayEnabled ) { var currTop = RICHFX.jQuery.topZIndex(); if ( this.bUseVideoOverlay ) { currTop -= 5; } if (this.sViewsID != "null" && RICHFX.jQuery('#'+this.sViewsID).attr('id')) RICHFX.jQuery('#'+this.sViewsID).css('z-index', currTop); if (this.sSwatchesID != "null" && RICHFX.jQuery('#'+this.sSwatchesID).attr('id')) RICHFX.jQuery('#'+this.sSwatchesID).css('z-index', currTop); if ( RICHFX.jQuery.browser.msie && (RICHFX.jQuery.browser.version < 8)) { RICHFX.helpers.refreshZIndexIE('RICHFXViewerContainer_'+this.sViewerID, 20000); } } // Hide Hero image to allow source change fade to run correctly if ( this.sElementID.indexOf('__richfx_id_') == -1 ) { RICHFX.jQuery('#'+ this.sElementID).attr('style', 'visibility: hidden'); } // Possible call to loadData RICHFX.jQuery(document).bind('rfxVideo.ended', RICHFX.jQuery.proxy(function(){ this.bTriggerVideo = false; var sv = this.oSwatchImages[this.sPreviousView][this.sCurrentSwatch]; this.changeView({"data": sv}); }, this)); RICHFX.jQuery(document).bind('rfxRotate.ended', RICHFX.jQuery.proxy(function(){ var sv = this.oSwatchImages[this.sPreviousView][this.sCurrentSwatch]; this.changeView({"data": sv}); this._showPrevAndNextIndicators(); if ( this.bFloatRotationView ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_rotationImg').show(); } }, this)); RICHFX.jQuery(document).bind('rfxRotate.zoom', RICHFX.jQuery.proxy(function(){ this._showPrevAndNextIndicators(); if ( this.bFloatRotationView ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_rotationImg').show(); } }, this)); this._findCurrentViewPos(); // '#RICHFXViewerContainer_'+this.sViewerID RICHFX.jQuery(document).bind('imageCC.nextImage', RICHFX.jQuery.proxy(function(event, viewerID){ //console.log('Caught nextImage: ' + viewerID + '|' + this.sViewerID); if ( viewerID != this.sViewerID ) return; // get viewName from this.oPXmlViewOrder if ( this.currentViewPos == (this.oPXmlViewOrder.length - 1) ) { this.currentViewPos = 0; } else { this.currentViewPos++; } if ( this.bVideoSettings && this.bFloatVideoView ) { var nextView = this.oPXmlViewOrder[this.currentViewPos]; // avoid the 'video' view if ( nextView == this.sVideoViewName ) { if ( this.currentViewPos == (this.oPXmlViewOrder.length - 1) ) { this.currentViewPos = 0; } else { this.currentViewPos++; } } } if ( this.bRotationSettings && this.bFloatRotationView ) { var nextView = this.oPXmlViewOrder[this.currentViewPos]; // avoid the 'video' view if ( nextView == this.sRotationViewName ) { if ( this.currentViewPos == (this.oPXmlViewOrder.length - 1) ) { this.currentViewPos = 0; } else { this.currentViewPos++; } } } if ( this.bSlideAltView ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr').show(); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_next').animate({left: '0px'}, 600, RICHFX.jQuery.proxy(function(){ var nextView = this.oPXmlViewOrder[this.currentViewPos]; var sv = this.oViewOrder[this.sCurrentSwatch][nextView]; if ( sv == undefined ) { //sv = this.oViewOrder[this.sCurrentSwatch][nextView]; sv = this.oSwatchImages[nextView][this.sHeroSwatchID]; } this.prevNextTransiton = true; //console.log("Calling changeView - 1732 - ", sv); this.changeView({'data': sv}); // setup next set of images when available RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).bind('image.change.complete', RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).unbind('image.change.complete'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_next').hide(); this.prevNextTransiton = false; this._setupPrevAndNextViews(); }, this)); }, this)); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr').animate({left: (0-this.iVWidth)+'px'}, 600, RICHFX.jQuery.proxy(function(){ // All update handled by '_next' animation }, this)); } else { //RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr').show(); //RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_next').css('left', '0px'); //RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr').css('left', (0-this.iVWidth)+'px'); // setup for next images var nextView = this.oPXmlViewOrder[this.currentViewPos]; var sv = this.oViewOrder[this.sCurrentSwatch][nextView]; if ( sv == undefined ) { //sv = this.oViewOrder[this.sCurrentSwatch][nextView]; sv = this.oSwatchImages[nextView][this.sHeroSwatchID]; } this.prevNextTransiton = true; //console.log("Calling changeView - 1766 - ", sv); //console.log("viewCheck: " + this.sCurrentView +"|"+ sv.swatchData.view); if ( this.sCurrentView != sv.swatchData.view ) this.changeView({'data': sv}); // setup next set of images when available RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).bind('image.change.complete', RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).unbind('image.change.complete'); //RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_next').hide(); this.prevNextTransiton = false; this._setupPrevAndNextViews(); }, this)); } }, this)); RICHFX.jQuery(document).bind('imageCC.prevImage', RICHFX.jQuery.proxy(function(event, viewerID){ //console.log('Caught prevImage: ' + viewerID + '|' + this.sViewerID); if ( viewerID != this.sViewerID ) return; // get viewName from this.oPXmlViewOrder if ( this.currentViewPos == 0 ) { this.currentViewPos = (this.oPXmlViewOrder.length - 1); } else { this.currentViewPos--; } if ( this.bVideoSettings && this.bFloatVideoView ) { var prevView = this.oPXmlViewOrder[this.currentViewPos]; // avoid the 'video' view if ( prevView == this.sVideoViewName ) { if ( this.currentViewPos == 0 ) { this.currentViewPos = (this.oPXmlViewOrder.length - 1); } else { this.currentViewPos--; } } } if ( this.bRotationSettings && this.bFloatRotationView ) { var nextView = this.oPXmlViewOrder[this.currentViewPos]; // avoid the 'video' view if ( nextView == this.sRotationViewName ) { if ( this.currentViewPos == 0 ) { this.currentViewPos = (this.oPXmlViewOrder.length - 1); } else { this.currentViewPos--; } } } if ( this.bSlideAltView ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr').show(); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prev').animate({left: '0px'}, 600, RICHFX.jQuery.proxy(function(){ var prevView = this.oPXmlViewOrder[this.currentViewPos]; var sv = this.oViewOrder[this.sCurrentSwatch][prevView]; if ( sv == undefined ) { //sv = this.oViewOrder[this.sCurrentSwatch][prevView]; sv = this.oSwatchImages[prevView][this.sHeroSwatchID]; } this.prevNextTransiton = true; //console.log("Calling changeView - 1841 - ", sv); this.changeView({'data': sv}); // setup next set of images when available RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).bind('image.change.complete', RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).unbind('image.change.complete'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prev').hide(); this.prevNextTransiton = false; this._setupPrevAndNextViews(); }, this)); }, this)); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr').animate({left: this.iVWidth+'px'}, 600, RICHFX.jQuery.proxy(function(){ // All update handled by '_next' animation }, this)); } else { //RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr').show(); //RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prev').css('left', '0px'); //RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr').css('left', this.iVWidth+'px'); var prevView = this.oPXmlViewOrder[this.currentViewPos]; var sv = this.oViewOrder[this.sCurrentSwatch][prevView]; if ( sv == undefined ) { //sv = this.oViewOrder[this.sCurrentSwatch][prevView]; sv = this.oSwatchImages[prevView][this.sHeroSwatchID]; } this.prevNextTransiton = true; //console.log("Calling changeView - 1872 - ", sv); this.changeView({'data': sv}); // setup next set of images when available RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).bind('image.change.complete', RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).unbind('image.change.complete'); //RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prev').hide(); this.prevNextTransiton = false; this._setupPrevAndNextViews(); }, this)); } }, this)); // If colorChange only handle swipe if( Modernizr != undefined && Modernizr.touch && RICHFX.media.aAttachedComponents[this.sViewerID].length == 1 ) { // Swipe Left to show alt view RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).bind('touchstart', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; this.touchStartX = touch.touches[0].pageX; if ( touch.touches[1] == undefined ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).bind('touchmove', RICHFX.jQuery.proxy(function(event) { var touch = event.originalEvent; touchEndX = touch.touches[0].pageX; if ( touch.touches[1] == undefined ) { if ( this.touchStartX - touchEndX > 50 ) { //console.log ('nextImage trigger: ' + this.sViewerID, event); RICHFX.jQuery(document).trigger('imageCC.nextImage', [this.sViewerID]); } if( touchEndX - this.touchStartX > 50 ) { //console.log ('prevImage trigger: ' + this.sViewerID, event); RICHFX.jQuery(document).trigger('imageCC.prevImage', [this.sViewerID]); } } else { // reset touchstartX to negate it this.touchStartX = touchEndX; } return false; }, this)); } }, this)); } // Check if prevNext Images are needed if ( this.bShowPrevNextImages ) { if ( this.oPXmlViewOrder.length == 1 ) { this.bShowPrevNextImages = false; this.bSetupNextPrevImages = false; } } if ( this.bShowPrevNextImages ) { var prevImgSrc = this.sImageServiceURL+this.sPrevImageID; var nextImgSrc = this.sImageServiceURL+this.sNextImageID; prevImgSrc = RICHFX.media.buildRequiredUrl(prevImgSrc); nextImgSrc = RICHFX.media.buildRequiredUrl(nextImgSrc); var prevContents = ''; var nextContents = ''; prevPosTop = ((this.iVHeight * this.iPrevPercTop)/100); prevPosLeft = ((this.iVWidth * this.iPrevPercLeft)/100); nextPosTop = ((this.iVHeight * this.iNextPercTop)/100); nextPosLeft = ((this.iVWidth * this.iNextPercLeft)/100); // Set z-index/ RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).append('
' + prevContents + '
'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).append('
' + nextContents + '
'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_nextImg').bind('click', RICHFX.jQuery.proxy(function(){ //console.log ('nextImage click trigger: ' + this.sViewerID, event); RICHFX.jQuery(document).trigger('imageCC.nextImage', [this.sViewerID]); return false; }, this)); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prevImg').bind('click', RICHFX.jQuery.proxy(function(){ //console.log ('prevImage click trigger: ' + this.sViewerID, event); RICHFX.jQuery(document).trigger('imageCC.prevImage', [this.sViewerID]); return false; }, this)); } //console.log('checking float view: ' + this.bFoundVideoView); if ( this.bFoundVideoView && this.bFloatVideoView ) { var floatImgSrc = this.sImageServiceURL+this.sVideoImageID; floatImgSrc = RICHFX.media.buildRequiredUrl(floatImgSrc); var contents = ''; var videoPosTop = ((this.iVHeight * this.iVideoPercTop)/100); var videoPosLeft = ((this.iVWidth * this.iVideoPercLeft)/100); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).append('
' + contents + '
'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_videoImg').bind('click', RICHFX.jQuery.proxy(function(){ var sv = this.oSwatchImages[this.sVideoViewName][this.sCurrentSwatch]; this.bTriggerVideo = true; //console.log("Calling changeView - 1985 - ", sv); this.changeView({'data': sv}); return false; }, this)); } if ( this.bFoundRotationView && this.bFloatRotationView ) { var floatImgSrc = this.sImageServiceURL+this.sRotateImageID; floatImgSrc = RICHFX.media.buildRequiredUrl(floatImgSrc); var contents = ''; var rotationPosTop = ((this.iVHeight * this.iRotatePercTop)/100); var rotationPosLeft = ((this.iVWidth * this.iRotatePercLeft)/100); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).append('
' + contents + '
'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_rotationImg').bind('click', RICHFX.jQuery.proxy(function(){ var sv = this.oSwatchImages[this.sRotationViewName][this.sCurrentSwatch]; this._hidePrevAndNextIndicators(); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_rotationImg').hide(); //console.log("Calling changeView - 2008 - ", sv); this.changeView({'data': sv}); return false; }, this)); } if ( this.bSetupNextPrevImages ) { this._setupPrevAndNextViews(); } } }, buildTooltip: function() { RICHFX.jQuery('body').append('
'); }, showTooltip: function(data) { // retrieve tooltip node var tt = RICHFX.jQuery('#RICHFXTooltip'); var target = RICHFX.jQuery('#'+data.target); // update text tt.html(target.attr('title')); target.attr('title', ''); var absoluteOffset = target.offset(); var leftPosition = this.iSwatchTooltipLeftPosition; var topPosition = this.iSwatchTooltipTopPosition; if (data.type === "views") { leftPosition = this.iViewTooltipLeftPosition; topPosition = this.iViewTooltipTopPosition; } tt.css('left', parseInt(absoluteOffset.left + leftPosition)+'px'); tt.css('top', parseInt(absoluteOffset.top + topPosition)+'px'); tt.css('visibility', 'visible'); }, hideTooltip: function(data) { RICHFX.jQuery('#'+data.target).attr('title', RICHFX.jQuery('#RICHFXTooltip').html()); RICHFX.jQuery('#RICHFXTooltip').css('visibility', 'hidden'); }, changeSwatchUsingCustomControl: function(data){ var custControl = RICHFX.jQuery('#'+this.sExternalSwatchControl); if (custControl) { if ( this.oSwatchViews !== undefined && this.oSwatchImages !== undefined) { var newColor = this.sCurrentSwatchInternalName; if ( this.sExternalSwatchControlAttr == undefined ) { if (custControl.val() != '') { newColor = custControl.val(); } } else { var attrVal = RICHFX.jQuery(custControl).find(":selected").attr(this.sExternalSwatchControlAttr); if ( attrVal != '' ) { newColor = attrVal; } } for ( var s in this.oSwatchImages[this.sCurrentView]) { var sv = this.oSwatchImages[this.sCurrentView][s]; if ( sv.swatchData.internalName == newColor ) { this.changeSwatch({"data": sv}); } } this.sCurrentSwatchInternalName = newColor; } if (this.bUseSlider) { // We need to scroll to a particular swatch in the carousel var scrollTo = 1; for ( var s in this.oSwatchOrder[this.sCurrentView] ) { s= s.substring(2, s.length); if (s == this.sCurrentSwatch) { break; } scrollTo++; } RICHFX.jQuery('#'+RICHFX.helpers.registeredSliders[this.sSwatchesID]).trigger('scroll.carousel', {'scrollTo': scrollTo}); } } }, changeCustomControlSwatch: function(data) { if ( this.sExternalSwatchControlAttr == undefined ) { RICHFX.jQuery('#'+this.sExternalSwatchControl).val(this.sCurrentSwatchInternalName); } else { // find option by attribute RICHFX.jQuery('#'+this.sExternalSwatchControl+' option').each(RICHFX.jQuery.proxy(function(i, el) { if ( RICHFX.jQuery(el).attr(this.sExternalSwatchControlAttr) == this.sCurrentSwatchInternalName) { RICHFX.jQuery(el).attr('selected', true); } else { RICHFX.jQuery(el).removeAttr('selected'); } }, this)); } }, changeViewUsingCustomControl: function(data){ var custControl = RICHFX.jQuery('#'+this.sExternalViewControl); if (custControl) { if ( this.oSwatchViews !== undefined && this.oSwatchImages !== undefined) { var newView = this.sCurrentView; if ( this.sExternalViewControlAttr == undefined ) { if (custControl.val() != '') { newView = custControl.val(); } } else { var attrVal = RICHFX.jQuery(custControl).find(":selected").attr(this.sExternalViewControlAttr); if ( attrVal != '' ) { newView = attrVal; } } if (this.oSwatchImages[newView]) { if (this.oSwatchImages[newView][this.sCurrentSwatch]) { var sv = this.oSwatchImages[newView][this.sCurrentSwatch]; //console.log("Calling changeView - 2151 - ", sv); this.changeView({"data": sv}); } } else { RICHFX.jQuery.Console.Error('External view name ('+newView+') does not match internal view name'); } this.sCurrentSwatchInternalName = newView; } if (this.bUseSlider) { // We need to scroll to a particular swatch in the carousel var scrollTo = 1; for ( var v in this.oViewOrder[this.sCurrentSwatch] ) { if (v == this.sCurrentView) { break; } scrollTo++; } RICHFX.jQuery('#'+RICHFX.helpers.registeredSliders[this.sViewsID]).trigger('scroll.carousel', {'scrollTo': scrollTo}); } } }, changeCustomControlView: function() { if ( this.sExternalViewControlAttr == undefined ) { RICHFX.jQuery('#'+this.sExternalViewControl).val(this.sCurrentView); } else { // find option by attribute RICHFX.jQuery('#'+this.sExternalViewControl+' > option').each(RICHFX.jQuery.proxy(function(i, el) { if ( RICHFX.jQuery(el).attr(this.sExternalViewControlAttr) == this.sCurrentView) { RICHFX.jQuery(el).attr('selected', true); } else { RICHFX.jQuery(el).removeAttr('selected'); } }, this)); } }, _getProductInfo: function() { var vars = [], hash; var heroSrc = RICHFX.jQuery(this.oHeroElement).attr('src'); var heroMedia = RICHFX.jQuery(this.oHeroElement).attr('rfxMedia'); this.sRfxCcGroup = RICHFX.helpers.sanitiseMetadata(RICHFX.jQuery(this.oHeroElement).attr('rfxCcGroup')); var hashes = heroSrc.slice(heroSrc.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); // Gather info where necessary if ( this.sRfxCcGroup != null && this.sRfxCcGroup != '' ) { if ( hash[0].toLowerCase() == 'swatchid' ) this.sRfxCcSwatch = hash[1]; if ( hash[0].toLowerCase() == 'viewid' ) this.sRfxCcView = hash[1]; } vars[hash[0].toLowerCase()] = hash[1]; } // Get from Embed var productXMLReq = this.oSettings.productXmlServiceUrl; //HACK: Tmp addition for iPad testing .. it does not like the short address productXMLReq = productXMLReq.replace("dev-rfxweb-01/", "dev-rfxweb-01.channeladvisor.com/"); var heroMediaStr = ""; if ( this.sRfxCcGroup != null && this.sRfxCcGroup != '' ) { productXMLReq = productXMLReq + "profileid=" + RICHFX.settings.sProfileID + "&" + this.sRfxCcGroup + "&viewerid=" + this.oSettings.organisatinalViewerId + "&callback=?"; var ccGroupRfxmedia = "profileid=" + RICHFX.settings.sProfileID + "&" + this.sRfxCcGroup; RICHFX.jQuery(this.oHeroElement).attr('rfxMedia', ccGroupRfxmedia); heroMediaStr = ccGroupRfxmedia; } else if ( heroMedia != null && heroMedia != "" && heroMedia.indexOf('=') != -1 ) { productXMLReq = productXMLReq + "&" + heroMedia + "&viewerid=" + this.oSettings.organisatinalViewerId + "&callback=?"; heroMediaStr = heroMedia; } else { // build request based on image request var firstParam = true; for ( var paramName in vars ) { if ( paramName.indexOf('recipe') == -1 && paramName.length > 1 ) { var paramVal = vars[paramName]; // Ensure consistency //paramName = paramName.toLowerCase(); if ( paramVal != "" && paramVal != undefined && paramVal != "undefined" ) { if ( firstParam ) { productXMLReq = productXMLReq + paramName + "=" + paramVal; firstParam = false; } else { productXMLReq = productXMLReq + "&" + paramName + "=" + paramVal; } if ( heroMediaStr == "" ) { heroMediaStr = paramName + "=" + paramVal; } else { heroMediaStr = heroMediaStr + "&" + paramName + "=" + paramVal; } } } } RICHFX.jQuery(this.oHeroElement).attr('rfxMedia', heroMediaStr); productXMLReq = productXMLReq + "&viewerid="+this.oSettings.organisatinalViewerId+"&callback=?"; } // create required function /* var callbackHero = heroMediaStr.replace(/[^a-z0-9]/gi, ''); var callbackName = 'productXmlCallback'+this.sName+callbackHero; var funcDef = "function " + callbackName + "(data) {return true;}"; eval(funcDef); */ // /* // Build pXml call var heroMediaStr = RICHFX.helpers.buildProductXmlRequest(this.oHeroElement, this.oSettings.productXmlServiceUrl, this.oSettings.organisatinalViewerId); var productXMLReq = this.oSettings.productXmlServiceUrl + heroMediaStr + "&viewerid="+this.oSettings.organisatinalViewerId+"&callback=?"; // iPad needs this for testing productXMLReq = productXMLReq.replace("dev-rfxweb-01/", "dev-rfxweb-01.channeladvisor.com/"); */ // create required function var callbackHero = heroMediaStr.replace(/[^a-z0-9]/gi, ''); var callbackName = 'productXmlCallback'+this.sName+callbackHero; var funcDef = "function " + callbackName + "(data) {return true;}"; eval(funcDef); // //console.log('Calling ajax request: ' + productXMLReq); productXMLReq = RICHFX.media.buildRequiredUrl(productXMLReq); RICHFX.jQuery.ajax({ url: productXMLReq, dataType: 'jsonp', jsonpCallback: callbackName, cache: true, context: this, success: function(data) { //console.log('AJAX succeed: ' + this.sViewerID + ' - ', RICHFX.media.aAttachedComponents[this.sViewerID]) for ( var id in RICHFX.media.aAttachedComponents[this.sViewerID] ) { var viewerName = RICHFX.media.aAttachedComponents[this.sViewerID][id]; if ( viewerName == "imageVideo" && this.bVideoSettings ) { this.checkForVideoView(data); break; } else { RICHFX.media.aVideoViewViewers[this.sViewerID] = false; } } RICHFX.jQuery(this.oHeroElement).trigger('imageColorChange.initialized'); RICHFX.jQuery.proxy(this._buildProductInfo(data), this); }, error: function(jqXHR, textStatus, errorThrown) { RICHFX.jQuery.Console.Warn("Ajax Error: ", errorThrown); }, complete: function (jqXHR, textStatus) { } }); }, _buildProductInfo: function(data) { var pSwatchImages = {}; var pSwatchViews = {}; this.oPXmlSwatchOrder = []; this.oPXmlViewOrder = []; var sFirstView = ""; var sFirstSwatch = ""; var defaultView = ""; if ( data["product"]["heroView"] != undefined && data["product"]["heroView"] != 'undefined') { this.sHeroViewID = data["product"]["heroView"]; } for ( var v in data["product"]["views"] ) { //if ( !RICHFX.helpers.isNumber(v) ) break; // handling a condition with IE8 var viewData = data["product"]["views"][v]; var viewName = viewData["@name"]; if ( this.sHeroSwatchID == "" ) { if ( viewData["heroSwatch"] != undefined && viewData["heroSwatch"] != 'undefined') { this.sHeroSwatchID = viewData["heroSwatch"]; } else { this.sHeroSwatchID = 'rfxEmptySwatch'; } } if ( viewName == undefined ) { viewName = 'rfxEmptyView'; } if ( defaultView == "" ) { defaulView = viewName; } pSwatchImages[viewName] = {}; this.oPXmlViewOrder[this.oPXmlViewOrder.length] = viewName; var visiblity = 1; if ( this.sHeroViewID == "" ) this.sHeroViewID = viewName; if ( sFirstView == "" ) sFirstView = this.sHeroViewID; for ( var s in viewData["swatches"] ) { var currSwatch = viewData["swatches"][s]; var swatchId = currSwatch["@id"]; if ( viewName == sFirstView ) { this.oPXmlSwatchOrder[this.oPXmlSwatchOrder.length] = swatchId; } if ( swatchId == undefined ) { swatchId = 'rfxEmptySwatch'; } pSwatchImages[viewName][swatchId] = {}; var lrgImage = ""; var lrgImagePath = ""; var lrgImageAlt = ""; var viewSrc = ""; var swatchInternalName = currSwatch["@internalName"]; var swatchExternalName = currSwatch["@externalName"]; var swatchItem = ""; var viewImage = ""; var swatchImage = ""; if ( swatchInternalName == undefined || swatchInternalName == "undefined" ) swatchInternalName = ''; if ( sFirstSwatch == "" ) { sFirstSwatch = swatchId; /* if ( this.sCurrentSwatchInternalName == null ) { this.sCurrentSwatchInternalName = swatchInternalName; } */ } var currViewCount = 0; for ( var img in currSwatch["images"] ) { var imgPath = currSwatch["images"][img]["@path"]; var imgType = currSwatch["images"][img]["@type"]; var imgId = currSwatch["images"][img]["@id"]; var imgAltText = currSwatch["images"][img]["text"]; swatchItem = imgId; // remove edgecast reference //imgPath = imgPath.replace("richfx", "dev-rfxweb-01"); if ( imgType == "initial" ) { var altText = ""; if (this.bShowAltViewAltText || ( imgAltText != undefined && imgAltText != "") ) { var tempAltText = viewName; if ( imgAltText != "" ) { tempAltText = imgAltText; } altText = 'alt="'+tempAltText+'" aria-label="'+tempAltText+'"'; } imgPath = RICHFX.media.buildRequiredUrl(imgPath); lrgImage = ''; lrgImagePath = imgPath; lrgImageAlt = altText; } else { viewSrc = imgPath; if ( imgType == "altView" ) { this.iAltViewWidth = currSwatch["images"][img]["size"]["width"]; this.iAltViewHeight = currSwatch["images"][img]["size"]["height"]; //console.log('altView Sizes: ' + this.iAltViewWidth +'|'+ this.iAltViewHeight); } } if ( this.bUseAltViewIndicators ) { viewSrc = this.sImageServiceURL +this.sIndicatorMetadataInActive; } var rotoationOverlaySrc = this.sImageServiceURL+this.sRotationOverlayImgMetadata; var videoOverlaySrc = this.sImageServiceURL+this.sVideoOverlayImgMetadata; if ( this.sVideoOverlayImgMetadata == '' ) { videoOverlaySrc = RICHFX.settings.sBaseURL +'ViewerDelivery/staticService?profileid=12056150&file=/assets/video-overlay.png'; } var overlayWidth = ((this.iAltViewWidth * 1) + 33); var overlayStyle = 'width: '+overlayWidth+'px; height: '+this.iAltViewHeight+'px; display: inline-block'; if (!this.bUseSlider) { overlayStyle = 'position: relative; ' + overlayStyle; } if ( this.bAltViewsVertical ) { overlayStyle = 'position: relative; '+this.iAltViewWidth+'px; height: '+this.iAltViewHeight+'px; display: block'; // 57px; 68px } viewSrc = RICHFX.media.buildRequiredUrl(viewSrc); rotoationOverlaySrc = RICHFX.media.buildRequiredUrl(rotoationOverlaySrc); videoOverlaySrc = RICHFX.media.buildRequiredUrl(videoOverlaySrc); if ( viewName == this.sVideoViewName ) { //console.log('float: found video view'); this.bFoundVideoView = true; } else if ( viewName == this.sRotationViewName ) { this.bFoundRotationView = true; } var altText = ""; if (this.bShowAltViewAltText || ( imgAltText != undefined && imgAltText != "") ) { var tempAltText = viewName; if ( imgAltText != "" ) { tempAltText = imgAltText; } altText = 'alt="'+tempAltText+'" aria-label="'+tempAltText+'"'; } if (this.sTooltip == 'both' || this.sTooltip == 'views') { if ( this.bUseRotationOverlay && viewName == this.sRotationViewName && !this.bFloatRotationView ) { viewImage = ''+ ''+v+' '+swatchInternalName+''+ '
' + ''+ ''+ '
' + '
'; } else if ( this.bUseVideoOverlay && viewName == this.sVideoViewName ) { if ( !this.bFloatVideoView ) { var leftPos = 0; //if (this.bUseSlider) { //leftPos = (currViewCount * this.iAltViewWidth) + 37; leftPos = (this.iAltViewWidth * 1) + 33; //console.log('Setting leftPos: '+ currViewCount + ' | ' + leftPos); //} viewImage = ''+ ''+v+' '+swatchInternalName+''+ '
' + ''+ ''+ '
' + '
'; } this.bTriggerVideo = false; } else { // Image data used in the views array viewImage = ''+ ''+v+' '+swatchInternalName+''+ ''+ ''; } } else { if ( this.bUseRotationOverlay && viewName == this.sRotationViewName && !this.bFloatRotationView ) { viewImage = ''+ ''+v+' '+swatchInternalName+''+ '
' + ''+ ''+ '
' + '
'; } else if ( this.bUseVideoOverlay && viewName == this.sVideoViewName ) { if ( !this.bFloatVideoView ) { var leftPos = 0; //if (this.bUseSlider) { // leftPos = ((currViewCount - 1) * this.iAltViewWidth) + 37; leftPos = ((this.iAltViewWidth * 1) + 33); //console.log('Setting leftPos: '+ currViewCount + ' | ' + leftPos); //} viewImage = ''+ ''+v+' '+swatchInternalName+''+ '
' + ''+ ''+ '
' + '
'; } this.bTriggerVideo = false; } else { var show = true; if ( viewName == this.sVideoViewName && this.bFloatVideoView ) show = false; if ( viewName == this.sRotationViewName && this.bFloatRotationView ) show = false; if (show) { viewImage = ''+ ''+v+' '+swatchInternalName+''+ ''+ ''; } } } currViewCount++; //console.log('Updataing currViewCount: '+ currViewCount ); } var swatchSrc = currSwatch["@path"]; // LimeLight example if ( swatchSrc != undefined ) { swatchSrc = swatchSrc.replace("richfx", "dev-rfxweb-01"); } var altText = ""; if (this.bShowSwatchAltText) { altText = 'alt="'+swatchExternalName+'" title="'+swatchExternalName+'"'; } swatchSrc = RICHFX.media.buildRequiredUrl(swatchSrc); if (this.sTooltip == 'both' || this.sTooltip == 'swatches') { swatchImage = ''+ ''+viewName+' '+swatchInternalName+''+ ''+ ''; } else { swatchImage = ''+ ''+viewName+' '+swatchInternalName+''+ ''+ ''; } var swatchData = {}; //revert update above if ( swatchInternalName == '' ) swatchInternalName = currSwatch["@internalName"]; swatchData["swatch"] = swatchId; swatchData["swatchBind"] = swatchId; swatchData["view"] = viewName; swatchData["altview"] = viewName; swatchData["default_view"] = defaultView; swatchData["visible"] = visiblity; swatchData["sequence"] = 1; swatchData["viewerID"] = this.sViewerID; swatchData["internalName"] = swatchInternalName; swatchData["externalName"] = swatchExternalName; swatchData["item"] = swatchItem; swatchData["image"] = imgId+'_'+swatchId+'_'+viewName; pSwatchImages[viewName][swatchId]["largeImage"] = lrgImage; pSwatchImages[viewName][swatchId]["largeImagePath"] = lrgImagePath; pSwatchImages[viewName][swatchId]["largeImageAlt"] = lrgImageAlt; pSwatchImages[viewName][swatchId]["swatchSrc"] = swatchSrc; pSwatchImages[viewName][swatchId]["swatchImage"] = swatchImage; pSwatchImages[viewName][swatchId]["swatchImageId"] = this.sViewerID+'_'+imgId+'_'+swatchId+'_'+viewName; pSwatchImages[viewName][swatchId]["swatchData"] = swatchData; pSwatchImages[viewName][swatchId]["viewSrc"] = viewSrc; if ( this.bUseSlider ) { pSwatchImages[viewName][swatchId]["viewImage"] = '
  • '+viewImage+'
  • '; } else { pSwatchImages[viewName][swatchId]["viewImage"] = viewImage; } pSwatchImages[viewName][swatchId]["viewImageId"] = this.sViewerID+'_'+viewName+'_'+imgId+'_'+swatchId+'_'+viewName; if ( this.sRfxCcGroup != null && this.sRfxCcGroup != '' ) { if ( this.sRfxCcSwatch == swatchInternalName ) { this.sHeroSwatchID = swatchId; sFirstSwatch = swatchId; } } } } // Build swatchView Object var firstView = true; for ( var v in data["product"]["views"] ) { //if ( !RICHFX.helpers.isNumber(v) ) break; // handling a condition with IE8 var viewData = data["product"]["views"][v]; var viewName = viewData["@name"]; if ( viewName == undefined ) { viewName = 'rfxEmptyView'; } for ( var s in viewData["swatches"] ) { var currSwatch = viewData["swatches"][s]; var swatchId = currSwatch["@id"]; if ( swatchId == undefined ) { swatchId = 'rfxEmptySwatch'; } if ( firstView || pSwatchViews[swatchId] == undefined ) pSwatchViews[swatchId] = {}; // deep copy the required object pSwatchViews[swatchId][viewName] = RICHFX.jQuery.extend(true, {}, pSwatchImages[viewName][swatchId]); } firstView = false; } this.sOriginalView = sFirstView; this.sCurrentSwatch = sFirstSwatch; this.sCurrentView = sFirstView; //console.log('3 setting sCurrentSwatchInternalName to ' + this.sCurrentSwatchInternalName); RICHFX.settings.sCurrentSwatch = this.sCurrentSwatchInternalName; RICHFX.settings.sCurrentView = this.sCurrentView; if ( this.sRfxCcGroup != null && this.sRfxCcGroup != '' ) { if ( this.sRfxCcView != null && this.sRfxCcView != '') { // reset if necessary this.sCurrentView = this.sRfxCcView; } } this.sHeroSwatch = sFirstSwatch; this.sHeroView = sFirstView; this.oSwatchOrder = RICHFX.jQuery.extend(true, {}, pSwatchImages); this.oSwatchImages = RICHFX.jQuery.extend(true, {}, pSwatchImages); this.oViewOrder = RICHFX.jQuery.extend(true, {}, pSwatchViews); this.oSwatchViews = RICHFX.jQuery.extend(true, {}, pSwatchViews); if (this.bSingleAltView || this.bShowVideoforAllSwatches) { //put all swatches in each view and all viewes in each swatch var videoOnly = false; if (!this.bSingleAltView && this.bShowVideoforAllSwatches) { //console.log('Working with Video Only!'); videoOnly = true; } //Find the swatch with the most views var totalViewCount = 0; var backfillSwatch = ""; var maxViewCount = 0; // Calculate total num of views for ( var v in pSwatchImages ) { totalViewCount++; } // Find swatch with most Views var controlView = {}; for ( var s in pSwatchViews ) { var viewCount = 0; for ( var v in pSwatchViews[s] ) { viewCount++; } if ( viewCount > maxViewCount ) { maxViewCount = viewCount; backfillSwatch = s; } } if ( maxViewCount != totalViewCount ) { for ( var v in pSwatchImages ) { if ( pSwatchViews[backfillSwatch][v] != undefined ) { controlView[v] = backfillSwatch; } else { for ( var s in pSwatchImages[v] ) { // save first swatch for that view controlView[v] = s; break; } } } } else { // Build control array with backfillSwatch for ( var v in pSwatchViews[backfillSwatch] ) { controlView[v] = backfillSwatch; } } // Find View with most Swatches var totalSwatchCount = 0; var backfillView = ""; var maxSwatchCount = 0; for ( var s in pSwatchViews ) { totalSwatchCount++; } var controlSwatch = {}; for ( var v in pSwatchImages ) { var swatchCount = 0; for ( var s in pSwatchImages[v] ) { swatchCount++; } if ( swatchCount > maxSwatchCount ) { maxSwatchCount = swatchCount; backfillView = v; } } if ( maxSwatchCount != totalSwatchCount ) { for ( var s in pSwatchViews ) { if ( pSwatchImages[backfillView][s] != undefined ) { controlSwatch[s] = backfillView; } else { for ( var v in pSwatchImages[backfillView] ) { // save first swatch for that view controlSwatch[s] = v; break; } } } } else { // Build control array with backfillSwatch for ( var s in pSwatchImages[backfillView] ) { controlSwatch[s] = backfillView; } } //console.log('pSwatchImages: ', pSwatchImages); //console.log('controlSwatch: ', controlSwatch); //console.log('controlView: ', controlView); // Backfill as necessary using the control arrays for ( var v in pSwatchImages ) { for ( var s in controlSwatch ) { //console.log('swatchClone lookup: ' + v + '|' + s); if ( pSwatchImages[v][s] == undefined ) { //var swatchClone = pSwatchImages[v][controlSwatch[v]]; var swatchClone = RICHFX.jQuery.extend(true, {}, pSwatchImages[v][controlView[v]]); swatchClone.swatchData.swatch = s; //console.log('swatchClone: ' + v + '|' + s + '|' + this.sVideoViewName + '|', swatchClone); if ( !videoOnly || ( v == this.sVideoViewName ) ) { //console.log('adding swatchClone for: ' + v); this.oSwatchImages[v][s] = RICHFX.jQuery.extend(true, {}, swatchClone); this.oSwatchOrder[v][s] = RICHFX.jQuery.extend(true, {}, swatchClone); } } } } for ( var s in pSwatchViews ) { for ( var v in controlView ) { if ( pSwatchViews[s][v] == undefined ) { //var viewClone = pSwatchViews[controlView[v]][v]; var viewClone = RICHFX.jQuery.extend(true, {}, pSwatchViews[controlView[v]][v]); viewClone.swatchData.swatch = s; //console.log('viewClone: ' + v + '|' + s + '|' + this.sVideoViewName + '|', viewClone); if ( !videoOnly || ( v == this.sVideoViewName ) ) { //console.log('adding viewClone for: ' + v); this.oSwatchViews[s][v] = RICHFX.jQuery.extend(true, {}, viewClone); this.oViewOrder[s][v] = RICHFX.jQuery.extend(true, {}, viewClone); } } } } } // get singleAltView Working this._buildSwatchList(); this._filterSwatches(); this._methods(); this.embed(); }, checkForVideoView: function(data) { for ( var v in data["product"]["views"] ) { var viewData = data["product"]["views"][v]; var viewName = viewData["@name"]; //console.log('Check for video view name: ' + viewName + '|' + this.sVideoViewName + '|' + this.sViewerID ); if ( viewName == this.sVideoViewName ) { RICHFX.media.aVideoViewViewers[this.sViewerID] = true; return; } } RICHFX.media.aVideoViewViewers[this.sViewerID] = false; }, changeSwatch: function(evt) { var sourceChangeAlt = ''; // No event data, so reset the swatches array - no swatches will be shown. This can occur when all swatches have been switched off if (!evt.data) { /* if (this.bUseSlider && RICHFX.helpers.registeredSliders[this.sSwatchesID] !== undefined) { RICHFX.jQuery('#'+RICHFX.helpers.registeredSliders[this.sSwatchesID]).trigger('reset.carousel'); // Reset the views too if there are none if (!RICHFX.helpers.objSize(this.oViewOrder[this.sHeroSwatch])) { RICHFX.jQuery('#'+RICHFX.helpers.registeredSliders[this.sViewsID]).trigger('reset.carousel'); } } */ this.sCurrentSwatch = this.sHeroSwatch!==undefined?this.sHeroSwatch:""; this.sCurrentView = this.sHeroView!==undefined?this.sHeroView:""; var data = {'src': RICHFX.jQuery('#'+this.sViewerID+'_'+this.sName).attr('src'), 'data': {'name': RICHFX.jQuery('#'+this.sViewerID+'_'+this.sName).attr('title')}, 'alt': RICHFX.jQuery('#'+this.sViewerID+'_'+this.sName).attr('alt') }; //console.log("Calling changeSource - 2932 - ", data); this.changeSource(data); } else { this.oPreviousData = evt.data; //this.sCurrentSwatch = evt.data.swatchData.swatch; this.sCurrentSwatch = evt.data.swatchData.swatchBind; this.sCurrentSwatchInternalName = evt.data.swatchData.internalName; this.sCurrentSwatchExternalName = evt.data.swatchData.externalName; //If the alt view has been set, then use that as the current. If the swatch doesn't exist for the current view, then use the view where it does exist as the current view if (evt.data.swatchData.altview) { this.sCurrentView = evt.data.swatchData.altview; } else { this.sCurrentView = evt.data.swatchData.view; } } //console.log('setting swatchView (3001): ' + this.sCurrentSwatch, this.oViewOrder); var sv = this.oViewOrder[this.sCurrentSwatch]; //if (!this.bUseSlider) { this.manageViewsDiv(sv); //} // Apply the bindings and triggers to the Views if (this.sViewsID != "null" && RICHFX.jQuery('#'+this.sViewsID).attr('id') && this.bAllowSelectionOfAltView) { this.manageViewBindings(sv, evt); } this.manageViewCSS(sv); if (this.sCurrentSwatch) { this.manageSwatchBindings(evt); if (evt.data !== undefined) { //Change source relies on the URL being in the following format: var data = {'src': evt.data.largeImagePath, 'data': evt.data.swatchData, 'alt': evt.data.largeImageAlt}; // save alt view to avoid double request sourceChangeAlt = data.alt; //console.log("Calling changeSource - 2973 - ", data); this.changeSource(data); if ( this.bInitialized ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).trigger('image.change.swatch', {'data': data, 'elem': this.oHeroElement}); } } else { RICHFX.jQuery.Console.Warn('changeSwatch: No image source given when changing swatch.'); //return; } } // use primaryView where necessary if ( ( this.sNewAltView != undefined ) && ( this.sNewAltView != this.sCurrentView ) ) { if ( this.sNewAltView != '' ) { this.sCurrentView = this.sNewAltView; } // check alt view to avoid double request if ( sourceChangeAlt != '' && sourceChangeAlt != this.sCurrentView ) { var sv = this.oSwatchImages[this.sCurrentView][this.sCurrentSwatch]; //console.log("Calling changeView - 3012 - ", sv); this.changeView({"data": sv}); } } else if ( this.bDefaultToPrimaryView ) { var sPrevView = this.sCurrentView; if ( this.bUseDefaultOrdering == false ) { if ( this.sDefaultView !== undefined ) { this.sCurrentView = this.sDefaultView; } else if ( this.sHeroView !== undefined ) { this.sCurrentView = this.sHeroView; } } var sv = this.oSwatchImages[this.sCurrentView][this.sCurrentSwatch]; var sLargeView = sv.swatchData["altview"]; // verify viewChange if ( sLargeView == this.sCurrentView ) { //console.log("Calling changeView - 3035 - ", sv); this.changeView({"data": sv}); } } if ( this.bFlipToAltView || this.bSlideAltView || this.bFadeAltView ) { if ( this.oViewOrder[this.sCurrentSwatch][this.sEffectAltView] != undefined ) { //var altImage = this.oViewOrder[this.sCurrentSwatch][this.sEffectAltView].largeImage; //var altSrc = RICHFX.jQuery(altImage).attr('src'); var altSrc = this.oViewOrder[this.sCurrentSwatch][this.sEffectAltView].largeImagePath; RICHFX.jQuery('#'+this.sViewerID+'_'+this.sName+'_alt').attr('src', altSrc); } } if ($) { $(document).trigger('richmedia.swatch.changed'); } else { RICHFX.jQuery(document).trigger('richmedia.swatch.changed'); } // native trigger this._fireNativeTrigger('richmedia.swatch.changed'); //console.log ('4 setting sCurrentSwatchInternalName to ' + this.sCurrentSwatchInternalName); RICHFX.settings.sCurrentSwatch = this.sCurrentSwatchInternalName; RICHFX.settings.sCurrentView = this.sCurrentView; }, manageSwatchBindings: function(evt) { var currViewSwatchArr = this.oSwatchOrder[this.sOriginalView]; // Apply the bindings and triggers to the swatches - bindings dont need to be in order if (this.sSwatchesID != "null" && RICHFX.jQuery('#'+this.sSwatchesID).attr('id')) { var selectedBindTo = ''; for ( var s in currViewSwatchArr ) { var sv = this.oSwatchImages[this.sOriginalView][s]; var bindTo = this.sViewerID+'_'+sv.swatchData.item+'_'+sv.swatchData.swatch+'_'+sv.swatchData.altview; // update setting where necessary if ( sv.swatchData.swatch == this.sCurrentSwatch ) selectedBindTo = bindTo; var viewBinding = this.sViewerID+'_'+sv.swatchData.altview+'_'+sv.swatchData.item+'_'+sv.swatchData.swatch+'_'+sv.swatchData.altview; RICHFX.jQuery('#'+bindTo).unbind('click'); RICHFX.jQuery('#'+bindTo).unbind('mousover'); RICHFX.jQuery('#'+bindTo).unbind('mouseout'); RICHFX.jQuery('#'+bindTo).unbind('mouseleave'); RICHFX.jQuery('#'+bindTo).unbind(this.sBindingEvent); RICHFX.jQuery('#'+bindTo).unbind(this.sSwatchBindingEvent); RICHFX.jQuery('#'+bindTo).unbind(this.sAltViewBindingEvent); if (s == this.sCurrentSwatch) { RICHFX.jQuery('#'+bindTo).addClass('RICHFXColorChangeSwatchSelected'); } else { RICHFX.jQuery('#'+bindTo).removeClass('RICHFXColorChangeSwatchSelected'); } if (this.sSwatchBindingEvent == 'hover') { // Only bind the mouseout for non-selected swatches if (evt.data.id != viewBinding) { RICHFX.jQuery('#'+bindTo).bind('mouseout', RICHFX.jQuery.proxy(function(event){ this.changeToPreviousSource(); }, this)); } RICHFX.jQuery('#'+bindTo).bind('mouseover', {data: sv}, RICHFX.jQuery.proxy(function(event){ var data = {'src': event.data.data.largeImagePath, 'data': event.data.data.swatchData, 'alt': event.data.data.largeImageAlt}; //console.log("Calling changeSource - 3098 - ", data); //this.changeSource(data); event.data.data.id = event.currentTarget.id; this.changeSwatch({"data": event.data.data}); }, this)); //console.log('adding focus bind to: ' + bindTo); RICHFX.jQuery('#'+bindTo).parent().bind('focus', {data: sv}, RICHFX.jQuery.proxy(function(event){ var swatchData = event.data.data.swatchData; var focusStr = swatchData.sViewerID+'_'+swatchData.altview+'_'+swatchData.item+'_'+swatchData.swatchBind+'_'+swatchData.altview; //console.log('Caught focus: ' + focusStr); if ( focusStr == this.sLastFocusedElement ) return false; this.sCurrFocusedElement = focusStr; var data = {'src': event.data.data.largeImagePath, 'data': event.data.data.swatchData, 'alt': event.data.data.largeImageAlt}; //console.log("Calling changeSwatch - focus - ", data); event.data.data.id = event.currentTarget.id; this.changeSwatch({"data": event.data.data}); //return false; }, this)); RICHFX.jQuery('#'+bindTo).bind('click', {data: sv}, RICHFX.jQuery.proxy(function(event){ event.data.data.id = event.currentTarget.id; this.changeSwatch({"data": event.data.data}); return false; }, this)); } else { RICHFX.jQuery('#'+bindTo).bind(this.sSwatchBindingEvent, {data: sv}, RICHFX.jQuery.proxy(function(event){ event.data.data.id = event.currentTarget.id; this.changeSwatch({"data": event.data.data}); return false; }, this)); RICHFX.jQuery('.RICHFXColorChangeLink').bind('keyup', {id: bindTo}, RICHFX.jQuery.proxy(function(event) { var keycode = (event.keyCode ? event.keyCode : event.which); if(keycode == '13') { var currSwatch = RICHFX.jQuery(event.target).find('img:first'); RICHFX.jQuery(currSwatch).click(); } }, this)); } //} // End of check for current swatch // Add the hover effect CSS RICHFX.jQuery('#'+bindTo).bind('mouseover', {id: bindTo}, RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#'+event.data.id).addClass('RICHFXColorChangeSwatchHover'); if (this.sTooltip == 'both' || this.sTooltip == 'swatches') { this.showTooltip({"target": event.data.id, "type": "swatches"}); } }, this)); RICHFX.jQuery('#'+bindTo).bind('mouseleave', {id: bindTo}, RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#'+event.data.id).removeClass('RICHFXColorChangeSwatchHover'); if (this.sTooltip == 'both' || this.sTooltip == 'swatches') { this.hideTooltip({"target": event.data.id}); } }, this)); } if ( selectedBindTo != '' ) { RICHFX.jQuery('#'+selectedBindTo).addClass('RICHFXColorChangeSwatchSelected'); } } }, manageViewBindings: function(sv, evt) { var selectedBindTo = ''; for ( var s in sv ) { // Store the current swatch, check if an alternative swatch has been set, if so, use that as the swatch. Basically if a swatch doesn't exist for the view then use the swatch from an alternative view var cs = sv[s].swatchData.swatchBind; var bindTo = this.sViewerID+'_'+sv[s].swatchData.altview+'_'+sv[s].swatchData.item+'_'+cs+'_'+sv[s].swatchData.altview; // Unbind all neccesary events RICHFX.jQuery('#'+bindTo).unbind('click'); RICHFX.jQuery('#'+bindTo).unbind('mousover'); RICHFX.jQuery('#'+bindTo).unbind('mouseout'); RICHFX.jQuery('#'+bindTo).unbind('mouseleave'); RICHFX.jQuery('#'+bindTo).unbind(this.sBindingEvent); RICHFX.jQuery('#'+bindTo).unbind(this.sSwatchBindingEvent); RICHFX.jQuery('#'+bindTo).unbind(this.sAltViewBindingEvent); var bindToOverlay = false; if ( (this.bUseRotationOverlay && sv[s].swatchData.altview == this.sRotationViewName) || (this.bUseVideoOverlay && sv[s].swatchData.altview == this.sVideoViewName)) { bindToOverlay = true; } if (s == this.sCurrentView) { if ( this.bUseAltViewIndicators ) { RICHFX.jQuery('#'+bindTo).attr('src', this.sImageServiceURL + this.sIndicatorMetadataActive); } else { RICHFX.jQuery('#'+bindTo).addClass('RICHFXColorChangeViewSelected'); } RICHFX.jQuery('#'+bindTo).bind('click', RICHFX.jQuery.proxy(function(event){ // stop the click cascading to any other viewer below return false; }, this)); if ( bindToOverlay ) { RICHFX.jQuery('#'+this.sViewerID+'_rotationOverlay').addClass('RICHFXColorChangeViewSelected'); RICHFX.jQuery('#'+this.sViewerID+'_rotationOverlay').bind('click', RICHFX.jQuery.proxy(function(event){ // stop the click cascading to any other viewer below return false; }, this)); RICHFX.jQuery('#'+this.sViewerID+'_videoOverlay').addClass('RICHFXColorChangeViewSelected'); RICHFX.jQuery('#'+this.sViewerID+'_videoOverlay').bind('click', RICHFX.jQuery.proxy(function(event){ // stop the click cascading to any other viewer below return false; }, this)); this.bTriggerVideo = true; } selectedBindTo = bindTo; } else { if ( this.bUseAltViewIndicators ) { RICHFX.jQuery('#'+bindTo).attr('src', this.sImageServiceURL + this.sIndicatorMetadataInActive); } else { RICHFX.jQuery('#'+bindTo).removeClass('RICHFXColorChangeViewSelected'); } // TODO: Refactor this if (this.sAltViewBindingEvent == 'hover') { if (evt.data.id != bindTo) { RICHFX.jQuery('#'+bindTo).bind('mouseout', RICHFX.jQuery.proxy(function(event){ this.changeToPreviousSource(); }, this)); } RICHFX.jQuery('#'+bindTo).bind('mouseover', {data: sv[s]}, RICHFX.jQuery.proxy(function(event){ var data = {'src': event.data.data.largeImagePath, 'data': event.data.data.swatchData, 'alt': event.data.data.largeImageAlt}; //console.log("Calling changeSource - 3220 - ", data); //this.changeSource(data); event.data.data.id = event.currentTarget.id; //console.log("Calling changeView - 3244 - ", event.data.data); this.changeView({'data': event.data.data}); }, this)); //console.log('adding focud bind to: ' + bindTo); RICHFX.jQuery('#'+bindTo).parent().bind('focus', {data: sv[s]}, RICHFX.jQuery.proxy(function(event){ var swatchData = event.data.data.swatchData; var focusStr = swatchData.sViewerID+'_'+swatchData.altview+'_'+swatchData.item+'_'+swatchData.swatchBind+'_'+swatchData.altview; if ( focusStr == this.sLastFocusedElement ) return false; this.sCurrFocusedElement = focusStr; var data = {'src': event.data.data.largeImagePath, 'data': event.data.data.swatchData, 'alt': event.data.data.largeImageAlt}; //console.log("Calling changeView - focus - ", data); event.data.data.id = event.currentTarget.id; this.changeView({'data': event.data.data}); //return false; }, this)); RICHFX.jQuery('#'+bindTo).bind('click', {data: sv[s]}, RICHFX.jQuery.proxy(function(event){ //id is passed so we don't change source using any bindings after a "click" for example. If the binding event is preview and we don't do this the mouseout will get called after the click and change the source. event.data.data.id = event.currentTarget.id; //console.log("Calling changeView - 3244 - ", event.data.data); this.changeView({'data': event.data.data}); return false; }, this)); if ( bindToOverlay ) { RICHFX.jQuery('#'+this.sViewerID+'_rotationOverlay').removeClass('RICHFXColorChangeViewSelected'); RICHFX.jQuery('#'+this.sViewerID+'_rotationOverlay').bind('click', {data: sv[s]}, RICHFX.jQuery.proxy(function(event){ //id is passed so we don't change source using any bindings after a "click" for example. If the binding event is preview and we don't do this the mouseout will get called after the click and change the source. event.data.data.id = event.currentTarget.id; //console.log("Calling changeView - 3256 - ", event.data.data); this.changeView({'data': event.data.data}); return false; }, this)); RICHFX.jQuery('#'+this.sViewerID+'_videoOverlay').removeClass('RICHFXColorChangeViewSelected'); RICHFX.jQuery('#'+this.sViewerID+'_videoOverlay').bind('click', {data: sv[s]}, RICHFX.jQuery.proxy(function(event){ //id is passed so we don't change source using any bindings after a "click" for example. If the binding event is preview and we don't do this the mouseout will get called after the click and change the source. event.data.data.id = event.currentTarget.id; //console.log("Calling changeView - 3266 - ", event.data.data); this.changeView({'data': event.data.data}); return false; }, this)); this.bTriggerVideo = false; } } else { //console.log("binding changeView - 3274 - " + bindTo + "|" + this.sAltViewBindingEvent, sv[s]); RICHFX.jQuery('#'+bindTo).bind(this.sAltViewBindingEvent, {data: sv[s]}, RICHFX.jQuery.proxy(function(event){ event.data.data.id = event.currentTarget.id; //console.log("Calling changeView - 3277 - " + event.currentTarget.id, event.data.data); this.changeView({'data': event.data.data}); return false; }, this)); RICHFX.jQuery('.RICHFXColorChangeLink').bind('keyup', {id: bindTo}, RICHFX.jQuery.proxy(function(event) { var keycode = (event.keyCode ? event.keyCode : event.which); if(keycode == '13') { var currView = RICHFX.jQuery(event.target).find('img:first'); RICHFX.jQuery(currView).click(); } }, this)); if ( bindToOverlay ) { RICHFX.jQuery('#'+this.sViewerID+'_rotationOverlay').bind(this.sAltViewBindingEvent, {data: sv[s]}, RICHFX.jQuery.proxy(function(event){ event.data.data.id = event.currentTarget.id; //console.log("Calling changeView - 3287 - ", event.data.data); this.changeView({'data': event.data.data}); return false; }, this)); RICHFX.jQuery('#'+this.sViewerID+'_videoOverlay').bind(this.sAltViewBindingEvent, {data: sv[s]}, RICHFX.jQuery.proxy(function(event){ event.data.data.id = event.currentTarget.id; //console.log("Calling changeView - 3295 - ", event.data.data); this.changeView({'data': event.data.data}); return false; }, this)); RICHFX.jQuery('#'+this.sViewerID+'_rotationOverlay').bind('mouseover', {id: bindTo}, RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#'+event.data.id).addClass('RICHFXColorChangeViewHover'); }, this)); RICHFX.jQuery('#'+this.sViewerID+'_videoOverlay').bind('mouseover', {id: bindTo}, RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#'+event.data.id).addClass('RICHFXColorChangeViewHover'); }, this)); RICHFX.jQuery('#'+this.sViewerID+'_rotationOverlay').bind('mouseout', {id: bindTo}, RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#'+event.data.id).removeClass('RICHFXColorChangeViewHover'); }, this)); RICHFX.jQuery('#'+this.sViewerID+'_videoOverlay').bind('mouseout', {id: bindTo}, RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#'+event.data.id).removeClass('RICHFXColorChangeViewHover'); }, this)); this.bTriggerVideo = false; } } } // End of check for current view // Add the hover effect CSS RICHFX.jQuery('#'+bindTo).bind('mouseover', {id: bindTo}, RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#'+event.data.id).addClass('RICHFXColorChangeViewHover'); if (this.sTooltip == 'both' || this.sTooltip == 'views') { this.showTooltip({"target": event.data.id, "type": "views"}); } }, this)); RICHFX.jQuery('#'+bindTo).bind('mouseleave', {id: bindTo}, RICHFX.jQuery.proxy(function(event){ RICHFX.jQuery('#'+event.data.id).removeClass('RICHFXColorChangeViewHover'); if (this.sTooltip == 'both' || this.sTooltip == 'views') { this.hideTooltip({"target": event.data.id}); } }, this)); } if ( this.bUseAltViewIndicators ) { RICHFX.jQuery('#'+selectedBindTo).attr('src', this.sImageServiceURL + this.sIndicatorMetadataActive); } else { RICHFX.jQuery('#'+selectedBindTo).addClass('RICHFXColorChangeViewSelected'); } }, manageViewsDiv: function(sv) { //console.log('Entered manageViewsDiv: ', sv); if ( this.sViewsID != "null" && ( this.bShowSingleAltViewDiv || (!this.bShowSingleAltViewDiv && this.oPXmlViewOrder.length > 1) )) { RICHFX.jQuery('#'+this.sViewsID).html(""); var viewsHTML = ''; var viewCount = 0; if ( this.bUseSlider ) { viewsHTML = '
    ').appendTo('#RICHFXViewerContainer_'+this.sViewerID); } RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr').html(''); RICHFX.jQuery('').appendTo('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr'); } //swatchData = this.oSwatchImages[nextView][this.sHeroSwatchID]; swatchData = this.oSwatchImages[nextView][this.sCurrentSwatch]; //swatchData = this.oViewOrder[this.sCurrentSwatch][nextView]; if ( swatchData == undefined ) { swatchData = this.oViewOrder[this.sCurrentSwatch][nextView]; //swatchData = this.oSwatchImages[nextView][this.sHeroSwatchID]; } if ( swatchData == undefined ) { swatchData = this.oSwatchImages[nextView][this.sHeroSwatchID]; //swatchData = this.oSwatchImages[nextView][this.sCurrentSwatch]; } if ( swatchData != undefined ) { //var altView = swatchData.largeImage; //var altSrc = RICHFX.jQuery(altView).attr('src'); var altSrc = swatchData.largeImagePath; altSrc = RICHFX.media.buildRequiredUrl(altSrc); if ( RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_next').length == 0 ) { RICHFX.jQuery('
    ').appendTo('#RICHFXViewerContainer_'+this.sViewerID); } RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_next').html(''); RICHFX.jQuery('').appendTo('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_next'); } //swatchData = this.oSwatchImages[prevView][this.sHeroSwatchID]; swatchData = this.oSwatchImages[prevView][this.sCurrentSwatch]; //swatchData = this.oViewOrder[this.sCurrentSwatch][prevView]; if ( swatchData == undefined ) { swatchData = this.oViewOrder[this.sCurrentSwatch][prevView]; //swatchData = this.oSwatchImages[prevView][this.sHeroSwatchID]; } if ( swatchData == undefined ) { swatchData = this.oSwatchImages[prevView][this.sHeroSwatchID]; //swatchData = this.oSwatchImages[prevView][this.sCurrentSwatch]; } if ( swatchData != undefined ) { //var altView = swatchData.largeImage; //var altSrc = RICHFX.jQuery(altView).attr('src'); var altSrc = swatchData.largeImagePath; altSrc = RICHFX.media.buildRequiredUrl(altSrc); if ( RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prev').length == 0 ) { RICHFX.jQuery('
    ').appendTo('#RICHFXViewerContainer_'+this.sViewerID); } RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prev').html(''); RICHFX.jQuery('').appendTo('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prev'); } RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).css('overflow', 'hidden'); var zIndex = 1000 if ( this.bSlideAltView ) { zIndex = 26000; } RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr').css('left', '0px'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr').hide(); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_curr').css('z-index', zIndex); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_next').css('left', this.iVWidth+'px'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_next').show(); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_next').css('z-index', zIndex); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prev').css('left', (0-this.iVWidth) + 'px'); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prev').show(); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prev').css('z-index', zIndex); }, _hidePrevAndNextIndicators: function() { if ( this.bShowPrevNextImages ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prevImg').hide(); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_nextImg').hide(); } }, _showPrevAndNextIndicators: function() { if ( this.bShowPrevNextImages ) { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_prevImg').show(); RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID+'_'+this.sName+'_nextImg').show(); } }, _findCurrentViewPos: function() { for ( var viewIdx in this.oPXmlViewOrder ) { var currView = this.oPXmlViewOrder[viewIdx]; if ( currView == this.sCurrentView ) { this.currentViewPos = viewIdx; break; } } }, _fireNativeTrigger: function(eventName) { //console.log('UserAgent: ' + navigator.userAgent); // native trigger /* var evt = new CustomEvent('Event'); evt.initEvent(eventName, true, true) document.dispatchEvent(evt); */ var evt = document.createEvent("CustomEvent"); evt.initCustomEvent(eventName, true, true, { detail: { 'RMEvent' : eventName } }); document.dispatchEvent(evt); }, register: function() { RICHFX.media.aLoadedComponents['imageColorChange'] = true; if (!RICHFX.media.aRegViewers[this.sElementID]) { RICHFX.media.aRegViewers[this.sElementID] = {}; } RICHFX.media.aRegViewers[this.sElementID][this.sViewerID+'_imageColorChange'] = this; }, _methods: function() { this.aExternalMethods = ['changeSwatch', 'changeView']; }, execute: function(action, obj) { // Check if the action is allowed if (RICHFX.jQuery.inArray( action, this.aExternalMethods ) >= 0 ) { if (action == "changeSwatch") { var swatchName = this._lookupSwatchIDbyName(this.sCurrentView, obj); if ( swatchName != null ) { var sv = this.oSwatchImages[this.sCurrentView][swatchName]; this.changeSwatch({'data': sv}); } else { // Try to handle 'single alt view' swatchName = this._lookupSwatchIDbyName(this.sHeroView, obj); if ( swatchName != null ) { var sv = this.oSwatchImages[this.sHeroView][swatchName]; this.changeSwatch({'data': sv}); } } } else if (action == "changeView") { var sv = this.oSwatchImages[obj][this.sCurrentSwatch]; //console.log("Calling changeView - 4644 - ", sv); this.changeView({'data': sv}); } } }, addSlider: function() { var count = this.oPXmlViewOrder.length; //console.log('Reached Add Slider: ' + count + ", " + this.iSliderMinImages); if ( count >= this.iSliderMinImages ) { var sliderID = this.SliderApplyTo[0]; this.SliderItemWidth = this.iAltViewWidth; this.SliderItemHeight = this.iAltViewHeight; var carousel = RICHFX.jQuery('#'+sliderID + ' > ul'); RICHFX.jQuery(carousel).attr('id', this.sViewerID+sliderID); RICHFX.jQuery(carousel).attr('className', 'jcarousel-skin-'+this.sSliderSkin); var size = RICHFX.jQuery('#'+sliderID).width(); /* this.itemWidth = size / count; this.itemHeight = this.itemWidth; console.log('itemWidth|itemHeight : ' + this.itemWidth + '|' + this.itemHeight); */ if ( this.bVertical ) { size = RICHFX.jQuery('#'+sliderID).height(); RICHFX.jQuery(carousel).css('height', size+'px'); } else { //carousel.style.width = size+'px'; RICHFX.jQuery(carousel).css('width', ((this.itemWidth * count)+10)+'px'); //console.log('carousel Width: ' + this.sViewerID+v + ' - ' + carousel.style.width + ' | ' + this.itemWidth); } RICHFX.jQuery(document).bind('slider.load.views', RICHFX.jQuery.proxy(function(){ //console.log('Handling slider.load.views'); // Add the rest of the views to the slider var sv = this.oViewOrder[this.sCurrentSwatch]; var currSwatch = this.oSwatchImages[this.sHeroViewID][this.sHeroSwatchID]; var evt = {'data': currSwatch}; console.log('currentSwatch|currentView: ' + this.sCurrentSwatch + ' | ' + this.sCurrentView, sv ) //RICHFX.jQuery('#'+carousel.options.slider).trigger('reset.carousel'); RICHFX.jQuery('#'+this.oSliderSettings.applyTo).trigger('add.views.to.carousel', {'items': sv, 'view': this.sCurrentView, 'pXmlViewOrder': this.oPXmlViewOrder, 'swatch': this.sCurrentSwatch}); this.manageViewBindings(sv, evt); },this)); RICHFX.jQuery('#'+this.sViewerID+sliderID).jcarousel({ id: this.sViewerID+sliderID, slider: sliderID, itemCount: count, vertical: this.bSliderVertical, start: this.iSliderStart, scroll: this.iSliderScroll, animation: this.sSliderAnimation, easing: this.sSliderEasing, auto: this.iSliderAuto, wrap: this.sSliderWrap, buttonPrevEvent: this.sSliderButtonPrevEvent, buttonNextEvent: this.sSliderButtonNextEvent, initCallback: this.sliderCarouselCallback, containerSize: size, controlHeight: this.SliderControlImageHeight, controlWidth: this.SliderControlImageWidth, itemHeight: this.SliderItemHeight, itemWidth: this.SliderItemWidth, viewableImages: (this.iSliderMinImages - 1) }); // Disable text selection within the gallery RICHFX.helpers.disableSelection(document.getElementById(sliderID)); // Update relevant CSS this.addSliderControlsCSS(); } }, addSliderControlsCSS: function() { if ( !this.bSliderVertical ) { var doubleWidth = (2*this.SliderControlImageWidth); var tripleWidth = (3*this.SliderControlImageWidth); var nextImgSrc = RICHFX.settings.sStaticServiceURL + "?profileId=12056150&file=skins/"+this.sSliderSkin+"/next-horizontal.png"; var prevImgSrc = RICHFX.settings.sStaticServiceURL + "?profileId=12056150&file=skins/"+this.sSliderSkin+"/prev-horizontal.png"; // Upadte images? if( this.sPrevImageMetadata != '' ) { prevImgSrc = this.sImageServiceURL+this.sSliderPrevImageMetadata; } if( this.sNextImageMetadata != '' ) { nextImgSrc = this.sImageServiceURL+this.sSliderNextImageMetadata; } // TMP for testing RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-horizontal', 'backgound-repeat: no-repeat'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-horizontal', 'backgound-position: 0 0'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-horizontal', 'background-image: url("'+nextImgSrc+'")'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-horizontal', 'backgound-repeat: no-repeat'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-horizontal', 'backgound-position: 0 0'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-horizontal', 'background-image: url("'+prevImgSrc+'")'); // Set control width & height RICHFX.jQuery('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-horizontal').css('width', this.SliderControlImageWidth+'px'); RICHFX.jQuery('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-horizontal').css('width', this.SliderControlImageWidth+'px'); RICHFX.jQuery('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-horizontal').css('height', this.SliderControlImageHeight+'px'); RICHFX.jQuery('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-horizontal').css('height', this.SliderControlImageHeight+'px'); // Add image menagement of horizontal controls RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-horizontal:hover', 'background-position: -'+this.SliderControlImageWidth+'px 0'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-horizontal:active', 'background-position: -'+doubleWidth+'px 0'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-horizontal.jcarousel-next-disabled-horizontal, ' + '.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-horizontal.jcarousel-next-disabled-horizontal:hover, ' + '.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-horizontal.jcarousel-next-disabled-horizontal:active', 'cursor: default; background-position: -'+tripleWidth+'px 0'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-horizontal:hover', 'background-position: -'+this.SliderControlImageWidth+'px 0'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-horizontal:active', 'background-position: -'+doubleWidth+'px 0'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-horizontal.jcarousel-prev-disabled-horizontal, ' + '.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-horizontal.jcarousel-prev-disabled-horizontal:hover, ' + '.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-horizontal.jcarousel-prev-disabled-horizontal:active', 'cursor: default; background-position: -'+tripleWidth+'px 0'); } else { var doubleHeight = (2*this.SliderControlImageHeight); var tripleHeight = (3*this.SliderControlImageHeight); var nextImgSrc = RICHFX.settings.sStaticServiceURL + "?profileId=12056150&file=skins/rfx1/next-vertical.png"; var prevImgSrc = RICHFX.settings.sStaticServiceURL + "?profileId=12056150&file=skins/rfx1/prev-vertical.png"; // Upadte images? if( this.sSliderPrevImageMetadata != '' ) { prevImgSrc = this.sImageServiceURL+this.sSliderPrevImageMetadata; } if( this.sNextImageMetadata != '' ) { nextImgSrc = this.sImageServiceURL+this.sSliderNextImageMetadata; } // TMP for testing RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-vertical', 'backgound-repeat: no-repeat'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-vertical', 'backgound-position: 0 0'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-vertical', 'background-image: url("'+nextImgDefault+'")'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-vertical', 'backgound-repeat: no-repeat'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-vertical', 'backgound-position: 0 0'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-vertical', 'background-image: url("'+prevImgDefault+'")'); // Set control width & height RICHFX.jQuery('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-vertical').css('width', this.SliderControlImageWidth+'px'); RICHFX.jQuery('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-vertical').css('width', this.SliderControlImageWidth+'px'); RICHFX.jQuery('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-vertical').css('height', this.SliderControlImageHeight+'px'); RICHFX.jQuery('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-vertical').css('height', this.SliderControlImageHeight+'px'); // Add image menagement of horizontal controls RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-vertical:hover', 'background-position: 0 -'+this.SliderControlImageWidth+'px'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderkin+' .jcarousel-next-vertical:active', 'background-position: 0 -'+doubleHeight+'px'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-vertical.jcarousel-next-disabled-vertical, ' + '.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-vertical.jcarousel-next-disabled-vertical:hover, ' + '.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-next-vertical.jcarousel-next-disabled-vertical:active', 'cursor: default; background-position: 0 -'+tripleHeight+'px'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-vertical:hover', 'background-position: 0 -'+this.SliderControlImageWidth+'px'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-vertical:active', 'background-position: 0 -'+doubleHeight+'px'); RICHFX.helpers.addCSSRule('.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-vertical.jcarousel-prev-disabled-vertical, ' + '.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-vertical.jcarousel-prev-disabled-vertical:hover, ' + '.jcarousel-skin-'+this.sSliderSkin+' .jcarousel-prev-vertical.jcarousel-prev-disabled-vertical:active', 'cursor: default; background-position: 0 -'+tripleHeight+'px'); } }, sliderCarouselCallback: function(carousel) { //console.log('managing events for: ' + carousel.options.id); // Unbind any bindings, so we dont continuously bind as we reset the slider RICHFX.jQuery('#'+carousel.options.id).unbind('scroll.carousel'); RICHFX.jQuery('#'+carousel.options.id).unbind('reset.carousel'); RICHFX.jQuery('#'+carousel.options.id).unbind('add.swatches.to.carousel'); RICHFX.jQuery('#'+carousel.options.id).unbind('add.views.to.carousel'); // Bind the carousel to reset - triggered from within ImageColorChange, but could be anywhere RICHFX.jQuery('#'+carousel.options.slider).bind('reset.carousel', function( evt ) { carousel.size(0); carousel.reset(); }); // Add items to the carousel - current added from within ImageColorChange RICHFX.jQuery('#'+carousel.options.slider).bind('add.swatches.to.carousel', function( evt, data ) { var items = data.items; var i = 1; var scrollTo = 1; for (var item in items) { carousel.add(i, items[item].swatchImage); if (data.swatch == items[item].swatchData.swatch) { scrollTo = i; } i++; } carousel.size(i>0?i-1:i); carousel.scroll(scrollTo, false); }); // Scroll to a particular item in the carousel RICHFX.jQuery('#'+carousel.options.slider).bind('scroll.carousel', function( evt, data ) { var scrollTo = data.scrollTo; carousel.scroll(scrollTo, false); }); // Add items to the carousel - current added from within ImageColorChange //TODO: We should be able to use just one binding to add either the swatches or the views, just pass in a flag or something to signify what we are adding RICHFX.jQuery('#'+carousel.options.slider).bind('add.views.to.carousel', function( evt, data ) { var items = data.items; var i = 1; var scrollTo = 1; //for (var item in items) { for ( var v in data.pXmlViewOrder ) { var item = data.pXmlViewOrder[v]; //console.log('Adding to Carousel: ' + i + ' | ' + item + ': ', items[item].viewImage); carousel.add(i, items[item].viewImage); if (data.view == items[item].swatchData.view) { scrollTo = i; } i++; } carousel.size(i>0?i-1:i); carousel.scroll(scrollTo, false); }); //RICHFX.jQuery('#'+carousel.options.slider).css('opacity', 1); RICHFX.jQuery('#'+carousel.options.slider).css('overflow-y', 'visible'); RICHFX.jQuery(document).trigger('slider.load.views'); }, loadData: function() { RICHFX.jQuery('#RICHFXViewerContainer_'+this.sViewerID).bind('imagecolorchange.load.images', {data: {'images': this.oSwatchImages}}, RICHFX.jQuery.proxy(function(evt){ this.loadImageObj(evt.data.data); }, this)); RICHFX[this.sLoadingType].oCallBacks['RICHFXViewerContainer_'+this.sViewerID+'_imageColorChange'] = {}; RICHFX[this.sLoadingType].oCallBacks['RICHFXViewerContainer_'+this.sViewerID+'_imageColorChange']['imagecolorchange.load.images'] = true; RICHFX[this.sLoadingType].loadCallBacks(this.iLoadingDistance); }, loadImageObj: function(evt) { // Event holds the images that we need to load var images = evt.images; if (images) { for (var v in images) { for (var s in images[v]) { // Only preload the images if the colorChange viewer is the only viewer if (images[v][s].largeImage) { // Had to create the image elements like this as Firefox and Chrome were not caching the images var cacheImage = document.createElement('img'); //cacheImage.src = RICHFX.jQuery(images[v][s].largeImage).attr('src'); cacheImage.src = images[v][s].largeImagePath; } // Load swatches if (images[v][s].swatchSrc) { var cacheImage = document.createElement('img'); cacheImage.src = images[v][s].swatchSrc; } // Load views if (images[v][s].viewSrc) { var cacheImage = document.createElement('img'); cacheImage.src = images[v][s].viewSrc; } } } } } };