From d655665fb673a6e4cf6c950d5a3965b0ef0b65ef Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Sat, 30 May 2009 01:23:33 -0400 Subject: [PATCH] Make sure (defficient) APPLET, OBJECT and EMBED elements are extended with simulated methods in IE8. Return early if _extendedByPrototype is present on an element. --- CHANGELOG | 2 ++ src/dom/dom.js | 16 ++++++---------- test/unit/dom_test.js | 19 ++++++++++++++++++- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 03fa21a..a8df558 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Make sure (deficient) APPLET, OBJECT and EMBED elements are extended with simulated methods in IE8. Return early if `_extendedByPrototype` is present on an element. (Tobie Langel, kangax) + * Replace array creation and `Array#include` with a more efficient `RegExp#test`. (kangax) * Reorganize the way `ElementExtensions` are defined. Make sure elements used in SpecificElementExtensions are cleaned up. (kangax) diff --git a/src/dom/dom.js b/src/dom/dom.js index 14ff976..ae92058 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -1685,16 +1685,12 @@ Element.extend = (function() { if (HTMLOBJECTELEMENT_PROTOTYPE_BUGGY && HTMLAPPLETELEMENT_PROTOTYPE_BUGGY) { return function(element) { - if (element && element.tagName) { - var tagName = element.tagName.toUpperCase(); - if (tagName === 'OBJECT' || tagName === 'APPLET') { + if (element && typeof element._extendedByPrototype == 'undefined') { + var t = element.tagName; + if (t && (/^(?:object|applet|embed)$/i.test(t))) { extendElementWith(element, Element.Methods); - if (tagName === 'OBJECT') { - extendElementWith(element, Element.Methods.ByTag.OBJECT) - } - else if (tagName === 'APPLET') { - extendElementWith(element, Element.Methods.ByTag.APPLET) - } + extendElementWith(element, Element.Methods.Simulated); + extendElementWith(element, Element.Methods.ByTag[t.toUpperCase()]); } } return element; @@ -2008,4 +2004,4 @@ Element.addMethods({ } return Element.extend(clone); } -}); \ No newline at end of file +}); diff --git a/test/unit/dom_test.js b/test/unit/dom_test.js index d9e2e30..3299584 100644 --- a/test/unit/dom_test.js +++ b/test/unit/dom_test.js @@ -641,6 +641,20 @@ new Test.Unit.Runner({ }, testElementExtend: function() { + + Element.Methods.Simulated.simulatedMethod = function() { + return 'simulated'; + }; + Element.addMethods(); + + function testTag(tagName) { + var element = document.createElement(tagName); + this.assertEqual(element, Element.extend(element)); + // test method from Methods + this.assertRespondsTo('show', element); + // test method from Simulated + this.assertRespondsTo('simulatedMethod', element); + } var element = $('element_extend_test'); this.assertRespondsTo('show', element); @@ -665,6 +679,9 @@ new Test.Unit.Runner({ this.assertEqual(textnode, Element.extend(textnode)); this.assert(typeof textnode['show'] == 'undefined'); }, this); + + // clean up + delete Element.Methods.Simulated.simulatedMethod; }, testElementExtendReextendsDiscardedNodes: function() { @@ -1490,4 +1507,4 @@ function preservingBrowserDimensions(callback) { } finally { window.resizeTo(original.width, original.height); } -} \ No newline at end of file +}