jQuery(function($) {

    var PhileoLikes = function(form, options) {
        this.options = $.extend({}, $.fn.phileo.defaults, options);
        this.$form = $(form);

        this.$count = $(this.options.count);

        var self = this;
        this.$form.submit(function(event) {
            event.preventDefault();

            $.ajax({
                url: self.$form.attr('action'),
                type: "POST",
                data: self.$form.serialize(),
                statusCode: {
                    200: function(data, textStatus, jqXHR) {
                        self.$count.text(data.likes_count);
                        self.$form[data.liked ? 'addClass' : 'removeClass'](self.options.toggle_class);
                    }
                }
            });
        });
    };

    $.fn.phileo = function(options) {
        $(this).each(function(i, el) {
            var phileo = new PhileoLikes(el, options);
            $(el).data('Phileo', {instance: phileo});
        });
        return this;
    };

    $.fn.phileo.defaults = {
        toggle_class: 'phileo-liked',
        count: false
    };
});

!function($){
    "use strict";

    var PhileoLikes = function(form, options) {
        this.options = $.extend({}, $.fn.phileo.defaults, options);
        this.$form = $(form);

        this.$count = $(this.options.count);

        var self = this;
        this.$form.submit(function(event) {
            event.preventDefault();

            $.ajax({
                url: self.$form.attr('action'),
                type: "POST",
                data: self.$form.serialize(),
                statusCode: {
                    200: function(data, textStatus, jqXHR) {
                        self.$count.text(data.likes_count);
                        self.$form[data.liked ? 'addClass' : 'removeClass'](self.options.toggle_class);
                    }
                }
            });
        });
    };

    $.fn.phileo = function(options) {
        $(this).each(function(i, el) {
            var phileo = new PhileoLikes(el, options);
            $(el).data('Phileo', {instance: phileo});
        });
        return this;
    };

    $.fn.phileo.defaults = {
        toggle_class: 'phileo-liked',
        count: false
    };
}( window.jQuery || window.ender );

Add jQuery plugin on page load, not domready
Add jQuery plugin on page load, not domready

The phileo plugin was added to jQuery in the domready event callback. As
this plugin could be loaded at the bottom of a page - AFTER phileo
widget scripts - it was possible for the phileo plugin to not be
loaded when the widgets were initialized in the domready event. As the
phileo plugin does not need the DOM to be ready to set itself up, the
plugin now loads as the page is loading. This allows phileo widgets to
be inserted before the phileo plugin script and for everything to still
work.
