pickadate

http://amsul.ca/pickadate.js/api

http://amsul.ca/pickadate.js/api/#method-get-disable

The API§

You can play with the picker API to extend and create custom functionality:

var $input = $(‘.datepicker‘).pickadate()

// Use the picker object directly.
var picker = $input.pickadate(‘picker‘)
picker.methodName(argument1, argument2, ...)
picker.objectName

// Or pass through the element’s plugin data.
$input.pickadate(methodName, argument1, argument2, ...)
$input.pickadate(objectName)

For most examples on this page, the date picker is used, but the same API applies to the time picker as well.

Methods§

There are eleven methods available on the picker:

  1. open
  2. close
  3. start
  4. stop
  5. render
  6. clear
  7. get
  8. set
  9. on
  10. off
  11. trigger

All these methods (except get) return the picker object and are therefore chainable:

picker.open().clear().close()...

Objects§

There are four objects available through the picker:

  1. $node
  2. $root
  3. _hidden
  4. component

The Methods§

Open and Close§

Open and close the picker holder. To check if it’s already open, use the get method.

picker.open()
picker.close()

// If a “click” is involved, prevent the event bubbling.
event.stopPropagation()

// If we want to maintain focus on the input,
// prevent the default action on “mousedown”.
event.preventDefault()

Close with focus§

Close the picker while keeping focus on the input element by passing a truth-y argument.

picker.close(true)

Open without focus§

Open the picker without focusing onto the input element by passing false as the first argument. Opening the picker this way, there’s a few things to note:

(1) The only way to close it is with a separate custom binding – in this example, on document click.

(2) The “opening” events are still triggered – however, using the get method to see if the picker is open will return false.

(3) If any of the picker elements is focused/clicked, it resumes normal behavior.

picker.open(false)
$(document).on(‘click‘, function() {
  picker.close()
})

Start and Stop§

Destroy and rebuild the picker. To check if it’s already started, use the get method.

picker.stop()
picker.start()

Destroying the picker also clears any events’ callbacks bound on it.

Render§

Refresh the picker after adding something to the holder.

picker.render()

By default, only the “face” of the picker (i.e. the box element), has it’s contents re-rendered. To render the entire picker from the root up, pass true as the first argument:

picker.render(true)

Clear§

Clear the value in the picker’s input element.

picker.clear()

This is a shorthand that uses the set method behind the scenes.

Get§

Get the properties, objects, and states of the picker.

picker.get(thing)

The thing argument is an optional string and can be one of the following:

* Item Objects§

The things denoted in the list above with an asterisk (*) return a picker item object that can be formatted by passing a second string argument using the date or time formatting rules:

picker.get(thing, format)

Each “date” or “time” within the picker has an item object accompanying it behind the scenes.

Here’s a date picker item object for 20 April, 2015:

{
  // The full year.
  year: 2015,

  // The month with zero-as-index.
  month: 3,

  // The date of the month.
  date: 20,

  // The day of the week with zero-as-index.
  day: 1,

  // The underlying JavaScript Date object.
  obj: "Mon, 20 Apr 2015 00:00:00 EDT",

  // The “pick” value used for comparisons.
  pick: 1429502400000
}

Here’s a time picker item object for 4:20 PM:

{
  // Hour of the day from 0 to 23.
  hour: 16,

  // The minutes of the hour from 0 to 59 (based on the interval).
  mins: 20,

  // The “pick” value used for comparisons.
  pick: 980
}

Get value§

Returns the string value of the picker’s input element.

picker.get() // Short for `picker.get(‘value‘)`.

Get select§

Returns the item object or formatted string of the date that is visually selected.

Defaults to null when there’s no value.

picker.get(‘select‘)
picker.get(‘select‘, ‘yyyy/mm/dd‘)

Get highlight§

Returns the item object or formatted string of the date that is visually highlighted.

Defaults to “today” (or “now” for the time picker) when there’s no value.

picker.get(‘highlight‘)
picker.get(‘highlight‘, ‘yyyy/mm/dd‘)

