tmort / Socialite

Other
1.68k stars 163 forks source link

Hacker News share button #25

Closed igrigorik closed 12 years ago

igrigorik commented 12 years ago

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:

<li><a href="http://news.ycombinator.com/submit" class="socialite hackernews-share" data-url="http://socialitejs.com" rel="nofollow" target="_blank"><span class="vhidden">Share on Hacker News</span></a></li>
dbushell commented 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.

igrigorik commented 12 years ago

Should be good to go - I think. :)

dbushell commented 12 years ago

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!