Skip to:
Content

BuddyPress.org

Ticket #5691: 5691.patch

File 5691.patch, 2.9 KB (added by boonebgorges, 12 years ago)
  • src/bp-xprofile/admin/js/admin.js

    diff --git src/bp-xprofile/admin/js/admin.js src/bp-xprofile/admin/js/admin.js
    index 80b43c9..ae9ab27 100644
    function add_option(forWhat) {  
    6161        document.getElementById(forWhat + '_option_number').value = theId;
    6262}
    6363
    64 function show_options(forWhat) {
    65         document.getElementById( 'radio'          ).style.display = 'none';
    66         document.getElementById( 'selectbox'      ).style.display = 'none';
    67         document.getElementById( 'multiselectbox' ).style.display = 'none';
    68         document.getElementById( 'checkbox'       ).style.display = 'none';
    69 
    70         if ( forWhat === 'radio' ) {
    71                 document.getElementById( 'radio' ).style.display = '';
     64/**
     65 * Hide all "options" sections, and show the options section for the forWhat type.
     66 */
     67function show_options( forWhat ) {
     68        for ( var i = 0; i < XProfileAdmin.supports_options_field_types.length; i++ ) {
     69                document.getElementById( XProfileAdmin.supports_options_field_types[i] ).style.display = 'none';
    7270        }
    7371
    74         if ( forWhat === 'selectbox' ) {
    75                 document.getElementById( 'selectbox' ).style.display = '';
    76         }
    77 
    78         if ( forWhat === 'multiselectbox' ) {
    79                 document.getElementById( 'multiselectbox' ).style.display = '';
    80         }
    81 
    82         if ( forWhat === 'checkbox' ) {
    83                 document.getElementById( 'checkbox' ).style.display = '';
     72        if ( XProfileAdmin.supports_options_field_types.indexOf( forWhat ) >= 0 ) {
     73                document.getElementById( forWhat ).style.display = '';
    8474        }
    8575}
    8676
    … … jQuery( document ).ready( function() {  
    124114
    125115        // Set focus in Field Title, if we're on the right page
    126116        jQuery( '#bp-xprofile-add-field #title' ).focus();
    127        
     117
    128118        // Set up deleting options ajax
    129119        jQuery( 'a.ajax-option-delete' ).on( 'click', function() {
    130120                var theId = this.id.split( '-' );
  • src/bp-xprofile/bp-xprofile-cssjs.php

    diff --git src/bp-xprofile/bp-xprofile-cssjs.php src/bp-xprofile/bp-xprofile-cssjs.php
    index 8fb4f67..98ccaf9 100644
    function xprofile_add_admin_js() {  
    3939
    4040                $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    4141                wp_enqueue_script( 'xprofile-admin-js', buddypress()->plugin_url . "bp-xprofile/admin/js/admin{$min}.js", array( 'jquery', 'jquery-ui-sortable' ), bp_get_version() );
     42
     43                // Localize strings.
     44                // supports_options_field_types is a dynamic list of field
     45                // types that support options, for use in showing/hiding the
     46                // "please enter options for this field" section
     47                $strings = array(
     48                        'supports_options_field_types' => array(),
     49                );
     50
     51                foreach ( bp_xprofile_get_field_types() as $field_type => $field_type_class ) {
     52                        $field = new $field_type_class();
     53                        if ( $field->supports_options ) {
     54                                $strings['supports_options_field_types'][] = $field_type;
     55                        }
     56                }
     57
     58                wp_localize_script( 'xprofile-admin-js', 'XProfileAdmin', $strings );
    4259        }
    4360}
    4461add_action( 'admin_enqueue_scripts', 'xprofile_add_admin_js', 1 );