Get view§

Returns the item object or formatted string of the date that determines the current view.

Defaults to the first day of the current month (or “now” for the time picker) when there’s no value.

picker.get(‘view‘)
picker.get(‘view‘, ‘yyyy/mm/dd‘)

Get min§

Returns the item object or formatted string of the date that determines the lower limit.

Defaults to a -Infinity item object when it is not explicitly set in the options or through the picker’s API.

picker.get(‘min‘)
picker.get(‘min‘, ‘yyyy/mm/dd‘)

Get max§

Returns the item object or formatted string of the date that determines the upper limit.

Defaults to an Infinity item object when it is not explicitly set in the options or through the picker’s API.

picker.get(‘max‘)
picker.get(‘max‘, ‘yyyy/mm/dd‘)

Get open§

Returns a boolean value of whether the picker is open or not.

picker.get(‘open‘)

Get start§

Returns a boolean value of whether the picker has started or not.

picker.get(‘start‘)

Get id§

Returns a unique string that is the ID of the picker and it’s element. If the element has no ID, it is set to something random.

picker.get(‘id‘)

Get disable and enable§

Both these things work together to determine which item objects to disable on the picker:

// Array passed in options to disable dates
var datesToDisable = [ 1, 4, 7, [2015,3,8], [2015,3,19], new Date(2015,3,26) ]

// Returns `1` to represent a base “enabled” state
picker.get(‘enable‘)

// Returns the collection of dates to disable
picker.get(‘disable‘)

However, when all dates are disabled and a select few are enabled, it behaves differently:

// Array passed in options to disable all dates except a few
var datesToDisable = [ true, 1, 4, 7, [2015,3,8], [2015,3,19], new Date(2015,3,26) ]

// Returns `-1` to represent a base “flipped” state
picker.get(‘enable‘)

// Returns the collection of dates to *not* disable
picker.get(‘disable‘)

Set§

Set the properties, objects, and states of the picker.

// One at a time
picker.set(thing, value)

// Multiple at once
picker.set({
  thing: value,
  thing: value,
  thing: value
})

The value is based on the thing being set. The thing, is a string that can be:

* cascading changes§

When the things denoted in the list above with an asterisk (*) are set, they cascade into updating other things using the same value.

muted callbacks§

By default, any callbacks bound with the on method will be fired when it’s relevant thing is set. To silenty set a thing, pass an options object with the muted parameter set to true:

// One at a time
picker.set(thing, value, { muted: true })

// Multiple at once
picker.set({
  thing: value,
  thing: value,
  thing: value
}, { muted: true })

Set clear§

Clear the value in the picker’s input element.

picker.set(‘clear‘)

This is the full form of the clear method.

Set select§

Setting select has cascading changes that update the highlight, the view, and the value of the input element based on the settings format.

Select a date item object§

// Using arrays formatted as [YEAR, MONTH, DATE].
picker.set(‘select‘, [2015, 3, 20])

// Using JavaScript Date objects.
picker.set(‘select‘, new Date(2015, 3, 30))

// Using positive integers as UNIX timestamps.
picker.set(‘select‘, 1429970887654)

// Using a string along with the parsing format (defaults to `format` option).
picker.set(‘select‘, ‘2016-04-20‘, { format: ‘yyyy-mm-dd‘ })

Select a time item object§

// Using arrays formatted as [HOUR,MINUTE].
picker.set(‘select‘, [3,0])

// Using JavaScript Date objects.
picker.set(‘select‘, new Date(2015, 3, 20, 10, 30))

// Using positive integers as minutes.
picker.set(‘select‘, 540)

// Using a string along with the parsing format (defaults to `format` option).
picker.set(‘select‘, ‘04-30‘, { format: ‘hh-i‘ })

Set highlight§

Setting highlight has a cascading change that updates the item object that sets the view of the picker.

Highlight a date item object§

// Using arrays formatted as [YEAR, MONTH, DATE].
picker.set(‘highlight‘, [2015, 3, 20])

