瀏覽代碼

Rename options setting to compiler

simov 8 年之前
父節點
當前提交
662e998d12
共有 3 個文件被更改,包括 23 次插入19 次删除
  1. 11 7
      background/background.js
  2. 2 2
      background/markdown.js
  3. 10 10
      content/popup.js

+ 11 - 7
background/background.js

@@ -6,7 +6,7 @@ chrome.storage.sync.get((res) => {
   var match = '.*\\/.*\\.(?:markdown|mdown|mkdn|md|mkd|mdwn|mdtxt|mdtext|text)(?:#.*)?$'
 
   var defaults = {
-    options: md.defaults,
+    compiler: md.defaults,
     theme: 'github',
     raw: false,
     match,
@@ -28,6 +28,10 @@ chrome.storage.sync.get((res) => {
   else if (!options.origins['file://']) {
     options.origins['file://'] = match
   }
+  // v2.4 -> v2.5
+  else if (!options.compiler) {
+    options.compiler = options.options
+  }
 
   chrome.storage.sync.set(options)
 
@@ -123,19 +127,19 @@ chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
     md.compile(req.markdown, sendResponse)
   }
   else if (req.message === 'settings') {
-    chrome.storage.sync.get(['options', 'theme', 'raw'], (res) => {
-      delete res.options.langPrefix
+    chrome.storage.sync.get(['compiler', 'theme', 'raw'], (res) => {
+      delete res.compiler.langPrefix
       sendResponse(res)
     })
   }
-  else if (req.message === 'options') {
-    req.options.langPrefix = 'language-' // prism
-    chrome.storage.sync.set({options: req.options}, sendResponse)
+  else if (req.message === 'compiler') {
+    req.compiler.langPrefix = 'language-' // prism
+    chrome.storage.sync.set({compiler: req.compiler}, sendResponse)
     sendMessage({message: 'reload'})
   }
   else if (req.message === 'defaults') {
     chrome.storage.sync.set(
-      {options: md.defaults, theme: 'github', raw: false}, sendResponse)
+      {compiler: md.defaults, theme: 'github', raw: false}, sendResponse)
     sendMessage({message: 'reload'})
   }
   else if (req.message === 'theme') {

+ 2 - 2
background/markdown.js

@@ -20,8 +20,8 @@ var md = (() => {
   }
 
   function compile (markdown, sendResponse) {
-    chrome.storage.sync.get((sync) => {
-      marked.setOptions(sync.options)
+    chrome.storage.sync.get((res) => {
+      marked.setOptions(res.compiler)
 
       marked(markdown, (err, html) => {
         if (err) throw err

+ 10 - 10
content/popup.js

@@ -1,17 +1,17 @@
 
 var state = {
-  options: [],
+  compiler: {},
   themes: [],
   theme: '',
   raw: false
 }
 
 var events = {
-  changeOptions: (e) => {
-    state.options[e.target.name] = !state.options[e.target.name]
+  changeCompiler: (e) => {
+    state.compiler[e.target.name] = !state.compiler[e.target.name]
     chrome.runtime.sendMessage({
-      message: 'options',
-      options: state.options
+      message: 'compiler',
+      compiler: state.compiler
     })
   },
 
@@ -56,7 +56,7 @@ var description = {
 }
 
 function init (res) {
-  state.options = res.options
+  state.compiler = res.compiler
   state.theme = res.theme
 
   state.themes = chrome.runtime.getManifest().web_accessible_resources
@@ -71,7 +71,7 @@ function oncreate (vnode) {
   componentHandler.upgradeElements(vnode.dom)
 }
 var onupdate = (key) => (vnode) => {
-  if (vnode.dom.classList.contains('is-checked') !== state.options[key]) {
+  if (vnode.dom.classList.contains('is-checked') !== state.compiler[key]) {
     vnode.dom.classList.toggle('is-checked')
   }
 }
@@ -105,14 +105,14 @@ m.mount(document.querySelector('body'), {
           m('a.mdl-tabs__tab', {href: '#tab-content'}, 'Content')
         ),
         m('.mdl-tabs__panel #tab-compiler', {class: 'is-active'},
-          m('.mdl-grid', Object.keys(state.options).map((key) =>
+          m('.mdl-grid', Object.keys(state.compiler).map((key) =>
             m('.mdl-cell',
               m('label.mdl-switch mdl-js-switch mdl-js-ripple-effect',
                 {oncreate, onupdate: onupdate(key), title: description[key]}, [
                 m('input[type="checkbox"].mdl-switch__input', {
                   name: key,
-                  checked: state.options[key],
-                  onchange: events.changeOptions
+                  checked: state.compiler[key],
+                  onchange: events.changeCompiler
                 }),
                 m('span.mdl-switch__label', key)
               ])