HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<a style="position: absolute; top: 0; right: 0;" class="gh-fork" href="https://github.com/anasnakawa/kalendae-skins">
<img src="https://raw.github.com/anasnakawa/kalendae-skins/gh-pages/images/forkme-red.png" alt="Fork me on GitHub">
</a>
<div id="wrap">
<div class="auto-kal"></div>
</div>
/** Base container **/
.kalendae {
display: inline-block;zoom:1;*display:inline;
background:#eee;
padding:10px;
margin:5px;
border-radius:5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
font-size:11px;
font-family:'Helvetica Neue', 'Helvetica';
cursor:default;
position:relative;
}
/** Popup Container for Kalendae.Input **/
.kalendae.k-floating {
position:absolute;
top:0;
left:0;
z-index:100000;
margin:0;
box-shadow:0 1px 3px rgba(0,0,0,0.75);
-moz-box-shadow:0 1px 3px rgba(0,0,0,0.75);
-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.75);
}
/** Kalendae.Input's popup close button **/
.kalendae .k-btn-close {
position:absolute;
top:-8px;
right:-8px;
width:16px;
height:16px;
background:white;
border:2px solid #ccc;
color:#999;
line-height:17px;
text-align:center;
font-size:13px;
border-radius:10px;
box-shadow:0 1px 3px rgba(0,0,0,0.75);
cursor:pointer;
}
.kalendae .k-btn-close:after {content:"\2716";}
.kalendae .k-btn-close:hover {
color:#7EA0E2;
background:white;
border-color:#7EA0E2;
}
/** Month Container **/
.kalendae .k-calendar {display: inline-block;zoom:1;*display:inline;width:155px;vertical-align:top;}
/** Month Separator **/
.kalendae .k-separator {display: inline-block;zoom:1;*display:inline;width:2px;vertical-align:top;background:#ddd;height:155px;margin:0px 10px;}
/** Month Title Row **/
.kalendae .k-title {text-align:center;white-space:nowrap;position:relative;height:18px;}
.kalendae .k-caption {font-size:12px;line-height:18px;}
/** Month and Year Buttons **/
.kalendae .k-btn-previous-month,
.kalendae .k-btn-next-month,
.kalendae .k-btn-previous-year,
.kalendae .k-btn-next-year {width:16px;height:16px;cursor:pointer;position:absolute;top:0;color:#777;font-size:20px;line-height:14px;}
.kalendae .k-btn-previous-year {left:0;}
.kalendae .k-btn-previous-month {left:16px;}
.kalendae .k-btn-next-month {right:16px;}
.kalendae .k-btn-next-year {right:0;}
.kalendae .k-btn-previous-month:after {content:"\276E";}
.kalendae .k-btn-next-month:after {content:"\276F";}
.kalendae .k-btn-previous-year:after {content:"\276E\276E";}
.kalendae .k-btn-next-year:after {content:"\276F\276F";}
.kalendae .k-btn-previous-year,
.kalendae .k-btn-next-year {letter-spacing:-4px;text-align:left;}
.kalendae .k-btn-previous-month:hover,
.kalendae .k-btn-next-month:hover {color:#7EA0E2;}
.kalendae .k-btn-previous-year:hover,
.kalendae .k-btn-next-year:hover {color:#6FDF81;}
/** Remove extra buttons when calendar shows multiple months **/
.kalendae .k-first-month .k-btn-next-month,
.kalendae .k-middle-month .k-btn-next-month,
.kalendae .k-middle-month .k-btn-previous-month,
.kalendae .k-last-month .k-btn-previous-month,
.kalendae .k-first-month .k-btn-next-year,
.kalendae .k-middle-month .k-btn-next-year,
.kalendae .k-middle-month .k-btn-previous-year,
.kalendae .k-last-month .k-btn-previous-year {display:none;}
/** Force specific width for month container contents **/
.kalendae .k-title,
.kalendae .k-header,
.kalendae .k-days {
width:154px;
display:block;
overflow:hidden;
}
/** Hide unusable buttons **/
.kalendae.k-disable-next-month-btn .k-btn-next-month,
.kalendae.k-disable-previous-month-btn .k-btn-previous-month,
.kalendae.k-disable-next-year-btn .k-btn-next-year,
.kalendae.k-disable-previous-year-btn .k-btn-previous-year {
display:none;
}
/** Week columns and day cells **/
.kalendae .k-header span,
.kalendae .k-days span {
float:left;
margin:1px 1px;
}
.kalendae .k-header span {
text-align:center;
font-weight:bold;
width:20px;
padding:1px 0;
color:#666;
}
.kalendae .k-days span {
text-align:right;
width:13px;
height:1.1em;
line-height:1em;
padding:2px 3px 2px 2px;
border:1px solid transparent;
border-radius:3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
color:#999;
}
/** Today **/
.kalendae .k-today {
text-decoration:underline;
}
/** Selected day, when outside the selectable area **/
.kalendae .k-days span.k-selected {
border-color:#1072A5;
color:#1072A5;
}
/** Selected day, when inside the selectable area **/
.kalendae .k-days span.k-selected.k-active {
background:#7EA0E2;
color:white;
}
/** Days between the start and end points on a range, outside of the selectable area **/
.kalendae .k-days span.k-range {
background:none;
border-color:#6DD4FE;
}
/** Days between the start and end points on a range, inside of the selectable area **/
.kalendae .k-days span.k-range.k-active {
background:#C4D4F1;
border-color:#19AEFE;
color:#333;
}
/** Selectable but not selected day **/
.kalendae .k-days span.k-active {
border-color:#ddd;
background-color:#fff;
cursor:pointer;
color:#333;
}
/** Selectable day, hovered **/
.kalendae .k-days span.k-active:hover {
border-color:#666;
}
/** Days outside of the month view (before the first day of the month, after the last day of the month) **/
.kalendae .k-days span.k-out-of-month {color:#ddd;}
/*-------------------------------------IE8 ONLY CODE BELOW THIS LINE--------------------------------------------*/
.kalendae.ie8.k-floating {
border:1px solid #ccc;
}
.kalendae.ie8 .k-btn-close {
width:20px;
height:20px;
border:none;
background:url('close.png') no-repeat top left;
}
.kalendae.ie8 .k-btn-close:after {display:none;}
.kalendae.ie8 .k-btn-previous-month,
.kalendae.ie8 .k-btn-next-month,
.kalendae.ie8 .k-btn-previous-year,
.kalendae.ie8 .k-btn-next-year {width:16px;height:16px;cursor:pointer;background:#777 url('arrows.png') no-repeat center left;position:absolute;top:0;}
.kalendae.ie8 .k-btn-next-month,
.kalendae.ie8 .k-btn-next-year {background-position:center right;}
.kalendae.ie8 .k-btn-previous-month:hover,
.kalendae.ie8 .k-btn-next-month:hover {background-color:#7EA0E2;}
.kalendae.ie8 .k-btn-previous-year,
.kalendae.ie8 .k-btn-next-year {background-color:#333;}
.kalendae.ie8 .k-btn-previous-year:hover,
.kalendae.ie8 .k-btn-next-year:hover {background-color:#6FDF81;}
.kalendae.ie8 .k-btn-previous-month:after,
.kalendae.ie8 .k-btn-next-month:after,
.kalendae.ie8 .k-btn-previous-year:after,
.kalendae.ie8 .k-btn-next-year:after {display:none;}
/*!------------------------------------------
* Kalendae Metal Skin
* ------------------------------------------
* Author:
* Anas Nakawa - @anasnakawa - [email protected]
* Credits:
* Kalendae plugin: Jarvis Badgley - [email protected]
* Skin inspiration: Orman Clark - http://www.premiumpixels.com
* License:
* MIT License - https://opensource.org/licenses/mit-license.php
* ------------------------------------------
*/
.kalendae {
-webkit-border-radius: 0;
-moz-border-radius: 0;
-ms-border-radius: 0;
-o-border-radius: 0;
border-radius: 0;
padding: 0;
border-bottom: 1px solid #bbbbbb;
-webkit-box-shadow: 0 5px 0 -4px #f7f7f7, 0 5px 0 -3px #bbbbbb, 0 11px 0 -8px #f7f7f7, 0 11px 0 -7px #bbbbbb, 0 0 15px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0 5px 0 -4px #f7f7f7, 0 5px 0 -3px #bbbbbb, 0 11px 0 -8px #f7f7f7, 0 11px 0 -7px #bbbbbb, 0 0 15px rgba(0, 0, 0, 0.3);
box-shadow: 0 5px 0 -4px #f7f7f7, 0 5px 0 -3px #bbbbbb, 0 11px 0 -8px #f7f7f7, 0 11px 0 -7px #bbbbbb, 0 0 15px rgba(0, 0, 0, 0.3);
background-color: transparent;
}
.kalendae .k-calendar {
width: 210px;
}
.kalendae .k-title,
.kalendae .k-header,
.kalendae .k-days {
width: auto;
}
.kalendae .k-title {
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzM5MzkzOSIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzIwMjAyMCIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #393939), color-stop(100%, #202020));
background: -webkit-linear-gradient(#393939, #202020);
background: -moz-linear-gradient(#393939, #202020);
background: -o-linear-gradient(#393939, #202020);
background: linear-gradient(#393939, #202020);
-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 1px 1px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 1px 1px rgba(0, 0, 0, 0.3);
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 1px 1px rgba(0, 0, 0, 0.3);
-webkit-border-radius: 3px 3px 0 0;
-moz-border-radius: 3px 3px 0 0;
-ms-border-radius: 3px 3px 0 0;
-o-border-radius: 3px 3px 0 0;
border-radius: 3px 3px 0 0;
background-color: transparent;
border: 1px solid black;
color: #e0e0e0;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.9);
padding: 5px;
line-height: 25px;
height: 25px;
}
.kalendae .k-title .k-caption {
font-weight: bold;
}
.kalendae .k-title a {
background-image: url('data:"image/png";base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAcFJREFUeNrslr9Kw1AUxnuvCRSMEGKldUqhYAlmcOrkIvgc2e2QQl7BsbSL4HMUHOrkA3QRB5cuSRabFwiihdRzIEJo7r9kKWguHEIufF/OPZyb3yG73a51yEVbB17a/gYhRCrar5qKhudz8ArwEjAhniGcCl4sjdwHy1AMXJ7nXS6Xy2/XdT/gdQJxVEej4sOsgG3bx47j6IvFohcEwb2maU+wPRAdn6VJ0/RC5iPsARAQ3/dPwOB2OBy+wFZb2tUFTZIkjzIfpSaEEupQyk4URcrtjpr5fG7KfKjidVlTSm/6/f5nhSu2DsPwTubDTMCyrK9ckMFjCvf8CkQr0QdZms1m8yr1YXU0lOgM4h1ipHpzWBoVH1Lnr/an/oTk39OwSaCZB1QTcHKumxW8WZryHuuvVljI7wnyHLmOfK+p4fpoghMMAKMPgNHr8XhsIFKR+ZJTlzQ4E8BzyvPhJdBGbs9ms3NEqGLJmRqcCWAOOOX5MBNAXmdZ1gF0qn6cq8GZoNvt6pWaEHmN3EZ+qybA0+BMIPKhAsMV8hs5nvO8ZRjGVpJESRPH8ZvQR9LRv+Ud5Vzv1dXwfJp5oJkHfgQYADiTnvJq+mHGAAAAAElFTkSuQmCC');
background-repeat: no-repeat;
margin-top: 9px;
}
.kalendae .k-title a:after {
content: none;
}
.kalendae .k-title a.k-btn-previous-year, .kalendae .k-title a.k-btn-previous-month {
margin-left: 5px;
}
.kalendae .k-title a.k-btn-next-year, .kalendae .k-title a.k-btn-next-month {
margin-right: 5px;
}
.kalendae .k-title a.k-btn-previous-year {
background-position: -16px -16px;
}
.kalendae .k-title a.k-btn-previous-month {
background-position: 0 -16px;
}
.kalendae .k-title a.k-btn-next-year {
background-position: -16px 0;
}
.kalendae .k-title a.k-btn-next-month {
background-position: 0 0;
}
.kalendae .k-header {
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzIyMjIyMiIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzU1NTU1NSIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #222222), color-stop(100%, #555555));
background: -webkit-linear-gradient(#222222, #555555);
background: -moz-linear-gradient(#222222, #555555);
background: -o-linear-gradient(#222222, #555555);
background: linear-gradient(#222222, #555555);
color: #dadada;
text-shadow: 0 1px 0 black;
}
.kalendae .k-header span {
color: #dadada;
width: 30px;
line-height: 20px;
text-transform: uppercase;
}
.kalendae .k-header span,
.kalendae .k-days span {
margin: 0;
}
.kalendae .k-calendar .k-days span {
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ffffff), color-stop(100%, #ffffff));
background: -webkit-linear-gradient(#ffffff, #ffffff);
background: -moz-linear-gradient(#ffffff, #ffffff);
background: -o-linear-gradient(#ffffff, #ffffff);
background: linear-gradient(#ffffff, #ffffff);
-webkit-box-shadow: 1px 1px 0 white inset;
-moz-box-shadow: 1px 1px 0 white inset;
box-shadow: 1px 1px 0 white inset;
-webkit-border-radius: 0;
-moz-border-radius: 0;
-ms-border-radius: 0;
-o-border-radius: 0;
border-radius: 0;
color: lighteb(#666666, 20);
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
border-bottom: 1px solid #eeeeee;
border-left: 1px solid #eeeeee;
width: 23px;
height: 23px;
line-height: 23px;
padding-top: 2px;
text-align: center;
}
.kalendae .k-calendar .k-days span.k-active, .kalendae .k-calendar .k-days span.k-out-of-month {
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2U3ZTdlNyIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iI2Q5ZDlkOSIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #e7e7e7), color-stop(100%, #d9d9d9));
background: -webkit-linear-gradient(#e7e7e7, #d9d9d9);
background: -moz-linear-gradient(#e7e7e7, #d9d9d9);
background: -o-linear-gradient(#e7e7e7, #d9d9d9);
background: linear-gradient(#e7e7e7, #d9d9d9);
color: #666666;
border-top-color: transparent;
border-right-color: transparent;
border-bottom: 1px solid #bbbbbb;
border-left: 1px solid #bbbbbb;
}
.kalendae .k-calendar .k-days span.k-active:hover, .kalendae .k-calendar .k-days span.k-out-of-month:hover {
border-color: #888888;
}
.kalendae .k-calendar .k-days span.k-active.k-selected, .kalendae .k-calendar .k-days span.k-selected.k-out-of-month, .kalendae .k-calendar .k-days span.k-active.k-range, .kalendae .k-calendar .k-days span.k-range.k-out-of-month {
-webkit-box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3) inset;
-moz-box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3) inset;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3) inset;
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzE0OGFkMyIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzVkYjhmMCIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #148ad3), color-stop(100%, #5db8f0));
background: -webkit-linear-gradient(#148ad3, #5db8f0);
background: -moz-linear-gradient(#148ad3, #5db8f0);
background: -o-linear-gradient(#148ad3, #5db8f0);
background: linear-gradient(#148ad3, #5db8f0);
background-color: #148ad3;
border-color: #0b4d76;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.7);
color: white;
}
.kalendae .k-calendar .k-days span.k-active.k-selected.k-out-of-month, .kalendae .k-calendar .k-days span.k-selected.k-out-of-month, .kalendae .k-calendar .k-days span.k-active.k-range.k-out-of-month, .kalendae .k-calendar .k-days span.k-range.k-out-of-month {
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2Y1ZjVmNSIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iI2VjZWNlYyIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #f5f5f5), color-stop(100%, #ececec));
background: -webkit-linear-gradient(#f5f5f5, #ececec);
background: -moz-linear-gradient(#f5f5f5, #ececec);
background: -o-linear-gradient(#f5f5f5, #ececec);
background: linear-gradient(#f5f5f5, #ececec);
color: #666666;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
background-color: whitesmoke;
border-color: #bbbbbb;
}
.kalendae .k-calendar .k-days span.k-out-of-month {
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2Y1ZjVmNSIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iI2VjZWNlYyIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #f5f5f5), color-stop(100%, #ececec));
background: -webkit-linear-gradient(#f5f5f5, #ececec);
background: -moz-linear-gradient(#f5f5f5, #ececec);
background: -o-linear-gradient(#f5f5f5, #ececec);
background: linear-gradient(#f5f5f5, #ececec);
border-bottom: 1px solid #bbbbbb;
border-left: 1px solid #bbbbbb;
color: #666666;
}
.kalendae .k-calendar.k-first-month .k-title {
-webkit-border-radius: 3px 0 0 0;
-moz-border-radius: 3px 0 0 0;
-ms-border-radius: 3px 0 0 0;
-o-border-radius: 3px 0 0 0;
border-radius: 3px 0 0 0;
}
.kalendae .k-calendar.k-middle-month .k-title {
-webkit-border-radius: 0;
-moz-border-radius: 0;
-ms-border-radius: 0;
-o-border-radius: 0;
border-radius: 0;
}
.kalendae .k-calendar.k-last-month .k-title {
-webkit-border-radius: 0 3px 0 0;
-moz-border-radius: 0 3px 0 0;
-ms-border-radius: 0 3px 0 0;
-o-border-radius: 0 3px 0 0;
border-radius: 0 3px 0 0;
}
.kalendae .k-separator {
background: none;
height: 233px;
margin: 0;
width: 0;
}
body {
background: url('https://raw.github.com/anasnakawa/kalendae-skins/gh-pages/images/rainbow-wallpaper.jpg');
}
#wrap {
display: block;
margin: 50px auto;
width: 210px;
}
/********************************************************************
* Kalendae, a framework agnostic javascript date picker *
* Copyright(c) 2012 Jarvis Badgley ([email protected]) *
* https://github.com/ChiperSoft/Kalendae *
* Version 0.2 *
********************************************************************/
(function (undefined) {
var today;
var Kalendae = function (targetElement, options) {
//if the first argument isn't an element and isn't a string, assume that it is the options object
if (!(targetElement instanceof Element || typeof targetElement === 'string')) options = targetElement;
var self = this,
classes = self.classes,
opts = self.settings = util.merge(self.defaults, {attachTo:targetElement}, options || {}),
$container = self.container = util.make('div', {'class':classes.container}),
calendars = self.calendars = [],
startDay = moment().day(opts.weekStart),
vsd,
columnHeaders = [],
$cal,
$title,
$caption,
$header,
$days, dayNodes = [],
$span,
i = 0,
j = opts.months;
if (util.isIE8()) util.addClassName($container, 'ie8');
//generate the column headers (Su, Mo, Tu, etc)
i = 7;
while (i--) {
columnHeaders.push( startDay.format('ddd').substr(0,opts.columnHeaderLength) );
startDay.add('days',1);
}
//setup publish/subscribe and apply any subscriptions passed in settings
MinPubSub(self);
if (typeof opts.subscribe === 'object') {
for (i in opts.subscribe) if (opts.subscribe.hasOwnProperty(i)) {
self.subscribe(i, opts.subscribe[i]);
}
}
//process default selected dates
self._sel = [];
if (!!opts.selected) self.setSelected(opts.selected, false);
//set the view month
if (!!opts.viewStartDate) {
vsd = moment(opts.viewStartDate, opts.format);
} else if (self._sel.length > 0) {
vsd = moment(self._sel[0]);
} else {
vsd = moment();
}
self.viewStartDate = vsd.date(1);
var viewDelta = ({
'past' : opts.months-1,
'today-past' : opts.months-1,
'any' : opts.months>2?Math.floor(opts.months/2):0,
'today-future' : 0,
'future' : 0
})[this.settings.direction];
if (viewDelta && moment().month()==moment(self.viewStartDate).month()){
self.viewStartDate = moment(self.viewStartDate).subtract({M:viewDelta}).date(1);
}
if (typeof opts.blackout === 'function') {
self.blackout = opts.blackout;
} else if (!!opts.blackout) {
var bdates = parseDates(opts.blackout, opts.parseSplitDelimiter);
self.blackout = function (input) {
input = moment(input).yearDay();
if (input < 1 || !self._sel || self._sel.length < 1) return false;
var i = bdates.length;
while (i--) if (bdates[i].yearDay() === input) return true;
return false;
}
} else {
self.blackout = function () {return false;}
}
self.direction = self.directions[opts.direction] ? self.directions[opts.direction] : self.directions['any'];
//for the total months setting, generate N calendar views and add them to the container
j = Math.max(opts.months,1);
while (j--) {
$cal = util.make('div', {'class':classes.calendar}, $container);
$cal.setAttribute('data-cal-index', j);
if (opts.months > 1) {
if (j == Math.max(opts.months-1,1)) util.addClassName($cal, classes.monthFirst);
else if (j === 0) util.addClassName($cal, classes.monthLast);
else util.addClassName($cal, classes.monthMiddle);
}
//title bar
$title = util.make('div', {'class':classes.title}, $cal);
util.make('a', {'class':classes.previousYear}, $title); //previous button
util.make('a', {'class':classes.previousMonth}, $title); //previous button
util.make('a', {'class':classes.nextYear}, $title); //next button
util.make('a', {'class':classes.nextMonth}, $title); //next button
$caption = util.make('span', {'class':classes.caption}, $title); //title caption
//column headers
$header = util.make('div', {'class':classes.header}, $cal);
i = 0;
do {
$span = util.make('span', {}, $header);
$span.innerHTML = columnHeaders[i];
} while (++i < 7)
//individual day cells
$days = util.make('div', {'class':classes.days}, $cal);
i = 0;
dayNodes = [];
while (i++ < 42) {
dayNodes.push(util.make('span', {}, $days));
}
//store each calendar view for easy redrawing
calendars.push({
caption:$caption,
days:dayNodes
});
if (j) util.make('div', {'class':classes.monthSeparator}, $container);
}
self.draw();
util.addEvent($container, 'mousedown', function (event, target) {
var clickedDate;
if (util.hasClassName(target, classes.nextMonth)) {
//NEXT MONTH BUTTON
if (!self.disableNext && self.publish('view-changed', self, ['next-month']) !== false) {
self.viewStartDate.add('months',1);
self.draw();
}
return false;
} else if (util.hasClassName(target, classes.previousMonth)) {
//PREVIOUS MONTH BUTTON
if (!self.disablePreviousMonth && self.publish('view-changed', self, ['previous-month']) !== false) {
self.viewStartDate.subtract('months',1);
self.draw();
}
return false;
} else if (util.hasClassName(target, classes.nextYear)) {
//NEXT MONTH BUTTON
if (!self.disableNext && self.publish('view-changed', self, ['next-year']) !== false) {
self.viewStartDate.add('years',1);
self.draw();
}
return false;
} else if (util.hasClassName(target, classes.previousYear)) {
//PREVIOUS MONTH BUTTON
if (!self.disablePreviousMonth && self.publish('view-changed', self, ['previous-year']) !== false) {
self.viewStartDate.subtract('years',1);
self.draw();
}
return false;
} else if (util.hasClassName(target.parentNode, classes.days) && util.hasClassName(target, classes.dayActive) && (clickedDate = target.getAttribute('data-date'))) {
//DAY CLICK
clickedDate = moment(clickedDate, opts.dayAttributeFormat).hours(12);
if (self.publish('date-clicked', self, [clickedDate]) !== false) {
switch (opts.mode) {
case 'multiple':
if (!self.addSelected(clickedDate)) self.removeSelected(clickedDate);
break;
case 'range':
self.addSelected(clickedDate);
break;
case 'single':
/* falls through */
default:
self.addSelected(clickedDate);
break;
}
}
return false;
}
return false;
});
if (!!(opts.attachTo = util.$(opts.attachTo))) {
opts.attachTo.appendChild($container);
}
};
Kalendae.prototype = {
defaults : {
attachTo: null, /* the element to attach the root container to. can be string or DOMElement */
months: 1, /* total number of months to display side by side */
weekStart: 0, /* day to use for the start of the week. 0 is Sunday */
direction: 'any', /* past, today-past, any, today-future, future */
directionScrolling: true, /* if a direction other than any is defined, prevent scrolling out of range */
viewStartDate: null, /* date in the month to display. When multiple months, this is the left most */
blackout: null, /* array of dates, or function to be passed a date */
selected: null, /* dates already selected. can be string, date, or array of strings or dates. */
mode: 'single', /* single, multiple, range */
format: null, /* string used for parsing dates. */
subscribe: null, /* object containing events to subscribe to */
columnHeaderLength: 2, /* number of characters to show in the column headers */
titleFormat: 'MMMM, YYYY', /* format mask for month titles. See momentjs.com for rules */
dayNumberFormat: 'D', /* format mask for individual days */
dayAttributeFormat: 'YYYY-MM-DD', /* format mask for the data-date attribute set on every span */
parseSplitDelimiter: /,\s*|\s+-\s+/, /* regex to use for splitting multiple dates from a passed string */
rangeDelimiter: ' - ', /* string to use between dates when outputting in range mode */
multipleDelimiter: ', ', /* string to use between dates when outputting in multiple mode */
dateClassMap: {}
},
classes : {
container :'kalendae',
calendar :'k-calendar',
monthFirst :'k-first-month',
monthMiddle :'k-middle-month',
monthLast :'k-last-month',
title :'k-title',
previousMonth :'k-btn-previous-month',
nextMonth :'k-btn-next-month',
previousYear :'k-btn-previous-year',
nextYear :'k-btn-next-year',
caption :'k-caption',
header :'k-header',
days :'k-days',
dayOutOfMonth :'k-out-of-month',
dayActive :'k-active',
daySelected :'k-selected',
dayInRange :'k-range',
dayToday :'k-today',
monthSeparator :'k-separator',
disablePreviousMonth :'k-disable-previous-month-btn',
disableNextMonth :'k-disable-next-month-btn',
disablePreviousYear :'k-disable-previous-year-btn',
disableNextYear :'k-disable-next-year-btn'
},
disablePreviousMonth: false,
disableNextMonth: false,
disablePreviousYear: false,
disableNextYear: false,
directions: {
'past' :function (date) {return moment(date).yearDay() >= today.yearDay();},
'today-past' :function (date) {return moment(date).yearDay() > today.yearDay();},
'any' :function (date) {return false;},
'today-future' :function (date) {return moment(date).yearDay() < today.yearDay();},
'future' :function (date) {return moment(date).yearDay() <= today.yearDay();}
},
getSelectedAsDates : function () {
var out = [];
var i=0, c = this._sel.length;
for (;i<c;i++) {
out.push(this._sel[i].nativeDate());
}
return out;
},
getSelectedAsText : function (format) {
var out = [];
var i=0, c = this._sel.length;
for (;i<c;i++) {
out.push(this._sel[i].format(format || this.settings.format || 'YYYY-MM-DD'))
}
return out;
},
getSelectedRaw : function () {
var out = [];
var i=0, c = this._sel.length;
for (;i<c;i++) {
out.push(moment(this._sel[i]))
}
return out;
},
getSelected : function (format) {
var sel = this.getSelectedAsText(format);
switch (this.settings.mode) {
case 'range':
sel.splice(2); //shouldn't be more than two, but lets just make sure.
return sel.join(this.settings.rangeDelimiter);
case 'multiple':
return sel.join(this.settings.multipleDelimiter);
case 'single':
/* falls through */
default:
return sel[0];
}
},
isSelected : function (input) {
input = moment(input).yearDay();
if (input < 1 || !this._sel || this._sel.length < 1) return false;
switch (this.settings.mode) {
case 'range':
var a = this._sel[0] ? this._sel[0].yearDay() : 0,
b = this._sel[1] ? this._sel[1].yearDay() : 0;
if (a === input || b === input) return 1;
if (!a || !b) return 0;
if ((input > a && input < b) || (a<b && input < a && input > b)) return -1;
return false;
case 'multiple':
var i = this._sel.length;
while (i--) {
if (this._sel[i].yearDay() === input) {
return true;
}
}
return false;
case 'single':
/* falls through */
default:
return (this._sel[0] && (this._sel[0].yearDay() === input));
}
return false;
},
setSelected : function (input, draw) {
this._sel = parseDates(input, this.settings.parseSplitDelimiter, this.settings.format);
this._sel.sort(function (a,b) {return a.yearDay() - b.yearDay();});
if (draw !== false) this.draw();
},
addSelected : function (date, draw) {
date = moment(date).hours(12);
switch (this.settings.mode) {
case 'multiple':
if (!this.isSelected(date)) this._sel.push(date);
else return false;
break;
case 'range':
if (this._sel.length !== 1) this._sel = [date];
else {
if (date.yearDay() > this._sel[0].yearDay()) this._sel[1] = date;
else this._sel = [date, this._sel[0]];
}
break;
case 'single':
/* falls through */
default:
this._sel = [date];
break;
}
this._sel.sort(function (a,b) {return a.yearDay() - b.yearDay();});
this.publish('change', this);
if (draw !== false) this.draw();
return true;
},
removeSelected : function (date, draw) {
date = moment(date).yearDay();
var i = this._sel.length;
while (i--) {
if (this._sel[i].yearDay() === date) {
this._sel.splice(i,1);
this.publish('change', this);
if (draw !== false) this.draw();
return true;
}
}
return false;
},
draw : function draw() {
// return;
var month = moment(this.viewStartDate).hours(12), //force middle of the day to avoid any weird date shifts
day,
classes = this.classes,
cal,
$span,
klass,
i=0, c,
j=0, k,
s,
dateString,
opts = this.settings;
c = this.calendars.length;
do {
day = moment(month).date(1);
day.day( day.day() < this.settings.weekStart ? this.settings.weekStart-7 : this.settings.weekStart);
//if the first day of the month is less than our week start, back up a week
cal = this.calendars[i];
cal.caption.innerHTML = month.format(this.settings.titleFormat);
j = 0;
do {
$span = cal.days[j];
klass = [];
s = this.isSelected(day);
if (s) klass.push(({'-1':classes.dayInRange,'1':classes.daySelected, 'true':classes.daySelected})[s]);
if (day.month() != month.month()) klass.push(classes.dayOutOfMonth);
else if (!(this.blackout(day) || this.direction(day)) || s>0) klass.push(classes.dayActive);
if (day.yearDay() === today.yearDay()) klass.push(classes.dayToday);
dateString = day.format(this.settings.dayAttributeFormat);
if (opts.dateClassMap[dateString]) klass.push(opts.dateClassMap[dateString]);
$span.innerHTML = day.format(opts.dayNumberFormat);
$span.className = klass.join(' ');
$span.setAttribute('data-date', dateString);
day.add('days',1);
} while (++j < 42);
month.add('months',1);
} while (++i < c);
if (opts.directionScrolling) {
var diff = -(moment().diff(month, 'months'));
if (opts.direction==='today-past' || opts.direction==='past') {
if (diff <= 0) {
this.disableNextMonth = false;
util.removeClassName(this.container, classes.disableNextMonth);
} else {
this.disableNextMonth = true;
util.addClassName(this.container, classes.disableNextMonth);
}
} else if (opts.direction==='today-future' || opts.direction==='future') {
if (diff > opts.months) {
this.disablePreviousMonth = false;
util.removeClassName(this.container, classes.disablePreviousMonth);
} else {
this.disablePreviousMonth = true;
util.addClassName(this.container, classes.disablePreviousMonth);
}
}
if (opts.direction==='today-past' || opts.direction==='past') {
if (month.add({Y:1}).diff(moment(), 'years') < 0) {
this.disableNextYear = false;
util.removeClassName(this.container, classes.disableNextYear);
} else {
this.disableNextYear = true;
util.addClassName(this.container, classes.disableNextYear);
}
} else if (opts.direction==='today-future' || opts.direction==='future') {
if (month.subtract({Y:1}).diff(moment(), 'years') > 0) {
this.disablePreviousYear = false;
util.removeClassName(this.container, classes.disablePreviousYear);
} else {
this.disablePreviousYear = true;
util.addClassName(this.container, classes.disablePreviousYear);
}
}
}
}
}
var parseDates = function (input, delimiter, format) {
var output = [];
if (typeof input === 'string') {
input = input.split(delimiter);
} else if (!util.isArray(input)) {
input = [input];
}
var c = input.length;
i = 0;
do {
if (input[i]) output.push( moment(input[i], format).hours(12) );
} while (++i < c);
return output;
}
window.Kalendae = Kalendae;
var util = Kalendae.util = {
isIE8: function() {
return !!( (/msie 8./i).test(navigator.appVersion) && !(/opera/i).test(navigator.userAgent) && window.ActiveXObject && XDomainRequest && !window.msPerformance );
},
// ELEMENT FUNCTIONS
$: function (elem) {
return (typeof elem == 'string') ? document.getElementById(elem) : elem;
},
$$: function (selector) {
return document.querySelectorAll(selector);
},
make: function (tagName, attributes, attach) {
var k, e = document.createElement(tagName);
if (!!attributes) for (k in attributes) if (attributes.hasOwnProperty(k)) e.setAttribute(k, attributes[k]);
if (!!attach) attach.appendChild(e);
return e;
},
// Returns true if the DOM element is visible, false if it's hidden.
// Checks if display is anything other than none.
isVisible: function (elem) {
// shamelessly copied from jQuery
return elem.offsetWidth > 0 || elem.offsetHeight > 0;
},
getStyle: function (elem, styleProp) {
var y;
if (elem.currentStyle) {
y = elem.currentStyle[styleProp];
} else if (window.getComputedStyle) {
y = window.getComputedStyle(elem, null)[styleProp];
}
return y;
},
domReady:function (f){/in/.test(document.readyState) ? setTimeout(function() {util.domReady(f);},9) : f()},
// Adds a listener callback to a DOM element which is fired on a specified
// event. Callback is sent the event object and the element that triggered the event
addEvent: function (elem, eventName, callback) {
var listener = function (event) {
event = event || window.event;
var target = event.target || event.srcElement;
var block = callback.apply(elem, [event, target]);
if (block === false) {
if (!!event.preventDefault) event.preventDefault();
else {
event.returnValue = false;
event.cancelBubble = true;
}
}
return block;
};
if (elem.attachEvent) { // IE only. The "on" is mandatory.
elem.attachEvent("on" + eventName, listener);
} else { // Other browsers.
elem.addEventListener(eventName, listener, false);
}
return listener;
},
// Removes a listener callback from a DOM element which is fired on a specified
// event.
removeEvent: function (elem, event, listener) {
if (elem.detachEvent) { // IE only. The "on" is mandatory.
elem.detachEvent("on" + event, listener);
} else { // Other browsers.
elem.removeEventListener(event, listener, false);
}
},
hasClassName: function(elem, className) { //copied and modified from Prototype.js
if (!(elem = util.$(elem))) return false;
var eClassName = elem.className;
return (eClassName.length > 0 && (eClassName == className || new RegExp("(^|\\s)" + className + "(\\s|$)").test(eClassName)));
},
addClassName: function(elem, className) { //copied and modified from Prototype.js
if (!(elem = util.$(elem))) return;
if (!util.hasClassName(elem, className)) elem.className += (elem.className ? ' ' : '') + className;
},
removeClassName: function(elem, className) { //copied and modified from Prototype.js
if (!(elem = util.$(elem))) return;
elem.className = util.trimString(elem.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' '));
},
isFixed: function (elem) {
do {
if (util.getStyle(elem, 'position') === 'fixed') return true;
} while ((elem = elem.offsetParent));
return false;
},
getPosition: function (elem, isInner) {
var x = elem.offsetLeft,
y = elem.offsetTop,
r = {};
if (!isInner) {
while ((elem = elem.offsetParent)) {
x += elem.offsetLeft;
y += elem.offsetTop;
}
}
r[0] = r.left = x;
r[1] = r.top = y;
return r;
},
getHeight: function (elem) {
return elem.offsetHeight || elem.scrollHeight;
},
getWidth: function (elem) {
return elem.offsetWidth || elem.scrollWidth;
},
// TEXT FUNCTIONS
trimString: function (input) {
return input.replace(/^\s+/, '').replace(/\s+$/, '');
},
// OBJECT FUNCTIONS
merge: function () {
/* Combines multiple objects into one.
* Syntax: util.extend([true], object1, object2, ... objectN)
* If first argument is true, function will merge recursively.
*/
var deep = (arguments[0]===true),
d = {},
i = deep?1:0;
var _c = function (a, b) {
if (typeof b !== 'object') return;
for (var k in b) if (b.hasOwnProperty(k)) {
//if property is an object or array, merge the contents instead of overwriting, if extend() was called as such
if (deep && typeof a[k] === 'object' && typeof b[k] === 'object') _update(a[k], b[k]);
else a[k] = b[k];
}
return a;
}
for (; i < arguments.length; i++) {
_c(d, arguments[i]);
}
return d;
},
isArray: function (array) {
return !(
!array ||
(!array.length || array.length === 0) ||
typeof array !== 'object' ||
!array.constructor ||
array.nodeType ||
array.item
);
}
};
//auto-initializaiton code
Kalendae.util.domReady(function () {
var els = util.$$('.auto-kal'),
i = els.length,
e;
while (i--) {
e = els[i];
if (e.tagName === 'INPUT') {
//if element is an input, bind a popup calendar to the input.
new Kalendae.Input(e);
} else {
//otherwise, insert a flat calendar into the element.
new Kalendae({attachTo:e});
}
}
});
Kalendae.Input = function (targetElement, options) {
var $input = this.input = util.$(targetElement),
overwriteInput;
if (!$input || $input.tagName !== 'INPUT') throw "First argument for Kalendae.Input must be an <input> element or a valid element id.";
var self = this,
classes = self.classes
opts = self.settings = util.merge(self.defaults, options);
//force attachment to the body
opts.attachTo = window.document.body;
//if no override provided, use the input's contents
if (!opts.selected) opts.selected = $input.value;
else overwriteInput = true;
//call our parent constructor
Kalendae.call(self, opts);
//create the close button
if (opts.closeButton) {
var $closeButton = util.make('a', {'class':classes.closeButton}, self.container)
util.addEvent($closeButton, 'click', function () {
$input.blur();
});
}
if (overwriteInput) $input.value = self.getSelected();
var $container = self.container,
noclose = false;
$container.style.display = 'none';
util.addClassName($container, classes.positioned);
util.addEvent($container, 'mousedown', function (event, target) {
noclose = true; //IE8 doesn't obey event blocking when it comes to focusing, so we have to do this shit.
});
util.addEvent(window.document, 'mousedown', function (event, target) {
noclose = false;
});
util.addEvent($input, 'focus', function () {
self.setSelected(this.value);
self.show();
});
util.addEvent($input, 'blur', function () {
if (noclose) {
noclose = false;
$input.focus();
}
else self.hide();
});
util.addEvent($input, 'keyup', function (event) {
self.setSelected(this.value);
});
self.subscribe('change', function () {
$input.value = self.getSelected();
});
};
Kalendae.Input.prototype = util.merge(Kalendae.prototype, {
defaults : util.merge(Kalendae.prototype.defaults, {
format: 'MM/DD/YYYY',
side: 'bottom',
closeButton: true,
offsetLeft: 0,
offsetTop: 0
}),
classes : util.merge(Kalendae.prototype.classes, {
positioned : 'k-floating',
closeButton: 'k-btn-close'
}),
show : function () {
var $container = this.container,
style = $container.style,
$input = this.input,
pos = util.getPosition($input);
style.display = '';
switch (opts.side) {
case 'left':
style.left = (pos.left - util.getWidth($container) + this.settings.offsetLeft) + 'px';
style.top = (pos.top + this.settings.offsetTop) + 'px';
break;
case 'right':
style.left = (pos.left + util.getWidth($input)) + 'px';
style.top = (pos.top + this.settings.offsetTop) + 'px';
break;
case 'top':
style.left = (pos.left + this.settings.offsetLeft) + 'px';
style.top = (pos.top - util.getHeight($container) + this.settings.offsetTop) + 'px';
break;
case 'bottom':
/* falls through */
default:
style.left = (pos.left + this.settings.offsetLeft) + 'px';
style.top = (pos.top + util.getHeight($input) + this.settings.offsetTop) + 'px';
break;
}
style.position = util.isFixed($input) ? 'fixed' : 'absolute';
},
hide : function () {
this.container.style.display = 'none';
}
});
/*!
* MinPubSub, modified for use on Kalendae
* Copyright(c) 2011 Daniel Lamb <daniellmb.com>
* https://github.com/daniellmb/MinPubSub
* MIT Licensed
*/
var MinPubSub = function(d){
if (!d) d = this;
// the topic/subscription hash
var cache = d.c_ || {}; //check for "c_" cache for unit testing
d.publish = function(/* String */ topic, /* Object */ target, /* Array? */ args){
// summary:
// Publish some data on a named topic.
// topic: String
// The channel to publish on
// args: Array?
// The data to publish. Each array item is converted into an ordered
// arguments on the subscribed functions.
//
// example:
// Publish stuff on '/some/topic'. Anything subscribed will be called
// with a function signature like: function(a,b,c){ ... }
//
// publish("/some/topic", ["a","b","c"]);
var subs = cache[topic],
len = subs ? subs.length : 0,
r;
//can change loop or reverse array if the order matters
while(len--){
r = subs[len].apply(target, args || []);
if (typeof r === 'boolean') return r;
}
};
d.subscribe = function(/* String */ topic, /* Function */ callback, /* Boolean */ topPriority){
// summary:
// Register a callback on a named topic.
// topic: String
// The channel to subscribe to
// callback: Function
// The handler event. Anytime something is publish'ed on a
// subscribed channel, the callback will be called with the
// published array as ordered arguments.
//
// returns: Array
// A handle which can be used to unsubscribe this particular subscription.
//
// example:
// subscribe("/some/topic", function(a, b, c){ /* handle data */ });
if(!cache[topic]){
cache[topic] = [];
}
if (topPriority)
cache[topic].push(callback);
else
cache[topic].unshift(callback);
return [topic, callback]; // Array
};
d.unsubscribe = function(/* Array */ handle){
// summary:
// Disconnect a subscribed function for a topic.
// handle: Array
// The return value from a subscribe call.
// example:
// var handle = subscribe("/some/topic", function(){});
// unsubscribe(handle);
var subs = cache[handle[0]],
callback = handle[1],
len = subs ? subs.length : 0;
while(len--){
if(subs[len] === callback){
subs.splice(len, 1);
}
}
};
};// Moment.js
// Altered slightly for use in Kalendae.js
//
// (c) 2011 Tim Wood
// Moment.js is freely distributable under the terms of the MIT license.
//
// Version 1.3.0
var moment = Kalendae.moment = (function (Date, undefined) {
var moment,
round = Math.round,
languages = {},
hasModule = (typeof module !== 'undefined'),
paramsToParse = 'months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|'),
i,
charactersToReplace = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?|ZZ?|LT|LL?L?L?)/g,
nonuppercaseLetters = /[^A-Z]/g,
timezoneRegex = /\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g,
tokenCharacters = /(\\)?(MM?M?M?|dd?d?d|DD?D?D?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|ZZ?|T)/g,
inputCharacters = /(\\)?([0-9]+|([a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+|([\+\-]\d\d:?\d\d))/gi,
timezoneParseRegex = /([\+\-]|\d\d)/gi,
VERSION = "1.3.0",
shortcuts = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|');
// Moment prototype object
function Moment(date) {
this._d = date;
}
// left zero fill a number
// see http://jsperf.com/left-zero-filling for performance comparison
function leftZeroFill(number, targetLength) {
var output = number + '';
while (output.length < targetLength) {
output = '0' + output;
}
return output;
}
// helper function for _.addTime and _.subtractTime
function dateAddRemove(date, _input, adding, val) {
var isString = (typeof _input === 'string'),
input = isString ? {} : _input,
ms, d, M, currentDate;
if (isString && val) {
input[_input] = val;
}
ms = (input.ms || input.milliseconds || 0) +
(input.s || input.seconds || 0) * 1e3 + // 1000
(input.m || input.minutes || 0) * 6e4 + // 1000 * 60
(input.h || input.hours || 0) * 36e5; // 1000 * 60 * 60
d = (input.d || input.days || 0) +
(input.w || input.weeks || 0) * 7;
M = (input.M || input.months || 0) +
(input.y || input.years || 0) * 12;
if (ms) {
date.setTime(+date + ms * adding);
}
if (d) {
date.setDate(date.getDate() + d * adding);
}
if (M) {
currentDate = date.getDate();
date.setDate(1);
date.setMonth(date.getMonth() + M * adding);
date.setDate(Math.min(new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate(), currentDate));
}
return date;
}
// check if is an array
function isArray(input) {
return Object.prototype.toString.call(input) === '[object Array]';
}
// convert an array to a date.
// the array should mirror the parameters below
// note: all values past the year are optional and will default to the lowest possible value.
// [year, month, day , hour, minute, second, millisecond]
function dateFromArray(input) {
return new Date(input[0], input[1] || 0, input[2] || 1, input[3] || 0, input[4] || 0, input[5] || 0, input[6] || 0);
}
// format date using native date object
function formatDate(date, inputString) {
var m = new Moment(date),
currentMonth = m.month(),
currentDate = m.date(),
currentYear = m.year(),
currentDay = m.day(),
currentHours = m.hours(),
currentMinutes = m.minutes(),
currentSeconds = m.seconds(),
currentZone = m.zone(),
ordinal = moment.ordinal,
meridiem = moment.meridiem;
// check if the character is a format
// return formatted string or non string.
//
// uses switch/case instead of an object of named functions (like http://phpjs.org/functions/date:380)
// for minification and performance
// see http://jsperf.com/object-of-functions-vs-switch for performance comparison
function replaceFunction(input) {
// create a couple variables to be used later inside one of the cases.
var a, b;
switch (input) {
// MONTH
case 'M' :
return currentMonth + 1;
case 'Mo' :
return (currentMonth + 1) + ordinal(currentMonth + 1);
case 'MM' :
return leftZeroFill(currentMonth + 1, 2);
case 'MMM' :
return moment.monthsShort[currentMonth];
case 'MMMM' :
return moment.months[currentMonth];
// DAY OF MONTH
case 'D' :
return currentDate;
case 'Do' :
return currentDate + ordinal(currentDate);
case 'DD' :
return leftZeroFill(currentDate, 2);
// DAY OF YEAR
case 'DDD' :
a = new Date(currentYear, currentMonth, currentDate);
b = new Date(currentYear, 0, 1);
return ~~ (((a - b) / 864e5) + 1.5);
case 'DDDo' :
a = replaceFunction('DDD');
return a + ordinal(a);
case 'DDDD' :
return leftZeroFill(replaceFunction('DDD'), 3);
// WEEKDAY
case 'd' :
return currentDay;
case 'do' :
return currentDay + ordinal(currentDay);
case 'ddd' :
return moment.weekdaysShort[currentDay];
case 'dddd' :
return moment.weekdays[currentDay];
// WEEK OF YEAR
case 'w' :
a = new Date(currentYear, currentMonth, currentDate - currentDay + 5);
b = new Date(a.getFullYear(), 0, 4);
return ~~ ((a - b) / 864e5 / 7 + 1.5);
case 'wo' :
a = replaceFunction('w');
return a + ordinal(a);
case 'ww' :
return leftZeroFill(replaceFunction('w'), 2);
// YEAR
case 'YY' :
return leftZeroFill(currentYear % 100, 2);
case 'YYYY' :
return currentYear;
// AM / PM
case 'a' :
return currentHours > 11 ? meridiem.pm : meridiem.am;
case 'A' :
return currentHours > 11 ? meridiem.PM : meridiem.AM;
// 24 HOUR
case 'H' :
return currentHours;
case 'HH' :
return leftZeroFill(currentHours, 2);
// 12 HOUR
case 'h' :
return currentHours % 12 || 12;
case 'hh' :
return leftZeroFill(currentHours % 12 || 12, 2);
// MINUTE
case 'm' :
return currentMinutes;
case 'mm' :
return leftZeroFill(currentMinutes, 2);
// SECOND
case 's' :
return currentSeconds;
case 'ss' :
return leftZeroFill(currentSeconds, 2);
// TIMEZONE
case 'zz' :
// depreciating 'zz' fall through to 'z'
case 'z' :
return (date.toString().match(timezoneRegex) || [''])[0].replace(nonuppercaseLetters, '');
case 'Z' :
return (currentZone > 0 ? '+' : '-') + leftZeroFill(~~(Math.abs(currentZone) / 60), 2) + ':' + leftZeroFill(~~(Math.abs(currentZone) % 60), 2);
case 'ZZ' :
return (currentZone > 0 ? '+' : '-') + leftZeroFill(~~(10 * Math.abs(currentZone) / 6), 4);
// LONG DATES
case 'L' :
case 'LL' :
case 'LLL' :
case 'LLLL' :
case 'LT' :
return formatDate(date, moment.longDateFormat[input]);
// DEFAULT
default :
return input.replace(/(^\[)|(\\)|\]$/g, "");
}
}
return inputString.replace(charactersToReplace, replaceFunction);
}
// date from string and format string
function makeDateFromStringAndFormat(string, format) {
var inArray = [0, 0, 1, 0, 0, 0, 0],
timezoneHours = 0,
timezoneMinutes = 0,
isUsingUTC = false,
inputParts = string.match(inputCharacters),
formatParts = format.match(tokenCharacters),
i,
isPm;
// function to convert string input to date
function addTime(format, input) {
var a;
switch (format) {
// MONTH
case 'M' :
// fall through to MM
case 'MM' :
inArray[1] = ~~input - 1;
break;
case 'MMM' :
// fall through to MMMM
case 'MMMM' :
for (a = 0; a < 12; a++) {
if (moment.monthsParse[a].test(input)) {
inArray[1] = a;
break;
}
}
break;
// DAY OF MONTH
case 'D' :
// fall through to DDDD
case 'DD' :
// fall through to DDDD
case 'DDD' :
// fall through to DDDD
case 'DDDD' :
inArray[2] = ~~input;
break;
// YEAR
case 'YY' :
input = ~~input;
inArray[0] = input + (input > 70 ? 1900 : 2000);
break;
case 'YYYY' :
inArray[0] = ~~Math.abs(input);
break;
// AM / PM
case 'a' :
// fall through to A
case 'A' :
isPm = (input.toLowerCase() === 'pm');
break;
// 24 HOUR
case 'H' :
// fall through to hh
case 'HH' :
// fall through to hh
case 'h' :
// fall through to hh
case 'hh' :
inArray[3] = ~~input;
break;
// MINUTE
case 'm' :
// fall through to mm
case 'mm' :
inArray[4] = ~~input;
break;
// SECOND
case 's' :
// fall through to ss
case 'ss' :
inArray[5] = ~~input;
break;
// TIMEZONE
case 'Z' :
// fall through to ZZ
case 'ZZ' :
isUsingUTC = true;
a = input.match(timezoneParseRegex);
if (a[1]) {
timezoneHours = ~~a[1];
}
if (a[2]) {
timezoneMinutes = ~~a[2];
}
// reverse offsets
if (a[0] === '-') {
timezoneHours = -timezoneHours;
timezoneMinutes = -timezoneMinutes;
}
break;
}
}
for (i = 0; i < formatParts.length; i++) {
addTime(formatParts[i], inputParts[i]);
}
// handle am pm
if (isPm && inArray[3] < 12) {
inArray[3] += 12;
}
// if is 12 am, change hours to 0
if (isPm === false && inArray[3] === 12) {
inArray[3] = 0;
}
// handle timezone
inArray[3] += timezoneHours;
inArray[4] += timezoneMinutes;
// return
return isUsingUTC ? new Date(Date.UTC.apply({}, inArray)) : dateFromArray(inArray);
}
// compare two arrays, return the number of differences
function compareArrays(array1, array2) {
var len = Math.min(array1.length, array2.length),
lengthDiff = Math.abs(array1.length - array2.length),
diffs = 0,
i;
for (i = 0; i < len; i++) {
if (~~array1[i] !== ~~array2[i]) {
diffs++;
}
}
return diffs + lengthDiff;
}
// date from string and array of format strings
function makeDateFromStringAndArray(string, formats) {
var output,
inputParts = string.match(inputCharacters),
scores = [],
scoreToBeat = 99,
i,
curDate,
curScore;
for (i = 0; i < formats.length; i++) {
curDate = makeDateFromStringAndFormat(string, formats[i]);
curScore = compareArrays(inputParts, formatDate(curDate, formats[i]).match(inputCharacters));
if (curScore < scoreToBeat) {
scoreToBeat = curScore;
output = curDate;
}
}
return output;
}
moment = function (input, format) {
if (input === null) {
return null;
}
var date;
// parse UnderscoreDate object
if (input && input._d instanceof Date) {
date = new Date(+input._d);
// parse string and format
} else if (format) {
if (isArray(format)) {
date = makeDateFromStringAndArray(input, format);
} else {
date = makeDateFromStringAndFormat(input, format);
}
// parse everything else
} else {
date = input === undefined ? new Date() :
input instanceof Date ? input :
isArray(input) ? dateFromArray(input) :
new Date(input);
}
return new Moment(date);
};
// version number
moment.version = VERSION;
// language switching and caching
moment.lang = function (key, values) {
var i,
param,
req,
parse = [];
if (values) {
for (i = 0; i < 12; i++) {
parse[i] = new RegExp('^' + values.months[i] + '|^' + values.monthsShort[i].replace('.', ''), 'i');
}
values.monthsParse = values.monthsParse || parse;
languages[key] = values;
}
if (languages[key]) {
for (i = 0; i < paramsToParse.length; i++) {
param = paramsToParse[i];
moment[param] = languages[key][param] || moment[param];
}
} else {
if (hasModule) {
req = require('./lang/' + key);
moment.lang(key, req);
}
}
};
// set default language
moment.lang('en', {
months : "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
monthsShort : "Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),
weekdays : "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
weekdaysShort : "Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),
longDateFormat : {
LT : "h:mm A",
L : "MM/DD/YYYY",
LL : "MMMM D YYYY",
LLL : "MMMM D YYYY LT",
LLLL : "dddd, MMMM D YYYY LT"
},
meridiem : {
AM : 'AM',
am : 'am',
PM : 'PM',
pm : 'pm'
},
calendar : {
sameDay : '[Today at] LT',
nextDay : '[Tomorrow at] LT',
nextWeek : 'dddd [at] LT',
lastDay : '[Yesterday at] LT',
lastWeek : '[last] dddd [at] LT',
sameElse : 'L'
},
relativeTime : {
future : "in %s",
past : "%s ago",
s : "a few seconds",
m : "a minute",
mm : "%d minutes",
h : "an hour",
hh : "%d hours",
d : "a day",
dd : "%d days",
M : "a month",
MM : "%d months",
y : "a year",
yy : "%d years"
},
ordinal : function (number) {
var b = number % 10;
return (~~ (number % 100 / 10) === 1) ? 'th' :
(b === 1) ? 'st' :
(b === 2) ? 'nd' :
(b === 3) ? 'rd' : 'th';
}
});
// helper function for _date.from() and _date.fromNow()
function substituteTimeAgo(string, number, withoutSuffix) {
var rt = moment.relativeTime[string];
return (typeof rt === 'function') ?
rt(number || 1, !!withoutSuffix, string) :
rt.replace(/%d/i, number || 1);
}
function relativeTime(milliseconds, withoutSuffix) {
var seconds = round(Math.abs(milliseconds) / 1000),
minutes = round(seconds / 60),
hours = round(minutes / 60),
days = round(hours / 24),
years = round(days / 365),
args = seconds < 45 && ['s', seconds] ||
minutes === 1 && ['m'] ||
minutes < 45 && ['mm', minutes] ||
hours === 1 && ['h'] ||
hours < 22 && ['hh', hours] ||
days === 1 && ['d'] ||
days <= 25 && ['dd', days] ||
days <= 45 && ['M'] ||
days < 345 && ['MM', round(days / 30)] ||
years === 1 && ['y'] || ['yy', years];
args[2] = withoutSuffix;
return substituteTimeAgo.apply({}, args);
}
// shortcut for prototype
moment.fn = Moment.prototype = {
clone : function () {
return moment(this);
},
valueOf : function () {
return +this._d;
},
nativeDate : function () {
return this._d;
},
toString : function () {
return this._d.toString();
},
toDate : function () {
return this._d;
},
format : function (inputString) {
return formatDate(this._d, inputString);
},
add : function (input, val) {
this._d = dateAddRemove(this._d, input, 1, val);
return this;
},
subtract : function (input, val) {
this._d = dateAddRemove(this._d, input, -1, val);
return this;
},
diff : function (input, val, asFloat) {
var inputMoment = moment(input),
diff = this._d - inputMoment._d,
year = this.year() - inputMoment.year(),
month = this.month() - inputMoment.month(),
day = this.day() - inputMoment.day(),
output;
if (val === 'months') {
output = year * 12 + month + day / 30;
} else if (val === 'years') {
output = year + month / 12;
} else {
output = val === 'seconds' ? diff / 1e3 : // 1000
val === 'minutes' ? diff / 6e4 : // 1000 * 60
val === 'hours' ? diff / 36e5 : // 1000 * 60 * 60
val === 'days' ? diff / 864e5 : // 1000 * 60 * 60 * 24
val === 'weeks' ? diff / 6048e5 : // 1000 * 60 * 60 * 24 * 7
val === 'days' ? diff / 3600 : diff;
}
return asFloat ? output : round(output);
},
from : function (time, withoutSuffix) {
var difference = this.diff(time),
rel = moment.relativeTime,
output = relativeTime(difference, withoutSuffix);
return withoutSuffix ? output : (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output);
},
fromNow : function (withoutSuffix) {
return this.from(moment(), withoutSuffix);
},
calendar : function () {
var today = moment(),
todayAtZeroHour = moment([today.year(), today.month(), today.date()]),
diff = this.diff(todayAtZeroHour, 'days', true),
calendar = moment.calendar,
allElse = calendar.sameElse,
format = diff < -6 ? allElse :
diff < -1 ? calendar.lastWeek :
diff < 0 ? calendar.lastDay :
diff < 1 ? calendar.sameDay :
diff < 2 ? calendar.nextDay :
diff < 7 ? calendar.nextWeek : allElse;
return this.format(typeof format === 'function' ? format.apply(this) : format);
},
isLeapYear : function () {
var year = this.year();
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
},
isDST : function () {
return this.zone() !== moment([this.year()]).zone();
},
day : function (input) {
var day = this._d.getDay();
return (typeof input === 'undefined') ? day :
this.add({ d : input - day });
}
};
// helper for adding shortcuts
function makeShortcut(name, key) {
moment.fn[name] = function (input) {
if (typeof input !== 'undefined') {
this._d['set' + key](input);
return this;
} else {
return this._d['get' + key]();
}
};
}
// loop through and add shortcuts (Month, Date, Hours, Minutes, Seconds, Milliseconds)
for (i = 0; i < shortcuts.length; i ++) {
makeShortcut(shortcuts[i].toLowerCase(), shortcuts[i]);
}
// add shortcut for year (uses different syntax than the getter/setter 'year' == 'FullYear')
makeShortcut('year', 'FullYear');
// add shortcut for timezone offset (no setter)
moment.fn.zone = function () {
return this._d.getTimezoneOffset();
};
return moment;
})(Date);
//function to reset the date object to 00:00 GMT
moment.fn.stripTime = function () {
this._d = new Date(Math.floor(this._d.valueOf() / 86400000) * 86400000);
return this;
}
//function to get the total number of days since the epoch.
moment.fn.yearDay = function (input) {
var yearday = Math.floor(this._d / 86400000);
return (typeof input === 'undefined') ? yearday :
this.add({ d : input - yearday });
}
today = moment().stripTime();
if (typeof jQuery !== 'undefined') {
jQuery.fn.kalendae = function (options) {
this.each(function (i, e) {
if (e.tagName === 'INPUT') {
//if element is an input, bind a popup calendar to the input.
$(e).data('kalendae', new Kalendae.Input(e, options));
} else {
//otherwise, insert a flat calendar into the element.
$(e).data('kalendae', new Kalendae($.extend({}, {attachTo:e}, options)));
}
});
return this;
}
}
})();
Also see: Tab Triggers