2021-07-22 20:26:40 +03:00
|
|
|
// REFACTOR: convert to IIFE
|
2019-03-27 02:20:54 +03:00
|
|
|
var settings;
|
|
|
|
|
|
|
|
if (!Cookies.enabled) {
|
2020-04-04 10:41:56 +03:00
|
|
|
document.getElementById('cookies-disabled-warning').style.display = 'block';
|
2019-03-27 02:20:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//try to load settings from cookie
|
|
|
|
var settingsFromCookie = Cookies.get('pixelEditorSettings');
|
|
|
|
if(!settingsFromCookie) {
|
2020-04-04 10:41:56 +03:00
|
|
|
console.log('settings cookie not found');
|
|
|
|
settings = {
|
|
|
|
switchToChangedColor: true,
|
|
|
|
enableDynamicCursorOutline: true, //unused - performance
|
|
|
|
enableBrushPreview: true, //unused - performance
|
|
|
|
enableEyedropperPreview: true, //unused - performance
|
|
|
|
numberOfHistoryStates: 20,
|
2020-09-29 20:10:50 +03:00
|
|
|
maxColorsOnImportedImage: 128,
|
2021-07-07 03:42:11 +03:00
|
|
|
pixelGridColour: '#000000'
|
2020-04-04 10:41:56 +03:00
|
|
|
};
|
2019-03-27 02:20:54 +03:00
|
|
|
}
|
|
|
|
else{
|
2020-04-04 10:41:56 +03:00
|
|
|
console.log('settings cookie found');
|
|
|
|
console.log(settingsFromCookie);
|
|
|
|
var settings = JSON.parse(settingsFromCookie);
|
2019-03-27 02:20:54 +03:00
|
|
|
}
|
|
|
|
console.log(settings);
|
|
|
|
|
|
|
|
//on clicking the save button in the settings dialog
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', 'save-settings', saveSettings);
|
2019-03-27 02:20:54 +03:00
|
|
|
|
2021-01-08 18:20:39 +03:00
|
|
|
function saveSettings() {
|
2020-04-04 10:41:56 +03:00
|
|
|
//check if values are valid
|
2021-07-10 00:44:04 +03:00
|
|
|
if (isNaN(Util.getValue('setting-numberOfHistoryStates'))) {
|
2020-04-04 10:41:56 +03:00
|
|
|
alert('Invalid value for numberOfHistoryStates');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//save new settings to settings object
|
2021-07-10 00:44:04 +03:00
|
|
|
settings.numberOfHistoryStates = Util.getValue('setting-numberOfHistoryStates');
|
|
|
|
settings.pixelGridColour = Util.getValue('setting-pixelGridColour');
|
2020-09-29 20:10:50 +03:00
|
|
|
// Filling pixel grid again if colour changed
|
|
|
|
fillPixelGrid();
|
2020-04-04 10:41:56 +03:00
|
|
|
|
|
|
|
//save settings object to cookie
|
|
|
|
var cookieValue = JSON.stringify(settings);
|
|
|
|
Cookies.set('pixelEditorSettings', cookieValue, { expires: Infinity });
|
|
|
|
|
|
|
|
//close window
|
2021-07-14 00:40:23 +03:00
|
|
|
Dialogue.closeDialogue();
|
2021-01-08 18:20:39 +03:00
|
|
|
}
|