[0]ホーム
so we must enable childList to be notified of our actual target mutations to descendants such as changing the value of an existing style attribute don't fire unless subtree is enabled */var reviewWrapHeightConfig = reviewWrapHeightConfig || {attributes:true,childList:true,subtree:true};// Create instance of MutationObservervar reviewWrapObserver = reviewWrapObserver || new MutationObserver(reviewWrapHeightCallback);// Track how many times this javascript is loadedvar reviewWrapObservers = reviewWrapObservers || 0;// Callback to get body and start MutationObserver (body tag does not exist in page when script is first added to page)var startReviewWrapObserver = startReviewWrapObserver || function(){ // Get body if we haven't already var reviewWrapHeightTarget = reviewWrapHeightTarget || document.querySelector("body"); // Start mutation observer reviewWrapObserver.observe(reviewWrapHeightTarget,reviewWrapHeightConfig);};// Increment script load counter, first load should == 1reviewWrapObservers++;if(reviewWrapObservers == 1){ // Start when dom ready document.addEventListener('DOMContentLoaded',startReviewWrapObserver);}/** * Add a child to $el by calling $el.html(...) * @param $el required, the element that the child will be added to * @param tag required, the tag for the element that will be added * @param css required, the value of the class attribute of the element * @param html optional, the body of the element that will be added * @param attrs optional, additional attributes for the element that will be added, css and html will be ignored * @return the new child */function addChildTo($el,tag,css,html,attrs){ if(typeof html != 'undefined' && html != null && html != '') { $el.html(`<${tag}>${html}${tag}>`); } else { $el.html(`<${tag}>${tag}>`); } css = css.replace(' ','.'); const $new = $el.find(`${tag}.${css}`); if(typeof attrs != 'undefined') { for(const [key, value] of Object.entries(attrs)) { if(key != 'html' && key != 'css') { $new.attr(key,value); } } } return $new;}/** * Append a child to $el with no body whose only attribute is class * @param $el required, the element that the child will be appended to * @param tag required, the tag of the element that will be appended * @param css required, the value of class attribute for the element that will be appended * @return the new child */function appendChildTo($el,tag,css){ $el.append(`<${tag}>${tag}>`); css = css.replace(' ','.'); return $el.find(`${tag}.${css}`);}/** * Create be the first html for elements that do not exist in catalog of TurnTo Account * @param $el required, the element to create "be the first" html in */function noReviews($el){ const attrs = { div:{css:'tt-c-reviews-summary__no-reivews'}, heading:{css:'tt-c-reviews-summary__heading tt-u-mb--xs',role:'heading','aria-level':2,html:'No Ratings'}, body:{css:'tt-c-reviews-summary__no-reivews-body tt-u-spacing--md'}, p:{css:'tt-c-reviews-summary__no-review-text',html:'Be the first to review this item'} }; const $noReviews = addChildTo($el,'div',attrs.div.css); const $heading = addChildTo($noReviews,'div',attrs.heading.css,attrs.heading.html,attrs.heading); const $body = appendChildTo($noReviews,'div',attrs.body.css); addChildTo($body,'p',attrs.p.css,attrs.p.html);}/*]]>*/