PageSourceSearch

https://www.aquabells.jp/reservation/js/lib/exvalidation.js

js aquabells.jp collected 2026-10-04 15:51:04 UTC 17,368 bytes, 555 lines download raw bytes

1/*!
2 * exValidation
3 *
4 * @version   : 1.3.3
5 * @author    : nori ([email protected])
6 * @copyright : 5509 (http://5509.me/)
7 * @license   : The MIT License
8 * @link      : http://5509.me/log/exvalidation
9 * @modified  : 2012-04-09 16:59
10 */
11;(function($, window, undefined) {
12  $.exValidationRules = $.exValidationRules || {};
13  var exValidation = function(form, conf) {
14    if ( $("form#validate").length > 1 ) {
15      alert("You cannot select any forms");
16      return false;
17    }
18
19    this.form = form;
20    // for browse
21    var _this = this,
22      b = $("body");
23
24    conf = this.conf = $.extend({
25      errInsertPos       : "body", // "body" or after(before)
26      err                : null,
27      ok                 : null,
28      errFocus           : false,
29      errHoverHide       : false,
30      stepValidation     : false,
31      scrollToErr        : true,
32      scrollDuration     : 500,
33      scrollAdjust       : -10,
34      customScrollAdjust : false,
35      errPosition        : "absolute", // fixed
36      errOpacity         : undefined,
37      errTipPos          : "right", // left
38      errTipCloseBtn     : true,
39      errTipCloseLabel   : "×",
40      errZIndex          : 500,
41      errMsgPrefix       : "",
42      customAddError     : null, // function(){}
43      customClearError   : null, // function(){}
44      customSubmit       : null, // function(){}
45      customListener     : "blur keyup change focus",
46      customBind         : null,
47      /* Using this conf, you can bind validation func to any element
48        {
49          object: $(button),
50          listener: "blur keyup change focus",
51          callback: function() {}
52        }
53      */
54      customGetErrHeight  : null,
55      firstValidate       : false,
56      // default checking targets
57      inputs: [
58        "input:text",
59        "input:password",
60        "input:hidden",
61        "input:file",
62        "textarea",
63        "select",
64        "input[type=email]",
65        "input[type=url]",
66        "input[type=tel]",
67        "input[type=date]",
68        "input[type=datetime]",
69        "input[type=month]",
70        "input[type=week]",
71        "input[type=time]",
72        "input[type=datetime-local]",
73        "input[type=number]",
74        "input[type=range]",
75        "input[type=color]",
76        "[class*=group]",
77        "[class*=radio]",
78        "[class*=checkbox]"
79      ],
80      // default checking targets in groups
81      groupInputs: [
82        "input:text",
83        "input:password",
84        "input:checkbox",
85        "input:radio",
86        "input[type=email]",
87        "input[type=url]",
88        "input[type=tel]",
89        "input[type=date]",
90        "input[type=datetime]",
91        "input[type=month]",
92        "input[type=week]",
93        "input[type=time]",
94        "input[type=datetime-local]",
95        "input[type=number]",
96        "input[type=range]",
97        "input[type=color]",
98        "select",
99        "textarea"
100      ]
101    }, conf);
102
103    conf.inputs = conf.inputs.join(",");
104    conf.groupInputs = conf.groupInputs.join(",");
105
106    this.errFocus = function(id) {
107      if ( !conf.errFocus ) return false;
108      errFocus(id, conf.errZIndex);
109    };
110    this.errFocusClear = function() {
111      if ( !conf.errFocus ) return false;
112      errFocusClear(conf.errZIndex);
113    };
114
115    if ( fnConfirmation(conf.customSubmit) ) {
116      form.submit(function() {
117        return false;
118      });
119    }
120    form.find("input:checkbox,input:radio,input:button,input:submit,input:reset").click(function() {
121      _this.errFocusClear();
122    });
123
124    // addClasses for each inputs by validation rules
125    for ( var c in conf.rules ) {
126      $("#" + c).addClass(conf.rules[c]);
127    }
128
129    // If this form doesn"t have ID, formID for error tips is to be decided by random integer
130    var formID = form.attr("id")
131      ? "form_" + form.attr("id")
132      : "form_" + randomInt()*randomInt();
133
134    var inputs = $(conf.inputs, form)
135      .filter(function() { return !$(this).parents().hasClass("chkgroup"); }),
136      classReg = returnReg(),
137      bindValidateFuncs = function(target, group) {
138        var self = group ? group : target;
139        target.bind(conf.customListener, function() {
140          _this.basicValidate(group ? group : this, conf.err, conf.ok);
141          _this.errFocus("#err_" + self.attr("id"));
142        }).blur(function() {
143          _this.errFocusClear();
144        });
145      };
146
147    inputs.each(function() {
148      var self = $(this),
149        cl = this.className,
150        id = this.id,
151        reg1 = undefined,
152        reg2 = undefined,
153        toggleTarget = undefined;
154
155      if ( conf.errTipPos === "right" ) {
156        self.addClass("errPosRight");
157      }
158
159      // if target has one of classRegulations
160      if ( classReg.test(cl) ) {
161        if ( conf.errInsertPos === "body" ) {
162          b.append(_this.generateErr(id, formID));
163        } else {
164          self[conf.errInsertPos](_this.generateErr(id, formID));
165          self.addClass(conf.errInsertPos);
166        }
167
168        if ( conf.errHoverHide ) {
169          $("#err_"+id).mouseenter(function() {
170            $(this).fadeOut();
171          });
172        }
173        if ( conf.errTipCloseBtn ) {
174          $("#err_"+id).append(
175            $("<p class=\"pError\"></p>")
176              .addClass("formErrorClose")
177              .text(conf.errTipCloseLabel)
178              .click(function() {
179                $(this).parent().fadeOut();
180              })
181          );
182        }
183        if ( conf.errOpacity !== undefined ) {
184          $("#err_"+id).children().css("opacity", conf.errOpacity);
185        }
186        if ( conf.errPosition === "absolute" ) {
187          if ( fnConfirmation(conf.customGetErrHeight) ) {
188            _this.customGetErrHeight(id);
189          } else {
190            _this.getErrHeight(id, conf.errZIndex);
191          }
192
193          // Reget the position
194          $(window).resize(function() {
195            if ( fnConfirmation(conf.customGetErrHeight) ) {
196              _this.customGetErrHeight(id);
197            } else {
198              _this.getErrHeight(id, conf.errZIndex);
199            }
200          });
201        }
202        $("#err_"+id).hide();
203      }
204
205    });
206
207    // Checkboxによる分岐
208    inputs.each(function() {
209      var _self = $(this),
210        reg1 = undefined,
211        reg2 = undefined,
212        toggleTarget = undefined;
213
214      if ( this.className.match(/chktoggle_([^_]+)_([^ ]+)/) ) {
215        reg1 = "#" + RegExp.$1;
216        reg2 = "#" + RegExp.$2;
217        toggleTarget = $(reg2).removeClass("chkrequired");
218        $(reg1).click(function() {
219          console.log(toggleTarget);
220          if ( this.checked ) {
221            toggleTarget.addClass("chkrequired");
222          } else {
223            toggleTarget.removeClass("chkrequired");
224          }
225          _this.laterCall(toggleTarget);
226        });
227      }
228
229      if ( !conf.firstValidate ) return;
230      if ( _self.hasClass("chkgroup") ) {
231        bindValidateFuncs($(conf.groupInputs, _self), _self);
232      } else {
233        bindValidateFuncs(_self);
234      }
235    });
236
237    // You call this func everytime you like after init
238    this.laterCall = function(t) {
239      _this.basicValidate(t, conf.err, conf.ok);
240    };
241
242    function _exeValidation(customBindCallback) {
243      if ( conf.firstValidate ) {
244        inputs.unbind("blur keyup change click");
245        conf.firstValidate = false;
246      }
247      inputs.each(function() {
248        var self = $(this);
249        _this.basicValidate(this, conf.err, conf.ok, true);
250
251        if ( self.hasClass("chkgroup") ) {
252          bindValidateFuncs($(conf.groupInputs, self), self);
253        } else {
254          bindValidateFuncs(self);
255        }
256      });
257
258      var err = $(".formError:visible[class*='"+formID+"']");
259      // if errs are displayed
260      if ( err.length > 0 ) {
261        if ( fnConfirmation(conf.customAddError) ) {
262          conf.customAddError();
263        }
264        if ( conf.scrollToErr ) {
265          var reverseOffsetTop,
266            infoErr, errTop,
267            scrollTarget = $.support.boxModel
268              ? navigator.appName.indexOf("Opera") !== -1 ?
269                "html" : "html,body"
270              : "body";
271          if ( !conf.customScrollAdjust ) {
272            reverseOffsetTop = $(err[0]).offset().top;
273            errTop = $(err[0]);
274
275            for ( var i=0, l=err.length; i<l; i++ ) {
276              infoErr = $(err[i]);
277              reverseOffsetTop = infoErr.offset().top < reverseOffsetTop
278                ? infoErr.offset().top : reverseOffsetTop;
279              errTop = infoErr.offset().top < reverseOffsetTop
280                ? infoErr : errTop;
281            }
282
283            if ( conf.errPosition === "fixed" ) {
284              reverseOffsetTop -= $("#"+errTop.attr("id").replace("err_", "")).get(0).offsetHeight;
285            }
286          } else {
287            reverseOffsetTop = fnConfirmation(conf.customScrollAdjust)
288              ? parseFloat(conf.customScrollAdjust()) : parseFloat(conf.customScrollAdjust);
289
290          }
291
292          /*$(scrollTarget).animate({
293            scrollTop: reverseOffsetTop + conf.scrollAdjust,
294            easing: $.easing.easeInOutCirc ? "easeInOutCirc" : "swing",
295            duration: conf.scrollDuration
296          });*/
297          var scroll = reverseOffsetTop + conf.scrollAdjust - $('.head_wrap').height();
298          $('html,body').animate({
299            scrollTop: scroll
300          }, 400);
301
302
303          /*$(scrollTarget).css({
304            "margin-top" : $(window).scrollTop() - scroll + "px",
305            "transition" : "0.5s ease-in-out"
306          }).data("transitioning", true);
307
308          $(scrollTarget).on("transitionend webkitTransitionEnd msTransitionEnd oTransitionEnd", function (e) {
309            if (e.target == e.currentTarget && $(this).data("transitioning") === true) {
310              console.log(scroll);
311              $(this).removeAttr("style").data("transitioning", false);
312              $('html,body').scrollTop(scroll);
313
314              return;
315            }
316
317          });*/
318        }
319        return false;
320
321      // if no err is displayed
322      } else {
323        if ( fnConfirmation(conf.customClearError) ) {
324          // falseが返ってきた場合はキャンセルする
325          var result = conf.customClearError();
326          if ( !result ) return false;
327          // if ( result == false ) return false;
328        }
329        // CustomBindCallBack
330        if ( fnConfirmation(customBindCallback) ) {
331          customBindCallback();
332          return false;
333        } else {
334          // customSubmit
335          if ( fnConfirmation(conf.customSubmit) ) {
336            conf.customSubmit();
337            return false;
338          // Default Postback
339          } else {
340            // OK
341            return true;
342          }
343        }
344      }
345    }
346
347    // When the form is submited
348    $("form#validate").submit(_exeValidation);
349
350    // Add the Validation
351    if ( conf.customBind ) {
352      conf.customBind.object.bind(conf.customBind.listener, function() {
353        _exeValidation(conf.customBind.callback);
354        return false;
355      });
356    }
357
358    // Return the instance
359    return this;
360  };
361
362  // Common prototype functions
363  exValidation.prototype = {
364    // Errtip content
365    // this HTML source code from "A jQuery inline form validation, because validation is a mess"
366    // thanks to http://bit.ly/onlNv (http://www.position-relative.net/)
367    generateErr: function(id, formID) {
368      return [
369        '<div id="err_'+id+'" class="formError userformError'+' '+formID+' '+this.conf.errPosition+'">',
370          '<div class="formErrorMsg formErrorContent"></div>',
371          '<div class="formErrorArrow">',
372            '<div class="line10"></div>',
373            '<div class="line9"></div>',
374            '<div class="line8"></div>',
375            '<div class="line7"></div>',
376            '<div class="line6"></div>',
377            '<div class="line5"></div>',
378            '<div class="line4"></div>',
379            '<div class="line3"></div>',
380            '<div class="line2"></div>',
381            '<div class="line1"></div>',
382          '</div>',
383        '</div>'
384      ].join("");
385    },
386    // Insert error message
387    insertErrMsg: function(t, id, c, errMsg) {
388      var msgs = $(".errMsg", "#err_"+id),
389        returnFlg = true;
390      if ( msgs.length > 0 ) {
391        $.each(msgs, function() {
392          if ( $(this).hasClass(c) ) {
393            returnFlg = false;
394          }
395        });
396      }
397      if ( !returnFlg ) return false;
398      $(".formErrorMsg", "#err_"+id).append(
399        $("<p class=\"pError\"></p>")
400          .addClass("errMsg")
401          .addClass(c)
402          .text(errMsg)
403        );
404      this.getErrHeight(id);
405    },
406    // Basic get error height
407    getErrHeight: function(id, zIndex) {
408      if ( this.conf.errPosition !== "absolute" ) return false;
409      var input = $("#"+id),
410        err = $("#err_"+id),
411        target = input.is(":hidden") ? input.next() : input,
412        pos = target.offset();
413
414      if ( !!pos ) {
415        var left = target.hasClass("errPosRight")
416            ? pos.left + target.get(0).offsetWidth - 40
417            : pos.left - 20;
418
419        err.css({
420          position: "absolute",
421          top: pos.top - err.get(0).offsetHeight,
422          left: left
423        });
424      }
425
426      if ( zIndex ) {
427        err.css("zIndex", zIndex);
428      }
429    },
430    // Basic validation
431    basicValidate: function(t, err, ok) {
432      var _t = $(t),
433        CL = _t.attr("class"),
434        chk = $.exValidationRules,
435        id = _t.attr("id"),
436        txt = "",
437        _this = this;
438
439      if ( _t.hasClass("chkgroup") ) {
440        var groupInputs = $(_this.conf.groupInputs, t);
441        groupInputs.each(function(i) {
442          var self = $(this);
443          txt += self.val();
444          if( CL.indexOf("chkemail") !== -1 && i==0 && self.val().length > 0 )
445            txt += "@";
446        });
447      } else {
448        txt = _t.val();
449      }
450
451      var check = {
452        isError: false,
453        failed: function(t, c) {
454          var msg = chk[c][0];
455          if ( c.match(/chkmin/i) && CL.match(/chkmin(\d+)/i) ) {
456            msg = RegExp.$1 + msg;
457          } else
458          if ( c.match(/chkmax/i) && CL.match(/chkmax(\d+)/i) ) {
459            msg = RegExp.$1 + msg;
460          }
461
462          if( fnConfirmation(err) ) {
463            err(t, id, _this.conf.errMsgPrefix + msg);
464          } else {
465            _t.addClass("err");
466            $("."+c, "#err_"+id).show();
467            $("#err_"+id).stop(true, true).fadeIn();
468            _this.insertErrMsg(t, id, c, _this.conf.errMsgPrefix + msg);
469            _this.getErrHeight(id);
470          }
471          this.isError = true;
472        }
473      };
474
475      var c;
476			for ( c in chk ) {
477				if ( _t.hasClass(c)
478				|| (c === "chkmin" && CL.match(/(?:\s+|^)chkmin\d+(?:\s+|$)/) )
479				|| (c === "chkmax" && CL.match(/(?:\s+|^)chkmax\d+(?:\s+|$)/) )
480				|| ( CL.indexOf(c) !== -1 && CL.indexOf("chkretype") !== -1 ) ) {
481					if ( typeof(chk[c][1]) !== "function" ) {
482						if ( !txt.match(chk[c][1]) ) {
483							check.failed(t, c);
484						} else
485						if ( _this.conf.stepValidation ) {
486							if ( $(".errMsg:visible", "#err_"+id).length > 1 ) {
487								$("."+c, "#err_"+id).hide();
488								_this.getErrHeight(id);
489							}
490						}
491					} else {
492						if ( !chk[c][1](txt, t) ) {
493							check.failed(t, c);
494						} else
495						if ( _this.conf.stepValidation ) {
496							if ( $(".errMsg:visible", "#err_"+id).length > 1 ) {
497								$("."+c, "#err_"+id).hide();
498								_this.getErrHeight(id);
499							}
500						}
501					}
502				}
503			}
504
505			if ( !check.isError ) {
506				if ( fnConfirmation(ok) ) {
507					ok(t, id);
508				} else {
509					_t.removeClass("err");
510					$("#err_"+id).fadeOut();
511				}
512			}
513    }
514  }
515
516  // Common functions
517  function returnReg() {
518    var validationClasses = "";
519    for( var c in $.exValidationRules ) {
520      validationClasses += "(?:\\s+|^)"+c+"(?:\\s+|$)|";
521    }
522    validationClasses += "(?:\\s+|^)chkmin\\d+(?:\\s+|$)|";
523    validationClasses += "(?:\\s+|^)chkmax\\d+(?:\\s+|$)|";
524    validationClasses = validationClasses.replace(/\|$/,"");
525    return new RegExp(validationClasses);
526  }
527  function errFocusClear(errZIndex) {
528    $(".formError")
529      .removeClass("fadeOut")
530      .css("zIndex", errZIndex)
531  }
532  function errFocus(id, errZIndex) {
533    var formError = $(".formError");
534    formError.removeClass("fadeOut").css("zIndex", errZIndex);
535    formError.not(id).addClass("fadeOut");
536    $(id).css({
537      zIndex: errZIndex + 100
538    });
539  }
540  function fnConfirmation(fn) {
541    return fn && typeof fn === "function";
542  }
543  function randomInt() {
544    return Math.floor(Math.random()*10)+1;
545  }
546
547  // Extense the namespace of jQuery as method
548  // This function returns instance
549  $.fn.exValidation = function(options) {
550    return new exValidation(this, options);
551  };
552  if ( !$.fn.validation ) {
553    $.fn.validation = $.fn.exValidation;
554  }
555})(jQuery, this);

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.