Merge pull request #644 from ethereum/theme_switch
Multiple themes for access by browser sol theme-chooser.jspull/3094/head
commit
3beb255961
@ -0,0 +1,61 @@ |
||||
'use strict' |
||||
|
||||
function Storage (prefix) { |
||||
this.exists = function (name) { |
||||
return this.get(name) !== null |
||||
} |
||||
|
||||
this.get = function (name) { |
||||
return window.localStorage.getItem(prefix + name) |
||||
} |
||||
|
||||
this.set = function (name, content) { |
||||
try { |
||||
window.localStorage.setItem(prefix + name, content) |
||||
} catch (exception) { |
||||
return false |
||||
} |
||||
return true |
||||
} |
||||
|
||||
this.remove = function (name) { |
||||
window.localStorage.removeItem(prefix + name) |
||||
return true |
||||
} |
||||
|
||||
this.rename = function (originalName, newName) { |
||||
var content = this.get(originalName) |
||||
if (!this.set(newName, content)) { |
||||
return false |
||||
} |
||||
this.remove(originalName) |
||||
return true |
||||
} |
||||
|
||||
function safeKeys () { |
||||
// NOTE: this is a workaround for some browsers
|
||||
return Object.keys(window.localStorage).filter(function (item) { return item !== null && item !== undefined }) |
||||
} |
||||
|
||||
this.keys = function () { |
||||
return safeKeys() |
||||
// filter any names not including the prefix
|
||||
.filter(function (item) { return item.indexOf(prefix, 0) === 0 }) |
||||
// remove prefix from filename and add the 'browser' path
|
||||
.map(function (item) { return item.substr(prefix.length) }) |
||||
} |
||||
|
||||
// on startup, upgrade the old storage layout
|
||||
safeKeys().forEach(function (name) { |
||||
if (name.indexOf('sol-cache-file-', 0) === 0) { |
||||
var content = window.localStorage.getItem(name) |
||||
window.localStorage.setItem(name.replace(/^sol-cache-file-/, 'sol:'), content) |
||||
window.localStorage.removeItem(name) |
||||
} |
||||
}) |
||||
|
||||
// remove obsolete key
|
||||
window.localStorage.removeItem('editor-size-cache') |
||||
} |
||||
|
||||
module.exports = Storage |
@ -1,8 +1,6 @@ |
||||
// var csjs = require('csjs-inject')
|
||||
module.exports = styleGuideDark |
||||
|
||||
module.exports = styleGuide |
||||
|
||||
function styleGuide () { |
||||
function styleGuideDark () { |
||||
/* -------------------------------------------------------------------------- |
||||
|
||||
CSS PROPERTIES |
@ -0,0 +1,31 @@ |
||||
// var remixLib = require('remix-lib')
|
||||
var styleGuideLight = require('./style-guide') |
||||
var styleGuideDark = require('./styleGuideDark') |
||||
var Storage = require('../storage') |
||||
module.exports = { |
||||
|
||||
chooser: function () { |
||||
var themeStorage = new Storage('style:') |
||||
if (themeStorage.exists('theme')) { |
||||
if (themeStorage.get('theme') === 'dark') { |
||||
return styleGuideDark() |
||||
} else { |
||||
return styleGuideLight() |
||||
} |
||||
} else { |
||||
return styleGuideLight() |
||||
} |
||||
}, |
||||
|
||||
switchTheme: function (theme) { |
||||
var themeStorage = new Storage('style:') |
||||
themeStorage.set('theme', theme) |
||||
if (theme === 'dark') { |
||||
return styleGuideDark() |
||||
} else if (theme === 'light') { |
||||
return styleGuideLight() |
||||
} else { |
||||
return styleGuideLight() |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue