/** * @required $ jQuery */ (function (ns) { function fnProxy(fn, context) { if ( typeof context === "string" ) { var tmp = fn[ context ]; context = fn; fn = tmp; } // Quick check to determine if target is callable, in the spec // this throws a TypeError, but we will just return undefined. if ( !jQuery.isFunction( fn ) ) { return undefined; } // Simulated bind var args = Array.prototype.slice.call( arguments, 2 ), proxy = function() { return fn.apply( context, args.concat( Array.prototype.slice.call( arguments ) ) ); }; // Set the guid of unique handler to the same of original handler, so it can be removed proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++; return proxy; } ns.Form = function (options) { this.construct.apply(this, arguments); }; var fn = ns.Form.prototype; fn.construct = function (options) { this.options = $.extend({ /** * @type {String} */ formId: null, /** * @type {Object} ex.: {monthNum: dayCount, ...} */ monthDayCount: null }, options); this.form = $('#' + this.options.formId); this.dueDateMonth = $('[name="dueDateMonth"]', this.form); this.dueDateDay = $('[name="dueDateDay"]', this.form); this.dueDateMonth.bind('change', fnProxy(this.onMonthChange, this)); }; fn.onMonthChange = function (e) { var month = this.dueDateMonth.val(), lastDay = '', dayCount, i; if ('' == month || null == (dayCount = this.options.monthDayCount[month])) { this.dueDateDay.val('').attr('disabled', true); return; } this.dueDateDay.attr('disabled', true); if (this.dueDateDay.val() > dayCount) { this.dueDateDay.val(''); } this.dueDateDay.find('option').each(function (index, node) { var $node = $(node); lastDay = $node.val(); if (lastDay !== '' && lastDay > dayCount) { $node.remove(); } }); if (lastDay < dayCount) { for (i = +lastDay + 1; i <= dayCount; ++i) { $('