Index: branches/liquidthreads/skins/common/lqt.js |
— | — | @@ -11,7 +11,38 @@ |
12 | 12 | } |
13 | 13 | } |
14 | 14 | |
| 15 | +var LqtDateRangeRectifier = function( startsel, endsel ) { |
| 16 | + this.startsel = startsel; |
| 17 | + this.endsel = endsel; |
| 18 | + |
| 19 | + this.oldstart = this.startsel.selectedIndex; |
| 20 | + this.oldend = this.endsel.selectedIndex; |
15 | 21 | |
| 22 | + this.handle_start_changed = function(e) { |
| 23 | + newi = this.startsel.selectedIndex; |
| 24 | + oldi = this.oldstart; |
| 25 | + endi = this.endsel.selectedIndex; |
| 26 | + goal = newi - (oldi - endi); // seem backwards? it's because |
| 27 | + this.endsel.selectedIndex = Math.max(goal, 0); |
| 28 | + this.oldend = endi; // later months have smaller |
| 29 | + this.oldstart = newi; // indexes. |
| 30 | + } |
| 31 | + |
| 32 | + this.handle_end_changed = function(e){ |
| 33 | + this.startsel.selectedIndex = Math.max(this.endsel.selectedIndex, |
| 34 | + this.startsel.selectedIndex) |
| 35 | + this.oldend = this.endsel.selectedIndex; |
| 36 | + this.oldstart = this.startsel.selectedIndex; |
| 37 | + } |
| 38 | + |
| 39 | + // In order for this instance to recieve the events, we need to capture the |
| 40 | + // current value of 'this' with a closure, because this = the target object |
| 41 | + // in event handlers. |
| 42 | + me = this; |
| 43 | + lqt_add_event( this.startsel, 'change', function(e) { me.handle_start_changed(e) }); |
| 44 | + lqt_add_event( this.endsel, 'change', function(e) { me.handle_end_changed(e) }); |
| 45 | +} |
| 46 | + |
16 | 47 | function lqt_on_load() { |
17 | 48 | if(!document.getElementById) return; |
18 | 49 | |
— | — | @@ -28,9 +59,8 @@ |
29 | 60 | |
30 | 61 | var searchform = document.getElementById("lqt_archive_search_form"); |
31 | 62 | if ( searchform ) { |
32 | | - lqt_add_event( document.getElementById("lqt_archive_start"), 'change', function(e) { |
33 | | - alert(e.target); |
34 | | - } ); |
| 63 | + new LqtDateRangeRectifier( document.getElementById("lqt_archive_start"), |
| 64 | + document.getElementById("lqt_archive_end")); |
35 | 65 | } |
36 | 66 | } |
37 | 67 | |