Javascript / Events References

  • Updated

This guide describes how to make further modifications to the Main Widget using Javascript. This may require a listening event to ensure JS is properly run after the Widget has loaded.


In This Guide


Adding The Listening Event Code

Add this JS function to listen for events fired by Stamped:

function addEventListenerStamped(el, eventName, handler) { 
   if (el.addEventListener) { el.addEventListener(eventName, handler); }
   else { el.attachEvent('on' + eventName, function () { handler.call(el); }); } 
}

// Listening for event
addEventListenerStamped(document, '##replaceWithEventName##', function(e) {
  console.log(e);
});

// Example
// Listening for reviews widget loaded event
addEventListenerStamped(document, 'stamped:reviews:loaded', function(e) {
  console.log(e);
});

Events

Event Name Fired When
stamped:reviews:submitted Review is submitted through the widget form
stamped:reviews:loaded Reviews main widget loaded
stamped:questions:loaded Q&A section loaded in main widget
stamped:ugcmodal:paged stamped:ugcmodal:open Pop-up modal loaded/on page change
stamped:photo:uploaded Photo/video uploaded on main widget submission form

JS Methods

Script Function
StampedFn.reloadUGC(); Reloads all widgets on the page including Main Widgets and Display Widgets
(example use case: change the data-product-id attribute value in the Main Widget, and call this method to reload the reviews)
StampedFn.loadBadges(); Reloads the star ratings widget with classname ".stamped-product-reviews-badge"
StampedFn.toggleForm('review') Toggle the visibility of the review form
StampedFn.toggleForm('question')

Toggle the visibility of the question form

 

Was this article helpful?

0 out of 9 found this helpful

Have more questions? Submit a request