| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking - Libraries |
| 4 |
* @subpackage html.plugins |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2018 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
$value = !empty($displayData['value']) ? $displayData['value'] : ''; |
| 15 |
$name = !empty($displayData['name']) ? $displayData['name'] : uniqid(); |
| 16 |
$id = !empty($displayData['id']) ? $displayData['id'] : $name; |
| 17 |
$class = !empty($displayData['class']) ? $displayData['class'] : ''; |
| 18 |
$format = !empty($displayData['format']) ? $displayData['format'] : 'Y-m-d'; |
| 19 |
$attr = !empty($displayData['attr']) ? $displayData['attr'] : ''; |
| 20 |
$showTime = !empty($displayData['showTime']) ? $displayData['showTime'] : false; |
| 21 |
|
| 22 |
?> |
| 23 |
|
| 24 |
<span class="wp-calendar-box"> |
| 25 |
|
| 26 |
<input |
| 27 |
type="text" |
| 28 |
name="<?php echo $name; ?>" |
| 29 |
id="<?php echo $id; ?>" |
| 30 |
class="<?php echo $class; ?> wp-datepicker" |
| 31 |
value="<?php echo $value; ?>" |
| 32 |
data-value="<?php echo $value; ?>" |
| 33 |
autocomplete="off" |
| 34 |
<?php echo $attr; ?> |
| 35 |
/> |
| 36 |
|
| 37 |
<i class="dashicons dashicons-calendar-alt"></i> |
| 38 |
|
| 39 |
</span> |
| 40 |
|
| 41 |
<script> |
| 42 |
|
| 43 |
jQuery('input[name="<?php echo $name; ?>"]').on('change', function() { |
| 44 |
<?php if ($showTime) { ?> |
| 45 |
var curr = jQuery(this).val(); |
| 46 |
var prev = jQuery(this).attr('data-value'); |
| 47 |
|
| 48 |
if (!curr) { |
| 49 |
// do nothing in case of empty dates |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
// extract time from previous date set |
| 54 |
var time = prev.match(/ (\d{1,2}:\d{1,2})$/); |
| 55 |
|
| 56 |
// check if we have a time and the selected date doesn't |
| 57 |
if (time && !curr.match(/ (\d{1,2}:\d{1,2})$/)) { |
| 58 |
// append time to current date |
| 59 |
curr += ' ' + time.pop(); |
| 60 |
} |
| 61 |
|
| 62 |
// update previous value with current one |
| 63 |
jQuery(this).attr('data-value', curr); |
| 64 |
jQuery(this).val(curr); |
| 65 |
<?php } ?> |
| 66 |
}); |
| 67 |
|
| 68 |
</script> |
| 69 |
|