diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-04-17 12:12:22 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-04-17 12:12:22 +0300 |
| commit | 68fc9e55e538e03f94509731ab41a0c8cf96710f (patch) | |
| tree | 3edb1e81864ac3eb35ba0fe8087ed24da1b812bf /html/assets/js/require/AttributePlugin.js | |
| parent | 84b2da85a1b452922dadb6a609533b9945afe51d (diff) | |
| download | classroom-68fc9e55e538e03f94509731ab41a0c8cf96710f.tar.gz classroom-68fc9e55e538e03f94509731ab41a0c8cf96710f.tar.bz2 classroom-68fc9e55e538e03f94509731ab41a0c8cf96710f.zip | |
setup a real server environment (apache DocumentRoot=/var/www/public)
Diffstat (limited to 'html/assets/js/require/AttributePlugin.js')
| -rw-r--r-- | html/assets/js/require/AttributePlugin.js | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/html/assets/js/require/AttributePlugin.js b/html/assets/js/require/AttributePlugin.js deleted file mode 100644 index d0568a2..0000000 --- a/html/assets/js/require/AttributePlugin.js +++ /dev/null @@ -1,138 +0,0 @@ -require('jQuery', function ($) { - - function debounce(func, wait, immediate) { - var timeout; - return function () { - var context = this, args = arguments; - var later = function () { - timeout = null; - if (!immediate) func.apply(context, args); - }; - var callNow = immediate && !timeout; - clearTimeout(timeout); - timeout = setTimeout(later, wait); - if (callNow) func.apply(context, args); - }; - }; - - function init($element, pluginName, pluginConfiguration, callback) { - if (typeof (pluginName) === 'undefined') { - return; - } - - require([pluginName], function (plugin) { - if (typeof (plugin) === 'undefined') { - throw 'plugin ' + pluginName + ' is undefined'; - } - plugin($element, pluginConfiguration); - }); - } - - - var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/; - function parseOptions(data, element) { - if (data === "true") { - return true; - } - - if (data === "false") { - return false; - } - - if (data === "null") { - return null; - } - - // Only convert to a number if it doesn't change the string - if (data === +data + "") { - return +data; - } - - if (rbrace.test(data)) { - return tryParseJson(data, element); - } - - return data; - } - function tryParseJson(json, element) { - try { - return JSON.parse(json) - } - catch (err) { - console.warn(element, 'error during parsing of json', json, err); - return json; - } - } - - function attach($container) { - $container.find('*').addBack().each(function () { - var domNode = this; - var attributeNamePrefix = "data-plugin-"; - var plugins = []; - var initialized = domNode.initializedPlugins = (domNode.initializedPlugins || {}); - var $element = $(this); - for (var i = 0; i < domNode.attributes.length; i++) { - var attribute = domNode.attributes[i]; - - if (attribute.name.indexOf(attributeNamePrefix) != 0) { - continue; - } - if (initialized[attribute.name]) { - continue; - } - - var plugin = { name: attribute.name.substring(attributeNamePrefix.length), options: parseOptions(attribute.value, domNode) }; - init($element, plugin.name, plugin.options); - initialized[attribute.name] = true; - } - }); - } - $.fn.parseAttributePlugins = function () { - attach($(this)); - return $(this); - }; - var attachFn = debounce(function () { - attach($('body')); - }, 100); - - $(function () { - attachFn(); - }); - $('body').on('contentInjected', function (e) { - attachFn(); - }); - $.defineAttributePlugin = function (pluginName, dependencies, plugin) { - if (typeof (plugin) == 'undefined') { - plugin = dependencies; - dependencies = []; - } - define(pluginName, dependencies, function () { - var dependencyValues = arguments; - if (dependencies.length) { - return function ($element, options) { - var args = [$element, options]; - for (var i = 0; i < dependencyValues.length; i++) { - args.push(dependencyValues[i]); - } - - plugin.apply(this, args); - }; - } - return function ($element, options) { - - plugin($element, options); - }; - }); - }; - - $.fn.executePlugin = function (pluginName, pluginConfiguration, callback) { - return $(this).each(function () { - var $element = $(this); - init($element, pluginName, pluginConfiguration, function () { - if (typeof (callback) !== 'undefined') { - callback.apply($element, []); - } - }); - }); - }; -});
\ No newline at end of file |
