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

Auto Save

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

              
                .wrapper
  %form
    %select.custom-date{name: 'select'}
      %option{value: 7} 7 Days
      %option{value: 30} 30 Days
      %option{value: 90, selected: true} 90 Days
      %option{value: 180} 180 Days
      %option{value: 365} 365 Days
      %option{id: 'custom'} Custom

              
            
!

CSS

              
                @import compass

@mixin reset
  // https://meyerweb.com/eric/tools/css/reset/ 
  // v2.0 | 20110126
  // License: none (public domain)
  html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6,
  p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del,
  dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt,
  var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label,
  legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside,
  canvas, details, embed, figure, figcaption, footer, header, hgroup,
  menu, nav, output, ruby, section, summary, time, mark, audio, video
    margin: 0
    padding: 0
    border: 0
    font-size: 100%
    font: inherit
    vertical-align: baseline
  // HTML5 display-role reset for older browsers
  article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section
    display: block
  body
    line-height: 1
  ol, ul
    list-style: none
  blockquote, q
    quotes: none
  blockquote:before, blockquote:after, q:before, q:after
    content: ''
    content: none
  table
    border-collapse: collapse
    border-spacing: 0
@mixin unselectable
  -moz-user-select: -moz-none
  -khtml-user-select: none
  -webkit-user-select: none
  -ms-user-select: none
  user-select: none
@mixin clearfloat
  &:before, &:after
    content: ""
    display: table
  &:after
    clear: both
  zoom: 1
@mixin border-box
  -moz-box-sizing: border-box
  -webkit-box-sizing: border-box
  box-sizing: border-box
  *, *:before, *:after
    -moz-box-sizing: border-box
    -webkit-box-sizing: border-box
    box-sizing: border-box


html, body
  margin: 0
  padding: 0
  height: 100%
.wrapper
  padding: 12px
select
  -webkit-appearance: menulist-button
  width: 200px
  height: 25px
.drp-popup
  font-family: "AvenirLTStd-Heavy", "Avenir LT Std 85 Heavy", "Open Sans", Helvetica, Arial, sans-serif

$outer-border-color: #d6d6d6
$outer-box-shadow: 0px 4px 10px 0 #828282

$bgcolor: #FFFFFF
$text-color: #444444
$border-color: #e0e0e0
$inactive-color: #e0e0e0
$selected-color: #2a91ca
$in-range-bgcolor: #ddf3fe
$preset-label-color: #bcbcbc
$month-picker-arrow-color: #afafaf

$light-gray: #cccccc
$lighter-gray: #efefef

$day-width: 30px
$day-height: 24px
$day-spacing: 3px

$calendar-width: ($day-width * 7) + ($day-spacing * 6)


