var silkProduct = xb.core.object.extend( silkNodeStruct, { ctor: function( domNode ) { silkNodeStruct.prototype.ctor.call( this, domNode ); }, getPrice: function( postfix ) { var postfix = ( typeof( postfix ) === "undefined" ) ? "" : postfix; var name_i = "product-price-integral" + postfix; var name_f = "product-price-fractional" + postfix; var result = 0; var i = this.get( name_i ); var f = this.get( name_f ); if ( i !== null && f !== null ) { result = 1 * i.domNode.textContent + ( f.domNode.textContent / 100 ); } return result; }, setPrice: function( value, postfix ) { var postfix = ( typeof( postfix ) === "undefined" ) ? "" : postfix; var name_i = "product-price-integral" + postfix; var name_f = "product-price-fractional" + postfix; var i = this.get( name_i ); var f = this.get( name_f ); var price = ( new Number( value ) ).toFixed( 2 ).split( "." ); if ( i !== null ) { i.setValue( price[ 0 ] ); } if ( f !== null ) { f.setValue( price[ 1 ] ); } }, setProductOption: function( option ) { var option = ( typeof( option ) === "string" ) ? option : null; if ( option === null ) { return; } var variaties = this.get( "product-variaties-list" ); if ( variaties !== null ) { variaties.each( function() { var cell = this.get( "product-cell_1" ); if ( cell.domNode.textContent == option ) { $( cell.domNode ).addClass( "selected" ); } else { $( cell.domNode ).removeClass( "selected" ); } } ); this.setStatus(); } }, getProductOptionNode: function() { var variaties = this.get( "product-variaties-list" ); if ( variaties !== null ) { for ( var i = 0, il = variaties.childNodes.length; i < il; i++ ) { var row = variaties.childNodes[ i ]; var cell = row.get( "product-cell_1" ); if ( cell !== null ) { if ( $( cell.domNode ).hasClass( "selected" ) ) { return cell; } } } } return null; }, setLinks: function() { }, postRender: function() { // this.setPrice( this.getPrice() * 1.21, "-incl" ); this.setFBLink(); }, setFBLink: function() { var link = window.location.href; var fb = this.get( "product-link-facebook" ); if ( fb !== null ) { var fbl = "https://www.facebook.com/sharer/sharer.php?u="; fbl += encodeURIComponent( link ); fbl += "&src=sdkpreparse"; fb.domNode.href = fbl; } }, setStatus: function() { var variaties = this.get( "product-variaties-list" ); if ( variaties === null || variaties.childNodes.length === 0 ) { return; } var option = this.getProductOptionNode(); if ( option === null ) { $( this.domNode ).addClass( "thunderbirds-are-not-go" ); } else { $( this.domNode ).removeClass( "thunderbirds-are-not-go" ); } }, onRender: function() { this.postRender(); this.setStatus(); var self = this; }, onClick: function( evt ) { console.log( "Clicked me", this, evt.target ); if ( $( evt.target ).hasClass( "silk-elm text cell_1" ) ) { if ( $( evt.target ).parents( ".table-list.variaties-list" ).length ) { this.setProductOption( evt.target.textContent ); } } if ( $( evt.target ).hasClass( "basket-add" ) || $( evt.target ).parents( ".basket-add" ).length ) { return this.onAddToBasket( evt ); } if ( $( evt.target ).hasClass( "basket-order" ) || $( evt.target ).parents( ".basket-order" ).length ) { return this.onAddToBasket( evt, true ); } }, onAddToBasket: function( evt, checkout ) { evt.preventDefault(); if ( $( evt.target ).parents( ".thunderbirds-are-not-go" ).length ) { return false; } var checkout = ( typeof( checkout ) === "boolean" ) ? checkout : false; var optionValue = null; var option = this.getProductOptionNode(); if ( option !== null ) { optionValue = option.domNode.textContent; } var linkNode = $( this.domNode ).find( "[data-simply-field='product-link']" ); if ( linkNode.length ) { var link = linkNode[ 0 ].href; if ( link ) { silk.basket.add( link, { "amount": 1, "option": optionValue, "checkout": checkout } ); } } return true; }, onDOMChange: function( mutations ) { this.postRender(); } } ); var silkProductSummary = xb.core.object.extend( silkProduct, { onRender: function() { this.postRender(); var self = this; }, onClick: function( evt, list ) { if ( silkProduct.prototype.onClick.call( this, evt, list ) ) { return true; } if ( document.body.getAttribute( "data-simply-edit" ) === null ) { var link = this.get( "product-link" ); if ( link !== null ) { var path = link.domNode.pathname; if ( path[ 0 ] !== "/" ) { path = "/" + path; } if ( silk.navigation.goto( path ) ) { var view = $( ".silk-object.product.view" ); if ( view.length ) { $( document ).scrollTo( view[ 0 ] ); } return false; } var linkNode = this.get( "product-link" ); if ( linkNode !== null ) { var link = linkNode.domNode.href; window.location = link; return false; } return true; } } return true; } } );