Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                #calendar
  h1 Print yourself a calendar
  p.
    Mark it every time you do that thing you promised yourself.
    <br><a href="http://lifehacker.com/281626/jerry-seinfelds-productivity-secret">Build a habit, like Seinfeld did</a>.
  form
    p
      label
        span Year
        input(type="number" min="999" max="9999" required autofocus v-model="year")
    p
      button(type="button" v-on:click="year = year - 1") −
      button(type="button" v-on:click="year = 1 + year") +
      button(type="button" v-on:click="year = currentYear") {{ currentYear }}
    p
      button(type="button" v-on:click="getPDF()").is-wide Get calendar
  p <a href="http://luminarious.net">a luminarious design</a>


              
            
!

CSS

              
                // Variables
$spacing = 0.5rem
color = {
  background: #FFF
  text: #666
  accent: #F06
}
*
  box-sizing: border-box
html,
body
  padding: 0
  margin: 0
body
  height: 100vh
  display: flex
  align-items: center
  justify-content: center
  font-family: sans-serif
button,
input
  padding: 1rem
  width: 100%
  font-size: inherit

// Elements
#calendar
  background-color: color.background
  color: color.text
  max-width: 30em

h1
  font-size: 2rem
  
button,
input,
select,
textarea
  border: 2px solid color.text

button
  cursor: pointer
  color: color.accent
  background-color: transparent
  text-transform: lowercase
  &:focus,
  &:hover
    background-color: #EEE
    
a
  color: color.accent
  &:hover
    color: #000
  
form
  p
    display: flex
  button,
  label
    flex: 1
  button:not(:first-child)
    margin-left: 1rem

input
  color: #000
  &:invalid
    border-color: color.accent
    
// Classes
.is-wide
  flex: 2
              
            
!

JS

              
                const makecalendar = function(year) {
  const doc = new window['jsPDF']('landscape', 'mm', 'a4')
  doc['setFontSize'](12)
  doc['setFont']("helvetica", "bold")
  doc['setTextColor'](160)

  for (var x = 30, y = 30, month = 0; month <= 12; x = 30, y += 12, month++) {
    if (month == 0) { //First row is the year
      for (let i = 0; i < 4; i++, x += 6.3) {
        const YYYY = year.toString()
        doc['text'](x, y, YYYY[i])
      }
    } else { // Then come the actual months
      const daysInMonth = new Date(year, month, 0).getDate()

      for (let day = 1; day <= daysInMonth; day++) {
        const weekday = new Date(year, month - 1, day - 1).getDay()
        const DD = day.toString()

        doc['setTextColor'](weekday == 5 || weekday == 6 ? 100 : 160)
        doc['text'](x, y, DD)

        ;(day < 10) ? x += 6.3: x += 8.2
      }
    }
  }
  return doc
}

const app = {
  el: '#calendar',
  data: {
    currentYear: new Date().getFullYear(),
    year: new Date().getFullYear()
  },
  methods: {
    getPDF() {
      const year = this.year
      const doc = makecalendar(year)
      doc['save']('Calendar ' + year + ' (A4).pdf')
        //doc['output']('dataurlnewwindow')
    }
  }
}

document.onreadystatechange = () => {
  if (document.readyState == "interactive") {
    new Vue(app)
  }
}
              
            
!
999px

Console