]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Fix cleanup issues found by unit tests 9282/head
authorKevin Ball <kmball11@gmail.com>
Fri, 21 Oct 2016 21:54:32 +0000 (14:54 -0700)
committerKevin Ball <kmball11@gmail.com>
Fri, 21 Oct 2016 21:54:32 +0000 (14:54 -0700)
js/foundation.orbit.js
js/foundation.reveal.js
js/foundation.tooltip.js
js/foundation.util.keyboard.js

index 8a41d4dff97bfa74d13e0e82f257f27586cc2e5e..3da0b04c5518cb39db89a4490c38db8a6f93c3e2 100644 (file)
@@ -216,7 +216,7 @@ class Orbit {
           _this.changeSlide(ltr, $slide, idx);
         });
       }
-      
+
       if (this.options.accessible) {
         this.$wrapper.add(this.$bullets).on('keydown.zf.orbit', function(e) {
           // handle keyboard event with keyboard util
@@ -247,6 +247,7 @@ class Orbit {
   * @fires Orbit#slidechange
   */
   changeSlide(isLTR, chosenSlide, idx) {
+    if (!this.$slides) {return; } // Don't freak out if we're in the middle of cleanup
     var $curSlide = this.$slides.filter('.is-active').eq(0);
 
     if (/mui/g.test($curSlide[0].className)) { return false; } //if the slide is currently animating, kick out of the function
@@ -273,7 +274,7 @@ class Orbit {
       * @event Orbit#beforeslidechange
       */
       this.$element.trigger('beforeslidechange.zf.orbit', [$curSlide, $newSlide]);
-      
+
       if (this.options.bullets) {
         idx = idx || this.$slides.index($newSlide); //grab index to update bullets
         this._updateBullets(idx);
index 211f1667cc54dc4190060c1d2734ec3177c0dd2e..05f949c20421bdad3c764c44719a44e0e58e29a8 100644 (file)
@@ -157,10 +157,10 @@ class Reveal {
 
     if (this.options.closeOnClick && this.options.overlay) {
       this.$overlay.off('.zf.reveal').on('click.zf.reveal', function(e) {
-        if (e.target === _this.$element[0] || 
-          $.contains(_this.$element[0], e.target) || 
-            !$.contains(document, e.target)) { 
-              return; 
+        if (e.target === _this.$element[0] ||
+          $.contains(_this.$element[0], e.target) ||
+            !$.contains(document, e.target)) {
+              return;
         }
         _this.close();
       });
@@ -247,8 +247,10 @@ class Reveal {
         Foundation.Motion.animateIn(this.$overlay, 'fade-in');
       }
       Foundation.Motion.animateIn(this.$element, this.options.animationIn, () => {
-        this.focusableElements = Foundation.Keyboard.findFocusable(this.$element);
-        afterAnimationFocus();
+        if(this.$element) { // protect against object having been removed
+          this.focusableElements = Foundation.Keyboard.findFocusable(this.$element);
+          afterAnimationFocus();
+        }
       });
     }
     // jQuery method of reveal
@@ -292,12 +294,13 @@ class Reveal {
    */
   _extraHandlers() {
     var _this = this;
+    if(!this.$element) { return; } // If we're in the middle of cleanup, don't freak out
     this.focusableElements = Foundation.Keyboard.findFocusable(this.$element);
 
     if (!this.options.overlay && this.options.closeOnClick && !this.options.fullScreen) {
       $('body').on('click.zf.reveal', function(e) {
-        if (e.target === _this.$element[0] || 
-          $.contains(_this.$element[0], e.target) || 
+        if (e.target === _this.$element[0] ||
+          $.contains(_this.$element[0], e.target) ||
             !$.contains(document, e.target)) { return; }
         _this.close();
       });
index dd85fadda4eaaa728ae715c995accf9a4f5432c0..1936d1b9529b1b10f138e18409dbe90e952233b6 100644 (file)
@@ -455,4 +455,4 @@ Tooltip.defaults = {
 // Window exports
 Foundation.plugin(Tooltip, 'Tooltip');
 
-}(jQuery);
\ No newline at end of file
+}(jQuery);
index 290e743829291abb17f4caf91f8ee6419a542d99..d4a5344aceb6d68a9e4c4b35c4e823e5eb4c9ec2 100644 (file)
@@ -83,6 +83,7 @@ var Keyboard = {
    * @return {jQuery} $focusable - all focusable elements within `$element`
    */
   findFocusable($element) {
+    if(!$element) {return false; }
     return $element.find('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]').filter(function() {
       if (!$(this).is(':visible') || $(this).attr('tabindex') < 0) { return false; } //only have visible elements and those that have a tabindex greater or equal 0
       return true;