ink_ui_rails 2.1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +21 -0
- data/README.md +39 -0
- data/lib/ink_ui_rails.rb +8 -0
- data/lib/ink_ui_rails/version.rb +3 -0
- data/vendor/assets/fonts/font/FontAwesome.otf +0 -0
- data/vendor/assets/fonts/font/fontawesome-webfont.eot +0 -0
- data/vendor/assets/fonts/font/fontawesome-webfont.svg +399 -0
- data/vendor/assets/fonts/font/fontawesome-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/fontawesome-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-b-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-b-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-b-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-b-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-bi-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-bi-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-bi-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-bi-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-c-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-c-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-c-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-c-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-l-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-l-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-l-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-l-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-li-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-li-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-li-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-li-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-m-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-m-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-m-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-m-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-mi-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-mi-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-mi-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-mi-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-r-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-r-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-r-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-r-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-ri-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-ri-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-ri-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-ri-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntumono-b-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntumono-b-webfont.svg +242 -0
- data/vendor/assets/fonts/font/ubuntumono-b-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntumono-b-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntumono-bi-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntumono-bi-webfont.svg +242 -0
- data/vendor/assets/fonts/font/ubuntumono-bi-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntumono-bi-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntumono-r-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntumono-r-webfont.svg +242 -0
- data/vendor/assets/fonts/font/ubuntumono-r-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntumono-r-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntumono-ri-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntumono-ri-webfont.svg +242 -0
- data/vendor/assets/fonts/font/ubuntumono-ri-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntumono-ri-webfont.woff +0 -0
- data/vendor/assets/images/img/SAPOlogo.png +0 -0
- data/vendor/assets/images/img/favicon.ico +0 -0
- data/vendor/assets/images/img/home_bkg.png +0 -0
- data/vendor/assets/images/img/home_logo_IE.jpg +0 -0
- data/vendor/assets/images/img/icon_Sprite.png +0 -0
- data/vendor/assets/images/img/ink-favicon.ico +0 -0
- data/vendor/assets/images/img/logo_home.png +0 -0
- data/vendor/assets/images/img/shot_ink.png +0 -0
- data/vendor/assets/images/img/shot_intra.png +0 -0
- data/vendor/assets/images/img/shot_livebots.png +0 -0
- data/vendor/assets/images/img/shot_meo.png +0 -0
- data/vendor/assets/images/img/shot_musicbox.png +0 -0
- data/vendor/assets/images/img/shot_pessoa.png +0 -0
- data/vendor/assets/images/img/splash.1024x748.png +0 -0
- data/vendor/assets/images/img/splash.320x460.png +0 -0
- data/vendor/assets/images/img/splash.768x1004.png +0 -0
- data/vendor/assets/images/img/touch-icon.114.png +0 -0
- data/vendor/assets/images/img/touch-icon.16.png +0 -0
- data/vendor/assets/images/img/touch-icon.256.png +0 -0
- data/vendor/assets/images/img/touch-icon.57.png +0 -0
- data/vendor/assets/images/img/touch-icon.72.png +0 -0
- data/vendor/assets/javascripts/autoload.js +85 -0
- data/vendor/assets/javascripts/example.json +1174 -0
- data/vendor/assets/javascripts/holder.js +440 -0
- data/vendor/assets/javascripts/html5shiv-printshiv.js +496 -0
- data/vendor/assets/javascripts/html5shiv.js +298 -0
- data/vendor/assets/javascripts/ink-all.js +18015 -0
- data/vendor/assets/javascripts/ink-ui.js +7737 -0
- data/vendor/assets/javascripts/ink.aux.js +506 -0
- data/vendor/assets/javascripts/ink.close.js +54 -0
- data/vendor/assets/javascripts/ink.datepicker.js +1194 -0
- data/vendor/assets/javascripts/ink.datepicker.pt.js +32 -0
- data/vendor/assets/javascripts/ink.draggable.js +437 -0
- data/vendor/assets/javascripts/ink.droppable.js +193 -0
- data/vendor/assets/javascripts/ink.formvalidator.js +712 -0
- data/vendor/assets/javascripts/ink.gallery.js +757 -0
- data/vendor/assets/javascripts/ink.imagequery.js +259 -0
- data/vendor/assets/javascripts/ink.js +10278 -0
- data/vendor/assets/javascripts/ink.modal.js +628 -0
- data/vendor/assets/javascripts/ink.pagination.js +473 -0
- data/vendor/assets/javascripts/ink.progressbar.js +110 -0
- data/vendor/assets/javascripts/ink.smoothscroller.js +234 -0
- data/vendor/assets/javascripts/ink.sortablelist.js +338 -0
- data/vendor/assets/javascripts/ink.spy.js +123 -0
- data/vendor/assets/javascripts/ink.sticky.js +254 -0
- data/vendor/assets/javascripts/ink.table.js +621 -0
- data/vendor/assets/javascripts/ink.tabs.js +426 -0
- data/vendor/assets/javascripts/ink.toggle.js +218 -0
- data/vendor/assets/javascripts/ink.treeview.js +179 -0
- data/vendor/assets/javascripts/ink_ui.js +1 -0
- data/vendor/assets/javascripts/modernizr.js +815 -0
- data/vendor/assets/javascripts/prettify.js +28 -0
- data/vendor/assets/stylesheets/ink/_ink-ie7.css +1662 -0
- data/vendor/assets/stylesheets/ink/_ink.css +7496 -0
- data/vendor/assets/stylesheets/ink/ink_ui.scss.css +2 -0
- data/vendor/assets/stylesheets/ink_ui.scss.css +1 -0
- metadata +203 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
/**
|
2
|
+
* @module Ink.UI.Close_1
|
3
|
+
* @author inkdev AT sapo.pt
|
4
|
+
* @version 1
|
5
|
+
*/
|
6
|
+
Ink.createModule('Ink.UI.Close', '1', ['Ink.Dom.Event_1','Ink.Dom.Css_1','Ink.Util.Array_1'], function(Event, Css, InkArray ) {
|
7
|
+
'use strict';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Subscribes clicks on the document.body. If and only if you clicked on an element
|
11
|
+
* having class "ink-close", will go up the DOM hierarchy looking for an element with any
|
12
|
+
* of the following classes: "ink-alert", "ink-alert-block".
|
13
|
+
* If it is found, it is removed from the DOM.
|
14
|
+
*
|
15
|
+
* One should call close once per page (full page refresh).
|
16
|
+
*
|
17
|
+
* @class Ink.UI.Close
|
18
|
+
* @constructor
|
19
|
+
* @version 1
|
20
|
+
* @uses Ink.Dom.Event
|
21
|
+
* @uses Ink.Dom.Css
|
22
|
+
* @uses Ink.Util.Array
|
23
|
+
* @example
|
24
|
+
* <script>
|
25
|
+
* Ink.requireModules(['Ink.UI.Close_1'],function( Close ){
|
26
|
+
* new Close();
|
27
|
+
* });
|
28
|
+
* </script>
|
29
|
+
*/
|
30
|
+
var Close = function() {
|
31
|
+
|
32
|
+
Event.observe(document.body, 'click', function(ev) {
|
33
|
+
var el = Event.element(ev);
|
34
|
+
if (!Css.hasClassName(el, 'ink-close') && !Css.hasClassName(el, 'ink-dismiss')) { return; }
|
35
|
+
|
36
|
+
var classes;
|
37
|
+
do {
|
38
|
+
if (!el.className) { continue; }
|
39
|
+
classes = el.className.split(' ');
|
40
|
+
if (!classes) { continue; }
|
41
|
+
if ( InkArray.inArray('ink-alert', classes) ||
|
42
|
+
InkArray.inArray('ink-alert-block', classes) ) { break; }
|
43
|
+
} while ((el = el.parentNode));
|
44
|
+
|
45
|
+
if (el) {
|
46
|
+
Event.stop(ev);
|
47
|
+
el.parentNode.removeChild(el);
|
48
|
+
}
|
49
|
+
});
|
50
|
+
};
|
51
|
+
|
52
|
+
return Close;
|
53
|
+
|
54
|
+
});
|
@@ -0,0 +1,1194 @@
|
|
1
|
+
/**
|
2
|
+
* @module Ink.UI.DatePicker_1
|
3
|
+
* @author inkdev AT sapo.pt
|
4
|
+
* @version 1
|
5
|
+
*/
|
6
|
+
Ink.createModule('Ink.UI.DatePicker', '1', ['Ink.UI.Aux_1','Ink.Dom.Event_1','Ink.Dom.Css_1','Ink.Dom.Element_1','Ink.Dom.Selector_1','Ink.Util.Array_1','Ink.Util.Date_1'], function(Aux, Event, Css, Element, Selector, InkArray, InkDate ) {
|
7
|
+
'use strict';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @class Ink.UI.DatePicker
|
11
|
+
* @constructor
|
12
|
+
* @version 1
|
13
|
+
* @uses Ink.UI.Aux
|
14
|
+
* @uses Ink.Dom.Event
|
15
|
+
* @uses Ink.Dom.Css
|
16
|
+
* @uses Ink.Dom.Element
|
17
|
+
* @uses Ink.Dom.Selector
|
18
|
+
* @uses Ink.Util.Array
|
19
|
+
* @uses Ink.Util.Date
|
20
|
+
*
|
21
|
+
* @param {String|DOMElement} selector
|
22
|
+
* @param {Object} [options] Options
|
23
|
+
* @param {String} [options.instance] unique id for the datepicker
|
24
|
+
* @param {String} [options.format] Date format string
|
25
|
+
* @param {String} [options.cssClass] CSS class to be applied to the datepicker
|
26
|
+
* @param {String} [options.position] position the datepicker. Accept right or bottom, default is right
|
27
|
+
* @param {Boolean} [options.onFocus] if the datepicker should open when the target element is focused
|
28
|
+
* @param {Function} [options.onYearSelected] callback function to execute when the year is selected
|
29
|
+
* @param {Function} [options.onMonthSelected] callback function to execute when the month is selected
|
30
|
+
* @param {Function} [options.validDayFn] callback function to execute when 'rendering' the day (in the month view)
|
31
|
+
* @param {String} [options.startDate] Date to define init month. Must be in yyyy-mm-dd format
|
32
|
+
* @param {Function} [options.onSetDate] callback to execute when set date
|
33
|
+
* @param {Boolean} [options.displayInSelect] whether to display the component in a select. defaults to false.
|
34
|
+
* @param {Boolean} [options.showClose] whether to display the close button or not. defaults to true.
|
35
|
+
* @param {Boolean} [options.showClean] whether to display the clean button or not. defaults to true.
|
36
|
+
* @param {String} [options.yearRange] enforce limits to year for the Date, ex: '1990:2020' (deprecated)
|
37
|
+
* @param {String} [options.dateRange] enforce limits to year, month and day for the Date, ex: '1990-08-25:2020-11'
|
38
|
+
* @paran {Number} [options.startWeekDay] day to use as first column on the calendar view. Defaults to Monday (1)
|
39
|
+
* @param {String} [options.closeText] text to display on close button. defaults to 'Fechar'
|
40
|
+
* @param {String} [options.cleanText] text to display on clean button. defaults to 'Limpar'
|
41
|
+
* @param {String} [options.prevLinkText] text to display on the previous button. defaults to '«'
|
42
|
+
* @param {String} [options.nextLinkText] text to display on the previous button. defaults to '«'
|
43
|
+
* @param {String} [options.ofText] text to display between month and year. defaults to ' de '
|
44
|
+
* @param {Object} [options.month] Hash of month names. Defaults to portuguese month names. January is 1.
|
45
|
+
* @param {Object} [options.wDay] Hash of weekdays. Defaults to portuguese month names. Sunday is 0.
|
46
|
+
*
|
47
|
+
* @example
|
48
|
+
* <input type="text" id="dPicker" />
|
49
|
+
* <script>
|
50
|
+
* Ink.requireModules(['Ink.Dom.Selector_1','Ink.UI.DatePicker_1'],function( Selector, DatePicker ){
|
51
|
+
* var datePickerElement = Ink.s('#dPicker');
|
52
|
+
* var datePickerObj = new DatePicker( datePickerElement );
|
53
|
+
* });
|
54
|
+
* </script>
|
55
|
+
*/
|
56
|
+
var DatePicker = function(selector, options) {
|
57
|
+
|
58
|
+
if (selector) {
|
59
|
+
this._dataField = Aux.elOrSelector(selector, '1st argument');
|
60
|
+
}
|
61
|
+
|
62
|
+
this._options = Ink.extendObj({
|
63
|
+
instance: 'scdp_' + Math.round(99999*Math.random()),
|
64
|
+
format: 'yyyy-mm-dd',
|
65
|
+
cssClass: 'sapo_component_datepicker',
|
66
|
+
position: 'right',
|
67
|
+
onFocus: true,
|
68
|
+
onYearSelected: undefined,
|
69
|
+
onMonthSelected: undefined,
|
70
|
+
validDayFn: undefined,
|
71
|
+
startDate: false, // format yyyy-mm-dd
|
72
|
+
onSetDate: false,
|
73
|
+
displayInSelect: false,
|
74
|
+
showClose: true,
|
75
|
+
showClean: true,
|
76
|
+
yearRange: false,
|
77
|
+
dateRange: false,
|
78
|
+
startWeekDay: 1,
|
79
|
+
closeText: 'Close',
|
80
|
+
cleanText: 'Clear',
|
81
|
+
prevLinkText: '«',
|
82
|
+
nextLinkText: '»',
|
83
|
+
ofText: ' de ',
|
84
|
+
month: {
|
85
|
+
1:'January',
|
86
|
+
2:'February',
|
87
|
+
3:'March',
|
88
|
+
4:'April',
|
89
|
+
5:'May',
|
90
|
+
6:'June',
|
91
|
+
7:'July',
|
92
|
+
8:'August',
|
93
|
+
9:'September',
|
94
|
+
10:'October',
|
95
|
+
11:'November',
|
96
|
+
12:'December'
|
97
|
+
},
|
98
|
+
wDay: {
|
99
|
+
0:'Sunday',
|
100
|
+
1:'Monday',
|
101
|
+
2:'Tuesday',
|
102
|
+
3:'Wednesday',
|
103
|
+
4:'Thursday',
|
104
|
+
5:'Friday',
|
105
|
+
6:'Saturday'
|
106
|
+
}
|
107
|
+
}, Element.data(this._dataField) || {});
|
108
|
+
|
109
|
+
this._options = Ink.extendObj(this._options, options || {});
|
110
|
+
|
111
|
+
this._options.format = this._dateParsers[ this._options.format ] || this._options.format;
|
112
|
+
|
113
|
+
this._hoverPicker = false;
|
114
|
+
|
115
|
+
this._picker = null;
|
116
|
+
if (this._options.pickerField) {
|
117
|
+
this._picker = Aux.elOrSelector(this._options.pickerField, 'pickerField');
|
118
|
+
}
|
119
|
+
|
120
|
+
this._today = new Date();
|
121
|
+
this._day = this._today.getDate( );
|
122
|
+
this._month = this._today.getMonth( );
|
123
|
+
this._year = this._today.getFullYear( );
|
124
|
+
|
125
|
+
this._setMinMax( this._options.dateRange || this._options.yearRange );
|
126
|
+
this._data = new Date( Date.UTC.apply( this , this._checkDateRange( this._year , this._month , this._day ) ) );
|
127
|
+
|
128
|
+
if(this._options.startDate && typeof this._options.startDate === 'string' && /\d\d\d\d\-\d\d\-\d\d/.test(this._options.startDate)) {
|
129
|
+
this.setDate( this._options.startDate );
|
130
|
+
}
|
131
|
+
|
132
|
+
this._init();
|
133
|
+
|
134
|
+
this._render();
|
135
|
+
|
136
|
+
if ( !this._options.startDate ){
|
137
|
+
if( this._dataField && typeof this._dataField.value === 'string' && this._dataField.value){
|
138
|
+
this.setDate( this._dataField.value );
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
Aux.registerInstance(this, this._containerObject, 'datePicker');
|
143
|
+
};
|
144
|
+
|
145
|
+
DatePicker.prototype = {
|
146
|
+
version: '0.1',
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Initialization function. Called by the constructor and
|
150
|
+
* receives the same parameters.
|
151
|
+
*
|
152
|
+
* @method _init
|
153
|
+
* @private
|
154
|
+
*/
|
155
|
+
_init: function(){
|
156
|
+
Ink.extendObj(this._options,this._lang || {});
|
157
|
+
},
|
158
|
+
|
159
|
+
/**
|
160
|
+
* Renders the DatePicker's markup
|
161
|
+
*
|
162
|
+
* @method _render
|
163
|
+
* @private
|
164
|
+
*/
|
165
|
+
_render: function() {
|
166
|
+
/*jshint maxstatements:100, maxcomplexity:30 */
|
167
|
+
this._containerObject = document.createElement('div');
|
168
|
+
|
169
|
+
this._containerObject.id = this._options.instance;
|
170
|
+
|
171
|
+
this._containerObject.className = 'sapo_component_datepicker';
|
172
|
+
var dom = document.getElementsByTagName('body')[0];
|
173
|
+
|
174
|
+
if(this._options.showClose || this._options.showClean){
|
175
|
+
this._superTopBar = document.createElement("div");
|
176
|
+
this._superTopBar.className = 'sapo_cal_top_options';
|
177
|
+
if(this._options.showClean){
|
178
|
+
var clean = document.createElement('a');
|
179
|
+
clean.className = 'clean';
|
180
|
+
clean.innerHTML = this._options.cleanText;
|
181
|
+
this._superTopBar.appendChild(clean);
|
182
|
+
}
|
183
|
+
if(this._options.showClose){
|
184
|
+
var close = document.createElement('a');
|
185
|
+
close.className = 'close';
|
186
|
+
close.innerHTML = this._options.closeText;
|
187
|
+
this._superTopBar.appendChild(close);
|
188
|
+
}
|
189
|
+
this._containerObject.appendChild(this._superTopBar);
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
var calendarTop = document.createElement("div");
|
194
|
+
calendarTop.className = 'sapo_cal_top';
|
195
|
+
|
196
|
+
this._monthDescContainer = document.createElement("div");
|
197
|
+
this._monthDescContainer.className = 'sapo_cal_month_desc';
|
198
|
+
|
199
|
+
this._monthPrev = document.createElement('div');
|
200
|
+
this._monthPrev.className = 'sapo_cal_prev';
|
201
|
+
this._monthPrev.innerHTML ='<a href="#prev" class="change_month_prev">' + this._options.prevLinkText + '</a>';
|
202
|
+
|
203
|
+
this._monthNext = document.createElement('div');
|
204
|
+
this._monthNext.className = 'sapo_cal_next';
|
205
|
+
this._monthNext.innerHTML ='<a href="#next" class="change_month_next">' + this._options.nextLinkText + '</a>';
|
206
|
+
|
207
|
+
calendarTop.appendChild(this._monthPrev);
|
208
|
+
calendarTop.appendChild(this._monthDescContainer);
|
209
|
+
calendarTop.appendChild(this._monthNext);
|
210
|
+
|
211
|
+
this._monthContainer = document.createElement("div");
|
212
|
+
this._monthContainer.className = 'sapo_cal_month';
|
213
|
+
|
214
|
+
this._containerObject.appendChild(calendarTop);
|
215
|
+
this._containerObject.appendChild(this._monthContainer);
|
216
|
+
|
217
|
+
this._monthSelector = document.createElement('ul');
|
218
|
+
this._monthSelector.className = 'sapo_cal_month_selector';
|
219
|
+
|
220
|
+
var ulSelector;
|
221
|
+
var liMonth;
|
222
|
+
for(var i=1; i<=12; i++){
|
223
|
+
if ((i-1) % 4 === 0) {
|
224
|
+
ulSelector = document.createElement('ul');
|
225
|
+
}
|
226
|
+
liMonth = document.createElement('li');
|
227
|
+
liMonth.innerHTML = '<a href="#" class="sapo_calmonth_' + ( (String(i).length === 2) ? i : "0" + i) + '">' + this._options.month[i].substring(0,3) + '</a>';
|
228
|
+
ulSelector.appendChild(liMonth);
|
229
|
+
if (i % 4 === 0) {
|
230
|
+
this._monthSelector.appendChild(ulSelector);
|
231
|
+
}
|
232
|
+
}
|
233
|
+
|
234
|
+
this._containerObject.appendChild(this._monthSelector);
|
235
|
+
|
236
|
+
this._yearSelector = document.createElement('ul');
|
237
|
+
this._yearSelector.className = 'sapo_cal_year_selector';
|
238
|
+
|
239
|
+
this._containerObject.appendChild(this._yearSelector);
|
240
|
+
|
241
|
+
if(!this._options.onFocus || this._options.displayInSelect){
|
242
|
+
if(!this._options.pickerField){
|
243
|
+
this._picker = document.createElement('a');
|
244
|
+
this._picker.href = '#open_cal';
|
245
|
+
this._picker.innerHTML = 'open';
|
246
|
+
this._picker.style.position = 'absolute';
|
247
|
+
this._picker.style.top = Element.elementTop(this._dataField);
|
248
|
+
this._picker.style.left = Element.elementLeft(this._dataField) + (Element.elementWidth(this._dataField) || 0) + 5 + 'px';
|
249
|
+
this._dataField.parentNode.appendChild(this._picker);
|
250
|
+
this._picker.className = 'sapo_cal_date_picker';
|
251
|
+
} else {
|
252
|
+
this._picker = Aux.elOrSelector(this._options.pickerField, 'pickerField');
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
if(this._options.displayInSelect){
|
257
|
+
if (this._options.dayField && this._options.monthField && this._options.yearField || this._options.pickerField) {
|
258
|
+
this._options.dayField = Aux.elOrSelector(this._options.dayField, 'dayField');
|
259
|
+
this._options.monthField = Aux.elOrSelector(this._options.monthField, 'monthField');
|
260
|
+
this._options.yearField = Aux.elOrSelector(this._options.yearField, 'yearField');
|
261
|
+
}
|
262
|
+
else {
|
263
|
+
throw "To use display in select you *MUST* to set dayField, monthField, yearField and pickerField!";
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
dom.insertBefore(this._containerObject, dom.childNodes[0]);
|
268
|
+
// this._dataField.parentNode.appendChild(this._containerObject, dom.childNodes[0]);
|
269
|
+
|
270
|
+
if (!this._picker) {
|
271
|
+
Event.observe(this._dataField,'focus',Ink.bindEvent(function(){
|
272
|
+
this._containerObject = Element.clonePosition(this._containerObject, this._dataField);
|
273
|
+
|
274
|
+
if ( this._options.position === 'bottom' )
|
275
|
+
{
|
276
|
+
this._containerObject.style.top = Element.elementHeight(this._dataField) + Element.offsetTop(this._dataField) + 'px';
|
277
|
+
this._containerObject.style.left = Element.offset2(this._dataField)[0] +'px';
|
278
|
+
}
|
279
|
+
else
|
280
|
+
{
|
281
|
+
this._containerObject.style.top = Element.offset2(this._dataField)[1] +'px';
|
282
|
+
this._containerObject.style.left = Element.elementWidth(this._dataField) + Element.offset2(this._dataField)[0] +'px';
|
283
|
+
}
|
284
|
+
//dom.appendChild(this._containerObject);
|
285
|
+
this._updateDate();
|
286
|
+
this._showMonth();
|
287
|
+
this._containerObject.style.display = 'block';
|
288
|
+
},this));
|
289
|
+
}
|
290
|
+
else {
|
291
|
+
Event.observe(this._picker,'click',Ink.bindEvent(function(e){
|
292
|
+
Event.stop(e);
|
293
|
+
this._containerObject = Element.clonePosition(this._containerObject,this._picker);
|
294
|
+
this._updateDate();
|
295
|
+
this._showMonth();
|
296
|
+
this._containerObject.style.display = 'block';
|
297
|
+
},this));
|
298
|
+
}
|
299
|
+
|
300
|
+
if(!this._options.displayInSelect){
|
301
|
+
Event.observe(this._dataField,'change', Ink.bindEvent(function() {
|
302
|
+
this._updateDate( );
|
303
|
+
this._showDefaultView( );
|
304
|
+
this.setDate( );
|
305
|
+
if ( !this._hoverPicker )
|
306
|
+
{
|
307
|
+
this._containerObject.style.display = 'none';
|
308
|
+
}
|
309
|
+
},this));
|
310
|
+
Event.observe(this._dataField,'blur', Ink.bindEvent(function() {
|
311
|
+
if ( !this._hoverPicker )
|
312
|
+
{
|
313
|
+
this._containerObject.style.display = 'none';
|
314
|
+
}
|
315
|
+
},this));
|
316
|
+
}
|
317
|
+
else {
|
318
|
+
Event.observe(this._options.dayField,'change', Ink.bindEvent(function(){
|
319
|
+
var yearSelected = this._options.yearField[this._options.yearField.selectedIndex].value;
|
320
|
+
if(yearSelected !== '' && yearSelected !== 0) {
|
321
|
+
this._updateDate();
|
322
|
+
this._showDefaultView();
|
323
|
+
}
|
324
|
+
},this));
|
325
|
+
Event.observe(this._options.monthField,'change', Ink.bindEvent(function(){
|
326
|
+
var yearSelected = this._options.yearField[this._options.yearField.selectedIndex].value;
|
327
|
+
if(yearSelected !== '' && yearSelected !== 0){
|
328
|
+
this._updateDate();
|
329
|
+
this._showDefaultView();
|
330
|
+
}
|
331
|
+
},this));
|
332
|
+
Event.observe(this._options.yearField,'change', Ink.bindEvent(function(){
|
333
|
+
this._updateDate();
|
334
|
+
this._showDefaultView();
|
335
|
+
},this));
|
336
|
+
}
|
337
|
+
|
338
|
+
Event.observe(document,'click',Ink.bindEvent(function(e){
|
339
|
+
if (e.target === undefined) { e.target = e.srcElement; }
|
340
|
+
if (!Element.descendantOf(this._containerObject, e.target) && e.target !== this._dataField) {
|
341
|
+
if (!this._picker) {
|
342
|
+
this._containerObject.style.display = 'none';
|
343
|
+
}
|
344
|
+
else if (e.target !== this._picker &&
|
345
|
+
(!this._options.displayInSelect ||
|
346
|
+
(e.target !== this._options.dayField && e.target !== this._options.monthField && e.target !== this._options.yearField) ) ) {
|
347
|
+
if (!this._options.dayField ||
|
348
|
+
(!Element.descendantOf(this._options.dayField, e.target) &&
|
349
|
+
!Element.descendantOf(this._options.monthField, e.target) &&
|
350
|
+
!Element.descendantOf(this._options.yearField, e.target) ) ) {
|
351
|
+
this._containerObject.style.display = 'none';
|
352
|
+
}
|
353
|
+
}
|
354
|
+
}
|
355
|
+
},this));
|
356
|
+
|
357
|
+
this._showMonth();
|
358
|
+
|
359
|
+
this._monthChanger = document.createElement('a');
|
360
|
+
this._monthChanger.href = '#monthchanger';
|
361
|
+
this._monthChanger.className = 'sapo_cal_link_month';
|
362
|
+
this._monthChanger.innerHTML = this._options.month[this._month + 1];
|
363
|
+
|
364
|
+
this._deText = document.createElement('span');
|
365
|
+
this._deText.innerHTML = this._options._deText;
|
366
|
+
|
367
|
+
|
368
|
+
this._yearChanger = document.createElement('a');
|
369
|
+
this._yearChanger.href = '#yearchanger';
|
370
|
+
this._yearChanger.className = 'sapo_cal_link_year';
|
371
|
+
this._yearChanger.innerHTML = this._year;
|
372
|
+
this._monthDescContainer.innerHTML = '';
|
373
|
+
this._monthDescContainer.appendChild(this._monthChanger);
|
374
|
+
this._monthDescContainer.appendChild(this._deText);
|
375
|
+
this._monthDescContainer.appendChild(this._yearChanger);
|
376
|
+
|
377
|
+
Event.observe(this._containerObject,'mouseover',Ink.bindEvent(function(e)
|
378
|
+
{
|
379
|
+
Event.stop( e );
|
380
|
+
this._hoverPicker = true;
|
381
|
+
},this));
|
382
|
+
|
383
|
+
Event.observe(this._containerObject,'mouseout',Ink.bindEvent(function(e)
|
384
|
+
{
|
385
|
+
Event.stop( e );
|
386
|
+
this._hoverPicker = false;
|
387
|
+
},this));
|
388
|
+
|
389
|
+
Event.observe(this._containerObject,'click',Ink.bindEvent(function(e){
|
390
|
+
if(typeof(e.target) === 'undefined'){
|
391
|
+
e.target = e.srcElement;
|
392
|
+
}
|
393
|
+
var className = e.target.className;
|
394
|
+
var isInactive = className.indexOf( 'sapo_cal_off' ) !== -1;
|
395
|
+
|
396
|
+
Event.stop(e);
|
397
|
+
|
398
|
+
if( className.indexOf('sapo_cal_') === 0 && !isInactive ){
|
399
|
+
var day = className.substr( 9 , 2 );
|
400
|
+
if( Number( day ) ) {
|
401
|
+
this.setDate( this._year + '-' + ( this._month + 1 ) + '-' + day );
|
402
|
+
this._containerObject.style.display = 'none';
|
403
|
+
} else if(className === 'sapo_cal_link_month'){
|
404
|
+
this._monthContainer.style.display = 'none';
|
405
|
+
this._yearSelector.style.display = 'none';
|
406
|
+
this._monthPrev.childNodes[0].className = 'action_inactive';
|
407
|
+
this._monthNext.childNodes[0].className = 'action_inactive';
|
408
|
+
this._setActiveMonth();
|
409
|
+
this._monthSelector.style.display = 'block';
|
410
|
+
} else if(className === 'sapo_cal_link_year'){
|
411
|
+
this._monthPrev.childNodes[0].className = 'action_inactive';
|
412
|
+
this._monthNext.childNodes[0].className = 'action_inactive';
|
413
|
+
this._monthSelector.style.display = 'none';
|
414
|
+
this._monthContainer.style.display = 'none';
|
415
|
+
this._showYearSelector();
|
416
|
+
this._yearSelector.style.display = 'block';
|
417
|
+
}
|
418
|
+
} else if( className.indexOf("sapo_calmonth_") === 0 && !isInactive ){
|
419
|
+
var month=className.substr(14,2);
|
420
|
+
if(Number(month)){
|
421
|
+
this._month = month - 1;
|
422
|
+
// if( typeof this._options.onMonthSelected === 'function' ){
|
423
|
+
// this._options.onMonthSelected(this, {
|
424
|
+
// 'year': this._year,
|
425
|
+
// 'month' : this._month
|
426
|
+
// });
|
427
|
+
// }
|
428
|
+
this._monthSelector.style.display = 'none';
|
429
|
+
this._monthPrev.childNodes[0].className = 'change_month_prev';
|
430
|
+
this._monthNext.childNodes[0].className = 'change_month_next';
|
431
|
+
|
432
|
+
if ( this._year < this._yearMin || this._year === this._yearMin && this._month <= this._monthMin ){
|
433
|
+
this._monthPrev.childNodes[0].className = 'action_inactive';
|
434
|
+
}
|
435
|
+
else if( this._year > this._yearMax || this._year === this._yearMax && this._month >= this._monthMax ){
|
436
|
+
this._monthNext.childNodes[0].className = 'action_inactive';
|
437
|
+
}
|
438
|
+
|
439
|
+
this._updateCal();
|
440
|
+
this._monthContainer.style.display = 'block';
|
441
|
+
}
|
442
|
+
} else if( className.indexOf("sapo_calyear_") === 0 && !isInactive ){
|
443
|
+
var year=className.substr(13,4);
|
444
|
+
if(Number(year)){
|
445
|
+
this._year = year;
|
446
|
+
if( typeof this._options.onYearSelected === 'function' ){
|
447
|
+
this._options.onYearSelected(this, {
|
448
|
+
'year': this._year
|
449
|
+
});
|
450
|
+
}
|
451
|
+
this._monthPrev.childNodes[0].className = 'action_inactive';
|
452
|
+
this._monthNext.childNodes[0].className = 'action_inactive';
|
453
|
+
this._yearSelector.style.display='none';
|
454
|
+
this._setActiveMonth();
|
455
|
+
this._monthSelector.style.display='block';
|
456
|
+
}
|
457
|
+
} else if( className.indexOf('change_month_') === 0 && !isInactive ){
|
458
|
+
if(className === 'change_month_next'){
|
459
|
+
this._updateCal(1);
|
460
|
+
} else if(className === 'change_month_prev'){
|
461
|
+
this._updateCal(-1);
|
462
|
+
}
|
463
|
+
} else if( className.indexOf('change_year_') === 0 && !isInactive ){
|
464
|
+
if(className === 'change_year_next'){
|
465
|
+
this._showYearSelector(1);
|
466
|
+
} else if(className === 'change_year_prev'){
|
467
|
+
this._showYearSelector(-1);
|
468
|
+
}
|
469
|
+
} else if(className === 'clean'){
|
470
|
+
if(this._options.displayInSelect){
|
471
|
+
this._options.yearField.selectedIndex = 0;
|
472
|
+
this._options.monthField.selectedIndex = 0;
|
473
|
+
this._options.dayField.selectedIndex = 0;
|
474
|
+
} else {
|
475
|
+
this._dataField.value = '';
|
476
|
+
}
|
477
|
+
} else if(className === 'close'){
|
478
|
+
this._containerObject.style.display = 'none';
|
479
|
+
}
|
480
|
+
|
481
|
+
this._updateDescription();
|
482
|
+
},this));
|
483
|
+
|
484
|
+
},
|
485
|
+
|
486
|
+
/**
|
487
|
+
* Sets the range of dates allowed to be selected in the Date Picker
|
488
|
+
*
|
489
|
+
* @method _setMinMax
|
490
|
+
* @param {String} dateRange Two dates separated by a ':'. Example: 2013-01-01:2013-12-12
|
491
|
+
* @private
|
492
|
+
*/
|
493
|
+
_setMinMax : function( dateRange )
|
494
|
+
{
|
495
|
+
var auxDate;
|
496
|
+
if( dateRange )
|
497
|
+
{
|
498
|
+
var dates = dateRange.split( ':' );
|
499
|
+
var pattern = /^(\d{4})((\-)(\d{1,2})((\-)(\d{1,2}))?)?$/;
|
500
|
+
if ( dates[ 0 ] )
|
501
|
+
{
|
502
|
+
if ( dates[ 0 ] === 'NOW' )
|
503
|
+
{
|
504
|
+
this._yearMin = this._today.getFullYear( );
|
505
|
+
this._monthMin = this._today.getMonth( ) + 1;
|
506
|
+
this._dayMin = this._today.getDate( );
|
507
|
+
}
|
508
|
+
else if ( pattern.test( dates[ 0 ] ) )
|
509
|
+
{
|
510
|
+
auxDate = dates[ 0 ].split( '-' );
|
511
|
+
|
512
|
+
this._yearMin = Math.floor( auxDate[ 0 ] );
|
513
|
+
this._monthMin = Math.floor( auxDate[ 1 ] ) || 1;
|
514
|
+
this._dayMin = Math.floor( auxDate[ 2 ] ) || 1;
|
515
|
+
|
516
|
+
if ( 1 < this._monthMin && this._monthMin > 12 )
|
517
|
+
{
|
518
|
+
this._monthMin = 1;
|
519
|
+
this._dayMin = 1;
|
520
|
+
}
|
521
|
+
|
522
|
+
if ( 1 < this._dayMin && this._dayMin > this._daysInMonth( this._yearMin , this._monthMin ) )
|
523
|
+
{
|
524
|
+
this._dayMin = 1;
|
525
|
+
}
|
526
|
+
}
|
527
|
+
else
|
528
|
+
{
|
529
|
+
this._yearMin = Number.MIN_VALUE;
|
530
|
+
this._monthMin = 1;
|
531
|
+
this._dayMin = 1;
|
532
|
+
}
|
533
|
+
}
|
534
|
+
|
535
|
+
if ( dates[ 1 ] )
|
536
|
+
{
|
537
|
+
if ( dates[ 1 ] === 'NOW' )
|
538
|
+
{
|
539
|
+
this._yearMax = this._today.getFullYear( );
|
540
|
+
this._monthMax = this._today.getMonth( ) + 1;
|
541
|
+
this._dayMax = this._today.getDate( );
|
542
|
+
}
|
543
|
+
else if ( pattern.test( dates[ 1 ] ) )
|
544
|
+
{
|
545
|
+
auxDate = dates[ 1 ].split( '-' );
|
546
|
+
|
547
|
+
this._yearMax = Math.floor( auxDate[ 0 ] );
|
548
|
+
this._monthMax = Math.floor( auxDate[ 1 ] ) || 12;
|
549
|
+
this._dayMax = Math.floor( auxDate[ 2 ] ) || this._daysInMonth( this._yearMax , this._monthMax );
|
550
|
+
|
551
|
+
if ( 1 < this._monthMax && this._monthMax > 12 )
|
552
|
+
{
|
553
|
+
this._monthMax = 12;
|
554
|
+
this._dayMax = 31;
|
555
|
+
}
|
556
|
+
|
557
|
+
var MDay = this._daysInMonth( this._yearMax , this._monthMax );
|
558
|
+
if ( 1 < this._dayMax && this._dayMax > MDay )
|
559
|
+
{
|
560
|
+
this._dayMax = MDay;
|
561
|
+
}
|
562
|
+
}
|
563
|
+
else
|
564
|
+
{
|
565
|
+
this._yearMax = Number.MAX_VALUE;
|
566
|
+
this._monthMax = 12;
|
567
|
+
this._dayMax = 31;
|
568
|
+
}
|
569
|
+
}
|
570
|
+
|
571
|
+
if ( !( this._yearMax >= this._yearMin && (this._monthMax > this._monthMin || ( (this._monthMax === this._monthMin) && (this._dayMax >= this._dayMin) ) ) ) )
|
572
|
+
{
|
573
|
+
this._yearMin = Number.MIN_VALUE;
|
574
|
+
this._monthMin = 1;
|
575
|
+
this._dayMin = 1;
|
576
|
+
|
577
|
+
this._yearMax = Number.MAX_VALUE;
|
578
|
+
this._monthMax = 12;
|
579
|
+
this._dayMaXx = 31;
|
580
|
+
}
|
581
|
+
}
|
582
|
+
else
|
583
|
+
{
|
584
|
+
this._yearMin = Number.MIN_VALUE;
|
585
|
+
this._monthMin = 1;
|
586
|
+
this._dayMin = 1;
|
587
|
+
|
588
|
+
this._yearMax = Number.MAX_VALUE;
|
589
|
+
this._monthMax = 12;
|
590
|
+
this._dayMax = 31;
|
591
|
+
}
|
592
|
+
},
|
593
|
+
|
594
|
+
/**
|
595
|
+
* Checks if a date is between the valid range.
|
596
|
+
* Starts by checking if the date passed is valid. If not, will fallback to the 'today' date.
|
597
|
+
* Then checks if the all params are inside of the date range specified. If not, it will fallback to the nearest valid date (either Min or Max).
|
598
|
+
*
|
599
|
+
* @method _checkDateRange
|
600
|
+
* @param {Number} year Year with 4 digits (yyyy)
|
601
|
+
* @param {Number} month Month
|
602
|
+
* @param {Number} day Day
|
603
|
+
* @return {Array} Array with the final processed date.
|
604
|
+
* @private
|
605
|
+
*/
|
606
|
+
_checkDateRange : function( year , month , day )
|
607
|
+
{
|
608
|
+
if ( !this._isValidDate( year , month + 1 , day ) )
|
609
|
+
{
|
610
|
+
year = this._today.getFullYear( );
|
611
|
+
month = this._today.getMonth( );
|
612
|
+
day = this._today.getDate( );
|
613
|
+
}
|
614
|
+
|
615
|
+
if ( year > this._yearMax )
|
616
|
+
{
|
617
|
+
year = this._yearMax;
|
618
|
+
month = this._monthMax - 1;
|
619
|
+
day = this._dayMax;
|
620
|
+
}
|
621
|
+
else if ( year < this._yearMin )
|
622
|
+
{
|
623
|
+
year = this._yearMin;
|
624
|
+
month = this._monthMin - 1;
|
625
|
+
day = this._dayMin;
|
626
|
+
}
|
627
|
+
|
628
|
+
if ( year === this._yearMax && month + 1 > this._monthMax )
|
629
|
+
{
|
630
|
+
month = this._monthMax - 1;
|
631
|
+
day = this._dayMax;
|
632
|
+
}
|
633
|
+
else if ( year === this._yearMin && month + 1 < this._monthMin )
|
634
|
+
{
|
635
|
+
month = this._monthMin - 1;
|
636
|
+
day = this._dayMin;
|
637
|
+
}
|
638
|
+
|
639
|
+
if ( year === this._yearMax && month + 1 === this._monthMax && day > this._dayMax ){ day = this._dayMax; }
|
640
|
+
else if ( year === this._yearMin && month + 1 === this._monthMin && day < this._dayMin ){ day = this._dayMin; }
|
641
|
+
else if ( day > this._daysInMonth( year , month + 1 ) ){ day = this._daysInMonth( year , month + 1 ); }
|
642
|
+
|
643
|
+
return [ year , month , day ];
|
644
|
+
},
|
645
|
+
|
646
|
+
/**
|
647
|
+
* Sets the markup in the default view mode (showing the days).
|
648
|
+
* Also disables the previous and next buttons in case they don't meet the range requirements.
|
649
|
+
*
|
650
|
+
* @method _showDefaultView
|
651
|
+
* @private
|
652
|
+
*/
|
653
|
+
_showDefaultView: function(){
|
654
|
+
this._yearSelector.style.display = 'none';
|
655
|
+
this._monthSelector.style.display = 'none';
|
656
|
+
this._monthPrev.childNodes[0].className = 'change_month_prev';
|
657
|
+
this._monthNext.childNodes[0].className = 'change_month_next';
|
658
|
+
|
659
|
+
if ( this._year < this._yearMin || this._year === this._yearMin && this._month + 1 <= this._monthMin ){
|
660
|
+
this._monthPrev.childNodes[0].className = 'action_inactive';
|
661
|
+
}
|
662
|
+
else if( this._year > this._yearMax || this._year === this._yearMax && this._month + 1 >= this._monthMax ){
|
663
|
+
this._monthNext.childNodes[0].className = 'action_inactive';
|
664
|
+
}
|
665
|
+
|
666
|
+
this._monthContainer.style.display = 'block';
|
667
|
+
},
|
668
|
+
|
669
|
+
/**
|
670
|
+
* Updates the date shown on the datepicker
|
671
|
+
*
|
672
|
+
* @method _updateDate
|
673
|
+
* @private
|
674
|
+
*/
|
675
|
+
_updateDate: function(){
|
676
|
+
var dataParsed;
|
677
|
+
if(!this._options.displayInSelect){
|
678
|
+
if(this._dataField.value !== ''){
|
679
|
+
if(this._isDate(this._options.format,this._dataField.value)){
|
680
|
+
dataParsed = this._getDataArrayParsed(this._dataField.value);
|
681
|
+
dataParsed = this._checkDateRange( dataParsed[ 0 ] , dataParsed[ 1 ] - 1 , dataParsed[ 2 ] );
|
682
|
+
|
683
|
+
this._year = dataParsed[ 0 ];
|
684
|
+
this._month = dataParsed[ 1 ];
|
685
|
+
this._day = dataParsed[ 2 ];
|
686
|
+
}else{
|
687
|
+
this._dataField.value = '';
|
688
|
+
this._year = this._data.getFullYear( );
|
689
|
+
this._month = this._data.getMonth( );
|
690
|
+
this._day = this._data.getDate( );
|
691
|
+
}
|
692
|
+
this._data.setFullYear( this._year , this._month , this._day );
|
693
|
+
this._dataField.value = this._writeDateInFormat( );
|
694
|
+
}
|
695
|
+
} else {
|
696
|
+
dataParsed = [];
|
697
|
+
if(this._isValidDate(
|
698
|
+
dataParsed[0] = this._options.yearField[this._options.yearField.selectedIndex].value,
|
699
|
+
dataParsed[1] = this._options.monthField[this._options.monthField.selectedIndex].value,
|
700
|
+
dataParsed[2] = this._options.dayField[this._options.dayField.selectedIndex].value
|
701
|
+
)){
|
702
|
+
dataParsed = this._checkDateRange( dataParsed[ 0 ] , dataParsed[ 1 ] - 1 , dataParsed[ 2 ] );
|
703
|
+
|
704
|
+
this._year = dataParsed[ 0 ];
|
705
|
+
this._month = dataParsed[ 1 ];
|
706
|
+
this._day = dataParsed[ 2 ];
|
707
|
+
} else {
|
708
|
+
dataParsed = this._checkDateRange( dataParsed[ 0 ] , dataParsed[ 1 ] - 1 , 1 );
|
709
|
+
if(this._isValidDate( dataParsed[ 0 ], dataParsed[ 1 ] + 1 ,dataParsed[ 2 ] )){
|
710
|
+
this._year = dataParsed[ 0 ];
|
711
|
+
this._month = dataParsed[ 1 ];
|
712
|
+
this._day = this._daysInMonth(dataParsed[0],dataParsed[1]);
|
713
|
+
|
714
|
+
this.setDate();
|
715
|
+
}
|
716
|
+
}
|
717
|
+
}
|
718
|
+
this._updateDescription();
|
719
|
+
this._showMonth();
|
720
|
+
},
|
721
|
+
|
722
|
+
/**
|
723
|
+
* Updates the date description shown at the top of the datepicker
|
724
|
+
*
|
725
|
+
* @method _updateDescription
|
726
|
+
* @private
|
727
|
+
*/
|
728
|
+
_updateDescription: function(){
|
729
|
+
this._monthChanger.innerHTML = this._options.month[ this._month + 1 ];
|
730
|
+
this._deText.innerHTML = this._options.ofText;
|
731
|
+
this._yearChanger.innerHTML = this._year;
|
732
|
+
},
|
733
|
+
|
734
|
+
/**
|
735
|
+
* Renders the year selector view of the datepicker
|
736
|
+
*
|
737
|
+
* @method _showYearSelector
|
738
|
+
* @private
|
739
|
+
*/
|
740
|
+
_showYearSelector: function(){
|
741
|
+
if (arguments.length){
|
742
|
+
var year = + this._year + arguments[0]*10;
|
743
|
+
year=year-year%10;
|
744
|
+
if ( year>this._yearMax || year+9<this._yearMin ){
|
745
|
+
return;
|
746
|
+
}
|
747
|
+
this._year = + this._year + arguments[0]*10;
|
748
|
+
}
|
749
|
+
|
750
|
+
var str = "<li>";
|
751
|
+
var ano_base = this._year-(this._year%10);
|
752
|
+
|
753
|
+
for (var i=0; i<=11; i++){
|
754
|
+
if (i % 4 === 0){
|
755
|
+
str+='<ul>';
|
756
|
+
}
|
757
|
+
|
758
|
+
if (!i || i === 11){
|
759
|
+
if ( i && (ano_base+i-1)<=this._yearMax && (ano_base+i-1)>=this._yearMin ){
|
760
|
+
str+='<li><a href="#year_next" class="change_year_next">' + this._options.nextLinkText + '</a></li>';
|
761
|
+
} else if( (ano_base+i-1)<=this._yearMax && (ano_base+i-1)>=this._yearMin ){
|
762
|
+
str+='<li><a href="#year_prev" class="change_year_prev">' + this._options.prevLinkText + '</a></li>';
|
763
|
+
} else {
|
764
|
+
str +='<li> </li>';
|
765
|
+
}
|
766
|
+
} else {
|
767
|
+
if ( (ano_base+i-1)<=this._yearMax && (ano_base+i-1)>=this._yearMin ){
|
768
|
+
str+='<li><a href="#" class="sapo_calyear_' + (ano_base+i-1) + (((ano_base+i-1) === this._data.getFullYear()) ? ' sapo_cal_on' : '') + '">' + (ano_base+i-1) +'</a></li>';
|
769
|
+
} else {
|
770
|
+
str+='<li><a href="#" class="sapo_cal_off">' + (ano_base+i-1) +'</a></li>';
|
771
|
+
|
772
|
+
}
|
773
|
+
}
|
774
|
+
|
775
|
+
if ((i+1) % 4 === 0) {
|
776
|
+
str+='</ul>';
|
777
|
+
}
|
778
|
+
}
|
779
|
+
|
780
|
+
str += "</li>";
|
781
|
+
|
782
|
+
this._yearSelector.innerHTML = str;
|
783
|
+
},
|
784
|
+
|
785
|
+
/**
|
786
|
+
* This function returns the given date in an array format
|
787
|
+
*
|
788
|
+
* @method _getDataArrayParsed
|
789
|
+
* @param {String} dateStr A date on a string.
|
790
|
+
* @private
|
791
|
+
* @return {Array} The given date in an array format
|
792
|
+
*/
|
793
|
+
_getDataArrayParsed: function(dateStr){
|
794
|
+
var arrData = [];
|
795
|
+
var data = InkDate.set( this._options.format , dateStr );
|
796
|
+
if (data) {
|
797
|
+
arrData = [ data.getFullYear( ) , data.getMonth( ) + 1 , data.getDate( ) ];
|
798
|
+
}
|
799
|
+
return arrData;
|
800
|
+
},
|
801
|
+
|
802
|
+
/**
|
803
|
+
* Checks if a date is valid
|
804
|
+
*
|
805
|
+
* @method _isValidDate
|
806
|
+
* @param {Number} year
|
807
|
+
* @param {Number} month
|
808
|
+
* @param {Number} day
|
809
|
+
* @private
|
810
|
+
* @return {Boolean} True if the date is valid, false otherwise
|
811
|
+
*/
|
812
|
+
_isValidDate: function(year, month, day){
|
813
|
+
var yearRegExp = /^\d{4}$/;
|
814
|
+
var validOneOrTwo = /^\d{1,2}$/;
|
815
|
+
return (
|
816
|
+
yearRegExp.test(year) &&
|
817
|
+
validOneOrTwo.test(month) &&
|
818
|
+
validOneOrTwo.test(day) &&
|
819
|
+
month >= 1 &&
|
820
|
+
month <= 12 &&
|
821
|
+
day >= 1 &&
|
822
|
+
day <= this._daysInMonth(year,month)
|
823
|
+
);
|
824
|
+
},
|
825
|
+
|
826
|
+
/**
|
827
|
+
* Checks if a given date is an valid format.
|
828
|
+
*
|
829
|
+
* @method _isDate
|
830
|
+
* @param {String} format A date format.
|
831
|
+
* @param {String} dateStr A date on a string.
|
832
|
+
* @private
|
833
|
+
* @return {Boolean} True if the given date is valid according to the given format
|
834
|
+
*/
|
835
|
+
_isDate: function(format, dateStr){
|
836
|
+
try {
|
837
|
+
if (typeof format === 'undefined'){
|
838
|
+
return false;
|
839
|
+
}
|
840
|
+
var data = InkDate.set( format , dateStr );
|
841
|
+
if( data && this._isValidDate( data.getFullYear( ) , data.getMonth( ) + 1 , data.getDate( ) ) ){
|
842
|
+
return true;
|
843
|
+
}
|
844
|
+
} catch (ex) {}
|
845
|
+
|
846
|
+
return false;
|
847
|
+
},
|
848
|
+
|
849
|
+
|
850
|
+
/**
|
851
|
+
* This method returns the date written with the format specified on the options
|
852
|
+
*
|
853
|
+
* @method _writeDateInFormat
|
854
|
+
* @private
|
855
|
+
* @return {String} Returns the current date of the object in the specified format
|
856
|
+
*/
|
857
|
+
_writeDateInFormat:function(){
|
858
|
+
return InkDate.get( this._options.format , this._data );
|
859
|
+
},
|
860
|
+
|
861
|
+
/**
|
862
|
+
* This method allows the user to set the DatePicker's date on run-time.
|
863
|
+
*
|
864
|
+
* @method setDate
|
865
|
+
* @param {String} dateString A date string in yyyy-mm-dd format.
|
866
|
+
* @public
|
867
|
+
*/
|
868
|
+
setDate : function( dateString )
|
869
|
+
{
|
870
|
+
if ( typeof dateString === 'string' && /\d{4}-\d{1,2}-\d{1,2}/.test( dateString ) )
|
871
|
+
{
|
872
|
+
var auxDate = dateString.split( '-' );
|
873
|
+
this._year = auxDate[ 0 ];
|
874
|
+
this._month = auxDate[ 1 ] - 1;
|
875
|
+
this._day = auxDate[ 2 ];
|
876
|
+
}
|
877
|
+
|
878
|
+
this._setDate( );
|
879
|
+
},
|
880
|
+
|
881
|
+
/**
|
882
|
+
* Sets the chosen date on the target input field
|
883
|
+
*
|
884
|
+
* @method _setDate
|
885
|
+
* @param {DOMElement} objClicked Clicked object inside the DatePicker's calendar.
|
886
|
+
* @private
|
887
|
+
*/
|
888
|
+
_setDate : function( objClicked ){
|
889
|
+
if( typeof objClicked !== 'undefined' && objClicked.className && objClicked.className.indexOf('sapo_cal_') === 0 )
|
890
|
+
{
|
891
|
+
this._day = objClicked.className.substr( 9 , 2 );
|
892
|
+
}
|
893
|
+
this._data.setFullYear.apply( this._data , this._checkDateRange( this._year , this._month , this._day ) );
|
894
|
+
|
895
|
+
if(!this._options.displayInSelect){
|
896
|
+
this._dataField.value = this._writeDateInFormat();
|
897
|
+
} else {
|
898
|
+
this._options.dayField.value = this._data.getDate();
|
899
|
+
this._options.monthField.value = this._data.getMonth()+1;
|
900
|
+
this._options.yearField.value = this._data.getFullYear();
|
901
|
+
}
|
902
|
+
if(this._options.onSetDate) {
|
903
|
+
this._options.onSetDate( this , { date : this._data } );
|
904
|
+
}
|
905
|
+
},
|
906
|
+
|
907
|
+
/**
|
908
|
+
* Makes the necessary work to update the calendar
|
909
|
+
* when choosing a different month
|
910
|
+
*
|
911
|
+
* @method _updateCal
|
912
|
+
* @param {Number} inc Indicates previous or next month
|
913
|
+
* @private
|
914
|
+
*/
|
915
|
+
_updateCal: function(inc){
|
916
|
+
|
917
|
+
if( typeof this._options.onMonthSelected === 'function' ){
|
918
|
+
this._options.onMonthSelected(this, {
|
919
|
+
'year': this._year,
|
920
|
+
'month' : this._month
|
921
|
+
});
|
922
|
+
}
|
923
|
+
this._updateMonth(inc);
|
924
|
+
this._showMonth();
|
925
|
+
},
|
926
|
+
|
927
|
+
/**
|
928
|
+
* Function that returns the number of days on a given month on a given year
|
929
|
+
*
|
930
|
+
* @method _daysInMonth
|
931
|
+
* @param {Number} _y - year
|
932
|
+
* @param {Number} _m - month
|
933
|
+
* @private
|
934
|
+
* @return {Number} The number of days on a given month on a given year
|
935
|
+
*/
|
936
|
+
_daysInMonth: function(_y,_m){
|
937
|
+
var nDays = 31;
|
938
|
+
|
939
|
+
switch (_m) {
|
940
|
+
case 2:
|
941
|
+
nDays = ((_y % 400 === 0) || (_y % 4 === 0 && _y % 100 !== 0)) ? 29 : 28;
|
942
|
+
break;
|
943
|
+
|
944
|
+
case 4:
|
945
|
+
case 6:
|
946
|
+
case 9:
|
947
|
+
case 11:
|
948
|
+
nDays = 30;
|
949
|
+
break;
|
950
|
+
}
|
951
|
+
|
952
|
+
return nDays;
|
953
|
+
},
|
954
|
+
|
955
|
+
|
956
|
+
/**
|
957
|
+
* Updates the calendar when a different month is chosen
|
958
|
+
*
|
959
|
+
* @method _updateMonth
|
960
|
+
* @param {Number} incValue - indicates previous or next month
|
961
|
+
* @private
|
962
|
+
*/
|
963
|
+
_updateMonth: function(incValue){
|
964
|
+
if(typeof incValue === 'undefined') {
|
965
|
+
incValue = "0";
|
966
|
+
}
|
967
|
+
|
968
|
+
var mes = this._month + 1;
|
969
|
+
var ano = this._year;
|
970
|
+
switch(incValue){
|
971
|
+
case -1:
|
972
|
+
if (mes===1){
|
973
|
+
if(ano === this._yearMin){ return; }
|
974
|
+
mes=12;
|
975
|
+
ano--;
|
976
|
+
}
|
977
|
+
else {
|
978
|
+
mes--;
|
979
|
+
}
|
980
|
+
this._year = ano;
|
981
|
+
this._month = mes - 1;
|
982
|
+
break;
|
983
|
+
case 1:
|
984
|
+
if(mes === 12){
|
985
|
+
if(ano === this._yearMax){ return; }
|
986
|
+
mes=1;
|
987
|
+
ano++;
|
988
|
+
}
|
989
|
+
else{
|
990
|
+
mes++;
|
991
|
+
}
|
992
|
+
this._year = ano;
|
993
|
+
this._month = mes - 1;
|
994
|
+
break;
|
995
|
+
default:
|
996
|
+
|
997
|
+
}
|
998
|
+
},
|
999
|
+
|
1000
|
+
/**
|
1001
|
+
* Key-value object that (for a given key) points to the correct parsing format for the DatePicker
|
1002
|
+
* @property _dateParsers
|
1003
|
+
* @type {Object}
|
1004
|
+
* @readOnly
|
1005
|
+
*/
|
1006
|
+
_dateParsers: {
|
1007
|
+
'yyyy-mm-dd' : 'Y-m-d' ,
|
1008
|
+
'yyyy/mm/dd' : 'Y/m/d' ,
|
1009
|
+
'yy-mm-dd' : 'y-m-d' ,
|
1010
|
+
'yy/mm/dd' : 'y/m/d' ,
|
1011
|
+
'dd-mm-yyyy' : 'd-m-Y' ,
|
1012
|
+
'dd/mm/yyyy' : 'd/m/Y' ,
|
1013
|
+
'dd-mm-yy' : 'd-m-y' ,
|
1014
|
+
'dd/mm/yy' : 'd/m/y' ,
|
1015
|
+
'mm/dd/yyyy' : 'm/d/Y' ,
|
1016
|
+
'mm-dd-yyyy' : 'm-d-Y'
|
1017
|
+
},
|
1018
|
+
|
1019
|
+
/**
|
1020
|
+
* Renders the current month
|
1021
|
+
*
|
1022
|
+
* @method _showMonth
|
1023
|
+
* @private
|
1024
|
+
*/
|
1025
|
+
_showMonth: function(){
|
1026
|
+
/*jshint maxstatements:100, maxcomplexity:20 */
|
1027
|
+
var i, j;
|
1028
|
+
var mes = this._month + 1;
|
1029
|
+
var ano = this._year;
|
1030
|
+
var maxDay = this._daysInMonth(ano,mes);
|
1031
|
+
|
1032
|
+
var wDayFirst = (new Date( ano , mes - 1 , 1 )).getDay();
|
1033
|
+
|
1034
|
+
var startWeekDay = this._options.startWeekDay || 0;
|
1035
|
+
|
1036
|
+
this._monthPrev.childNodes[0].className = 'change_month_prev';
|
1037
|
+
this._monthNext.childNodes[0].className = 'change_month_next';
|
1038
|
+
|
1039
|
+
if ( ano < this._yearMin || ano === this._yearMin && mes <= this._monthMin ){
|
1040
|
+
this._monthPrev.childNodes[0].className = 'action_inactive';
|
1041
|
+
}
|
1042
|
+
else if( ano > this._yearMax || ano === this._yearMax && mes >= this._monthMax ){
|
1043
|
+
this._monthNext.childNodes[0].className = 'action_inactive';
|
1044
|
+
}
|
1045
|
+
|
1046
|
+
if(startWeekDay && Number(startWeekDay)){
|
1047
|
+
if(startWeekDay > wDayFirst) {
|
1048
|
+
wDayFirst = 7 + startWeekDay - wDayFirst;
|
1049
|
+
} else {
|
1050
|
+
wDayFirst += startWeekDay;
|
1051
|
+
}
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
var html = '';
|
1055
|
+
|
1056
|
+
html += '<ul class="sapo_cal_header">';
|
1057
|
+
|
1058
|
+
for(i=0; i<7; i++){
|
1059
|
+
html+='<li>' + this._options.wDay[i + (((startWeekDay+i)>6) ? startWeekDay-7 : startWeekDay )].substring(0,1) + '</li>';
|
1060
|
+
}
|
1061
|
+
html+='</ul>';
|
1062
|
+
|
1063
|
+
var counter = 0;
|
1064
|
+
html+='<ul>';
|
1065
|
+
if(wDayFirst){
|
1066
|
+
for(j = startWeekDay; j < wDayFirst - startWeekDay; j++) {
|
1067
|
+
if (!counter){
|
1068
|
+
html+='<ul>';
|
1069
|
+
}
|
1070
|
+
html+='<li class="sapo_cal_empty"> </li>';
|
1071
|
+
counter++;
|
1072
|
+
}
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
for (i = 1; i <= maxDay; i++) {
|
1076
|
+
if (counter === 7){
|
1077
|
+
counter=0;
|
1078
|
+
html+='<ul>';
|
1079
|
+
}
|
1080
|
+
var idx = 'sapo_cal_' + ((String(i).length === 2) ? i : "0" + i);
|
1081
|
+
idx += ( ano === this._yearMin && mes === this._monthMin && i < this._dayMin ||
|
1082
|
+
ano === this._yearMax && mes === this._monthMax && i > this._dayMax ||
|
1083
|
+
ano === this._yearMin && mes < this._monthMin ||
|
1084
|
+
ano === this._yearMax && mes > this._monthMax ||
|
1085
|
+
ano < this._yearMin || ano > this._yearMax || ( this._options.validDayFn && !this._options.validDayFn.call( this, new Date( ano , mes - 1 , i) ) ) ) ? " sapo_cal_off" :
|
1086
|
+
(this._data.getFullYear( ) === ano && this._data.getMonth( ) === mes - 1 && i === this._day) ? " sapo_cal_on" : "";
|
1087
|
+
html+='<li><a href="#" class="' + idx + '">' + i + '</a></li>';
|
1088
|
+
|
1089
|
+
counter++;
|
1090
|
+
if(counter === 7){
|
1091
|
+
html+='</ul>';
|
1092
|
+
}
|
1093
|
+
}
|
1094
|
+
if (counter !== 7){
|
1095
|
+
for(i = counter; i < 7; i++){
|
1096
|
+
html+='<li class="sapo_cal_empty"> </li>';
|
1097
|
+
}
|
1098
|
+
html+='</ul>';
|
1099
|
+
}
|
1100
|
+
html+='</ul>';
|
1101
|
+
|
1102
|
+
|
1103
|
+
this._monthContainer.innerHTML = html;
|
1104
|
+
|
1105
|
+
},
|
1106
|
+
|
1107
|
+
/**
|
1108
|
+
* This method sets the active month
|
1109
|
+
*
|
1110
|
+
* @method _setActiveMonth
|
1111
|
+
* @param {DOMElement} parent DOMElement where all the months are.
|
1112
|
+
* @private
|
1113
|
+
*/
|
1114
|
+
_setActiveMonth: function(parent){
|
1115
|
+
if (typeof parent === 'undefined') {
|
1116
|
+
parent = this._monthSelector;
|
1117
|
+
}
|
1118
|
+
|
1119
|
+
var length = parent.childNodes.length;
|
1120
|
+
|
1121
|
+
if (parent.className && parent.className.match(/sapo_calmonth_/)) {
|
1122
|
+
var year = this._year;
|
1123
|
+
var month = parent.className.substr( 14 , 2 );
|
1124
|
+
|
1125
|
+
if ( year === this._data.getFullYear( ) && month === this._data.getMonth( ) + 1 )
|
1126
|
+
{
|
1127
|
+
Css.addClassName( parent , 'sapo_cal_on' );
|
1128
|
+
Css.removeClassName( parent , 'sapo_cal_off' );
|
1129
|
+
}
|
1130
|
+
else
|
1131
|
+
{
|
1132
|
+
Css.removeClassName( parent , 'sapo_cal_on' );
|
1133
|
+
if ( year === this._yearMin && month < this._monthMin ||
|
1134
|
+
year === this._yearMax && month > this._monthMax ||
|
1135
|
+
year < this._yearMin ||
|
1136
|
+
year > this._yearMax )
|
1137
|
+
{
|
1138
|
+
Css.addClassName( parent , 'sapo_cal_off' );
|
1139
|
+
}
|
1140
|
+
else
|
1141
|
+
{
|
1142
|
+
Css.removeClassName( parent , 'sapo_cal_off' );
|
1143
|
+
}
|
1144
|
+
}
|
1145
|
+
}
|
1146
|
+
else if (length !== 0){
|
1147
|
+
for (var i = 0; i < length; i++) {
|
1148
|
+
this._setActiveMonth(parent.childNodes[i]);
|
1149
|
+
}
|
1150
|
+
}
|
1151
|
+
},
|
1152
|
+
|
1153
|
+
/**
|
1154
|
+
* Prototype's method to allow the 'i18n files' to change all objects' language at once.
|
1155
|
+
* @param {Object} options Object with the texts' configuration.
|
1156
|
+
* @param {String} closeText Text of the close anchor
|
1157
|
+
* @param {String} cleanText Text of the clean text anchor
|
1158
|
+
* @param {String} prevLinkText "Previous" link's text
|
1159
|
+
* @param {String} nextLinkText "Next" link's text
|
1160
|
+
* @param {String} ofText The text "of", present in 'May of 2013'
|
1161
|
+
* @param {Object} month An object with keys from 1 to 12 that have the full months' names
|
1162
|
+
* @param {Object} wDay An object with keys from 0 to 6 that have the full weekdays' names
|
1163
|
+
* @public
|
1164
|
+
*/
|
1165
|
+
lang: function( options ){
|
1166
|
+
this._lang = options;
|
1167
|
+
},
|
1168
|
+
|
1169
|
+
/**
|
1170
|
+
* This calls the rendering of the selected month.
|
1171
|
+
*
|
1172
|
+
* @method showMonth
|
1173
|
+
* @public
|
1174
|
+
*/
|
1175
|
+
showMonth: function(){
|
1176
|
+
this._showMonth();
|
1177
|
+
},
|
1178
|
+
|
1179
|
+
/**
|
1180
|
+
* Returns true if the calendar sceen is in 'select day' mode
|
1181
|
+
*
|
1182
|
+
* @return {Boolean} True if the calendar sceen is in 'select day' mode
|
1183
|
+
* @public
|
1184
|
+
*/
|
1185
|
+
isMonthRendered: function(){
|
1186
|
+
var header = Selector.select('.sapo_cal_header',this._containerObject)[0];
|
1187
|
+
|
1188
|
+
return ( (Css.getStyle(header.parentNode,'display') !== 'none') && (Css.getStyle(header.parentNode.parentNode,'display') !== 'none') );
|
1189
|
+
}
|
1190
|
+
};
|
1191
|
+
|
1192
|
+
return DatePicker;
|
1193
|
+
|
1194
|
+
});
|