Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 46 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
# rolldate [![npm](https://img.shields.io/npm/v/rolldate.svg)](https://www.npmjs.com/package/rolldate) [![npm](https://img.shields.io/npm/dm/rolldate.svg)](https://www.npmjs.com/package/rolldate)
此插件为[jquery-date](https://github.com/weijhfly/jqueryDatePlugin "jquery-date")的全新版本,主要为了解决旧版参数设计不够合理、滑动效率不高、依赖jquery、没有可选的主题风格等问题,并增加了回调函数,使插件有更大的灵活性。
## 2019/05/24 3.0版本更新
上一个版本为2.1.5, 新版本(从3.0.0开始)的改动:

1. 使用方式由new rolldate.Date改为new Rolldate;
2. 回调函数调整:tapBefore更名为init,confirmBefore更名为confirm,取消confirmEnd,增加cancel;
3. 日期格式(format)调整为无限制,可根据规则随意组合;
This plugin is a new version of [jquery-date](https://github.com/weijhfly/jqueryDatePlugin "jquery-date"), primarily designed to address issues such as unreasonable parameter design, low scrolling efficiency, dependency on jQuery, lack of optional theme styles, etc. It also introduces callback functions for greater flexibility.

## 2019/02/03重要版本更新
上一个版本为1.5.1, 新版本(从2.0.0开始)与此前版本的不同之处:
## Version 3.0 Update (2019/05/24)

1. 将滑动插件由iscroll替换为better-scroll,提升了兼容性;
2. 改变了界面风格,操作更加方便;
3. 取消了rolldate.css文件,只需引入js即可;
4. 移除了主题风格、日期初始化的滑动时间设置;
The previous version was 2.1.5. Changes in the new version (starting from 3.0.0):

注意2.0.0之前的版本将不再维护,如有需要请访问:[旧版rolldate](https://weijhfly.github.io/rolldate-index2.html "rolldate")
## 演示
[rolldate](https://weijhfly.github.io/rolldate-index.html "rolldate")(下方直接扫码即可体验)
1. The usage changed from `new rolldate.Date` to `new Rolldate`.
2. Callback functions were adjusted: `tapBefore` renamed to `init`, `confirmBefore` renamed to `confirm`, `confirmEnd` removed, and `cancel` added.
3. The date format (format) is now unrestricted and can be freely combined according to rules.

## Important Version Update (2019/02/03)

The previous version was 1.5.1. The new version (starting from 2.0.0) differs from earlier versions in the following ways:

1. Replaced the scrolling plugin from iscroll to better-scroll, improving compatibility.
2. Changed the interface style for easier operation.
3. Removed the `rolldate.css` file; only the JS file needs to be included.
4. Removed theme styles and sliding time settings for date initialization.

**Note**: Versions prior to 2.0.0 will no longer be maintained. For previous versions, please visit: [Old rolldate](https://weijhfly.github.io/rolldate-index2.html "rolldate")

## Demo

Experience the [rolldate](https://weijhfly.github.io/rolldate-index.html "rolldate") (scan the QR code below for a direct experience):

![rolldate](https://weijhfly.github.io/images/rolldate-demo.jpg)

## Usage

### ES6
```js
import Rolldate from 'rolldate';
new Rolldate({
el: '#date'
});


## 使用方式
### es6
```js
Expand Down Expand Up @@ -54,22 +70,22 @@ seajs.use('rolldate',function(undefined){
});
```
## 参数、方法说明
名称|必填|默认值|说明
Name|Required|Default|Description
---|:-:|:-:|---
el|否|无|绑定插件的dom元素,插件内部使用document.querySelector<br>也可以直接传递dom元素对象,只支持单个
format||'YYYY-MM-DD'|日期格式,无限制。规则:年-YYYY -MM -DD -hh -mm -ss 使用/、-、空格、:之一分隔,可随意组合
beginYear||2000|日期开始年份
endYear||2100|日期结束年份
value|否|无|日期初始化的默认值,列如'2018-03-18'
lang|否|年、月、日...|配置插件语言,默认:title:'选择日期',cancel:'取消',confirm:'确认',<br>year:'年',month:'月',day:'日',hour:'时',min:'分',sec:''
minStep||1|分钟按指定数分隔
init||null|插件触发前的回调函数,return false可阻止插件执行
moveEnd||null|插件滚动后的回调函数,函数返回一个参数(better-scroll实例)
confirm||null|确认按钮触发前的回调函数,return false可阻止插件执行,<br>return其他值可修改日期,函数返回一个参数(选中的日期)
cancel||null|插件取消时触发的回调函数
trigger||'tap'|默认使用tap解决移动端click事件300ms延迟,可选click替换tap。注意使用tap会阻止其他绑定的click事件的触发
show|否|无|主动触发插件,当trigger为tap时,主动触发插件应该使用此方法
hide|否|无|主动隐藏插件
el|No|None|The DOM element to which the plugin is bound. The plugin uses `document.querySelector` internally. <br>You can also directly pass a DOM element object, only supports a single element.
format|No|'YYYY-MM-DD'|Date format, no restrictions. Rules: Year-YYYY Month-MM Day-DD Hour-hh Minute-mm Second-ss AM/PM-A Use one of /, -, space, : as separators, can be freely combined.
beginYear|No|2000|Start year of the date
endYear|No|2100|End year of the date
value|No|None|Default value for date initialization, e.g., '2018-03-18'
lang|No|Year, Month, Day...|Configure the plugin language, default: title:'Select Date', cancel:'Cancel', confirm:'Confirm',<br>year:'Year', month:'Month', day:'Day', hour:'Hour', min:'Minute', sec:'Second'
minStep|No|1|Minutes are divided by the specified number
init|No|null|Callback function before the plugin is triggered, return false to prevent the plugin from executing
moveEnd|No|null|Callback function after the plugin scrolls, the function returns one parameter (better-scroll instance)
confirm|No|null|Callback function before the confirm button is triggered, return false to prevent the plugin from executing, <br>return other values to modify the date, the function returns one parameter (selected date)
cancel|No|null|Callback function triggered when the plugin is canceled
trigger|No|'tap'|Default is to use tap to solve the 300ms delay of the click event on mobile devices, you can choose click to replace tap. Note that using tap will prevent other bound click events from being triggered
show|No|None|Actively trigger the plugin, when trigger is tap, actively trigger the plugin should use this method
hide|No|None|Actively hide the plugin

```js
//完整参数、方法示例
Expand Down
30 changes: 21 additions & 9 deletions dist/rolldate.cjs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/**
/**
* Rolldate 3.1.3
* Copyright 2018-2020
* Copyright 2018-2024
* weijhfly https://github.com/weijhfly/rolldate
* Licensed under MIT
* Released on: aug 4, 2018
*/

'use strict';

function styleInject(css, ref) {
Expand Down Expand Up @@ -35,7 +34,7 @@ function styleInject(css, ref) {
}
}

var css = ".rolldate-container{font-size:20px;color:#333;text-align:center}.rolldate-container ul{margin:0;padding:0}.rolldate-container li{list-style-type:none}.rolldate-container header{position:relative;line-height:60px;font-size:18px;border-bottom:1px solid #e0e0e0}.rolldate-container .rolldate-mask{position:fixed;width:100%;height:100%;top:0;left:0;z-index:999;background-color:rgba(37,38,45,.4)}.rolldate-container .rolldate-panel{position:fixed;bottom:0;left:0;width:100%;height:273px;z-index:1000;background:#fff;-webkit-transition:all .3s ease-in-out;-o-transition:all .3s ease-in-out;transition:all .3s ease-in-out;-webkit-transform:translate3d(0,273px,0);transform:translate3d(0,273px,0)}.rolldate-container .rolldate-btn{position:absolute;left:0;top:0;height:100%;padding:0 15px;color:#666;font-size:16px;cursor:pointer;-webkit-tap-highlight-color:transparent}.rolldate-container .rolldate-confirm{left:auto;right:0;color:#007bff}.rolldate-container .rolldate-content{position:relative;top:20px}.rolldate-container .rolldate-wrapper{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex}.rolldate-container .rolldate-wrapper>div{-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1;height:173px;line-height:36px;overflow:hidden;-webkit-flex-basis:-8e;-ms-flex-preferred-size:-8e;flex-basis:-8e;width:1%}.rolldate-container .rolldate-wrapper ul{margin-top:68px}.rolldate-container .rolldate-wrapper li{height:36px}.rolldate-container .rolldate-dim{position:absolute;left:0;top:0;width:100%;height:68px;background:-o-linear-gradient(bottom,hsla(0,0%,100%,.4),hsla(0,0%,100%,.8));background:-webkit-gradient(linear, left bottom, left top, from(hsla(0, 0%, 100%, 0.4)), to(hsla(0, 0%, 100%, 0.8)));background:-o-linear-gradient(bottom, hsla(0, 0%, 100%, 0.4), hsla(0, 0%, 100%, 0.8));background:linear-gradient(0deg,hsla(0,0%,100%,.4),hsla(0,0%,100%,.8));pointer-events:none;-webkit-transform:translateZ(0);transform:translateZ(0);z-index:10}.rolldate-container .mask-top{border-bottom:1px solid #ebebeb}.rolldate-container .mask-bottom{top:auto;bottom:1px;border-top:1px solid #ebebeb}.rolldate-container .fadeIn{-webkit-transform:translateZ(0);transform:translateZ(0)}.rolldate-container .fadeOut{-webkit-transform:translate3d(0,273px,0);transform:translate3d(0,273px,0)}@media screen and (max-width:414px){.rolldate-container{font-size:18px}}@media screen and (max-width:320px){.rolldate-container{font-size:15px}}";
var css = ".rolldate-container{font-size:20px;color:#333;text-align:center}.rolldate-container ul{margin:0;padding:0}.rolldate-container li{list-style-type:none}.rolldate-container header{position:relative;line-height:60px;font-size:18px;border-bottom:1px solid #e0e0e0}.rolldate-container .rolldate-mask{position:fixed;width:100%;height:100%;top:0;left:0;z-index:999;background-color:rgba(37,38,45,.4)}.rolldate-container .rolldate-panel{position:fixed;bottom:0;left:0;width:100%;height:273px;z-index:1000;background:#fff;transition:all .3s ease-in-out;-webkit-transform:translate3d(0,273px,0);transform:translate3d(0,273px,0)}.rolldate-container .rolldate-btn{position:absolute;left:0;top:0;height:100%;padding:0 15px;color:#666;font-size:16px;cursor:pointer;-webkit-tap-highlight-color:transparent}.rolldate-container .rolldate-confirm{left:auto;right:0;color:#007bff}.rolldate-container .rolldate-content{position:relative;top:20px}.rolldate-container .rolldate-wrapper{display:flex}.rolldate-container .rolldate-wrapper>div{flex:1;height:173px;line-height:36px;overflow:hidden;flex-basis:-8e;width:1%}.rolldate-container .rolldate-wrapper ul{margin-top:68px}.rolldate-container .rolldate-wrapper li{height:36px}.rolldate-container .rolldate-dim{position:absolute;left:0;top:0;width:100%;height:68px;background:linear-gradient(0deg,hsla(0,0%,100%,.4),hsla(0,0%,100%,.8));pointer-events:none;-webkit-transform:translateZ(0);transform:translateZ(0);z-index:10}.rolldate-container .mask-top{border-bottom:1px solid #ebebeb}.rolldate-container .mask-bottom{top:auto;bottom:1px;border-top:1px solid #ebebeb}.rolldate-container .fadeIn{-webkit-transform:translateZ(0);transform:translateZ(0)}.rolldate-container .fadeOut{-webkit-transform:translate3d(0,273px,0);transform:translate3d(0,273px,0)}@media screen and (max-width:414px){.rolldate-container{font-size:18px}}@media screen and (max-width:320px){.rolldate-container{font-size:15px}}";
styleInject(css);

var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
Expand Down Expand Up @@ -115,11 +114,12 @@ Rolldate.prototype = {
DD: 'rolldate-day',
hh: 'rolldate-hour',
mm: 'rolldate-min',
ss: 'rolldate-sec'
ss: 'rolldate-sec',
A: 'rolldate-ampm' // Add this line
},
opts: { //插件默认配置
el: '',
format: 'YYYY-MM-DD',
format: 'YYYY-MM-DD', // Add 'A' for AM/PM
beginYear: 2000,
endYear: 2100,
init: null,
Expand All @@ -128,8 +128,8 @@ Rolldate.prototype = {
cancel: null,
minStep: 1,
trigger: 'tap',
lang: { title: '选择日期', cancel: '取消', confirm: '确认', year: '年', month: '月', day: '日', hour: '时', min: '分', sec: '秒' }
}
lang: { title: '选择日期', cancel: '取消', confirm: '确认', year: '年', month: '月', day: '日', hour: '时', min: '分', sec: '秒', am: '上午', pm: '下午' // Add AM/PM
} }
};
},
extend: function extend(config) {
Expand Down Expand Up @@ -208,6 +208,12 @@ Rolldate.prototype = {
ul += '<li class="wheel-item ' + itemClass + '" data-index="' + domMndex + '">' + (o < 10 ? '0' + o : o) + lang.sec + '</li>';
domMndex++;
}
} else if (f == 'A') {
// Add AM/PM selection
['AM', 'PM'].forEach(function (period, index) {
itemClass = date.getHours() < 12 && period === 'AM' || date.getHours() >= 12 && period === 'PM' ? 'active' : '';
ul += '<li class="wheel-item ' + index + ' ' + itemClass + '" data-index="' + index + '">' + lang[period.toLowerCase()] + '</li>';
});
}
ul += '</ul></div>';
}
Expand Down Expand Up @@ -252,6 +258,12 @@ Rolldate.prototype = {
_this.scroll['DD'].refresh();
}
}

// Add When scrolling ends for hour, update AM/PM
if (that.wrapper.id === domId['hh'] && _this.scroll['A']) {
var period = parseInt(_this.scroll['hh'].selectedIndex) < 12 ? 0 : 1;
_this.scroll['A'].wheelTo(period);
}
});
};

Expand Down Expand Up @@ -436,7 +448,7 @@ Rolldate.prototype = {
}, 300);
},
getSelected: function getSelected(scroll) {
return $('#' + scroll.wrapper.id + ' li', 1)[scroll.getSelectedIndex()].innerText.replace(/\D/g, '');
return $('#' + scroll.wrapper.id + ' li', 1)[scroll.getSelectedIndex()].innerText.replace(/\D/g, '') || $('#' + scroll.wrapper.id + ' li', 1)[scroll.getSelectedIndex()].innerText;
}
};
Rolldate.version = version;
Expand Down
Loading