pixel-editor/js/_settings.js

51 lines
1.6 KiB
JavaScript
Raw Normal View History

// 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,
maxColorsOnImportedImage: 128,
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
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
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
settings.numberOfHistoryStates = Util.getValue('setting-numberOfHistoryStates');
settings.pixelGridColour = Util.getValue('setting-pixelGridColour');
// 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
Dialogue.closeDialogue();
2021-01-08 18:20:39 +03:00
}