Skip to content

Commit 70c2236

Browse files
author
bradrobertson
committed
Merge branch 'dev' of github.com:jquerytools/jquerytools into dev
2 parents 2528b83 + 1359517 commit 70c2236

File tree

7 files changed

+108
-28
lines changed

7 files changed

+108
-28
lines changed

src/dateinput/dateinput.js

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Since: Mar 2010
1010
* Date: @DATE
1111
*/
12-
(function($) {
12+
(function($, undefined) {
1313

1414
/* TODO:
1515
preserve today highlighted
@@ -91,7 +91,7 @@
9191

9292
// @return amount of days in certain month
9393
function dayAm(year, month) {
94-
return 32 - new Date(year, month, 32).getDate();
94+
return new Date(year, month + 1, 0).getDate();
9595
}
9696

9797
function zeropad(val, len) {
@@ -339,10 +339,10 @@
339339

340340

341341
if (index > 41) {
342-
self.addMonth();
342+
showNextMonth();
343343
el = $("#" + css.weeks + " a:eq(" + (index-42) + ")");
344344
} else if (index < 0) {
345-
self.addMonth(-1);
345+
showPreviousMonth();
346346
el = $("#" + css.weeks + " a:eq(" + (index+42) + ")");
347347
} else {
348348
el = days.eq(index);
@@ -354,17 +354,17 @@
354354
}
355355

356356
// pageUp / pageDown
357-
if (key == 34) { return self.addMonth(); }
358-
if (key == 33) { return self.addMonth(-1); }
357+
if (key == 34) { return showNextMonth(); }
358+
if (key == 33) { return showPreviousMonth(); }
359359

360360
// home
361-
if (key == 36) { return self.today(); }
361+
if (key == 36) { return self.today(); }
362362

363363
// enter
364364
if (key == 13) {
365365
if (!$(e.target).is("select")) {
366-
$("." + css.focus).click();
367-
}
366+
$("." + css.focus).click();
367+
}
368368
}
369369

370370
return $([16, 17, 18, 9]).index(key) >= 0;
@@ -382,12 +382,42 @@
382382
});
383383
}
384384
//}}}
385-
385+
386+
387+
/**
388+
* @private
389+
*
390+
* Calculates the days in the next month to properly switch months
391+
*
392+
*/
393+
function showNextMonth() {
394+
395+
var daysNextMonth = dayAm(currYear, currMonth + 1);
396+
397+
/*
398+
* If next month has less days than the current date
399+
* add number of days in the next month, otherwise add
400+
* number of days in the current month
401+
*/
402+
return self.addDay(currDay > daysNextMonth ? daysNextMonth : dayAm(currYear, currMonth));
403+
}
404+
405+
/**
406+
* @private
407+
*
408+
* Return to previous month
409+
*/
410+
function showPreviousMonth() {
411+
return self.addDay(-dayAm(currYear, currMonth));
412+
}
386413

387414
$.extend(self, {
388415

389-
//{{{ show
390-
416+
417+
/**
418+
* @public
419+
* Show the calendar
420+
*/
391421
show: function(e) {
392422

393423
if (input.attr("readonly") || input.attr("disabled") || opened) { return; }
@@ -417,14 +447,14 @@
417447
// prev / next month
418448
pm = root.find("#" + css.prev).unbind("click").click(function(e) {
419449
if (!pm.hasClass(css.disabled)) {
420-
self.addMonth(-1);
450+
showPreviousMonth();
421451
}
422452
return false;
423453
});
424454

425455
nm = root.find("#" + css.next).unbind("click").click(function(e) {
426456
if (!nm.hasClass(css.disabled)) {
427-
self.addMonth();
457+
showNextMonth();
428458
}
429459
return false;
430460
});
@@ -456,16 +486,15 @@
456486

457487
return self;
458488
},
459-
//}}}
460-
461-
462-
//{{{ setValue
463489

490+
/**
491+
* @public
492+
*
493+
* Set the value of the dateinput
494+
*/
464495
setValue: function(year, month, day) {
465496

466-
467-
468-
var date = integer(month) >= -1 ? new Date(integer(year), integer(month), integer(day || 1)) :
497+
var date = integer(month) >= -1 ? new Date(integer(year), integer(month), integer(day == undefined || isNaN(day) ? 1 : day)) :
469498
year || value;
470499

471500
if (date < min) { date = min; }
@@ -495,6 +524,7 @@
495524

496525
currMonth = month;
497526
currYear = year;
527+
currDay = day;
498528

499529
// variables
500530
var tmp = new Date(year, month, 1 - conf.firstDay), begin = tmp.getDay(),
@@ -508,7 +538,7 @@
508538
// month selector
509539
monthSelector.empty();
510540
$.each(labels.months, function(i, m) {
511-
if (min < new Date(year, i + 1, -1) && max > new Date(year, i, 0)) {
541+
if (min < new Date(year, i + 1, 1) && max > new Date(year, i, 0)) {
512542
monthSelector.append($("<option/>").html(m).attr("value", i));
513543
}
514544
});
@@ -518,7 +548,7 @@
518548
var yearNow = now.getFullYear();
519549

520550
for (var i = yearNow + conf.yearRange[0]; i < yearNow + conf.yearRange[1]; i++) {
521-
if (min <= new Date(i + 1, -1, 1) && max > new Date(i, 0, 0)) {
551+
if (min < new Date(i + 1, 0, 1) && max > new Date(i, 0, 0)) {
522552
yearSelector.append($("<option/>").text(i));
523553
}
524554
}

test/dateinput/setmin.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- HTML5 date input -->
88
<input type="date" name="mydate" data-value="2010-12-01" min="2010-12-01" max="2011-12-02" />
99

10-
<input type="date" name="mydate" data-value="2010-12-01" min="2010-12-01" max="2012-07-01" />
10+
<input type="date" name="mydate" data-value="2010-12-30" min="2010-12-30" max="2012-07-01" />
1111

1212
<!-- make it happen -->
1313
<script>

test/tooltip/click.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
<script src="../../../jquery-1.3.2.js"></script>
2+
<script src="../../../jquery-1.6.2.js"></script>
33
<script src="../tools.tooltip.js"></script>
44
<link rel="stylesheet" type="text/css" href="style.css"/>
55

test/tooltip/dynamic.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
<script src="../../../jquery-1.3.2.js"></script>
2+
<script src="../../../jquery-1.6.2.js"></script>
33
<script src="../tools.tooltip.js"></script>
44
<script src="../tools.tooltip.dynamic.js"></script>
55

test/tooltip/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
<script src="../js/jquery-1.4.1.js"></script>
2+
<script src="../js/jquery-1.6.2.js"></script>
33
<script src="../../src/tooltip/tooltip.js"></script>
44
<script src="../../src/tooltip/tooltip.slide.js"></script>
55

test/tooltip/many.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
<script src="../js/jquery-1.4.1.js"></script>
2+
<script src="../js/jquery-1.6.2.js"></script>
33
<script src="../../src/tooltip/tooltip.js"></script>
44

55
<style>

test/tooltip/vertical_form.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
<script src="../js/jquery-1.6.2.js"></script>
3+
<script src="../../src/tooltip/tooltip.js"></script>
4+
5+
<style type="text/css">
6+
body{
7+
padding:50px;
8+
}
9+
10+
input {
11+
display:block;
12+
margin:10px;
13+
}
14+
15+
/* tooltip styling. by default the element to be styled is .tooltip */
16+
.tooltip {
17+
display:none;
18+
background:transparent url('http://flowplayer.org/tools/img/tooltip/black_arrow.png');
19+
font-size:12px;
20+
height:70px;
21+
width:160px;
22+
padding:25px;
23+
color:#fff;
24+
}
25+
</style>
26+
27+
<input type="text" title="The tooltip text #1" />
28+
<input type="text" title="The tooltip text #2" />
29+
<input type="text" title="The tooltip text #3" />
30+
<input type="text" title="The tooltip text #4" />
31+
<input type="text" title="The tooltip text #5" />
32+
<input type="text" title="The tooltip text #6" />
33+
<input type="text" title="The tooltip text #7" />
34+
<input type="text" title="The tooltip text #8" />
35+
36+
<script type="text/javascript">
37+
$(function(){
38+
$("input").tooltip({
39+
events: {
40+
input: "focus mouseenter,blur mouseleave"
41+
}
42+
}).mouseleave(function(){
43+
console.log("input mouseleave");
44+
});
45+
46+
$(".tooltip").live('mouseleave', function(){
47+
console.log("tooltip mouseleave");
48+
});
49+
});
50+
</script>

0 commit comments

Comments
 (0)