├── .eslintrc.json ├── .github └── CODEOWNERS ├── .gitignore ├── .travis.yml ├── LICENSE.md ├── README.md ├── package-lock.json ├── package.json ├── template.js ├── tests ├── .eslintrc.json ├── basic.html ├── document-fragment.html └── runner.html └── wct.conf.json /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint:recommended", 3 | "env": { 4 | "browser": true 5 | }, 6 | "plugins": [ 7 | "html" 8 | ], 9 | "rules": { 10 | "semi": "error", 11 | "strict": "error" 12 | }, 13 | "parserOptions": { 14 | "ecmaVersion": 5 15 | } 16 | } -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @azakus 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | dist: trusty 4 | node_js: '9' 5 | addons: 6 | firefox: latest 7 | chrome: stable 8 | before_script: 9 | - npm run lint 10 | script: 11 | - xvfb-run wct --npm 12 | - if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then wct --npm -s 'windows 10/microsoftedge@13' -s 'windows 10/microsoftedge@14' -s 'windows 10/microsoftedge@15' -s 'windows 10/microsoftedge@16' 13 | -s 'windows 8.1/internet explorer@11' -s 'macos 10.13/safari@11' -s 'os x 10.12/safari@10' -s 'os x 10.11/safari@9' -s 'Linux/chrome@41'; 14 | fi 15 | env: 16 | global: 17 | - secure: oucYIKHVGwlwga761L4VtSlIDA1rFOnglofd8A3DwbDG7yAJG8/5knkzB/1KiveGGswbfgLyi74ni43Ge1c6AUvEQOeKvaDmjvw4BZ59lRMD+ADWcSFHIhvQ7ArxFiWt/jusFoacMfxdX3ExnWFPfYOctb96olpIIyN6eif5vx13knmW+0iE9upuO1fkPKms7Ym/XjXDsv79SJ+wVrs8iqguO1oXoxwPP/RRAKhK3pyhSIqKnCFeU7UIVHFFEcfOSHm5LtrDvqqTfUGd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LX4KQNf0GYILNqgsWA8bjh4ws= 19 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # License 2 | 3 | Everything in this repo is BSD style license unless otherwise specified. 4 | 5 | Copyright (c) 2016 The Polymer Authors. All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following disclaimer 13 | in the documentation and/or other materials provided with the 14 | distribution. 15 | * Neither the name of Google Inc. nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 🚨 Moved to [`webcomponents/polyfills/packages/template`][1] 🚨 2 | 3 | The [`webcomponents/template`][2] repo has been migrated to [`packages/template`][1] folder of the [`webcomponents/polyfills`][3] 🚝 *monorepo*. 4 | 5 | We are *actively* working on migrating open Issues and PRs to the new repo. New Issues and PRs should be filed at [`webcomponents/polyfills`][3]. 6 | 7 | [1]: https://github.com/webcomponents/polyfills/tree/master/packages/template 8 | [2]: https://github.com/webcomponents/template 9 | [3]: https://github.com/webcomponents/polyfills 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@webcomponents/template", 3 | "version": "1.4.0", 4 | "description": "Minimal template polyfills needed by webcomponents.js", 5 | "main": "template.js", 6 | "directories": { 7 | "test": "tests" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/webcomponents/template.git" 12 | }, 13 | "author": "The Polymer Authors", 14 | "license": "BSD-3-Clause", 15 | "bugs": { 16 | "url": "https://github.com/webcomponents/template/issues" 17 | }, 18 | "scripts": { 19 | "test": "npm run lint && wct", 20 | "lint": "eslint template.js tests/**/*.html" 21 | }, 22 | "homepage": "http://webcomponents.org", 23 | "devDependencies": { 24 | "eslint": "^5.2.0", 25 | "eslint-plugin-html": "^4.0.3", 26 | "wct-browser-legacy": "^1.0.1", 27 | "web-component-tester": "^6.7.1" 28 | }, 29 | "publishConfig": { 30 | "access": "public" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /template.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright (c) 2016 The Polymer Project Authors. All rights reserved. 4 | * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 5 | * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 6 | * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 7 | * Code distributed by Google as part of the polymer project is also 8 | * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 9 | */ 10 | 11 | // minimal template polyfill 12 | (function() { 13 | 'use strict'; 14 | 15 | var needsTemplate = (typeof HTMLTemplateElement === 'undefined'); 16 | var brokenDocFragment = !(document.createDocumentFragment().cloneNode() instanceof DocumentFragment); 17 | var needsDocFrag = false; 18 | 19 | // NOTE: Replace DocumentFragment to work around IE11 bug that 20 | // causes children of a document fragment modified while 21 | // there is a mutation observer to not have a parentNode, or 22 | // have a broken parentNode (!?!) 23 | if (/Trident/.test(navigator.userAgent)) { 24 | (function() { 25 | 26 | needsDocFrag = true; 27 | 28 | var origCloneNode = Node.prototype.cloneNode; 29 | Node.prototype.cloneNode = function cloneNode(deep) { 30 | var newDom = origCloneNode.call(this, deep); 31 | if (this instanceof DocumentFragment) { 32 | newDom.__proto__ = DocumentFragment.prototype; 33 | } 34 | return newDom; 35 | }; 36 | 37 | // IE's DocumentFragment querySelector code doesn't work when 38 | // called on an element instance 39 | DocumentFragment.prototype.querySelectorAll = HTMLElement.prototype.querySelectorAll; 40 | DocumentFragment.prototype.querySelector = HTMLElement.prototype.querySelector; 41 | 42 | Object.defineProperties(DocumentFragment.prototype, { 43 | 'nodeType': { 44 | get: function () { 45 | return Node.DOCUMENT_FRAGMENT_NODE; 46 | }, 47 | configurable: true 48 | }, 49 | 50 | 'localName': { 51 | get: function () { 52 | return undefined; 53 | }, 54 | configurable: true 55 | }, 56 | 57 | 'nodeName': { 58 | get: function () { 59 | return '#document-fragment'; 60 | }, 61 | configurable: true 62 | } 63 | }); 64 | 65 | var origInsertBefore = Node.prototype.insertBefore; 66 | function insertBefore(newNode, refNode) { 67 | if (newNode instanceof DocumentFragment) { 68 | var child; 69 | while ((child = newNode.firstChild)) { 70 | origInsertBefore.call(this, child, refNode); 71 | } 72 | } else { 73 | origInsertBefore.call(this, newNode, refNode); 74 | } 75 | return newNode; 76 | } 77 | Node.prototype.insertBefore = insertBefore; 78 | 79 | var origAppendChild = Node.prototype.appendChild; 80 | Node.prototype.appendChild = function appendChild(child) { 81 | if (child instanceof DocumentFragment) { 82 | insertBefore.call(this, child, null); 83 | } else { 84 | origAppendChild.call(this, child); 85 | } 86 | return child; 87 | }; 88 | 89 | var origRemoveChild = Node.prototype.removeChild; 90 | var origReplaceChild = Node.prototype.replaceChild; 91 | Node.prototype.replaceChild = function replaceChild(newChild, oldChild) { 92 | if (newChild instanceof DocumentFragment) { 93 | insertBefore.call(this, newChild, oldChild); 94 | origRemoveChild.call(this, oldChild); 95 | } else { 96 | origReplaceChild.call(this, newChild, oldChild); 97 | } 98 | return oldChild; 99 | }; 100 | 101 | Document.prototype.createDocumentFragment = function createDocumentFragment() { 102 | var frag = this.createElement('df'); 103 | frag.__proto__ = DocumentFragment.prototype; 104 | return frag; 105 | }; 106 | 107 | var origImportNode = Document.prototype.importNode; 108 | Document.prototype.importNode = function importNode(impNode, deep) { 109 | deep = deep || false; 110 | var newNode = origImportNode.call(this, impNode, deep); 111 | if (impNode instanceof DocumentFragment) { 112 | newNode.__proto__ = DocumentFragment.prototype; 113 | } 114 | return newNode; 115 | }; 116 | })(); 117 | } 118 | 119 | // NOTE: we rely on this cloneNode not causing element upgrade. 120 | // This means this polyfill must load before the CE polyfill and 121 | // this would need to be re-worked if a browser supports native CE 122 | // but not