init
This commit is contained in:
3
wp-content/themes/flatsome/inc/shortcodes/ux_countdown/countdown-script-min.js
vendored
Normal file
3
wp-content/themes/flatsome/inc/shortcodes/ux_countdown/countdown-script-min.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
//http://hilios.github.io/jQuery.countdown/
|
||||
|
||||
!function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"use strict";function b(a){if(a instanceof Date)return a;if(String(a).match(g))return String(a).match(/^[0-9]*$/)&&(a=Number(a)),String(a).match(/\-/)&&(a=String(a).replace(/\-/g,"/")),new Date(a);throw new Error("Couldn't cast `"+a+"` to a date object.")}function c(a){var b=a.toString().replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1");return new RegExp(b)}function d(a){return function(b){var d=b.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi);if(d)for(var f=0,g=d.length;g>f;++f){var h=d[f].match(/%(-|!)?([a-zA-Z]{1})(:[^;]+;)?/),j=c(h[0]),k=h[1]||"",l=h[3]||"",m=null;h=h[2],i.hasOwnProperty(h)&&(m=i[h],m=Number(a[m])),null!==m&&("!"===k&&(m=e(l,m)),""===k&&10>m&&(m="0"+m.toString()),b=b.replace(j,m.toString()))}return b=b.replace(/%%/,"%")}}function e(a,b){var c="s",d="";return a&&(a=a.replace(/(:|;|\s)/gi,"").split(/\,/),1===a.length?c=a[0]:(d=a[0],c=a[1])),1===Math.abs(b)?d:c}var f=[],g=[],h={precision:100,elapse:!1};g.push(/^[0-9]*$/.source),g.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),g.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),g=new RegExp(g.join("|"));var i={Y:"years",m:"months",n:"daysToMonth",w:"weeks",d:"daysToWeek",D:"totalDays",H:"hours",M:"minutes",S:"seconds"},j=function(b,c,d){this.el=b,this.$el=a(b),this.interval=null,this.offset={},this.options=a.extend({},h),this.instanceNumber=f.length,f.push(this),this.$el.data("countdown-instance",this.instanceNumber),d&&("function"==typeof d?(this.$el.on("update.countdown",d),this.$el.on("stoped.countdown",d),this.$el.on("finish.countdown",d)):this.options=a.extend({},h,d)),this.setFinalDate(c),this.start()};a.extend(j.prototype,{start:function(){null!==this.interval&&clearInterval(this.interval);var a=this;this.update(),this.interval=setInterval(function(){a.update.call(a)},this.options.precision)},stop:function(){clearInterval(this.interval),this.interval=null,this.dispatchEvent("stoped")},toggle:function(){this.interval?this.stop():this.start()},pause:function(){this.stop()},resume:function(){this.start()},remove:function(){this.stop.call(this),f[this.instanceNumber]=null,delete this.$el.data().countdownInstance},setFinalDate:function(a){this.finalDate=b(a)},update:function(){if(0===this.$el.closest("html").length)return void this.remove();var b,c=void 0!==a._data(this.el,"events"),d=new Date;b=this.finalDate.getTime()-d.getTime(),b=Math.ceil(b/1e3),b=!this.options.elapse&&0>b?0:Math.abs(b),this.totalSecsLeft!==b&&c&&(this.totalSecsLeft=b,this.elapsed=d>=this.finalDate,this.offset={seconds:this.totalSecsLeft%60,minutes:Math.floor(this.totalSecsLeft/60)%60,hours:Math.floor(this.totalSecsLeft/60/60)%24,days:Math.floor(this.totalSecsLeft/60/60/24)%7,daysToWeek:Math.floor(this.totalSecsLeft/60/60/24)%7,daysToMonth:Math.floor(this.totalSecsLeft/60/60/24%30.4368),totalDays:Math.floor(this.totalSecsLeft/60/60/24),weeks:Math.floor(this.totalSecsLeft/60/60/24/7),months:Math.floor(this.totalSecsLeft/60/60/24/30.4368),years:Math.abs(this.finalDate.getFullYear()-d.getFullYear())},this.options.elapse||0!==this.totalSecsLeft?this.dispatchEvent("update"):(this.stop(),this.dispatchEvent("finish")))},dispatchEvent:function(b){var c=a.Event(b+".countdown");c.finalDate=this.finalDate,c.elapsed=this.elapsed,c.offset=a.extend({},this.offset),c.strftime=d(this.offset),this.$el.trigger(c)}}),a.fn.countdown=function(){var b=Array.prototype.slice.call(arguments,0);return this.each(function(){var c=a(this).data("countdown-instance");if(void 0!==c){var d=f[c],e=b[0];j.prototype.hasOwnProperty(e)?d[e].apply(d,b.slice(1)):null===String(e).match(/^[$A-Z_][0-9A-Z_$]*$/i)?(d.setFinalDate.call(d,e),d.start()):a.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi,e))}else new j(this,b[0],b[1])})}});
|
@@ -0,0 +1,40 @@
|
||||
/* UX Countdown Shortcode Styles */
|
||||
.ux-timer{
|
||||
width:100%;
|
||||
position:relative;
|
||||
border-spacing: 5px;
|
||||
margin: .3em 0 .2em;
|
||||
font-size: 300%;
|
||||
display: table;
|
||||
table-layout: fixed;
|
||||
}
|
||||
.ux-timer span{
|
||||
display:table-cell;
|
||||
font-weight: bolder;
|
||||
text-align: center;
|
||||
color:#FFF;
|
||||
line-height: 80%;
|
||||
padding: .4em .1em .1em;
|
||||
margin:0 .05em .2em;
|
||||
border-radius: 5px;
|
||||
background-color: rgba(0,0,0,.85);
|
||||
}
|
||||
.ux-timer span strong{
|
||||
font-family: 'Helvetica' Sans-serif;
|
||||
font-size: 30%;
|
||||
opacity: .7;
|
||||
text-transform: uppercase;
|
||||
display: block;
|
||||
}
|
||||
.ux-timer.light span{
|
||||
background-color: rgba(255,255,255,.85);
|
||||
color: #000;
|
||||
}
|
||||
.ux-timer-text span{
|
||||
font-weight: bolder;
|
||||
display: inline-block;
|
||||
margin: 0 .35em
|
||||
}
|
||||
.ux-timer-text strong{
|
||||
margin-left: .2em
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
Flatsome.behavior('ux-countdown', {
|
||||
attach: function (context) {
|
||||
jQuery('[data-countdown]', context).each(function () {
|
||||
var $this = jQuery(this), finalDate = jQuery(this).data('countdown');
|
||||
|
||||
var t_hour = jQuery(this).data('text-hour'),
|
||||
t_min = jQuery(this).data('text-min'),
|
||||
t_week = jQuery(this).data('text-week'),
|
||||
t_day = jQuery(this).data('text-day'),
|
||||
t_sec = jQuery(this).data('text-sec'),
|
||||
t_min_p = jQuery(this).data('text-min-p'),
|
||||
t_hour_p = jQuery(this).data('text-hour-p'),
|
||||
t_week_p = jQuery(this).data('text-week-p'),
|
||||
t_day_p = jQuery(this).data('text-day-p'),
|
||||
t_sec_p = jQuery(this).data('text-sec-p'),
|
||||
t_plural = jQuery(this).data('text-plural');
|
||||
|
||||
var hours_plural = t_hour+t_plural;
|
||||
var days_plural = t_day+t_plural;
|
||||
var weeks_plural = t_week+t_plural;
|
||||
var min_plural = t_min;
|
||||
var sec_plural = t_sec;
|
||||
|
||||
if(t_hour_p) hours_plural = t_hour_p;
|
||||
if(t_min_p) min_plural = t_min_p;
|
||||
if(t_week_p) weeks_plural = t_week_p;
|
||||
if(t_day_p) days_plural = t_day_p;
|
||||
if(t_sec_p) sec_plural = t_sec_p;
|
||||
|
||||
$this.countdown(finalDate).on('update.countdown', function (event) {
|
||||
var format = '<span>%-H<strong>%!H:'+t_hour+','+hours_plural+';</strong></span><span>%-M<strong>%!M:'+t_min+','+min_plural+';</strong></span><span>%-S<strong>%!S:'+t_sec+','+sec_plural+';</strong></span>';
|
||||
|
||||
if(event.offset.days > 0) { format = '<span>%-d<strong>%!d:'+t_day+','+days_plural+';</strong></span>' + format; }
|
||||
if(event.offset.weeks > 0) { format = '<span>%-w<strong>%!w:'+t_week+','+weeks_plural+';</strong></span>' + format; }
|
||||
|
||||
jQuery(this).html(event.strftime(format));
|
||||
|
||||
}).on('finish.countdown', function (event) {
|
||||
var format = '<span>%-H<strong>%!H:'+t_hour+','+hours_plural+';</strong></span><span>%-M<strong>%!M:'+t_min+','+min_plural+';</strong></span><span>%-S<strong>%!S:'+t_sec+','+sec_plural+';</strong></span>';
|
||||
jQuery(this).html(event.strftime(format));
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
// Register scripts
|
||||
function flatsome_countdown_shortcode_scripts() {
|
||||
wp_register_style( 'flatsome-countdown-style', get_template_directory_uri() . '/inc/shortcodes/ux_countdown/ux-countdown.css', 'flatsome-style');
|
||||
wp_register_script( 'flatsome-countdown-script', get_template_directory_uri() . '/inc/shortcodes/ux_countdown/countdown-script-min.js', 'flatsome-countdown-script');
|
||||
wp_register_script( 'flatsome-countdown-theme-js', get_template_directory_uri() . '/inc/shortcodes/ux_countdown/ux-countdown.js', 'flatsome-js', '3.2.6', true);
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'flatsome_countdown_shortcode_scripts' );
|
||||
|
||||
// Register Shortcode
|
||||
function ux_countdown_shortcode( $atts ){
|
||||
$atts = shortcode_atts( array(
|
||||
'_id' => 'timer-'.rand(),
|
||||
'before' => '',
|
||||
'after' => '',
|
||||
'year' => '2021',
|
||||
'month' => '12',
|
||||
'day' => '31',
|
||||
'color' => 'dark',
|
||||
'bg_color' => '',
|
||||
'bg_color__md' => '',
|
||||
'bg_color__sm' => '',
|
||||
'time' => '18:00',
|
||||
'style' => 'clock',
|
||||
'size' => '300',
|
||||
'size__md' => '',
|
||||
'size__sm' => '',
|
||||
't_hour' => 'hour',
|
||||
't_min' => 'min',
|
||||
't_day' => 'day',
|
||||
't_week' => 'week',
|
||||
't_sec' => 'sec',
|
||||
//
|
||||
't_plural' => 's',
|
||||
't_hour_p' => '',
|
||||
't_min_p' => '',
|
||||
't_day_p' => '',
|
||||
't_week_p' => '',
|
||||
't_sec_p' => '',
|
||||
|
||||
), $atts );
|
||||
|
||||
extract( $atts );
|
||||
|
||||
wp_enqueue_style('flatsome-countdown-style');
|
||||
wp_enqueue_script('flatsome-countdown-script');
|
||||
wp_enqueue_script('flatsome-countdown-theme-js');
|
||||
|
||||
$date = $year.'/'.$month.'/'.$day;
|
||||
|
||||
// Fix Time
|
||||
if($time == '24:00') $time = '23:59:59';
|
||||
|
||||
if($time) $date = $date.' '.$time;
|
||||
|
||||
$args = array(
|
||||
'size' => array(
|
||||
'selector' => '',
|
||||
'unit' => '%',
|
||||
'property' => 'font-size',
|
||||
),
|
||||
'bg_color' => array(
|
||||
'selector' => 'span',
|
||||
'property' => 'background-color',
|
||||
),
|
||||
);
|
||||
// data-text-hour-p="'.$t_hour_p.'" data-text-day-p="'.$t_day_p.'" data-text-week-p="'.$t_week_p.'" data-text-min-p="'.$t_min_p.'" data-text-sec-p="'.$t_sec_p.'"
|
||||
// Texts
|
||||
$translations = 'data-text-plural="'.$t_plural.'" data-text-hour="'.$t_hour.'" data-text-day="'.$t_day.'" data-text-week="'.$t_week.'" data-text-min="'.$t_min.'" data-text-sec="'.$t_sec.'"';
|
||||
|
||||
// Add plurals
|
||||
if(isset($t_hour_p) || isset($t_day_p)) {
|
||||
$translations = $translations.' '.'data-text-hour-p="'.$t_hour_p.'" data-text-day-p="'.$t_day_p.'" data-text-week-p="'.$t_week_p.'" data-text-min-p="'.$t_min_p.'" data-text-sec-p="'.$t_sec_p.'"';
|
||||
}
|
||||
|
||||
if($style == 'clock'){
|
||||
return $before.'<div id="'.$_id.'" class="ux-timer '.$color.'" '.$translations.' data-countdown="'.$date.'"><span> <div class="loading-spin dark centered"></div><strong> </strong></span></div>'.ux_builder_element_style_tag($_id, $args, $atts).$after;
|
||||
} else{
|
||||
return $before.'<span id="'.$_id.'" class="ux-timer-text" '.$translations.' data-countdown="'.$date.'"></span>'.ux_builder_element_style_tag($_id, $args, $atts).''.$after;
|
||||
}
|
||||
}
|
||||
add_shortcode('ux_countdown', 'ux_countdown_shortcode');
|
Reference in New Issue
Block a user