├── .gitignore ├── src ├── shadow-dom.js ├── shadow-dom-css.js ├── html-imports.js ├── document.currentScript.js └── document.registerElement.js ├── test ├── shadow-dom-css.html ├── nested-html-imports.html ├── components │ ├── shadow-dom-css.html │ ├── test1.html │ └── sub-import1.html └── index.html ├── package.json ├── Gruntfile.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | *.sublime-* 4 | -------------------------------------------------------------------------------- /src/shadow-dom.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | if ('createShadowRoot' in HTMLElement.prototype) { return; } 4 | 5 | HTMLElement.prototype.createShadowRoot = function() { 6 | 7 | return this.shadowRoot = this; 8 | }; 9 | 10 | })(); 11 | -------------------------------------------------------------------------------- /test/shadow-dom-css.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/nested-html-imports.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web-components-polyfills", 3 | "version": "1.2.1", 4 | "description": "Lightweight Web Components polyfills.", 5 | "main": "web-components-polyfills.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git@git.dev.wds.co:web-components/web-components-polyfills.git" 12 | }, 13 | "keywords": [ 14 | "web", 15 | "components", 16 | "shadow", 17 | "dom", 18 | "custom", 19 | "elements", 20 | "html", 21 | "imports" 22 | ], 23 | "author": "Roman Liutikov ", 24 | "license": "MIT", 25 | "dependencies": {}, 26 | "devDependencies": { 27 | "grunt": "^0.4.5", 28 | "grunt-contrib-uglify": "^0.5.1" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function (grunt) { 4 | 5 | grunt.initConfig({ 6 | pkg: grunt.file.readJSON('package.json'), 7 | uglify: { 8 | optimize: { 9 | files: { 10 | 'build/web-components-polyfills.min.js': [ 11 | 'src/document.currentScript.js', 12 | 'src/shadow-dom-css.js', 13 | 'src/shadow-dom.js', 14 | 'src/document.registerElement.js', 15 | 'src/html-imports.js' 16 | ] 17 | }, 18 | options: { 19 | wrap: true, 20 | sourceMap: true, 21 | sourceMapName: 'build/web-components-polyfills.min.js.map' 22 | } 23 | }, 24 | options: { 25 | banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + 26 | '<%= grunt.template.today("yyyy-mm-dd") %> */' 27 | } 28 | } 29 | }); 30 | 31 | grunt.loadNpmTasks('grunt-contrib-uglify'); 32 | 33 | grunt.registerTask('default', ['uglify:optimize']); 34 | 35 | }; 36 | -------------------------------------------------------------------------------- /test/components/shadow-dom-css.html: -------------------------------------------------------------------------------- 1 | 24 | 25 | 50 | -------------------------------------------------------------------------------- /test/components/test1.html: -------------------------------------------------------------------------------- 1 | 23 | 24 | 50 | -------------------------------------------------------------------------------- /test/components/sub-import1.html: -------------------------------------------------------------------------------- 1 | 3 | 22 | 23 | 24 | 25 | 26 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/shadow-dom-css.js: -------------------------------------------------------------------------------- 1 | (function (scope) { 2 | 3 | /* Assume Shadow DOM is supported */ 4 | scope.ShadowDOMCSS = { support: true }; 5 | 6 | /* Check for Shadow DOM support */ 7 | if ('createShadowRoot' in HTMLElement.prototype) { return; } 8 | 9 | /* If not — set to false */ 10 | scope.ShadowDOMCSS.support = false; 11 | 12 | /* Shadow DOM CSS polyfill */ 13 | scope.ShadowDOMCSS.shim = function (importEl) { 14 | 15 | var importStyles; 16 | 17 | /* Get styles from template. Depends on