PageSourceSearch

https://www.oh-o.meiji.ac.jp/js/jquery.dependent-selects.js

js meiji.ac.jp collected 2026-09-24 08:30:54 UTC 12,635 bytes, 295 lines download raw bytes

1// Generated by CoffeeScript 1.9.1
2
3/*
4 * jQuery Dependent Selects v1.2.2
5 * Copyright 2012 Mark J Smith, Simpleweb
6 * Details on http://github.com/simpleweb/jquery-dependent-selects
7 */
8(function($) {
9  return $.fn.dependentSelects = function(options) {
10    var clearAllSelectsByParent, createNewSelect, createSelectId, findSelectParent, hideSelect, htmlEncode, insertLabel, insertPlaceholderSelect, labelAtDepth, pathForOption, placeholderOptionAtDepth, placeholderSelectAtDepth, prepareSelect, selectChange, selectPreSelected, selectedOption, showSelect, splitName, splitOptionName;
11    if (options == null) {
12      options = {};
13    }
14    options = $.extend({
15      'separator': ' > ',
16      'placeholderOption': '',
17      'placeholderSelect': false,
18      'class': false,
19      'labels': false
20    }, options);
21    createSelectId = function() {
22      var int;
23      int = parseInt(Math.random() * 1000);
24      if ($("[data-dependent-id='" + int + "']").length > 0) {
25        return createSelectId();
26      } else {
27        return int;
28      }
29    };
30    splitName = function($name) {
31      var array, i, item, j, len;
32      array = $.map($name.split(options.separator), function(valuePart) {
33        return $.trim(valuePart);
34      });
35      i = 0;
36      for (j = 0, len = array.length; j < len; j++) {
37        item = array[j];
38        if (item === '') {
39          array.splice(i, 1);
40          i--;
41        }
42        i++;
43      }
44      return array;
45    };
46    splitOptionName = function($option) {
47      return splitName($option.text());
48    };
49    placeholderSelectAtDepth = function(depth, $select) {
50      var placeholder, text;
51      depth--;
52      placeholder = options.placeholderSelect;
53      if (placeholder) {
54        if (placeholder === true) {
55          placeholder = $select.data('dependent-select-placeholders');
56        }
57        if (typeof placeholder === 'object') {
58          if (placeholder[depth]) {
59            text = placeholder[depth];
60          } else {
61            text = placeholder[placeholder.length - 1];
62          }
63        } else {
64          text = placeholder;
65        }
66        return $("<select disabled><option>" + text + "</option></select>").attr({
67          'data-dependent-depth': depth + 1,
68          'data-dependent-placeholder': true,
69          'data-dependent-id': $select.attr('data-dependent-id')
70        });
71      }
72    };
73    placeholderOptionAtDepth = function(depth) {
74      var placeholder, text;
75      depth--;
76      placeholder = options.placeholderOption;
77      if (typeof placeholder === 'object') {
78        if (placeholder[depth]) {
79          text = placeholder[depth];
80        } else {
81          text = placeholder[placeholder.length - 1];
82        }
83      } else {
84        text = placeholder;
85      }
86      return $("<option>" + text + "</option>");
87    };
88    labelAtDepth = function(depth, $select) {
89      var labels;
90      depth--;
91      labels = options.labels;
92      if (labels) {
93        if (labels === true) {
94          labels = $select.data('dependent-labels');
95        }
96        if (labels[depth]) {
97          return labels[depth];
98        } else {
99          return labels[labels.length - 1];
100        }
101      } else {
102        return false;
103      }
104    };
105    hideSelect = function($select) {
106      var label, placeholder_select, select_depth, select_id;
107      select_id = $select.attr('data-dependent-id');
108      select_depth = $select.attr('data-dependent-depth');
109      placeholder_select = $("select[data-dependent-placeholder][data-dependent-id='" + select_id + "'][data-dependent-depth='" + select_depth + "']");
110      label = $("label[data-dependent-id='" + select_id + "'][data-dependent-depth='" + select_depth + "']").hide();
111      if (placeholder_select.length > 0) {
112        placeholder_select.show();
113        label.show();
114      }
115      return $select.hide();
116    };
117    showSelect = function($select) {
118      var label, placeholder_select, select_depth, select_id;
119      select_id = $select.attr('data-dependent-id');
120      select_depth = $select.attr('data-dependent-depth');
121      placeholder_select = $("select[data-dependent-placeholder][data-dependent-id='" + select_id + "'][data-dependent-depth='" + select_depth + "']");
122      label = $("label[data-dependent-id='" + select_id + "'][data-dependent-depth='" + select_depth + "']").show();
123      if (placeholder_select.length > 0) {
124        placeholder_select.hide();
125      }
126      return $select.show();
127    };
128    insertLabel = function($select, $parent) {
129      var $label, label, select_depth, select_id;
130      if (label = labelAtDepth($select.attr('data-dependent-depth'), $select)) {
131        select_id = $select.attr('data-dependent-id');
132        select_depth = $select.attr('data-dependent-depth');
133        $label = $("<label>" + label + "</label>").attr({
134          'data-dependent-id': select_id,
135          'data-dependent-depth': select_depth
136        });
137        if (!($("label[data-dependent-id='" + select_id + "'][data-dependent-depth='" + select_depth + "']").length > 0)) {
138          if ($parent) {
139            return $parent.after($label);
140          } else {
141            return $select.before($label);
142          }
143        }
144      }
145    };
146    insertPlaceholderSelect = function($select) {
147      var $placeholderSelect, depth, select_id;
148      if ($placeholderSelect = placeholderSelectAtDepth($select.attr('data-dependent-depth'), $select)) {
149        select_id = $select.attr('data-dependent-id');
150        depth = $select.attr('data-dependent-depth');
151        if (!($("select[data-dependent-placeholder][data-dependent-id='" + select_id + "'][data-dependent-depth='" + depth + "']").length > 0)) {
152          return $select.before($placeholderSelect);
153        }
154      }
155    };
156    clearAllSelectsByParent = function($parent) {
157      return $(".dependent-sub[data-dependent-id='" + ($parent.attr('data-dependent-id')) + "']").each(function() {
158        if (parseInt($(this).attr('data-dependent-depth')) > parseInt($parent.attr('data-dependent-depth'))) {
159          $(this).find('option:first').attr('selected', 'selected');
160          return hideSelect($(this));
161        }
162      });
163    };
164    createNewSelect = function(name, $select, depth) {
165      var $currentSelect, $labels, $newSelect, path, select_id;
166      select_id = $select.attr('data-dependent-id');
167      path = pathForOption($select, name);
168      if (($currentSelect = $("select[data-dependent-path='" + path + "'][data-dependent-id='" + select_id + "']")).length > 0) {
169        return $currentSelect;
170      }
171      $newSelect = $('<select class="dependent-sub"/>').attr('data-dependent-depth', depth).attr('data-dependent-input-name', $select.attr('data-dependent-input-name')).attr('data-dependent-id', select_id).addClass(options["class"]).append(placeholderOptionAtDepth(depth));
172      if (options.labels === true) {
173        $newSelect.attr('data-dependent-labels', $select.attr('data-dependent-labels'));
174      }
175      if (options.placeholderSelect === true) {
176        $newSelect.attr('data-dependent-select-placeholders', $select.attr('data-dependent-select-placeholders'));
177      }
178      if (($labels = $("label[data-dependent-id='" + select_id + "'][data-dependent-depth='" + depth + "']")).length > 0) {
179        $newSelect.insertAfter($labels);
180      } else {
181        $newSelect.insertAfter($select);
182      }
183      insertLabel($newSelect, $select);
184      insertPlaceholderSelect($newSelect);
185      return hideSelect($newSelect);
186    };
187    selectChange = function($select) {
188      var $sub, path, select_id, val, valName;
189      $("select[data-dependent-id='" + ($select.attr('data-dependent-id')) + "'][name]").removeAttr('name');
190      valName = $select.find(':selected').html();
191      val = $select.val();
192      select_id = $select.attr('data-dependent-id');
193      clearAllSelectsByParent($select);
194      path = pathForOption($select, valName).replace("'", "\\'");
195      if (($sub = $(".dependent-sub[data-dependent-path='" + path + "'][data-dependent-id='" + select_id + "']")).length > 0) {
196        showSelect($sub);
197        return $sub.attr('name', $select.attr('data-dependent-input-name'));
198      } else {
199        return $select.attr('name', $select.attr('data-dependent-input-name'));
200      }
201    };
202    selectedOption = function($select) {
203      var $selectedOption, val;
204      $selectedOption = $select.find('option:selected');
205      val = $selectedOption.val();
206      if (!(val === '' || val === placeholderOptionAtDepth($select.attr('data-dependent-depth')).val())) {
207        return $select.attr('data-dependent-selected-id', val);
208      }
209    };
210    findSelectParent = function($select) {
211      var $all_options, $selects;
212      $selects = $("select[data-dependent-id='" + ($select.attr('data-dependent-id')) + "']");
213      $all_options = $selects.find('option');
214      return $selects.filter(function() {
215        var vals;
216        vals = [];
217        $(this).find('option').each(function() {
218          return vals.push($(this).attr('data-dependent-path') === $select.attr('data-dependent-path'));
219        });
220        return $.inArray(true, vals) > -1;
221      });
222    };
223    pathForOption = function($select, $name) {
224      if ($select.attr('data-dependent-depth') === '0') {
225        return $name;
226      } else {
227        return $select.attr('data-dependent-path') + options.separator + $name;
228      }
229    };
230    selectPreSelected = function($select) {
231      var $all_options, $current_select, $selected_option, $selected_select, $selects, current_option_text, i, j, ref, selected_id;
232      if ((selected_id = $select.attr('data-dependent-selected-id'))) {
233        $selects = $("select[data-dependent-id='" + ($select.attr('data-dependent-id')) + "']");
234        $all_options = $selects.find('option');
235        $selected_option = $all_options.filter("[value='" + selected_id + "']");
236        $selected_select = $selected_option.closest('select');
237        $current_select = $selected_select;
238        current_option_text = $selected_option.html();
239        for (i = j = ref = parseInt($selected_select.attr('data-dependent-depth')); ref <= 0 ? j <= 0 : j >= 0; i = ref <= 0 ? ++j : --j) {
240          $current_select.find('option').each(function() {
241            if ($(this).html() === current_option_text) {
242              return $(this).attr('selected', 'selected');
243            } else {
244              return $(this).removeAttr('selected');
245            }
246          });
247          showSelect($current_select);
248          current_option_text = splitName($current_select.attr('data-dependent-path')).slice(-1)[0];
249          $current_select = findSelectParent($current_select);
250        }
251        return $selected_select.trigger('change');
252      }
253    };
254    prepareSelect = function($select, depth, select_id) {
255      var $options, name;
256      $select.attr('data-dependent-depth', depth).attr('data-dependent-id', select_id);
257      $options = $select.children('option');
258      $options.each(function() {
259        var $newOption, $option, $subSelect, name, path, val;
260        $option = $(this);
261        name = splitOptionName($option);
262        val = $option.val();
263        if (name.length > 1) {
264          $subSelect = createNewSelect(htmlEncode(name[0]), $select, depth + 1);
265          path = pathForOption($select, name[0]);
266          $subSelect.attr('data-dependent-path', path);
267          $newOption = $option.clone();
268          $newOption.html($.trim(splitOptionName($newOption).slice(1).join(options.separator)));
269          $subSelect.append($newOption);
270          $option.val('').html(name[0]).attr('data-dependent-path', path);
271          if ($options.parent().find("[data-dependent-path='" + path + "']").length > 1) {
272            $option.remove();
273          }
274          return prepareSelect($subSelect, depth + 1, select_id);
275        }
276      });
277      name = $select.attr('name');
278      selectChange($select);
279      return $select.off('change').on('change', function() {
280        return selectChange($select);
281      });
282    };
283    htmlEncode = function(value) {
284      return $('<div/>').text(value).html();
285    };
286    return this.each(function() {
287      var $select;
288      $select = $(this);
289      $select.attr('data-dependent-input-name', $select.attr('name'));
290      selectedOption($select);
291      prepareSelect($select, 0, createSelectId());
292      return selectPreSelected($select);
293    });
294  };
295})(jQuery);

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.