// Using JavaScript Date objects.
picker.set(‘highlight‘, new Date(2015, 3, 30))

// Using positive integers as UNIX timestamps.
picker.set(‘highlight‘, 1429970887654)

// Using a string along with the parsing format (defaults to `format` option).
picker.set(‘highlight‘, ‘2016-04-20‘, { format: ‘yyyy-mm-dd‘ })

Highlight a time item object§

// Using arrays formatted as [HOUR,MINUTE].
picker.set(‘highlight‘, [15,30])

// Using JavaScript Date objects.
picker.set(‘highlight‘, new Date(2015, 3, 20, 10, 30))

// Using positive integers as minutes.
picker.set(‘highlight‘, 1080)

// Using a string along with the parsing format (defaults to `format` option).
picker.set(‘highlight‘, ‘04-30‘, { format: ‘hh-i‘ })

Set view§

Setting view has no cascading changes and the highlight remains unaffected.

Viewset a date item object§

The value passed gets normalized to the first date of the month to bring into view.

// Using arrays formatted as [YEAR,MONTH,DATE].
picker.set(‘view‘, [2000,3,20])

// Using JavaScript Date objects.
picker.set(‘view‘, new Date(1988,7,14))

// Using positive integers as UNIX timestamps.
picker.set(‘view‘, 1587355200000)

// Using a string along with the parsing format (defaults to `format` option).
picker.set(‘view‘, ‘2016-04-20‘, { format: ‘yyyy-mm-dd‘ })

Viewset a time item object§

// Using arrays formatted as [HOUR,MINUTE].
picker.set(‘view‘, [15,30])

// Using JavaScript Date objects.
picker.set(‘view‘, new Date(2015, 3, 20, 10, 30))

// Using positive integers as minutes.
picker.set(‘view‘, 1080)

// Using a string along with the parsing format (defaults to `format` option).
picker.set(‘view‘, ‘04-30‘, { format: ‘hh-i‘ })

Set min§

Setting min has cascading changes on the select, highlight, and view only when the particular item object goes out of range.

Limit the min date §

// Using arrays formatted as [YEAR,MONTH,DATE].
picker.set(‘min‘, [2015,3,20])

// Using JavaScript Date objects.
picker.set(‘min‘, new Date(2015,7,14))

// Using formatted strings.
picker.set(‘min‘, ‘8 January, 2016‘))

// Using integers as days relative to today.
picker.set(‘min‘, -4)

// Using `true` for “today”.
picker.set(‘min‘, true)

// Using `false` to remove.
picker.set(‘min‘, false)

Limit the min time §

// Using arrays formatted as [HOUR,MINUTE].
picker.set(‘min‘, [15,30])

// Using JavaScript Date objects.
picker.set(‘min‘, new Date(2015, 3, 20, 10, 30))

// Using formatted strings.
picker.set(‘min‘, ‘4:30 PM‘))

// Using integers as intervals relative from now.
picker.set(‘min‘, -4)

// Using `true` for “now”.
picker.set(‘min‘, true)

// Using `false` to remove.
picker.set(‘min‘, false)

Set max§

Setting max has cascading changes on the select, highlight, and view only when the particular item object goes out of range.

Limit the max date §

// Using arrays formatted as [YEAR,MONTH,DATE].
picker.set(‘max‘, [2015,3,20])

// Using JavaScript Date objects.
picker.set(‘max‘, new Date(2015,7,14))

// Using formatted strings.
picker.set(‘max‘, ‘20 April, 2016‘))

// Using integers as days relative to today.
picker.set(‘max‘, 4)

// Using `true` for “today”.
picker.set(‘max‘, true)

// Using `false` to remove.
picker.set(‘max‘, false)

Limit the max time §

// Using arrays formatted as [HOUR,MINUTE].
picker.set(‘max‘, [15,30])

// Using JavaScript Date objects.
picker.set(‘max‘, new Date(2015, 3, 20, 10, 30))

// Using formatted strings.
picker.set(‘max‘, ‘11:30 AM‘))

