Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/03/2012 02:28:05 AM (13 years ago)
Author:
johnjamesjacoby
Message:

XProfile:

  • Allow options to be sorted.
  • Escape all the things.
  • Props humanshell.
  • Fixes #3778.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/admin/js/admin.js

    r6264 r6294  
    44    var newDiv    = document.createElement('p');
    55    var newOption = document.createElement('input');
    6     var label     = document.createElement( 'label' );
    7     var txt       = document.createTextNode( "Option " + theId + ": " );
     6    var span     = document.createElement( 'span' );
     7    var txt       = document.createTextNode( "\u00A0\u039E\u00A0" );
    88    var isDefault = document.createElement( 'input' );
    9     var label1    = document.createElement( 'label' );
     9    var span1    = document.createElement( 'span' );
    1010    var txt1      = document.createTextNode( " Default Value " );
    1111
    1212    newDiv.setAttribute('id', forWhat + '_div' + theId);
     13    newDiv.setAttribute('class', 'sortable');
    1314   
    1415    newOption.setAttribute( 'type', 'text' );
     
    1617    newOption.setAttribute( 'id', forWhat + '_option' + theId );
    1718
    18     label.setAttribute( 'for', forWhat + '_option' + theId );
    19     label.appendChild( txt );
     19    span.appendChild( txt );
    2020
    2121    if ( forWhat == 'checkbox' || forWhat == 'multiselectbox' ) {
     
    2929    isDefault.setAttribute( 'value', theId );
    3030
    31     label1.appendChild( txt1 );
    32     label1.setAttribute( 'for', 'isDefault_' + forWhat + '_option[]' );
     31    span1.appendChild( txt1 );
    3332
    3433    var toDelete     = document.createElement( 'a' );
     
    3938    toDelete.appendChild( toDeleteText );
    4039
    41     newDiv.appendChild( label );
     40    newDiv.appendChild( span );
    4241    newDiv.appendChild( newOption );
    4342    newDiv.appendChild( document.createTextNode( " " ) );
    4443    newDiv.appendChild( isDefault );
    45     newDiv.appendChild( label1 );
     44    newDiv.appendChild( span1 );
    4645    newDiv.appendChild( toDelete );
    4746    holder.appendChild( newDiv );
    4847
     48    // re-initialize the sorable ui
     49    enableSortableFieldOptions( forWhat );
    4950
    5051    theId++;
     
    8687};
    8788
    88 // Set up deleting options ajax
     89function enableSortableFieldOptions( forWhat ) {
     90    if ( jQuery( '#' + forWhat + ' p.sortable' ).length > 1 ) {
     91        jQuery( '.options-box' ).sortable( {
     92            items: 'p.sortable',
     93            tolerance: 'pointer',
     94            axis: 'y',
     95            handle: 'span'
     96        });
     97
     98        jQuery( '.sortable span' ).css( 'cursor', 'move' );
     99    }
     100}
     101
     102function destroySortableFieldOptions() {
     103    jQuery( '.options-box' ).sortable( 'destroy' );
     104    jQuery( '.sortable span' ).css( 'cursor', 'default' );
     105}
     106
    89107jQuery( document ).ready( function() {
    90108
     109    // Set up deleting options ajax
    91110    jQuery( 'a.ajax-option-delete' ).click(
    92111        function() {
     
    103122        }
    104123    );
     124
     125    //
     126    jQuery( '[id^="sort_order_"]' ).change(function() {
     127        if ( jQuery( this ).val() != 'custom' ) {
     128            destroySortableFieldOptions();
     129        } else {
     130            enableSortableFieldOptions( jQuery('#fieldtype :selected').val() );
     131        }
     132    });
    105133
    106134    // Show object if JS is enabled
     
    150178    // Change cursor to move if JS is enabled
    151179    .css( 'cursor', 'move' );
     180
     181    // Allow reordering of field options
     182    enableSortableFieldOptions( jQuery('#fieldtype :selected').val() );
    152183
    153184    // tabs init with a custom tab template and an "add" callback filling in the content
Note: See TracChangeset for help on using the changeset viewer.