Closed igrigorik closed 12 years ago
Hi Ilya, this is great :)
I've since moved extra widgets into an extensions
folder rather than in the core socialite.js
, so if you could submit this as socialite.hackernews.js
that would be much appreciated (I'm looking towards a build tool in the future).
Before you do, there is a problem with loading multiple instances, see my demo here. Because the script has already loaded and activated the first instance, nothing happens to the others.
To fix this you could use Socialite.reloadNetwork()
like I do with Buffer App extension but that's really a last resort. Better yet, as the author of hn.js
you could expose iframe creation to perhaps window.HN.render(contextElement)
. Then it's simply a case of adding 'activate' to your widget:
Socialite.widget('hackernews', 'share', {
/* ... */
activate: function(instance) {
if (window.HN) {
window.HN.render(instance.el);
}
}
});
Or something like that. If window.HN
doesn't exist, the script is still loading and the instance will be swept up and rendered automatically, otherwise the script has already loaded and we can trigger a render immediately. If you could do this method that would be amazing!
As a side note you don't need to set widget.intype
. That was just a shortcut for LinkedIn so multiple widgets could share the same init function.
Should be good to go - I think. :)
Perfect. Well it passed my whirlwind 2 minute browser testing (IE8 and Firefox 3.6)
The button in the actual iframe looks a bit ropey in IE7 but since this is Hacker News we're talking about I shouldn't think that kind of support is required ;)
Thanks!
https://github.com/igrigorik/hackernews-button
Works as advertised, the only caveat is that above widget doesn't have a "large" widget like the other demo plugins. Otherwise, this does the trick: