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

Shariff class not callable lately #34

Closed
neffets opened this issue Mar 3, 2015 · 9 comments
Closed

Shariff class not callable lately #34

neffets opened this issue Mar 3, 2015 · 9 comments

Comments

@neffets
Copy link

neffets commented Mar 3, 2015

Our pages include as a tag<div id="socialshare"></div> (from former socialshare-privacy plugin).
Before we could use after dom-ready a javascript-call:

$('#socialshare').socialSharePrivacy( settings );

Now all is encapsulated as anonymous functions.

How we can call it now at a later like any othe jquery-plugin

Not working was the initial code:

__Shariff($('#socialshare'), {theme:'white'})

How we can call the _Shariff function from extern javascript in a normal html-page (not a node-app)?

@pmb0
Copy link
Member

pmb0 commented Mar 3, 2015

Let me see if I understood your question. You replaced the old socialshare-privacy code with Shariff.

The socialshare-privacy documentation recommended using the script tag inside the <head> of your document.

In contrast to that, Shariff must be included right before the (closing) </body> tag to work. Have you followed that instruction?

@neffets
Copy link
Author

neffets commented Mar 3, 2015

Yes,
if I would have an <div class="shariff"></div> it would work that way.
My problem is,

  1. that the html-code has no class="shariff", i have an id=socialshare
  2. I want enable the Share-Buttons later, not at body-end, but only after dom-ready

Solution could be:

  1. on dom-ready I add with javascript the class=shariff to my div-with-id
    Now comes problem 2
  2. dom-ready ist later then body-end, I now want to trigger the shariff-code later, or better I want to give my $('#socialshare') as object to Shariff to paint the share-buttons there

@pmb0
Copy link
Member

pmb0 commented Mar 4, 2015

Embedding Shariff is difficult in your situation (not a node project, no .shariff element).

Try something like this:

<head>
$(function() {
    $("#socialshare").addClass("shariff");
    $.getScript("/path/to/shariff.js");
});
</head>

In my opinion modifying the HTML document is the best option.

@leegladding
Copy link

We had a problem using this too recently. Our project was also not a node project.

We had need to initialize the shariff code after it was loaded on to the page, to allow for later ajax'd content to include the sharing functionality. The way we fixed this was to assign the _Shariff function to the window object. This allowed us to call as and when we needed.

Is this something you could add to this project to allow the plugin to be used in this way as well?

@pmb0
Copy link
Member

pmb0 commented Apr 4, 2015

Just pushed a change that renames _Shariff to Shariff and that exports the Shariff class to the global (window) object:

27cd300#diff-f9e06b21d8f4ff0e3fd8301ee954ec47R236

This example html page shows how to initialize shariff after it was loaded:

https://github.com/heiseonline/shariff/blob/master/demo/custom-initialization.html

The change is not released yet.

@leegladding
Copy link

Looks great. Any idea when this might be released?

@pmb0
Copy link
Member

pmb0 commented Apr 7, 2015

Today or tomorrow.

@leegladding
Copy link

Perfect. Thanks for the update.

@pmb0
Copy link
Member

pmb0 commented Apr 8, 2015

Just released v1.9.1.

@pmb0 pmb0 closed this as completed Apr 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants