'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } !function ($) { /** * Abide module. * @module foundation.abide */ var Abide = function () { /** * Creates a new instance of Abide. * @class * @fires Abide#init * @param {Object} element - jQuery object to add the trigger to. * @param {Object} options - Overrides to the default plugin settings. */ function Abide(element) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, Abide); this.$element = element; this.options = $.extend({}, Abide.defaults, this.$element.data(), options); this._init(); Foundation.registerPlugin(this, 'Abide'); } /** * Initializes the Abide plugin and calls functions to get Abide functioning on load. * @private */ _createClass(Abide, [{ key: '_init', value: function _init() { this.$inputs = this.$element.find('input, textarea, select'); this._events(); } /** * Initializes events for Abide. * @private */ }, { key: '_events', value: function _events() { var _this2 = this; this.$element.off('.abide').on('reset.zf.abide', function () { _this2.resetForm(); }).on('submit.zf.abide', function () { return _this2.validateForm(); }); if (this.options.validateOn === 'fieldChange') { this.$inputs.off('change.zf.abide').on('change.zf.abide', function (e) { _this2.validateInput($(e.target)); }); } if (this.options.liveValidate) { this.$inputs.off('input.zf.abide').on('input.zf.abide', function (e) { _this2.validateInput($(e.target)); }); } if (this.options.validateOnBlur) { this.$inputs.off('blur.zf.abide').on('blur.zf.abide', function (e) { _this2.validateInput($(e.target)); }); } } /** * Calls necessary functions to update Abide upon DOM change * @private */ }, { key: '_reflow', value: function _reflow() { this._init(); } /** * Checks whether or not a form element has the required attribute and if it's checked or not * @param {Object} element - jQuery object to check for required attribute * @returns {Boolean} Boolean value depends on whether or not attribute is checked or empty */ }, { key: 'requiredCheck', value: function requiredCheck($el) { if (!$el.attr('required')) return true; var isGood = true; switch ($el[0].type) { case 'checkbox': isGood = $el[0].checked; break; case 'select': case 'select-one': case 'select-multiple': var opt = $el.find('option:selected'); if (!opt.length || !opt.val()) isGood = false; break; default: if (!$el.val() || !$el.val().length) isGood = false; } return isGood; } /** * Based on $el, get the first element with selector in this order: * 1. The element's direct sibling('s). * 3. The element's parent's children. * * This allows for multiple form errors per input, though if none are found, no form errors will be shown. * * @param {Object} $el - jQuery object to use as reference to find the form error selector. * @returns {Object} jQuery object with the selector. */ }, { key: 'findFormError', value: function findFormError($el) { var $error = $el.siblings(this.options.formErrorSelector); if (!$error.length) { $error = $el.parent().find(this.options.formErrorSelector); } return $error; } /** * Get the first element in this order: * 2. The