2020-11-18 09:11:12 +00:00
|
|
|
/**
|
2020-11-18 10:51:22 +00:00
|
|
|
* @class Settings
|
2020-11-18 09:11:12 +00:00
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function Settings() {
|
|
|
|
this.hideHelpDialogue = this.loadBoolean( 'hide-help-dialogue' );
|
|
|
|
this.autoExpand = this.loadBoolean( 'autoexpand' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$.extend( Settings.prototype, {
|
2016-10-20 14:35:13 +00:00
|
|
|
/**
|
2020-11-18 09:11:12 +00:00
|
|
|
* @type {boolean}
|
2016-10-20 14:35:13 +00:00
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
hideHelpDialogue: null,
|
2016-10-20 14:35:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
autoExpand: null,
|
2016-10-20 14:35:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
shouldHideHelpDialogue: function () {
|
|
|
|
return this.hideHelpDialogue;
|
|
|
|
},
|
2016-10-20 14:35:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
shouldAutoExpand: function () {
|
|
|
|
return this.autoExpand;
|
|
|
|
},
|
2016-10-20 14:35:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @param {boolean} newSetting
|
|
|
|
*/
|
|
|
|
setHideHelpDialogue: function ( newSetting ) {
|
|
|
|
if ( newSetting !== this.hideHelpDialogue ) {
|
|
|
|
this.saveBoolean( 'hide-help-dialogue', newSetting );
|
|
|
|
this.hideHelpDialogue = newSetting;
|
|
|
|
}
|
|
|
|
},
|
2016-10-20 14:35:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @param {boolean} newSetting
|
|
|
|
*/
|
|
|
|
setAutoExpand: function ( newSetting ) {
|
|
|
|
if ( newSetting !== this.autoExpand ) {
|
|
|
|
this.saveBoolean( 'autoexpand', newSetting );
|
|
|
|
this.autoExpand = newSetting;
|
|
|
|
}
|
|
|
|
},
|
2016-10-20 14:35:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {string} name
|
|
|
|
* @param {string} defaultValue
|
|
|
|
* @return {string|boolean}
|
|
|
|
*/
|
|
|
|
loadSetting: function ( name, defaultValue ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
let setting;
|
2023-05-20 12:40:43 +00:00
|
|
|
if ( mw.user.isNamed() ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
setting = mw.user.options.get( 'userjs-revslider-' + name );
|
|
|
|
} else {
|
2023-08-25 14:23:18 +00:00
|
|
|
setting = mw.storage.get( 'mw-revslider-' + name ) ||
|
|
|
|
mw.cookie.get( '-revslider-' + name );
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
2016-10-20 14:35:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
return setting !== null && setting !== false ? setting : defaultValue;
|
|
|
|
},
|
2016-10-20 14:35:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {string} name
|
|
|
|
* @param {boolean} [defaultValue]
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
loadBoolean: function ( name, defaultValue ) {
|
|
|
|
return this.loadSetting( name, defaultValue ? '1' : '0' ) === '1';
|
|
|
|
},
|
2016-10-20 14:35:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {string} name
|
|
|
|
* @param {string} value
|
|
|
|
*/
|
|
|
|
saveSetting: function ( name, value ) {
|
2023-05-20 12:40:43 +00:00
|
|
|
if ( mw.user.isNamed() ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
( new mw.Api() ).saveOption( 'userjs-revslider-' + name, value );
|
|
|
|
} else {
|
|
|
|
if ( !mw.storage.set( 'mw-revslider-' + name, value ) ) {
|
|
|
|
mw.cookie.set( '-revslider-' + name, value ); // use cookie when localStorage is not available
|
2016-10-20 14:35:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {string} name
|
|
|
|
* @param {boolean} value
|
|
|
|
*/
|
|
|
|
saveBoolean: function ( name, value ) {
|
|
|
|
this.saveSetting( name, value ? '1' : '0' );
|
|
|
|
}
|
|
|
|
} );
|
2016-10-20 14:35:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
module.exports = Settings;
|