Skip to content

Commit

Permalink
count down default time removed to fix static time issue and Label co…
Browse files Browse the repository at this point in the history
…ntrol added for days,minuts etc text
  • Loading branch information
codersaiful committed Feb 26, 2021
1 parent f1f64a5 commit 9014cd7
Showing 1 changed file with 94 additions and 22 deletions.
116 changes: 94 additions & 22 deletions inc/widgets/count-down-timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function _register_controls() {

//For General Section
$this->content_general_controls();

$this->content_label();
//For Design Section Style Tab
$this->style_design_controls();

Expand All @@ -70,6 +70,12 @@ protected function render() {
$date = $settings['date_time'];
$date_time = date( 'm/d/Y H:i', strtotime($date) );

//Label's
$days = $settings['days'];
$hours = $settings['hours'];
$minutes = $settings['minutes'];
$seconds = $settings['seconds'];

/**
* Filter for Changing Date and time.
*
Expand All @@ -86,37 +92,42 @@ protected function render() {
<div class="ua-coun-down-timer <?php echo esc_attr( $unique_class ); ?>">
<div class="single-date">
<span class="timer_int days">00 </span>
<span class="timer_label"><?php echo esc_html__( 'Days', 'ultraaddons' )?></span>
<span class="timer_label"><?php echo $days; ?></span>
</div>
<?php echo $separator; ?>
<div class="single-date">
<span class="timer_int hrs">00 </span>
<span class="timer_label"><?php echo esc_html__( 'Hours', 'ultraaddons' )?></span>
<span class="timer_label"><?php echo esc_html( $hours ); ?></span>
</div>
<?php echo $separator; ?>
<div class="single-date">
<span class="timer_int mnts">00 </span>
<span class="timer_label"><?php echo esc_html__( 'Minutes', 'ultraaddons' )?></span>
<span class="timer_label"><?php echo esc_html( $minutes ); ?></span>
</div>
<?php echo $separator; ?>
<div class="single-date">
<span class="timer_int secs">00 </span>
<span class="timer_label"><?php echo esc_html__( 'Seconds', 'ultraaddons' )?></span>
<span class="timer_label"><?php echo esc_html( $seconds ); ?></span>
</div>
</div>
</div>
<script type="text/javascript">

// Countdown for page 4
function getTimeRemaining(endtime) {
if(Date.parse(endtime) < Date.parse(new Date())){

var current_time = Date.parse(new Date());
var finis_time = Date.parse(endtime);

if(finis_time < current_time){
return;
}
const total = Date.parse(endtime) - Date.parse(new Date());
const seconds = Math.floor((total / 1000) % 60);
const minutes = Math.floor((total / 1000 / 60) % 60);
const hours = Math.floor((total / (1000 * 60 * 60)) % 24);
const days = Math.floor(total / (1000 * 60 * 60 * 24));

var total = finis_time - current_time;
var seconds = Math.floor((total / 1000) % 60);
var minutes = Math.floor((total / 1000 / 60) % 60);
var hours = Math.floor((total / (1000 * 60 * 60)) % 24);
var days = Math.floor(total / (1000 * 60 * 60 * 24));

return {
total,
Expand All @@ -127,9 +138,9 @@ function getTimeRemaining(endtime) {
};
}

function initializeClock(id, endtime) {
function initializeClock(endtime) {
try{
// const clock = document.getElementById('countdownsss');

var clock = document.querySelector('.<?php echo esc_attr( $unique_class ); ?>');
var daysSpan = clock.querySelector('.days');
var hoursSpan = clock.querySelector('.hrs');
Expand Down Expand Up @@ -157,16 +168,81 @@ function updateClock() {
}
}

var deadline = new Date(Date.parse('<?php echo esc_attr( $settings['date_time'] ); ?>'));// new Date(Date.parse(new Date()) + 15 * 24 * 60 * 60 * 1000);
// const deadline = new Date(Date.parse('1/25/2021 10:20:00'));// new Date(Date.parse(new Date()) + 15 * 24 * 60 * 60 * 1000);
// console.log(deadline,new Date(Date.parse('1/25/2021 10:20:00')));
initializeClock('countdown', deadline);
var deadline = new Date(Date.parse('<?php echo esc_attr( $date_time ); ?>'));
initializeClock(deadline);
</script>

<?php

}

protected function content_label(){
$this->start_controls_section(
'label',
[
'label' => esc_html__( 'Label', 'ultraaddons' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);


$this->add_control(
'days',
[
'label' => __( 'Day', 'ultraaddons' ),
'type' => Controls_Manager::TEXT,
'placeholder' => __( 'eg: Days', 'ultraaddons' ),
'label_block' => TRUE,
'dynamic' => ['active' => true],
'default' => esc_html__( 'Days', 'ultraaddons' ),
]
);


$this->add_control(
'hours',
[
'label' => __( 'Hour', 'ultraaddons' ),
'type' => Controls_Manager::TEXT,
'placeholder' => __( 'eg: Hours', 'ultraaddons' ),
'label_block' => TRUE,
'dynamic' => ['active' => true],
'default' => esc_html__( 'Hours', 'ultraaddons' ),
]
);


$this->add_control(
'minutes',
[
'label' => __( 'Minute', 'ultraaddons' ),
'type' => Controls_Manager::TEXT,
'placeholder' => __( 'eg: Minutes', 'ultraaddons' ),
'label_block' => TRUE,
'dynamic' => ['active' => true],
'default' => esc_html__( 'Minutes', 'ultraaddons' ),
]
);


$this->add_control(
'seconds',
[
'label' => __( 'Second', 'ultraaddons' ),
'type' => Controls_Manager::TEXT,
'placeholder' => __( 'eg: Seconds', 'ultraaddons' ),
'label_block' => TRUE,
'dynamic' => ['active' => true],
'default' => esc_html__( 'Seconds', 'ultraaddons' ),
]
);



$this->end_controls_section();

}

/**
* General Section for Content Controls
*
Expand All @@ -181,16 +257,12 @@ protected function content_general_controls() {
]
);

$default_date_time = date( 'Y-m-d H:i', ( time() + ( 86400 * 16 ) ) );

$this->add_control(
'date_time',
[
'label' => __( 'End Date', 'ultraaddons' ),
'type' => Controls_Manager::DATE_TIME,
//'default' => 'YYYY-mm-dd HH:ii',
##'default' => 'mm/dd/YYYY HH:ii',
'default' => $default_date_time,//'2021-01-25 12:00',
'frontend_available' => true,
]
);

Expand Down

0 comments on commit 9014cd7

Please sign in to comment.