| @@ 303-393 (lines=91) @@ | ||
| 300 | * @since 1.0.6 |
|
| 301 | * @return mixed |
|
| 302 | */ |
|
| 303 | public static function siteorigin_js() { |
|
| 304 | ob_start(); |
|
| 305 | ?> |
|
| 306 | <script> |
|
| 307 | /** |
|
| 308 | * Check a form to see what items shoudl be shown or hidden. |
|
| 309 | */ |
|
| 310 | function sd_so_show_hide(form) { |
|
| 311 | jQuery(form).find(".sd-argument").each(function () { |
|
| 312 | ||
| 313 | var $element_require = jQuery(this).data('element_require'); |
|
| 314 | ||
| 315 | if ($element_require) { |
|
| 316 | ||
| 317 | $element_require = $element_require.replace("'", "'"); // replace single quotes |
|
| 318 | $element_require = $element_require.replace(""", '"'); // replace double quotes |
|
| 319 | ||
| 320 | if (eval($element_require)) { |
|
| 321 | jQuery(this).removeClass('sd-require-hide'); |
|
| 322 | } else { |
|
| 323 | jQuery(this).addClass('sd-require-hide'); |
|
| 324 | } |
|
| 325 | } |
|
| 326 | }); |
|
| 327 | } |
|
| 328 | ||
| 329 | /** |
|
| 330 | * Toggle advanced settings visibility. |
|
| 331 | */ |
|
| 332 | function sd_so_toggle_advanced($this) { |
|
| 333 | var form = jQuery($this).parents('form,.form,.so-content'); |
|
| 334 | form.find('.sd-advanced-setting').toggleClass('sd-adv-show'); |
|
| 335 | return false;// prevent form submit |
|
| 336 | } |
|
| 337 | ||
| 338 | /** |
|
| 339 | * Initialise a individual widget. |
|
| 340 | */ |
|
| 341 | function sd_so_init_widget($this, $selector) { |
|
| 342 | if (!$selector) { |
|
| 343 | $selector = 'form'; |
|
| 344 | } |
|
| 345 | // only run once. |
|
| 346 | if (jQuery($this).data('sd-widget-enabled')) { |
|
| 347 | return; |
|
| 348 | } else { |
|
| 349 | jQuery($this).data('sd-widget-enabled', true); |
|
| 350 | } |
|
| 351 | ||
| 352 | 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>'; |
|
| 353 | var form = jQuery($this).parents('' + $selector + ''); |
|
| 354 | ||
| 355 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
|
| 356 | jQuery(form).append($button); |
|
| 357 | } |
|
| 358 | ||
| 359 | // show hide on form change |
|
| 360 | jQuery(form).change(function () { |
|
| 361 | sd_so_show_hide(form); |
|
| 362 | }); |
|
| 363 | ||
| 364 | // show hide on load |
|
| 365 | sd_so_show_hide(form); |
|
| 366 | } |
|
| 367 | ||
| 368 | jQuery(function () { |
|
| 369 | jQuery(document).on('open_dialog', function (w, e) { |
|
| 370 | setTimeout(function () { |
|
| 371 | if (jQuery('.so-panels-dialog-wrapper:visible .so-content.panel-dialog .sd-show-advanced').length) { |
|
| 372 | console.log('exists'); |
|
| 373 | if (jQuery('.so-panels-dialog-wrapper:visible .so-content.panel-dialog .sd-show-advanced').val() == '1') { |
|
| 374 | console.log('true'); |
|
| 375 | sd_so_init_widget('.so-panels-dialog-wrapper:visible .so-content.panel-dialog .sd-show-advanced', 'div'); |
|
| 376 | } |
|
| 377 | } |
|
| 378 | }, 200); |
|
| 379 | }); |
|
| 380 | }); |
|
| 381 | </script> |
|
| 382 | <?php |
|
| 383 | $output = ob_get_clean(); |
|
| 384 | ||
| 385 | /* |
|
| 386 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
|
| 387 | */ |
|
| 388 | ||
| 389 | return str_replace( array( |
|
| 390 | '<script>', |
|
| 391 | '</script>' |
|
| 392 | ), '', $output ); |
|
| 393 | } |
|
| 394 | ||
| 395 | /** |
|
| 396 | * Output the JS and CSS for the shortcode insert button. |
|
| @@ 862-895 (lines=34) @@ | ||
| 859 | * |
|
| 860 | * @return mixed |
|
| 861 | */ |
|
| 862 | public function widget_css() { |
|
| 863 | ob_start(); |
|
| 864 | ?> |
|
| 865 | <style> |
|
| 866 | .sd-advanced-setting { |
|
| 867 | display: none; |
|
| 868 | } |
|
| 869 | ||
| 870 | .sd-advanced-setting.sd-adv-show { |
|
| 871 | display: block; |
|
| 872 | } |
|
| 873 | ||
| 874 | .sd-argument.sd-require-hide, |
|
| 875 | .sd-advanced-setting.sd-require-hide { |
|
| 876 | display: none; |
|
| 877 | } |
|
| 878 | ||
| 879 | button.sd-advanced-button { |
|
| 880 | margin-right: 3px !important; |
|
| 881 | font-size: 20px !important; |
|
| 882 | } |
|
| 883 | </style> |
|
| 884 | <?php |
|
| 885 | $output = ob_get_clean(); |
|
| 886 | ||
| 887 | /* |
|
| 888 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
|
| 889 | */ |
|
| 890 | ||
| 891 | return str_replace( array( |
|
| 892 | '<style>', |
|
| 893 | '</style>' |
|
| 894 | ), '', $output ); |
|
| 895 | } |
|
| 896 | ||
| 897 | /** |
|
| 898 | * Gets some JS for the widgets screen. |
|
| @@ 902-1069 (lines=168) @@ | ||
| 899 | * |
|
| 900 | * @return mixed |
|
| 901 | */ |
|
| 902 | public function widget_js() { |
|
| 903 | ob_start(); |
|
| 904 | ?> |
|
| 905 | <script> |
|
| 906 | ||
| 907 | /** |
|
| 908 | * Toggle advanced settings visibility. |
|
| 909 | */ |
|
| 910 | function sd_toggle_advanced($this) { |
|
| 911 | var form = jQuery($this).parents('form,.form'); |
|
| 912 | form.find('.sd-advanced-setting').toggleClass('sd-adv-show'); |
|
| 913 | return false;// prevent form submit |
|
| 914 | } |
|
| 915 | ||
| 916 | /** |
|
| 917 | * Check a form to see what items shoudl be shown or hidden. |
|
| 918 | */ |
|
| 919 | function sd_show_hide(form) { |
|
| 920 | console.log('show/hide'); |
|
| 921 | jQuery(form).find(".sd-argument").each(function () { |
|
| 922 | ||
| 923 | var $element_require = jQuery(this).data('element_require'); |
|
| 924 | ||
| 925 | if ($element_require) { |
|
| 926 | ||
| 927 | $element_require = $element_require.replace("'", "'"); // replace single quotes |
|
| 928 | $element_require = $element_require.replace(""", '"'); // replace double quotes |
|
| 929 | ||
| 930 | if (eval($element_require)) { |
|
| 931 | jQuery(this).removeClass('sd-require-hide'); |
|
| 932 | } else { |
|
| 933 | jQuery(this).addClass('sd-require-hide'); |
|
| 934 | } |
|
| 935 | } |
|
| 936 | }); |
|
| 937 | } |
|
| 938 | ||
| 939 | /** |
|
| 940 | * Initialise widgets from the widgets screen. |
|
| 941 | */ |
|
| 942 | function sd_init_widgets($selector) { |
|
| 943 | jQuery(".sd-show-advanced").each(function (index) { |
|
| 944 | sd_init_widget(this, $selector); |
|
| 945 | }); |
|
| 946 | } |
|
| 947 | ||
| 948 | /** |
|
| 949 | * Initialise a individual widget. |
|
| 950 | */ |
|
| 951 | function sd_init_widget($this, $selector) { |
|
| 952 | console.log($selector); |
|
| 953 | ||
| 954 | if (!$selector) { |
|
| 955 | $selector = 'form'; |
|
| 956 | } |
|
| 957 | // only run once. |
|
| 958 | if (jQuery($this).data('sd-widget-enabled')) { |
|
| 959 | return; |
|
| 960 | } else { |
|
| 961 | jQuery($this).data('sd-widget-enabled', true); |
|
| 962 | } |
|
| 963 | ||
| 964 | 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>'; |
|
| 965 | var form = jQuery($this).parents('' + $selector + ''); |
|
| 966 | ||
| 967 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
|
| 968 | console.log('add advanced button'); |
|
| 969 | ||
| 970 | jQuery(form).find('.widget-control-save').after($button); |
|
| 971 | } else { |
|
| 972 | console.log('no advanced button'); |
|
| 973 | console.log(jQuery($this).val()); |
|
| 974 | console.log(jQuery(form).find('.sd-advanced-button').length); |
|
| 975 | ||
| 976 | } |
|
| 977 | ||
| 978 | // show hide on form change |
|
| 979 | jQuery(form).change(function () { |
|
| 980 | sd_show_hide(form); |
|
| 981 | }); |
|
| 982 | ||
| 983 | // show hide on load |
|
| 984 | sd_show_hide(form); |
|
| 985 | } |
|
| 986 | ||
| 987 | /** |
|
| 988 | * Init a customizer widget. |
|
| 989 | */ |
|
| 990 | function sd_init_customizer_widget(section) { |
|
| 991 | if (section.expanded) { |
|
| 992 | section.expanded.bind(function (isExpanding) { |
|
| 993 | if (isExpanding) { |
|
| 994 | // is it a SD widget? |
|
| 995 | if (jQuery(section.container).find('.sd-show-advanced').length) { |
|
| 996 | // init the widget |
|
| 997 | sd_init_widget(jQuery(section.container).find('.sd-show-advanced'), ".form"); |
|
| 998 | } |
|
| 999 | } |
|
| 1000 | }); |
|
| 1001 | } |
|
| 1002 | } |
|
| 1003 | ||
| 1004 | /** |
|
| 1005 | * If on widgets screen. |
|
| 1006 | */ |
|
| 1007 | jQuery(function () { |
|
| 1008 | // if not in customizer. |
|
| 1009 | if (!wp.customize) { |
|
| 1010 | sd_init_widgets("form"); |
|
| 1011 | } |
|
| 1012 | ||
| 1013 | // init on widget added |
|
| 1014 | jQuery(document).on('widget-added', function (e, widget) { |
|
| 1015 | console.log('widget added'); |
|
| 1016 | // is it a SD widget? |
|
| 1017 | if (jQuery(widget).find('.sd-show-advanced').length) { |
|
| 1018 | // init the widget |
|
| 1019 | sd_init_widget(jQuery(widget).find('.sd-show-advanced'), "form"); |
|
| 1020 | } |
|
| 1021 | }); |
|
| 1022 | ||
| 1023 | // inint on widget updated |
|
| 1024 | jQuery(document).on('widget-updated', function (e, widget) { |
|
| 1025 | console.log('widget updated'); |
|
| 1026 | ||
| 1027 | // is it a SD widget? |
|
| 1028 | if (jQuery(widget).find('.sd-show-advanced').length) { |
|
| 1029 | // init the widget |
|
| 1030 | sd_init_widget(jQuery(widget).find('.sd-show-advanced'), "form"); |
|
| 1031 | } |
|
| 1032 | }); |
|
| 1033 | ||
| 1034 | }); |
|
| 1035 | ||
| 1036 | ||
| 1037 | /** |
|
| 1038 | * We need to run this before jQuery is ready |
|
| 1039 | */ |
|
| 1040 | if (wp.customize) { |
|
| 1041 | wp.customize.bind('ready', function () { |
|
| 1042 | ||
| 1043 | // init widgets on load |
|
| 1044 | wp.customize.control.each(function (section) { |
|
| 1045 | sd_init_customizer_widget(section); |
|
| 1046 | }); |
|
| 1047 | ||
| 1048 | // init widgets on add |
|
| 1049 | wp.customize.control.bind('add', function (section) { |
|
| 1050 | sd_init_customizer_widget(section); |
|
| 1051 | }); |
|
| 1052 | ||
| 1053 | }); |
|
| 1054 | ||
| 1055 | } |
|
| 1056 | <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
|
| 1057 | </script> |
|
| 1058 | <?php |
|
| 1059 | $output = ob_get_clean(); |
|
| 1060 | ||
| 1061 | /* |
|
| 1062 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
|
| 1063 | */ |
|
| 1064 | ||
| 1065 | return str_replace( array( |
|
| 1066 | '<script>', |
|
| 1067 | '</script>' |
|
| 1068 | ), '', $output ); |
|
| 1069 | } |
|
| 1070 | ||
| 1071 | ||
| 1072 | /** |
|