Kazushi Morishima 6 سال پیش
والد
کامیت
b74765347f
1فایلهای تغییر یافته به همراه282 افزوده شده و 282 حذف شده
  1. 282 282
      src/main/webapp/js/suggestor.js

+ 282 - 282
src/main/webapp/js/suggestor.js

@@ -21,189 +21,216 @@
         suggestingSts = false,
 
         suggestor = {
-      init: function($element, setting) {
-        var suggestor;
-
-        suggestingSts = false;
-        $boxElement = $("<div/>");
-        $boxElement.addClass("suggestorBox");
-
-        //style sheet
-        $boxElement.css("display", "none");
-        $boxElement.css("position", "absolute");
-        $boxElement.css("text-align", "left");
-        $boxElement.css("font-size", $element.css("font-size"));
-        if (typeof setting.boxCssInfo === "undefined") {
-          $boxElement.css("border", "1px solid #cccccc");
-          $boxElement.css(
-            "-webkit-box-shadow",
-            "0 3px 2px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(236, 236, 236, 0.6)"
-          );
-          $boxElement.css(
-            "-moz-box-shadow",
-            "0 3px 2px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(236, 236, 236, 0.6)"
-          );
-          $boxElement.css(
-            "box-shadow",
-            "0 3px 2px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(236, 236, 236, 0.6)"
-          );
-          $boxElement.css("background-color", "#fff");
-        } else {
-          $boxElement.css(setting.boxCssInfo);
-        }
+          init: function($element, setting) {
+            var suggestor;
 
-        $textArea = $element;
-        $textArea.attr("autocomplete", "off");
+            suggestingSts = false;
+            $boxElement = $("<div/>");
+            $boxElement.addClass("suggestorBox");
 
-        isFocusList = false;
-        inputText = $textArea.val();
+            //style sheet
+            $boxElement.css("display", "none");
+            $boxElement.css("position", "absolute");
+            $boxElement.css("text-align", "left");
+            $boxElement.css("font-size", $element.css("font-size"));
+            if (typeof setting.boxCssInfo === "undefined") {
+              $boxElement.css("border", "1px solid #cccccc");
+              $boxElement.css(
+                "-webkit-box-shadow",
+                "0 3px 2px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(236, 236, 236, 0.6)"
+              );
+              $boxElement.css(
+                "-moz-box-shadow",
+                "0 3px 2px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(236, 236, 236, 0.6)"
+              );
+              $boxElement.css(
+                "box-shadow",
+                "0 3px 2px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(236, 236, 236, 0.6)"
+              );
+              $boxElement.css("background-color", "#fff");
+            } else {
+              $boxElement.css(setting.boxCssInfo);
+            }
 
-        //settings
-        settingAjaxInfo = setting.ajaxinfo;
-        settingMinTerm = setting.minterm;
-        $settingSearchForm = setting.searchForm;
-        listSelectedCssInfo = setting.listSelectedCssInfo;
-        listDeselectedCssInfo = setting.listDeselectedCssInfo;
-        settingAdjustWidthVal = setting.adjustWidthVal;
+            $textArea = $element;
+            $textArea.attr("autocomplete", "off");
 
-        boxCssInfo = setting.boxCssInfo;
+            isFocusList = false;
+            inputText = $textArea.val();
 
-        $boxElement.hover(
-          function() {
-            isMouseHover = true;
-          },
-          function() {
-            isMouseHover = false;
-          }
-        );
+            //settings
+            settingAjaxInfo = setting.ajaxinfo;
+            settingMinTerm = setting.minterm;
+            $settingSearchForm = setting.searchForm;
+            listSelectedCssInfo = setting.listSelectedCssInfo;
+            listDeselectedCssInfo = setting.listDeselectedCssInfo;
+            settingAdjustWidthVal = setting.adjustWidthVal;
 
-        this.resize();
-        suggestor = this;
-        $(window).resize(function() {
-          suggestor.resize();
-        });
+            boxCssInfo = setting.boxCssInfo;
 
-        $("body").append($boxElement);
-      },
+            $boxElement.hover(
+              function() {
+                isMouseHover = true;
+              },
+              function() {
+                isMouseHover = false;
+              }
+            );
 
-      suggest: function() {
-        suggestingSts = true;
+            this.resize();
+            suggestor = this;
+            $(window).resize(function() {
+              suggestor.resize();
+            });
 
-        this.resize();
+            $("body").append($boxElement);
+          },
 
-        var suggestor = this;
-        inputText = $textArea.val();
+          suggest: function() {
+            suggestingSts = true;
 
-        listNum = 0;
-        listSelNum = 0;
+            this.resize();
 
-        if (inputText.length < settingMinTerm) {
-          $boxElement.css("display", "none");
-          suggestingSts = false;
-          return;
-        }
+            var suggestor = this;
+            inputText = $textArea.val();
+
+            listNum = 0;
+            listSelNum = 0;
+
+            if (inputText.length < settingMinTerm) {
+              $boxElement.css("display", "none");
+              suggestingSts = false;
+              return;
+            }
 
-        $.ajax({
-          url: settingAjaxInfo.url,
-          type: "get",
-          dataType: "jsonp",
-          cache: false,
-          data: {
-            query: $textArea.val(),
-            fields: settingAjaxInfo.fn,
-            num: settingAjaxInfo.num * 2,
-            lang: settingAjaxInfo.lang
+            $.ajax({
+              url: settingAjaxInfo.url,
+              type: "get",
+              dataType: "jsonp",
+              cache: false,
+              data: {
+                query: $textArea.val(),
+                fields: settingAjaxInfo.fn,
+                num: settingAjaxInfo.num * 2,
+                lang: settingAjaxInfo.lang
+              },
+              traditional: true
+            })
+              .done(function(obj) {
+                suggestor.createAutoCompleteList(obj);
+              })
+              .fail(function(a, obj, b) {
+                suggestingSts = false;
+                return;
+              });
           },
-          traditional: true
-        })
-          .done(function(obj) {
-            suggestor.createAutoCompleteList(obj);
-          })
-          .fail(function(a, obj, b) {
-            suggestingSts = false;
-            return;
-          });
-      },
-
-      createAutoCompleteList: function(obj) {
-        if (obj.response.status !== 0) {
-          $boxElement.css("display", "none");
-          return;
-        }
 
-        var hits = obj.response.result.hits,
-            suggestor = this,
-            reslist,
-            $olEle,
-            str,
-            chkCorrectWord,
-            $tmpli,
-            $liEle,
-            i, j, k;
-
-        listNum = 0;
-        if (typeof hits !== "undefined") {
-          reslist = [];
-          for (i = 0; i < hits.length; i++) {
-            reslist.push(hits[i].text);
-          }
-          $olEle = $("<ol/>");
-          $olEle.css("list-style", "none");
-          $olEle.css("padding", "0");
-          $olEle.css("margin", "2px");
-
-          for (
-            j = 0;
-            j < reslist.length && listNum < settingAjaxInfo.num;
-            j++
-          ) {
-            str = reslist[j];
-            chkCorrectWord = true;
-
-            $tmpli = $($olEle.children("li"));
-            for (k = 0; k < $tmpli.length; k++) {
-              if (str === $($tmpli.get(k)).html()) {
-                chkCorrectWord = false;
-              }
+          createAutoCompleteList: function(obj) {
+            if (obj.response.status !== 0) {
+              $boxElement.css("display", "none");
+              return;
             }
 
-            if (chkCorrectWord) {
-              $liEle = $("<li/>");
-              $liEle.html(str);
-              $liEle.click(function() {
-                var str = $(this).html();
-                suggestor.fixList();
-                $textArea.val(str);
-                if (typeof $settingSearchForm !== "undefined") {
-                  $settingSearchForm.submit();
-                  //$settingSearchForm.trigger("submit");
+            var hits = obj.response.result.hits,
+                suggestor = this,
+                reslist,
+                $olEle,
+                str,
+                chkCorrectWord,
+                $tmpli,
+                $liEle,
+                i, j, k;
+
+            listNum = 0;
+            if (typeof hits !== "undefined") {
+              reslist = [];
+              for (i = 0; i < hits.length; i++) {
+                reslist.push(hits[i].text);
+              }
+              $olEle = $("<ol/>");
+              $olEle.css("list-style", "none");
+              $olEle.css("padding", "0");
+              $olEle.css("margin", "2px");
+
+              for (
+                j = 0;
+                j < reslist.length && listNum < settingAjaxInfo.num;
+                j++
+              ) {
+                str = reslist[j];
+                chkCorrectWord = true;
+
+                $tmpli = $($olEle.children("li"));
+                for (k = 0; k < $tmpli.length; k++) {
+                  if (str === $($tmpli.get(k)).html()) {
+                    chkCorrectWord = false;
+                  }
                 }
-              });
-              $liEle.hover(
-                function() {
-                  listSelNum =
-                    $(this)
-                      .closest("ol")
-                      .children("li")
-                      .index(this) + 1;
-                  $(this)
-                    .closest("ol")
-                    .children("li")
-                    .each(function(i) {
-                      if (i === listSelNum - 1) {
-                        if (typeof listSelectedCssInfo === "undefined") {
-                          $(this).css("background-color", "#e5e5e5");
-                        } else {
-                          $(this).css(listSelectedCssInfo);
-                        }
-                      } else {
+
+                if (chkCorrectWord) {
+                  $liEle = $("<li/>");
+                  $liEle.html(str);
+                  $liEle.click(function() {
+                    var str = $(this).html();
+                    suggestor.fixList();
+                    $textArea.val(str);
+                    if (typeof $settingSearchForm !== "undefined") {
+                      $settingSearchForm.submit();
+                      //$settingSearchForm.trigger("submit");
+                    }
+                  });
+                  $liEle.hover(
+                    function() {
+                      listSelNum =
+                        $(this)
+                          .closest("ol")
+                          .children("li")
+                          .index(this) + 1;
+                      $(this)
+                        .closest("ol")
+                        .children("li")
+                        .each(function(i) {
+                          if (i === listSelNum - 1) {
+                            if (typeof listSelectedCssInfo === "undefined") {
+                              $(this).css("background-color", "#e5e5e5");
+                            } else {
+                              $(this).css(listSelectedCssInfo);
+                            }
+                          } else {
+                            if (typeof listDeselectedCssInfo !== "undefined") {
+                              $(this).css(listDeselectedCssInfo);
+                            } else {
+                              if (
+                                typeof boxCssInfo === "undefined" ||
+                                typeof boxCssInfo["background-color"] ===
+                                  "undefined"
+                              ) {
+                                $(this).css("background-color", "#ffffff");
+                              } else {
+                                $(this).css(
+                                  "background-color",
+                                  boxCssInfo["background-color"]
+                                );
+                              }
+                            }
+                          }
+                        });
+                    },
+                    function() {
+                      if (
+                        listSelNum ===
+                        $(this)
+                          .closest("ol")
+                          .children("li")
+                          .index(this) +
+                          1
+                      ) {
                         if (typeof listDeselectedCssInfo !== "undefined") {
                           $(this).css(listDeselectedCssInfo);
                         } else {
                           if (
                             typeof boxCssInfo === "undefined" ||
-                            typeof boxCssInfo["background-color"] ===
-                              "undefined"
+                            typeof boxCssInfo["background-color"] === "undefined"
                           ) {
                             $(this).css("background-color", "#ffffff");
                           } else {
@@ -213,143 +240,116 @@
                             );
                           }
                         }
-                      }
-                    });
-                },
-                function() {
-                  if (
-                    listSelNum ===
-                    $(this)
-                      .closest("ol")
-                      .children("li")
-                      .index(this) +
-                      1
-                  ) {
-                    if (typeof listDeselectedCssInfo !== "undefined") {
-                      $(this).css(listDeselectedCssInfo);
-                    } else {
-                      if (
-                        typeof boxCssInfo === "undefined" ||
-                        typeof boxCssInfo["background-color"] === "undefined"
-                      ) {
-                        $(this).css("background-color", "#ffffff");
-                      } else {
-                        $(this).css(
-                          "background-color",
-                          boxCssInfo["background-color"]
-                        );
+                        listSelNum = 0;
                       }
                     }
-                    listSelNum = 0;
-                  }
-                }
-              );
+                  );
 
-              $liEle.css("padding", "2px");
+                  $liEle.css("padding", "2px");
 
-              $olEle.append($liEle);
-              listNum++;
-            }
-          }
+                  $olEle.append($liEle);
+                  listNum++;
+                }
+              }
 
-          if (listNum > 0 && $textArea.val().length >= settingMinTerm) {
-            $boxElement.html("");
-            $boxElement.append($olEle);
-            $boxElement.css("display", "block");
-          } else {
-            $boxElement.css("display", "none");
-          }
-        } else {
-          $boxElement.css("display", "none");
-        }
-        this.resize();
+              if (listNum > 0 && $textArea.val().length >= settingMinTerm) {
+                $boxElement.html("");
+                $boxElement.append($olEle);
+                $boxElement.css("display", "block");
+              } else {
+                $boxElement.css("display", "none");
+              }
+            } else {
+              $boxElement.css("display", "none");
+            }
+            this.resize();
 
-        suggestingSts = false;
-      },
+            suggestingSts = false;
+          },
 
-      selectlist: function(direction) {
-        if ($boxElement.css("display") === "none") {
-          return;
-        }
+          selectlist: function(direction) {
+            if ($boxElement.css("display") === "none") {
+              return;
+            }
 
-        if (direction === "down") {
-          listSelNum++;
-        } else if (direction === "up") {
-          listSelNum--;
-        } else {
-          return;
-        }
+            if (direction === "down") {
+              listSelNum++;
+            } else if (direction === "up") {
+              listSelNum--;
+            } else {
+              return;
+            }
 
-        isFocusList = true;
+            isFocusList = true;
 
-        if (listSelNum < 0) {
-          listSelNum = listNum;
-        } else if (listSelNum > listNum) {
-          listSelNum = 0;
-        }
+            if (listSelNum < 0) {
+              listSelNum = listNum;
+            } else if (listSelNum > listNum) {
+              listSelNum = 0;
+            }
 
-        $boxElement
-          .children("ol")
-          .children("li")
-          .each(function(i) {
-            if (i === listSelNum - 1) {
-              if (typeof listSelectedCssInfo === "undefined") {
-                $(this).css("background-color", "#e5e5e5");
-              } else {
-                $(this).css(listSelectedCssInfo);
-              }
-              $textArea.val($(this).html());
-            } else {
-              if (typeof listDeselectedCssInfo !== "undefined") {
-                $(this).css(listDeselectedCssInfo);
-              } else {
-                if (
-                  typeof boxCssInfo === "undefined" ||
-                  typeof boxCssInfo["background-color"] === "undefined"
-                ) {
-                  $(this).css("background-color", "#ffffff");
+            $boxElement
+              .children("ol")
+              .children("li")
+              .each(function(i) {
+                if (i === listSelNum - 1) {
+                  if (typeof listSelectedCssInfo === "undefined") {
+                    $(this).css("background-color", "#e5e5e5");
+                  } else {
+                    $(this).css(listSelectedCssInfo);
+                  }
+                  $textArea.val($(this).html());
                 } else {
-                  $(this).css(
-                    "background-color",
-                    boxCssInfo["background-color"]
-                  );
+                  if (typeof listDeselectedCssInfo !== "undefined") {
+                    $(this).css(listDeselectedCssInfo);
+                  } else {
+                    if (
+                      typeof boxCssInfo === "undefined" ||
+                      typeof boxCssInfo["background-color"] === "undefined"
+                    ) {
+                      $(this).css("background-color", "#ffffff");
+                    } else {
+                      $(this).css(
+                        "background-color",
+                        boxCssInfo["background-color"]
+                      );
+                    }
+                  }
                 }
-              }
+              });
+            if (listSelNum === 0) {
+              $textArea.val(inputText);
             }
-          });
-        if (listSelNum === 0) {
-          $textArea.val(inputText);
-        }
-      },
-
-      fixList: function() {
-        if (listSelNum > 0) {
-          $textArea.val(
-            $(
-              $boxElement
-                .children("ol")
-                .children("li")
-                .get(listSelNum - 1)
-            ).html()
-          );
-        }
-        inputText = $textArea.val();
+          },
 
-        isFocusList = false;
-        $boxElement.css("display", "none");
-        listNum = 0;
-      },
-
-      resize: function() {
-        $boxElement.css("top", $textArea.offset().top + $textArea.height() + 6);
-        $boxElement.css("left", $textArea.offset().left);
-        $boxElement.css("height", "auto");
-        $boxElement.css("width", "auto");
-        if ($boxElement.width() < $textArea.width() + settingAdjustWidthVal) {
-          $boxElement.width($textArea.width() + settingAdjustWidthVal);
-        }
-      }
-    };
+          fixList: function() {
+            if (listSelNum > 0) {
+              $textArea.val(
+                $(
+                  $boxElement
+                    .children("ol")
+                    .children("li")
+                    .get(listSelNum - 1)
+                ).html()
+              );
+            }
+            inputText = $textArea.val();
+
+            isFocusList = false;
+            $boxElement.css("display", "none");
+            listNum = 0;
+          },
+
+          resize: function() {
+            $boxElement.css("top", $textArea.offset().top + $textArea.height() + 6);
+            $boxElement.css("left", $textArea.offset().left);
+            $boxElement.css("height", "auto");
+            $boxElement.css("width", "auto");
+            if ($boxElement.width() < $textArea.width() + settingAdjustWidthVal) {
+              $boxElement.width($textArea.width() + settingAdjustWidthVal);
+            }
+          }
+        };
 
     suggestor.init($(this), setting);