diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 4f2811457a5303ce688ae1f853d6da31f3101b16..0000000000000000000000000000000000000000 --- a/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -infusion/* diff --git a/README.md b/README.md index 9e4e60e7ebd887e769cbbc16579dc34ba0926b51..14b5e11ba792378e1a7fb5ec3b865c8ab0bde99d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Table of contents Introduction ------------ -The Date Timepicker module adds one of 3 jQuery plugins to any DateTime field in +The Date Timepicker module adds one of 4 jQuery plugins to any DateTime field in the Widget settings. Features: @@ -38,6 +38,7 @@ The Date Timepicker module requires the following JavaScript libraries: - [jQuery UI Timepicker](https://github.com/fgelinas/timepicker) - [jQuery Timepicker Addon](https://github.com/trentrichardson/jQuery -Timepicker-Addon) +- [Flatpickr Plugin](https://flatpickr.js.org/#introduction) Follow the installation instructions below for installing the module and the libraries. @@ -71,7 +72,23 @@ Installation "/libraries/jquery-ui-timepicker" folder. - Extract the jQuery Timepicker Addon library into the "/libraries/jquery-timepicker-addon" folder. +- Extract the Flatpickr library into the + "/libraries/flatpickr" + There is also a `composer.libraries.json` which you can use to copy and paste the library repositories in your site's `composer.json` file and use composer to download the libraries + + ``` + composer require "jonthornton-jquery-timepicker/jonthornton-jquery-timepicker" + composer require "jquery-ui-timepicker/jquery-ui-timepicker" + composer require "jquery-addon-timepicker/jquery-addon-timepicker + composer require "flatpickr-library/flatpickr-library" + ``` +6. Additional steps for installing the **flatpickr** library + + You will need **NodeJS** and **npm** installed for these steps, go to the **/libraries/flatpickr** directory and run: + + - `npm install` to install the library dependencies + - `npm run build` to compile the library and create a **dist** directory with the js and css files that the module needs. Configuration ------------- diff --git a/composer.json b/composer.json index 442a04ca52996102bc13c3909c0a3643fff6b753..bc5aa46527b59baf7041efb04563250a08c5dda3 100644 --- a/composer.json +++ b/composer.json @@ -5,16 +5,6 @@ "license": "GPL-2.0+", "homepage": "https://www.drupal.org/project/timepicker", "authors": [ - { - "name": "Ivan Tibezh (tibezh)", - "homepage": "https://www.drupal.org/u/tibezh", - "role": "Maintainer" - }, - { - "name": "Lilian Catanoi (liliancatanoi90)", - "homepage": "https://www.drupal.org/u/liliancatanoi90", - "role": "Maintainer" - }, { "name": "Daniel Rodriguez (danrod)", "homepage": "https://www.drupal.org/u/danrod", diff --git a/composer.libraries.json b/composer.libraries.json index 9bb2e5c727b10873d9d53cba05ea691054285fe1..b0b0ac5fc296cfcde7f12761367ee872c0b2d5ea 100644 --- a/composer.libraries.json +++ b/composer.libraries.json @@ -52,10 +52,10 @@ } } }, - "jquery-timepicker-addon": { + "jquery-addon-timepicker": { "type": "package", "package": { - "name": "jquery-timepicker-addon/jquery-timepicker-addon", + "name": "jquery-addon-timepicker/jquery-addon-timepicker", "version": "1.6.3", "type": "drupal-library", "extra": { @@ -66,12 +66,28 @@ "type": "zip" } } + }, + "flatpickr-library": { + "type": "package", + "package": { + "name": "flatpickr/flatpickr", + "version": "4.6.13", + "type": "drupal-library", + "extra": { + "installer-name": "flatpickr" + }, + "dist": { + "url": "https://github.com/flatpickr/flatpickr/archive/refs/tags/v4.6.13.zip", + "type": "zip" + } + } } }, "require": { "jonthornton-jquery-timepicker/jonthornton-jquery-timepicker": "1.14.1", "jquery-ui-timepicker/jquery-ui-timepicker": "0.3.3", - "jquery-timepicker-addon/jquery-timepicker-addon": "1.6.3" + "jquery-addon-timepicker/jquery-addon-timepicker": "1.6.3", + "flatpickr-library/flatpickr-library": "4.6.13" } } \ No newline at end of file diff --git a/js/flatpickr.js b/js/flatpickr.js new file mode 100644 index 0000000000000000000000000000000000000000..ec8ab7aaaf1e1bf49c5464e1aabbc995fb2434c4 --- /dev/null +++ b/js/flatpickr.js @@ -0,0 +1,31 @@ +/** + * @file + * + * Callback for flatpickr. + */ + +(function ($) { + Drupal.behaviors.flatpickr = { + attach:(context, settings) => { + + const fieldName = []; + + Object.keys(settings.timepicker.flatpickr_timepicker).forEach((key, index) => { + if (key !== null) { + fieldName[index] = key; + } + }); + + const requiredOptions = { + enableTime: true, + noCalendar: true, + dateFormat: "H:i", + }; + + for (let i = 0; i < fieldName.length; i++) { + $('input[name="' + fieldName[i] + '[' + i + '][value][time]"').flatpickr(requiredOptions); + } + } + }; + +}(jQuery)); diff --git a/timepicker.libraries.yml b/timepicker.libraries.yml index 481588267eab5dc97acae2b326de7a577e1b7d1b..520cce88edc98244ad3c6bf6f2bf31e4a4b6ca65 100644 --- a/timepicker.libraries.yml +++ b/timepicker.libraries.yml @@ -23,6 +23,14 @@ jquery-addon-timepicker: - core/jquery - timepicker/jquery.ui.timepicker.addon +flatpickr-timepicker: + version: VERSION + js: + js/flatpickr.js: { } + dependencies: + - core/jquery + - timepicker/flatpickr-library + # Define third-party libraries. jonthornton-jquery-timepicker: remote: https://github.com/jonthornton/jquery-timepicker @@ -61,13 +69,27 @@ jquery.ui.timepicker.addon: gpl-compatible: false css: theme: - /libraries/jquery-timepicker-addon/dist/jquery-ui-timepicker-addon.css: { } + /libraries/jquery-addon-timepicker/dist/jquery-ui-timepicker-addon.css: { } js: - libraries/jquery-ui/jquery-ui.min.js: {} - /libraries/jquery-timepicker-addon/dist/jquery-ui-timepicker-addon.js: { } + /libraries/jquery-addon-timepicker/dist/jquery-ui-timepicker-addon.js: { } dependencies: - core/jquery-ui - jquery_ui/core - jquery_ui/widget - jquery_ui_datepicker/datepicker - jquery_ui/jquery.ui.slider + +flatpickr-library: + remote: https://github.com/flatpickr/flatpickr + version: VERSION + license: + name: MIT + url: https://github.com/flatpickr/flatpickr/blob/master/LICENSE.md + gpl-compatible: false + css: + theme: + /libraries/flatpickr/dist/flatpickr.css: { } + js: + /libraries/flatpickr/dist/flatpickr.js: { } + dependencies: + - core/jquery \ No newline at end of file diff --git a/timepicker.module b/timepicker.module index 1b3b73cb5f4ae3e7040ec10eb73f4dc74965cf12..ff86267e7e7dcc03790b179f591656a09af74cbb 100644 --- a/timepicker.module +++ b/timepicker.module @@ -114,6 +114,22 @@ function timepicker_timepicker_libraries() { 'http://trentrichardson.com/examples/timepicker/#tp-options', ], ], + 'timepicker_flatpickr' => [ + 'title' => 'Flatpickr JS', + 'callback library' => [ + 'extension' => 'timepicker', + 'name' => 'flatpickr-timepicker', + ], + 'depended library' => [ + 'extension' => 'timepicker', + 'name' => 'flatpickr-library', + 'download url' => + 'https://github.com/flatpickr/flatpickr/archive/master.zip', + 'library path' => '/libraries/flatpickr', + 'js options reference url' => + 'https://flatpickr.js.org/getting-started', + ], + ], ]; }