Skip to content

Commit e87525c

Browse files
committed
2.0新版
1 parent 5e967c8 commit e87525c

20 files changed

+11698
-800
lines changed

.babelrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"modules": false,
5+
"targets": {
6+
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7+
}
8+
}],
9+
"stage-2"
10+
],
11+
"plugins": ["transform-runtime", "external-helpers"],
12+
"env": {
13+
"test": {
14+
"presets": ["env", "stage-2"],
15+
"plugins": ["istanbul"]
16+
}
17+
},
18+
"ignore":["bscroll.min.js"]
19+
}

README.md

Lines changed: 98 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,108 @@
1-
# jquery-date [![npm](https://img.shields.io/npm/v/jquery-date.svg)](https://www.npmjs.com/package/jquery-date)
2-
- 此插件依赖jquery,且是为移动端而写,也支持pc端的使用,但因为操作不便和样式问题,所以不建议。
3-
- 支持年月、年月日、年月日时分、年月日时分秒等,详细格式见demo.html/jquery.date.js。
4-
- 时间限制limitTime参数目前只做了年月日限制。
1+
# jdate(jquery-date) [![npm](https://img.shields.io/npm/v/jquery-date.svg)](https://www.npmjs.com/package/jquery-date) [![npm](https://img.shields.io/npm/dm/jquery-date.svg)](https://www.npmjs.com/package/jquery-date)
2+
此为jdate 2.0新版,完全参照jdate的下一代版本<a href="https://github.com/weijhfly/rolldate">rolldate</a>做了全新改版,查看旧版请点击<a href="https://github.com/weijhfly/jqueryDatePlugin/tree/1.4.3">返回旧版(1.4.3分支)</a>
3+
<br>
4+
此版特色:
5+
1. 拥有和rolldate完全一样的功能;<br>
6+
2. 体积更小,兼容性更强;
57

