Skip to content

Commit

Permalink
Move demo code into the repo
Browse files Browse the repository at this point in the history
Easier to maintain the demo code and dependencies.
  • Loading branch information
dubrox committed Jan 14, 2025
1 parent 7badec9 commit b495992
Show file tree
Hide file tree
Showing 15 changed files with 783 additions and 406 deletions.
8 changes: 8 additions & 0 deletions demos/alt-field.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div id="mdp-demo"></div>
<input type="text" id="altField" value="04/19/2017, 04/21/2017" />
<!-- Dates in the 'value' attribute of the altField are automatically added to the calendar -->
<script>
$("#mdp-demo").multiDatesPicker({
altField: "#altField",
});
</script>
7 changes: 7 additions & 0 deletions demos/custom-date-format.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="mdp-demo"></div>
<script>
$("#mdp-demo").multiDatesPicker({
dateFormat: "y-m-d",
defaultDate: "85-2-19",
});
</script>
7 changes: 7 additions & 0 deletions demos/days-range.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="mdp-demo"></div>
<script>
$("#mdp-demo").multiDatesPicker({
mode: "daysRange",
autoselectRange: [0, 5],
});
</script>
12 changes: 12 additions & 0 deletions demos/disable-calendar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="mdp-demo"></div>
<script>
var today = new Date();
var tomorrow = new Date().setDate(today.getDate() + 1);

$("#mdp-demo").multiDatesPicker({
disabled: true,
// today and tomorrow are selected just to show how selected dates look
// in a disabled calendar
addDates: [today, tomorrow],
});
</script>
8 changes: 8 additions & 0 deletions demos/disable-dates.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div id="mdp-demo"></div>
<script>
var date = new Date();
$("#mdp-demo").multiDatesPicker({
// disable the 1st and 3rd of the current month
addDisabledDates: [date.setDate(1), date.setDate(3)],
});
</script>
20 changes: 20 additions & 0 deletions demos/full-year.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<style>
/*
Styles needed just to fit the embedded
version in a smaller space.
*/
body {
font-size: x-small !important;
height: 600px;
}
</style>
<div id="mdp-demo"></div>
<script>
var today = new Date();
var y = today.getFullYear();
$("#mdp-demo").multiDatesPicker({
addDates: ["10/14/" + y, "02/19/" + y, "01/14/" + y, "11/16/" + y],
numberOfMonths: [3, 4],
defaultDate: "1/1/" + y,
});
</script>
64 changes: 64 additions & 0 deletions demos/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!doctype html>
<html>
<head>
<title>MDP demo page</title>
<link
rel="stylesheet"
href="https://code.jquery.com/ui/1.13.2/themes/pepper-grinder/jquery-ui.css"
/>
<link rel="stylesheet" href="../jquery-ui.multidatespicker.css" />
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.14.0/jquery-ui.min.js"></script>
<script src="../jquery-ui.multidatespicker.js"></script>
<style>
body {
font-family: sans-serif;
}
#code {
font-size: x-small;
white-space: pre;
background: black;
color: #eee;
padding: 0.5em;
}
</style>
<script>
const loadDemo = (name) => {
$.get(
`${name}.html`,
function (demoCode) {
$("#code").text(demoCode);
$("#preview").html(demoCode);
},
"html",
);
};

const loadDemoFromQuery = () => {
const defaultDemo = "simple";
const params = new URLSearchParams(window.location.search);
const demoName = params.get("demo") || defaultDemo;
loadDemo(demoName);
};

const toggleCodeVisibility = (e) => {
e.preventDefault();
const codeElement = document.getElementById("code");
const previewElement = document.getElementById("preview");
const wasVisible = codeElement.style.display === "block";
codeElement.style.display = wasVisible ? "none" : "block";
window.scrollTo(0, wasVisible ? 0 : 400);
};

$(function () {
loadDemoFromQuery();
$("#toggle-code-visibility").click(toggleCodeVisibility);
});
</script>
</head>
<body>
<div id="preview"></div>
<a id="toggle-code-visibility" href="#">Code used</a>
<code id="code" style="display: none"></code>
</body>
</html>
4 changes: 4 additions & 0 deletions demos/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<input id="mdp-demo" type="text" />
<script>
$("#mdp-demo").multiDatesPicker();
</script>
4 changes: 4 additions & 0 deletions demos/max-picks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div id="mdp-demo"></div>
<script>
$("#mdp-demo").multiDatesPicker({ maxPicks: 2 });
</script>
7 changes: 7 additions & 0 deletions demos/min-max-date.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="mdp-demo"></div>
<script>
$("#mdp-demo").multiDatesPicker({
minDate: 0, // today
maxDate: 30, // +30 days from today
});
</script>
9 changes: 9 additions & 0 deletions demos/pickable-range.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div id="mdp-demo"></div>
<script>
var date = new Date();
$("#mdp-demo").multiDatesPicker({
pickableRange: 7,
adjustRangeToDisabled: true,
addDisabledDates: [date.setDate(10), date.setDate(15)],
});
</script>
8 changes: 8 additions & 0 deletions demos/preselect-dates.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div id="mdp-demo"></div>
<script>
var date = new Date();
$("#mdp-demo").multiDatesPicker({
// preselect the 14th and 19th of the current month
addDates: [date.setDate(14), date.setDate(19)],
});
</script>
4 changes: 4 additions & 0 deletions demos/simple.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div id="mdp-demo"></div>
<script>
$("#mdp-demo").multiDatesPicker();
</script>
12 changes: 12 additions & 0 deletions demos/ui-calendar-methods.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="mdp-demo"></div>
<script>
$("#mdp-demo").multiDatesPicker({
beforeShowDay: $.datepicker.noWeekends,
});
/*
Note: disabling dates using 'beforeShowDay'
may produce undesired results with MDP functionalities
that involve ranges, because MDP will still consider
those dates as available.
*/
</script>
Loading

0 comments on commit b495992

Please sign in to comment.