mirror of
https://github.com/tenrok/vue2-datepicker.git
synced 2026-06-11 00:52:26 +03:00
refactor: 2.0
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
export function isPlainObject (obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object Object]'
|
||||
}
|
||||
|
||||
export function isDateObejct (value) {
|
||||
return value instanceof Date
|
||||
}
|
||||
|
||||
export function isValidDate (date) {
|
||||
if (date === null || date === undefined) {
|
||||
return false
|
||||
}
|
||||
return !!new Date(date).getTime()
|
||||
}
|
||||
|
||||
export function isValidRange (date) {
|
||||
return (
|
||||
Array.isArray(date) &&
|
||||
date.length === 2 &&
|
||||
isValidDate(date[0]) &&
|
||||
isValidDate(date[1]) &&
|
||||
(new Date(date[1]).getTime() >= new Date(date[0]).getTime())
|
||||
)
|
||||
}
|
||||
|
||||
export function parseTime (time) {
|
||||
const values = (time || '').split(':')
|
||||
if (values.length >= 2) {
|
||||
const hours = parseInt(values[0], 10)
|
||||
const minutes = parseInt(values[1], 10)
|
||||
return {
|
||||
hours,
|
||||
minutes
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function formatTime (time, type = '24') {
|
||||
let hours = time.hours
|
||||
hours = (type === '24') ? hours : (hours % 12 || 12)
|
||||
hours = hours < 10 ? '0' + hours : hours
|
||||
let minutes = time.minutes < 10 ? '0' + time.minutes : time.minutes
|
||||
let result = hours + ':' + minutes
|
||||
if (type === '12') {
|
||||
result += time.hours >= 12 ? ' pm' : ' am'
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
export default function scrollIntoView (container, selected) {
|
||||
if (!selected) {
|
||||
container.scrollTop = 0
|
||||
return
|
||||
}
|
||||
|
||||
const offsetParents = []
|
||||
let pointer = selected.offsetParent
|
||||
while (pointer && container !== pointer && container.contains(pointer)) {
|
||||
offsetParents.push(pointer)
|
||||
pointer = pointer.offsetParent
|
||||
}
|
||||
const top = selected.offsetTop + offsetParents.reduce((prev, curr) => (prev + curr.offsetTop), 0)
|
||||
const bottom = top + selected.offsetHeight
|
||||
const viewRectTop = container.scrollTop
|
||||
const viewRectBottom = viewRectTop + container.clientHeight
|
||||
|
||||
if (top < viewRectTop) {
|
||||
container.scrollTop = top
|
||||
} else if (bottom > viewRectBottom) {
|
||||
container.scrollTop = bottom - container.clientHeight
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user