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.
<!-- calendar -->
<div class="calendar-container iscroll-wrapper" data-bind="iscroll: loaded, css: rowTracker() + ' ' + animate()">
<div class="calendar iscroll-scroller" data-bind="css: mode">
<div class="calendar-body" data-bind="foreach: {data: rows, as: 'row', afterRender: renderedRows}">
<div class="calendar-row iscroll-row" data-bind="css: row.css() + ' ' + row.mode(), attr: {'data-year': row.date().year(), 'data-month': row.date().month()}">
<!-- ko template {name: row.type, data: row.date} --><!-- /ko -->
</div>
</div>
</div>
<div class="calendar calendar-fixed iscroll-header" data-bind="css: mode">
<div class="calendar-nav">
<div class="calendar-row">
<!-- ko template {name: 'heading', data: scrollDate} --><!-- /ko -->
</div>
</div>
</div>
</div>
<script type="text/html" id="lastWeek">
<!-- ko template {name: 'heading', data: row.headerDate} --><!-- /ko -->
<!-- ko template {name: 'week', data: row.date} --><!-- /ko -->
</script>
<script type="text/html" id="lastSeason">
<!-- ko template {name: 'heading', data: row.headerDate} --><!-- /ko -->
<!-- ko template {name: 'season', data: row.date} --><!-- /ko -->
</script>
<script type="text/html" id="heading">
<div class="calendar-heading">
<div class="calendar-heading-year" data-bind="event: { tap: function(){if($root.mode() == 'calendar-mode-week'){ $root.switchView(); }}}">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="calendar-heading-year-text" data-bind="text: $data.format('YYYY')"></span></div>
<div class="calendar-heading-month" data-bind="text: $data.format('MMMM')"></div>
<div class="calendar-heading-days clearfix" data-bind="foreach: Array(7)">
<span class="calendar-heading-day calendar-day" data-bind="text: moment().weekday($index()).format('ddd')"></span>
</div>
</div>
</script>
<script type="text/html" id="week" data-bind="css: ''">
<div class="calendar-week clearfix" data-bind="foreach: Array(7)">
<span class="calendar-day calendar-day-outline" data-bind="text: $parent.weekday($index()).format('DD')">test</span>
</div>
</script>
<script type="text/html" id="season">
<div class="calendar-season clearfix" data-bind="foreach: Array(4)">
<span class="calendar-month calendar-month-outline" data-bind="event: { tap: function(){$root.selectMonth(new moment().year($parent.year()).month($parent.month() + $index()).date(1))}}, text: new moment().month($parent.month() + $index()).format('MMM')">test</span>
</div>
</script>
<!-- /calendar -->
html, body {
height: 100%;
}
@padding: 0px;
//== Media queries breakpoints
//
//## Define the breakpoints at which your layout will change, adapting to different screen sizes.
// Extra small screen / phone
// Note: Deprecated @screen-xs and @screen-phone as of v3.0.1
@screen-xs: 480px;
@screen-xs-min: @screen-xs;
@screen-phone: @screen-xs-min;
// Small screen / tablet
// Note: Deprecated @screen-sm and @screen-tablet as of v3.0.1
@screen-sm: 768px;
@screen-sm-min: @screen-sm;
@screen-tablet: @screen-sm-min;
// Medium screen / desktop
// Note: Deprecated @screen-md and @screen-desktop as of v3.0.1
@screen-md: 992px;
@screen-md-min: @screen-md;
@screen-desktop: @screen-md-min;
// Large screen / wide desktop
// Note: Deprecated @screen-lg and @screen-lg-desktop as of v3.0.1
@screen-lg: 1200px;
@screen-lg-min: @screen-lg;
@screen-lg-desktop: @screen-lg-min;
// So media queries don't overlap when required, provide a maximum
@screen-xs-max: (@screen-sm-min - 1);
@screen-sm-max: (@screen-md-min - 1);
@screen-md-max: (@screen-lg-min - 1);
//== Container sizes
//
//## Define the maximum width of `.container` for different screen sizes.
// X-Small screen / phone
@container-phone: ((440px));
// For `@screen-sm-min` and up.
@container-xs: @container-phone;
// Small screen / tablet
@container-tablet: ((720px));
// For `@screen-sm-min` and up.
@container-sm: @container-tablet;
// Medium screen / desktop
@container-desktop: ((940px));
// For `@screen-md-min` and up.
@container-md: @container-desktop;
// Large screen / wide desktop
@container-large-desktop: ((1140px));
// For `@screen-lg-min` and up.
@container-lg: @container-large-desktop;
//Calendar colors
@c-header-year: #ff4900;
@c-header-color: #0067b7;
@c-header-sub-color: #999;
.calendar-fixed() {
left: 50%;
position: relative;
&:extend(.clearfix all);
}
.make-week(@width) {
@unit: @width/7;
margin-left: [email protected]/2;
&-container {
//padding-top: @unit;
}
.mCSB_scrollTools {
top: @unit;
}
.calendar-body {
//margin-top: [email protected];
}
.calendar-row {
&.calendar-row-last {
.calendar-heading {
display: none;
}
}
height: @unit;
width: @width;
margin-left: @padding;
margin-right: @padding;
.calendar-heading {
}
}
.calendar-month {
line-height: @unit;
}
.calendar-day {
width: @unit;
}
}
.calendar {
.calendar-fixed();
width: @container-xs + @padding*2;
height: 100%;
overflow: visible;
&-scroller {
height: 100%;
position: static;
overflow: auto;
}
&-container {
height: 100%;
position: relative;
}
&-fixed {
position: fixed;
top: 0;
height: auto;
z-index: 1;
overflow: visible;
background: #fff;
.calendar-row {
background: #fff;
&:before {
content: '';
background: #fff;
position: fixed;
top: 0;
left: 0;
right: 0;
height: inherit;
}
}
}
.make-week(@container-xs);
@media (min-width: @screen-sm-min) {
width: @container-sm + @padding*2; .make-week(@container-sm)
}
@media (min-width: @screen-md-min) {
width: @container-md + @padding*2; .make-week(@container-md)
}
@media (min-width: @screen-lg-min) {
width: @container-lg + @padding*2; .make-week(@container-lg)
}
&-day {
display: block;
float: left;
height: 100%;
text-align: right;
padding: 10px;
position: relative;
&-outline:before {
content: '';
display: block;
position: absolute;
top: 5px;
left: 5px;
right: 5px;
bottom: 5px;
border-bottom: 1px solid #ccc;
}
}
&-week {
height: 100%;
}
&-month {
display: inline-block;
float: left;
width: 25%;
text-align: center;
font-size: 18px;
color: @c-header-color;
padding: 10px;
position: relative;
cursor: pointer;
&-outline:before {
content: '';
display: block;
position: absolute;
top: 20px;
left: 20px;
right: 20px;
bottom: 20px;
border: 1px solid #ccc;
box-shadow: 0 5px 19px -11px #000044;
}
&-outline:hover:before {
-webkit-animation-name: lift;
animation-name: lift;
}
&-outline:before {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
}
@delay: .1s;
& .calendar-row &{
&-heading, &-week, &-season, &-month, &-day{
-webkit-animation-duration: .5s;
animation-duration: .5s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
}
&.calendar-mode-season .calendar-mode-week.calendar-row &{
.calendar-container.animate &-heading{
-webkit-animation-name:fadeOutRight;
animation-name:fadeOutRight;
}
.calendar-container.animate &-week{
-webkit-animation-name:fadeOutRight;
animation-name:fadeOutRight;
}
&-season{}
&-month{}
&-day{}
}
&.calendar-mode-season .calendar-mode-season.calendar-row &{
.calendar-container.animate &-heading{
-webkit-animation-name:fadeInLeft;
animation-name:fadeInLeft;
-webkit-animation-delay: @delay;
animation-delay: @delay;
}
&-week{}
.calendar-container.animate &-season{
-webkit-animation-name:fadeInLeft;
animation-name:fadeInLeft;
-webkit-animation-delay: @delay;
animation-delay: @delay;
}
&-day{
display: none;
}
&-month{}
}
&.calendar-mode-week .calendar-mode-season.calendar-row &{
.calendar-container.animate &-heading{
-webkit-animation-name:fadeOutLeft;
animation-name:fadeOutLeft;
}
&-week{}
.calendar-container.animate &-season{
-webkit-animation-name:fadeOutLeft;
animation-name:fadeOutLeft;
}
&-month{}
&-day{}
}
&.calendar-mode-week .calendar-mode-week.calendar-row &{
.calendar-container.animate &-heading{
-webkit-animation-name:fadeInRight;
animation-name:fadeInRight;
-webkit-animation-delay: @delay;
animation-delay: @delay;
}
.calendar-container.animate &-week{
-webkit-animation-name:fadeInRight;
animation-name:fadeInRight;
-webkit-animation-delay: @delay;
animation-delay: @delay;
}
&-season{}
&-month{
display: none;
}
&-day{}
}
&-heading {
height: 100%;
position: relative;
box-shadow: 0 9px 16px -15px #004;
&-year, &-month, &-days, &-day {
-webkit-animation-duration: .5s;
animation-duration: .5s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
&-day {
-webkit-animation-delay: .2s;
animation-delay: .2s;
}
&-year {
color: @c-header-year;
text-align: center;
position: absolute;
left: 0;
right: 0;
bottom: 25%;
font-size: 18px;
.glyphicon {
display: none;
}
&-text{
font-size: 24px;
}
cursor: pointer;
z-index: 100;
}
&-month {
color: @c-header-color;
text-align: center;
position: absolute;
left: 0;
right: 0;
bottom: 25%;
font-size: 24px;
}
&-days {
position: absolute;
bottom: 0;
}
&-day {
color: @c-header-sub-color;
text-align: center;
padding: 5px;
}
.calendar.calendar-mode-week .calendar-mode-week.calendar-row &,
.calendar.calendar-mode-season .calendar-mode-season.calendar-row &{
& {
//-webkit-animation-name:fadeInLeft;
//animation-name:fadeInLeft;
}
}
.calendar.calendar-mode-week .calendar-mode-season.calendar-row &,
.calendar.calendar-mode-season .calendar-mode-week.calendar-row &{
& {
//-webkit-animation-name:fadeOutRight;
//animation-name:fadeOutRight;
}
}
.calendar-fixed.calendar-mode-season &,
.calendar.calendar-mode-season .calendar-mode-season.calendar-row & {
&-year {
}
}
.calendar-fixed.calendar-mode-week &,
.calendar.calendar-mode-week .calendar-mode-week.calendar-row & {
&-month {
color: @c-header-color;
text-align: center;
position: absolute;
left: 0;
right: 0;
bottom: 25%;
font-size: 24px;
}
&-days {
position: absolute;
bottom: 0;
}
&-day {
color: @c-header-sub-color;
text-align: center;
padding: 5px;
}
}
.calendar.calendar-mode-season .calendar-mode-season.calendar-row & {
&-year {
//-webkit-animation-name:fadeInLeft;
//animation-name:fadeInLeft;
}
&-month, &-days, &-day {
display: none;
}
}
.calendar.calendar-mode-week .calendar-mode-week.calendar-row & {
& {
//-webkit-animation-name:fadeInLeft;
//animation-name:fadeInLeft;
}
&-year {
display:none;
}
&-month, &-days{
//-webkit-animation-name:fadeInLeft;
//animation-name:fadeInLeft;
}
}
.calendar.calendar-mode-season .calendar-mode-week.calendar-row & {
&-year {
display: none;
}
&-month {
//-webkit-animation-name:fadeOutRight;
//animation-name:fadeOutRight;
}
&-days {
//-webkit-animation-name:fadeOutRight;
//animation-name:fadeOutRight;
}
&-day {
//display: none;
}
}
.calendar.calendar-mode-week .calendar-mode-season.calendar-row & {
& {
//-webkit-animation-name:fadeOutRight;
//animation-name:fadeOutRight;
}
&-year {
//-webkit-animation-name:fadeOutRight;
//animation-name:fadeOutRight;
}
&-month {
display: none;
}
&-days {
display: none;
}
&-day {
//display: none;
}
}
.calendar-fixed.calendar-mode-week & {
& {
//display: none;
}
&-year {
display: inline-block;
right: auto;
text-align: left;
bottom: 50%;
.calendar-container.animate & {
-webkit-animation-name:fadeInRight;
animation-name:fadeInRight;
}
.glyphicon {
display: inline;
}
}
.calendar-container.animate &-month {
-webkit-animation-name:fadeInRight;
animation-name:fadeInRight;
}
.calendar-container.animate &-days {
-webkit-animation-name:fadeInRight;
animation-name:fadeInRight;
}
&-day {
//display: none;
}
}
.calendar-fixed.calendar-mode-season & {
& {
//display: none;
}
.calendar-container.animate &-year {
-webkit-animation-name:fadeInLeft;
animation-name:fadeInLeft;
}
.calendar-container.animate &-month {
display: block;
-webkit-animation-name:fadeOutRight;
animation-name:fadeOutRight;
}
.calendar-container.animate &-days {
display: block;
-webkit-animation-name:fadeOutRight;
animation-name:fadeOutRight;
}
.calendar-container &-month {
display: none;
}
.calendar-container &-days {
display: none;
}
&-day {
//display: none;
}
}
}
}
.iscroll-wrapper {
position: absolute;
z-index: 1;
top: 0px;
bottom: 0px;
left: 0;
width: 100%;
overflow: hidden;
margin: 0px auto;
}
.iscroll-scroller {
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
position: relative;
z-index: 1;
-webkit-tap-highlight-color: rgba(0,0,0,0);
width: 100%;
list-style: none;
padding: 0;
text-align: left;
-webkit-transform: translateZ(0);
-moz-transform: translateZ(0);
-ms-transform: translateZ(0);
-o-transform: translateZ(0);
transform: translateZ(0);
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-text-size-adjust: none;
-moz-text-size-adjust: none;
-ms-text-size-adjust: none;
-o-text-size-adjust: none;
text-size-adjust: none;
-webkit-backface-visibility: hidden;
}
.iscroll-row {
position: absolute;
}
@-webkit-keyframes lift {
0% {
box-shadow: 0px 5px 19px -11px #000044;
}
50% {
box-shadow: -2px 7px 17px -9px #000044;
}
100% {
box-shadow: 0px 5px 19px -11px #000044;
}
}
@keyframes lift {
0% {
box-shadow: 0px 5px 19px -11px #000044;
}
50% {
box-shadow: -2px 7px 17px -9px #000044;
}
100% {
box-shadow: 0px 5px 19px -11px #000044;
}
}
.make-row-switching() {
// styles for toggling last row header;
.rowGroups(@index) when (@index = 0) { // initial
@next: @index + 1;
@itemWeek: ~"[email protected]{index}.calendar-row-switching .calendar-mode-week [email protected]{index}.calendar-row-last";
@itemSeason:~"[email protected]{index}.calendar-row-switching .calendar-mode-season [email protected]{index}.calendar-row-last";
@itemUp: ~"[email protected]{index}.calendar-row-switching.calendar-scroll-up .calendar-mode-week [email protected]{index}.calendar-row-last";
@itemDown: ~"[email protected]{index}.calendar-row-switching.calendar-scroll-down .calendar-mode-week [email protected]{index}.calendar-row-last";
@item1: ~"@{itemWeek} .calendar-heading";
@item2: ~"@{itemWeek} .calendar-week";
@item3: ~"@{itemWeek} .calendar-season";
@item4: ~"@{itemWeek} .calendar-heading-year";
@item5: ~"[email protected]{index}.calendar-row-switching .calendar-mode-week [email protected]{next}.calendar-row-first .calendar-heading-year";
@item6: ~"@{item4} .glyphicon, @{item5} .glyphicon";
@item7: ~"@{itemUp} .calendar-heading-year";
@item8: ~"[email protected]{index}.calendar-row-switching.calendar-scroll-up .calendar-mode-week [email protected]{next}.calendar-row-first .calendar-heading-year";
@item9: ~"@{itemDown} .calendar-heading-year";
@item10: ~"[email protected]{index}.calendar-row-switching.calendar-scroll-down .calendar-mode-week [email protected]{next}.calendar-row-first .calendar-heading-year";
@item11: ~"@{itemSeason} .calendar-heading";
@item12: ~"@{itemSeason} .calendar-week";
@item13: ~"@{itemSeason} .calendar-season";
.rowGroups((@index + 1), @item1, @item2, @item3, @item4, @item5, @item6, @item7, @item8, @item9, @item10, @item11, @item12, @item13);
}
.rowGroups(@index, @list1, @list2, @list3, @list4, @list5, @list6, @list7, @list8, @list9, @list10, @list11, @list12, @list13) when (@index < 11) { // general; "=<" isn't a typo
@next: @index + 1;
@itemWeek: ~"[email protected]{index}.calendar-row-switching .calendar-mode-week [email protected]{index}.calendar-row-last";
@itemSeason:~"[email protected]{index}.calendar-row-switching .calendar-mode-season [email protected]{index}.calendar-row-last";
@itemUp: ~"[email protected]{index}.calendar-row-switching.calendar-scroll-up .calendar-mode-week [email protected]{index}.calendar-row-last";
@itemDown: ~"[email protected]{index}.calendar-row-switching.calendar-scroll-down .calendar-mode-week [email protected]{index}.calendar-row-last";
@item1: ~"@{itemWeek} .calendar-heading";
@item2: ~"@{itemWeek} .calendar-week";
@item3: ~"@{itemWeek} .calendar-season";
@item4: ~"@{itemWeek} .calendar-heading-year";
@item5: ~"[email protected]{index}.calendar-row-switching .calendar-mode-week [email protected]{next}.calendar-row-first .calendar-heading-year";
@item6: ~"@{item4} .glyphicon, @{item5} .glyphicon";
@item7: ~"@{itemUp} .calendar-heading-year";
@item8: ~"[email protected]{index}.calendar-row-switching.calendar-scroll-up .calendar-mode-week [email protected]{next}.calendar-row-first .calendar-heading-year";
@item9: ~"@{itemDown} .calendar-heading-year";
@item10: ~"[email protected]{index}.calendar-row-switching.calendar-scroll-down .calendar-mode-week [email protected]{next}.calendar-row-first .calendar-heading-year";
@item11: ~"@{itemSeason} .calendar-heading";
@item12: ~"@{itemSeason} .calendar-week";
@item13: ~"@{itemSeason} .calendar-season";
.rowGroups((@index + 1), ~"@{list1}, @{item1}", ~"@{list2}, @{item2}", ~"@{list3}, @{item3}", ~"@{list4}, @{item4}", ~"@{list5}, @{item5}", ~"@{list6}, @{item6}", ~"@{list7}, @{item7}", ~"@{list8}, @{item8}", ~"@{list9}, @{item9}", ~"@{list10}, @{item10}", ~"@{list11}, @{item11}", ~"@{list12}, @{item12}", ~"@{list13}, @{item13}");
}
.rowGroups(@index, @list1, @list2, @list3, @list4, @list5, @list6, @list7, @list8, @list9, @list10, @list11, @list12, @list13) when (@index = 11) { // general; "=<" isn't a typo
@next: 0;
@itemWeek: ~"[email protected]{index}.calendar-row-switching .calendar-mode-week [email protected]{index}.calendar-row-last";
@itemSeason:~"[email protected]{index}.calendar-row-switching .calendar-mode-season [email protected]{index}.calendar-row-last";
@itemUp: ~"[email protected]{index}.calendar-row-switching.calendar-scroll-up .calendar-mode-week [email protected]{index}.calendar-row-last";
@itemDown: ~"[email protected]{index}.calendar-row-switching.calendar-scroll-down .calendar-mode-week [email protected]{index}.calendar-row-last";
@item1: ~"@{itemWeek} .calendar-heading";
@item2: ~"@{itemWeek} .calendar-week";
@item3: ~"@{itemWeek} .calendar-season";
@item4: ~"@{itemWeek} .calendar-heading-year";
@item5: ~"[email protected]{index}.calendar-row-switching .calendar-mode-week [email protected]{next}.calendar-row-first .calendar-heading-year";
@item6: ~"@{item4} .glyphicon, @{item5} .glyphicon";
@item7: ~"@{itemUp} .calendar-heading-year";
@item8: ~"[email protected]{index}.calendar-row-switching.calendar-scroll-up .calendar-mode-week [email protected]{next}.calendar-row-first .calendar-heading-year";
@item9: ~"@{itemDown} .calendar-heading-year";
@item10: ~"[email protected]{index}.calendar-row-switching.calendar-scroll-down .calendar-mode-week [email protected]{next}.calendar-row-first .calendar-heading-year";
@item11: ~"@{itemSeason} .calendar-heading";
@item12: ~"@{itemSeason} .calendar-week";
@item13: ~"@{itemSeason} .calendar-season";
.rowGroups((@index + 1), ~"@{list1}, @{item1}", ~"@{list2}, @{item2}", ~"@{list3}, @{item3}", ~"@{list4}, @{item4}", ~"@{list5}, @{item5}", ~"@{list6}, @{item6}", ~"@{list7}, @{item7}", ~"@{list8}, @{item8}", ~"@{list9}, @{item9}", ~"@{list10}, @{item10}", ~"@{list11}, @{item11}", ~"@{list12}, @{item12}", ~"@{list13}, @{item13}");
}
.rowGroups(@index, @list1, @list2, @list3, @list4, @list5, @list6, @list7, @list8, @list9, @list10, @list11, @list12, @list13) when (@index > 11) { // terminal
@{list1} {
display: block;
}
@{list2} {
display: none;
}
@{list3} {
display: none;
}
@{list4} {
text-align: left;
bottom: 50%;
display: inline-block;
right: auto;
}
@{list5} {
text-align: left;
bottom: 50%;
display: inline-block;
right: auto;
}
@{list6} {
display: inline;
}
@{list7} {
display: none;
}
@{list8} {
-webkit-animation-name:fadeInDown;
animation-name:fadeInDown;
-webkit-animation-delay: .2s;
animation-delay: .2s;
-webkit-animation-duration: .3s;
animation-duration: .3s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
@{list9} {
-webkit-animation-name:fadeInUp;
animation-name:fadeInUp;
-webkit-animation-duration: .2s;
animation-duration: .2s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
@{list10} {
display: none;
}
@{list11} {
display: block;
}
@{list12} {
display: none;
}
@{list13} {
display: none;
}
}
.rowGroups(0); // kickstart it
}
.make-row-switching();
.calendar-row-switching .calendar.calendar-fixed.calendar-mode-season{
display: none;
}
.calendar-row-switching .calendar.calendar-fixed.calendar-mode-week .calendar-heading-month{
display: none;
}
.calendar-row-switching .calendar.calendar-fixed.calendar-mode-week .calendar-heading-days{
display: none;
}
.calendar-row-switching .calendar.calendar-fixed.calendar-mode-week,
.calendar-row-switching .calendar.calendar-fixed.calendar-mode-week .calendar-row:before,
.calendar-row-switching .calendar.calendar-fixed.calendar-mode-week .calendar-row{
background: transparent;
z-index: 0;
}
.calendar-row-switching .calendar.calendar-fixed.calendar-mode-week .calendar-heading{
box-shadow: none;
}
.calendar-row-switching .calendar.calendar-fixed.calendar-mode-week .calendar-heading-year{
-webkit-animation-name:fadeOut;
animation-name:fadeOut;
-webkit-animation-duration: .2s;
animation-duration: .2s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.calendar.calendar-fixed.calendar-mode-week .calendar-heading-year{
}
/**
* Solver for cubic bezier curve with implicit control points at (0,0) and (1.0, 1.0)
*/
function UnitBezier(p1x, p1y, p2x, p2y) {
// pre-calculate the polynomial coefficients
// First and last control points are implied to be (0,0) and (1.0, 1.0)
this.cx = 3.0 * p1x;
this.bx = 3.0 * (p2x - p1x) - this.cx;
this.ax = 1.0 - this.cx -this.bx;
this.cy = 3.0 * p1y;
this.by = 3.0 * (p2y - p1y) - this.cy;
this.ay = 1.0 - this.cy - this.by;
}
UnitBezier.prototype.epsilon = 1e-6; // Precision
UnitBezier.prototype.sampleCurveX = function(t) {
return ((this.ax * t + this.bx) * t + this.cx) * t;
}
UnitBezier.prototype.sampleCurveY = function (t) {
return ((this.ay * t + this.by) * t + this.cy) * t;
}
UnitBezier.prototype.sampleCurveDerivativeX = function (t) {
return (3.0 * this.ax * t + 2.0 * this.bx) * t + this.cx;
}
UnitBezier.prototype.solveCurveX = function (x, epsilon) {
var t0;
var t1;
var t2;
var x2;
var d2;
var i;
// First try a few iterations of Newton's method -- normally very fast.
for (t2 = x, i = 0; i < 8; i++) {
x2 = this.sampleCurveX(t2) - x;
if (Math.abs (x2) < epsilon)
return t2;
d2 = this.sampleCurveDerivativeX(t2);
if (Math.abs(d2) < epsilon)
break;
t2 = t2 - x2 / d2;
}
// No solution found - use bi-section
t0 = 0.0;
t1 = 1.0;
t2 = x;
if (t2 < t0) return t0;
if (t2 > t1) return t1;
while (t0 < t1) {
x2 = this.sampleCurveX(t2);
if (Math.abs(x2 - x) < epsilon)
return t2;
if (x > x2) t0 = t2;
else t1 = t2;
t2 = (t1 - t0) * .5 + t0;
}
// Give up
return t2;
}
// Find new T as a function of Y along curve X
UnitBezier.prototype.solve = function (x, epsilon) {
return this.sampleCurveY( this.solveCurveX(x, epsilon) );
}
// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
function calendarViewModel() {
this.loaded = ko.observable(false);
this.animate = ko.observable('animate');
this.currentDate = ko.observable(new moment());
this.scrollDate = ko.observable(new moment());
this.scroller;
this.rowItemIndex = 0;
this.rowDataIndex = 0;
this.rowPhaseIndex = 0;
this.mode = ko.observable();
this.month = this.currentDate().month();
this.year = this.currentDate().year();
this.scrollMonth = this.scrollDate().month();
this.scrollYear = this.scrollDate().year();
this.rows = [];
this.rowCount = 30;
this.rowTracker = ko.observable();
var calendar = this;
this.switchView = function(){
this.resetScroller(this.scrollDate());
rowsAsSeasons();
}
this.selectMonth = function(m){
this.resetScroller(m);
rowsAsWeeks();
}
this.resetScroller = function(m){
var index;
this.currentDate(m);
this.scrollToIndex(0);
this.scroller.refresh();
this.scrollDate(m);
this.rowItemIndex = 23;
this.rowDataIndex = -7;
this.rowPhaseIndex = 0;
}
this.animateIn = function(element){
$(element).addClass('animated fadeInLeft');
}
this.animateOut = function(element){
//$(element).addClass('animated fadeOutRight');
}
this.renderedRows = function(element){
if ($(element).parent().children().length === this.foreach.length) {
calendar.loaded(true);
}
}
this.update = function (iItem, iData, phase) {
var scrollDirection = '';
var rowCount = this.rows.length;
if (calendar.rowPhaseIndex < phase) {
scrollDirection = 'up';
calendar.rowItemIndex = iItem < (rowCount - 1) ? iItem + 1: 0;
calendar.rowDataIndex = iData - rowCount;
}
if (calendar.rowPhaseIndex > phase) {
scrollDirection = 'down';
calendar.rowItemIndex = iItem;
calendar.rowDataIndex = iData;
}
calendar.rowPhaseIndex = phase;
if (phase > 0) {
phase = Math.max(phase + 0, 0);
var mode = calendar.mode();
if(mode === 'calendar-mode-week'){
var monthCount = Math.floor(iData / 7);
var yearIndex = Math.floor(monthCount / 12);
var monthIndex = monthCount % 12;
var weekIndex = iData % 7;
//debugger;
var totalMonth = Math.floor(phase / 7);
totalMonth += calendar.month;
var phaseY = Math.floor(totalMonth / 12);
phaseY += calendar.year;
var phaseM = Math.floor(totalMonth % 12);
var phaseW = phase % 7;
if(phaseW < 6){
calendar.rowTracker('calendar-group-' + phaseM);
} else if(phaseW === 6){
calendar.rowTracker('calendar-group-' + phaseM + ' calendar-row-switching' + ' calendar-scroll-' + scrollDirection);
}
this.animate('');
var scrollPhaseDate = new moment().year(phaseY).month(phaseM);
//updateWeek(iItem, yearIndex, monthIndex, weekIndex);
this.scrollDate(scrollPhaseDate);
this.animate('');
}
if(mode === 'calendar-mode-season'){
var yearIndex = Math.floor(iData / 4);
var seasonIndex = iData % 4;
var phaseY = Math.floor(phase / 4);
phaseY += calendar.year;
var phaseS = Math.floor(phase % 4);
var yeargroup = phaseY % 10;
if(phaseS < 3){
calendar.rowTracker('calendar-group-' + yeargroup);
} else if(phaseS === 3){
calendar.rowTracker('calendar-group-' + yeargroup + ' calendar-row-switching' + ' calendar-scroll-' + scrollDirection);
}
this.animate('');
var scrollPhaseDate = new moment().year(phaseY);
//updateSeason(iItem, yearIndex, seasonIndex);
this.scrollDate(scrollPhaseDate);
this.animate('');
}
}
}
this.scrollToIndex = function (i) {
if (this.scroller instanceof IScroll) {
var indexH = (i * this.scroller.infiniteElementHeight);
this.scroller.scrollTo(0, -indexH);
setTimeout(function () {
calendar.scroller.refresh();
}, 500);
}
}
//this is the number of classes that are used for the scrollaway header
var maxRowGroups = 10;
calendar.currentDate.subscribe(function(newValue) {
calendar.month = newValue.month();
calendar.year = newValue.year();
});
calendar.scrollDate.subscribe(function(newValue) {
calendar.scrollMonth = newValue.month();
calendar.scrollYear = newValue.year();
});
function initScroll(view) {
var options, infinite, target;
options = {
scrollbars: false,
mouseWheel: true,
bounce: false,
interactiveScrollbars: false,
resizePolling: 100,
//deceleration: .01,
tap: true,
useDefaultPhase: false,
cacheSize: 60
};
target = '.iscroll-row';
if ((typeof jQuery == "function") && (typeof jQuery['find'] == "function")) {
options.infiniteElements = $(view).find(target);
} else {
options.infiniteElements = target;
}
//Called from iScroll to create array to add to the cache
options.dataset = function requestData(start, count) {
this.updateCache(start, []);
};
//Called from iScroll after element has phased to update the content of the element
options.dataFiller = function updateContent(iItem, iData, index) {
calendar.update(iItem, iData, this.options.getPhase.call(this));
}
options.getPhase = function getPhase() {
var center = -this.y + this.wrapperHeight / 2;
var minorPhase = -this.y / this.infiniteElementHeight;
var neg = 1;
if(minorPhase < 0){
neg = -1;
}
return Math.floor(minorPhase) * neg;
}
//Init the iscroll plugin
debugger;
var scroller = new IScroll(view, options);
return scroller;
}
function initRows(){
for(var i = 0; i < calendar.rowCount; i++){
calendar.rows[i] = {
type: ko.observable(),
css: ko.observable(''),
mode: ko.observable(''),
tracking: ko.observable(),
headerDate: ko.observable(),
date: ko.observable()
}
}
}
function getRate(i, iCount){
var t = i / iCount;
var curve = new UnitBezier(.25, .1, .25, 1);
var t1 = curve.solve(t, UnitBezier.prototype.epsilon);
var rate = 100 + (((iCount * .25) * 100) * t1);
return rate;
}
function rowsAsWeeks(){
calendar.animate('animate');
calendar.mode('calendar-mode-week');
var yearIndex = 0;
var monthIndex = 0;
var weekIndex = 0;
for(var i = 0; i < calendar.rows.length; i++){
var rowCount = calendar.rows.length;
var rowIndex = i + calendar.rowItemIndex;
if (rowIndex >= rowCount){
rowIndex = rowIndex - rowCount;
}
var iData = i + calendar.rowDataIndex;
var monthCount = Math.floor(iData / 7);
var yearIndex = Math.floor(monthCount / 12);
var monthIndex = monthCount % 12;
var weekIndex = iData % 7;
var rate = getRate(i, rowCount);
updateWeek(rowIndex, yearIndex, monthIndex, weekIndex, rate);
}
}
function updateWeek(rowIndex, yearIndex, monthIndex, weekIndex, rate){
var weekOffset = 1;
var row = calendar.rows[rowIndex];
var rowCount = calendar.rows.length;
var rowType;
var rowCSS;
var rowTracking;
var rowDate;
rate = rate || 0;
var groupName = (calendar.month + monthIndex) % 12;
if(weekIndex == 0){
rowType = 'heading';
rowCSS = 'calendar-row-first calendar-group-' + groupName;
rowTracking = rowCSS;
rowDate = new moment().year(calendar.year + yearIndex).month(calendar.month + monthIndex).date(1);
} else if(weekIndex < 6){
rowType = 'week';
rowCSS = 'calendar-group-' + groupName;
rowTracking = rowCSS;
rowDate = new moment().year(calendar.year + yearIndex).month(calendar.month + monthIndex).date(1 + ((weekIndex - weekOffset) * 7));
} else {
rowType = 'lastWeek';
rowCSS = 'calendar-row-last calendar-group-' + groupName;
rowTracking = rowCSS;
rowDate = new moment().year(calendar.year + yearIndex).month(calendar.month + monthIndex).date(1 + ((weekIndex - weekOffset) * 7));
}
var rowHeaderDate = new moment().year(calendar.year + yearIndex).month(calendar.month + monthIndex).date(1);
return updateRow(row, rowType, rowCSS, rowTracking, rowDate, rowHeaderDate, rate);
}
function rowsAsSeasons(){
calendar.animate('animate');
calendar.mode('calendar-mode-season');
var yearIndex = 0;
var seasonIndex = 0;
for(var i = 0; i < calendar.rows.length; i++){
var rowCount = calendar.rows.length;
var rowIndex = i + calendar.rowItemIndex;
if (rowIndex >= rowCount){
rowIndex = rowIndex - rowCount;
}
var iData = i + calendar.rowDataIndex;
var yearIndex = Math.floor(iData / 4);
var seasonIndex = iData % 4;
var rate = getRate(i, rowCount);
updateSeason(rowIndex, yearIndex, seasonIndex, rate);
}
}
function updateSeason(rowIndex, yearIndex, seasonIndex, rate){
var row = calendar.rows[rowIndex];
var rowCount = calendar.rows.length;
var rowType;
var rowCSS;
var rowTracking;
var rowDate;
rate = rate || 0;
var groupName = (calendar.year + yearIndex) % 10;
if(seasonIndex == 0){
rowType = 'heading';
rowCSS = 'calendar-row-first calendar-group-' + groupName;
rowTracking = rowCSS;
rowDate = new moment().year(calendar.year + yearIndex).month(0);
} else if(seasonIndex < 3){
rowType = 'season';
rowCSS = 'calendar-group-' + groupName;
rowTracking = rowCSS;
rowDate = new moment().year(calendar.year + yearIndex).month((seasonIndex - 1) * 4);
} else {
rowType = 'lastSeason';
rowCSS = 'calendar-row-last calendar-group-' + groupName;
rowTracking = rowCSS;
rowDate = new moment().year(calendar.year + yearIndex).month((seasonIndex - 1) * 4);
}
var rowHeaderDate = new moment().year(calendar.year + yearIndex).month(0);
return updateRow(row, rowType, rowCSS, rowTracking, rowDate, rowHeaderDate, rate);
}
function updateRow(row, rowType, rowCSS, rowTracking, rowDate, rowHeaderDate, rate){
row.type.extend({ rateLimit: rate});
row.css.extend({ rateLimit: rate });
row.tracking.extend({ rateLimit: rate });
row.date.extend({ rateLimit: rate });
row.headerDate.extend({ rateLimit: rate });
row.mode.extend({ rateLimit: rate - 100 });
row.type(rowType);
row.css(rowCSS);
row.tracking(rowTracking);
row.headerDate(rowHeaderDate);
row.date(rowDate);
row.mode(calendar.mode());
return rowDate;
}
initRows();
rowsAsWeeks();
var ko_unwrap = ko.utils.unwrapObservable;
ko.bindingHandlers['iscroll'] = {
'update': function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var loaded = valueAccessor();
if(typeof calendar.scroller == 'undefined'){
if(loaded()){
calendar.scroller = initScroll(element);
}
} else {
setTimeout(function () {
calendar.scroller.refresh();
}, 0);
}
}
};
}
// Activates knockout.js
ko.applyBindings(new calendarViewModel());
Also see: Tab Triggers