Browse Source

Add views for popup

Gerald 10 years ago
parent
commit
1e65f18e2b

+ 0 - 0
src/options/cache.js → src/cache.js


+ 46 - 0
src/common.js

@@ -78,3 +78,49 @@ function format() {
   });
 }
 */
+
+var BaseView = Backbone.View.extend({
+  initialize: function () {
+    var _this = this;
+    var gotTemplate;
+    if (_this.templateUrl)
+      gotTemplate = _.cache.get(_this.templateUrl)
+      .then(function (fn) {
+        _this.templateFn = fn;
+      });
+    var render = _this.render.bind(_this);
+    var initI18n = _this.initI18n.bind(_this);
+    _this.render = function () {
+      gotTemplate
+        ? gotTemplate.then(render).then(initI18n)
+        : render();
+      return _this;
+    };
+    _this.render();
+  },
+  initI18n: function () {
+    _.forEach(this.$('[data-i18n]'), function (node) {
+      node.innerHTML = _.i18n(node.dataset.i18n);
+    });
+  },
+  getValue: function (target) {
+    var key = target.dataset.id;
+    var value;
+    switch (key[0]) {
+    case '!':
+      key = key.slice(1);
+      value = target.checked;
+      break;
+    case '[':
+      key = key.slice(1);
+      value = _.filter(target.value.split('\n').map(function (s) {return s.trim();}));
+      break;
+    default:
+      value = target.value;
+    }
+    return {
+      key: key,
+      value: value,
+    };
+  },
+});

+ 1 - 1
src/manifest.json

