PluginProbe
Themify Builder / trunk
Themify Builder vtrunk
7.8.1 7.8.0 7.7.9 7.7.8 7.7.7 7.7.6 7.7.5 7.7.4 7.7.3 7.7.2 trunk 7.6.0 7.6.1 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.8 7.6.9 7.7.0 7.7.1
themify-builder / themify / plugin-compat / formidable.php

formidable.php in Themify Builder trunk, at themify/plugin-compat/formidable.php

117 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Themify Compatibility Code
4 *
5 * @package Themify
6 */
7
8 /**
9 * Formidable Forms
10 * @link https://formidableforms.com/
11 */
12 class Themify_Compat_formidable {
13
14 static function init() {
15 if ( ! is_admin() ) {
16 add_action( 'wp_print_footer_scripts', [ __CLASS__, 'wp_print_footer_scripts' ], 1 );
17 add_action( 'frm_pro_before_footer_js', [ __CLASS__, 'frm_pro_before_footer_js' ], 1 );
18 }
19 }
20
21 public static function wp_print_footer_scripts() {
22 if ( wp_script_is( 'slimselect', 'enqueued' ) || wp_script_is( 'slimselect', 'done' ) ) {
23 wp_add_inline_script( 'slimselect', self::get_script(), 'after' );
24 }
25 }
26
27 public static function frm_pro_before_footer_js() {
28 echo '<script>' . self::get_script() . '</script>';
29 }
30
31 private static function get_script() {
32 return <<<'JS'
33 (function(){
34 if(!window.SlimSelect || window.SlimSelect.__themifyFrmCompat){
35 return;
36 }
37 var OriginalSlimSelect = window.SlimSelect,
38 skipClickUntil = 0,
39 allowProgrammaticClick = false;
40
41 function ThemifySlimSelectCompat(args){
42 var select = args && args.select;
43 if('string' === typeof select){
44 select = document.querySelector(select);
45 }
46 if(select && 'SELECT' === select.tagName && select.classList.contains('frm_slimselect') && select.slim){
47 select.style.display = 'none';
48 select.setAttribute('aria-hidden','true');
49 return select.slim;
50 }
51 return new OriginalSlimSelect(args);
52 }
53
54 function getFormidableSlimSelect(option){
55 var content = option.closest('.ss-content.frm_slimselect'),
56 id = content ? content.getAttribute('data-id') : null,
57 select;
58 if(!id){
59 return null;
60 }
61 try{
62 select = document.querySelector('select.frm_slimselect[data-id="' + CSS.escape(id) + '"]');
63 }
64 catch(e){
65 select = document.querySelector('select.frm_slimselect[data-id="' + id.replace(/"/g,'\\"') + '"]');
66 }
67 return select && select.slim ? select.slim : null;
68 }
69
70 function selectOptionOnPointerDown(e){
71 var option = e.target && e.target.closest ? e.target.closest('.ss-content.frm_slimselect .ss-option') : null,
72 slim;
73 if(!option || option.classList.contains('ss-disabled') || option.classList.contains('ss-hide')){
74 return;
75 }
76 if(e.type === 'pointerdown' && e.pointerType && e.pointerType !== 'mouse'){
77 return;
78 }
79 if(e.button !== undefined && e.button !== 0){
80 return;
81 }
82 slim = getFormidableSlimSelect(option);
83 if(!slim || !slim.settings || !slim.settings.isOpen){
84 return;
85 }
86 allowProgrammaticClick = true;
87 option.click();
88 allowProgrammaticClick = false;
89 skipClickUntil = Date.now() + 500;
90 e.preventDefault();
91 e.stopImmediatePropagation();
92 }
93
94 function suppressDuplicateClick(e){
95 if(!allowProgrammaticClick && skipClickUntil && Date.now() < skipClickUntil){
96 skipClickUntil = 0;
97 e.preventDefault();
98 e.stopImmediatePropagation();
99 }
100 }
101
102 ThemifySlimSelectCompat.prototype = OriginalSlimSelect.prototype;
103 for(var key in OriginalSlimSelect){
104 if(Object.prototype.hasOwnProperty.call(OriginalSlimSelect,key)){
105 ThemifySlimSelectCompat[key] = OriginalSlimSelect[key];
106 }
107 }
108 ThemifySlimSelectCompat.__themifyFrmCompat = true;
109 window.SlimSelect = ThemifySlimSelectCompat;
110
111 document.addEventListener('pointerdown', selectOptionOnPointerDown, true);
112 document.addEventListener('click', suppressDuplicateClick, true);
113 })();
114 JS;
115 }
116 }
117