-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Howto integrate this in a website? #574
Comments
I managed to create modules from the distribution using a perl script to create the necessary exports to access the modules: #!/usr/bin/perl
my $home=$ENV{'HOME'};
my $MYDIR="$home/website/lib";
my @files=glob('locale/*.js');
open my $fo, ">$MYDIR/air-datepicker-locales.js";
print $fo "var air_datepicker_locales = {\n";
while(my $file = shift @files) {
$var = $file;
$var =~ s/locale.([^.]+).*/$1/;
$var =~ s/[-]/_/g;
print $fo "$var: ";
open my $fh, "<$file";
$locales = 0;
while(my $line = <$fh>) {
if ($locales eq 1) {
if ($line=~/}[;]/) { $line=~s/[;]/,/; }
print $fo "$line";
}
if ($line=~/var\s+_default/) {
$locales = 1;
$line=~s/var\s+_default[^{]+//;
print $fo "$line";
} elsif ($line=~/}[,]/) {
$locales = 0;
}
}
close $fh;
}
print $fo "};\n";
print $fo "class AirDatepickerLocale\n";
print $fo "{\n";
print $fo " static get(lang) { if (air_datepicker_locales[lang] === undefined) { return this.get('en'); } else { return air_datepicker_locales[lang]; } }\n";
print $fo "}\n";
print $fo "export { AirDatepickerLocale };\n";
close $fo;
open my $fh, "<air-datepicker.js";
open my $fo, ">$MYDIR/air-datepicker.js";
print $fo "var exports = {};\n";
while(my $line = <$fh>) {
print $fo $line;
}
print $fo "function airDatepicker(elem, options = {}) { return new AirDatepicker(elem, options); }\n";
print $fo "var AirDatepicker = exports.AirDatepicker;\n";
print $fo "\nexport { AirDatepicker };\n";
close $fh;
close $fo; Now I can use the locales and the AirDatepicker as a module import in my javascript: import { AirDatepicker } from '../lib/air-datepicker.js';
import { AirDatepickerLocale } from '../lib/air-datepicker-locales.js';
(...)
this._pickr = new AirDatepicker('#' + id, {
locale: AirDatepickerLocale.get(language()),
});
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm following the instructions provided, but I get one error after another:
gives:
gives:
gives:
When I just include the air-datepicker with the script tag,
and later on I just instantiate a datepicker
it works.
However, when I try to import locales...
I get:
When I add this:
Lateron, I get an error:
Please explain what I should do to integrate air-datepicker in a simple standard javascript/html app.
The provided documentation is somehow not enough for me to get going.
The text was updated successfully, but these errors were encountered: