summaryrefslogtreecommitdiff
path: root/html/content/lib/require/AttributePlugin.js
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-12 23:57:48 +0200
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-12 23:57:48 +0200
commit7aa203150fc1a2ec79c681c13f0d486d531746eb (patch)
treef09ba9f69ccd434e9c7fdeb41807fc8008784d8a /html/content/lib/require/AttributePlugin.js
parent221af3a2e035bd6689294509feb52f286d3bd5be (diff)
downloadclassroom-7aa203150fc1a2ec79c681c13f0d486d531746eb.tar.gz
classroom-7aa203150fc1a2ec79c681c13f0d486d531746eb.tar.bz2
classroom-7aa203150fc1a2ec79c681c13f0d486d531746eb.zip
error pages; js system to support back/front-end
Diffstat (limited to 'html/content/lib/require/AttributePlugin.js')
-rw-r--r--html/content/lib/require/AttributePlugin.js138
1 files changed, 0 insertions, 138 deletions
diff --git a/html/content/lib/require/AttributePlugin.js b/html/content/lib/require/AttributePlugin.js
deleted file mode 100644
index 79dc5af..0000000
--- a/html/content/lib/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