// Using integers as intervals relative from now.
picker.set(‘max‘, 4)

// Using `true` for “now”.
picker.set(‘max‘, true)

// Using `false` to remove.
picker.set(‘max‘, false)

Set disable and enable§

Setting disable or enable has cascading changes on the select, highlight, and view only when the currently selected item object becomes disabled.

An important thing to note here is that “setting” something as enabled or disabled adds the new elements to the collection of items to disable rather than completely replacing them with the new collection.

Disable/enable dates §

You can disable sets of dates and then enable the entire set or specific dates within those sets by the following methods:

  • Specific dates:

    picker.set(‘disable‘, [
    
      // Using a collection of arrays formatted as [YEAR,MONTH,DATE]
      [2016,9,3], [2016,9,9], [2016,9,20],
    
      // Using JavaScript Date objects
      new Date(2015,9,13), new Date(2015,9,24)
    ])
    picker.set(‘enable‘, [
      [2016,9,9],
      [2016,9,13],
      new Date(2015,9,20)
    ])

  •  
  •  

Disable/enable times §

You can disable sets of times and then enable the entire set or specific times within those sets by the following methods:

  • Specific times:

    picker.set(‘disable‘, [
    
      // Using a collection of arrays formatted as [HOUR,MINUTES]
      [2,30], [4,30], [9,0],
    
      // Using JavaScript Date objects
      new Date(2015,9,13,6), new Date(2015,9,13,12,30)
    ])
    picker.set(‘enable‘, [
      [4,30], [6,0],
      new Date(2015,9,13,9)
    ])

  •  

Enable an element within a disabled range §

When a date or time you want to enable falls within a disabled range, add the inverted property to the item:

picker.set(‘disable‘, [

  // Disable all Mondays, except November 15th, 2015.
  1, [2015, 10, 15, ‘inverted‘],

  // Disable all dates from March 2nd, 2016 to March 28th, 2016
  // except for March 10th and all between March 14th and March 23rd.
  { from: [2016, 2, 2], to: [2016, 2, 28] },
  [2016, 2, 10, ‘inverted‘],
  { from: [2016, 2, 14], to: [2016, 2, 23], inverted: true }
])
picker.set(‘disable‘, [

  // Disable all times from 1:00 AM to 1:59 AM, except 1:30 AM.
  1, [1, 30, ‘inverted‘],

  // Disable all times from 3:00 AM to 6:00 PM except
  // for 4:30 AM and all between 7:30 AM and 11:30 AM.
  { from: [3,0], to: [18,0] },
  [4, 30, ‘inverted‘],
  { from: [7,30], to: [11,30], inverted: true }
])

Set interval§

For the time picker only, you can change the interval between each time display.

Setting interval has cascading changes on the select, highlight, and view only when the particular item object goes out of range.

// Using integers representing the interval length in minutes
picker.set(‘interval‘, 15)
picker.set(‘interval‘, 20)
picker.set(‘interval‘, 120)

The Events and Callbacks§

Event on§

Bind callbacks to get fired off when the relative picker method is called (unless if the callback is “muted”):

// One at a time
picker.on(methodName, function() { … })

// Multiple at once
picker.on({
  methodName: function() { … },
  methodName: function() { … },
  methodName: function() { … }
})

The methodName can be open, close, render, start, stop, or set.

Within scope of these callbacks, this refers to the picker object – and for most events, no arguments are passed.

The only exception is the set method, which is passed an argument that provides more context as to what is being “set”.

Event callbacks as bindings§

After the picker has been initiated, callbacks to events can be set using the on method:

picker.on({
  open: function() {
    console.log(‘Opened up!‘)
  },
  close: function() {
    console.log(‘Closed now‘)
  },
  render: function() {
    console.log(‘Just rendered anew‘)
  },
  stop: function() {
    console.log(‘See ya‘)
  },
  set: function(thingSet) {
    console.log(‘Set stuff:‘, thingSet)
  }
})

