Skip to content

Commit b24967c

Browse files
update script priority
1 parent 970cf38 commit b24967c

File tree

6 files changed

+142
-11
lines changed

6 files changed

+142
-11
lines changed

assets/js/wcf-addons.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/* global WCF_ADDONS_JS */
2+
3+
(function ($) {
4+
/**
5+
* @param $scope The Widget wrapper element as a jQuery element
6+
* @param $ The jQuery alias
7+
*/
8+
9+
// Make sure you run this code under Elementor.
10+
$(window).on('elementor/frontend/init', function () {
11+
var device_width = $(window).width();
12+
var elementorBreakpoints = elementorFrontend.config.responsive.activeBreakpoints;
13+
var Modules = elementorModules.frontend.handlers.Base;
14+
var contact_form_7 = function contact_form_7($scope) {
15+
var submit_btn = $('.wpcf7-submit', $scope);
16+
var classes = submit_btn.attr('class');
17+
classes += ' wcf-btn-default ' + $('.wcf--form-wrapper', $scope).attr('btn-hover');
18+
submit_btn.replaceWith(function () {
19+
return $('<button/>', {
20+
html: $('.btn-icon').html() + submit_btn.attr('value'),
21+
"class": classes,
22+
type: 'submit'
23+
});
24+
});
25+
};
26+
var Countdown = Modules.extend({
27+
bindEvents: function bindEvents() {
28+
this.run();
29+
},
30+
run: function run() {
31+
var _this = this;
32+
// Update the count down every 1 second
33+
var x = setInterval(function () {
34+
_this.count_down(x);
35+
}, 1000);
36+
this.count_down(x);
37+
},
38+
count_down: function count_down(x) {
39+
// Set the date we're counting down to
40+
var countDownDate = new Date(this.getElementSettings('countdown_timer_due_date')).getTime();
41+
42+
// Get today's date and time
43+
var now = new Date().getTime();
44+
45+
// Find the distance between now and the count down date
46+
var distance = countDownDate - now;
47+
48+
// Time calculations for days, hours, minutes and seconds
49+
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
50+
var hours = Math.floor(distance % (1000 * 60 * 60 * 24) / (1000 * 60 * 60));
51+
var minutes = Math.floor(distance % (1000 * 60 * 60) / (1000 * 60));
52+
var seconds = Math.floor(distance % (1000 * 60) / 1000);
53+
54+
// If the count down is over, write some text
55+
if (distance < 0) {
56+
clearInterval(x);
57+
this.findElement('.wcf--countdown').html(this.time_finish_content());
58+
} else {
59+
this.findElement('.wcf--countdown').html(this.timer_content({
60+
'days': days,
61+
'hours': hours,
62+
'minutes': minutes,
63+
'seconds': seconds
64+
}));
65+
}
66+
},
67+
timer_content: function timer_content() {
68+
var _this2 = this;
69+
var times = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
70+
if (0 === times.length) {
71+
return;
72+
}
73+
var time_content = '';
74+
$.each(times, function (index, time) {
75+
var title = _this2.getElementSettings("countdown_timer_".concat(index, "_label"));
76+
time_content += "<div class=\"timer-content timer-item-".concat(index, " \"><span class=\"time-count ").concat(index, "-count\">").concat(time, "</span><span class=\"time-title ").concat(index, "-title\">").concat(title, "</span></div>");
77+
});
78+
return time_content;
79+
},
80+
time_finish_content: function time_finish_content() {
81+
var title = this.getElementSettings('time_expire_title');
82+
var description = this.getElementSettings('time_expire_desc');
83+
var finish_content = '<div class="countdown-expire">';
84+
if (title) {
85+
finish_content += "<div class=\"countdown-expire-title\">".concat(title, "</div>");
86+
}
87+
if (description) {
88+
finish_content += "<div class=\"countdown-expire-desc\">".concat(description, "</div>");
89+
}
90+
finish_content += '</div>';
91+
return finish_content;
92+
}
93+
});
94+
elementorFrontend.hooks.addAction("frontend/element_ready/wcf--contact-form-7.default", contact_form_7);
95+
elementorFrontend.hooks.addAction('frontend/element_ready/wcf--countdown.default', function ($scope) {
96+
elementorFrontend.elementsHandler.addHandler(Countdown, {
97+
$element: $scope
98+
});
99+
});
100+
var Search = function Search($scope) {
101+
var searchWrapper = $('.search--wrapper', $scope);
102+
var toggle_open = $('.toggle--open', $scope);
103+
var toggle_close = $('.toggle--close', $scope);
104+
toggle_open.on('click', function (e) {
105+
searchWrapper.addClass('search-visible');
106+
});
107+
toggle_close.on('click', function (e) {
108+
searchWrapper.removeClass('search-visible');
109+
});
110+
$("input", $scope).focus(function () {
111+
$(".wcf-search-form", $scope).addClass('wcf-search-form--focus');
112+
});
113+
$("input", $scope).focusout(function () {
114+
$(".wcf-search-form", $scope).removeClass('wcf-search-form--focus');
115+
});
116+
};
117+
elementorFrontend.hooks.addAction('frontend/element_ready/wcf--blog--search--form.default', Search);
118+
});
119+
})(jQuery);

