Skip to content

Commit cad5cd8

Browse files
committed
Formatting and cleanup
1 parent 8692f30 commit cad5cd8

File tree

2 files changed

+31
-49
lines changed

2 files changed

+31
-49
lines changed

datepicker-rewrite/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
<input id="datepicker" type="text" />
3030
<input id="datepicker2" type="text" />
3131
<script>
32-
jQuery(function($) {
33-
$("#culture").change( function() {
32+
$( function() {
33+
$( "#culture" ).change( function() {
3434
$.global.preferCulture( $( this ).val() );
3535
$( ":ui-datepicker" ).datepicker( "refresh" );
3636
})
37-
$("#datepicker-inline").datepicker({
37+
$( "#datepicker-inline" ).datepicker( {
3838
select: function( event, ui ) {
39-
$("#inline-output").val( ui.date );
39+
$( "#inline-output" ).val( ui.date );
4040
}
4141
});
42-
$("#datepicker, #datepicker2").datepicker();
42+
$( "#datepicker, #datepicker2" ).datepicker();
4343
});
4444
</script>
4545

datepicker-rewrite/picker.js

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
/*
2-
* jQuery UI Datepicker Lite
3-
*
4-
* Copyright 2010 Marc Grabanski
5-
* Licensed under the MIT license
6-
*
7-
*
8-
* Depends:
9-
* jquery.ui.core.js
10-
* jquery.ui.widget.js
11-
* jquery.ui.position.js
12-
* jquery.ui.button.js
13-
* jquery.date.js
14-
* jquery.tmpl.js
15-
* jquery.ui.datepicker.html
2+
* Experimental datepicker rewrite to evaluate jquery-tmpl.
3+
*
4+
* Based on Marc Grabanski's https://github.com/1Marc/jquery-ui-datepicker-lite
165
*/
176
(function( $, undefined ) {
187

@@ -22,35 +11,36 @@ $.widget( "ui.datepicker", {
2211
_create: function() {
2312
var self = this;
2413
this.date = $.date();
25-
if (this.element.is("input")) {
14+
if ( this.element.is( "input" ) ) {
2615
self._bind( {
2716
click: "open",
2817
// TODO click on picker should not close
2918
blur: "close"
3019
});
31-
this.picker = $("<div/>").insertAfter(this.element).hide();
32-
this.picker.css({
20+
this.picker = $( "<div/>" ).insertAfter( this.element ).hide();
21+
this.picker.css( {
3322
position: "absolute"
3423
});
3524
} else {
3625
this.inline = true;
3726
this.picker = this.element;
3827
}
39-
this.picker.delegate(".ui-datepicker-prev", "click", function() {
40-
self.date.adjust("M", -1);
28+
this.picker.delegate( ".ui-datepicker-prev", "click", function() {
29+
self.date.adjust( "M", -1 );
4130
self.refresh();
4231
});
43-
this.picker.delegate(".ui-datepicker-next", "click", function() {
44-
self.date.adjust("M", +1)
32+
this.picker.delegate( ".ui-datepicker-next", "click", function() {
33+
self.date.adjust( "M", +1 )
4534
self.refresh();
4635
});
47-
this.picker.delegate(".ui-datepicker-calendar a", "click", function( event ) {
48-
self.date.setDay( +$(this).text() );
49-
if (!self.inline) {
36+
this.picker.delegate( ".ui-datepicker-calendar a", "click", function( event ) {
37+
// TODO exclude clicks on lead days or handle them correctly
38+
self.date.setDay( +$( this ).text() );
39+
if ( !self.inline ) {
5040
self.element.val( self.date.format() );
5141
self.close();
5242
}
53-
self._trigger("select", event, {
43+
self._trigger( "select", event, {
5444
date: self.date.format(),
5545
});
5646
});
@@ -61,37 +51,29 @@ $.widget( "ui.datepicker", {
6151
this.date.refresh();
6252
this.picker.empty();
6353

64-
$("#ui-datepicker-tmpl").tmpl({
54+
$( "#ui-datepicker-tmpl" ).tmpl({
6555
date: this.date
66-
}).appendTo(this.picker)
67-
.find("button").button().end()
56+
}).appendTo( this.picker )
57+
.find( "button" ).button().end()
6858

6959
// against display:none in datepicker.css
70-
this.picker.find(".ui-datepicker").css("display", "block");
60+
this.picker.find( ".ui-datepicker" ).css( "display", "block" );
7161
this._hoverable( this.picker.find( ".ui-datepicker-header a" ) );
7262
this._hoverable( this.picker.find( ".ui-datepicker-header a, .ui-datepicker-calendar a" ) );
7363
},
74-
_setOption: function( key, value ) {
75-
$.Widget.prototype._setOption.apply( this, arguments );
76-
if ( key === "" ) {
77-
}
78-
},
7964
open: function( event ) {
8065
this.picker.fadeIn( "fast" );
81-
// would open ever get called for non-inline datepickers?
82-
if (!this.inline) {
83-
this.picker.position({
84-
my: "left top",
85-
at: "left bottom",
86-
of: this.element
87-
});
88-
}
66+
this.picker.position({
67+
my: "left top",
68+
at: "left bottom",
69+
of: this.element
70+
});
8971
},
9072
close: function( event ) {
9173
this.picker.fadeOut();
9274
},
93-
destroy: function() {
94-
if (!this.inline) {
75+
_destroy: function() {
76+
if ( !this.inline ) {
9577
this.picker.remove();
9678
}
9779
},

0 commit comments

Comments
 (0)