@@ -4,11 +4,6 @@ import { ajaxShowMessage } from './ajax-message.ts';
44import isStorageSupported from './functions/isStorageSupported.ts' ;
55import formatDateTime from './functions/formatDateTime.ts' ;
66
7- /**
8- * Functions used in configuration forms and on user preferences pages
9- */
10- const Config = { } ;
11-
127window . configInlineParams ;
138window . configScriptLoaded ;
149
@@ -138,7 +133,7 @@ function getFieldValue (field, fieldType) {
138133 *
139134 * @return {object }
140135 */
141- Config . getAllValues = ( ) => {
136+ function getAllValues ( ) {
142137 var $elements = $ ( 'fieldset input, fieldset select, fieldset textarea' ) ;
143138 var values = { } ;
144139 var type ;
@@ -155,7 +150,7 @@ Config.getAllValues = () => {
155150 }
156151 }
157152 return values ;
158- } ;
153+ }
159154
160155/**
161156 * Checks whether field has its default value
@@ -197,9 +192,9 @@ function checkFieldDefault (field, type) {
197192 *
198193 * @return {string }
199194 */
200- Config . getIdPrefix = function ( element ) {
195+ function getIdPrefix ( element ) {
201196 return $ ( element ) . attr ( 'id' ) . replace ( / [ ^ - ] + $ / , '' ) ;
202- } ;
197+ }
203198
204199// ------------------------------------------------------------------
205200// Form validation and field operations
@@ -300,7 +295,7 @@ window.validators = {
300295 * @param {boolean } onKeyUp whether fire on key up
301296 * @param {any[] } params validation function parameters
302297 */
303- Config . registerFieldValidator = ( id , type , onKeyUp , params ) => {
298+ function registerFieldValidator ( id , type , onKeyUp , params ) {
304299 if ( typeof window . validators [ type ] === 'undefined' ) {
305300 return ;
306301 }
@@ -310,7 +305,7 @@ Config.registerFieldValidator = (id, type, onKeyUp, params) => {
310305 if ( validate [ id ] . length === 0 ) {
311306 validate [ id ] . push ( [ type , params , onKeyUp ] ) ;
312307 }
313- } ;
308+ }
314309
315310/**
316311 * Returns validation functions associated with form field
@@ -350,7 +345,7 @@ function getFieldValidators (fieldId, onKeyUpOnly) {
350345 *
351346 * @param {object } errorList list of errors in the form {field id: error array}
352347 */
353- Config . displayErrors = function ( errorList ) {
348+ function displayErrors ( errorList ) {
354349 var tempIsEmpty = function ( item ) {
355350 return item !== '' ;
356351 } ;
@@ -398,7 +393,7 @@ Config.displayErrors = function (errorList) {
398393 $errorCnt . remove ( ) ;
399394 }
400395 }
401- } ;
396+ }
402397
403398/**
404399 * Validates fields and fieldsets and call displayError function as required
@@ -485,7 +480,7 @@ function validateFieldAndFieldset (field, isKeyUp) {
485480 Config . displayErrors ( errors ) ;
486481}
487482
488- Config . loadInlineConfig = ( ) => {
483+ function loadInlineConfig ( ) {
489484 if ( ! Array . isArray ( window . configInlineParams ) ) {
490485 return ;
491486 }
@@ -494,9 +489,9 @@ Config.loadInlineConfig = () => {
494489 window . configInlineParams [ i ] ( ) ;
495490 }
496491 }
497- } ;
492+ }
498493
499- Config . setupValidation = function ( ) {
494+ function setupValidation ( ) {
500495 validate = { } ;
501496 window . configScriptLoaded = true ;
502497 if ( window . configScriptLoaded && typeof window . configInlineParams !== 'undefined' ) {
@@ -543,7 +538,7 @@ Config.setupValidation = function () {
543538 } else if ( $checkPageRefresh ) {
544539 $checkPageRefresh . val ( '1' ) ;
545540 }
546- } ;
541+ }
547542
548543//
549544// END: Form validation and field operations
@@ -576,7 +571,7 @@ function restoreField (fieldId): void {
576571 setFieldValue ( $field , getFieldType ( $field ) , window . defaultValues [ fieldId ] ) ;
577572}
578573
579- Config . setupRestoreField = function ( ) {
574+ function setupRestoreField ( ) {
580575 $ ( 'div.tab-content' )
581576 . on ( 'mouseenter' , '.restore-default, .set-value' , function ( ) {
582577 $ ( this ) . css ( 'opacity' , 1 ) ;
@@ -601,7 +596,7 @@ Config.setupRestoreField = function () {
601596 . find ( '.restore-default, .set-value' )
602597 // inline-block for IE so opacity inheritance works
603598 . css ( { display : 'inline-block' , opacity : 0.25 } ) ;
604- } ;
599+ }
605600
606601//
607602// END: "Restore default" and "set value" buttons
@@ -693,7 +688,7 @@ function offerPrefsAutoimport () {
693688/**
694689 * @return {function }
695690 */
696- Config . off = function ( ) {
691+ function off ( ) {
697692 return function ( ) {
698693 $ ( '.optbox input[id], .optbox select[id], .optbox textarea[id]' ) . off ( 'change' ) . off ( 'keyup' ) ;
699694 $ ( '.optbox input[type=button][name=submit_reset]' ) . off ( 'click' ) ;
@@ -703,12 +698,12 @@ Config.off = function () {
703698 $ ( document ) . off ( 'click' , 'div.click-hide-message' ) ;
704699 $ ( '#prefs_autoload' ) . find ( 'a' ) . off ( 'click' ) ;
705700 } ;
706- } ;
701+ }
707702
708703/**
709704 * @return {function }
710705 */
711- Config . on = function ( ) {
706+ function on ( ) {
712707 return function ( ) {
713708 var $topmenuUpt = $ ( '#user_prefs_tabs' ) ;
714709 $topmenuUpt . find ( 'a.active' ) . attr ( 'rel' , 'samepage' ) ;
@@ -786,6 +781,21 @@ Config.on = function () {
786781 $ ( this ) . parent ( '.card-body' ) . find ( '.prefs-form' ) . show ( ) ;
787782 } ) ;
788783 } ;
784+ }
785+
786+ /**
787+ * Used in configuration forms and on user preferences pages
788+ */
789+ const Config = {
790+ getAllValues : getAllValues ,
791+ getIdPrefix : getIdPrefix ,
792+ registerFieldValidator : registerFieldValidator ,
793+ displayErrors : displayErrors ,
794+ loadInlineConfig : loadInlineConfig ,
795+ setupValidation : setupValidation ,
796+ setupRestoreField : setupRestoreField ,
797+ off : off ,
798+ on : on ,
789799} ;
790800
791801window . Config = Config ;
0 commit comments