@@ -17,7 +17,7 @@
   "browser_action": {
     "default_icon": "images/icon19.png",
     "default_title": "__MSG_extName__",
-    "default_popup": "popup.html"
+    "default_popup": "popup/index.html"
   },
   "background": {
     "page": "background/index.html"

+ 6 - 6
src/options/index.html

@@ -5,19 +5,19 @@
     <title data-i18n="extName"></title>
     <link rel="shortcut icon" type="image/png" href="/images/icon16.png">
     <link rel="stylesheet" href="/lib/font-awesome/font-awesome.min.css">
-    <link rel="stylesheet" href="/options/style.css">
+    <link rel="stylesheet" href="style.css">
     <script src="/lib/zepto.min.js"></script>
     <script src="/lib/underscore-min.js"></script>
     <script src="/lib/backbone-min.js"></script>
     <script src="/lib/zip.js/zip.js"></script>
     <script src="/common.js"></script>
-    <script src="/options/cache.js"></script>
-    <script src="/options/view.js"></script>
-    <script src="/options/model.js"></script>
+    <script src="/cache.js"></script>
+    <script src="view.js"></script>
+    <script src="model.js"></script>
   </head>
   <body>
     <div id="app"></div>
-    <script src="/options/app.js"></script>
-    <script src="/options/editor.js"></script>
+    <script src="app.js"></script>
+    <script src="editor.js"></script>
   </body>
 </html>

+ 9 - 55
src/options/view.js

@@ -1,53 +1,7 @@
-var BaseView = Backbone.View.extend({
-  initialize: function () {
-    var _this = this;
-    var gotTemplate;
-    if (_this.templateUrl)
-      gotTemplate = _.cache.get(_this.templateUrl)
-      .then(function (fn) {
-        _this.templateFn = fn;
-      });
-    var render = _this.render.bind(_this);
-    var initI18n = _this.initI18n.bind(_this);
-    _this.render = function () {
-      gotTemplate
-        ? gotTemplate.then(render).then(initI18n)
-        : render();
-      return _this;
-    };
-    _this.render();
-  },
-  initI18n: function () {
-    _.forEach(this.$('[data-i18n]'), function (node) {
-      node.innerHTML = _.i18n(node.dataset.i18n);
-    });
-  },
-  getValue: function (target) {
-    var key = target.dataset.id;
-    var value;
-    switch (key[0]) {
-    case '!':
-      key = key.slice(1);
-      value = target.checked;
-      break;
-    case '[':
-      key = key.slice(1);
-      value = _.filter(target.value.split('\n').map(function (s) {return s.trim();}));
-      break;
-    default:
-      value = target.value;
-    }
-    return {
-      key: key,
-      value: value,
-    };
-  },
-});
-
 var DEFAULT_ICON = '/images/icon48.png';
 var ScriptView = BaseView.extend({
   className: 'script',
-  templateUrl: 'templates/script.html',
+  templateUrl: '/options/templates/script.html',
   events: {
     'click [data-id=edit]': 'onEdit',
     'click [data-id=remove]': 'onRemove',
@@ -145,7 +99,7 @@ var ScriptView = BaseView.extend({
 var MainTab = BaseView.extend({
   el: '#tab',
   name: 'main',
-  templateUrl: 'templates/tab-installed.html',
+  templateUrl: '/options/templates/tab-installed.html',
   events: {
     'click #bNew': 'newScript',
     'click #bUpdate': 'updateAll',
@@ -209,7 +163,7 @@ var MainTab = BaseView.extend({
 
 var ExportList = BaseView.extend({
   el: '.export-list',
-  templateUrl: 'templates/option.html',
+  templateUrl: '/options/templates/option.html',
   initialize: function () {
     BaseView.prototype.initialize.call(this);
     this.listenTo(scriptList, 'reset change', this.render);
@@ -251,7 +205,7 @@ var SettingsTab = BaseView.extend({
     'click #bExport': 'exportData',
     'click #bVacuum': 'onVacuum',
   },
-  templateUrl: 'templates/tab-settings.html',
+  templateUrl: '/options/templates/tab-settings.html',
   render: function () {
     var options = _.options.getAll();
     this.$el.html(this.templateFn(options));
@@ -448,7 +402,7 @@ var SettingsTab = BaseView.extend({
 var AboutTab = BaseView.extend({
   el: '#tab',
   name: 'about',
-  templateUrl: 'templates/tab-about.html',
+  templateUrl: '/options/templates/tab-about.html',
   render: function () {
     this.$el.html(this.templateFn());
     return this;
@@ -457,7 +411,7 @@ var AboutTab = BaseView.extend({
 
 var MainView = BaseView.extend({
   el: '#app',
-  templateUrl: 'templates/main.html',
+  templateUrl: '/options/templates/main.html',
   tabs: {
     '': MainTab,
     settings: SettingsTab,
@@ -484,7 +438,7 @@ var ConfirmView = BaseView.extend({
     'change [data-check]': 'updateCheckbox',
     'change #cbClose': 'updateClose',
   },
-  templateUrl: 'templates/confirm.html',
+  templateUrl: '/options/templates/confirm.html',
   initialize: function (url, _from) {
     this.url = url;
     this.from = _from;
@@ -666,7 +620,7 @@ var ConfirmView = BaseView.extend({
 
 var MetaView = BaseView.extend({
   className: 'button-panel',
-  templateUrl: 'templates/edit-meta.html',
+  templateUrl: '/options/templates/edit-meta.html',
   events: {
     'change [data-id]': 'onChange',
   },
@@ -688,7 +642,7 @@ var MetaView = BaseView.extend({
 
 var EditView = BaseView.extend({
   className: 'frame edit',
-  templateUrl: 'templates/edit.html',
+  templateUrl: '/options/templates/edit.html',
   events: {
     'click .button-toggle': 'toggleButton',
     'change [data-id]': 'updateCheckbox',

+ 0 - 24
src/popup.html

@@ -1,24 +0,0 @@
-<!DOCTYPE html>
-<html>
-	<head>
-		<meta charset="utf-8" />
-		<link rel="stylesheet" type="text/css" href="lib/font-awesome/font-awesome.min.css">
-		<!-- common:css -->
-		<link rel="stylesheet/less" type="text/css" href="style.less">
-		<script src="lib/less.min.js"></script>
-		<!-- endinject -->
-		<title>Popup Menu - Violentmonkey</title>
-	</head>
-	<body class=popup>
-		<div id=main>
-			<div class="menu ellipsis"></div>
-			<div class="menu ellipsis"></div>
-		</div>
-		<div class=hide id=commands>
-			<div class="menu ellipsis"></div>
-			<div class="menu ellipsis"></div>
-		</div>
-	</body>
-</html>
-<script src=common.js></script>
-<script src=popup.js></script>

+ 20 - 0
src/popup/index.html

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta charset="utf-8">
+		<title>Popup Menu - Violentmonkey</title>
+		<link rel="stylesheet" href="/lib/font-awesome/font-awesome.min.css">
+    <link rel="stylesheet" href="style.css">
+		<script src="/lib/zepto.min.js"></script>
+    <script src="/lib/underscore-min.js"></script>
+    <script src="/lib/backbone-min.js"></script>
+		<script src="/common.js"></script>
+    <script src="/cache.js"></script>
+    <script src="view.js"></script>
+    <script src="model.js"></script>
+	</head>
+  <body>
+    <div id="popup"></div>
+		<script src=popup.js></script>
+	</body>
+</html>

+ 0 - 0
src/popup.js → src/popup/popup.js


+ 0 - 0
src/popup/style.css


+ 2 - 0
src/popup/templates/list.html

@@ -0,0 +1,2 @@
+<div class="menu ellipsis"></div>
+<div class="menu ellipsis"></div>

+ 11 - 0
src/popup/view.js

@@ -0,0 +1,11 @@
+var MenuView = BaseView.extend({
+  templateUrl: '/popup/templates/list.html',
+  render: function () {
+  },
+});
+
+var CommandsView = BaseView.extend({
+  templateUrl: '/popup/templates/list.html',
+  render: function () {
+  },
+});