@@ -153,14 +153,15 @@ function findFocusableElementWithin(hostElement) {
153153/**
154154 * Determines if an element is attached to the DOM.
155155 * @param {Element } element to check
156- * @return {Boolean } whether the element is in DOM
156+ * @return {boolean } whether the element is in DOM
157157 */
158158function isConnected ( element ) {
159159 return element . isConnected || document . body . contains ( element ) ;
160160}
161161
162162/**
163163 * @param {!Event } event
164+ * @return {?Element }
164165 */
165166function findFormSubmitter ( event ) {
166167 if ( event . submitter ) {
@@ -179,7 +180,7 @@ function findFormSubmitter(event) {
179180 submitter = root . activeElement ;
180181 }
181182
182- if ( submitter . form !== form ) {
183+ if ( ! submitter || submitter . form !== form ) {
183184 return null ;
184185 }
185186 return submitter ;
@@ -195,7 +196,7 @@ function maybeHandleSubmit(event) {
195196 var form = /** @type {!HTMLFormElement } */ ( event . target ) ;
196197
197198 // We'd have a value if we clicked on an imagemap.
198- var value = dialogPolyfill . useValue ;
199+ var value = dialogPolyfill . imagemapUseValue ;
199200 var submitter = findFormSubmitter ( event ) ;
200201 if ( value === null && submitter ) {
201202 value = submitter . value ;
@@ -215,7 +216,8 @@ function maybeHandleSubmit(event) {
215216 }
216217 event . preventDefault ( ) ;
217218
218- if ( submitter ) {
219+ if ( value != null ) {
220+ // nb. we explicitly check against null/undefined
219221 dialog . close ( value ) ;
220222 } else {
221223 dialog . close ( ) ;
@@ -751,7 +753,7 @@ dialogPolyfill.DialogManager.prototype.removeDialog = function(dpi) {
751753
752754dialogPolyfill . dm = new dialogPolyfill . DialogManager ( ) ;
753755dialogPolyfill . formSubmitter = null ;
754- dialogPolyfill . useValue = null ;
756+ dialogPolyfill . imagemapUseValue = null ;
755757
756758/**
757759 * Installs global handlers, such as click listers and native method overrides. These are needed
@@ -796,7 +798,7 @@ if (window.HTMLDialogElement === undefined) {
796798 */
797799 document . addEventListener ( 'click' , function ( ev ) {
798800 dialogPolyfill . formSubmitter = null ;
799- dialogPolyfill . useValue = null ;
801+ dialogPolyfill . imagemapUseValue = null ;
800802 if ( ev . defaultPrevented ) { return ; } // e.g. a submit which prevents default submission
801803
802804 var target = /** @type {Element } */ ( ev . target ) ;
@@ -810,7 +812,7 @@ if (window.HTMLDialogElement === undefined) {
810812 if ( ! valid ) {
811813 if ( ! ( target . localName === 'input' && target . type === 'image' ) ) { return ; }
812814 // this is a <input type="image">, which can submit forms
813- dialogPolyfill . useValue = ev . offsetX + ',' + ev . offsetY ;
815+ dialogPolyfill . imagemapUseValue = ev . offsetX + ',' + ev . offsetY ;
814816 }
815817
816818 var dialog = findNearestDialog ( target ) ;
0 commit comments