AdminPageFramework_FieldType_color::getScripts PHP Метод

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

protected getScripts ( )
    protected function getScripts()
    {
        $_aJSArray = json_encode($this->aFieldTypeSlugs);
        $_sDoubleQuote = '\\"';
        return <<<JAVASCRIPTS
registerAdminPageFrameworkColorPickerField = function( osTragetInput, aOptions ) {
    
    var osTargetInput   = 'string' === typeof osTragetInput 
        ? '#' + osTragetInput 
        : osTragetInput;
    var sInputID        = 'string' === typeof osTragetInput 
        ? osTragetInput 
        : osTragetInput.attr( 'id' );

    // Only for the iris color picker.
    var _aDefaults = {
        defaultColor: false, // you can declare a default color here, or in the data-default-color attribute on the input     
        change: function( event, ui ){
            jQuery( this ).trigger( 
                'admin-page-framework_field_type_color_changed',
                [ jQuery( this ), sInputID ]
            ); 
        }, // a callback to fire whenever the color changes to a valid color. reference : http://automattic.github.io/Iris/     
        clear: function( event, ui ) {
            jQuery( this ).trigger(
                'admin-page-framework_field_type_color_cleared',
                [ jQuery( '#' + sInputID ), sInputID ]
            );            
        }, // a callback to fire when the input is emptied or an invalid color
        hide: true, // hide the color picker controls on load
        palettes: true // show a group of common colors beneath the square or, supply an array of colors to customize further                
    };
    var _aColorPickerOptions = jQuery.extend( {}, _aDefaults, aOptions );
        
    'use strict';
    /* This if-statement checks if the color picker element exists within jQuery UI
     If it does exist, then we initialize the WordPress color picker on our text input field */
    if( 'object' === typeof jQuery.wp && 'function' === typeof jQuery.wp.wpColorPicker ){
        jQuery( osTargetInput ).wpColorPicker( _aColorPickerOptions );
    }
    else {
        /* We use farbtastic if the WordPress color picker widget doesn't exist */
        jQuery( '#color_' + sInputID ).farbtastic( osTargetInput );
    }
}

/* The below function will be triggered when a new repeatable field is added. Since the APF repeater script does not
    renew the color piker element (while it does on the input tag value), the renewal task must be dealt here separately. */
jQuery( document ).ready( function(){
        
    jQuery().registerAdminPageFrameworkCallbacks( {     
        /**
         * Called when a field of this field type gets repeated.
         */
        repeated_field: function( oCloned, aModel ) {
                        
            oCloned.find( 'input.input_color' ).each( function( iIterationIndex ) {
                
                var _oNewColorInput = jQuery( this );
                var _oIris          = _oNewColorInput.closest( '.wp-picker-container' );
                // WP 3.5+
                if ( _oIris.length > 0 ) { 
                    // unbind the existing color picker script in case there is.
                    var _oNewColorInput = _oNewColorInput.clone(); 
                }                    
                var _sInputID       = _oNewColorInput.attr( 'id' );
                
                // Reset the value of the color picker.
                var _sInputValue    = _oNewColorInput.val() 
                    ? _oNewColorInput.val() 
                    : _oNewColorInput.attr( 'data-default' );
                var _sInputStyle = _sInputValue !== 'transparent' && _oNewColorInput.attr( 'style' )
                    ? _oNewColorInput.attr( 'style' ) 
                    : '';
                _oNewColorInput.val( _sInputValue ); // set the default value    
                _oNewColorInput.attr( 'style', _sInputStyle ); // remove the background color set to the input field ( for WP 3.4.x or below )  

                // Replace the old color picker elements with the new one.
                // WP 3.5+
                if ( _oIris.length > 0 ) { 
                    jQuery( _oIris ).replaceWith( _oNewColorInput );
                } 
                // WP 3.4.x -     
                else { 
                    oCloned.find( '.colorpicker' )
                        .replaceWith( '<div class=\\"colorpicker\\" id=\\"color_' + _sInputID + '\\"></div>' );
                }

                // Bind the color picker event.
                registerAdminPageFrameworkColorPickerField( _oNewColorInput );                
            
            } );                   
        },    
    },
    {$_aJSArray}
    );
});
JAVASCRIPTS;
    }