.drp-popup
  top: 30px
  @include border-box
  // display: none
  position: absolute
  z-index: 9999
  font-size: 12px
  color: $text-color
  background-color: $bgcolor
  margin: 15px 0
  padding: 18px 18px 38px
  text-transform: uppercase
  border: 1px solid $outer-border-color
  -webkit-border-radius: 12px
  -moz-border-radius: 12px
  border-radius: 12px
  -webkit-box-shadow: $outer-box-shadow
  -moz-box-shadow: $outer-box-shadow
  box-shadow: $outer-box-shadow
  a
    text-decoration: none
  ul
    list-style: none
    padding: 0
    margin: 0
  .drp-timeline
    position: relative
    .drp-timeline-bar
      position: relative
      height: 13px
      border-bottom: 3px solid $light-gray
      bottom: 21px
      &:before, &:after
        content: ''
        position: absolute
        height: 15px
        border-left: 3px solid $light-gray
        bottom: -9px
        left: 0
      &:after
        left: auto
        right: 0
    .drp-timeline-presets
      position: relative
      z-index: 1
      li
        position: relative
        width: 87px
        height: 36px
        display: inline-block
        color: $preset-label-color
        // IE8 has issues with mousehover when there is no bg color, and
        //  "background-color: transparent" doesn't work. I hate you IE8.
        background-image: url('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==')
        text-align: center
        cursor: pointer
        &:first-child
          margin-left: 3px
        .drp-button
          z-index: 2
          cursor: pointer
          background-color: $border-color
          width: 12px
          height: 12px
          position: absolute
          bottom: 4px
          left: 37px
          -webkit-border-radius: 50%
          -moz-border-radius: 50%
          border-radius: 50%
          border: 2px solid $bgcolor
          -webkit-transition: all 0.15s ease
          -moz-transition: all 0.15s ease
          -o-transition: all 0.15s ease
          transition: all 0.15s ease
        &.drp-selected
          color: $text-color
        &.drp-selected .drp-button, &:hover .drp-button
          background-color: $selected-color
          width: 16px
          height: 16px
          left: 35px
          bottom: 2px
  .drp-calendar
    display: table-cell
    vertical-align: top
    width: $calendar-width
    padding-bottom: 8px
    border-bottom: 1px solid $border-color
    .drp-month-picker
      position: relative
      background-color: $lighter-gray
      height: 30px
      -webkit-border-radius: 20px
      -moz-border-radius: 20px
      border-radius: 20px
      margin-bottom: 3px
      line-height: 32px
      .drp-month-title
        font-size: 14px
        text-align: center
      .drp-arrow
        @include unselectable
        cursor: pointer
        position: absolute
        width: 28px
        height: 30px
        line-height: 32px
        text-align: center
        left: 0
        top: 0
        color: $month-picker-arrow-color
      .drp-arrow-right
        left: auto
        right: 0px
    .drp-day-headers
      li
        display: inline-block
        width: $day-width
        height: $day-height
        line-height: 26px
        margin: 0 0 $day-spacing $day-spacing
        text-align: center
        &:first-child
          margin-left: 0
    .drp-days
      @include clearfloat
      li
        @include unselectable
        width: $day-width + $day-spacing
        height: $day-height
        border-right: solid $day-spacing $bgcolor
        float: left
        cursor: pointer
        line-height: 26px
        text-align: center
        margin: 0 0 $day-spacing 0
        &.drp-day-last-in-row
          width: $day-width
          border-right: none
        &.drp-day-in-range
          color: $selected-color
          background-color: $in-range-bgcolor
          border-color: $in-range-bgcolor
        &.drp-day-last-in-range
          border-color: $bgcolor
        &.drp-day-selected, &:hover
          color: $lighter-gray
          background-color: $selected-color
        &.drp-day-disabled
          color: $light-gray
          &:hover
            background-color: $bgcolor
            cursor: default
      .drp-day-empty
        background-color: transparent !important
        cursor: auto
  .drp-calendars
    padding: 18px 0 10px
    border-top: 1px solid $border-color
  .drp-calendar:first-child
    .drp-day-selected
      border-color: $in-range-bgcolor

  .drp-calendar-date
    position: absolute
    bottom: 0px
    height: 34px
    width: inherit
    text-align: center
    color: $selected-color
    font-size: 16px
    &:before
      font-size: 12px
      color: $text-color
  .drp-calendar-start
    .drp-calendar-date:before
      content: 'Start Date: '
  .drp-calendar-end
    .drp-calendar-date:before
      content: 'End Date: '

  .drp-calendar-separator
    display: table-cell
    position: relative
    width: 69px
    top: 8px
    &:before
      content: ''
      position: absolute
      height: 90%
      border-left: 1px solid $border-color
      left: 34px
    &:after
      content: 'To'
      position: absolute
      top: 80px
      color: $selected-color
      background-color: $bgcolor
      height: 38px
      width: 69px
      text-align: center
      font-size: 16px
      line-height: 41px
  .drp-tip
    position: absolute
    top: 0
    left: 30px
    &:before, &:after
      content: ""
      position: absolute
      border-style: solid
      bottom: 0
    &:before
      left: 0
      border-width: 0 16px 16px
      border-color: $outer-border-color transparent
    &:after
      left: 2px
      border-width: 0px 14px 14px
      border-color: $bgcolor transparent

              
            
!

JS

              
                $ = jQuery
DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
TEMPLATE = """
  <div class="drp-popup">
    <div class="drp-timeline">
      <ul class="drp-timeline-presets"></ul>
      <div class="drp-timeline-bar"></div>
    </div>
    <div class="drp-calendars">
      <div class="drp-calendar drp-calendar-start">
        <div class="drp-month-picker">
          <div class="drp-arrow"><</div>
          <div class="drp-month-title"></div>
          <div class="drp-arrow drp-arrow-right">></div>
        </div>
        <ul class="drp-day-headers"></ul>
        <ul class="drp-days"></ul>
        <div class="drp-calendar-date"></div>
      </div>
      <div class="drp-calendar-separator"></div>
      <div class="drp-calendar drp-calendar-end">
        <div class="drp-month-picker">
          <div class="drp-arrow"><</div>
          <div class="drp-month-title"></div>
          <div class="drp-arrow drp-arrow-right">></div>
        </div>
        <ul class="drp-day-headers"></ul>
        <ul class="drp-days"></ul>
        <div class="drp-calendar-date"></div>
      </div>
    </div>
    <div class="drp-tip"></div>
  </div>
"""

class DateRangePicker
  constructor: (@$select) ->
    @$dateRangePicker = $(TEMPLATE)
    @$select
      .attr('tabindex', '-1')
      .before @$dateRangePicker
    @isHidden = true
    @customOptionIndex = @$select[0].length-1
    @initBindings()
    @setRange @$select.val()

  initBindings: ->
    self = @
    # Prevent the select dropdown from appearing
    @$select.on 'focus mousedown', (e) ->
      $select = @
      setTimeout ->
        $select.blur()
      , 0
      return false
    # show/hide logic for the popup
    @$dateRangePicker.click (evt) ->
      evt.stopPropagation()
    $('body').click (evt) ->
      if evt.target == self.$select[0] && self.isHidden
        self.show()
      else if !self.isHidden
        self.hide()

    # Timeline buttons
    @$select.children().each ->
      self.$dateRangePicker.find('.drp-timeline-presets').append $("<li class='#{(@.selected && 'drp-selected') || ''}'>#{$(@).text()}<div class='drp-button'></div></li>")
    @$dateRangePicker.find('.drp-timeline-presets li').click (evt) ->
      $(@).addClass('drp-selected').siblings().removeClass('drp-selected')
      presetIndex = $(@).index()
      self.$select[0].selectedIndex = presetIndex
      self.setRange self.$select.val()
      self.showCustomDate() if presetIndex == self.customOptionIndex
  hide: ->
    @isHidden = true
    @$dateRangePicker.hide()
  show: ->
    @isHidden = false
    @$dateRangePicker.show()
  showCustomDate: ->
    @$dateRangePicker.find('.drp-timeline-presets li:last-child').addClass('drp-selected').siblings().removeClass('drp-selected')
    text = @formatDate(@startDate()) + ' - ' + @formatDate(@endDate())
    @$select.find('option:last-child').text text
    @$select[0].selectedIndex = @customOptionIndex
  formatDate: (d) ->
    "#{d.getMonth() + 1}/#{d.getDate()}/#{d.getFullYear().toString().substr(2,2)}"
  setRange: (daysTo) ->
    return false if isNaN daysTo
    # daysTo += 1

    endDate = new Date()
    startDate = new Date()
    # console.log(startDate.getDate())
    endDate.setTime(startDate.getTime() + daysTo*86400*1000)
    @startCalendar = new Calendar(@, @$dateRangePicker.find('.drp-calendar:first-child'), startDate, true)
    @endCalendar = new Calendar(@, @$dateRangePicker.find('.drp-calendar:last-child'), endDate, false)
    @draw()
  endDate: ->
    @endCalendar.date
  startDate: ->
    @startCalendar.date
  draw: ->
    @startCalendar.draw()
    @endCalendar.draw()


