Creating a "Plugin System" for my application

Creating a "Plugin System" for my application

Im creating an app that users can create plugins for in both PHP and jQuery. I had 2 questions about the jQuery plugin setup. Im using an observable design pattern I found online, somewhere on the jQuery site actually. Heres the code thus far:

The Observer:
  1. /**
    * @see https://api.jquery.com/jQuery.Callbacks/
    * @see http://addyosmani.com/resources/essentialjsdesignpatterns/book/#highlighter_506612
    */
    ;(function($) {
    var topics = [];

    function getTopic(id) {
    var callbacks;
    topic = id && topics[id];
    if (!topic) {
    callbacks = $.Callbacks();
    topic = {
    publish: callbacks.fire,
    subscribe: callbacks.add,
    unsubscribe: callbacks.remove
    };
    if (id) topics[id] = topic;
    }
    return topic;
    }

    $.observer = {
    publish: function(id) {
    var args = (2 <= arguments.length) ? Array.prototype.slice.call(arguments, 1) : [];
    var t = getTopic(id);
    return t.publish.apply(t, args);
    },
    subscribe: function(id, fn) {
    return getTopic(id).subscribe(fn);
    },
    unsubscribe: function(id, fn) {
    return getTopic(id).unsubscribe(fn);
    }
    };
    })(jQuery);
Creating Observable Object
  1. var $assets_dt = $assets_table.DataTable( {
    createdRow: function ( row, data, index ) {
    app.observable('assets.datatable.createrow', row, data, index);
    }
    } );

Example Usage: 
  1. /**
    * Color Tables functionality
    */
    color_tables = {
    /**
    * Criteria
    *
    * Rules of what colors to set for what columns
    *
    * @todo Allow regex and the ability to apply something that allows the user to specify when a cell ISNT a value
    */
    criteria: function() {
    var partition_id = $( '#data-table' ).data( 'partition-id' );

    var criteria = $.ajax( {
    type: "GET",
    url: '....smart_color.criteria.json',
    async: false,
    dataType: 'json'
    } ).responseText;

    var criteria_json = $.parseJSON(criteria);

    return criteria_json[ partition_id ] || false;
    },

    /**
    * Create Row
    *
    * Executes whenever the DataTables plugin initiates the tables and the rows are created (via JS, not PHP)
    *
    * @param row
    * @param data
    * @param index
    */
    create_row: function( row, data, index ) {
    var rules = color_tables.criteria();
    var highlight_rules = [];
    var i, add, classes;

    if(rules) {
    // Duplicate the rules array except the keys will be the column indexes in the table
    $.each( rules, function ( col, r ) {
    i = $( 'th#column-' + col ).index();

    highlight_rules[ i ] = r;
    } );
    //console.log('highlight rules: ', highlight_rules);

    $.each( data, function ( k, d ) {
    if ( k in highlight_rules ) {
    if ( $.isArray( highlight_rules[ k ].criteria ) ) {
    $.each( highlight_rules[ k ].criteria, function ( sk, ss ) {
    if ( data[ k ].match( new RegExp( ss ) ) ) {
    //$( 'td', row ).eq( k ).addClass( highlight_rules[k].class );
    if ( $.isArray( highlight_rules[ k ].classes ) ) {
    classes = highlight_rules[ k ].classes.join( ' ' );
    }
    else {
    classes = highlight_rules[ k ].classes;
    }

    $( 'td', row ).eq( k ).addClass( classes );
    }
    } );
    }
    else {
    if ( data[ k ].match( new RegExp( highlight_rules[ k ].criteria ) ) ) {
    //$( 'td', row ).eq( k ).addClass( highlight_rules[k].classes );
    if ( $.isArray( highlight_rules[ k ].classes ) ) {
    classes = highlight_rules[ k ].classes.join( ' ' );
    }
    else {
    classes = highlight_rules[ k ].classes;
    }

    $( 'td', row ).eq( k ).addClass( classes );
    }
    }
    }
    } );
    }
    }
    };

    // The initial assets table initiation
    $.observer.subscribe('assets.datatable.createrow', color_tables.create_row);



So that works decently well, I have 2 questions though...

  1. Is there a way to set this up so the observable functions can rather filter the data? Meaning if I wanted to create a plugin to do something basic like convert the username logged in to uppsercase, just run the username through a filter, and any plugins can filter out the data, but if no plugins are setup, just pass the data on as is
  2. As opposed to using the above method for plugins, should I just use custom events? Example: https://learn.jquery.com/events/introduction-to-custom-events/
Thanks!