DHello Everyone,
I was able to successfully add a piece of JS to the site globally and successfully works.
I am reading through the articles presented on my post, and I am having trouble deploying some JS to the PDP.
My JS is embedded on the PDP and uses the model custom fields to pull and manipulate the page.
On my extension's module JS, I changed the layout from 'layout' to PDP and added my script. Is this the proper way to execute this script?
define(
'FAS.PDPJS.PDPm'
, [
'FAS.PDPJS.PDPm.View'
]
, function (
PDPmView
)
{
'use strict';
return {
mountToApp: function mountToApp (container)
{
// using the 'Layout' component we add a new child view inside the 'Header' existing view
// (there will be a DOM element with the HTML attribute data-view="Header.Logo")
// more documentation of the Extensibility API in
// https://system.netsuite.com/help/helpcenter/en_US/APIs/SuiteCommerce/Extensibility/Frontend/index.html
/** @type {LayoutComponent} */
var layout = container.getComponent('PDP');
if(layout)
{
//
console.log('PDP JS ACTIVE, PDPJS.PDPm');
//PDP JS
var ItemType="{{model.item.itemtype}}",NonInvtPartval="{{pageHeader}}",sparepart="{{model.item.custitem303}}",Accessory="{{model.item.custitem491}}",SeriesComp="{{model.item.custitem40}}",brand="Service"===ItemType?"FAS":"{{model.item.manufacturer}}";brand="/img/manufacturers/"+(brand=(brand=brand.replace(/\W+(?!$)/g,"-")).replace(/\W$/,""))+".png",$(".brand img").attr("src",brand),"NonInvtPart"===ItemType&&($(".reviewsdiv").addClass("d-none"),$(".ratingdiv").addClass("d-none"),$(".skudiv").addClass("d-none"),$(".ddesc h2").html("{{pageHeader}}")),"NonInvtPart"!==ItemType&&"Service"!=ItemType||($("#pdp .hdr-sect h1").attr("content",NonInvtPartval).html(NonInvtPartval),$("#skuu_{{model.item.internalid}}").text(NonInvtPartval),$(".product-detail-to-quote-add-to-quote").remove()),"InvtPart"===ItemType&&"false"===sparepart&&$(".flexwarranty").removeClass("d-none"),46<$("#pdp .hdr-sect h1").text().length&&$("#pdp .hdr-sect h1").css("font-size","2em"),71<$("#pdp .hdr-sect h1").text().length&&$("#pdp .hdr-sect h1").css("font-size","1.5em"),92<$("#pdp .hdr-sect h1").text().length&&$("#pdp .hdr-sect h1").css("font-size","1.25em"),120<$("#pdp .hdr-sect h1").text().length&&$("#pdp .hdr-sect h1").css("font-size","100%"),$(function(){var t=$(".t360").height(),d=$(".t360").width(),e=$(".imgdiv").height(),i=$(".imgdiv").width();t<e&&($(".t360").height(e),$(".t360").width(i)),e<t&&($(".imgdiv").height(t),$(".imgdiv").width(d))}),$(".btn-360").click(function(){$(".imgdiv").toggleClass("d-none"),$(".threesix").toggleClass("d-none"),$(".btn-360").toggleClass("btn-360s")}),$(".btn-close").click(function(){$(".imgdiv").toggleClass("d-none"),$(".threesix").toggleClass("d-none"),$(".btn-360").toggleClass("btn-360s")}),$(".fdbk").click(function(){var t="";"sb.flexibleassembly.com"===window.location.hostname&&(t="https://IDFF-sb1.extforms.netsuite.com/app/site/crm/externalcasepage.nl?compid=I&formid=31&h=AAFdikaIbjmuWO61YDfCUN_16y4LeP5Hmthq8dCYwriIrB5js8Q"),"www.flexibleassembly.com"===window.location.hostname&&(t="https://I.extforms.netsuite.com/app/site/crm/externalcasepage.nl?compid=ID&formid=31&h=AAFdikaIflDGyjiCb_4gxq4sOmWaZl3bw04UPELDY3UxdXhZtwk"),window.open(t,"Feedback Form","height=1140,width=600")});var vid0="{{model.item.custitemfeaturedvidsnippet}}",vid1="{{model.item.custitemvidtab1}}",vid2="{{model.item.custitemvidtab2}}",vid3="{{model.item.custitemvidtab3}}",vid4="{{model.item.custitemvidtab4}}",vid5="{{model.item.custitemvidtab5}}",vid6="{{model.item.custitemvidtab6}}";""===vid0&&(vid0=vid1),""===vid1&&(vid1=vid2),""===vid2&&(vid2=vid3),""===vid3&&(vid3=vid4),""===vid4&&(vid4=vid5),""===vid5&&(vid5=vid6),""==vid0&&""==vid1&&""==vid2&&""==vid3&&""==vid4&&""==vid5&&""==vid6&&$(".videos").addClass("d-none"),$(".vid0").click(function(){$(".ftvid iframe").attr("src","https://www.youtube.com/embed/"+vid0)}),$(".vid1").click(function(){$(".ftvid iframe").attr("src","https://www.youtube.com/embed/"+vid1)}),$(".vid2").click(function(){$(".ftvid iframe").attr("src","https://www.youtube.com/embed/"+vid2)}),$(".vid3").click(function(){$(".ftvid iframe").attr("src","https://www.youtube.com/embed/"+vid3)}),$(".vid4").click(function(){$(".ftvid iframe").attr("src","https://www.youtube.com/embed/"+vid4)}),$(".vid5").click(function(){$(".ftvid iframe").attr("src","https://www.youtube.com/embed/"+vid5)}),$(".vid6").click(function(){$(".ftvid iframe").attr("src","https://www.youtube.com/embed/"+vid6)});var numTdocs=$(".tdoc").length;numTdocs<1&&$(".tdocrq").removeClass("d-none");var techdoc1="{{model.item.custitem116}}",fndr1=techdoc1.indexOf("(")+1,fndr1=techdoc1.slice(fndr1,-1),techdoc2="{{model.item.custitem118}}",fndr2=techdoc2.indexOf("(")+1,fndr2=techdoc2.slice(fndr2,-1),techdoc3="{{model.item.custitem120}}",fndr3=techdoc3.indexOf("(")+1,fndr3=techdoc3.slice(fndr3,-1),techdoc4="{{model.item.custitem122}}",fndr4=techdoc4.indexOf("(")+1,fndr4=techdoc4.slice(fndr4,-1),techdoc5="{{model.item.custitem124}}",fndr5=techdoc5.indexOf("(")+1,fndr5=techdoc5.slice(fndr5,-1),techdoc6="{{model.item.custitem126}}",fndr6=techdoc6.indexOf("(")+1,fndr6=techdoc6.slice(fndr6,-1),pdfimg="/img/file-pdf.png",zipimg="/img/file-zip.png",genimg="/img/file-tech-doc.png";$(document).ready(function(){"PDF"===fndr1&&$(".tdoc1 a img").attr("src",pdfimg),"ZIP"===fndr1&&$(".tdoc1 a img").attr("src",zipimg),"PDF"!=fndr1&&"ZIP"!=fndr1&&$(".tdoc1 a img").attr("src",genimg),"PDF"===fndr2&&$(".tdoc2 a img").attr("src",pdfimg),"ZIP"===fndr2&&$(".tdoc2 a img").attr("src",zipimg),"PDF"!=fndr2&&"ZIP"!=fndr2&&$(".tdoc2 a img").attr("src",genimg),"PDF"===fndr3&&$(".tdoc3 a img").attr("src",pdfimg),"ZIP"===fndr3&&$(".tdoc3 a img").attr("src",zipimg),"PDF"!=fndr3&&"ZIP"!=fndr3&&$(".tdoc3 a img").attr("src",genimg),"PDF"===fndr4&&$(".tdoc4 a img").attr("src",pdfimg),"ZIP"===fndr4&&$(".tdoc4 a img").attr("src",zipimg),"PDF"!=fndr4&&"ZIP"!=fndr4&&$(".tdoc4 a img").attr("src",genimg),"PDF"===fndr5&&$(".tdoc5 a img").attr("src",pdfimg),"ZIP"===fndr5&&$(".tdoc5 a img").attr("src",zipimg),"PDF"!=fndr5&&"ZIP"!=fndr5&&$(".tdoc5 a img").attr("src",genimg),"PDF"===fndr6&&$(".tdoc6 a img").attr("src",pdfimg),"ZIP"===fndr6&&$(".tdoc6 a img").attr("src",zipimg),"PDF"!=fndr6&&"ZIP"!=fndr6&&$(".tdoc6 a img").attr("src",genimg)}),$(".custom-pdp-fields-line-container").addClass("row").addClass("tspec"),$(".custom-pdp-fields-label b").wrap('<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6"></div>'),$(".custom-pdp-fields-label span").wrap('<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6"></div>'),$(".tspec").removeClass("custom-pdp-fields-line-container"),$(".custom-pdp-fields-label").removeClass("custom-pdp-fields-label");var numTspecs=$(".tspec").length;numTspecs<5&&$(".tecrq").removeClass("d-none");
if(ItemType==='Service'){$('.warning-section').remove(); $('.tech_spec').remove();$('.flexwarranty-section-new').remove();$('.review-section').remove();$('.tabs-dropdown').text('Technical Documents');$('.tab-pane').removeClass('tab-active');$('.act_documents').addClass('tab-active');}
if(ItemType==='Assembly'){$('.flexwarranty-section-new').remove();}
if(ItemType==='InvtPart' && Accessory === 'true' ){$('.review-section').remove();}
if(ItemType==='InvtPart' && sparepart === 'true' ){$('.features-benefits-section').remove();$('.technical-information-section').remove();$('.review-section').remove();$('.flexwarranty-section-new').remove();
$('.storedetaileddescription').append('<p><b>Note:</b> This item is a spare part, spare parts are non-returnable/non-refundable</p>');$('#main-container').css('background','#F3F8FA');}
if(ItemType==='NonInvtPart'){
$('.flexwarranty-section-new').remove();
$('.prcsect').remove();
$('.product-details-full-actions').remove();
setTimeout(function () {
$('#models-section .bx-wrapper').removeAttr('style');
$('#models-section .bx-wrapper').removeClass('bx-wrapper');
$('#models-section .bx-viewport').removeAttr('aria-live');
$('#models-section .bx-viewport').removeAttr('style');
$('#models-section .bx-viewport').removeClass('bx-viewport');
$('#models-section .bx-clone').remove();
$('#models-section .bx-controls').remove();
$('#models-section ul').removeAttr('style');
$('#models-section ul').removeAttr('id');
$('#models-section ul.item-relations-row li').removeAttr('style');
$('#models-section ul.item-relations-row').removeAttr('style');
$('#models-section ul.item-relations-row').removeAttr('data-type');
$('#models-section ul.item-relations-row').removeClass('item-relations-row');
$('.related-product-section').remove();
if($('.if_price_avail .product-views-price-lead ').attr('data-rate') == 'Call for Price' ){
$('.if_price_avail_add').remove();
$('.related-items-main-div-inner-new-col5').addClass("models-available-left");
}
$('#models-section').show();
}, 1000);
}
function addItmm(byId) {
var byyId = byId;
var qtyID = "qtyQ" + byyId;
var buyQty = document.getElementById(qtyID).value;
if (buyQty > 0) {
var addCartURL ="/app/site/backend/additemtocart.nl?c=ID&n=1&qty="+buyQty+"&buyid="+byyId;
//alert(addCartURL);
location.href = addCartURL; setTimeout("showCart()",300)
} else {
alert("Fill in a quantity of the item then Add to Cart.")}
} // end fun
function showCart() {
location.href = cartURL;
}
// PDP JS 2
jQuery(document).ready(function() {
// Show the first tab and hide the rest
$(document).ready(function(){
$('.tab-a').click(function(){