6-
下一版本计划 ([rolldate--传送门](https://github.com/weijhfly/rolldate "rolldate"))
7-
-----------------------------------
8-
- 不依赖jquery。
9-
- 使用new重写,配置将不挂在dom上,增加可选回调函数。
10-
- 滑动性能优化,可能会依赖相关插件(类似iScroll)。
8+
不足之处:
9+
1. 滑动较慢;
1110

12-
使用方式
13-
-----------------------------------
11+
此版更适合滑动天数少的情况(比如限制只能滑动几天),或者兼容性要求高的情况,一般情况更推荐使用rolldate。并且jdate基本不怎么更新和维护,主要作为一个次要版本出现。
12+
## 演示
13+
[jdate](https://weijhfly.github.io/jdate.html "jdate")(下方直接扫码即可体验)
14+
15+
![jdate](https://weijhfly.github.io/images/jdate-demo.png)
16+
17+
## 使用方式
18+
**特别注意:**
19+
jdate依赖jQuery,如果没有全局的$或jQuery(也要保证在jdate之前加载),必须先使用以下的代码:
20+
```js
21+
Jdate.usejQuery($);
22+
```
23+
如:
24+
```js
25+
import $ from 'jquery'
26+
import Jdate from 'jdate'
27+
28+
Jdate.usejQuery($);
29+
new Jdate({
30+
el:'#date'
31+
})
32+
```
33+
否则插件将报错,无法运行。
34+
### es6
35+
```js
36+
import Jdate from 'jdate'
37+
new Jdate({
38+
el:'#date'
39+
})
40+
```
1441
### commonJS
1542
```js
16-
var $ = require('jquery');
17-
require('jquery-date');
18-
$.date('#date');
43+
var Jdate = require('jdate');
44+
new Jdate({
45+
el:'#date'
46+
})
1947
```
20-
### require.js
48+
### amd
2149
```js
22-
require(['jquery-date'],function(){
23-
$.date('#date');
50+
require(['Jdate'],function(Jdate){
51+
new Jdate({
52+
el:'#date'
53+
})
2454
})
2555
```
26-
### browser
56+
### cmd
2757
```js
28-
$.date('#date');
58+
seajs.use('Jdate',function(undefined){
59+
//插件没有遵循cmd规范,这里的Jdate是全局的
60+
new Jdate({
61+
el:'#date'
62+
})
63+
});
64+
```
65+
## 参数、方法说明
66+
名称|必填|默认值|说明
67+
---|:-:|:-:|---
68+
el|是|无|绑定插件的dom元素,插件内部使用document.querySelector,<br>也可以直接传递dom元素对象,只支持单个
69+
format|否|'YYYY-MM-DD'|日期格式,无限制。规则:年-YYYY 月-MM 日-DD 时-hh 分-mm 秒-ss 使用/、-、空格、:之一分隔,可随意组合
70+
beginYear|否|2000|日期开始年份
71+
endYear|否|2100|日期结束年份
72+
value|否|无|日期初始化的默认值,列如'2018-03-18'
73+
lang|否|年、月、日...|配置插件语言,默认:title:'选择日期',cancel:'取消',confirm:'确认',<br>year:'年',month:'月',day:'日',hour:'时',min:'分',sec:'秒'
74+
minStep|否|1|分钟按指定数分隔
75+
init|否|null|插件触发前的回调函数,return false可阻止插件执行
76+
moveEnd|否|null|插件滚动后的回调函数
77+
confirm|否|null|确认按钮触发前的回调函数,return false可阻止插件执行,<br>return其他值可修改日期,函数返回一个参数(选中的日期)
78+
cancel|否|null|插件取消时触发的回调函数
79+
trigger|否|'tap'|默认使用tap解决移动端click事件300ms延迟,可选click替换tap。注意使用tap会阻止其他绑定的click事件的触发
80+
show|否|无|主动触发插件,当trigger为tap时,主动触发插件应该使用此方法
81+
hide|否|无|主动隐藏插件
82+
```js
83+
//完整参数、方法示例
84+
var jd = new Jdate({
85+
el: '#date',
86+
format: 'YYYY-MM-DD',
87+
beginYear: 2000,
88+
endYear: 2100,
89+
minStep:1,
90+
lang:{title:'自定义标题'},
91+
trigger:'tap',
92+
init: function() {
93+
console.log('插件开始触发');
94+
},
95+
moveEnd: function() {
96+
console.log('滚动结束');
97+
},
98+
confirm: function(date) {
99+
console.log('确定按钮触发');
100+
},
101+
cancel: function() {
102+
console.log('插件运行取消');
103+
}
104+
})
105+
jd.show();
106+
jd.hide();
107+
29108
```
30-
demo
31-
-----------------------------------
32-
请点击 [demo page](https://weijhfly.github.io/date-demo.html "demo")

config/banner.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* banner description
3+
*/
4+
var pkg = require('../package.json'),
5+
version = pkg.version,
6+
released = 'Licensed under MIT',
7+
repository = pkg.repository.url,
8+
author = 'Copyright ' + (new Date()).getFullYear() + ' 雾空',
9+
date = 'Released on: aug 4, 2018';
10+
11+
module.exports = {
12+
'info': [
13+
'Jdate ' + version,
14+
author,
15+
repository,
16+
released,
17+
date
18+
].join('\n')
19+
}

config/jdate.config.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
let path = require('path');
2+
let HtmlWebpackPlugin = require('html-webpack-plugin');
3+
let ExtractTextWebpackPlugin = require('extract-text-webpack-plugin');
4+
let CleanWebpackPlugin = require('clean-webpack-plugin');
5+
let webpack = require('webpack');
6+
let banner = require('./banner').info;
7+
8+
module.exports = {
9+
entry:'./src/index.js',
10+
output: {
11+
filename: 'jdate.min.js',
12+
path: path.resolve('dist'),
13+
library : 'Jdate',
14+
// libraryTarget: 'umd',
15+
libraryExport: "default",
16+
},
17+
devServer: {
18+
contentBase: './dist',
19+
host: 'localhost',
20+
//host: '0.0.0.0',
21+
port: 9091,
22+
open: false,
23+
hot: false
24+
},
25+
module:{
26+
rules:[
27+
{
28+
test:/\.js$/,
29+
exclude:/node_modules/,
30+
loader:'babel-loader',
31+
options:{
32+
presets:["es2015"]
33+
}
34+
},
35+
{
36+
test:/\.less$/,
37+
use: ['style-loader', 'css-loader', 'postcss-loader', 'less-loader']
38+
}
39+
]
40+
},
41+
plugins: [
42+
new HtmlWebpackPlugin({
43+
template: './src/index.html',
44+
hash: false,
45+
}),
46+
//new ExtractTextWebpackPlugin('css/jdate.css'),
47+
//new webpack.BannerPlugin(banner)
48+
],
49+
optimization: {
50+
minimize: false
51+
}
52+
}

0 commit comments

Comments
 (0)