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

Dealing with persistence? #19

Closed
benlk opened this issue Mar 29, 2017 · 1 comment
Closed

Dealing with persistence? #19

benlk opened this issue Mar 29, 2017 · 1 comment

Comments

@benlk
Copy link
Collaborator

benlk commented Mar 29, 2017

Sometimes you need a different embed code, like the Seamus ones:

<div id="responsive-embed-budget_by_dollar"></div>
<script type=text/javascript>
    (function(jQuery) {
        if (typeof jQuery !== 'undefined' && typeof jQuery.getScript === 'function') {
            // add randomness to id to support for multiple graphic instances in one story
            var el = document.getElementById("responsive-embed-budget_by_dollar");
            el.id = el.id + "-" + Math.random().toString(36).substr(2,5);
            jQuery.getScript("//pym.nprapps.org/pym.v1.min.js").done(function () {
                jQuery(function () { // Wait for page load
                    var pymParent = new pym.Parent(
                        el.id,
                        'http://f.benlk.com/graphics/budget_by_dollar/child.html',
                        {}
                    );

                    jQuery.getScript("//carebot.nprapps.org/carebot-tracker.v0.min.js").done(function () {
                        var tracker = new CarebotTracker.VisibilityTracker(el.id, function(result) {
                            // Ignore Carebot events to empty embeds, keeps listening after unloading the page
                            if (pymParent.el.getElementsByTagName('iframe').length !== 0) {
                                pymParent.sendMessage('on-screen', result.bucket);
                            }
                        });
                        // Check if there is already an scroll tracker somewhere on the page
                        if (!document.querySelector("[data-carebot-scroll]")) {
                            pymParent.el.setAttribute("data-carebot-scroll", "");
                            var scrollTracker = new CarebotTracker.ScrollTracker('storytext', function(percent, seconds) {
                                // Ignore Carebot events to empty embeds, keeps listening after unloading the page
                                if (pymParent.el.getElementsByTagName('iframe').length !== 0) {
                                    pymParent.sendMessage('scroll-depth', JSON.stringify({percent: percent,seconds: seconds}));
                                }
                            });
                        }
                    });

                });
            });
        } else {
            console.error('could not load graphic: jQuery is not on the page.');
        }
    })(window.jQuery);
</script> 

Do we want this plugin to handle that? Do we want to make a different plugin, supporting the same shortcode, that does a different type of initialization?

@benlk
Copy link
Collaborator Author

benlk commented Apr 5, 2017

This plugin can handle different types of predefined embeds if:

  • add an admin page allowing choosing between different types of embed codes
  • set the default to the current embed code type, so that nothing changes.

This can handle different types of user-defined embed scripts if:

  • embeds are generated by callbacks
  • there exists a filter in the admin page allowing theme/plugin devs to add new callback options

This embed-type setting would have to be plugin-wide, probably limited to admins, and we wouldn't want to encourage people to mess with the default.

If we need to change the default embed code in the future, without updating older installs' embed codes, we can start saving an on-install version number for this plugin in the options table, and then in a subsequent release only change the default to use new embed codes if the on-install version number is greater than x or some such.

@benlk benlk mentioned this issue Feb 14, 2018
10 tasks
@benlk benlk closed this as completed in 0003fed Aug 31, 2018
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

1 participant