forked from laravelcm/laravel.cm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧑💻 Update Article datepicker (laravelcm#128)
- Loading branch information
1 parent
4db4b49
commit 48ce6fa
Showing
12 changed files
with
231 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"/js/app.js": "/js/app.js?id=e624a82705e66ddf8f8774361377693b", | ||
"/css/app.css": "/css/app.css?id=3542b9735c706c26665a33113b79c212" | ||
"/js/app.js": "/js/app.js?id=b3926f80205eb8b77d68a280462d061f", | ||
"/css/app.css": "/css/app.css?id=e1f5ef9f7dd1d6ba4334d8eb1f233620" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
export default () => ({ | ||
datePickerOpen: false, | ||
datePickerValue: '', | ||
datePickerRealValue: '', | ||
datePickerFormat: 'd M, Y', | ||
datePickerMonth: '', | ||
datePickerYear: '', | ||
datePickerDay: '', | ||
datePickerDaysInMonth: [], | ||
datePickerBlankDaysInMonth: [], | ||
datePickerMonthNames: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Décembre'], | ||
datePickerDays: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'], | ||
|
||
datePickerDayClicked(day) { | ||
let selectedDate = new Date(Date.UTC(this.datePickerYear, this.datePickerMonth, day)) | ||
this.datePickerDay = day | ||
this.datePickerValue = this.datePickerFormatDate(selectedDate, this.datePickerFormat) | ||
this.datePickerRealValue = selectedDate | ||
this.datePickerIsSelectedDate(day) | ||
this.datePickerOpen = false | ||
}, | ||
|
||
datePickerPreviousMonth() { | ||
if (this.datePickerMonth === 0) { | ||
this.datePickerYear-- | ||
this.datePickerMonth = 12 | ||
} | ||
this.datePickerMonth-- | ||
this.datePickerCalculateDays() | ||
}, | ||
|
||
datePickerNextMonth() { | ||
if (this.datePickerMonth === 11) { | ||
this.datePickerMonth = 0 | ||
this.datePickerYear++ | ||
} else { | ||
this.datePickerMonth++ | ||
} | ||
this.datePickerCalculateDays() | ||
}, | ||
|
||
datePickerIsSelectedDate(day) { | ||
const d = new Date(Date.UTC(this.datePickerYear, this.datePickerMonth, day)) | ||
return this.datePickerValue === this.datePickerFormatDate(d, this.datePickerFormat) | ||
}, | ||
|
||
datePickerIsToday(day) { | ||
const today = new Date() | ||
const d = new Date(Date.UTC(this.datePickerYear, this.datePickerMonth, day)) | ||
return today.toDateString() === d.toDateString() | ||
}, | ||
|
||
datePickerCalculateDays() { | ||
let daysInMonth = new Date(Date.UTC(this.datePickerYear, this.datePickerMonth + 1, 0)).getUTCDate(); | ||
// find where to start calendar day of week | ||
let dayOfWeek = new Date(Date.UTC(this.datePickerYear, this.datePickerMonth)).getUTCDay(); | ||
let blankDaysArray = []; | ||
for (let i = 1; i <= dayOfWeek; i++) { | ||
blankDaysArray.push(i); | ||
} | ||
let daysArray = []; | ||
for (let i = 1; i <= daysInMonth; i++) { | ||
daysArray.push(i); | ||
} | ||
this.datePickerBlankDaysInMonth = blankDaysArray; | ||
this.datePickerDaysInMonth = daysArray; | ||
}, | ||
|
||
datePickerFormatDate(date, format = null) { | ||
let formattedDay = this.datePickerDays[date.getUTCDay()]; | ||
let formattedDate = ('0' + date.getUTCDate()).slice(-2); // appends 0 (zero) in single digit date | ||
let formattedMonth = this.datePickerMonthNames[date.getUTCMonth()]; | ||
let formattedMonthShortName = this.datePickerMonthNames[date.getUTCMonth()].substring(0, 3); | ||
let formattedMonthInNumber = ('0' + (parseInt(date.getUTCMonth()) + 1)).slice(-2); | ||
let formattedYear = date.getUTCFullYear(); | ||
|
||
if (format && format === 'd M, Y') { | ||
return `${formattedDate} ${formattedMonthShortName}, ${formattedYear}` | ||
} | ||
|
||
if (format && format === 'MM-DD-YYYY') { | ||
return `${formattedMonthInNumber}-${formattedDate}-${formattedYear}` | ||
} | ||
|
||
if (format && format === 'DD-MM-YYYY') { | ||
return `${formattedDate}-${formattedMonthInNumber}-${formattedYear}` | ||
} | ||
|
||
if (format && format === 'YYYY-MM-DD') { | ||
return `${formattedYear}-${formattedMonthInNumber}-${formattedDate}` | ||
} | ||
|
||
if (format && format === 'D d M, Y') { | ||
return `${formattedDay} ${formattedDate} ${formattedMonthShortName} ${formattedYear}` | ||
} | ||
|
||
return `${formattedMonth} ${formattedDate}, ${formattedYear}` | ||
}, | ||
|
||
init() { | ||
let currentDate = new Date() | ||
|
||
if (this.datePickerValue) { | ||
currentDate = new Date(Date.parse(this.datePickerValue)) | ||
} | ||
|
||
this.datePickerMonth = currentDate.getUTCMonth() | ||
this.datePickerYear = currentDate.getUTCFullYear() | ||
this.datePickerDay = currentDate.getUTCDay() | ||
this.datePickerValue = this.datePickerFormatDate(currentDate, this.datePickerFormat) | ||
this.datePickerCalculateDays() | ||
|
||
this.$watch('datePickerValue', () => { | ||
this.datePickerRealValue = new Date(Date.UTC(this.datePickerYear, this.datePickerMonth, this.datePickerDay)) | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import intlTelInput from 'intl-tel-input'; | ||
import intlTelInput from 'intl-tel-input' | ||
|
||
export default (element) => ({ | ||
input: element, // '#myID' selector css | ||
|
@@ -9,18 +9,18 @@ export default (element) => ({ | |
nationalMode: true, | ||
geoIpLookup: function(success, failure) { | ||
fetch('https://ipinfo.io').then(response => { | ||
let countryCode = (response && response.country) ? response.country : 'CM'; | ||
success(countryCode); | ||
let countryCode = (response && response.country) ? response.country : 'CM' | ||
success(countryCode) | ||
}) | ||
}, | ||
utilsScript: 'https://unpkg.com/[email protected]/build/js/utils.js' | ||
}); | ||
}) | ||
let handleChange = () => { | ||
if (iti.isValidNumber()) { | ||
phoneNumber.value = iti.getNumber(); | ||
phoneNumber.value = iti.getNumber() | ||
} | ||
}; | ||
phoneNumber.addEventListener('change', handleChange); | ||
phoneNumber.addEventListener('keyup', handleChange); | ||
} | ||
phoneNumber.addEventListener('change', handleChange) | ||
phoneNumber.addEventListener('keyup', handleChange) | ||
} | ||
}) |
Oops, something went wrong.