Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a custom js file for android picker #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"cordova": {
"id": "cordova-plugin-inline-datepicker",
"platforms": [
"ios"
"ios",
"android"
]
},
"publishConfig": {
Expand All @@ -17,7 +18,8 @@
},
"keywords": [
"ecosystem:cordova",
"cordova-ios"
"cordova-ios",
"cordova-android"
],
"author": "Can Kutlu Kinay <[email protected]>",
"license": "MIT",
Expand Down
18 changes: 15 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<name>Cordova Inline DatePicker</name>
<js-module name="DatePicker" src="www/datepicker.js">
<clobbers target="cordova.plugins.DatePicker" />
</js-module>
<description>Hybrid Date Picker for Android/iOS</description>

<platform name="ios">
<js-module name="DatePicker" src="www/datepicker.js">
<clobbers target="cordova.plugins.DatePicker" />
</js-module>
<config-file parent="/*" target="config.xml">
<feature name="CDVDatePicker">
<param name="ios-package" value="CDVDatePicker" />
Expand All @@ -16,5 +18,15 @@
<source-file src="src/ios/DatePicker.swift" />
<source-file src="src/ios/DatePickerManager.swift" />
</platform>
<platform name="android">
<js-module name="DatePicker" src="www/androiddatepicker.js">
<clobbers target="cordova.plugins.DatePicker" />
</js-module>
<config-file target="res/xml/config.xml" parent="/*">
<feature name="DatePicker">
<param name="android-package" value="com.mihri.DatePicker" />
</feature>
</config-file>
</platform>
<dependency id="cordova-plugin-add-swift-support" version="*" />
</plugin>
71 changes: 71 additions & 0 deletions www/androiddatepicker.js
Original file line number Diff line number Diff line change
@@ -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
};