Skip to content

Commit

Permalink
Add "dateVisible" function and calFormatter argument. Fire "displayCh…
Browse files Browse the repository at this point in the history
…ange" on picker controls. Re: #356
  • Loading branch information
jtsage committed Dec 3, 2014
1 parent 4114d6e commit c8fdbfe
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/api/calFormatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The function must accept a single argument, which is an object of the Date:
"Date" : 1-31, // Integer
"ISO" : YYYY-MM-DD, // ISO Date Representation
"Comp" : YYYYMMDD, // Little endian date compare representation
"dateVisible" : bool // Selected date is on the screen
}

{% endhighlight %}
Expand Down
17 changes: 17 additions & 0 deletions docs/api/dateVisible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: dateVisible
short: Return if selected calendar date is visible
modes: [
]
cats: [ 'public' ]
relat: "public"
layout: func
rettype: "JavaScript Date() Object"
---

Return if the selected calendar date is visible. Only valid for calbox, otherwise it will
always return true.

{% highlight js %}
$(input).datebox('dateVisible');
{% endhighlight %}
7 changes: 6 additions & 1 deletion js/jqm-datebox.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// 3-jQueryMobileVersion
// Check Header for Build Date.
version: "3-1.4.5-03",
version: "3-1.4.5-04",

theme: false,
themeDefault: "a",
Expand Down Expand Up @@ -986,6 +986,7 @@
o.theme = thisTheme;

w.calBackDate = false;
w.calDateVisible = true;
w.disabled = false;
w.runButton = false;
w._date = window.Date;
Expand Down Expand Up @@ -1578,6 +1579,10 @@
// Provide a PUBLIC function to get the last entered duration
return this.lastDuration;
},
dateVisible: function() {
// Provide a PUBLIC function to see if selected calendar date is visible
return this.calDateVisible;
},
setTheDate: function( newDate ) {
// Provide a PUBLIC function to set the date
// ACCEPTS: Date Object or String in proper output format
Expand Down
50 changes: 48 additions & 2 deletions js/jqm-datebox.mode.calbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"calbox": function () {
var tempVal, pickerControl, calContent, genny, weekdayControl, listControl,
row, col, rows, cols, htmlRow, i, prangeS, prangeL, fmtRet, fmtObj,
absStartDO, absEndDO,
w = this,
o = this.options,
dList = o.calDateList,
Expand Down Expand Up @@ -356,7 +357,7 @@
)
);
}

pickerControl.a.on( "change", function () {
if ( w.calBackDate === false ) {
w.calBackDate = new Date(w.theDate.getTime());
Expand All @@ -365,6 +366,15 @@
if ( w.theDate.get(1) !== parseInt( $( this ).val(), 10 ) ) {
w.theDate.setD( 2, 0 );
}
if ( w.calBackDate !== false ) {
w._t( {
method: "displayChange",
selectedDate: w.calBackDate,
shownDate: w.theDate,
thisChange: "p",
thisChangeAmount: null
});
}
w.refresh();
});
pickerControl.b.on( "change", function () {
Expand All @@ -375,6 +385,15 @@
if (w.theDate.get(1) !== parseInt( pickerControl.a.val(), 10)) {
w.theDate.setD( 2, 0 );
}
if ( w.calBackDate !== false ) {
w._t( {
method: "displayChange",
selectedDate: w.calBackDate,
shownDate: w.theDate,
thisChange: "p",
thisChangeAmount: null
});
}
w.refresh();
});

Expand Down Expand Up @@ -436,7 +455,33 @@
$.isFunction( window[ o.calFormatter ] ) ) {
o.calFormatter = window[ o.calFormatter ];
}


absStartDO = new Date(
w.theDate.get(0),
genny[0][0][1],
genny[0][0][0],
0, 0, 0, 0 );
absEndDO = new Date(
w.theDate.get(0),
genny[genny.length-1][6][1],
genny[genny.length-1][6][0],
0, 0, 0, 0 );

if ( w.calBackDate === false ) {
w.calDateVisible = true;
} else {
if ( o.calOnlyMonth ) {
w.calDateVisible = false;
} else {
if ( w.calBackDate.comp() < absStartDO.comp() ||
w.calBackDate.comp() > absEndDO.comp() ) {
w.calDateVisible = false;
} else {
w.calDateVisible = true;
}
}
}

for ( row = 0, rows = genny.length; row < rows; row++ ) {
htmlRow = $("<div>", { "class": uid + "gridrow" } );
if ( w.__( "isRTL" ) ) { htmlRow.css( "direction", "rtl" ); }
Expand Down Expand Up @@ -487,6 +532,7 @@
w._zPad(fmtObj.Month + 1) + "-" +
w._zPad(fmtObj.Date);
fmtObj.Comp = parseInt( fmtObj.ISO.replace( /-/g, "" ), 10 );
fmtObj.dateVisible = w.calDateVisible;
tempVal = o.calFormatter(fmtObj);
if ( typeof tempVal !== "object" ) {
fmtRet = { text: tempVal, "class": "" };
Expand Down

0 comments on commit c8fdbfe

Please sign in to comment.