Changeset 2566:9bf417837888 for admin/js/date-picker.js
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/js/date-picker.js
r0 r2566 2 2 { 3 3 if (!document.getElementById) { return; } 4 4 5 5 if (!target || target.nodeName.toLowerCase() != 'input') { 6 6 return; 7 7 } 8 8 9 9 this.target = target; 10 10 this.oTable = document.createElement('table'); … … 17 17 this.oTable.id = 'dc_datepicker_'+target.id; 18 18 this.oTable.className = 'date-picker'; 19 19 20 20 var cur = 1; 21 21 var oRow, oHeading, oSpan; 22 22 23 23 // Set title 24 24 oRow = document.createElement('tr'); 25 25 26 26 // Month block 27 27 oHeading = document.createElement('th'); 28 28 oHeading.colSpan = 4; 29 29 oHeading.className = 'date-picker-month'; 30 30 31 31 var nav = document.createElement('span'); 32 32 nav.appendChild(document.createTextNode(String.fromCharCode(171))); … … 36 36 nav.className = 'date-picker-control'; 37 37 oHeading.appendChild(nav); 38 39 oHeading.appendChild(document.createTextNode(String.fromCharCode(160))); 40 38 39 oHeading.appendChild(document.createTextNode(String.fromCharCode(160))); 40 41 41 nav = document.createElement('span'); 42 42 nav.appendChild(document.createTextNode(String.fromCharCode(187))); … … 46 46 nav.className = 'date-picker-control'; 47 47 oHeading.appendChild(nav); 48 49 oHeading.appendChild(document.createTextNode(String.fromCharCode(160))); 50 48 49 oHeading.appendChild(document.createTextNode(String.fromCharCode(160))); 50 51 51 oHeading.appendChild(this.oMonth); 52 52 53 53 oRow.appendChild(oHeading); 54 54 55 55 // Year block 56 56 oHeading = document.createElement('th'); 57 57 oHeading.colSpan = 3; 58 58 oHeading.className = 'date-picker-year'; 59 59 60 60 oHeading.appendChild(this.oYear); 61 62 oHeading.appendChild(document.createTextNode(String.fromCharCode(160))); 63 61 62 oHeading.appendChild(document.createTextNode(String.fromCharCode(160))); 63 64 64 nav = document.createElement('span'); 65 65 nav.appendChild(document.createTextNode(String.fromCharCode(171))); … … 69 69 nav.className = 'date-picker-control'; 70 70 oHeading.appendChild(nav); 71 72 oHeading.appendChild(document.createTextNode(String.fromCharCode(160))); 73 71 72 oHeading.appendChild(document.createTextNode(String.fromCharCode(160))); 73 74 74 nav = document.createElement('span'); 75 75 nav.appendChild(document.createTextNode(String.fromCharCode(187))); … … 79 79 nav.className = 'date-picker-control'; 80 80 oHeading.appendChild(nav); 81 81 82 82 oRow.appendChild(oHeading); 83 83 84 84 this.oBody.appendChild(oRow); 85 85 86 86 // Create legend 87 87 oRow = document.createElement('tr'); … … 95 95 } 96 96 this.oBody.appendChild(oRow); 97 97 98 98 // Create 6 rows of 7 cols for days 99 99 for (var i=0; i<6; i++) { 100 100 oRow = document.createElement('tr'); 101 101 102 102 for (var j=0; j<7; j++) { 103 103 this.oDates[cur] = document.createElement('td'); … … 107 107 cur++; 108 108 } 109 109 110 110 this.oBody.appendChild(oRow); 111 111 } 112 112 113 113 // Time controls 114 114 oRow = document.createElement('tr'); 115 115 116 116 oHeading = document.createElement('th'); 117 117 oHeading.className = 'date-picker-control'; … … 121 121 oHeading.obj = this; 122 122 oHeading.onclick = function() { this.fn.call(this.obj); }; 123 123 124 124 oRow.appendChild(oHeading); 125 125 126 126 oHeading = document.createElement('th'); 127 127 oHeading.colSpan = 5; 128 128 129 129 oSpan = document.createElement('span'); 130 130 oSpan.className = 'date-picker-control'; … … 143 143 oHeading.appendChild(oSpan); 144 144 oHeading.appendChild(document.createTextNode(String.fromCharCode(160))); 145 145 146 146 this.oHour.size = 3; 147 147 oHeading.appendChild(this.oHour); 148 148 149 149 oHeading.appendChild(document.createTextNode(' : ')); 150 150 151 151 this.oMinute.size = 3; 152 152 oHeading.appendChild(this.oMinute); 153 153 154 154 oHeading.appendChild(document.createTextNode(String.fromCharCode(160))); 155 155 oSpan = document.createElement('span'); … … 167 167 oSpan.obj = this; 168 168 oSpan.onclick = function() { this.fn.call(this.obj,+1); }; 169 169 170 170 oHeading.appendChild(oSpan); 171 171 172 172 oRow.appendChild(oHeading); 173 173 174 174 // Close control 175 175 oHeading = document.createElement('th'); … … 180 180 oHeading.obj = this; 181 181 oHeading.onclick = function() { this.fn.call(this.obj); }; 182 182 183 183 oRow.appendChild(oHeading); 184 184 185 185 this.oBody.appendChild(oRow); 186 186 }; … … 192 192 hour: 0, 193 193 minute: 0, 194 194 195 195 img_src: '', 196 196 img_top: '0.2em', 197 197 now_msg: 'now', 198 198 close_msg: 'close', 199 199 200 200 days: new Array('Monday','Tuesday','Wednesday','Thursday','Friday', 201 201 'Saturday','Sunday'), 202 202 203 203 months: new Array('January','February','March','April','May','June', 204 204 'July','August','September','October','November','December'), 205 206 205 206 207 207 setDate: function() { 208 208 if (this.numberOfDays() < this.day) { 209 209 this.day = this.numberOfDays(); 210 210 } 211 211 212 212 while (this.oYear.hasChildNodes()) { 213 213 this.oYear.removeChild(this.oYear.firstChild) 214 214 } 215 215 this.oYear.appendChild(document.createTextNode(this.year)); 216 216 217 217 while (this.oMonth.hasChildNodes()) { 218 218 this.oMonth.removeChild(this.oMonth.firstChild) … … 220 220 this.oMonth.appendChild(document.createTextNode( 221 221 this.months[this.month-1])); 222 222 223 223 var firstDay = this.firstDay(); 224 224 var nbDays = this.numberOfDays(); 225 225 226 226 // Empty days 227 227 for (var i=1; i<=42; i++) { … … 233 233 this.oDates[i].onclick = function() { return; }; 234 234 } 235 235 236 236 // Insert days from the first day to the last 237 237 for (i=1; i<=nbDays; i++) { 238 238 var j=firstDay+i-1; 239 239 240 240 while (this.oDates[j].hasChildNodes()) { 241 241 this.oDates[j].removeChild(this.oDates[j].firstChild) 242 242 } 243 243 244 244 this.oDates[j].appendChild(document.createTextNode(i)); 245 245 this.oDates[j].index = i; … … 253 253 } 254 254 } 255 255 256 256 // Set time 257 257 this.setHour(this.hour); 258 258 this.setMinute(this.minute); 259 259 }, 260 260 261 261 setHour: function(h) { 262 262 if (h < 0) { h = 23; } 263 263 if (h > 23) { h = 0; } 264 264 if (h < 10) { h = '0'+h; } 265 265 266 266 this.hour = h*1; 267 267 this.oHour.value = h; 268 268 }, 269 269 270 270 setMinute: function(m) { 271 271 if (m < 0) { m = 59; } 272 272 if (m > 59) { m = 0; } 273 273 if (m < 10) { m = '0'+m; } 274 274 275 275 this.minute = m*1; 276 276 this.oMinute.value = m; 277 277 }, 278 278 279 279 changeMonth: function(dir) { 280 280 var y = this.year; 281 281 var m = this.month; 282 282 m = m+dir; 283 283 284 284 if (m > 12) { this.month = 1; this.year++; } 285 285 else if ( m < 1) { this.month = 12; this.year--; } 286 286 else { this.month = m; } 287 287 288 288 this.setDate(); 289 289 }, 290 290 291 291 changeYear: function(dir) { 292 292 this.year = this.year + dir; 293 293 this.setDate(); 294 294 }, 295 295 296 296 changeHour: function(dir) { 297 297 this.setHour(this.hour*1+dir); 298 298 }, 299 299 300 300 changeMinute: function(dir) { 301 301 this.setMinute(this.minute*1+dir); 302 302 }, 303 303 304 304 sendDate: function(d) { 305 305 var m = this.month; 306 306 var hour = this.oHour.value*1; 307 307 var minute = this.oMinute.value*1; 308 308 309 309 if (hour < 0 || hour > 23 || isNaN(hour)) { hour = 0; } 310 310 if (minute < 0 || minute > 59 || isNaN(minute)) { minute = 0; } 311 311 312 312 if (m < 10) { m = '0'+m; } 313 313 if (d < 10) { d = '0'+d; } 314 314 if (hour < 10) { hour = '0'+hour; } 315 315 if (minute < 10) { minute = '0'+minute; } 316 316 317 317 this.target.value = this.year+'-'+m+'-'+d+' '+hour+':'+minute; 318 318 this.close(); 319 319 }, 320 320 321 321 sendNow: function() { 322 322 var dt = new Date(); … … 326 326 var h = dt.getHours(); 327 327 var i = dt.getMinutes(); 328 328 329 329 if (m < 10) { m = '0'+m; } 330 330 if (d < 10) { d = '0'+d; } 331 331 if (h < 10) { h = '0'+h; } 332 332 if (i < 10) { i = '0'+i; } 333 333 334 334 this.target.value = y+'-'+m+'-'+d+' '+h+':'+i; 335 335 this.close(); 336 336 }, 337 337 338 338 close: function() { 339 339 document.body.removeChild(this.oTable); 340 340 }, 341 341 342 342 numberOfDays: function() { 343 343 var res = 31; … … 352 352 } 353 353 } 354 354 355 355 return res; 356 356 }, 357 357 358 358 firstDay: function() { 359 359 var dt = new Date(this.year,this.month-1,1); 360 360 var res = dt.getDay(); 361 361 362 362 if (res == 0) { 363 363 res = 7; 364 364 } 365 365 366 366 return res; 367 367 }, 368 368 369 369 show: function() { 370 370 // Parsing target value … … 385 385 this.minute = dt.getMinutes(); 386 386 } 387 387 388 388 this.oTable.appendChild(this.oBody); 389 389 this.setDate(); … … 392 392 this.oHour.focus(); 393 393 }, 394 394 395 395 setPosition: function() { 396 396 var t_x = this.findPosX(this.target); … … 398 398 var o_h = this.oTable.offsetHeight; 399 399 var o_w = this.oTable.offsetWidth; 400 400 401 401 this.oTable.style.position = 'absolute'; 402 402 this.oTable.style.zIndex = '100'; … … 404 404 this.oTable.style.left = t_x+'px'; 405 405 }, 406 406 407 407 findPosX: function(obj) { 408 408 var curleft = 0; … … 420 420 return curleft; 421 421 }, 422 422 423 423 findPosY: function(obj) { 424 424 var curtop = 0; … … 436 436 return curtop; 437 437 }, 438 438 439 439 draw: function() { 440 440 var imgE = document.createElement('img'); … … 446 446 imgE.fn = this.show; 447 447 imgE.onclick = function() { this.fn.apply(this.obj); }; 448 448 449 449 this.target.parentNode.style.position = 'relative'; 450 450 this.target.parentNode.insertBefore(imgE,this.target.nextSibling);
Note: See TracChangeset
for help on using the changeset viewer.