瀏覽代碼

去掉闭包

Luolei 6 年之前
父節點
當前提交
146e994870
共有 3 個文件被更改,包括 81 次插入90 次删除
  1. 8 10
      src/js/disclaimer.js
  2. 69 70
      src/js/information.js
  3. 4 10
      src/js/promise.js

+ 8 - 10
src/js/disclaimer.js

@@ -1,13 +1,11 @@
 const {post, config} = require('./promise.js');
 const $ = require("jquery");
 
-(function(){
-    getDisclaimer();
-    function getDisclaimer() {
-        post(config.disclaimer, '').then((res) => {
-            const data = res.data.data;
-            $("h1").html(data[2].title);
-            $(".content").html(data[2].description);
-        })
-    }
-})()
+getDisclaimer();
+function getDisclaimer() {
+    post(config.disclaimer, '').then((res) => {
+        const data = res.data.data;
+        $("h1").html(data[2].title);
+        $(".content").html(data[2].description);
+    })
+}

+ 69 - 70
src/js/information.js

@@ -7,78 +7,77 @@ const {
 } = require('./promise.js');
 const $ = require("jquery");
 
-(function () {
-  getInfomation();
-  function getInfomation() {
-    var param = {
-      "type": getUrlArgObject('type'),
-      "questionId": getUrlArgObject('questionId'),
-      "position": getUrlArgObject('position')
-    };
+function getInfomation() {
+  var param = {
+    "type": getUrlArgObject('type'),
+    "questionId": getUrlArgObject('questionId'),
+    "position": getUrlArgObject('position')
+  };
 
-    post(config.information, param).then((res) => {
-      const data = res.data.data
-      var str = '';
-      var anchors = '';
-      var item = '';
-      if (!data) {
-        $("h1").html("暂时没有数据");
-        $(".anchors").css("display", "none");
-        return;
+  post(config.information, param).then((res) => {
+    const data = res.data.data
+    var str = '';
+    var anchors = '';
+    var item = '';
+    if (!data) {
+      $("h1").html("暂时没有数据");
+      $(".anchors").css("display", "none");
+      return;
+    }
+    var list = data.introduceDetailList;
+    $("h1").html(data.tagName);
+    $("h1").css({
+      "color": "#267FD7",
+      "borderBottom": "4px solid  #E9E9E9",
+      "padding": "0px 60px 50px 0px"
+    });
+    for (var i = 0; i < list.length; i++) {
+      item = list[i];
+      item.content = item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
+      anchors = '<li><i></i><a href="#' + item.id +
+        '">' + item.title + '</a></li><li class="anchor-line"></li>';
+      str = '<div class="title"><h2 id="' + item.id +
+        '">'
+      if (getUrlArgObject('type') == 8) {
+        str += '【' + item.title + '】'
+      } else {
+        str += item.title
       }
-      var list = data.introduceDetailList;
-      $("h1").html(data.tagName);
-      $("h1").css({
-        "color": "#267FD7",
-        "borderBottom": "4px solid  #E9E9E9",
-        "padding": "0px 60px 50px 0px"
-      });
-      for (var i = 0; i < list.length; i++) {
-        item = list[i];
-        item.content = item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
-        anchors = '<li><i></i><a href="#' + item.id +
-          '">' + item.title + '</a></li><li class="anchor-line"></li>';
-        str = '<div class="title"><h2 id="' + item.id +
-          '">'
-        if (getUrlArgObject('type') == 8) {
-          str += '【' + item.title + '】'
-        } else {
-          str += item.title
-        }
-        str += '</h2></div>' +
-          '<div>' + item.content + '<div>';
-        if (i != list.length - 1 && getUrlArgObject('type') != 8) {
-          str += '<div class="line"></div>'
-        }
-        $(".infos").append(str);
-        $(".anchors ul").append(anchors);
+      str += '</h2></div>' +
+        '<div>' + item.content + '<div>';
+      if (i != list.length - 1 && getUrlArgObject('type') != 8) {
+        str += '<div class="line"></div>'
       }
-      addLinkClickEvent();
-      adjustHeight();
-      function addScrollEvent() {
-        var scrollTop = $('.infos').scrollTop()
-        var divHeight = 0;
-        for (var i = 0; i < list.length; i++) {
-          divHeight = divHeight + parseInt($('#' + list[i].id).css('height')) + parseInt($('#' + list[i].id).parent().next().css('height')) + 40
-          if (divHeight > scrollTop) {
-            var anchor = 2 * i;
-            $('.anchors ul').children().eq(anchor).addClass('active').siblings().removeClass('active');
-            return;
-          }
+      $(".infos").append(str);
+      $(".anchors ul").append(anchors);
+    }
+    addLinkClickEvent();
+    adjustHeight();
+    function addScrollEvent() {
+      var scrollTop = $('.infos').scrollTop()
+      var divHeight = 0;
+      for (var i = 0; i < list.length; i++) {
+        divHeight = divHeight + parseInt($('#' + list[i].id).css('height')) + parseInt($('#' + list[i].id).parent().next().css('height')) + 40
+        if (divHeight > scrollTop) {
+          var anchor = 2 * i;
+          $('.anchors ul').children().eq(anchor).addClass('active').siblings().removeClass('active');
+          return;
         }
       }
-      $(".infos").scroll(throttle(addScrollEvent, 200));
-    })
-  }
-  function addLinkClickEvent() {
-    $("li:first").addClass("active");
-    $("li>a").on("click", function () {
-      $(".active").removeClass('active');
-      $(this).parent().addClass("active");
-    });
-  }
-  function adjustHeight() {
-    var ht = window.innerHeight;
-    $(".content").height(ht - 145 + "px");
-  }
-})();
+    }
+    $(".infos").scroll(throttle(addScrollEvent, 200));
+  })
+}
+getInfomation();
+
+function addLinkClickEvent() {
+  $("li:first").addClass("active");
+  $("li>a").on("click", function () {
+    $(".active").removeClass('active');
+    $(this).parent().addClass("active");
+  });
+}
+function adjustHeight() {
+  var ht = window.innerHeight;
+  $(".content").height(ht - 145 + "px");
+}

+ 4 - 10
src/js/promise.js

@@ -4,10 +4,10 @@ const qs = require('qs');
 const $ = require("jquery");
 
 const config = {
-  pushInner:'http://192.168.2.241:5050/api/icss/push/pushInner',
-  calculate:'http://192.168.2.241:5050/api/icss/calc/calculate',
-  disclaimer: 'http://192.168.2.241:5050/api/icss/disclaimerInformation/getDisclaimerInformations',
-  information: 'http://192.168.2.241:5050/api/icss/introduceInfo/getByQuestionId'
+  pushInner:'/api/icss/push/pushInner',
+  calculate:'/api/icss/calc/calculate',
+  disclaimer: '/api/icss/disclaimerInformation/getDisclaimerInformations',
+  information: '/api/icss/introduceInfo/getByQuestionId'
 }
 const imageUrlPrefix = 'http://192.168.2.241:82';
 const getUrlArgObject = function(parm) {  
@@ -61,9 +61,3 @@ module.exports = {
   imageUrlPrefix,
   throttle
 }
-
-// window.config = config
-// window.post = post
-// window.getUrlArgObject = getUrlArgObject
-// window.imageUrlPrefix = imageUrlPrefix
-// window.throttle = throttle