Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate count from element data #52

Open
otterslide opened this issue Mar 17, 2016 · 6 comments
Open

Populate count from element data #52

otterslide opened this issue Mar 17, 2016 · 6 comments

Comments

@otterslide
Copy link

I'm looking for a way to populate count directly through HTML.

Something like
<div class="share" data-facebook-count="2" data-pinterest-count="4"> etc.

Any ideas appreciated.. I don't really want to modify the jssocials.js to do this, but I think there is no other way?
It would be nice if there was some function I could override to achieve this.

Thanks a lot for any help!

@otterslide
Copy link
Author

I was able to figure it out based on the answer to another issue for opening a popup on click.

I just changed the _loadCount logic to return the count from the element data. In case anyone is ever interested:
<div data-cnt="1,2,3,4,5" class="share">


 _loadCount: function(share) {
            var deferred = $.Deferred();
            var cnt = this._$element.data('cnt').split(",");

            var idx = 0;
            if(share.share=="googleplus") idx =0;
            else if(share.share=="pinterest") idx =1;
            else if(share.share=="facebook") idx =2;
            else if(share.share=="twitter") idx =3;
            else if(share.share=="email") idx =4;

            return deferred.resolve(cnt[idx]).promise();
        },

Really flexible plugin, thanks to all the developers.

@Ruud68
Copy link
Contributor

Ruud68 commented Mar 18, 2016

Hi, what is the advantage / your use case for doing it this way?

@otterslide
Copy link
Author

Usually most people need only one share item, but I have a page with 15 of them. It's a summary of other pages on my site that can be shared. It doesn't make sense to let the client retrieve 5 different counts for 15 items, they will have to request 75 URLs. That's a lot of load on mobile data for mobile users, and will slow everything down. If I keep my own counts in my database, I can provide them with the page load and speed up the load time significantly.

@tabalinas
Copy link
Owner

Thanks for the feedback and sharing your use case. I'll consider having some mechanism to get shares count out of control.

@Ruud68
Copy link
Contributor

Ruud68 commented Mar 19, 2016

Hi, I have two use cases for my Joomla! plugin that involves multiple buttons on a page:

  1. Blog page that has the buttons on top, bottom and somewhere in the text
  2. a overview page of blogs where on that page the buttons are placed below or in the displayed intro text of those listed blogs.

The difference between these two is that for 1. all counts should be the same as they count the actual page they are displayed at (the url for all button sets is the same). For 2 the counts are different as they do not display the counts of the page they are displayed on, but count the shares of the url they are pointing to.

What would be a performance gain (not sure if this is already implemented or not) would be for case 1 to only once retrieve the counts and then for every consequent placement of the buttons re-use these counts on that page. Some sort of caching of the counts for a specific url.

Here is an example of case 1: Multiple buttons on one page pointing to same url > https://www.lerendeleiders.nl/persoonlijk-leiderschap/464-nlp-de-weg-van-excellentie
and case 2: multiple buttons pointing to different url's > https://www.lerendeleiders.nl/

Hope this helps :)

@tergra
Copy link

tergra commented Nov 16, 2016

@otterslide I have the same use case as yours. So did you finally manage to put all the counts in your database to retrieve them faster ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants