From: Gorrie Date: Thu, 12 Jan 2017 00:46:05 +0000 (+1300) Subject: Add attribute for auto focus X-Git-Tag: 6.3.1~23^2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F9632%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Add attribute for auto focus Checks for the attribute [data-autofocus] within the toggled off canvas and focuses on the first occurrence if available. Otherwise reverts to standard behaviour. --- diff --git a/js/foundation.offcanvas.js b/js/foundation.offcanvas.js index 2121ca0c8..fb5c2b1f1 100644 --- a/js/foundation.offcanvas.js +++ b/js/foundation.offcanvas.js @@ -196,7 +196,12 @@ class OffCanvas { if (this.options.autoFocus === true) { this.$element.one(Foundation.transitionend(this.$element), function() { - _this.$element.find('a, button').eq(0).focus(); + var canvasFocus = _this.$element.find('[data-autofocus]'); + if (canvasFocus.length) { + canvasFocus.eq(0).focus(); + } else { + _this.$element.find('a, button').eq(0).focus(); + } }); }