define('plugins.setup', ['plugins'], function (plugins) { var system = plugins.setup({ //the global attribute name prefix that hints the system //for a given plugin in a node attributeNamePrefix: "data-plugin", //This is a way to configure/extend all plugin instances. //The 'configuration' object will be available to all plugins //using the 'this.configuration' //You can return a promise (wrapping an xhr request or other async operations) preconfigure: function (ctx) { //ctx.configuration.someProperty = someValue; }, //the time (in seconds) that the system will wait before //it destroys a disconnected plugin. Default value is 10 idleTimeout: 10, //the time (in seconds) that the system will wait before //it starts processing discovered plugins. Default value is 10 processInterval: 10, //the time (in seconds) that the system will wait before //it triggers a cleanup cycle. Default value is 10 clearInterval: 10, //the attribute that hints the system to lazy load a node's plugins lazyLoadAttribute: 'plugins-lazy', //the margin of the IntersectionObserver //that detects when a lazy plugin should be registered lazyLoadRootMargin: '0px 0px 200px 0px', //the attribute that hints the system to ignore a node from //the plugin discovery phase ignoreAttribute: 'plugins-ignore', //predicate function to filter out a node from //the plugin discovery phase filter: function (node) { //ignore nodes with the v-plugin directive. Plugins will be initialized by the directive itself. //return node.getAttribute("v-plugin") === null; return true; }, //false if the automatic discovery of plugins is not desired observeDocument: true, // shouldLazyLoad: function (node, pluginOptions, lazyLoadAttributeName) { // return true; // } }), $ = window.jQuery, $$plugins = {}; system.use(function (context) { //system.moduleLoader.basePath = '/src/plugins/'; context.onCreate(function (instance) { if (instance.application.debug) { console.log(instance.definition.type, 'plugin instance created', instance.definition); } if (instance.application.debug) { instance.onDisconnect(logger("Disconnected")); instance.onConnect(logger("Connected")); instance.onDestroy(logger("Destroyed")); } function logger (msg){ return function (instance) { console.log(msg, instance.definition); } } }); context.moduleLoader = { load: function (pluginType, element) { return new Promise(function (resolve) { window.require(pluginType, resolve); }); } } $$plugins.execute = context.processor.initialize; $$plugins.parse = context.processor.process; $$plugins.define = function (pluginName, dependencies, plugin, invoke) { invoke = invoke || function (fn, args, context) { return fn.apply(context, args); } if (typeof (plugin) == 'undefined') { plugin = dependencies; dependencies = []; } define(pluginName, dependencies, function () { var dependencyValues = arguments; return function (element, options) { var args = [element, options], i; for (i = 0; i < dependencyValues.length; i++) { args.push(dependencyValues[i]); } return invoke(plugin, args, this); }; }); }; }); if ($) { $ = window.jQuery; $.defineAttributePlugin = function (pluginName, dependencies, plugin) { return $$plugins.define(pluginName, dependencies, plugin, function (fn, args, context){ args[0] = $(args[0]); return fn.apply(context, args); }); } $.fn.parseAttributePlugins = function () { return $(this).each(function () { $$plugins.parse([this]); }); }; $.fn.executePlugin = function (pluginName, pluginConfiguration, callback) { return $(this).each(function () { var $element = $(this); return $$plugins.execute(this, pluginName, pluginName, pluginConfiguration).then(function (resolved) { if (typeof (callback) !== 'undefined') { return callback.apply($element, [resolved]); } }); }); }; $.getOnce = function (options) { if (!window.getOnceCallbacks) { window.getOnceCallbacks = {}; } if (options.data) { var s = $.param(options.data, options.traditional); if (options.url.indexOf('?') == -1) { options.url += '?' + s; } else { options.url += '&' + s; } delete options.data; } if (window.getOnceCallbacks[options.url]) { window.getOnceCallbacks[options.url].push({ success: options.success, error: options.error }); return; } window.getOnceCallbacks[options.url] = [{ success: options.success, error: options.error }]; function done(m, a) { var callbacks = window.getOnceCallbacks[options.url]; for (var i = 0; i < callbacks.length; i++) { callbacks[i][m].apply(this, a); } delete window.getOnceCallbacks[options.url]; } options.success = function () { done.apply(this, ['success', arguments]); }; options.error = function () { done.apply(this, ['error', arguments]); }; $.ajax(options); } window.define.amd["jQuery"] = window.define.amd["jquery"] = { loaded: true, ready: true, object: $ }; } if (window.Vue) { window.define.amd["Vue"] = { loaded: true, ready: true, object: window.Vue }; } window.$$plugins = $$plugins; return system.initialize; }); require(['plugins.setup'], function (initialize) { var pluginsSystem = initialize(); pluginsSystem.application.debug = false; window.define.amd["plugins.system"] = { loaded: true, ready: true, object: pluginsSystem }; window.define.amd["application"] = { loaded: true, ready: true, object: pluginsSystem.application }; });