/** * Returns the field type specific JavaScript script. */ protected function getScripts() { $_aJSArray = json_encode($this->aFieldTypeSlugs); $_sScript = parent::getScripts(); $_sScript .= <<<JAVASCRIPTS jQuery( document ).ready( function(){ // Add the select all and none buttons. jQuery( '.admin-page-framework-checkbox-container-posttype[data-select_all_button]' ).each( function( iIndex ){ jQuery( this ).before( '<div class=\\"select_all_button_container\\" onclick=\\"jQuery( this ).selectAllAdminPageFrameworkCheckboxes(); return false;\\"><a class=\\"select_all_button button button-small\\">' + jQuery( this ).data( 'select_all_button' ) + '</a></div>' ); }); jQuery( '.admin-page-framework-checkbox-container-posttype[data-select_none_button]' ).each( function( iIndex ){ jQuery( this ).before( '<div class=\\"select_none_button_container\\" onclick=\\"jQuery( this ).deselectAllAdminPageFrameworkCheckboxes(); return false;\\"><a class=\\"select_all_button button button-small\\">' + jQuery( this ).data( 'select_none_button' ) + '</a></div>' ); }); // When the post type check-boxes are clicked, show/hide the corresponding taxonomy elements. jQuery( document ).on( 'change', '.admin-page-framework-field-post_type_taxonomy .admin-page-framework-field-posttype input[type="checkbox"]', function() { var _sPostTypeSlug = jQuery( this ).data( 'key' ); var _sTargetTabsSelector = '.tab-box-container li.tab-box-tab[data-associated-post-types*="' + _sPostTypeSlug + ',"]'; var _sTargetCBContainers = '.tab-box-content[data-associated-post-types*="' + _sPostTypeSlug + ',"]'; var _sTabsBoxSelector = '.tab-box-container'; var _oField = jQuery( this ).closest( '.admin-page-framework-field-post_type_taxonomy' ); var _oTargetTabs = _oField.find( _sTargetTabsSelector ); var _oTargetCBContainers = _oField.find( _sTargetCBContainers ); if ( jQuery( this ).is( ':checked' ) ) { // Show the associated taxonomy tabs. // Check the number of showing tabs. // Note that there are post types which do not have any taxonomy. if ( _oTargetTabs.length ) { _oTargetTabs.show() .trigger( 'click' ); // need to activate a tab. // Enable the check-boxes as they will be disabled when the post type check-box is unchecked. _oTargetCBContainers.find( 'input[type=checkbox]' ).removeAttr( 'disabled' ); // If at least one item which is associated with a taxonomy is checked, the tabs-container box should be displayed. _oField.find( _sTabsBoxSelector ).show(); } } else { var _sVisibleTabsSelector = '.tab-box-container li.tab-box-tab:visible'; // Hide the associated taxonomy tabs. if ( _oTargetTabs.length ) { _oTargetTabs.hide(); // Disable the check-boxes so that the values won't be sent. _oTargetCBContainers.find( 'input[type=checkbox]' ).attr( 'disabled','disabled' ); // Activate the first visible tab item. _oField.find( _sVisibleTabsSelector ).first().trigger( 'click' ); } // If none of the tabs is shown, hide the check-box container box. if ( ! _oField.find( _sVisibleTabsSelector ).length ){ _oField.find( _sTabsBoxSelector ).hide(); } } }); // Hide the unchecked elements (tabs and check-box containers). jQuery( '.admin-page-framework-field-post_type_taxonomy .admin-page-framework-field-posttype input[type="checkbox"]:not(:checked)' ).each( function(){ jQuery( this ).trigger( 'change' ); } ); jQuery().registerAdminPageFrameworkCallbacks( { /** * Called when a field gets repeated. */ repeated_field: function( oCloned, aModel ) { // Uncheck all the items and hide the associated elements (tabs and check-box containers). oCloned.find( '.admin-page-framework-field-posttype input[type="checkbox"]' ) .prop( 'checked', false ) .trigger( 'change' ); }, }, {$_aJSArray} ); }); JAVASCRIPTS; return $_sScript; }