balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

redux-extension-metaboxes.js (2733B)


      1 /* global reduxMetaboxes */
      2 
      3 jQuery(
      4 	function( $ ) {
      5 		'use strict';
      6 
      7 		var isGutenberg = false;
      8 
      9 		$.reduxMetaBoxes = $.reduxMetaBoxes || {};
     10 
     11 		$( document ).ready(
     12 			function() {
     13 				$.reduxMetaBoxes.init();
     14 
     15 				if ( $( 'body' ).hasClass( 'block-editor-page' ) ) {
     16 					isGutenberg = true;
     17 				}
     18 			}
     19 		);
     20 
     21 		setTimeout(
     22 			function() {
     23 				if ( true === isGutenberg ) {
     24 					$( '.postbox .toggle-indicator' ).removeClass( 'toggle-indicator' ).addClass( 'el' );
     25 				}
     26 
     27 				$( '#publishing-action .button, #save-action .button, .editor-post-publish-button' ).click(
     28 					function() {
     29 						$( '.redux-save-warn' ).slideUp();
     30 
     31 						window.onbeforeunload = null;
     32 					}
     33 				);
     34 			},
     35 			1000
     36 		);
     37 
     38 		$.reduxMetaBoxes.init = function() {
     39 			$.reduxMetaBoxes.notLoaded = true;
     40 
     41 			$.redux.initFields();
     42 
     43 			if ( $( 'body' ).hasClass( 'block-editor-page' ) ) {
     44 				isGutenberg = true;
     45 			}
     46 
     47 			if ( isGutenberg ) {
     48 				setTimeout(
     49 					function() {
     50 						$.reduxMetaBoxes.checkBoxVisibility();
     51 
     52 						$( '.editor-post-format__content select' ).change(
     53 							function() {
     54 								$.reduxMetaBoxes.checkBoxVisibility( 'post_format' );
     55 							}
     56 						);
     57 					},
     58 					1000
     59 				);
     60 			} else {
     61 				$.reduxMetaBoxes.checkBoxVisibility();
     62 
     63 				$( '#page_template' ).change(
     64 					function() {
     65 						$.reduxMetaBoxes.checkBoxVisibility( 'page_template' );
     66 					}
     67 				);
     68 
     69 				$( 'input[name="post_format"]:radio' ).change(
     70 					function() {
     71 						$.reduxMetaBoxes.checkBoxVisibility( 'post_format' );
     72 					}
     73 				);
     74 			}
     75 		};
     76 
     77 		$.reduxMetaBoxes.checkBoxVisibility = function( fieldID ) {
     78 			if ( 0 !== reduxMetaboxes.length ) {
     79 				$.each(
     80 					reduxMetaboxes,
     81 					function( box, values ) {
     82 						$.each(
     83 							values,
     84 							function( field, v ) {
     85 								var visible = false;
     86 								var testValue;
     87 
     88 								if ( field === fieldID || ! fieldID ) {
     89 									if ( 'post_format' === field ) {
     90 										if ( isGutenberg ) {
     91 											testValue = $( ' .editor-post-format__content select option:selected' ).val();
     92 										} else {
     93 											testValue = $( 'input:radio[name="post_format"]:checked' ).val();
     94 										}
     95 									} else {
     96 										testValue = $( '#' + field ).val();
     97 									}
     98 
     99 									if ( testValue ) {
    100 										$.each(
    101 											v,
    102 											function( key, val ) {
    103 												if ( val === testValue ) {
    104 													visible = true;
    105 												}
    106 											}
    107 										);
    108 
    109 										if ( ! visible && ! $.reduxMetaBoxes.notLoaded ) {
    110 											$( '#' + box ).hide();
    111 										} else if ( ! visible ) {
    112 											$( '#' + box ).hide();
    113 										} else {
    114 											$( '#' + box ).fadeIn( '300' );
    115 											$.redux.initFields();
    116 										}
    117 									}
    118 								}
    119 							}
    120 						);
    121 					}
    122 				);
    123 			}
    124 		};
    125 	}
    126 );