From a6d36f84e359fc648aa769324ed5bcb348145b6d Mon Sep 17 00:00:00 2001 From: John Messerly Date: Thu, 26 Jun 2014 16:16:31 -0700 Subject: [PATCH] fix form.elements -- this is used by NodeBind getAssociatedRadioButtons --- build.json | 1 + shadowdom.js | 1 + src/wrappers/HTMLFormElement.js | 35 +++++++++++++++++++++++++++++++++ test/js/HTMLFormElement.js | 17 ++++++++++++++++ test/test.main.js | 1 + 5 files changed, 55 insertions(+) create mode 100644 src/wrappers/HTMLFormElement.js create mode 100644 test/js/HTMLFormElement.js diff --git a/build.json b/build.json index dd25bb1..639f1b8 100644 --- a/build.json +++ b/build.json @@ -19,6 +19,7 @@ "src/wrappers/HTMLElement.js", "src/wrappers/HTMLCanvasElement.js", "src/wrappers/HTMLContentElement.js", + "src/wrappers/HTMLFormElement.js", "src/wrappers/HTMLImageElement.js", "src/wrappers/HTMLShadowElement.js", "src/wrappers/HTMLTemplateElement.js", diff --git a/shadowdom.js b/shadowdom.js index d5c6fed..432fd45 100644 --- a/shadowdom.js +++ b/shadowdom.js @@ -35,6 +35,7 @@ 'src/wrappers/HTMLElement.js', 'src/wrappers/HTMLCanvasElement.js', 'src/wrappers/HTMLContentElement.js', + 'src/wrappers/HTMLFormElement.js', 'src/wrappers/HTMLImageElement.js', 'src/wrappers/HTMLShadowElement.js', 'src/wrappers/HTMLTemplateElement.js', diff --git a/src/wrappers/HTMLFormElement.js b/src/wrappers/HTMLFormElement.js new file mode 100644 index 0000000..842066f --- /dev/null +++ b/src/wrappers/HTMLFormElement.js @@ -0,0 +1,35 @@ +/* + * Copyright 2014 The Polymer Authors. All rights reserved. + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ + +(function(scope) { + 'use strict'; + + var HTMLElement = scope.wrappers.HTMLElement; + var mixin = scope.mixin; + var registerWrapper = scope.registerWrapper; + var wrapHTMLCollection = scope.wrapHTMLCollection; + var unwrap = scope.unwrap; + + var OriginalHTMLFormElement = window.HTMLFormElement; + + function HTMLFormElement(node) { + HTMLElement.call(this, node); + } + HTMLFormElement.prototype = Object.create(HTMLElement.prototype); + mixin(HTMLFormElement.prototype, { + get elements() { + // Note: technically this should be an HTMLFormControlsCollection, but + // that inherits from HTMLCollection, so should be good enough. Spec: + // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#htmlformcontrolscollection + return wrapHTMLCollection(unwrap(this).elements); + } + }); + + registerWrapper(OriginalHTMLFormElement, HTMLFormElement, + document.createElement('form')); + + scope.wrappers.HTMLFormElement = HTMLFormElement; +})(window.ShadowDOMPolyfill); diff --git a/test/js/HTMLFormElement.js b/test/js/HTMLFormElement.js new file mode 100644 index 0000000..9423868 --- /dev/null +++ b/test/js/HTMLFormElement.js @@ -0,0 +1,17 @@ +/* + * Copyright 2014 The Polymer Authors. All rights reserved. + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ + +suite('HTMLFormElement', function() { + + test('elements', function() { + var form = document.createElement('form'); + var input = document.createElement('input'); + form.appendChild(input); + assert.instanceOf(form.elements, HTMLCollection); + assert.equal(form.elements.length, 1); + }); + +}); diff --git a/test/test.main.js b/test/test.main.js index e397fe9..cbc62f0 100644 --- a/test/test.main.js +++ b/test/test.main.js @@ -85,6 +85,7 @@ var modules = [ 'HTMLContentElement.js', 'HTMLElement.js', 'HTMLFieldSetElement.js', + 'HTMLFormElement.js', 'HTMLHeadElement.js', 'HTMLHtmlElement.js', 'HTMLImageElement.js',