diff --git a/client/js/controllers/page_controller.js b/client/js/controllers/page_controller.js index da30ec03..af1f8f2f 100644 --- a/client/js/controllers/page_controller.js +++ b/client/js/controllers/page_controller.js @@ -1,7 +1,7 @@ 'use strict'; const events = require('../events.js'); -const settingsController = require('./settings_controller.js'); +const settings = require('../settings.js'); const EndlessPageView = require('../views/endless_page_view.js'); const ManualPageView = require('../views/manual_page_view.js'); @@ -14,7 +14,7 @@ class PageController { } update() { - if (settingsController.getSettings().endlessScroll) { + if (settings.getSettings().endlessScroll) { this.pageView = new EndlessPageView(); } else { this.pageView = new ManualPageView(); diff --git a/client/js/controllers/settings_controller.js b/client/js/controllers/settings_controller.js index 51fe8bb5..777bf3ae 100644 --- a/client/js/controllers/settings_controller.js +++ b/client/js/controllers/settings_controller.js @@ -1,7 +1,7 @@ 'use strict'; const page = require('page'); -const events = require('../events.js'); +const settings = require('../settings.js'); const topNavController = require('../controllers/top_nav_controller.js'); const SettingsView = require('../views/settings_view.js'); @@ -17,38 +17,10 @@ class SettingsController { settingsRoute() { topNavController.activate('settings'); this.settingsView.render({ - getSettings: () => this.getSettings(), - saveSettings: newSettings => this.saveSettings(newSettings), + getSettings: () => settings.getSettings(), + saveSettings: newSettings => settings.saveSettings(newSettings), }); } - - saveSettings(browsingSettings) { - localStorage.setItem('settings', JSON.stringify(browsingSettings)); - events.notify(events.Success, 'Settings saved'); - events.notify(events.SettingsChange); - } - - getSettings(settings) { - const defaultSettings = { - endlessScroll: false, - }; - let ret = {}; - let userSettings = localStorage.getItem('settings'); - if (userSettings) { - userSettings = JSON.parse(userSettings); - } - if (!userSettings) { - userSettings = {}; - } - for (let key of Object.keys(defaultSettings)) { - if (key in userSettings) { - ret[key] = userSettings[key]; - } else { - ret[key] = defaultSettings[key]; - } - } - return ret; - } }; module.exports = new SettingsController(); diff --git a/client/js/settings.js b/client/js/settings.js new file mode 100644 index 00000000..21227765 --- /dev/null +++ b/client/js/settings.js @@ -0,0 +1,36 @@ +'use strict'; + +const events = require('./events.js'); + +function saveSettings(browsingSettings) { + localStorage.setItem('settings', JSON.stringify(browsingSettings)); + events.notify(events.Success, 'Settings saved'); + events.notify(events.SettingsChange); +} + +function getSettings(settings) { + const defaultSettings = { + endlessScroll: false, + }; + let ret = {}; + let userSettings = localStorage.getItem('settings'); + if (userSettings) { + userSettings = JSON.parse(userSettings); + } + if (!userSettings) { + userSettings = {}; + } + for (let key of Object.keys(defaultSettings)) { + if (key in userSettings) { + ret[key] = userSettings[key]; + } else { + ret[key] = defaultSettings[key]; + } + } + return ret; +} + +module.exports = { + getSettings: getSettings, + saveSettings: saveSettings, +};