OSDN Git Service

js: modularize javascript codes
authorhylom <hylom@users.sourceforge.jp>
Wed, 1 Aug 2018 11:24:31 +0000 (20:24 +0900)
committerhylom <hylom@users.sourceforge.jp>
Wed, 1 Aug 2018 11:24:31 +0000 (20:24 +0900)
12 files changed:
src/newslash_web/public/js/ad-codes-editor.js
src/newslash_web/public/js/blocking-manager.js
src/newslash_web/public/js/boxes-editor.js
src/newslash_web/public/js/feeds-editor.js
src/newslash_web/public/js/index.js
src/newslash_web/public/js/login.js
src/newslash_web/public/js/newslash.js
src/newslash_web/public/js/submissions-manager.js
src/newslash_web/public/js/tag-editor.js
src/newslash_web/public/js/user-profile.js
src/newslash_web/public/js/user-settings.js
src/newslash_web/templates/admin/sidebar/index.html.tt2

index 5fe93f2..c3f59b9 100644 (file)
@@ -1,8 +1,8 @@
-/* sidebar_editor.js */
-const editor = {};
-var vm;
+/* ad-codes-editor.js */
+const adCodesEditor = {};
 
-editor.run = function run (params) {
+adCodesEditor.run = function run (params) {
+  var vm;
   const data = {
     message: '',
     adCodes: [],
@@ -19,7 +19,7 @@ editor.run = function run (params) {
         this.message = "save_failed";
         return;
       }
-        
+      
       const reqData = {
         name: target.name,
         description: target.description,
index 9586918..742522a 100644 (file)
@@ -1,8 +1,8 @@
 /* blocking-manager.js */
 const blockingManager = {};
-var vm;
 
 blockingManager.run = function run (params) {
+  var vm;
   const data = {
     message: '',
     items: [],
index 32d6610..d5c89b1 100644 (file)
@@ -1,56 +1,56 @@
-/* sidebar_editor.js */
-const editor = {};
-var vm;
+/* boxes-editor.js */
+const boxesEditor = {};
 
+boxesEditor.run = function run (params) {
 
-Vue.component('box-editor', {
-  template: '#box-editor',
-  props: {
-    box: Object,
-  },
-  data: function () {
-    return { message: "", };
-  },
-  computed: {
-    nameNg: function () { return !this.box.name.length; },
-  },
-  methods: {
-    save: function save() {
-      // create/update box
-      this.message = "";
-      newslash.admin.updateBox(this.box).then(
-        (response) => { // success
-          if (response.error) {
-            this.message = "error: " + response.message;
-            return;
-          }
-          if (!response.id) {
-            this.message = "error: " + response.message;
-            return;
-          }
-          this.message = "saved.";
-          if (this.box.id == 0) {
+  var vm;
+
+  Vue.component('box-editor', {
+    template: '#box-editor',
+    props: {
+      box: Object,
+    },
+    data: function () {
+      return { message: "", };
+    },
+    computed: {
+      nameNg: function () { return !this.box.name.length; },
+    },
+    methods: {
+      save: function save() {
+        // create/update box
+        this.message = "";
+        newslash.admin.updateBox(this.box).then(
+          (response) => { // success
+            if (response.error) {
+              this.message = "error: " + response.message;
+              return;
+            }
+            if (!response.id) {
+              this.message = "error: " + response.message;
+              return;
+            }
+            this.message = "saved.";
+            if (this.box.id == 0) {
               this.box.id = response.id;
+            }
+            this.box.edited = false;
+          },
+          (response) => { // fail
+            this.message = "error";
           }
-          this.box.edited = false;
-        },
-        (response) => { // fail
-          this.message = "error";
+        );
+      },
+      close: function close() {
+        this.box.editing = false;
+        this.message = "";
+        if (this.box.id == 0) {
+          vm.boxItems.pop();
         }
-      );
+      },
     },
-    close: function close() {
-      this.box.editing = false;
-      this.message = "";
-      if (this.box.id == 0) {
-        vm.boxItems.pop();
-      }
-    },
-  },
-});
-
+  });
 
-editor.run = function run (params) {
   const data = {
     message: '',
     boxItems: [],
index 0a3e5aa..b11ebbd 100644 (file)
@@ -1,83 +1,83 @@
-/* sidebar_editor.js */
+/* feeds-editor.js */
 var feedsEditor = {};
-var vm;
 
-Vue.component('feed-editor', {
-  template: '#feed-editor',
-  props: {
-    feed: Object,
-  },
-  data: function () {
-    return { message: "" };
-  },
-  methods: {
-    save: function save() {
-      // create/update feed
-      this.message = "";
-      var postData = {
-        action: this.feed.feed_id ? "update" : "create",
-        url: this.feed.url,
-        title: this.feed.title,
-        name: this.feed.name,
-        description: this.feed.description,
-        feed_id: this.feed.feed_id,
-      };
-      this.$http.post("/api/v1/admin/feed", postData).then(
-        (response) => { // success
-          if (response.body.error) {
-            this.message = "error: " + response.body.message;
-            return;
-          }
-          if (!response.body.feed_id) {
-            this.message = "error: " + response.body.message;
-            return;
-          }
-          this.message = "saved.";
-          if (this.feed.feed_id == 0) {
-              this.feed.feed_id = response.body.feed_id;
-          }
-        },
-        (response) => { // fail
-          this.message = "error";
-            return;
-        }
-      );
+feedsEditor.run = function run (params) {
+  var vm;
+
+  Vue.component('feed-editor', {
+    template: '#feed-editor',
+    props: {
+      feed: Object,
     },
-    close: function close() {
-      this.feed.editing = false;
-      this.message = "";
-      if (this.feed.feed_id == 0) {
-        vm.feeds.pop();
-      }
+    data: function () {
+      return { message: "" };
     },
-    fetch: function fetch() {
-      this.message = "";
-      var postData = {
-        action: "fetch",
-        url: this.feed.url,
-      };
-      this.$http.post("/api/v1/admin/feed", postData).then(
-        (response) => { // success
-          if (response.body.error) {
-            this.message = "error: " + response.body.message;
+    methods: {
+      save: function save() {
+        // create/update feed
+        this.message = "";
+        var postData = {
+          action: this.feed.feed_id ? "update" : "create",
+          url: this.feed.url,
+          title: this.feed.title,
+          name: this.feed.name,
+          description: this.feed.description,
+          feed_id: this.feed.feed_id,
+        };
+        this.$http.post("/api/v1/admin/feed", postData).then(
+          (response) => { // success
+            if (response.body.error) {
+              this.message = "error: " + response.body.message;
+              return;
+            }
+            if (!response.body.feed_id) {
+              this.message = "error: " + response.body.message;
+              return;
+            }
+            this.message = "saved.";
+            if (this.feed.feed_id == 0) {
+              this.feed.feed_id = response.body.feed_id;
+            }
+          },
+          (response) => { // fail
+            this.message = "error";
             return;
           }
-          this.feed.url = response.body.item.url;
-          this.feed.title = response.body.item.title;
-          this.feed.description = response.body.item.description;
-        },
-        (response) => { // fail
+        );
+      },
+      close: function close() {
+        this.feed.editing = false;
+        this.message = "";
+        if (this.feed.feed_id == 0) {
+          vm.feeds.pop();
+        }
+      },
+      fetch: function fetch() {
+        this.message = "";
+        var postData = {
+          action: "fetch",
+          url: this.feed.url,
+        };
+        this.$http.post("/api/v1/admin/feed", postData).then(
+          (response) => { // success
+            if (response.body.error) {
+              this.message = "error: " + response.body.message;
+              return;
+            }
+            this.feed.url = response.body.item.url;
+            this.feed.title = response.body.item.title;
+            this.feed.description = response.body.item.description;
+          },
+          (response) => { // fail
             this.message = "error: " + response.body.message;
             return;
-        }
-      );
-      
+          }
+        );
+        
+      },
     },
-  },
-});
-
+  });
 
-feedsEditor.run = function run (params) {
   var data = {
     message: '',
     feeds: [],
index cf6bdbc..3bf7868 100644 (file)
@@ -1,8 +1,9 @@
 /* index.js */
 var index = {};
-var vm;
 
 index.run = function run (params) {
+  var vm;
+
   const userConfig = params.userConfig || {};
   const user = params.user || {};
   const siteInfo = params.siteInfo || {};
index 524e2a0..5f74094 100644 (file)
@@ -1,7 +1,7 @@
 var login = {};
-var vmLogin;
 
 login.run = function run(params) {
+  var vmLogin;
 
   $(".toggle-login-modal").on('click', function () {
     console.log("toggle-login-modal");
index c636070..18eebdd 100644 (file)
@@ -5,7 +5,7 @@ var Newslash = function (options) {
   this.baseUrl = options.baseUrl || '/api/v1';
 };
 
-function initNewslash() {
+function _initNewslash() {
   // fake Promise for old browser
   function FakePromise(f) {
     this.then = function(resolve, reject) {
@@ -132,5 +132,5 @@ function initNewslash() {
 
 }
 
-initNewslash();
+_initNewslash();
 var newslash = new Newslash();
index 5161fdc..18f5162 100644 (file)
@@ -1,8 +1,8 @@
 /* submissions-manager.js */
 const submissionsManager = {};
-var vm;
 
 submissionsManager.run = function run (params) {
+  var vm;
   const data = {
     message: '',
     submissions: [],
index f374273..401a000 100644 (file)
@@ -30,4 +30,4 @@ tagEditor.run = function run(params) {
   });
 };
 
-tagEditor.run();
+// tagEditor.run();
index 7accba0..86303cf 100644 (file)
@@ -1,8 +1,8 @@
 /* index.js */
 var userProfile = {};
-var vm;
 
 userProfile.run = function run (params) {
+  var vm;
   var data = {
     relation: params.relation || 0,
     status: "",
index 404e02a..2df6ec4 100644 (file)
@@ -1,8 +1,8 @@
 /* user-settings.js */
-const editor = {};
-var vm;
+const userSettings = {};
 
-editor.run = function run (params) {
+userSettings.run = function run (params) {
+  var vm;
   const userConfig = params.userConfig || {};
   const user = params.user || {};
   const data = {
index b65106a..a5496b6 100644 (file)
 [% helpers.load_js("boxes-editor.js") %]
 [%# <script src="/js/boxes-editor.js" ></script> %]
 <script>
-  editor.run({ el: '#boxes-manager' });
+  boxesEditor.run({ el: '#boxes-manager' });
 </script>
 
 [% END %]