The jQuery Plugin Construct

The plugin function at core is what defines the order of initization. When the /blockstrap/js/blockstrap.js file is included in the header, the plugin functionality is called the moment the /defaults.json configuration file has been loaded, after which the following order of events then transpire:

As seen here:

function plugin(element, options, defaults)
{
    // MERGE DEFAULT AND PLUGIN OPTIONS
    var settings = $.extend({}, defaults, options);
    // THEN GET CONFIG FILE
    $.fn.blockstrap.core.get(bs_theme_config, 'json', function(results)
    {
        if($.isPlainObject(results))
        {
            $.fn.blockstrap.settings = $.extend({}, settings, results);
            $.fn.blockstrap.core.settings(element);
            $.fn.blockstrap.defaults();
            var bs = $.fn.blockstrap;
            var $bs = blockstrap_functions;
            var dependencies = $.fn.blockstrap.settings.dependencies;
            var modules = $.fn.blockstrap.settings.modules;
            // LOADING SCREEN
            // TODO: REMOVE FROM CORE...?
            // BETTER PLACED IN THEMES...?
            $.ajax({
                url: $.fn.blockstrap.settings.core_base + 'html/' + 'loading.html',
                dataType: 'HTML',
                type: 'GET',
                complete: function(results)
                {
                    var element = $.fn.blockstrap.element;
                    var id = $.fn.blockstrap.settings.content_id;
                    if($(element).find('#' + id).length < 1)
                    {
                        if(results)
                        {
                            if(results.responseText && results.responseText === '404')
                            {
                                // Do nothing!
                            }
                            else
                            {
                                var loading = results.responseText;
                                $($.fn.blockstrap.element).append(loading);
                            }
                        }
                    }
                }
            });
            // UPDATE CORE IF REQUIRED
            $bs.update(bs.settings.v, function()
            {
                // USE LESS.css ...?
                bs.core.less(function()
                {
                    // INSERT CSS
                    bs.core.css(function()
                    {
                        if($.isArray(dependencies))
                        {
                            // INCLUDE JS DEPENDENCIES
                            $bs.include(bs, 0, dependencies, function()
                            {
                                if($.isArray(modules))
                                {
                                    // INCLUDE JS MODULES
                                    $bs.include(bs, 0, modules, function()
                                    {
                                        bs.core.loaded();
                                    });
                                }
                                else
                                {
                                    bs.core.loaded();
                                }
                            }, true);
                        }
                        else
                        {
                            bs.core.loaded();
                        }
                    });
                });
            });
        }
    });
}

  1. Related Articles
  2. Return to Core
  3. Configuration Settings
  4. Defaults
  5. Core Functions
  6. Blockstrap Functions
  7. Plugin Construct
  8. Table of Contents