Code Duplication    Length = 34-168 lines in 3 locations

vendor/ayecode/wp-super-duper/wp-super-duper.php 3 locations

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