heiseonline / shariff

👮 Shariff enables website users to share their favorite content without compromising their privacy.
http://ct.de/-2467514
MIT License
1.4k stars 177 forks source link

Shariff class not callable lately #34

Closed neffets closed 9 years ago

neffets commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

https://github.com/heiseonline/shariff/commit/27cd3004e441373ebf161fe032b2b6273842d942#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 commented 9 years ago

Looks great. Any idea when this might be released?

pmb0 commented 9 years ago

Today or tomorrow.

leegladding commented 9 years ago

Perfect. Thanks for the update.

pmb0 commented 9 years ago

Just released v1.9.1.