class Calendar
  constructor: (@dateRangePicker, @$calendar, @date, @isStartCalendar) ->
    self = @
    @date.setHours(0,0,0,0)
    @_visibleMonth = @month()
    @_visibleYear = @year()
    @$title = @$calendar.find('.drp-month-title')
    @$dayHeaders = @$calendar.find('.drp-day-headers')
    @$days = @$calendar.find('.drp-days')
    @$dateDisplay = @$calendar.find('.drp-calendar-date')
    @$calendar.find('.drp-arrow').click (evt) ->
      if $(@).hasClass('drp-arrow-right') then self.showNextMonth() else self.showPreviousMonth()
      return false
  showPreviousMonth: ->
    if @_visibleMonth == 1
      @_visibleMonth = 12
      @_visibleYear -= 1
    else
      @_visibleMonth -= 1
    @draw()
  showNextMonth: ->
    if @_visibleMonth == 12
      @_visibleMonth = 1
      @_visibleYear += 1
    else
      @_visibleMonth += 1
    @draw()
  setDay: (day) ->
    @setDate(@visibleYear(), @visibleMonth(), day)
    @dateRangePicker.showCustomDate()
  setDate: (year, month, day) ->
    @date = new Date(year, month - 1, day)
    @dateRangePicker.draw()
  draw: ->
    @$dayHeaders.empty()
    # set month name
    @$title.text "#{@nameOfMonth(@visibleMonth())} #{@visibleYear()}"
    # populate day headers
    @$dayHeaders.append($("<li>#{day.substr(0,2)}</li>")) for day in DAYS
    @drawDateDisplay()
    @drawDays()
  dateIsSelected: (date) ->
    date.getTime() == @date.getTime()
  dateIsInRange: (date) ->
    date >= @dateRangePicker.startDate() && date <= @dateRangePicker.endDate()
  dayClass: (day, firstDayOfMonth, lastDayOfMonth) ->
    date = new Date(@visibleYear(), @visibleMonth()-1, day)
    classes = ''
    if @dateIsSelected(date)
      classes = 'drp-day-selected'
    else if @dateIsInRange(date)
      classes = 'drp-day-in-range'
      if date.getTime() == @dateRangePicker.endDate().getTime()
        classes += ' drp-day-last-in-range'
    else if @isStartCalendar
      if date > @dateRangePicker.endDate()
        classes += ' drp-day-disabled'
    else if date < @dateRangePicker.startDate()
      classes += ' drp-day-disabled'
    if (day+firstDayOfMonth-1)%7 == 0 || day == lastDayOfMonth
      classes += ' drp-day-last-in-row'

    return classes
  drawDays: ->
    self = @
    @$days.empty()
    firstDayOfMonth = @firstDayOfMonth(@visibleMonth(), @visibleYear())
    lastDayOfMonth = @daysInMonth(@visibleMonth(), @visibleYear())
    @$days.append($("<li class='drp-day drp-day-empty'></li>")) for i in [1..firstDayOfMonth-1] by 1
    @$days.append($("<li class='drp-day #{@dayClass(i,firstDayOfMonth,lastDayOfMonth)}'>#{i}</li>")) for i in [1..lastDayOfMonth] by 1
    @$calendar.find('.drp-day').click (evt) ->
      return false if $(@).hasClass('drp-day-disabled')
      day = parseInt($(@).text(), 10)
      return false if isNaN(day)
      self.setDay(day)
  drawDateDisplay: ->
    @$dateDisplay.text [@month(), @day(), @year()].join('/')
  month: ->
    @date.getMonth() + 1
  day: ->
    @date.getDate()
  dayOfWeek: ->
    @date.getDay() + 1
  year: ->
    @date.getFullYear()
  visibleMonth: ->
    @_visibleMonth
  visibleYear: ->
    @_visibleYear
  nameOfMonth: (month) ->
    MONTHS[month-1]
  firstDayOfMonth: (month, year) ->
    new Date(year, month - 1, 1).getDay() + 1
  daysInMonth: (month, year) ->
    month ||= @visibleMonth()
    year ||= @visibleYear()
    new Date(year, month, 0).getDate()

$.fn.dateRangePicker = ->
  new DateRangePicker(@)

$('.custom-date').dateRangePicker()

              
            
!
999px

Console