Skip to:
Content

BuddyPress.org

Changeset 8007


Ignore:
Timestamp:
02/28/2014 09:46:51 PM (11 years ago)
Author:
djpaul
Message:

Members + Templates: code standards improvement for the profile field "clear" button JS. Also adds jsdoc.

Location:
trunk
Files:
2 edited

Legend:

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

    r7963 r8007  
    3232
    3333
    34 function clear(container) {
    35     if( !document.getElementById(container) ) return;
     34/**
     35 * Deselects any select options or input options for the specified field element.
     36 *
     37 * @param {String} container HTML ID of the field
     38 * @since BuddyPress (1.0.0)
     39 */
     40function clear( container ) {
     41    container = document.getElementById( container );
     42    if ( ! container ) {
     43        return;
     44    }
    3645
    37     var container = document.getElementById(container);
     46    var radioButtons = container.getElementsByTagName( 'INPUT' ),
     47        options = container.getElementsByTagName( 'OPTION' ),
     48        i       = 0;
    3849
    39     if ( radioButtons = container.getElementsByTagName('INPUT') ) {
    40         for(var i=0; i<radioButtons.length; i++) {
     50    if ( radioButtons ) {
     51        for ( i = 0; i < radioButtons.length; i++ ) {
    4152            radioButtons[i].checked = '';
    4253        }
    4354    }
    4455
    45     if ( options = container.getElementsByTagName('OPTION') ) {
    46         for(var i=0; i<options.length; i++) {
     56    if ( options ) {
     57        for ( i = 0; i < options.length; i++ ) {
    4758            options[i].selected = false;
    4859        }
    4960    }
    50 
    51     return;
    5261}
  • trunk/bp-templates/bp-legacy/js/buddypress.js

    r7952 r8007  
    16971697}
    16981698
    1699 function clear(container) {
    1700     if( !document.getElementById(container) ) return;
    1701 
    1702     var container = document.getElementById(container);
    1703 
    1704     if ( radioButtons = container.getElementsByTagName('INPUT') ) {
    1705         for(var i=0; i<radioButtons.length; i++) {
     1699/**
     1700 * Deselects any select options or input options for the specified field element.
     1701 *
     1702 * @param {String} container HTML ID of the field
     1703 * @since BuddyPress (1.2.0)
     1704 */
     1705function clear( container ) {
     1706    container = document.getElementById( container );
     1707    if ( ! container ) {
     1708        return;
     1709    }
     1710
     1711    var radioButtons = container.getElementsByTagName( 'INPUT' ),
     1712        options = container.getElementsByTagName( 'OPTION' ),
     1713        i       = 0;
     1714
     1715    if ( radioButtons ) {
     1716        for ( i = 0; i < radioButtons.length; i++ ) {
    17061717            radioButtons[i].checked = '';
    17071718        }
    17081719    }
    17091720
    1710     if ( options = container.getElementsByTagName('OPTION') ) {
    1711         for(var i=0; i<options.length; i++) {
     1721    if ( options ) {
     1722        for ( i = 0; i < options.length; i++ ) {
    17121723            options[i].selected = false;
    17131724        }
    17141725    }
    1715 
    1716     return;
    17171726}
    17181727
Note: See TracChangeset for help on using the changeset viewer.