| @@ 191-281 (lines=91) @@ | ||
| 188 | * @since 1.0.6 |
|
| 189 | * @return mixed |
|
| 190 | */ |
|
| 191 | public static function siteorigin_js() { |
|
| 192 | ob_start(); |
|
| 193 | ?> |
|
| 194 | <script> |
|
| 195 | /** |
|
| 196 | * Check a form to see what items shoudl be shown or hidden. |
|
| 197 | */ |
|
| 198 | function sd_so_show_hide(form) { |
|
| 199 | jQuery(form).find(".sd-argument").each(function () { |
|
| 200 | ||
| 201 | var $element_require = jQuery(this).data('element_require'); |
|
| 202 | ||
| 203 | if ($element_require) { |
|
| 204 | ||
| 205 | $element_require = $element_require.replace("'", "'"); // replace single quotes |
|
| 206 | $element_require = $element_require.replace(""", '"'); // replace double quotes |
|
| 207 | ||
| 208 | if (eval($element_require)) { |
|
| 209 | jQuery(this).removeClass('sd-require-hide'); |
|
| 210 | } else { |
|
| 211 | jQuery(this).addClass('sd-require-hide'); |
|
| 212 | } |
|
| 213 | } |
|
| 214 | }); |
|
| 215 | } |
|
| 216 | ||
| 217 | /** |
|
| 218 | * Toggle advanced settings visibility. |
|
| 219 | */ |
|
| 220 | function sd_so_toggle_advanced($this) { |
|
| 221 | var form = jQuery($this).parents('form,.form,.so-content'); |
|
| 222 | form.find('.sd-advanced-setting').toggleClass('sd-adv-show'); |
|
| 223 | return false;// prevent form submit |
|
| 224 | } |
|
| 225 | ||
| 226 | /** |
|
| 227 | * Initialise a individual widget. |
|
| 228 | */ |
|
| 229 | function sd_so_init_widget($this, $selector) { |
|
| 230 | if (!$selector) { |
|
| 231 | $selector = 'form'; |
|
| 232 | } |
|
| 233 | // only run once. |
|
| 234 | if (jQuery($this).data('sd-widget-enabled')) { |
|
| 235 | return; |
|
| 236 | } else { |
|
| 237 | jQuery($this).data('sd-widget-enabled', true); |
|
| 238 | } |
|
| 239 | ||
| 240 | 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>'; |
|
| 241 | var form = jQuery($this).parents('' + $selector + ''); |
|
| 242 | ||
| 243 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
|
| 244 | jQuery(form).append($button); |
|
| 245 | } |
|
| 246 | ||
| 247 | // show hide on form change |
|
| 248 | jQuery(form).change(function () { |
|
| 249 | sd_so_show_hide(form); |
|
| 250 | }); |
|
| 251 | ||
| 252 | // show hide on load |
|
| 253 | sd_so_show_hide(form); |
|
| 254 | } |
|
| 255 | ||
| 256 | jQuery(function () { |
|
| 257 | jQuery(document).on('open_dialog', function (w, e) { |
|
| 258 | setTimeout(function () { |
|
| 259 | if (jQuery('.so-panels-dialog-wrapper:visible .so-content.panel-dialog .sd-show-advanced').length) { |
|
| 260 | console.log('exists'); |
|
| 261 | if (jQuery('.so-panels-dialog-wrapper:visible .so-content.panel-dialog .sd-show-advanced').val() == '1') { |
|
| 262 | console.log('true'); |
|
| 263 | sd_so_init_widget('.so-panels-dialog-wrapper:visible .so-content.panel-dialog .sd-show-advanced', 'div'); |
|
| 264 | } |
|
| 265 | } |
|
| 266 | }, 200); |
|
| 267 | }); |
|
| 268 | }); |
|
| 269 | </script> |
|
| 270 | <?php |
|
| 271 | $output = ob_get_clean(); |
|
| 272 | ||
| 273 | /* |
|
| 274 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
|
| 275 | */ |
|
| 276 | ||
| 277 | return str_replace( array( |
|
| 278 | '<script>', |
|
| 279 | '</script>' |
|
| 280 | ), '', $output ); |
|
| 281 | } |
|
| 282 | ||
| 283 | /** |
|
| 284 | * Output the JS and CSS for the shortcode insert button. |
|
| @@ 596-629 (lines=34) @@ | ||
| 593 | <?php |
|
| 594 | } |
|
| 595 | ||
| 596 | public function widget_css() { |
|
| 597 | ob_start(); |
|
| 598 | ?> |
|
| 599 | <style> |
|
| 600 | .sd-advanced-setting { |
|
| 601 | display: none; |
|
| 602 | } |
|
| 603 | ||
| 604 | .sd-advanced-setting.sd-adv-show { |
|
| 605 | display: block; |
|
| 606 | } |
|
| 607 | ||
| 608 | .sd-argument.sd-require-hide, |
|
| 609 | .sd-advanced-setting.sd-require-hide { |
|
| 610 | display: none; |
|
| 611 | } |
|
| 612 | ||
| 613 | button.sd-advanced-button { |
|
| 614 | margin-right: 3px !important; |
|
| 615 | font-size: 20px !important; |
|
| 616 | } |
|
| 617 | </style> |
|
| 618 | <?php |
|
| 619 | $output = ob_get_clean(); |
|
| 620 | ||
| 621 | /* |
|
| 622 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
|
| 623 | */ |
|
| 624 | ||
| 625 | return str_replace( array( |
|
| 626 | '<style>', |
|
| 627 | '</style>' |
|
| 628 | ), '', $output ); |
|
| 629 | } |
|
| 630 | ||
| 631 | public function widget_js() { |
|
| 632 | ob_start(); |
|
| @@ 631-798 (lines=168) @@ | ||
| 628 | ), '', $output ); |
|
| 629 | } |
|
| 630 | ||
| 631 | public function widget_js() { |
|
| 632 | ob_start(); |
|
| 633 | ?> |
|
| 634 | <script> |
|
| 635 | ||
| 636 | /** |
|
| 637 | * Toggle advanced settings visibility. |
|
| 638 | */ |
|
| 639 | function sd_toggle_advanced($this) { |
|
| 640 | var form = jQuery($this).parents('form,.form'); |
|
| 641 | form.find('.sd-advanced-setting').toggleClass('sd-adv-show'); |
|
| 642 | return false;// prevent form submit |
|
| 643 | } |
|
| 644 | ||
| 645 | /** |
|
| 646 | * Check a form to see what items shoudl be shown or hidden. |
|
| 647 | */ |
|
| 648 | function sd_show_hide(form) { |
|
| 649 | console.log('show/hide'); |
|
| 650 | jQuery(form).find(".sd-argument").each(function () { |
|
| 651 | ||
| 652 | var $element_require = jQuery(this).data('element_require'); |
|
| 653 | ||
| 654 | if ($element_require) { |
|
| 655 | ||
| 656 | $element_require = $element_require.replace("'", "'"); // replace single quotes |
|
| 657 | $element_require = $element_require.replace(""", '"'); // replace double quotes |
|
| 658 | ||
| 659 | if (eval($element_require)) { |
|
| 660 | jQuery(this).removeClass('sd-require-hide'); |
|
| 661 | } else { |
|
| 662 | jQuery(this).addClass('sd-require-hide'); |
|
| 663 | } |
|
| 664 | } |
|
| 665 | }); |
|
| 666 | } |
|
| 667 | ||
| 668 | /** |
|
| 669 | * Initialise widgets from the widgets screen. |
|
| 670 | */ |
|
| 671 | function sd_init_widgets($selector) { |
|
| 672 | jQuery(".sd-show-advanced").each(function (index) { |
|
| 673 | sd_init_widget(this, $selector); |
|
| 674 | }); |
|
| 675 | } |
|
| 676 | ||
| 677 | /** |
|
| 678 | * Initialise a individual widget. |
|
| 679 | */ |
|
| 680 | function sd_init_widget($this, $selector) { |
|
| 681 | console.log($selector); |
|
| 682 | ||
| 683 | if (!$selector) { |
|
| 684 | $selector = 'form'; |
|
| 685 | } |
|
| 686 | // only run once. |
|
| 687 | if (jQuery($this).data('sd-widget-enabled')) { |
|
| 688 | return; |
|
| 689 | } else { |
|
| 690 | jQuery($this).data('sd-widget-enabled', true); |
|
| 691 | } |
|
| 692 | ||
| 693 | var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>'; |
|
| 694 | var form = jQuery($this).parents('' + $selector + ''); |
|
| 695 | ||
| 696 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
|
| 697 | console.log('add advanced button'); |
|
| 698 | ||
| 699 | jQuery(form).find('.widget-control-save').after($button); |
|
| 700 | } else { |
|
| 701 | console.log('no advanced button'); |
|
| 702 | console.log(jQuery($this).val()); |
|
| 703 | console.log(jQuery(form).find('.sd-advanced-button').length); |
|
| 704 | ||
| 705 | } |
|
| 706 | ||
| 707 | // show hide on form change |
|
| 708 | jQuery(form).change(function () { |
|
| 709 | sd_show_hide(form); |
|
| 710 | }); |
|
| 711 | ||
| 712 | // show hide on load |
|
| 713 | sd_show_hide(form); |
|
| 714 | } |
|
| 715 | ||
| 716 | /** |
|
| 717 | * Init a customizer widget. |
|
| 718 | */ |
|
| 719 | function sd_init_customizer_widget(section) { |
|
| 720 | if (section.expanded) { |
|
| 721 | section.expanded.bind(function (isExpanding) { |
|
| 722 | if (isExpanding) { |
|
| 723 | // is it a SD widget? |
|
| 724 | if (jQuery(section.container).find('.sd-show-advanced').length) { |
|
| 725 | // init the widget |
|
| 726 | sd_init_widget(jQuery(section.container).find('.sd-show-advanced'), ".form"); |
|
| 727 | } |
|
| 728 | } |
|
| 729 | }); |
|
| 730 | } |
|
| 731 | } |
|
| 732 | ||
| 733 | /** |
|
| 734 | * If on widgets screen. |
|
| 735 | */ |
|
| 736 | jQuery(function () { |
|
| 737 | // if not in customizer. |
|
| 738 | if (!wp.customize) { |
|
| 739 | sd_init_widgets("form"); |
|
| 740 | } |
|
| 741 | ||
| 742 | // init on widget added |
|
| 743 | jQuery(document).on('widget-added', function (e, widget) { |
|
| 744 | console.log('widget added'); |
|
| 745 | // is it a SD widget? |
|
| 746 | if (jQuery(widget).find('.sd-show-advanced').length) { |
|
| 747 | // init the widget |
|
| 748 | sd_init_widget(jQuery(widget).find('.sd-show-advanced'), "form"); |
|
| 749 | } |
|
| 750 | }); |
|
| 751 | ||
| 752 | // inint on widget updated |
|
| 753 | jQuery(document).on('widget-updated', function (e, widget) { |
|
| 754 | console.log('widget updated'); |
|
| 755 | ||
| 756 | // is it a SD widget? |
|
| 757 | if (jQuery(widget).find('.sd-show-advanced').length) { |
|
| 758 | // init the widget |
|
| 759 | sd_init_widget(jQuery(widget).find('.sd-show-advanced'), "form"); |
|
| 760 | } |
|
| 761 | }); |
|
| 762 | ||
| 763 | }); |
|
| 764 | ||
| 765 | ||
| 766 | /** |
|
| 767 | * We need to run this before jQuery is ready |
|
| 768 | */ |
|
| 769 | if (wp.customize) { |
|
| 770 | wp.customize.bind('ready', function () { |
|
| 771 | ||
| 772 | // init widgets on load |
|
| 773 | wp.customize.control.each(function (section) { |
|
| 774 | sd_init_customizer_widget(section); |
|
| 775 | }); |
|
| 776 | ||
| 777 | // init widgets on add |
|
| 778 | wp.customize.control.bind('add', function (section) { |
|
| 779 | sd_init_customizer_widget(section); |
|
| 780 | }); |
|
| 781 | ||
| 782 | }); |
|
| 783 | ||
| 784 | } |
|
| 785 | <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
|
| 786 | </script> |
|
| 787 | <?php |
|
| 788 | $output = ob_get_clean(); |
|
| 789 | ||
| 790 | /* |
|
| 791 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
|
| 792 | */ |
|
| 793 | ||
| 794 | return str_replace( array( |
|
| 795 | '<script>', |
|
| 796 | '</script>' |
|
| 797 | ), '', $output ); |
|
| 798 | } |
|
| 799 | ||
| 800 | ||
| 801 | /** |
|