| @@ 428-518 (lines=91) @@ | ||
| 425 | * @since 1.0.6 |
|
| 426 | * @return mixed |
|
| 427 | */ |
|
| 428 | public static function siteorigin_js() { |
|
| 429 | ob_start(); |
|
| 430 | ?> |
|
| 431 | <script> |
|
| 432 | /** |
|
| 433 | * Check a form to see what items shoudl be shown or hidden. |
|
| 434 | */ |
|
| 435 | function sd_so_show_hide(form) { |
|
| 436 | jQuery(form).find(".sd-argument").each(function () { |
|
| 437 | ||
| 438 | var $element_require = jQuery(this).data('element_require'); |
|
| 439 | ||
| 440 | if ($element_require) { |
|
| 441 | ||
| 442 | $element_require = $element_require.replace("'", "'"); // replace single quotes |
|
| 443 | $element_require = $element_require.replace(""", '"'); // replace double quotes |
|
| 444 | ||
| 445 | if (eval($element_require)) { |
|
| 446 | jQuery(this).removeClass('sd-require-hide'); |
|
| 447 | } else { |
|
| 448 | jQuery(this).addClass('sd-require-hide'); |
|
| 449 | } |
|
| 450 | } |
|
| 451 | }); |
|
| 452 | } |
|
| 453 | ||
| 454 | /** |
|
| 455 | * Toggle advanced settings visibility. |
|
| 456 | */ |
|
| 457 | function sd_so_toggle_advanced($this) { |
|
| 458 | var form = jQuery($this).parents('form,.form,.so-content'); |
|
| 459 | form.find('.sd-advanced-setting').toggleClass('sd-adv-show'); |
|
| 460 | return false;// prevent form submit |
|
| 461 | } |
|
| 462 | ||
| 463 | /** |
|
| 464 | * Initialise a individual widget. |
|
| 465 | */ |
|
| 466 | function sd_so_init_widget($this, $selector) { |
|
| 467 | if (!$selector) { |
|
| 468 | $selector = 'form'; |
|
| 469 | } |
|
| 470 | // only run once. |
|
| 471 | if (jQuery($this).data('sd-widget-enabled')) { |
|
| 472 | return; |
|
| 473 | } else { |
|
| 474 | jQuery($this).data('sd-widget-enabled', true); |
|
| 475 | } |
|
| 476 | ||
| 477 | var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>'; |
|
| 478 | var form = jQuery($this).parents('' + $selector + ''); |
|
| 479 | ||
| 480 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
|
| 481 | jQuery(form).append($button); |
|
| 482 | } |
|
| 483 | ||
| 484 | // show hide on form change |
|
| 485 | jQuery(form).change(function () { |
|
| 486 | sd_so_show_hide(form); |
|
| 487 | }); |
|
| 488 | ||
| 489 | // show hide on load |
|
| 490 | sd_so_show_hide(form); |
|
| 491 | } |
|
| 492 | ||
| 493 | jQuery(function () { |
|
| 494 | jQuery(document).on('open_dialog', function (w, e) { |
|
| 495 | setTimeout(function () { |
|
| 496 | if (jQuery('.so-panels-dialog-wrapper:visible .so-content.panel-dialog .sd-show-advanced').length) { |
|
| 497 | console.log('exists'); |
|
| 498 | if (jQuery('.so-panels-dialog-wrapper:visible .so-content.panel-dialog .sd-show-advanced').val() == '1') { |
|
| 499 | console.log('true'); |
|
| 500 | sd_so_init_widget('.so-panels-dialog-wrapper:visible .so-content.panel-dialog .sd-show-advanced', 'div'); |
|
| 501 | } |
|
| 502 | } |
|
| 503 | }, 200); |
|
| 504 | }); |
|
| 505 | }); |
|
| 506 | </script> |
|
| 507 | <?php |
|
| 508 | $output = ob_get_clean(); |
|
| 509 | ||
| 510 | /* |
|
| 511 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
|
| 512 | */ |
|
| 513 | ||
| 514 | return str_replace( array( |
|
| 515 | '<script>', |
|
| 516 | '</script>' |
|
| 517 | ), '', $output ); |
|
| 518 | } |
|
| 519 | ||
| 520 | /** |
|
| 521 | * Output the JS and CSS for the shortcode insert button. |
|
| @@ 1003-1036 (lines=34) @@ | ||
| 1000 | * |
|
| 1001 | * @return mixed |
|
| 1002 | */ |
|
| 1003 | public function widget_css() { |
|
| 1004 | ob_start(); |
|
| 1005 | ?> |
|
| 1006 | <style> |
|
| 1007 | .sd-advanced-setting { |
|
| 1008 | display: none; |
|
| 1009 | } |
|
| 1010 | ||
| 1011 | .sd-advanced-setting.sd-adv-show { |
|
| 1012 | display: block; |
|
| 1013 | } |
|
| 1014 | ||
| 1015 | .sd-argument.sd-require-hide, |
|
| 1016 | .sd-advanced-setting.sd-require-hide { |
|
| 1017 | display: none; |
|
| 1018 | } |
|
| 1019 | ||
| 1020 | button.sd-advanced-button { |
|
| 1021 | margin-right: 3px !important; |
|
| 1022 | font-size: 20px !important; |
|
| 1023 | } |
|
| 1024 | ||
| 1025 | button.sd-toggle-group-button{ |
|
| 1026 | background-color: #f3f3f3; |
|
| 1027 | color: #23282d; |
|
| 1028 | cursor: pointer; |
|
| 1029 | padding: 10px; |
|
| 1030 | width: 100%; |
|
| 1031 | border: none; |
|
| 1032 | text-align: left; |
|
| 1033 | outline: none; |
|
| 1034 | font-size: 13px; |
|
| 1035 | font-weight: bold; |
|
| 1036 | margin-bottom: 1px; |
|
| 1037 | } |
|
| 1038 | </style> |
|
| 1039 | <?php |
|
| @@ 1057-1224 (lines=168) @@ | ||
| 1054 | * |
|
| 1055 | * @return mixed |
|
| 1056 | */ |
|
| 1057 | public function widget_js() { |
|
| 1058 | ob_start(); |
|
| 1059 | ?> |
|
| 1060 | <script> |
|
| 1061 | ||
| 1062 | /** |
|
| 1063 | * Toggle advanced settings visibility. |
|
| 1064 | */ |
|
| 1065 | function sd_toggle_advanced($this) { |
|
| 1066 | var form = jQuery($this).parents('form,.form'); |
|
| 1067 | form.find('.sd-advanced-setting').toggleClass('sd-adv-show'); |
|
| 1068 | return false;// prevent form submit |
|
| 1069 | } |
|
| 1070 | ||
| 1071 | /** |
|
| 1072 | * Check a form to see what items shoudl be shown or hidden. |
|
| 1073 | */ |
|
| 1074 | function sd_show_hide(form) { |
|
| 1075 | console.log('show/hide'); |
|
| 1076 | jQuery(form).find(".sd-argument").each(function () { |
|
| 1077 | ||
| 1078 | var $element_require = jQuery(this).data('element_require'); |
|
| 1079 | ||
| 1080 | if ($element_require) { |
|
| 1081 | ||
| 1082 | $element_require = $element_require.replace("'", "'"); // replace single quotes |
|
| 1083 | $element_require = $element_require.replace(""", '"'); // replace double quotes |
|
| 1084 | ||
| 1085 | if (eval($element_require)) { |
|
| 1086 | jQuery(this).removeClass('sd-require-hide'); |
|
| 1087 | } else { |
|
| 1088 | jQuery(this).addClass('sd-require-hide'); |
|
| 1089 | } |
|
| 1090 | } |
|
| 1091 | }); |
|
| 1092 | } |
|
| 1093 | ||
| 1094 | /** |
|
| 1095 | * Initialise widgets from the widgets screen. |
|
| 1096 | */ |
|
| 1097 | function sd_init_widgets($selector) { |
|
| 1098 | jQuery(".sd-show-advanced").each(function (index) { |
|
| 1099 | sd_init_widget(this, $selector); |
|
| 1100 | }); |
|
| 1101 | } |
|
| 1102 | ||
| 1103 | /** |
|
| 1104 | * Initialise a individual widget. |
|
| 1105 | */ |
|
| 1106 | function sd_init_widget($this, $selector) { |
|
| 1107 | console.log($selector); |
|
| 1108 | ||
| 1109 | if (!$selector) { |
|
| 1110 | $selector = 'form'; |
|
| 1111 | } |
|
| 1112 | // only run once. |
|
| 1113 | if (jQuery($this).data('sd-widget-enabled')) { |
|
| 1114 | return; |
|
| 1115 | } else { |
|
| 1116 | jQuery($this).data('sd-widget-enabled', true); |
|
| 1117 | } |
|
| 1118 | ||
| 1119 | var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>'; |
|
| 1120 | var form = jQuery($this).parents('' + $selector + ''); |
|
| 1121 | ||
| 1122 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
|
| 1123 | console.log('add advanced button'); |
|
| 1124 | ||
| 1125 | jQuery(form).find('.widget-control-save').after($button); |
|
| 1126 | } else { |
|
| 1127 | console.log('no advanced button'); |
|
| 1128 | console.log(jQuery($this).val()); |
|
| 1129 | console.log(jQuery(form).find('.sd-advanced-button').length); |
|
| 1130 | ||
| 1131 | } |
|
| 1132 | ||
| 1133 | // show hide on form change |
|
| 1134 | jQuery(form).change(function () { |
|
| 1135 | sd_show_hide(form); |
|
| 1136 | }); |
|
| 1137 | ||
| 1138 | // show hide on load |
|
| 1139 | sd_show_hide(form); |
|
| 1140 | } |
|
| 1141 | ||
| 1142 | /** |
|
| 1143 | * Init a customizer widget. |
|
| 1144 | */ |
|
| 1145 | function sd_init_customizer_widget(section) { |
|
| 1146 | if (section.expanded) { |
|
| 1147 | section.expanded.bind(function (isExpanding) { |
|
| 1148 | if (isExpanding) { |
|
| 1149 | // is it a SD widget? |
|
| 1150 | if (jQuery(section.container).find('.sd-show-advanced').length) { |
|
| 1151 | // init the widget |
|
| 1152 | sd_init_widget(jQuery(section.container).find('.sd-show-advanced'), ".form"); |
|
| 1153 | } |
|
| 1154 | } |
|
| 1155 | }); |
|
| 1156 | } |
|
| 1157 | } |
|
| 1158 | ||
| 1159 | /** |
|
| 1160 | * If on widgets screen. |
|
| 1161 | */ |
|
| 1162 | jQuery(function () { |
|
| 1163 | // if not in customizer. |
|
| 1164 | if (!wp.customize) { |
|
| 1165 | sd_init_widgets("form"); |
|
| 1166 | } |
|
| 1167 | ||
| 1168 | // init on widget added |
|
| 1169 | jQuery(document).on('widget-added', function (e, widget) { |
|
| 1170 | console.log('widget added'); |
|
| 1171 | // is it a SD widget? |
|
| 1172 | if (jQuery(widget).find('.sd-show-advanced').length) { |
|
| 1173 | // init the widget |
|
| 1174 | sd_init_widget(jQuery(widget).find('.sd-show-advanced'), "form"); |
|
| 1175 | } |
|
| 1176 | }); |
|
| 1177 | ||
| 1178 | // inint on widget updated |
|
| 1179 | jQuery(document).on('widget-updated', function (e, widget) { |
|
| 1180 | console.log('widget updated'); |
|
| 1181 | ||
| 1182 | // is it a SD widget? |
|
| 1183 | if (jQuery(widget).find('.sd-show-advanced').length) { |
|
| 1184 | // init the widget |
|
| 1185 | sd_init_widget(jQuery(widget).find('.sd-show-advanced'), "form"); |
|
| 1186 | } |
|
| 1187 | }); |
|
| 1188 | ||
| 1189 | }); |
|
| 1190 | ||
| 1191 | ||
| 1192 | /** |
|
| 1193 | * We need to run this before jQuery is ready |
|
| 1194 | */ |
|
| 1195 | if (wp.customize) { |
|
| 1196 | wp.customize.bind('ready', function () { |
|
| 1197 | ||
| 1198 | // init widgets on load |
|
| 1199 | wp.customize.control.each(function (section) { |
|
| 1200 | sd_init_customizer_widget(section); |
|
| 1201 | }); |
|
| 1202 | ||
| 1203 | // init widgets on add |
|
| 1204 | wp.customize.control.bind('add', function (section) { |
|
| 1205 | sd_init_customizer_widget(section); |
|
| 1206 | }); |
|
| 1207 | ||
| 1208 | }); |
|
| 1209 | ||
| 1210 | } |
|
| 1211 | <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
|
| 1212 | </script> |
|
| 1213 | <?php |
|
| 1214 | $output = ob_get_clean(); |
|
| 1215 | ||
| 1216 | /* |
|
| 1217 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
|
| 1218 | */ |
|
| 1219 | ||
| 1220 | return str_replace( array( |
|
| 1221 | '<script>', |
|
| 1222 | '</script>' |
|
| 1223 | ), '', $output ); |
|
| 1224 | } |
|
| 1225 | ||
| 1226 | ||
| 1227 | /** |
|