2

I've implemented a tumblr post button following their docs, and the popup works great. However, I need to pass in an image URL that is dynamically created on the page, rather than hardcoding in an image url. I'm trying to do this with jQuery.

HOWEVER, the inline script required to launch the 'post' popup fires, and prevents my jQuery (being triggered by clicking the 'post' button) from firing. I tried moving the inline tumblr script to my js, which allowed my jQuery to fire, but not the tumblr popup.

Ideally, the inline script would fire AFTER my jQuery, since the jQuery is the bit that generates the image URL I need to pass in.

Is there a way to do this, maybe with onLoad or something?

My button, as generated by Tumblr is this (sorry I can't get it on multiple lines for some reason):

 <a class='tumblr-share-button' data-color='blue' data-notes='right' data-posttype='photo' data-content='image URL will go here' href='https://embed.tumblr.com/share'></a> <script>!function(d,s,id){var js,ajs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src='https://assets.tumblr.com/share-button.js';ajs.parentNode.insertBefore(js,ajs);}}(document, 'script', 'tumblr-js');</script>

And my jQuery (that is not executing) is:

$('.tumblr-share-button').click(function(e){
var svg = $("#svg")[0];
svg.toDataURL("image/png", {
    callback: function(img) {
    var img = img.replace("data:image/png;base64,", "");
    var imgurTitle = $("meta[property='og:title']").attr("content");
    $.ajax({ 
          url: 'https://api.imgur.com/3/image',
          headers: {'Authorization': 'Client-ID ******'},
          type: 'POST',
          data: {'image': img, 'type': 'base64', 'title': imgurTitle},
          success: function(result) { 
          imageURL = result.data.link;
          $('.tumblr-share-button').data('data-content',imageURL);
          },
          error: function(){
            console.log('error');
          }
    });
  }
  });
 });

Any help would be tremendously appreciated!!!

tx291
  • 1,251
  • 6
  • 24
  • 42

0 Answers0