]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Update forms to delegate events 762/head
authorNic Haynes <nic@nicinabox.com>
Tue, 7 Aug 2012 01:18:31 +0000 (20:18 -0500)
committerNic Haynes <nic@nicinabox.com>
Tue, 7 Aug 2012 01:18:31 +0000 (20:18 -0500)
Elements are not required to exist when DOM is loaded.

vendor/assets/javascripts/foundation/jquery.foundation.forms.js

index 11c2c61d00874836b28476e069ef4e9f956f7f56..73838ef2143bcacb13ced522b157be21da17a3da 100644 (file)
@@ -7,7 +7,7 @@
 */
 
 (function( $ ){
-  
+
   /**
    * Helper object used to quickly adjust all hidden parent element's, display and visibility properties.
    * This is currently used for the custom drop downs. When the dropdowns are contained within a reveal modal
       adjust : function( $child ) {
         // Internal reference.
         var _self = this;
-        
+
         // Set all hidden parent elements, including this element.
         _self.hidden = $child.parents().andSelf().filter( ":hidden" );
-        
+
         // Loop through all hidden elements.
         _self.hidden.each( function() {
-          
+
           // Cache the element.
           var $elem = $( this );
-          
+
           // Store the style attribute.
           // Undefined if element doesn't have a style attribute.
           _self.tmp.push( $elem.attr( 'style' ) );
-          
+
           // Set the element's display property to block,
           // but ensure it's visibility is hidden.
           $elem.css( { 'visibility' : 'hidden', 'display' : 'block' } );
         });
-      
+
       }, // end adjust
 
       /**
@@ -96,7 +96,7 @@
 
   jQuery.foundation = jQuery.foundation || {};
   jQuery.foundation.customForms = jQuery.foundation.customForms || {};
-  
+
   $.foundation.customForms.appendCustomMarkup = function ( options ) {
 
     var defaults = {
         // Insert the the currently selected list item before all other elements.
         // Then, find the element and assign it to $currentSelect.
         //
-        
+
         $currentSelect = $customSelect.prepend( '<a href="#" class="current">' + $selectedOption.html() + '</a>' ).find( ".current" );
         //
         // Add the custom select element after the <select> element.
           if ($currentSelect) {
             $currentSelect.html( $( this ).html() );
           }
-          
+
         }
 
       });
     }
   };
 
-  $('form.custom span.custom.checkbox').on('click', function (event) {
+  $(document).on('click', 'form.custom span.custom.checkbox', function (event) {
     event.preventDefault();
     event.stopPropagation();
 
     toggleCheckbox($(this));
   });
 
-  $('form.custom span.custom.radio').on('click', function (event) {
+  $(document).on('click', 'form.custom span.custom.radio', function (event) {
     event.preventDefault();
     event.stopPropagation();
 
     toggleRadio($(this));
   });
 
-  $('form.custom select').on('change', function (event) {
+  $(document).on('change', 'form.custom select', function (event) {
     refreshCustomSelect($(this));
   });
 
-  $('form.custom label').on('click', function (event) {
+  $(document).on('click', 'form.custom label', function (event) {
     var $associatedElement = $('#' + $(this).attr('for')),
         $customCheckbox,
         $customRadio;
     }
   });
 
-  $('form.custom div.custom.dropdown a.current, form.custom div.custom.dropdown a.selector').live('click', function (event) {
+  $(document).on('click', 'form.custom div.custom.dropdown a.current, form.custom div.custom.dropdown a.selector', function (event) {
     var $this = $(this),
         $dropdown = $this.closest('div.custom.dropdown'),
         $select = $dropdown.prev();
     }
   });
 
-  $('form.custom div.custom.dropdown li').live('click', function (event) {
+  $(document).on('click', 'form.custom div.custom.dropdown li', function (event) {
     var $this = $(this),
         $customDropdown = $this.closest('div.custom.dropdown'),
         $select = $customDropdown.prev(),
     $select[0].selectedIndex = selectedIndex;
 
     $select.trigger('change');
-  });  
-  
-  
+  });
+
+
   $.fn.foundationCustomForms = $.foundation.customForms.appendCustomMarkup;
 
 })( jQuery );