friends_ajax_core 0.0.51

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/app/assets/images/icons-16/icon-arrow-down-hover.png +0 -0
  3. data/app/assets/images/icons-16/icon-arrow-down.png +0 -0
  4. data/app/assets/images/icons-16/icon-arrow-right-hover.png +0 -0
  5. data/app/assets/images/icons-16/icon-arrow-right.png +0 -0
  6. data/app/assets/images/icons/icon-close.png +0 -0
  7. data/app/assets/images/icons/loader-16.png +0 -0
  8. data/app/assets/images/icons/loader-24.png +0 -0
  9. data/app/assets/images/menu/alpha-bg-60.png +0 -0
  10. data/app/assets/images/menu/alpha-bg-75.png +0 -0
  11. data/app/assets/images/menu/alpha-bg-95.png +0 -0
  12. data/app/assets/images/menu/alpha-bg-99.png +0 -0
  13. data/app/assets/javascripts/ajax_callbacks_core/common.js.erb +83 -0
  14. data/app/assets/javascripts/ajax_callbacks_core/forms.js.erb +27 -0
  15. data/app/assets/javascripts/ajax_callbacks_core/helpers.js.erb +216 -0
  16. data/app/assets/javascripts/ajax_ext_core/colorpicker.js +484 -0
  17. data/app/assets/javascripts/ajax_ext_core/date.js.erb +335 -0
  18. data/app/assets/javascripts/ajax_ext_core/faye.js +2 -0
  19. data/app/assets/javascripts/ajax_ext_core/jquery-json.js +178 -0
  20. data/app/assets/javascripts/ajax_ext_core/jquery-ui-timepicker-addon.js +1923 -0
  21. data/app/assets/javascripts/ajax_ext_core/jquery.hash.js +203 -0
  22. data/app/assets/javascripts/ajax_ext_core/jquery.jsonSuggest.js +25 -0
  23. data/app/assets/javascripts/ajax_ext_core/jquery.mtz.monthpicker.js +271 -0
  24. data/app/assets/javascripts/ajax_ext_core/preload_images.js +56 -0
  25. data/app/assets/javascripts/ajax_ui_core/autocomplete.js.erb +26 -0
  26. data/app/assets/javascripts/ajax_ui_core/datepicker.js.erb +144 -0
  27. data/app/assets/javascripts/ajax_ui_core/friends_ui.js.erb +23 -0
  28. data/app/assets/javascripts/ajax_ui_core/overlay.js.erb +85 -0
  29. data/app/assets/javascripts/ajax_ui_core/slide-down.js +163 -0
  30. data/app/assets/javascripts/friends_ajax_core.js.erb +11 -0
  31. data/app/assets/javascripts/init_ajax_core.js.erb +22 -0
  32. data/app/controllers/friends_ajax_controller.rb +6 -0
  33. data/app/helpers/friends_ajax_helper.rb +176 -0
  34. data/app/views/layouts/_ajax_overlay.html.erb +5 -0
  35. data/app/views/layouts/_info_overlay.html.erb +9 -0
  36. data/app/views/layouts/_invisible_overlay.html.erb +10 -0
  37. data/app/views/layouts/_layout_defaults.html.erb +39 -0
  38. data/app/views/layouts/_overlay_js.html.erb +30 -0
  39. data/app/views/layouts/ajax_overlay.html.erb +5 -0
  40. data/app/views/layouts/info_overlay.html.erb +9 -0
  41. data/config/routes.rb +10 -0
  42. data/lib/friends_ajax_core.rb +117 -0
  43. data/lib/friends_ajax_core/version.rb +4 -0
  44. metadata +143 -0
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Hash
3
+ * a jQuery plugin that implements the MooTools's Hash, a brand new native/object.
4
+ *
5
+ * Copyright (c) 2010-2011 Guillaume Coguiec <g.coguiec@gmail.com>
6
+ *
7
+ * Inspired by MooTools (mootools-core, mootools-more) under the same MIT license.
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is furnished
14
+ * to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ * THE SOFTWARE.
26
+ */
27
+
28
+ (function($, window) {
29
+
30
+ if (window.Hash) { return; }
31
+
32
+ var Hash = function(params) {
33
+ params = ($.isFunction(params)) ? { initialize: params} : params;
34
+ var Object = function() {
35
+ var value = (this.initialize) ? this.initialize.apply(this, arguments) : this;
36
+ return value;
37
+ };
38
+ $.extend(Object, this);
39
+ $.extend(Object.prototype, params);
40
+ return Object;
41
+ };
42
+
43
+ var Hash = new Hash({
44
+ name: 'Hash',
45
+ length: 0,
46
+ _internals: [ 'length', '$type' ],
47
+
48
+ initialize: function(o) {
49
+ if ('undefined' != typeof o) { this.merge(o); }
50
+ this.$type = this.name.toLowerCase();
51
+ },
52
+
53
+ isHash: function(o) {
54
+ if ('undefined' === typeof o) { return false; }
55
+ return (this.name.toLowerCase() === o.$type);
56
+ },
57
+
58
+ clone: function(o) {
59
+ o = (undefined === o) ? this : o;
60
+ if (!this.isHash(o)) { throw new Error('cannot clone a non-' + this.name + ' object.'); }
61
+ var clone = new Hash();
62
+ for (var key in o) { if (this.has(key, o)) { clone[key] = o[key]; } }
63
+ return clone;
64
+ },
65
+
66
+ has: function(key, bind) {
67
+ bind = (undefined === bind) ? this : bind;
68
+ if (0 <= $.inArray(key, this._internals)) { return false; }
69
+ return Object.prototype.hasOwnProperty.call(bind, key);
70
+ },
71
+
72
+ each: function(fn, bind) {
73
+ bind = (bind) ? bind : this;
74
+ for (var key in this) { if (this.has(key)) { fn.call(bind, key, this[key], this); } }
75
+ },
76
+
77
+ merge: function() {
78
+ var argc = arguments.length, argv = Array.prototype.slice.call(arguments);
79
+ if (0 === argc) { return this; }
80
+ for (var offset in argv) {
81
+ var o = (this.isHash(argv[offset])) ? argv[offset].clone() : argv[offset];
82
+ for (var key in o) { if (this.has(key, o)) { this[key] = o[key]; } }
83
+ }
84
+ this._updateLength();
85
+ return this;
86
+ },
87
+
88
+ set: function(key, value) {
89
+ if (!this[key] || this.has(key)) { this[key] = value; }
90
+ this._updateLength();
91
+ return this;
92
+ },
93
+
94
+ get: function(key) { return (this[key] && this.has(key)) ? this[key] : null; },
95
+
96
+ erase: function(key) {
97
+ if (this.has(key)) { delete this[key]; }
98
+ this._updateLength();
99
+ return this;
100
+ },
101
+
102
+ empty: function() {
103
+ this.each(function(key, value) { if (this.has(key)) { delete this[key]; } }, this);
104
+ this.length = 0;
105
+ return this;
106
+ },
107
+
108
+ keyOf: function (value) {
109
+ var keys = [];
110
+ for (var key in this) { if (this.has(key) && value === this[key]) { keys.push(key); } }
111
+ return (!keys.length) ? null : ((1 === keys.length) ? keys[0] : keys);
112
+ },
113
+
114
+ keys: function() {
115
+ var keys = [];
116
+ for (var key in this) { if (this.has(key)) { keys.push(key); } }
117
+ return keys;
118
+ },
119
+
120
+ values: function() {
121
+ var values = [];
122
+ for (var key in this) { if (this.has(key)) { values.push(this[key]); } }
123
+ return values;
124
+ },
125
+
126
+ cherrypick: function(deep, deeper) {
127
+ var argc = arguments.length, argv = Array.prototype.slice.call(arguments);
128
+ deep = (undefined === deep) ? false : deep;
129
+ deeper = (undefined === deeper) ? false: deeper;
130
+ if (0 === argc) { return this.toObject(false); }
131
+ var o = {};
132
+ for (var offset in argv) {
133
+ var key = argv[offset];
134
+ if (this.has(key)) {
135
+ o[key] = (deep && this.isHash(this[key])) ? this[key].toObject(deeper) : this[key];
136
+ }
137
+ }
138
+ return o;
139
+ },
140
+
141
+ contains: function(value) { return (null != this.keyOf(value)); },
142
+
143
+ register: function(key, value) {
144
+ if (undefined === this[key]) { this[key] = value; }
145
+ this._updateLength();
146
+ return this;
147
+ },
148
+
149
+ map: function(fn, bind, asObject) {
150
+ var results = {};
151
+ bind = (undefined === bind) ? this : bind;
152
+ asObject = (undefined === asObject) ? false : asObject;
153
+ for (var key in this) {
154
+ if (this.has(key)) { results[key] = fn.call(bind, key, this[key], this); }
155
+ }
156
+ return (asObject) ? results : new Hash(results);
157
+ },
158
+
159
+ filter: function(fn, bind, asObject) {
160
+ var results = {};
161
+ bind = (undefined === bind) ? this : bind;
162
+ asObject = (undefined === asObject) ? false : asObject;
163
+ for (var key in this) {
164
+ var value = this[key];
165
+ if (this.has(key) && fn.call(bind, key, value, this)) { results[key] = value; }
166
+ }
167
+ return (asObject) ? results : new Hash(results);
168
+ },
169
+
170
+ toObject: function(deep, deeper, fn) {
171
+ var o = {}, self = this;
172
+ deep = (undefined === deep) ? false : deep;
173
+ deeper = (undefined === deeper) ? false: deeper;
174
+ self = ('function' === typeof fn) ? this.map(fn, this) : self;
175
+ for (var key in self) {
176
+ if (self.has(key)) {
177
+ o[key] = (deep && self.isHash(self[key])) ? self[key].toObject(deeper) : self[key];
178
+ }
179
+ }
180
+ return o;
181
+ },
182
+
183
+ _updateLength: function() {
184
+ var length = 0;
185
+ for (var key in this) { length += ((this.has(key)) ? 1 : 0); }
186
+ this.length = length;
187
+ },
188
+
189
+ toString: function() {
190
+ var results = this.toObject(true, true, function(key, value) {
191
+ if ('object' === typeof value) { return value + ''; }
192
+ return value;
193
+ });
194
+ if ('undefined' === typeof window.JSON) { return results.toString(); }
195
+ return (JSON.stringify) ? JSON.stringify(results) : results.toString();
196
+ },
197
+
198
+ toJSON: function() { return this.toString(); }
199
+ });
200
+ $.extend(window, { Hash: Hash, $H: Hash });
201
+ $.extend($, { isHash: function(o) { return new Hash().isHash(o); } });
202
+
203
+ })(jQuery, this);
@@ -0,0 +1,25 @@
1
+
2
+ (function($){$.fn.jsonSuggest=function(searchData,settings){var defaults={minCharacters:1,maxResults:undefined,wildCard:"",caseSensitive:false,notCharacter:"!",maxHeight:350,highlightMatches:true,onSelect:undefined,ajaxResults:false};settings=$.extend(defaults,settings);return this.each(function(){function regexEscape(txt,omit){var specials=['/','.','*','+','?','|','(',')','[',']','{','}','\\'];if(omit){for(var i=0;i<specials.length;i++){if(specials[i]===omit){specials.splice(i,1);}}}
3
+ var escapePatt=new RegExp('(\\'+specials.join('|\\')+')','g');return txt.replace(escapePatt,'\\$1');}
4
+ var obj=$(this),wildCardPatt=new RegExp(regexEscape(settings.wildCard||''),'g'),results=$('<div />'),currentSelection,pageX,pageY;function selectResultItem(item){obj.val(item.text);$(results).html('').hide();if(typeof settings.onSelect==='function'){settings.onSelect(item);}}
5
+ function setHoverClass(el){$('div.resultItem',results).removeClass('hover');$(el).addClass('hover');currentSelection=el;}
6
+ function buildResults(resultObjects,sFilterTxt){sFilterTxt="("+sFilterTxt+")";var bOddRow=true,i,iFound=0,filterPatt=settings.caseSensitive?new RegExp(sFilterTxt,"g"):new RegExp(sFilterTxt,"ig");$(results).html('').hide();for(i=0;i<resultObjects.length;i+=1){var item=$('<div />'),text=resultObjects[i].text;if(settings.highlightMatches===true){text=text.replace(filterPatt,"<strong>$1</strong>");}
7
+ $(item).append('<p class="text">'+text+'</p>');if(typeof resultObjects[i].extra==='string'){$(item).append('<p class="extra">'+resultObjects[i].extra+'</p>');}
8
+ if(typeof resultObjects[i].image==='string'){$(item).prepend('<img src="'+resultObjects[i].image+'" />').append('<br style="clear:both;" />');}
9
+ $(item).addClass('resultItem').addClass((bOddRow)?'odd':'even').click(function(n){return function(){selectResultItem(resultObjects[n]);};}(i)).mouseover(function(el){return function(){setHoverClass(el);};}(item));$(results).append(item);bOddRow=!bOddRow;iFound+=1;if(typeof settings.maxResults==='number'&&iFound>=settings.maxResults){break;}}
10
+ if($('div',results).length>0){currentSelection=undefined;$(results).show().css('height','auto');if($(results).height()>settings.maxHeight){$(results).css({'overflow':'auto','height':settings.maxHeight+'px'});}}}
11
+ function runSuggest(e){if(this.value.length<settings.minCharacters){$(results).html('').hide();return false;}
12
+ var resultObjects=[],sFilterTxt=(!settings.wildCard)?regexEscape(this.value):regexEscape(this.value,settings.wildCard).replace(wildCardPatt,'.*'),bMatch=true,filterPatt,i;if(settings.notCharacter&&sFilterTxt.indexOf(settings.notCharacter)===0){sFilterTxt=sFilterTxt.substr(settings.notCharacter.length,sFilterTxt.length);if(sFilterTxt.length>0){bMatch=false;}}
13
+ sFilterTxt=sFilterTxt||'.*';sFilterTxt=settings.wildCard?'^'+sFilterTxt:sFilterTxt;filterPatt=settings.caseSensitive?new RegExp(sFilterTxt):new RegExp(sFilterTxt,"i");if(settings.ajaxResults===true){resultObjects=searchData(this.value,settings.wildCard,settings.caseSensitive,settings.notCharacter);if(typeof resultObjects==='string'){resultObjects=JSON.parse(resultObjects);}}
14
+ else{for(i=0;i<searchData.length;i+=1){if(filterPatt.test(searchData[i].text)===bMatch){resultObjects.push(searchData[i]);}}}
15
+ buildResults(resultObjects,sFilterTxt);}
16
+ function keyListener(e){switch(e.keyCode){case 13:$(currentSelection).trigger('click');return false;case 40:if(typeof currentSelection==='undefined'){currentSelection=$('div.resultItem:first',results).get(0);}
17
+ else{currentSelection=$(currentSelection).next().get(0);}
18
+ setHoverClass(currentSelection);if(currentSelection){$(results).scrollTop(currentSelection.offsetTop);}
19
+ return false;case 38:if(typeof currentSelection==='undefined'){currentSelection=$('div.resultItem:last',results).get(0);}
20
+ else{currentSelection=$(currentSelection).prev().get(0);}
21
+ setHoverClass(currentSelection);if(currentSelection){$(results).scrollTop(currentSelection.offsetTop);}
22
+ return false;default:runSuggest.apply(this,[e]);}}
23
+ $(results).addClass('jsonSuggestResults').css({'top':(obj.position().top+obj.height()+5)+'px','left':obj.position().left+'px','width':obj.width()+'px'}).hide();obj.after(results).keyup(keyListener).blur(function(e){var resPos=$(results).offset();resPos.bottom=resPos.top+$(results).height();resPos.right=resPos.left+$(results).width();if(pageY<resPos.top||pageY>resPos.bottom||pageX<resPos.left||pageX>resPos.right){$(results).hide();}}).focus(function(e){$(results).css({'top':(obj.position().top+obj.height()+5)+'px','left':obj.position().left+'px'});if($('div',results).length>0){$(results).show();}}).attr('autocomplete','off');$().mousemove(function(e){pageX=e.pageX;pageY=e.pageY;});if($.browser.opera){obj.keydown(function(e){if(e.keyCode===40){return keyListener(e);}});}
24
+ settings.notCharacter=regexEscape(settings.notCharacter||'');if(!settings.ajaxResults){if(typeof searchData==='function'){searchData=searchData();}
25
+ if(typeof searchData==='string'){searchData=JSON.parse(searchData);}}});};})(jQuery);
@@ -0,0 +1,271 @@
1
+ /*
2
+ * jQuery UI Monthpicker
3
+ *
4
+ * @licensed MIT <see below>
5
+ * @licensed GPL <see below>
6
+ *
7
+ * @author Luciano Costa
8
+ * http://lucianocosta.info/jquery.mtz.monthpicker/
9
+ *
10
+ * Depends:
11
+ * jquery.ui.core.js
12
+ */
13
+
14
+ /**
15
+ * MIT License
16
+ * Copyright (c) 2011, Luciano Costa
17
+ *
18
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
19
+ * of this software and associated documentation files (the "Software"), to deal
20
+ * in the Software without restriction, including without limitation the rights
21
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22
+ * copies of the Software, and to permit persons to whom the Software is
23
+ * furnished to do so, subject to the following conditions:
24
+ *
25
+ * The above copyright notice and this permission notice shall be included in
26
+ * all copies or substantial portions of the Software.
27
+ *
28
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34
+ * THE SOFTWARE.
35
+ */
36
+ /**
37
+ * GPL LIcense
38
+ * Copyright (c) 2011, Luciano Costa
39
+ *
40
+ * This program is free software: you can redistribute it and/or modify it
41
+ * under the terms of the GNU General Public License as published by the
42
+ * Free Software Foundation, either version 3 of the License, or
43
+ * (at your option) any later version.
44
+ *
45
+ * This program is distributed in the hope that it will be useful, but
46
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
47
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
48
+ * for more details.
49
+ *
50
+ * You should have received a copy of the GNU General Public License along
51
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
52
+ */
53
+
54
+ ;(function ($) {
55
+
56
+ var methods = {
57
+ init : function (options) {
58
+ return this.each(function () {
59
+ var
60
+ $this = $(this),
61
+ data = $this.data('monthpicker'),
62
+ year = (options && options.year) ? options.year : (new Date()).getFullYear(),
63
+ settings = $.extend({
64
+ pattern: 'mm/yyyy',
65
+ selectedMonth: null,
66
+ selectedMonthName: '',
67
+ selectedYear: year,
68
+ startYear: year - 10,
69
+ finalYear: year + 10,
70
+ monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
71
+ id: "monthpicker_" + (Math.random() * Math.random()).toString().replace('.', ''),
72
+ openOnFocus: true,
73
+ disabledMonths: []
74
+ }, options);
75
+
76
+ settings.dateSeparator = settings.pattern.replace(/(mmm|mm|m|yyyy|yy|y)/ig,'');
77
+
78
+ // If the plugin hasn't been initialized yet for this element
79
+ if (!data) {
80
+ $(this).data('monthpicker', {
81
+ 'target': $this,
82
+ 'settings': settings
83
+ });
84
+
85
+ if (settings.openOnFocus === true) {
86
+ $this.bind('focus', function () {
87
+ $this.monthpicker('show');
88
+ });
89
+ }
90
+
91
+ $this.monthpicker('mountWidget', settings);
92
+
93
+ $this.bind('monthpicker-click-month', function (e, month, year) {
94
+ $this.monthpicker('setValue', settings);
95
+ $this.monthpicker('hide');
96
+ });
97
+
98
+ // hide widget when user clicks elsewhere on page
99
+ $this.addClass("mtz-monthpicker-widgetcontainer");
100
+ $(document).unbind("mousedown.mtzmonthpicker").bind("mousedown.mtzmonthpicker", function (e) {
101
+ if (!e.target.className || e.target.className.toString().indexOf('mtz-monthpicker') < 0) {
102
+ $(".mtz-monthpicker-widgetcontainer").each(function () {
103
+ if (typeof($(this).data("monthpicker"))!="undefined") {
104
+ $(this).monthpicker('hide');
105
+ }
106
+ });
107
+ }
108
+ });
109
+ }
110
+
111
+ });
112
+ },
113
+
114
+ show: function (n) {
115
+ var widget = $('#' + this.data('monthpicker').settings.id);
116
+ var monthpicker = $('#' + this.data('monthpicker').target.attr("id") + ':eq(0)');
117
+ widget.css("top", monthpicker.offset().top + monthpicker.outerHeight());
118
+ widget.css("left", monthpicker.offset().left);
119
+ widget.show();
120
+ widget.find('select').focus();
121
+ this.trigger('monthpicker-show');
122
+ },
123
+
124
+ hide: function () {
125
+ var widget = $('#' + this.data('monthpicker').settings.id);
126
+ if (widget.is(':visible')) {
127
+ widget.hide();
128
+ this.trigger('monthpicker-hide');
129
+ }
130
+ },
131
+
132
+ setValue: function (settings) {
133
+ var
134
+ month = settings.selectedMonth,
135
+ year = settings.selectedYear;
136
+
137
+ if(settings.pattern.indexOf('mmm') >= 0) {
138
+ month = settings.selectedMonthName;
139
+ } else if(settings.pattern.indexOf('mm') >= 0 && settings.selectedMonth < 10) {
140
+ month = '0' + settings.selectedMonth;
141
+ }
142
+
143
+ if(settings.pattern.indexOf('yyyy') < 0) {
144
+ year = year.toString().substr(2,2);
145
+ }
146
+
147
+ if (settings.pattern.indexOf('y') > settings.pattern.indexOf(settings.dateSeparator)) {
148
+ this.val(month + settings.dateSeparator + year);
149
+ } else {
150
+ this.val(year + settings.dateSeparator + month);
151
+ }
152
+
153
+ this.change();
154
+ },
155
+
156
+ disableMonths: function (months) {
157
+ var
158
+ settings = this.data('monthpicker').settings,
159
+ container = $('#' + settings.id);
160
+
161
+ settings.disabledMonths = months;
162
+
163
+ container.find('.mtz-monthpicker-month').each(function () {
164
+ var m = parseInt($(this).data('month'));
165
+ if ($.inArray(m, months) >= 0) {
166
+ $(this).addClass('ui-state-disabled');
167
+ } else {
168
+ $(this).removeClass('ui-state-disabled');
169
+ }
170
+ });
171
+ },
172
+
173
+ mountWidget: function (settings) {
174
+ var
175
+ monthpicker = this,
176
+ container = $('<div id="'+ settings.id +'" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" />'),
177
+ header = $('<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all mtz-monthpicker" />'),
178
+ combo = $('<select class="mtz-monthpicker mtz-monthpicker-year" />'),
179
+ table = $('<table class="mtz-monthpicker" />'),
180
+ tbody = $('<tbody class="mtz-monthpicker" />'),
181
+ tr = $('<tr class="mtz-monthpicker" />'),
182
+ td = '',
183
+ selectedYear = settings.selectedYear,
184
+ option = null,
185
+ attrSelectedYear = $(this).data('selected-year'),
186
+ attrStartYear = $(this).data('start-year'),
187
+ attrFinalYear = $(this).data('final-year');
188
+
189
+ if (attrSelectedYear) {
190
+ settings.selectedYear = attrSelectedYear;
191
+ }
192
+
193
+ if (attrStartYear) {
194
+ settings.startYear = attrStartYear;
195
+ }
196
+
197
+ if (attrFinalYear) {
198
+ settings.finalYear = attrFinalYear;
199
+ }
200
+
201
+ container.css({
202
+ position:'absolute',
203
+ zIndex:999999,
204
+ whiteSpace:'nowrap',
205
+ width:'120px',
206
+ overflow:'hidden',
207
+ textAlign:'center',
208
+ display:'none',
209
+ top: monthpicker.offset().top + monthpicker.outerHeight(),
210
+ left: monthpicker.offset().left
211
+ });
212
+
213
+ // mount years combo
214
+ for (var i = settings.startYear; i <= settings.finalYear; i++) {
215
+ var option = $('<option class="mtz-monthpicker" />').attr('value', i).append(i);
216
+ if (settings.selectedYear === i) {
217
+ option.attr('selected', 'selected');
218
+ }
219
+ combo.append(option);
220
+ }
221
+ header.append(combo).appendTo(container);
222
+
223
+ // mount months table
224
+ for (var i=1; i<=12; i++) {
225
+ td = $('<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" />').attr('data-month',i);
226
+ td.append(settings.monthNames[i-1]);
227
+ tr.append(td).appendTo(tbody);
228
+ if (i % 3 === 0) {
229
+ tr = $('<tr class="mtz-monthpicker" />');
230
+ }
231
+ }
232
+
233
+ table.append(tbody).appendTo(container);
234
+
235
+ container.find('.mtz-monthpicker-month').bind('click', function () {
236
+ var m = parseInt($(this).data('month'));
237
+ if ($.inArray(m, settings.disabledMonths) < 0 ) {
238
+ settings.selectedMonth = $(this).data('month');
239
+ settings.selectedMonthName = $(this).text();
240
+ monthpicker.trigger('monthpicker-click-month', $(this).data('month'));
241
+ }
242
+ });
243
+
244
+ container.find('.mtz-monthpicker-year').bind('change', function () {
245
+ settings.selectedYear = $(this).val();
246
+ monthpicker.trigger('monthpicker-change-year', $(this).val());
247
+ });
248
+
249
+ container.appendTo('body');
250
+ },
251
+
252
+ destroy: function () {
253
+ return this.each(function () {
254
+ // TODO: look for other things to remove
255
+ $(this).removeData('monthpicker');
256
+ });
257
+ }
258
+
259
+ };
260
+
261
+ $.fn.monthpicker = function (method) {
262
+ if (methods[method]) {
263
+ return methods[method].apply(this, Array.prototype.slice.call( arguments, 1 ));
264
+ } else if (typeof method === 'object' || ! method) {
265
+ return methods.init.apply(this, arguments);
266
+ } else {
267
+ $.error('Method ' + method + ' does not exist on jQuery.mtz.monthpicker');
268
+ }
269
+ };
270
+
271
+ })(jQuery);