assets/js/wcf-addons.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/src/js/wcf-addons.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
/**
55
* @param $scope The Widget wrapper element as a jQuery element
66
* @param $ The jQuery alias
7-
*/
8-
9-
7+
*/
108
// Make sure you run this code under Elementor.
119
$(window).on('elementor/frontend/init', function () {
1210

13-
const device_width = $(window).width();
14-
const elementorBreakpoints = elementorFrontend.config.responsive.activeBreakpoints;
15-
1611
const Modules = elementorModules.frontend.handlers.Base;
1712

1813
const contact_form_7 = function ($scope) {

class-plugin.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function widget_scripts() {
7474
'wcf-addons-core' => [
7575
'handler' => 'wcf--addons',
7676
'src' => 'wcf-addons.min.js',
77-
'dep' => [ 'jquery', 'elementor-frontend', 'elementor-frontend-modules' ],
77+
'dep' => [ 'jquery' ],
7878
'version' => false,
7979
'arg' => true,
8080
],
@@ -294,7 +294,7 @@ public static function get_widget_scripts() {
294294
'search' => [
295295
'handler' => 'aae--search',
296296
'src' => 'widgets/search.min.js',
297-
'dep' => [ 'jquery' ],
297+
'dep' => [ 'jquery','wcf-addons-core' ],
298298
'version' => false,
299299
'arg' => true,
300300
],
@@ -441,7 +441,7 @@ public static function get_widget_style() {
441441
'countdown' => [
442442
'handler' => 'wcf--countdown',
443443
'src' => 'widgets/countdown.min.css',
444-
'dep' => [],
444+
'dep' => ['wcf-addons-core'],
445445
'version' => false,
446446
'media' => 'all',
447447
],
@@ -897,7 +897,7 @@ public function __construct() {
897897
add_action( 'elementor/elements/categories_registered', [ $this, 'widget_categories' ] );
898898

899899
// Register widget scripts
900-
add_action( 'wp_enqueue_scripts', [ $this, 'widget_scripts' ] );
900+
add_action( 'wp_enqueue_scripts', [ $this, 'widget_scripts' ],29 );
901901

902902
// Register widget style
903903
add_action( 'wp_enqueue_scripts', [ $this, 'widget_styles' ] );

widgets/contact-form-7.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,19 @@ public function get_style_depends() {
8686
'wcf--button',
8787
);
8888
}
89-
89+
/**
90+
* Retrieve the list of scripts the widget depended on.
91+
*
92+
* Used to set scripts dependencies required to run the widget.
93+
*
94+
* @return array Widget scripts dependencies.
95+
* @since 1.0.0
96+
*
97+
* @access public
98+
*/
99+
public function get_script_depends() {
100+
return [ 'wcf-addons-core' ];
101+
}
90102
public function contactform_forms() {
91103
$formlist = array();
92104
$forms_args = array(

widgets/countdown.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public function get_style_depends() {
9393
return [ 'wcf--countdown' ];
9494
}
9595

96+
public function get_script_depends() {
97+
return [ 'wcf-addons-core' ];
98+
}
99+
96100
/**
97101
* Register the widget controls.
98102
*

0 commit comments

Comments
 (0)