Search code examples
javascriptsocial-networkingyammer

Two different Yammer share buttons on the same page


Is it possible to add two different Yammer share buttons to the same page?

Using the documentation from Yammer I was able to add two buttons to the same page, but they still point to the same url (http://example.com/button2 with the following configuration).

  yam.platform.yammerShare({
    customButton: true,
    classSelector: 'button1',
    pageUrl: 'http://example.com/button1'
  });
  yam.platform.yammerShare({
    customButton: true,
    classSelector: 'button2',
    pageUrl: 'http://example.com/button2'
  });

I also set up a full Plunker here.


Solution

  • Turns out there's an API to the event handler itself, so I could do the binding myself and gained the required flexibility:

    document.getElementsByClassName('button1')[0].addEventListener('click', function() {
      yam.platform.yammerShareOpenPopup({
        defaultMessage: 'Check out'
        pageUrl: 'http://example.com/button1
      });
    });
    document.getElementsByClassName('button2')[0].addEventListener('click', function() {
      yam.platform.yammerShareOpenPopup({
        defaultMessage: 'Check out',
        pageUrl: 'http://example.com/button2'
      });
    });
    

    This is also simpler when the urls are required to change, e.g. due to client-side routing. Check out a full Plunker here.