Since these callbacks can only be bound after the picker has started, the ‘start‘ event cannot be given a callback this way. To do that, it must be passed as an option.

Event callbacks as options§

Before the picker has initiated, callbacks to events can be set by passing them as options when invoking the picker:

$(‘.datepicker‘).pickadate({
  onOpen: function() {
    console.log(‘Opened up!‘)
  },
  onClose: function() {
    console.log(‘Closed now‘)
  },
  onRender: function() {
    console.log(‘Just rendered anew‘)
  },
  onStart: function() {
    console.log(‘Hello there :)‘)
  },
  onStop: function() {
    console.log(‘See ya‘)
  },
  onSet: function(thingSet) {
    console.log(‘Set stuff:‘, thingSet)
  }
})

Event off§

Unbind callbacks that are bound using the on method:

picker.off(methodName, methodName, methodName, ...)

The methodName can be open, close, render, start, stop, or set.

picker.on(‘open‘, function() {
  console.log(‘Even when I’m opened, I’m not logged..‘)
})
picker.off(‘open‘)

Event trigger§

Trigger an event’s callbacks that have been queued up:

picker.on(‘open‘, function() {
  console.log(‘This logs without opening!‘)
})
picker.trigger(‘open‘)

Note: this doesn’t actually invoke the method; it only triggers the callback. Similar to jQuery’s triggerHandler method.

Optionally, you can also pass some data to the method being triggered:

picker.on(‘open‘, function(data) {
  console.log(‘This logs without opening with this data:‘, data)
})
picker.trigger(‘open‘, { some: ‘value‘ })

The Objects§

Object $node§

This is the picker’s relative input element wrapped as a jQuery object.

picker.$node

Object $root§

This is the picker’s relative root holder element wrapped as a jQuery object.

picker.$root

Object _hidden§

This is the picker’s relative hidden element, which is undefined if there’s no formatSubmit option.

There should be no reason to use this – it’s mostly for internal use. If you have a valid reason for using this, please mention it in the Issues.

Object component§

This is the picker’s relative component constructor that builds the date or time picker. This API is in flux – so avoid using it for now.

  • Ranges of dates:

    picker.set(‘disable‘, [
    
      // Using integers as the days of the week (1 to 7)
      1, 4, 7,
    
      // Using a range object with a “from” and “to” property
      { from: [2016,2,14], to: [2016,2,27] }
    ])
    picker.set(‘enable‘, [
      4,
      { from: [2016,2,24], to: [2016,2,27] }
    ])

  •  
  • “Flip” the enabled and disabled dates:
    picker.set(‘disable‘, ‘flip‘)
    picker.set(‘enable‘, ‘flip‘)

  •  
  • All the dates:
    // Disable all the dates
    picker.set(‘disable‘, true)
    picker.set(‘enable‘, false)
    
    // Enable all the dates
    picker.set(‘enable‘, true)
    picker.set(‘disable‘, false)

  •  
  • Ranges of times:
    picker.set(‘disable‘, [
    
      // Using integers as hours of the day (from 0 to 23)
      1, 4, 7,
    
      // Using a range object with a “from” and “to” property
      { from: [10,30], to: [18,0] }
    })
    picker.set(‘enable‘, [
      4,
      { from: [14,0], to: [16,30] }
    ])

  •  
  • “Flip” the enabled and disabled times:
    picker.set(‘disable‘, ‘flip‘)
    picker.set(‘enable‘, ‘flip‘)

  •  
  • All the times:
    // Disable all the times
    picker.set(‘disable‘, true)
    picker.set(‘enable‘, true)
    
    // Enable all the dates
    picker.set(‘enable‘, true)
    picker.set(‘disable‘, false)

时间: 2024-10-02 02:17:02

pickadate的相关文章

前端网站资源精编!!

不要吝啬你的赞美喜欢就点个赞 目录: 1-------- 走进前端2-------- jQuery3-------- CSS4-------- Angularjs5-------- ES66-------- React7-------- 移动端API8-------- avalon9-------- Requriejs10-------- vue11-------- Seajs12-------- Less,sass13-------- Markdown14-------- D315------

