Closed igal-getrailo closed 9 years ago
The answer on stackoverflow is misguided; pinit.js is specifically built to allow config requests to be passed by setting attributes on the SCRIPT tag. Here's one way:
(function(d) {
var s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '//assets.pinterest.com/js/pinit.js';
s.setAttribute('data-pin-hover', true);
var f = d.getElementsByTagName('SCRIPT')[0];
f.parentNode.insertBefore(f, s);
})(document);
Another reason this might be useful is to accomodate sites that want to host the Pinterest JavaScript and aggregate it into a single file / request with other JavaScript the page uses for optimal network usage. Calling the resulting resource "pinit.js" so it matches the regex would be unfortunate (and likely unsupported by most CMSs that aggregate a page's JavaScript in this fashion.)
True, once you're hosting the JS yourself, you can change it to obtain its configuration differently, but this makes any rigging up of automatic updates to the hosted JavaScript a more complex and brittle proposition.
What about reading these global configuration settings from the html
tag as well?
I'd be happy to look at a pull request that looked at the HTML tag for global configuration flags.
it'd be good to be able to set the data-pin-hover via script, for cases when the script is loaded via yepnope.js or Modernizr.
see http://stackoverflow.com/questions/23508120/set-options-when-loading-pinterest-asynchronously-with-modernizr for more details.