intanpalupidn / jquery-oembed

Automatically exported from code.google.com/p/jquery-oembed
0 stars 0 forks source link

Added new embedMethod #12

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hey Just wanted to share something I put together that worked more for 
what I need. Maybe it'll be useful to someone else... (Also, I pulled some 
logic out of the switch statement and put it into a new method in the 
plugin to use between the cases)

    $.fn.oembed.insertCode = function(container, embedMethod, oembed) 
{
        if (oembed == null)
            return;
        switch(embedMethod)
        {
            case "auto":
                if (container.attr("href") != null) {
                    insertCode(container, "append", oembed);
                }
                else {
                    insertCode(container, "replace", oembed);
                };
                break;
            case "replace":
                container.replaceWith(oembed.code);
                break;
            case "fill":
                container.html(oembed.code);
                break;
            case "append":
                var oembedContainer = this.getOembedContainer(container, 
oembed);
                oembedContainer.html(oembed.code);
                break;
            case "annotate":
                var oembedContainer = 
this.getOembedContainer(container, oembed);
                oembedContainer.html(oembed.code + '<span 
class="source">' + container.html() +
                '</span>');
                container.replaceWith(oembedContainer);
                break;
        }
    }

    $.fn.oembed.getOembedContainer = function(container, oembed) {
        var oembedContainer = container.next();
        if (oembedContainer == null || 
!oembedContainer.hasClass("oembed-container")) {
            oembedContainer = container
                .after('<div class="oembed-container"></div>')
                .next(".oembed-container");
            if (oembed != null && oembed.provider_name != null)
                oembedContainer.toggleClass("oembed-container-" + 
oembed.provider_name);
        }
        return oembedContainer;
    }

Original issue reported on code.google.com by pointles...@gmail.com on 17 Feb 2010 at 10:19

GoogleCodeExporter commented 8 years ago
If the insert methods don't fit you, you can use a callback function to control 
the 
HTML produced. See the "flickr-callback-example.html".

<script type="text/javascript">
    $(document).ready(function() {
        $(".oembed").oembed(null, null, function(container, oembed) {
            container
                .hide()
                .after("<table><tr><td>" + oembed.code + "</td><td>" 
+ oembed.code + "</tr></table>");
        });
    });
</script>

Original comment by rchamo...@gmail.com on 15 Mar 2010 at 10:29