PageSourceSearch

https://gumpla.jp/wp-content/themes/gush/assets/js/libs/jquery.searchHistory.js?06140536

js gumpla.jp collected 2026-10-03 22:13:59 UTC 7,326 bytes, 191 lines download raw bytes

1; (function ($, window) {
2  var defaults = {
3      maxShowNum: 10,
4      expires: 7,
5      input: '.c-search-history__input',
6      cookieName: 'searchHistory',
7      selected: function () { },
8      beforeSend: function () { return true; },
9      sendWhenSelect: true,
10      actionByCall:false
11  };
12  $.fn.searchHistory = function (customOptions) {
13      var form = this;
14      if (typeof customOptions == 'string') {
15          switch (customOptions) {
16              case 'close':
17                  _close(form[0]);
18                  break;
19              case 'open':
20                  _open(form[0]);
21                  break;
22              case 'clear':
23                  _clear(form[0]);
24                  break;
25          }
26          return form;
27      }
28
29      var options = $.extend({}, defaults, customOptions);
30      if (form.length > 1)
31          return null;
32      if (form.length==0)
33          return null;
34      
35      form.$input = form.find(options.input);
36      if (form.$input.length > 1)
37          return null;
38      var $history = $('<div class="o-search-history is-hide"></div>');
39      var $historyHeader = $('<div class="o-search-history__header"></div>');
40      var $historyTitle = $('<div class="o-search-history__title">検索履歴</div>');
41      var $list = $('<ul class="o-search-history__list"></ul>');
42      var $item = $('<li class="o-search-history__list-item"></li>');
43      var $clear = $('<div class="o-search-history__clear"><div class="o-search-history__clear-link u-link__text">検索履歴を削除</div></div>');
44      var strCookie = $.cookie(options.cookieName);
45      form.cookies = []
46      if (strCookie && strCookie != 'null')
47          $.each(strCookie.split('&'), function (index, value) {
48              form.cookies.push(unescape(value));
49          });
50      for (var i = 0; i < form.cookies.length; i++)
51      $list.append($item.clone().html(form.cookies[i]));
52      $history.append($list);
53      $historyHeader.insertBefore($list);
54      $historyHeader.append($historyTitle);
55      $historyHeader.append($clear);
56      
57      //dom_form
58      form[0].$history = $history;
59      form[0].$list = $list;
60      form[0].$clear = $clear;
61      form[0].$historyHeader = $historyHeader;
62      form[0].options = options;
63      //form.$input form.cookies
64      $history.insertAfter(form.$input);
65      options.actionByCall || form.$input.click(function (e) {
66          e.preventDefault();
67          e.stopPropagation();
68          if ($list.find('.o-search-history__list-item').length > 0)
69              _open(form[0]);
70      });
71      $(window).click(function (e) {
72          var source = e.target;
73          if (form.has(source).length == 0) {
74              _close(form[0]);
75          }
76      });
77      $history.data('fromitem', false);
78      form.submit(function () {
79          var newCookie = $.trim(form.$input.val());
80          var index = form.cookies.indexOf(newCookie);
81          var len = form.cookies.length;
82          if (index == -1)
83              len = form.cookies.unshift(newCookie);
84          else {
85              var temp = form.cookies[index];
86              for (var i = index; i > 0; i--)
87                  form.cookies[i] = form.cookies[i - 1];
88              form.cookies[0] = temp;
89          }
90          var tempCookie = (len > options.maxShowNum)?form.cookies.slice(0, options.maxShowNum):form.cookies;
91          $.each(tempCookie, function (index, value) {
92              tempCookie[index] = escape(value);
93          });
94          $.cookie(options.cookieName, tempCookie.join('&'), { expires: options.expires, path: '/' });
95          typeof options.selected == 'function' && options.selected($.trim(form.$input.val()));
96          if ((!options.sendWhenSelect) && $history.data('fromitem')) {
97              _close(form[0]);
98              $history.data('fromitem', false);
99              return false;
100          }
101          if (typeof options.beforeSend == 'function')
102              return options.beforeSend($.trim(form.$input.val()));
103          return true;
104      });
105      $clear.find('.o-search-history__clear-link').click(function (e) {
106          e.preventDefault();
107          e.stopPropagation();
108          _clear(form[0]);
109      });
110      $list.find('.o-search-history__list-item').click(function (e) {
111          e.preventDefault();
112          e.stopPropagation();
113					document.location.href = "https://gumpla.jp/?s=" + ($.trim($(this).html())),
114          form.$input.val($.trim($(this).html()));
115
116
117
118
119
120          typeof options.selected == 'function' && options.selected($.trim(form.$input.val()));
121          _close(form[0]);
122          form.$input.focus();
123          if(options.sendWhenSelect)
124              form.submit();
125      });
126      $history.data('index', -1);
127      form.$input.keyup({
128          '$input': form.$input,
129          '$history': $history,
130          '$list': $list.find('.o-search-history__list-item'), 
131          'index': $history.data('index')
132      }, function (e) {
133          var data = e.data;
134          var code = e.keyCode ? e.keyCode : e.which;
135          if ((code === 40 || code === 38) && data.$history.hasClass('is-show')) {
136              var len = data.$list.length,
137                  next,
138                  prev;
139              if (data.index === -1)
140                  data.$history.data('original', $.trim(data.$input.val()));
141              if (len) {
142                  if (len > 1) {
143                      if (data.index === len - 1) {
144                          next = -1;
145                          prev = data.index - 1;
146                      } else if (data.index === 0) {
147                          next = data.index + 1;
148                          prev = -1;
149                      } else if (data.index === -1) {
150                          next = 0;
151                          prev = len - 1;
152                      } else {
153                          next = data.index + 1;
154                          prev = data.index - 1;
155                      }
156                  } else if (data.index === -1) {
157                      next = 0;
158                      prev = 0;
159                  } else {
160                      prev = -1;
161                      next = -1;
162                  }
163                  data.index = (code === 40) ? next : prev;
164
165                  data.$list.removeClass("o-search-history__list-item-selected");
166                  if (data.index !== -1) {
167                      data.$input.val(data.$list.eq(data.index).addClass("o-search-history__list-item-selected").html());
168                      data.$history.data('fromitem', true);
169                  }
170                  else
171                      data.$input.val(data.$history.data('original'));
172                  data.$history.data('index', data.index);
173              }
174          }
175      });
176      function _open(dom_form) {
177          if (dom_form.$list.find('.o-search-history__list-item').length > 0)
178              dom_form.$history.addClass('is-show').removeClass('is-hide');
179      }
180      function _close(dom_form) {
181          dom_form.$history.addClass('is-hide').removeClass('is-show');
182      }
183      function _clear(dom_form) {
184          $.cookie(dom_form.options.cookieName, null);
185          form.cookies = [];
186          dom_form.$list.find('.o-search-history__list-item').remove();
187          _close(form[0]);
188      }
189      return form;
190  }
191})(jQuery, window);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.