summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2025-08-07 17:49:29 +0200
committerSimon Rettberg2025-08-07 17:49:29 +0200
commitb08893c5decc54781d0d9d5fe3cc5c533b9dcb36 (patch)
treedb5c646f9dce0a09e52c53a89ce6006210fbf827
parentIgnore KG2-specific files (diff)
downloadslx-admin-b08893c5decc54781d0d9d5fe3cc5c533b9dcb36.tar.gz
slx-admin-b08893c5decc54781d0d9d5fe3cc5c533b9dcb36.tar.xz
slx-admin-b08893c5decc54781d0d9d5fe3cc5c533b9dcb36.zip
JS: Reorganize script to lower number of ready listeners
-rw-r--r--script/slx-fixes.js182
1 files changed, 91 insertions, 91 deletions
diff --git a/script/slx-fixes.js b/script/slx-fixes.js
index a06761e4..8f6515bc 100644
--- a/script/slx-fixes.js
+++ b/script/slx-fixes.js
@@ -1,27 +1,3 @@
-// Give file select dialogs a modern style and feel
-$(document).ready(function() {
- $(document).on('change', '.btn-file :file', function() {
- var input = $(this);
- if (input.parents('.disabled').length !== 0)
- return;
- var numFiles = input.get(0).files ? input.get(0).files.length : 1;
- var label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
- input.trigger('fileselect', [numFiles, label]);
- });
- $('.btn-file :file').on('fileselect', function(event, numFiles, label) {
- var input = $(this).parents('.upload-ex').find(':text');
- var log = numFiles > 1 ? numFiles + ' files selected' : label;
- if (input.length) {
- input.val(log);
- }
- });
- $('.upload-ex :text').click(function () {
- var $this = $(this);
- if ($this.parents('.disabled').length !== 0)
- return;
- $this.parents('.upload-ex').find(':file').click();
- });
-});
// Replace message query params in URL, so you won't see them again if you bookmark or share the link
if (history && history.replaceState && window && window.location && window.location.search && window.location.search.indexOf('message[]=') !== -1) {
@@ -38,13 +14,6 @@ if (history && history.replaceState && window && window.location && window.locat
history.replaceState(null, null, window.location.pathname + str);
}
-// Simple decollapse functionality for tables
-$(document).ready(function() {
- $('.slx-decollapse').click(function () {
- $(this).siblings('.collapse').removeClass('collapse');
- });
-});
-
// Show not-allowed cursor for disabled links (not in btn-group as it messes up the style)
$('a.disabled').each(function() {
var $this = $(this);
@@ -56,58 +25,103 @@ $('a.disabled').each(function() {
var slxModalConfirmHandler;
-// Modern confirmation dialogs using bootstrap modal
$(document).ready(function() {
- var $title, $body, $button, $modal = null, $cache = {};
- slxModalConfirmHandler = function (e) {
- e.preventDefault();
- e.stopImmediatePropagation();
- var $this = $(this);
- if ($modal === null) {
- $modal = $('<div class="modal fade" id="modal-autogen" tabindex="-1" role="dialog"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal">&times;</button>'
- + '<b id="modal-autogen-title"></b></div><div id="modal-autogen-body" class="modal-body"></div>'
- + '<div class="modal-footer"><button type="submit" id="modal-autogen-button" data-dismiss="modal"></button></div></div></div></div>');
- $('#mainpage').append($modal);
- $title = $('#modal-autogen-title');
- $body = $('#modal-autogen-body');
- $button = $('#modal-autogen-button');
+ // Give file select dialogs a modern style and feel
+ $(document).on('change', '.btn-file :file', function() {
+ var input = $(this);
+ if (input.parents('.disabled').length !== 0)
+ return;
+ var numFiles = input.get(0).files ? input.get(0).files.length : 1;
+ var label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
+ input.trigger('fileselect', [numFiles, label]);
+ });
+ $('.btn-file :file').on('fileselect', function(event, numFiles, label) {
+ var input = $(this).parents('.upload-ex').find(':text');
+ var log = numFiles > 1 ? numFiles + ' files selected' : label;
+ if (input.length) {
+ input.val(log);
}
- $title.text($this.data('title') || $this.text());
- $button.html($this.data('close') || $this.html()).attr('class', $this.attr('class')).removeClass('btn-xs btn-sm btn-lg').off('click').click(function() {
- // Click and reconnect click handler so pressing "back" on the next page works
- $this.off('click', slxModalConfirmHandler).click().click(slxModalConfirmHandler);
- });
- var $wat, str = $this.data('confirm');
- if (str.substr(0, 9) === '#confirm-') {
- if ($cache[str]) {
- $wat = $cache[str];
+ });
+ $('.upload-ex :text').click(function () {
+ var $this = $(this);
+ if ($this.parents('.disabled').length !== 0)
+ return;
+ $this.parents('.upload-ex').find(':file').click();
+ });
+
+ // Simple decollapse functionality for tables
+ $('.slx-decollapse').click(function () {
+ $(this).siblings('.collapse').removeClass('collapse');
+ });
+
+ // Modern confirmation dialogs using bootstrap modal
+ (function() {
+ var $title, $body, $button, $modal = null, $cache = {};
+ slxModalConfirmHandler = function (e) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ var $this = $(this);
+ if ($modal === null) {
+ $modal = $('<div class="modal fade" id="modal-autogen" tabindex="-1" role="dialog"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal">&times;</button>'
+ + '<b id="modal-autogen-title"></b></div><div id="modal-autogen-body" class="modal-body"></div>'
+ + '<div class="modal-footer"><button type="submit" id="modal-autogen-button" data-dismiss="modal"></button></div></div></div></div>');
+ $('#mainpage').append($modal);
+ $title = $('#modal-autogen-title');
+ $body = $('#modal-autogen-body');
+ $button = $('#modal-autogen-button');
+ }
+ $title.text($this.data('title') || $this.text());
+ $button.html($this.data('close') || $this.html()).attr('class', $this.attr('class')).removeClass('btn-xs btn-sm btn-lg').off('click').click(function () {
+ // Click and reconnect click handler so pressing "back" on the next page works
+ $this.off('click', slxModalConfirmHandler).click().click(slxModalConfirmHandler);
+ });
+ var $wat, str = $this.data('confirm');
+ if (str.substr(0, 9) === '#confirm-') {
+ if ($cache[str]) {
+ $wat = $cache[str];
+ } else {
+ $cache[str] = $wat = $(str).detach(); // .detach as $wat might contain elements with id attribute
+ }
+ $body.empty().append($wat.clone(true).removeClass('hidden collapse invisible'));
} else {
- $cache[str] = $wat = $(str).detach(); // .detach as $wat might contain elements with id attribute
+ $body.text(str);
}
- $body.empty().append($wat.clone(true).removeClass('hidden collapse invisible'));
- } else {
- $body.text(str);
+ $modal.modal();
+ };
+ $('button[data-confirm]').click(slxModalConfirmHandler);
+ })();
+
+ // Taskmanager callbacks for running tasks
+ (function() {
+ var slxCbCooldown = 0;
+ function slxCheckCallbacks() {
+ $.post('api.php?do=cb', {token: TOKEN}, function (data) {
+ if (data.indexOf('True') >= 0) {
+ slxCbCooldown += 1;
+ } else {
+ slxCbCooldown += 10;
+ }
+ if (slxCbCooldown < 30)
+ setTimeout(slxCheckCallbacks, slxCbCooldown * 1000);
+ }, 'text');
}
- $modal.modal();
- };
- $('button[data-confirm]').click(slxModalConfirmHandler);
-});
-// Taskmanager callbacks for running tasks
-$(document).ready(function() {
- var slxCbCooldown = 0;
- function slxCheckCallbacks() {
- $.post('api.php?do=cb', { token: TOKEN }, function(data) {
- if ( data.indexOf('True') >= 0 ) {
- slxCbCooldown += 1;
- } else {
- slxCbCooldown += 10;
- }
- if (slxCbCooldown < 30)
- setTimeout(slxCheckCallbacks, slxCbCooldown * 1000);
- }, 'text');
- }
- slxCheckCallbacks();
+ slxCheckCallbacks();
+ })();
+
+ // Restore tab state on refresh and add it to URL so copying URLs works
+ (function() {
+ if ($('a[data-toggle="tab"]').click(function (e) {
+ history.pushState(null, null, this.getAttribute('href'));
+ }).length === 0) return;
+ var initTab = $('li.active > a[data-toggle="tab"]').attr('href');
+ var bla = function () {
+ var h = location.hash || initTab;
+ $('a[data-toggle="tab"][href="' + h + '"]').tab('show');
+ };
+ bla();
+ $(window).on('popstate', bla);
+ })();
});
// Caching script fetcher (https://api.jquery.com/jQuery.getScript/); use exactly like $.getScript
@@ -125,17 +139,3 @@ jQuery.cachedScript = function(url, callback, options) {
});
return jQuery.ajax( options );
};
-
-// Restore tab state on refresh and add it to URL so copying URLs works
-$(document).ready(function() {
- if ($('a[data-toggle="tab"]').click(function (e) {
- history.pushState(null, null, this.getAttribute('href'));
- }).length === 0) return;
- var initTab = $('li.active > a[data-toggle="tab"]').attr('href');
- var bla = function() {
- var h = location.hash || initTab;
- $('a[data-toggle="tab"][href="' + h + '"]').tab('show');
- };
- bla();
- $(window).on('popstate', bla);
-});