PluginProbe
Depicter — Popup & Slider Builder / 1.3.8
Depicter — Popup & Slider Builder v1.3.8
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Modules / WPBakery / module.php

module.php in Depicter — Popup & Slider Builder 1.3.8, at app/src/Modules/WPBakery/module.php

177 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Depicter\Modules\WPBakery;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 class Module {
10
11 /**
12 * Class constructor
13 */
14 public function __construct() {
15 if ( function_exists( 'vc_map' ) ) {
16 $this->map_vc_shortcodes();
17
18 vc_add_shortcode_param( 'depicter_slider_buttons', [ $this, 'slider_buttons_markup' ] );
19 add_action( 'vc_edit_form_fields_after_render', [ $this, 'add_scripts' ] );
20 }
21 }
22
23 /**
24 * Add depicter shortcode to wpbakery
25 *
26 * @return void
27 */
28 public function map_vc_shortcodes() {
29
30 vc_map([
31 'name' => __( 'Depicter', 'depicter' ),
32 'base' => 'depicter',
33 'category' => __( 'Content', 'depicter' ),
34 'description' => __( 'Make animated and interactive slider', 'depicter' ),
35 'icon' => \Depicter::core()->assets()->getUrl() . '/resources/images/svg/logo-without-text.svg',
36 'params' => $this->get_fields()
37 ]);
38 }
39
40 /**
41 * get fields
42 *
43 * @return array
44 * @throws \Exception
45 */
46 public function get_fields() {
47
48 $list = [
49 __( 'Select Slider', 'depicter' ) => 0
50 ];
51 $documents = \Depicter::documentRepository()->select( ['id', 'name', 'status'] )->orderBy('modified_at', 'DESC')->findAll()->get();
52 $documents = $documents ? $documents->toArray() : [];
53 foreach( $documents as $document ) {
54 $list[ "[#{$document['id']}]: " . $document['name'] ] = $document['id'];
55 }
56
57 $fields = [
58 [
59 'type' => 'dropdown',
60 'class' => '',
61 'admin_label' => true,
62 'heading' => __( 'Select Slider', 'depicter' ),
63 'param_name' => 'id',
64 'value' => $list,
65 ]
66 ];
67
68 foreach( $documents as $document ) {
69
70 $fields[] = [
71 'type' => 'depicter_slider_buttons',
72 'class' => '',
73 'param_name' => 'slider_control_buttons_' . $document['id'],
74 'isPublishedBefore' => \Depicter::documentRepository()->isPublishedBefore( $document['id'] ),
75 'documentStatus' => $document['status'],
76 'dependency' => [
77 'element' => 'id',
78 'value' => 18
79 ]
80 ];
81 }
82
83 return $fields;
84 }
85
86 /**
87 * Add script to the end of editor fields after render
88 *
89 * @return void
90 */
91 public function add_scripts() {
92 if ( empty( $_POST['tag'] ) || $_POST['tag'] != 'depicter' ) {
93 return;
94 }
95
96 echo '<script type="text/javascript">
97 var $sliderButtons = document.querySelectorAll(\'[data-param_type="depicter_slider_buttons"]\');
98 document.querySelector(\'[data-vc-shortcode="depicter"]\').querySelector("select").addEventListener( "change", function(){
99 if ( this.value != 0 ) {
100 $sliderButtons.forEach(function(el, index){ el.style.display = \'none\';});
101 document.querySelector(\'[data-vc-shortcode-param-name="slider_control_buttons_\' +this.value+ \'"]\').style.display = "block";
102 }
103 });
104 $sliderButtons.forEach(function(el, index){ el.style.display = \'none\';});
105 var id = document.querySelector(\'[data-vc-shortcode="depicter"]\').querySelector("select").value;
106 if ( id != "0" ) {
107 document.querySelector(\'[data-vc-shortcode-param-name="slider_control_buttons_\' +id+ \'"]\').style.display = "block";
108 }
109
110 document.querySelectorAll(".depicter-edit-slider").forEach(function(el, index){
111 el.addEventListener( "click", function(){
112 var id = document.querySelector(\'[data-vc-shortcode="depicter"]\').querySelector("select").value;
113 var editorUrl = depicterParams.editorUrl.replace( \'document=1\', \'document=\' + id );
114 window.open(editorUrl);
115 });
116 });
117
118 $sliderButtons.forEach(function(el, index){
119 var $publishButton = el.querySelector(".depicter-publish-slider:not([disabled])");
120 if ( $publishButton ) {
121 $publishButton.addEventListener( "click", function(event){
122 event.target.querySelector(".btn-label").style.display = "none";
123 event.target.querySelector(".depicter-state-icon").style.display = "inline-block";
124
125 var id = document.querySelector(\'[data-vc-shortcode="depicter"]\').querySelector("select").value;
126 var data = new FormData();
127 data.append(\'ID\', id);
128 data.append(\'status\', \'published\');
129
130 fetch( depicterParams.ajaxUrl + "?action=depicter/document/store", {
131 method: \'post\',
132 body: data,
133 headers: {
134 \'X-DEPICTER-CSRF\': depicterParams.token
135 }
136 })
137 .then((response) => response.json())
138 .then((data) => {
139 if (data.hits) {
140 event.target.disabled = "true";
141 event.target.querySelector(".btn-label").innerHTML = depicterParams.publishedText;
142 var $depicterNoticeWrapper = document.querySelector(".depicter-notice-wrapper");
143 if ( $depicterNoticeWrapper ) {
144 $depicterNoticeWrapper.style.display = "none";
145 }
146 }
147 event.target.querySelector(".btn-label").style.display = "inline-block";
148 event.target.querySelector(".depicter-state-icon").style.display = "none";
149 el.querySelector(".depicter-notice-txts").style.display = "none";
150 }).catch((error) => {
151 console.error(error);
152 });
153 });
154
155 el.querySelector(".btn-label").addEventListener( "click", function(event) {
156 event.target.parentNode.click();
157 });
158 }
159 });
160
161 </script>';
162 }
163
164 /**
165 * Get slider buttons control field markup
166 *
167 * @param array $settings
168 * @param string $value
169 * @return string
170 */
171 public function slider_buttons_markup( $settings, $value ) {
172 return \Depicter::view('admin/notices/builders-draft-notice')->with('view_args', $settings)->toString();
173 }
174 }
175
176 new Module();
177