mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
first commit
This commit is contained in:
45
js/_settings.js
Normal file
45
js/_settings.js
Normal file
@ -0,0 +1,45 @@
|
||||
var settings;
|
||||
|
||||
if (!Cookies.enabled) {
|
||||
document.getElementById('cookies-disabled-warning').style.display = 'block';
|
||||
}
|
||||
|
||||
//try to load settings from cookie
|
||||
var settingsFromCookie = Cookies.get('pixelEditorSettings');
|
||||
if(!settingsFromCookie) {
|
||||
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
|
||||
};
|
||||
}
|
||||
else{
|
||||
console.log('settings cookie found');
|
||||
console.log(settingsFromCookie);
|
||||
var settings = JSON.parse(settingsFromCookie);
|
||||
}
|
||||
console.log(settings);
|
||||
|
||||
//on clicking the save button in the settings dialog
|
||||
on('click', 'save-settings', function (){
|
||||
|
||||
//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');
|
||||
|
||||
//save settings object to cookie
|
||||
var cookieValue = JSON.stringify(settings);
|
||||
Cookies.set('pixelEditorSettings', cookieValue, { expires: Infinity });
|
||||
|
||||
//close window
|
||||
closeDialogue();
|
||||
});
|
Reference in New Issue
Block a user