From f85e90162f73e84e59e0df9c66a76092840eb58e Mon Sep 17 00:00:00 2001 From: Mihriban Minaz Date: Fri, 11 May 2018 14:38:24 +0200 Subject: [PATCH] Create a custom js file for android picker Implement UI changes and default values of datepicker Set datepicker default value and min value as options.date or date.now, fix margin problem Set selected date as dateFrom & dateUntil values --- package.json | 6 ++-- plugin.xml | 18 ++++++++-- www/androiddatepicker.js | 71 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 www/androiddatepicker.js diff --git a/package.json b/package.json index 061063c..6ea4771 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "cordova": { "id": "cordova-plugin-inline-datepicker", "platforms": [ - "ios" + "ios", + "android" ] }, "publishConfig": { @@ -17,7 +18,8 @@ }, "keywords": [ "ecosystem:cordova", - "cordova-ios" + "cordova-ios", + "cordova-android" ], "author": "Can Kutlu Kinay ", "license": "MIT", diff --git a/plugin.xml b/plugin.xml index 388f3bf..662068d 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,10 +3,12 @@ xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android"> Cordova Inline DatePicker - - - + Hybrid Date Picker for Android/iOS + + + + @@ -16,5 +18,15 @@ + + + + + + + + + + diff --git a/www/androiddatepicker.js b/www/androiddatepicker.js new file mode 100644 index 0000000..ebde5d4 --- /dev/null +++ b/www/androiddatepicker.js @@ -0,0 +1,71 @@ +var datePickerDict = {}; + +exports.create = function(element, options, success, error) { + options = options || {}; + let optionsId = options.id || element && element.getAttribute && element.getAttribute('data-datepicker-id') || Date.now().toString(36); + element && element.setAttribute && element.setAttribute('data-datepicker-id', optionsId); + const dateValue = (options.date || new Date()).toISOString().substring(0, 16); + let parentElement = element.parentElement; + + var newDatePicker = document.createElement('INPUT'); + newDatePicker.setAttribute('type', 'datetime-local'); + newDatePicker.setAttribute('name', optionsId); + newDatePicker.setAttribute('id', optionsId); + newDatePicker.value = dateValue; + newDatePicker.min = dateValue; + newDatePicker.setAttribute('style', 'color: none; padding: 0; -webkit-appearance: menulist; background-color: transparent; margin: -30px; margin-right: -200px; width: inherit; height: inherit;'); + + if (parentElement) { + parentElement.innerHTML = ''; + parentElement.appendChild(newDatePicker); + } + + datePickerDict[optionsId] = success; + + newDatePicker.onchange = function(event) { + const pickerId = event.srcElement.id || 'no-id'; + const dateInDateTime = parseISOString(event.srcElement.value); + const callbackFunc = datePickerDict[pickerId]; + + const datePickerInfo = []; + datePickerInfo['id'] = pickerId; + datePickerInfo['date'] = dateInDateTime.getTime() || 0; + datePickerInfo['initial'] = true; + callbackFunc(datePickerInfo); + }; + return newDatePicker; + }; + + function parseISOString(s) { + var b = s.split(/\D+/); + return new Date(Date.UTC(b[0], --b[1], b[2], b[3], b[4], b[5] || 0, b[6] || 0)); + } + + exports.show = function(element, options, success, error) { + } + + exports.hide = function(element, options, success, error) { + } + + exports.hideAll = function (root, success, error) { + } + + exports.remove = function (root, success, error) { + } + + exports.removeAll = function (success, error) { + } + + exports.Mode = { + // Displays hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. 6 | 53 | PM) + TIME: 0, + + // Displays month, day, and year depending on the locale setting (e.g. November | 15 | 2007) + DATE: 1, + + // Displays date, hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. Wed Nov 15 | 6 | 53 | PM) + DATE_AND_TIME: 2, + + // Displays hour and minute (e.g. 1 | 53) + COUNTDOWN_TIMER: 3 + };