项目作者: FreddyFY

项目描述 :
Material Datepicker
高级语言: JavaScript
项目地址: git://github.com/FreddyFY/material-datepicker.git
创建时间: 2015-10-12T19:52:28Z
项目社区:https://github.com/FreddyFY/material-datepicker

开源协议:MIT License

下载


material-datepicker

Demo

Demo Page

Usage

Include the JavaScript file and Stylesheet in your html page.
This plugin works with moment.js.
There are two methods to include the Material-Datepicker.

Method 1
When you have included moment.js already.

  1. <script type="text/javascript" src="https://momentjs.com/downloads/moment-with-locales.min.js"></script>
  2. <link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/FreddyFY/material-datepicker/1.0.9/dist/material-datepicker.css">
  3. <script type="text/javascript" src="https://cdn.rawgit.com/FreddyFY/material-datepicker/1.0.9/dist/material-datepicker.min.js"></script>

Method 2
When you don’t need moment.js itself.

  1. <link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/FreddyFY/material-datepicker/1.0.9/dist/material-datepicker.css">
  2. <script type="text/javascript" src="https://cdn.rawgit.com/FreddyFY/material-datepicker/1.0.9/dist/material-datepicker-with-moment-js.min.js"></script>

It’s better to download the files, instead of using the rawgit cdn server.


In its simplest case, Material-Picker can be initialised with a single line of Javascript.
You will probably also specify some options while applying the plugin.

  1. var monthpicker = new MaterialDatepicker('input');
  2. var monthpicker = new MaterialDatepicker('input', {
  3. type: 'month',
  4. lang: 'de',
  5. orientation: 'portrait'
  6. });

Options

  • type (default: “date”) [string] - Datepicker[“date”], Monthpicker[“month”]
  • lang (default: “en”) [string] - Language
  • orientation (default: “landscape”) [string] - Orientation of the picker: portait or landscape
  • color (default: “#80cbc4”) [string] - Color of the picker; Html color values
  • zIndex (default: “100”) [number] - z-index of the picker
  • position (default: “absolute”) [string] - position of the picker [fixed, static, ..]
  • theme (default: “light”) [string] - Theme of the picker: light or dark
  • openOn (default: “click”) [string] - How to open the picker: Click-events or ‘direct’
  • closeAfterClick (default: true) [string] - Close the picker after choose a date or not

  • date (default: today or string inside input) [type: Date Object] - The initial date of the Picker

  • weekBegin (default: “sunday”) [string] - Beginning weekday of the week: sunday or monday
  • outputFormat (default: date “YYYY/MM/DD”; month “MMMM YYYY”) [string] - Date-format* of the output [inside a input or OutputElement]
  • inputFormat (default: date “YYYY/MM/DD”; month “MMMM YYYY”) [string] - Date-format* of the input value attribute [in the inputElement]
  • topHeaderFormat (default: “YYYY”) [string] - Date-format* of the output [inside a input or OutputElement]
  • headerFormat (default: date “ddd, MMM D”; month “MMMM”) [string] - Date format in the header bar
  • sitePickerFormat (default: date “MMMM YYYY”; month “YYYY”) [string] - Date format in the site picker bar

  • onLoad (default: none) [function] - Function called when picker is loaded

  • onOpen (default: none) [function] - Function called when picker is open
  • onNewDate (default: none) [function] - Function called when new Date is picked and the picker is closed
  • onChange (default: none) [function] - Function called when the Date is changed, even if the picker is still open
  • outputElement (default: none) [string or Object] - Returns the date inside a SPAN-tag, P-tag or A-Tag

Example

  1. var monthpicker = new MaterialDatepicker('input', {
  2. lang: 'de',
  3. orientation: 'portrait',
  4. theme: 'dark',
  5. color: 'red',
  6. date: new Date(861999834000),
  7. outputFormat: 'd-mm-yyyy',
  8. inputFormat: 'ddmmyyyy',
  9. outputElment: '.month',
  10. onChange: function() {
  11. alert('Date Changed!!')
  12. },
  13. onNewDate: function() {
  14. alert('New Date Chosen!!')
  15. }
  16. });

API

.open()

.close()

.newDate( new Date(861999834000) ) set new Date

.date returns the current date

.element returns the choosen element

.picker returns the picker element

Building from source

  1. Clone the repository
    • git clone https://github.com/FreddyFY/material-datepicker.git
  2. Install dependencies
    • npm install
  3. Run grunt watch for development
    • npm start
  4. Run default grunt before a Pull Request
    • npm run build
  5. Output is in dist/