This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from arv/new-image
Add support for new Image
- Loading branch information
Showing
8 changed files
with
163 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
[ | ||
"../observe-js/src/observe.js", | ||
"../WeakMap/weakmap.js", | ||
"src/wrappers.js", | ||
"src/wrappers/events.js", | ||
"src/wrappers/NodeList.js", | ||
"src/wrappers/Node.js", | ||
"src/querySelector.js", | ||
"src/wrappers/node-interfaces.js", | ||
"src/wrappers/CharacterData.js", | ||
"src/wrappers/Element.js", | ||
"src/wrappers/HTMLElement.js", | ||
"src/wrappers/HTMLCanvasElement.js", | ||
"src/wrappers/HTMLContentElement.js", | ||
"src/wrappers/HTMLShadowElement.js", | ||
"src/wrappers/HTMLTemplateElement.js", | ||
"src/wrappers/HTMLUnknownElement.js", | ||
"src/wrappers/CanvasRenderingContext2D.js", | ||
"src/wrappers/WebGLRenderingContext.js", | ||
"src/wrappers/generic.js", | ||
"src/wrappers/ShadowRoot.js", | ||
"src/ShadowRenderer.js", | ||
"src/wrappers/elements-with-form-property.js", | ||
"src/wrappers/Document.js", | ||
"src/wrappers/Window.js", | ||
"src/wrappers/MutationObserver.js", | ||
"src/wrappers/Range.js", | ||
"src/wrappers/override-constructors.js" | ||
"../observe-js/src/observe.js", | ||
"../WeakMap/weakmap.js", | ||
"src/wrappers.js", | ||
"src/wrappers/events.js", | ||
"src/wrappers/NodeList.js", | ||
"src/wrappers/Node.js", | ||
"src/querySelector.js", | ||
"src/wrappers/node-interfaces.js", | ||
"src/wrappers/CharacterData.js", | ||
"src/wrappers/Element.js", | ||
"src/wrappers/HTMLElement.js", | ||
"src/wrappers/HTMLCanvasElement.js", | ||
"src/wrappers/HTMLContentElement.js", | ||
"src/wrappers/HTMLImageElement.js", | ||
"src/wrappers/HTMLShadowElement.js", | ||
"src/wrappers/HTMLTemplateElement.js", | ||
"src/wrappers/HTMLUnknownElement.js", | ||
"src/wrappers/CanvasRenderingContext2D.js", | ||
"src/wrappers/WebGLRenderingContext.js", | ||
"src/wrappers/generic.js", | ||
"src/wrappers/ShadowRoot.js", | ||
"src/ShadowRenderer.js", | ||
"src/wrappers/elements-with-form-property.js", | ||
"src/wrappers/Document.js", | ||
"src/wrappers/Window.js", | ||
"src/wrappers/MutationObserver.js", | ||
"src/wrappers/Range.js", | ||
"src/wrappers/override-constructors.js" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2013 The Polymer Authors. All rights reserved. | ||
// Use of this source code is goverened by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
(function(scope) { | ||
'use strict'; | ||
|
||
var HTMLElement = scope.wrappers.HTMLElement; | ||
var registerWrapper = scope.registerWrapper; | ||
var unwrap = scope.unwrap; | ||
var rewrap = scope.rewrap; | ||
|
||
var OriginalHTMLImageElement = window.HTMLImageElement; | ||
|
||
function HTMLImageElement(node) { | ||
HTMLElement.call(this, node); | ||
} | ||
HTMLImageElement.prototype = Object.create(HTMLElement.prototype); | ||
|
||
registerWrapper(OriginalHTMLImageElement, HTMLImageElement, | ||
document.createElement('img')); | ||
|
||
function Image(width, height) { | ||
if (!(this instanceof Image)) { | ||
throw new TypeError( | ||
'DOM object constructor cannot be called as a function.'); | ||
} | ||
|
||
var node = unwrap(document.createElement('img')); | ||
if (width !== undefined) | ||
node.width = width; | ||
if (height !== undefined) | ||
node.height = height; | ||
HTMLElement.call(this, node); | ||
rewrap(node, this); | ||
} | ||
|
||
Image.prototype = HTMLImageElement.prototype; | ||
|
||
scope.wrappers.HTMLImageElement = HTMLImageElement; | ||
scope.wrappers.Image = Image; | ||
})(this.ShadowDOMPolyfill); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2013 The Polymer Authors. All rights reserved. | ||
* Use of this source code is goverened by a BSD-style | ||
* license that can be found in the LICENSE file. | ||
*/ | ||
|
||
suite('HTMLImageElement', function() { | ||
|
||
var iconUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAHklEQVQ4T2Nk+A+EFADGUQMYRsOAYTQMgHloGKQDAJXkH/HZpKBrAAAAAElFTkSuQmCC'; | ||
|
||
test('instanceof', function() { | ||
var img = document.createElement('img'); | ||
assert.instanceOf(img, HTMLImageElement); | ||
assert.instanceOf(img, Image); | ||
assert.instanceOf(img, HTMLElement); | ||
}); | ||
|
||
test('Image', function() { | ||
var img = new Image(); | ||
assert.instanceOf(img, HTMLImageElement); | ||
assert.instanceOf(img, Image); | ||
assert.instanceOf(img, HTMLElement); | ||
}); | ||
|
||
test('Image arguments', function() { | ||
var img = new Image(32); | ||
assert.equal(img.width, 32); | ||
assert.equal(img.height, 0); | ||
|
||
var img = new Image(undefined, 32); | ||
assert.equal(img.width, 0); | ||
assert.equal(img.height, 32); | ||
}); | ||
|
||
test('Image called as function', function() { | ||
assert.throws(Image, TypeError); | ||
}); | ||
|
||
test('Image basics', function() { | ||
var img = new Image(); | ||
assert.equal('img', img.localName); | ||
|
||
var div = document.createElement('div'); | ||
div.appendChild(img); | ||
|
||
assert.equal(div.firstChild, img); | ||
assert.equal('<div><img></div>', div.outerHTML); | ||
|
||
assert.equal(img.width, 0); | ||
assert.equal(img.height, 0); | ||
}); | ||
|
||
test('Image load', function(done) { | ||
var img = new Image(); | ||
img.addEventListener('load', function() { | ||
done(); | ||
}); | ||
img.src = iconUrl; | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters