pixel-editor/js/_settings.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

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: '#0000FF'
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
on('click', 'save-settings', function (){
2020-04-04 10:41:56 +03:00
//check if values are valid
if (isNaN(getValue('setting-numberOfHistoryStates'))) {
alert('Invalid value for numberOfHistoryStates');
return;
}
//save new settings to settings object
settings.numberOfHistoryStates = getValue('setting-numberOfHistoryStates');
settings.pixelGridColour = 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
closeDialogue();
});