(function($, undefined) { $.fn.monthpicker = function(options) { var months = options.months || ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'], monthpicker = function(el) { this._el = $(el); this._init(); this._render(); this._renderyears(); this._rendermonths(); this._bind(); }; monthpicker.prototype = { destroy: function() { this._el.off('click'); this._yearsselect.off('click'); this._container.off('click'); $(document).off('click', $.proxy(this._hide, this)); this._container.remove(); }, _init: function() { this._el.html(options.years[0]+'-'+months[0]); this._el.data('monthpicker', this); }, _bind: function() { this._el.on('click', $.proxy(this._show, this)); $(document).on('click', $.proxy(this._hide, this)); this._yearsselect.on('click', function(e) { e.stoppropagation(); }); this._container.on('click', 'button', $.proxy(this._selectmonth, this)); }, _show: function(e) { e.preventdefault(); e.stoppropagation(); this._container.css('display', 'inline-block'); }, _hide: function() { this._container.css('display', 'none'); }, _selectmonth: function(e) { var monthindex = $(e.target).data('value'), month = months[monthindex], year = this._yearsselect.val(); if(this._el.attr('type')=="text"){ this._el.attr("value",year+'-'+month); }else{ this._el.html(year+'-'+month); } if (options.onmonthselect) { options.onmonthselect(monthindex, year); } }, _render: function() { var linkposition = this._el.position(), cssoptions = { display: 'none', position: 'absolute', top: linkposition.top + this._el.height() + (options.topoffset || 0), left: linkposition.left }; this._id = (new date).valueof(); this._container = $('
') .css(cssoptions) .appendto($('body')); }, _renderyears: function() { var markup = $.map(options.years, function(year) { return ''; }); var yearswrap = $('
').appendto(this._container); this._yearsselect = $('