JavaScript资源大全

目录 前端MVC 框架和库 包管理器 加载器 打包工具 测试框架 框架 断言 覆盖率 运行器 QA 工具 基于 Node 的 CMS 框架 模板引擎 数据可视化 编辑器 UI 输入 日历 选择 文件上传 其它 提示 模态框和弹出框 滚动 菜单 表格/栅格 框架 手势 地图 视频/音频 动画 图片处理 ECMAScript 6 软件开发工具包(SDK) 利器 前端MVC 框架和库 angular.js:为网络应用增强 HTML.官网 aurelia:一个适用于移动设备.桌面电脑和 web 的客户端

看着看着就哭了的前端地址大全

原文地址:http://www.w3cfuns.com/notes/16438/db8e9e0bf80676f32b2cafb9b4932313.html 综合类 | 地址--- | --- 前端知识体系|http://www.cnblogs.com/sb19871023/p/3894452.html前端知识结构|https://github.com/JacksonTian/fksWeb前端开发大系概览|https://github.com/unruledboy/WebFrontEndStack

JavaScript 资源大全中文版

包管理器 管理着 javascript 库,并提供读取和打包它们的工具. npm:npm 是 javascript 的包管理器.官网 Bower:一个 web 应用的包管理器.官网 component:能构建更好 web 应用的客户端包管理器.官网 spm:全新的静态包管理器.官网 jam:一个专注于浏览器端和兼容 RequireJS 的包管理器.官网 jspm:流畅的浏览器包管理器.官网 Ender:没有库文件的程序库.官网 volo:以项目模板.添加依赖项与自动化生成的方式创建前端项目.官网

个人Web工具箱&资源整理(1)

很久就想把使用的工具及收藏的资源整理一番:一是为了传达博客社区的理念:资源共享,而是方便自己及团队快速获取. 学习资源: 首推两个入门级在线参考网站. 1 w3c school. 2 Runoob.com(菜鸟教程). HTML5:标记语言,是HTML和XHTML的最新版本. HTML5 Outliner HTML5在线生成. 模板: jade:Jade 是一个高性能的模板引擎,它深受 Haml 影响,它是用 JavaScript 实现的,并且可以供 Node 使用. jade API:运行在N

javascript开源大全

javascript开源大全 Ajax框架-jQuery 可视化HTML编辑器-CKEditor 国产jQuery-UI框架-(jUI)-DWZ 网页开发FireFox插件-Firebug 服务器端的JavaScript脚本-Node.js jQuery图表插件-jQchart HTML5-开发框架-jQuery-Mobile 跨浏览器的RIA框架-ExtJS Flash视频播放器-JW-PLAYER jQuery表单插件-jQuery.form jQuery-File-Upload 可视化HT

JavaScript资源大全中文版(Awesome最新版)

JavaScript资源大全中文版(Awesome最新版) 目录 前端MVC框架与库 Package Managers Loaders Bundlers Testing Frameworks QA Tools QA工具 Node-Powered CMS Frameworks 节点供电的CMS框架 Templating Engines 模板发动机 Articles and Posts 文章和帖子 Data Visualization 数据可视化 Timeline 时间线 Spreadsheet 电

前端插件库【原】 2016-08-21

自己整理的一些质量还可以的前端插件,各种分类的都有,工作中需要用到插件时可以在下面的列表中查找. 1.幻灯片 Camera    a free jQuery slideshow by Pixedelic http://www.pixedelic.com/plugins/camera/ FlexSlider2    An awesome, fully responsive jQuery slider toolkit http://flexslider.woothemes.com/ Flickity

前端相关网址合集

综合类 | 地址--- | --- 前端知识体系--http://www.cnblogs.com/sb19871023/p/3894452.html前端知识结构--https://github.com/JacksonTian/fks免费的编程中文书籍索引--https://github.com/justjavac/free-programming-books-zh_CN智能社 - 精通JavaScript开发--http://study.163.com/course/introduction/2