AdminPageFramework_FieldType_taxonomy::getScripts PHP Метод

getScripts() защищенный Метод

protected getScripts ( )
    protected function getScripts()
    {
        $_aJSArray = json_encode($this->aFieldTypeSlugs);
        return parent::getScripts() . <<<JAVASCRIPTS
/* For tabs */
var enableAdminPageFrameworkTabbedBox = function( nodeTabBoxContainer ) {
    jQuery( nodeTabBoxContainer ).each( function() {
        jQuery( this ).find( '.tab-box-tab' ).each( function( i ) {
            
            if ( 0 === i ) {
                jQuery( this ).addClass( 'active' );
            }
                
            jQuery( this ).click( function( e ){
                     
                // Prevents jumping to the anchor which moves the scroll bar.
                e.preventDefault();
                
                // Remove the active tab and set the clicked tab to be active.
                jQuery( this ).siblings( 'li.active' ).removeClass( 'active' );
                jQuery( this ).addClass( 'active' );
                
                // Find the element id and select the content element with it.
                var thisTab = jQuery( this ).find( 'a' ).attr( 'href' );
                active_content = jQuery( this ).closest( '.tab-box-container' ).find( thisTab ).css( 'display', 'block' ); 
                active_content.siblings().css( 'display', 'none' );
                
            });
        });     
    });
};        

jQuery( document ).ready( function() {
         
    enableAdminPageFrameworkTabbedBox( jQuery( '.tab-box-container' ) );

    /* The repeatable event */
    jQuery().registerAdminPageFrameworkCallbacks( {
        /**
         * Called when a field of this field type gets repeated.
         */
        repeated_field: function( oCloned, aModel ) {
                           
            // Update attributes.            
            oCloned.find( 'div, li.category-list' ).incrementAttribute(
                'id', // attribute name
                aModel[ 'incremented_from' ], // index incremented from
                aModel[ 'id' ] // digit model
            );
            oCloned.find( 'label' ).incrementAttribute(
                'for', // attribute name
                aModel[ 'incremented_from' ], // index incremented from
                aModel[ 'id' ] // digit model
            );            
            oCloned.find( 'li.tab-box-tab a' ).incrementAttribute(
                'href', // attribute name
                aModel[ 'incremented_from' ], // index incremented from
                aModel[ 'id' ] // digit model
            );                 
            
            // Initialize
            enableAdminPageFrameworkTabbedBox( oCloned.find( '.tab-box-container' ) );
            
        },
    },
    {$_aJSArray}
    );
});     
JAVASCRIPTS;
    }

Usage Example

        /**
         * 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;
        }