├── .gitattributes ├── app ├── scripts │ └── main.js ├── robots.txt ├── favicon.ico ├── styles │ └── main.css ├── 404.html ├── index.html └── .htaccess ├── .bowerrc ├── test ├── .bowerrc ├── bower.json ├── spec │ └── test.js └── index.html ├── .gitignore ├── README.md ├── bower.json ├── .jshintrc ├── .editorconfig ├── package.json ├── Gruntfile.js └── LICENSE /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto -------------------------------------------------------------------------------- /app/scripts/main.js: -------------------------------------------------------------------------------- 1 | console.log('\'Allo \'Allo!'); -------------------------------------------------------------------------------- /app/robots.txt: -------------------------------------------------------------------------------- 1 | # robotstxt.org/ 2 | 3 | User-agent: * 4 | -------------------------------------------------------------------------------- /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "app/bower_components" 3 | } 4 | -------------------------------------------------------------------------------- /test/.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "bower_components" 3 | } 4 | -------------------------------------------------------------------------------- /app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beriberikix/polymerjs-cheatsheet/HEAD/app/favicon.ico -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .tmp 4 | .sass-cache 5 | app/bower_components 6 | test/bower_components 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | polymerjs-cheatsheet 2 | ==================== 3 | 4 | A terse guide to Polymer.js. See http://www.polymer-project.org/ for more details. 5 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "polymerjs-cheatsheet", 3 | "private": true, 4 | "dependencies": { 5 | "jquery": "~1.10.2" 6 | }, 7 | "devDependencies": {} 8 | } 9 | -------------------------------------------------------------------------------- /test/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "polymerjs-cheatsheet", 3 | "private": true, 4 | "dependencies": { 5 | "chai": "~1.8.0", 6 | "mocha": "~1.14.0" 7 | }, 8 | "devDependencies": {} 9 | } 10 | -------------------------------------------------------------------------------- /test/spec/test.js: -------------------------------------------------------------------------------- 1 | /* global describe, it */ 2 | 3 | (function () { 4 | 'use strict'; 5 | 6 | describe('Give it some context', function () { 7 | describe('maybe a bit more context here', function () { 8 | it('should run here few assertions', function () { 9 | 10 | }); 11 | }); 12 | }); 13 | })(); 14 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "browser": true, 4 | "esnext": true, 5 | "bitwise": true, 6 | "camelcase": true, 7 | "curly": true, 8 | "eqeqeq": true, 9 | "immed": true, 10 | "indent": 4, 11 | "latedef": true, 12 | "newcap": true, 13 | "noarg": true, 14 | "quotmark": "single", 15 | "undef": true, 16 | "unused": true, 17 | "strict": true, 18 | "trailing": true, 19 | "smarttabs": true, 20 | "jquery": true 21 | } 22 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | 10 | # Change these settings to your own preference 11 | indent_style = space 12 | indent_size = 4 13 | 14 | # We recommend you to keep these unchanged 15 | end_of_line = lf 16 | charset = utf-8 17 | trim_trailing_whitespace = true 18 | insert_final_newline = true 19 | 20 | [*.md] 21 | trim_trailing_whitespace = false 22 | -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Mocha Spec Runner 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/styles/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #DDD; 3 | color: #111111; 4 | font-family: "Courier New", Courier, monospace; 5 | font-size: 12px; 6 | } 7 | 8 | .browsehappy { 9 | margin: 0.2em 0; 10 | background: #ccc; 11 | color: #000; 12 | padding: 0.2em 0; 13 | } 14 | 15 | .flex-container { 16 | padding: 0; 17 | margin: 0; 18 | list-style: none; 19 | display: flex; 20 | flex-direction: column; 21 | } 22 | 23 | .flex-item { 24 | display: flex; 25 | flex-direction: column; 26 | } 27 | 28 | .columns{ 29 | -webkit-column-count: 3; 30 | -webkit-column-gap: 10px; 31 | -webkit-column-rule: 0px dotted black; 32 | -moz-column-count: 3; 33 | -moz-column-gap: 10px; 34 | -moz-column-rule: 0px dotted black; 35 | column-count: 3; 36 | column-gap: 10px; 37 | column-rule: 0px dotted black; 38 | } 39 | 40 | h2 { 41 | background-color: #AAA; 42 | color: #FFF; 43 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "polymerjs-cheatsheet", 3 | "version": "0.0.0", 4 | "dependencies": {}, 5 | "devDependencies": { 6 | "grunt": "~0.4.1", 7 | "grunt-contrib-copy": "~0.4.1", 8 | "grunt-contrib-concat": "~0.3.0", 9 | "grunt-contrib-uglify": "~0.2.0", 10 | "grunt-contrib-jshint": "~0.7.0", 11 | "grunt-contrib-cssmin": "~0.7.0", 12 | "grunt-contrib-connect": "~0.5.0", 13 | "grunt-contrib-clean": "~0.5.0", 14 | "grunt-contrib-htmlmin": "~0.1.3", 15 | "grunt-bower-install": "~0.7.0", 16 | "grunt-contrib-imagemin": "~0.2.0", 17 | "grunt-contrib-watch": "~0.5.2", 18 | "grunt-rev": "~0.1.0", 19 | "grunt-autoprefixer": "~0.5.0", 20 | "grunt-usemin": "~2.0.0", 21 | "grunt-mocha": "~0.4.0", 22 | "grunt-newer": "~0.6.0", 23 | "grunt-svgmin": "~0.2.0", 24 | "grunt-concurrent": "~0.4.0", 25 | "load-grunt-tasks": "~0.2.0", 26 | "time-grunt": "~0.2.0", 27 | "jshint-stylish": "~0.1.3" 28 | }, 29 | "engines": { 30 | "node": ">=0.8.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Page Not Found :( 6 | 141 | 142 | 143 |
144 |

Not found :(

145 |

Sorry, but the page you were trying to view does not exist.

146 |

It looks like this was the result of either:

147 | 151 | 154 | 155 |
156 | 157 | 158 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | // Generated on 2014-01-31 using generator-webapp 0.4.7 2 | 'use strict'; 3 | 4 | // # Globbing 5 | // for performance reasons we're only matching one level down: 6 | // 'test/spec/{,*/}*.js' 7 | // use this if you want to recursively match all subfolders: 8 | // 'test/spec/**/*.js' 9 | 10 | module.exports = function (grunt) { 11 | 12 | // Load grunt tasks automatically 13 | require('load-grunt-tasks')(grunt); 14 | 15 | // Time how long tasks take. Can help when optimizing build times 16 | require('time-grunt')(grunt); 17 | 18 | // Define the configuration for all the tasks 19 | grunt.initConfig({ 20 | 21 | // Project settings 22 | yeoman: { 23 | // Configurable paths 24 | app: 'app', 25 | dist: 'dist' 26 | }, 27 | 28 | // Watches files for changes and runs tasks based on the changed files 29 | watch: { 30 | js: { 31 | files: ['<%= yeoman.app %>/scripts/{,*/}*.js'], 32 | tasks: ['jshint'], 33 | options: { 34 | livereload: true 35 | } 36 | }, 37 | jstest: { 38 | files: ['test/spec/{,*/}*.js'], 39 | tasks: ['test:watch'] 40 | }, 41 | gruntfile: { 42 | files: ['Gruntfile.js'] 43 | }, 44 | styles: { 45 | files: ['<%= yeoman.app %>/styles/{,*/}*.css'], 46 | tasks: ['newer:copy:styles', 'autoprefixer'] 47 | }, 48 | livereload: { 49 | options: { 50 | livereload: '<%= connect.options.livereload %>' 51 | }, 52 | files: [ 53 | '<%= yeoman.app %>/{,*/}*.html', 54 | '.tmp/styles/{,*/}*.css', 55 | '<%= yeoman.app %>/images/{,*/}*.{gif,jpeg,jpg,png,svg,webp}' 56 | ] 57 | } 58 | }, 59 | 60 | // The actual grunt server settings 61 | connect: { 62 | options: { 63 | port: 9000, 64 | livereload: 35729, 65 | // Change this to '0.0.0.0' to access the server from outside 66 | hostname: 'localhost' 67 | }, 68 | livereload: { 69 | options: { 70 | open: true, 71 | base: [ 72 | '.tmp', 73 | '<%= yeoman.app %>' 74 | ] 75 | } 76 | }, 77 | test: { 78 | options: { 79 | port: 9001, 80 | base: [ 81 | '.tmp', 82 | 'test', 83 | '<%= yeoman.app %>' 84 | ] 85 | } 86 | }, 87 | dist: { 88 | options: { 89 | open: true, 90 | base: '<%= yeoman.dist %>', 91 | livereload: false 92 | } 93 | } 94 | }, 95 | 96 | // Empties folders to start fresh 97 | clean: { 98 | dist: { 99 | files: [{ 100 | dot: true, 101 | src: [ 102 | '.tmp', 103 | '<%= yeoman.dist %>/*', 104 | '!<%= yeoman.dist %>/.git*' 105 | ] 106 | }] 107 | }, 108 | server: '.tmp' 109 | }, 110 | 111 | // Make sure code styles are up to par and there are no obvious mistakes 112 | jshint: { 113 | options: { 114 | jshintrc: '.jshintrc', 115 | reporter: require('jshint-stylish') 116 | }, 117 | all: [ 118 | 'Gruntfile.js', 119 | '<%= yeoman.app %>/scripts/{,*/}*.js', 120 | '!<%= yeoman.app %>/scripts/vendor/*', 121 | 'test/spec/{,*/}*.js' 122 | ] 123 | }, 124 | 125 | 126 | // Mocha testing framework configuration options 127 | mocha: { 128 | all: { 129 | options: { 130 | run: true, 131 | urls: ['http://<%= connect.test.options.hostname %>:<%= connect.test.options.port %>/index.html'] 132 | } 133 | } 134 | }, 135 | 136 | 137 | 138 | 139 | 140 | // Add vendor prefixed styles 141 | autoprefixer: { 142 | options: { 143 | browsers: ['last 1 version'] 144 | }, 145 | dist: { 146 | files: [{ 147 | expand: true, 148 | cwd: '.tmp/styles/', 149 | src: '{,*/}*.css', 150 | dest: '.tmp/styles/' 151 | }] 152 | } 153 | }, 154 | 155 | // Automatically inject Bower components into the HTML file 156 | 'bower-install': { 157 | app: { 158 | html: '<%= yeoman.app %>/index.html', 159 | ignorePath: '<%= yeoman.app %>/' 160 | } 161 | }, 162 | 163 | // Renames files for browser caching purposes 164 | rev: { 165 | dist: { 166 | files: { 167 | src: [ 168 | '<%= yeoman.dist %>/scripts/{,*/}*.js', 169 | '<%= yeoman.dist %>/styles/{,*/}*.css', 170 | '<%= yeoman.dist %>/images/{,*/}*.{gif,jpeg,jpg,png,webp}', 171 | '<%= yeoman.dist %>/styles/fonts/{,*/}*.*' 172 | ] 173 | } 174 | } 175 | }, 176 | 177 | // Reads HTML for usemin blocks to enable smart builds that automatically 178 | // concat, minify and revision files. Creates configurations in memory so 179 | // additional tasks can operate on them 180 | useminPrepare: { 181 | options: { 182 | dest: '<%= yeoman.dist %>' 183 | }, 184 | html: '<%= yeoman.app %>/index.html' 185 | }, 186 | 187 | // Performs rewrites based on rev and the useminPrepare configuration 188 | usemin: { 189 | options: { 190 | assetsDirs: ['<%= yeoman.dist %>'] 191 | }, 192 | html: ['<%= yeoman.dist %>/{,*/}*.html'], 193 | css: ['<%= yeoman.dist %>/styles/{,*/}*.css'] 194 | }, 195 | 196 | // The following *-min tasks produce minified files in the dist folder 197 | imagemin: { 198 | dist: { 199 | files: [{ 200 | expand: true, 201 | cwd: '<%= yeoman.app %>/images', 202 | src: '{,*/}*.{gif,jpeg,jpg,png}', 203 | dest: '<%= yeoman.dist %>/images' 204 | }] 205 | } 206 | }, 207 | svgmin: { 208 | dist: { 209 | files: [{ 210 | expand: true, 211 | cwd: '<%= yeoman.app %>/images', 212 | src: '{,*/}*.svg', 213 | dest: '<%= yeoman.dist %>/images' 214 | }] 215 | } 216 | }, 217 | htmlmin: { 218 | dist: { 219 | options: { 220 | collapseBooleanAttributes: true, 221 | collapseWhitespace: true, 222 | removeAttributeQuotes: true, 223 | removeCommentsFromCDATA: true, 224 | removeEmptyAttributes: true, 225 | removeOptionalTags: true, 226 | removeRedundantAttributes: true, 227 | useShortDoctype: true 228 | }, 229 | files: [{ 230 | expand: true, 231 | cwd: '<%= yeoman.dist %>', 232 | src: '{,*/}*.html', 233 | dest: '<%= yeoman.dist %>' 234 | }] 235 | } 236 | }, 237 | 238 | // By default, your `index.html`'s will take care of 239 | // minification. These next options are pre-configured if you do not wish 240 | // to use the Usemin blocks. 241 | // cssmin: { 242 | // dist: { 243 | // files: { 244 | // '<%= yeoman.dist %>/styles/main.css': [ 245 | // '.tmp/styles/{,*/}*.css', 246 | // '<%= yeoman.app %>/styles/{,*/}*.css' 247 | // ] 248 | // } 249 | // } 250 | // }, 251 | // uglify: { 252 | // dist: { 253 | // files: { 254 | // '<%= yeoman.dist %>/scripts/scripts.js': [ 255 | // '<%= yeoman.dist %>/scripts/scripts.js' 256 | // ] 257 | // } 258 | // } 259 | // }, 260 | // concat: { 261 | // dist: {} 262 | // }, 263 | 264 | // Copies remaining files to places other tasks can use 265 | copy: { 266 | dist: { 267 | files: [{ 268 | expand: true, 269 | dot: true, 270 | cwd: '<%= yeoman.app %>', 271 | dest: '<%= yeoman.dist %>', 272 | src: [ 273 | '*.{ico,png,txt}', 274 | '.htaccess', 275 | 'images/{,*/}*.webp', 276 | '{,*/}*.html', 277 | 'styles/fonts/{,*/}*.*' 278 | ] 279 | }] 280 | }, 281 | styles: { 282 | expand: true, 283 | dot: true, 284 | cwd: '<%= yeoman.app %>/styles', 285 | dest: '.tmp/styles/', 286 | src: '{,*/}*.css' 287 | } 288 | }, 289 | 290 | 291 | 292 | // Run some tasks in parallel to speed up build process 293 | concurrent: { 294 | server: [ 295 | 'copy:styles' 296 | ], 297 | test: [ 298 | 'copy:styles' 299 | ], 300 | dist: [ 301 | 'copy:styles', 302 | 'imagemin', 303 | 'svgmin' 304 | ] 305 | } 306 | }); 307 | 308 | 309 | grunt.registerTask('serve', function (target) { 310 | if (target === 'dist') { 311 | return grunt.task.run(['build', 'connect:dist:keepalive']); 312 | } 313 | 314 | grunt.task.run([ 315 | 'clean:server', 316 | 'concurrent:server', 317 | 'autoprefixer', 318 | 'connect:livereload', 319 | 'watch' 320 | ]); 321 | }); 322 | 323 | grunt.registerTask('server', function () { 324 | grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.'); 325 | grunt.task.run(['serve']); 326 | }); 327 | 328 | grunt.registerTask('test', function(target) { 329 | if (target !== 'watch') { 330 | grunt.task.run([ 331 | 'clean:server', 332 | 'concurrent:test', 333 | 'autoprefixer', 334 | ]); 335 | } 336 | 337 | grunt.task.run([ 338 | 'connect:test', 339 | 'mocha' 340 | ]); 341 | }); 342 | 343 | grunt.registerTask('build', [ 344 | 'clean:dist', 345 | 'useminPrepare', 346 | 'concurrent:dist', 347 | 'autoprefixer', 348 | 'concat', 349 | 'cssmin', 350 | 'uglify', 351 | 'copy:dist', 352 | 'rev', 353 | 'usemin', 354 | 'htmlmin' 355 | ]); 356 | 357 | grunt.registerTask('default', [ 358 | 'newer:jshint', 359 | 'test', 360 | 'build' 361 | ]); 362 | }; 363 | -------------------------------------------------------------------------------- /app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Polymer.js Cheat Sheet 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 |
28 | 29 |

Polymer.js
Cheat Sheet

30 | 31 |
32 | 33 |
34 |

Polymer element interface

35 | 36 | Load platform.js on main page 37 | <­script src="platform.m­in.js­"­><­/­scr­ipt­> 38 | 39 | Import polymer.html into custom elements 40 | <link rel="import" href="bower_components/polymer/polymer.html"> 41 | 42 | Import custom element 43 | <link rel="im­por­t" href="x­-fo­o.h­tml­"­> 44 | 45 | Contruct instance of custom element 46 | <x-f­oo>­</x­-fo­o> 47 | 48 | Publish properties as attributes 49 | <­x-foo attr color=­"­blu­e"><­/x-­foo­> 50 | 51 | My foo is the light dom 52 | <­x-f­oo>My foo</x­-fo­o> 53 | 54 | Nested elements 55 | <­x-f­oo>­<x-­bar­></­x-b­ar>­</x­-fo­o> 56 | 57 | Accessing published methods 58 | docu­men­t.q­uer­ySe­lec­tor(­'x-­foo­').c­us­tom­Met­hod­(); 59 | 60 | Accessing published property 61 | docu­men­t.q­uer­ySe­lec­tor(­'x-­foo­').c­olor = 'red'; 62 | 63 | Wait for WebCom­pon­ent­sReady before accessing elements 64 | wind­ow.a­dd­Eve­ntL­ist­ene­r('­Web­Com­pon­ent­sRe­ady', functi­on(e) {
65 |   docume­nt.q­ue­ryS­ele­cto­r('­x-f­oo'­).b­arP­roperty = 'baz';­
66 | }); 67 |
68 |
69 | 70 | 71 |
72 |

Element registration

73 | 74 | Declaratively 75 | 76 | <polymer-element name="tag-name" class="active" mycustomattr>
77 |   <template>...</template>
78 |   <script>Polymer('tag-name');</script>
79 | </polymer-element> 80 |
81 | 82 | Script referenced inside 83 | 84 | <polymer-element name="tag-name">
85 |   <template>...</template>
86 |   <script src="path/to/tagname.js"></script>
87 | </polymer-element> 88 |
89 | 90 | Script referenced outside 91 | 92 | <script src="path/to/tagname.js"></script>
93 | <polymer-element name="tag-name">
94 |   <template>...</template>
95 | </polymer-element> 96 |
97 | 98 | No script 99 | 100 | <polymer-element name="tag-name" constructor="TagName" noscript>
101 |   <template>
102 |     <!-- shadow DOM here -->
103 |   </template>
104 | </polymer-element> 105 |
106 | 107 | Pure JavaScript 108 | 109 | <script>
110 |   Polymer('name-tag', {nameColor: 'red'});
111 |
112 |   var el = document.createElement('div');
113 |
114 |   el.innerHTML = '\
115 |   <polymer-element name="name-tag" attributes="name">\
116 |   <template>\
117 |   Hello <span style="color:{{nameColor}}">{{name}}</span>\
118 |   </template>\
119 |   </polymer-element>';
120 |
121 |   // Insert into DOM for polyfill to see it
122 |   document.body.appendChild(el);
123 | </script> 124 |
125 |
126 | 127 |
128 |

Element lifecycle methods

129 | 130 | Instance created 131 | crea­ted() 132 | 133 | Fully prepared (e.g. Shadow DOM, observers, event listeners, etc.) 134 | read­y() 135 | 136 | Instance was inserted 137 | atta­che­d() 138 | 139 | Instance was removed 140 | deta­che­d() 141 | 142 | Attribute was added, removed, or updated 143 | attr­ibu­teC­han­ged() 144 |
145 | 146 |
147 |

Expressions

148 | 149 | Identi­fiers & paths. These values are treated as relative to the local model, extracted, observed for changes and cause the expression to be re-eva­luated if one or more has changed. 150 | foo, foo.ba­r.baz 151 | 152 | Logical not operator 153 | ! 154 | 155 | Converted to Number. Or converted to Number, then negated. 156 | +foo, -bar 157 | 158 | Supported: <, >, <=, >=, ==, !=, ===, !== 159 | foo + bar, foo - bar, foo * bar 160 | 161 | Logical compar­ators 162 | foo && bar || baz 163 | 164 | Ternary operator 165 | a ? b : c 166 | 167 | Grouping (paren­thesis) 168 | (a + b) * (c + d) 169 | 170 | Literal values. Escaped strings and non-de­cimal numbers are not supported. 171 | numbers, strings, null, undefined 172 | 173 | Array & Object initia­lizers 174 | [foo, 1], {id: 1, foo: bar} 175 | 176 | Labeled statements 177 | foo: bar.baz; bat: boo > 2; 178 |
179 | 180 |
181 |

Filters

182 | 183 | Filter syntax 184 | {{ {...} | filterName }} 185 | 186 | tokenList allows you to dynamically set/remove class names based on the object passed to it. If the object key is truthy, the name will be applied as a class. 187 | <div class="{{ {active: user.selected, big: user.type == 'super'} | tokenList }}"> 188 | 189 | styleObjectallows you to bind to an object 190 | 191 | 192 | <div style="{{styles | styleObject}}">...</div> 193 | 194 | <!-- The literal case also works, but is purely stylistic. --> 195 | <div style="{{ {background: color} | styleObject }}">{{color}}</div> 196 | 197 | 198 |
199 | 200 |
201 |

Firing custom events

202 | 203 | fire(i­nType, inDetail, inToNode) 204 | this.f­ire­('o­uch', {msg: 'That hurt!'}); 205 | 206 | Listening outside the element 207 | docume­nt.q­ue­ryS­ele­cto­r('­ouc­h-b­utt­on'­).a­ddE­ven­tLi­ste­ner­('o­uch', functi­on(e) { consol­e.l­og(­e.type, e.deta­il.m­sg); // "­ouc­h" "That hurt!" }); 208 | 209 | Using on-* handlers within another Polymer element 210 | <ou­ch-­button on-ouc­h="{{ myMethod }}">­</o­uch­-bu­tto­n> 211 |
212 | 213 |
214 |

Change watcher

215 | 216 | When the value of a watched property changes, the approp­riate change handler is automa­tically invoked. 217 | 218 | proper­tyN­ame­Changed 219 | 220 | <po­lym­er-­element name="g­-co­ol" attrib­ute­s="b­etter best"> 221 | <sc­rip­t> 222 | Polyme­r('­g-c­ool', { 223 | better­Cha­nged: functi­on(­inO­ldV­alue) { 224 | }, 225 | bestCh­anged: functi­on(­inO­ldV­alue) { 226 | } 227 | }); 228 | </s­cri­pt> 229 | 230 |
231 | 232 |
233 |

Event Mapping

234 | 235 | on-key­press declar­ation maps the standard DOM "­key­pre­ss" event to the keypre­ssH­andler method defined on the element 236 | <te­mpl­ate­><input on-key­pre­ss=­"{{ keypre­ssH­andler }}">­</i­npu­t><­/te­mpl­ate> 237 | 238 | on-* handler 239 | button­Click: functi­on(­event, detail, sender) { ... } 240 | 241 | inEvent is the standard event object. 242 | event 243 | 244 | inDetail: A conven­ience form of inEven­t.d­etail. 245 | detail 246 | 247 | A reference to the node that declared the handler. This is often different from inEven­t.t­arget (the lowest node that received the event) and inEven­t.c­urr­ent­Target (the component processing the event), so Polymer provides it directly. 248 | sender 249 |
250 | 251 |
252 |

Element attributes

253 | 254 | Name for the custom element. Requires a "­-". 255 | <­pol­yme­r-e­lement name="t­ag-­nam­e"><­pol­yme­r-e­lem­ent­> 256 | 257 | Published properties 258 | <­pol­yme­r-e­lement attrib­ute­s="c­olo­r"><­pol­yme­r-e­lem­ent­> 259 | 260 | Extend other elements 261 | <­pol­yme­r-e­lement extend­s="o­the­r-e­lem­ent­"­><p­oly­mer­-el­eme­nt> 262 | 263 | For simple elements that don't need to call Polymer(). 264 | <­pol­yme­r-e­lement noscri­pt>­<po­lym­er-­ele­men­t> 265 | 266 | For simpler elements that don’t require the features of Shadow DOM, use the lightdom attribute to control how the element stamps out DOM. 267 | 268 | <­pol­yme­r-e­lement lightd­om>­<po­lym­er-­ele­men­t> 269 | 270 | The name of the constr­uctor to put on the global object. Allows users to create instances of your element using the new operator (e.g. var tagName = new TagNam­e()). 271 | <pol­yme­r-e­lement constr­uct­or=­"­Tag­Nam­e><pol­yme­r-e­lem­ent­> 272 |
273 | 274 |
275 |

Automatic node finding

276 | 277 | <te­mpl­ate­><input type="t­ext­" id="­nam­eIn­put­"­></­tem­pla­te> 278 | this.$.na­meI­npu­t.value 279 |
280 | 281 |
282 |

Extending elements

283 | 284 | A Polymer element can extend another element by using the extends attribute. The parent’s properties and methods are inherited by the child element and data-b­ound. You can override any attribute or method 285 | <po­lym­er-­element name="p­-el­" extend­s="p­-2">­</p­oly­mer­-el­eme­nt> 286 | 287 | Calls the parent's method 288 | this.s­uper(); 289 | 290 | Import the file with the extended element if not in the same file 291 | <link rel="im­­po­r­t­" href="x­­-f­o­o.h­­tml­­"­> 292 |
293 | 294 |
295 |

Template syntax

296 | 297 | You can bind properties in your component using declar­ative data binding and the “doubl­e-m­ust­ache” syntax ({{}}). 298 | <te­mpl­ate­>{{ owner }}<­/te­mpl­ate> 299 | 300 | repeats one instance for each item in the array 'users' 301 | <te­mplate repeat­="{{ user in users }}">­</t­emp­lat­e> 302 | 303 | Named scopes are useful for refere­ncing a model value from an “outer” model “scope”. 304 | <te­mplate bind="{{ foo as foo }}">­</t­emp­lat­e> 305 | 306 | Binds if and only if condit­ion­alValue is truthy. 307 | <te­mplate if="{{ condit­ion­alValue }}">­</t­emp­lat­e> 308 | 309 | Repeat if and only if condit­ion­alValue is truthy. 310 | <te­mplate repeat if="{{ condit­ion­alValue }}">­</t­emp­lat­e> 311 | 312 | When creating an instance, the content of this template will be ignored, and the content of #myTem­plate is used instead. 313 | <te­mplate bind ref="my­Tem­pla­te">­</t­emp­lat­e> 314 | 315 | When a tag is rendered, the content of the shadow host is projected into the spot that the <co­nte­nt> element appears. 316 | <co­ntent select­="h2­"­></­con­ten­t> 317 | 318 | double brackets ([[]]) be used in place of {{}}} to setup a one-time binding. The binding becomes inactive after Polymer sets its value for the first time. 319 | <input type="t­ext­" value=­"this value is inserted once: [[ obj.value ]]"> 320 | 321 | 322 | <po­lym­er-­element name="t­k-e­lem­ent­-da­tab­ind­ing­"> 323 | <te­mpl­ate­>{{­own­er}­}</­str­ong­></­tem­pla­te> 324 | <sc­rip­t> 325 | Polyme­r('­tk-­ele­men­t-d­ata­bin­ding', { 326 | owner: 'Daniel', 327 | users: [1,2,3] 328 | }); 329 | </s­cri­pt> 330 | </p­oly­mer­-el­eme­nt> 331 |
332 | 333 | 334 |
335 | 336 | 337 |
338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /app/.htaccess: -------------------------------------------------------------------------------- 1 | # Apache Server Configs v2.1.0 | MIT License 2 | # https://github.com/h5bp/server-configs-apache 3 | 4 | # (!) Using `.htaccess` files slows down Apache, therefore, if you have access 5 | # to the main server config file (usually called `httpd.conf`), you should add 6 | # this logic there: http://httpd.apache.org/docs/current/howto/htaccess.html. 7 | 8 | # ############################################################################## 9 | # # CROSS-ORIGIN RESOURCE SHARING (CORS) # 10 | # ############################################################################## 11 | 12 | # ------------------------------------------------------------------------------ 13 | # | Cross-domain AJAX requests | 14 | # ------------------------------------------------------------------------------ 15 | 16 | # Enable cross-origin AJAX requests. 17 | # http://code.google.com/p/html5security/wiki/CrossOriginRequestSecurity 18 | # http://enable-cors.org/ 19 | 20 | # 21 | # Header set Access-Control-Allow-Origin "*" 22 | # 23 | 24 | # ------------------------------------------------------------------------------ 25 | # | CORS-enabled images | 26 | # ------------------------------------------------------------------------------ 27 | 28 | # Send the CORS header for images when browsers request it. 29 | # https://developer.mozilla.org/en-US/docs/HTML/CORS_Enabled_Image 30 | # http://blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html 31 | # http://hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/ 32 | 33 | 34 | 35 | 36 | SetEnvIf Origin ":" IS_CORS 37 | Header set Access-Control-Allow-Origin "*" env=IS_CORS 38 | 39 | 40 | 41 | 42 | # ------------------------------------------------------------------------------ 43 | # | Web fonts access | 44 | # ------------------------------------------------------------------------------ 45 | 46 | # Allow access from all domains for web fonts 47 | 48 | 49 | 50 | Header set Access-Control-Allow-Origin "*" 51 | 52 | 53 | 54 | 55 | # ############################################################################## 56 | # # ERRORS # 57 | # ############################################################################## 58 | 59 | # ------------------------------------------------------------------------------ 60 | # | 404 error prevention for non-existing redirected folders | 61 | # ------------------------------------------------------------------------------ 62 | 63 | # Prevent Apache from returning a 404 error for a rewrite if a directory 64 | # with the same name does not exist. 65 | # http://httpd.apache.org/docs/current/content-negotiation.html#multiviews 66 | # http://www.webmasterworld.com/apache/3808792.htm 67 | 68 | Options -MultiViews 69 | 70 | # ------------------------------------------------------------------------------ 71 | # | Custom error messages / pages | 72 | # ------------------------------------------------------------------------------ 73 | 74 | # You can customize what Apache returns to the client in case of an error (see 75 | # http://httpd.apache.org/docs/current/mod/core.html#errordocument). 76 | 77 | ErrorDocument 404 /404.html 78 | 79 | 80 | # ############################################################################## 81 | # # INTERNET EXPLORER # 82 | # ############################################################################## 83 | 84 | # ------------------------------------------------------------------------------ 85 | # | Better website experience | 86 | # ------------------------------------------------------------------------------ 87 | 88 | # Force IE to render pages in the highest available mode in the various 89 | # cases when it may not: http://hsivonen.iki.fi/doctype/ie-mode.pdf. 90 | 91 | 92 | Header set X-UA-Compatible "IE=edge" 93 | # `mod_headers` can't match based on the content-type, however, we only 94 | # want to send this header for HTML pages and not for the other resources 95 | 96 | Header unset X-UA-Compatible 97 | 98 | 99 | 100 | # ------------------------------------------------------------------------------ 101 | # | Cookie setting from iframes | 102 | # ------------------------------------------------------------------------------ 103 | 104 | # Allow cookies to be set from iframes in IE. 105 | # http://msdn.microsoft.com/en-us/library/ms537343.aspx 106 | # http://www.w3.org/TR/2000/CR-P3P-20001215/ 107 | 108 | # 109 | # Header set P3P "policyref=\"/w3c/p3p.xml\", CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"" 110 | # 111 | 112 | 113 | # ############################################################################## 114 | # # MIME TYPES AND ENCODING # 115 | # ############################################################################## 116 | 117 | # ------------------------------------------------------------------------------ 118 | # | Proper MIME types for all files | 119 | # ------------------------------------------------------------------------------ 120 | 121 | 122 | 123 | # Audio 124 | AddType audio/mp4 m4a f4a f4b 125 | AddType audio/ogg oga ogg opus 126 | 127 | # Data interchange 128 | AddType application/json json map 129 | 130 | # JavaScript 131 | # Normalize to standard type (it's sniffed in IE anyways): 132 | # http://tools.ietf.org/html/rfc4329#section-7.2 133 | AddType application/javascript js 134 | 135 | # Video 136 | AddType video/mp4 f4v f4p m4v mp4 137 | AddType video/ogg ogv 138 | AddType video/webm webm 139 | AddType video/x-flv flv 140 | 141 | # Web fonts 142 | AddType application/font-woff woff 143 | AddType application/vnd.ms-fontobject eot 144 | 145 | # Browsers usually ignore the font MIME types and sniff the content, 146 | # however, Chrome shows a warning if other MIME types are used for the 147 | # following fonts. 148 | AddType application/x-font-ttf ttc ttf 149 | AddType font/opentype otf 150 | 151 | # Make SVGZ fonts work on iPad: 152 | # https://twitter.com/FontSquirrel/status/14855840545 153 | AddType image/svg+xml svgz 154 | AddEncoding gzip svgz 155 | 156 | # Other 157 | AddType application/octet-stream safariextz 158 | AddType application/x-chrome-extension crx 159 | AddType application/x-opera-extension oex 160 | AddType application/x-web-app-manifest+json webapp 161 | AddType application/x-xpinstall xpi 162 | AddType application/xml atom rdf rss xml 163 | AddType image/webp webp 164 | AddType image/x-icon cur 165 | AddType text/cache-manifest appcache manifest 166 | AddType text/vtt vtt 167 | AddType text/x-component htc 168 | AddType text/x-vcard vcf 169 | 170 | 171 | 172 | # ------------------------------------------------------------------------------ 173 | # | UTF-8 encoding | 174 | # ------------------------------------------------------------------------------ 175 | 176 | # Use UTF-8 encoding for anything served as `text/html` or `text/plain`. 177 | AddDefaultCharset utf-8 178 | 179 | # Force UTF-8 for certain file formats. 180 | 181 | AddCharset utf-8 .atom .css .js .json .rss .vtt .webapp .xml 182 | 183 | 184 | 185 | # ############################################################################## 186 | # # URL REWRITES # 187 | # ############################################################################## 188 | 189 | # ------------------------------------------------------------------------------ 190 | # | Rewrite engine | 191 | # ------------------------------------------------------------------------------ 192 | 193 | # Turning on the rewrite engine and enabling the `FollowSymLinks` option is 194 | # necessary for the following directives to work. 195 | 196 | # If your web host doesn't allow the `FollowSymlinks` option, you may need to 197 | # comment it out and use `Options +SymLinksIfOwnerMatch` but, be aware of the 198 | # performance impact: http://httpd.apache.org/docs/current/misc/perf-tuning.html#symlinks 199 | 200 | # Also, some cloud hosting services require `RewriteBase` to be set: 201 | # http://www.rackspace.com/knowledge_center/frequently-asked-question/why-is-mod-rewrite-not-working-on-my-site 202 | 203 | 204 | Options +FollowSymlinks 205 | # Options +SymLinksIfOwnerMatch 206 | RewriteEngine On 207 | # RewriteBase / 208 | 209 | 210 | # ------------------------------------------------------------------------------ 211 | # | Suppressing / Forcing the "www." at the beginning of URLs | 212 | # ------------------------------------------------------------------------------ 213 | 214 | # The same content should never be available under two different URLs especially 215 | # not with and without "www." at the beginning. This can cause SEO problems 216 | # (duplicate content), therefore, you should choose one of the alternatives and 217 | # redirect the other one. 218 | 219 | # By default option 1 (no "www.") is activated: 220 | # http://no-www.org/faq.php?q=class_b 221 | 222 | # If you'd prefer to use option 2, just comment out all the lines from option 1 223 | # and uncomment the ones from option 2. 224 | 225 | # IMPORTANT: NEVER USE BOTH RULES AT THE SAME TIME! 226 | 227 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 228 | 229 | # Option 1: rewrite www.example.com → example.com 230 | 231 | 232 | RewriteCond %{HTTPS} !=on 233 | RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 234 | RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] 235 | 236 | 237 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 238 | 239 | # Option 2: rewrite example.com → www.example.com 240 | 241 | # Be aware that the following might not be a good idea if you use "real" 242 | # subdomains for certain parts of your website. 243 | 244 | # 245 | # RewriteCond %{HTTPS} !=on 246 | # RewriteCond %{HTTP_HOST} !^www\. [NC] 247 | # RewriteCond %{SERVER_ADDR} !=127.0.0.1 248 | # RewriteCond %{SERVER_ADDR} !=::1 249 | # RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 250 | # 251 | 252 | 253 | # ############################################################################## 254 | # # SECURITY # 255 | # ############################################################################## 256 | 257 | # ------------------------------------------------------------------------------ 258 | # | Clickjacking | 259 | # ------------------------------------------------------------------------------ 260 | 261 | # Protect web site against clickjacking. 262 | 263 | # The example below sends the `X-Frame-Options` response header with the value 264 | # `DENY`, informing browsers not to display the web page content in any frame. 265 | 266 | # This might not be the best setting for everyone. You should read about the 267 | # other two possible values for `X-Frame-Options`: `SAMEORIGIN` and `ALLOW-FROM` 268 | # http://tools.ietf.org/html/rfc7034#section-2.1. 269 | 270 | # Keep in mind that while you could send the `X-Frame-Options` header for all 271 | # of your site’s pages, this has the potential downside that it forbids even 272 | # non-malicious framing of your content (e.g.: when users visit your site using 273 | # a Google Image Search results page). 274 | 275 | # Nonetheless, you should ensure that you send the `X-Frame-Options` header for 276 | # all pages that allow a user to make a state changing operation (e.g: pages 277 | # that contain one-click purchase links, checkout or bank-transfer confirmation 278 | # pages, pages that make permanent configuration changes, etc.). 279 | 280 | # Sending the `X-Frame-Options` header can also protect your web site against 281 | # more than just clickjacking attacks: https://cure53.de/xfo-clickjacking.pdf. 282 | 283 | # http://tools.ietf.org/html/rfc7034 284 | # http://blogs.msdn.com/b/ieinternals/archive/2010/03/30/combating-clickjacking-with-x-frame-options.aspx 285 | # https://www.owasp.org/index.php/Clickjacking 286 | 287 | # 288 | # Header set X-Frame-Options "DENY" 289 | # 290 | # Header unset X-Frame-Options 291 | # 292 | # 293 | 294 | # ------------------------------------------------------------------------------ 295 | # | Content Security Policy (CSP) | 296 | # ------------------------------------------------------------------------------ 297 | 298 | # You can mitigate the risk of cross-site scripting and other content-injection 299 | # attacks by setting a Content Security Policy which whitelists trusted sources 300 | # of content for your site. 301 | 302 | # The example header below allows ONLY scripts that are loaded from the current 303 | # site's origin (no inline scripts, no CDN, etc). This almost certainly won't 304 | # work as-is for your site! 305 | 306 | # For more details on how to craft a reasonable policy for your site, read: 307 | # http://html5rocks.com/en/tutorials/security/content-security-policy (or the 308 | # specification: http://w3.org/TR/CSP). Also, to make things easier, you can 309 | # use an online CSP header generator such as: http://cspisawesome.com/. 310 | 311 | # 312 | # Header set Content-Security-Policy "script-src 'self'; object-src 'self'" 313 | # 314 | # Header unset Content-Security-Policy 315 | # 316 | # 317 | 318 | # ------------------------------------------------------------------------------ 319 | # | File access | 320 | # ------------------------------------------------------------------------------ 321 | 322 | # Block access to directories without a default document. 323 | # Usually you should leave this uncommented because you shouldn't allow anyone 324 | # to surf through every directory on your server (which may includes rather 325 | # private places like the CMS's directories). 326 | 327 | 328 | Options -Indexes 329 | 330 | 331 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 332 | 333 | # Block access to hidden files and directories. 334 | # This includes directories used by version control systems such as Git and SVN. 335 | 336 | 337 | RewriteCond %{SCRIPT_FILENAME} -d [OR] 338 | RewriteCond %{SCRIPT_FILENAME} -f 339 | RewriteRule "(^|/)\." - [F] 340 | 341 | 342 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 343 | 344 | # Block access to backup and source files. 345 | # These files may be left by some text editors and can pose a great security 346 | # danger when anyone has access to them. 347 | 348 | 349 | 350 | # Apache < 2.3 351 | 352 | Order allow,deny 353 | Deny from all 354 | Satisfy All 355 | 356 | 357 | # Apache ≥ 2.3 358 | 359 | Require all denied 360 | 361 | 362 | 363 | 364 | # ------------------------------------------------------------------------------ 365 | # | Reducing MIME-type security risks | 366 | # ------------------------------------------------------------------------------ 367 | 368 | # Prevent some browsers from MIME-sniffing the response. 369 | 370 | # This reduces exposure to drive-by download attacks and should be enable 371 | # especially if the web server is serving user uploaded content, content 372 | # that could potentially be treated by the browser as executable. 373 | 374 | # http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx 375 | # http://msdn.microsoft.com/en-us/library/ie/gg622941.aspx 376 | # http://mimesniff.spec.whatwg.org/ 377 | 378 | # 379 | # Header set X-Content-Type-Options "nosniff" 380 | # 381 | 382 | # ------------------------------------------------------------------------------ 383 | # | Reflected Cross-Site Scripting (XSS) attacks | 384 | # ------------------------------------------------------------------------------ 385 | 386 | # (1) Try to re-enable the Cross-Site Scripting (XSS) filter built into the 387 | # most recent web browsers. 388 | # 389 | # The filter is usually enabled by default, but in some cases it may be 390 | # disabled by the user. However, in IE for example, it can be re-enabled 391 | # just by sending the `X-XSS-Protection` header with the value of `1`. 392 | # 393 | # (2) Prevent web browsers from rendering the web page if a potential reflected 394 | # (a.k.a non-persistent) XSS attack is detected by the filter. 395 | # 396 | # By default, if the filter is enabled and browsers detect a reflected 397 | # XSS attack, they will attempt to block the attack by making the smallest 398 | # possible modifications to the returned web page. 399 | # 400 | # Unfortunately, in some browsers (e.g.: IE), this default behavior may 401 | # allow the XSS filter to be exploited, thereby, it's better to tell 402 | # browsers to prevent the rendering of the page altogether, instead of 403 | # attempting to modify it. 404 | # 405 | # http://hackademix.net/2009/11/21/ies-xss-filter-creates-xss-vulnerabilities 406 | # 407 | # IMPORTANT: Do not rely on the XSS filter to prevent XSS attacks! Ensure that 408 | # you are taking all possible measures to prevent XSS attacks, the most obvious 409 | # being: validating and sanitizing your site's inputs. 410 | 411 | # http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-iv-the-xss-filter.aspx 412 | # http://blogs.msdn.com/b/ieinternals/archive/2011/01/31/controlling-the-internet-explorer-xss-filter-with-the-x-xss-protection-http-header.aspx 413 | # https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29 414 | 415 | # 416 | # # (1) (2) 417 | # Header set X-XSS-Protection "1; mode=block" 418 | # 419 | # Header unset X-XSS-Protection 420 | # 421 | # 422 | 423 | # ------------------------------------------------------------------------------ 424 | # | Secure Sockets Layer (SSL) | 425 | # ------------------------------------------------------------------------------ 426 | 427 | # Rewrite secure requests properly to prevent SSL certificate warnings, e.g.: 428 | # prevent `https://www.example.com` when your certificate only allows 429 | # `https://secure.example.com`. 430 | 431 | # 432 | # RewriteCond %{SERVER_PORT} !^443 433 | # RewriteRule ^ https://example-domain-please-change-me.com%{REQUEST_URI} [R=301,L] 434 | # 435 | 436 | # ------------------------------------------------------------------------------ 437 | # | HTTP Strict Transport Security (HSTS) | 438 | # ------------------------------------------------------------------------------ 439 | 440 | # Force client-side SSL redirection. 441 | 442 | # If a user types "example.com" in his browser, the above rule will redirect 443 | # him to the secure version of the site. That still leaves a window of oppor- 444 | # tunity (the initial HTTP connection) for an attacker to downgrade or redirect 445 | # the request. The following header ensures that browser will ONLY connect to 446 | # your server via HTTPS, regardless of what the users type in the address bar. 447 | # http://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec-14#section-6.1 448 | # http://www.html5rocks.com/en/tutorials/security/transport-layer-security/ 449 | 450 | # (!) Remove the `includeSubDomains` optional directive if the subdomains are 451 | # not using HTTPS. 452 | 453 | # 454 | # Header set Strict-Transport-Security "max-age=16070400; includeSubDomains" 455 | # 456 | 457 | # ------------------------------------------------------------------------------ 458 | # | Server software information | 459 | # ------------------------------------------------------------------------------ 460 | 461 | # Avoid displaying the exact Apache version number, the description of the 462 | # generic OS-type and the information about Apache's compiled-in modules. 463 | 464 | # ADD THIS DIRECTIVE IN THE `httpd.conf` AS IT WILL NOT WORK IN THE `.htaccess`! 465 | 466 | # ServerTokens Prod 467 | 468 | 469 | # ############################################################################## 470 | # # WEB PERFORMANCE # 471 | # ############################################################################## 472 | 473 | # ------------------------------------------------------------------------------ 474 | # | Compression | 475 | # ------------------------------------------------------------------------------ 476 | 477 | 478 | 479 | # Force compression for mangled headers. 480 | # http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping 481 | 482 | 483 | SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding 484 | RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding 485 | 486 | 487 | 488 | # Compress all output labeled with one of the following MIME-types 489 | # (for Apache versions below 2.3.7, you don't need to enable `mod_filter` 490 | # and can remove the `` and `` lines 491 | # as `AddOutputFilterByType` is still in the core directives). 492 | 493 | AddOutputFilterByType DEFLATE application/atom+xml \ 494 | application/javascript \ 495 | application/json \ 496 | application/rss+xml \ 497 | application/vnd.ms-fontobject \ 498 | application/x-font-ttf \ 499 | application/x-web-app-manifest+json \ 500 | application/xhtml+xml \ 501 | application/xml \ 502 | font/opentype \ 503 | image/svg+xml \ 504 | image/x-icon \ 505 | text/css \ 506 | text/html \ 507 | text/plain \ 508 | text/x-component \ 509 | text/xml 510 | 511 | 512 | 513 | 514 | # ------------------------------------------------------------------------------ 515 | # | Content transformations | 516 | # ------------------------------------------------------------------------------ 517 | 518 | # Prevent some of the mobile network providers from modifying the content of 519 | # your site: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.5. 520 | 521 | # 522 | # Header set Cache-Control "no-transform" 523 | # 524 | 525 | # ------------------------------------------------------------------------------ 526 | # | ETag removal | 527 | # ------------------------------------------------------------------------------ 528 | 529 | # Since we're sending far-future expires headers (see below), ETags can 530 | # be removed: http://developer.yahoo.com/performance/rules.html#etags. 531 | 532 | # `FileETag None` is not enough for every server. 533 | 534 | Header unset ETag 535 | 536 | 537 | FileETag None 538 | 539 | # ------------------------------------------------------------------------------ 540 | # | Expires headers (for better cache control) | 541 | # ------------------------------------------------------------------------------ 542 | 543 | # The following expires headers are set pretty far in the future. If you don't 544 | # control versioning with filename-based cache busting, consider lowering the 545 | # cache time for resources like CSS and JS to something like 1 week. 546 | 547 | 548 | 549 | ExpiresActive on 550 | ExpiresDefault "access plus 1 month" 551 | 552 | # CSS 553 | ExpiresByType text/css "access plus 1 year" 554 | 555 | # Data interchange 556 | ExpiresByType application/json "access plus 0 seconds" 557 | ExpiresByType application/xml "access plus 0 seconds" 558 | ExpiresByType text/xml "access plus 0 seconds" 559 | 560 | # Favicon (cannot be renamed!) and cursor images 561 | ExpiresByType image/x-icon "access plus 1 week" 562 | 563 | # HTML components (HTCs) 564 | ExpiresByType text/x-component "access plus 1 month" 565 | 566 | # HTML 567 | ExpiresByType text/html "access plus 0 seconds" 568 | 569 | # JavaScript 570 | ExpiresByType application/javascript "access plus 1 year" 571 | 572 | # Manifest files 573 | ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds" 574 | ExpiresByType text/cache-manifest "access plus 0 seconds" 575 | 576 | # Media 577 | ExpiresByType audio/ogg "access plus 1 month" 578 | ExpiresByType image/gif "access plus 1 month" 579 | ExpiresByType image/jpeg "access plus 1 month" 580 | ExpiresByType image/png "access plus 1 month" 581 | ExpiresByType video/mp4 "access plus 1 month" 582 | ExpiresByType video/ogg "access plus 1 month" 583 | ExpiresByType video/webm "access plus 1 month" 584 | 585 | # Web feeds 586 | ExpiresByType application/atom+xml "access plus 1 hour" 587 | ExpiresByType application/rss+xml "access plus 1 hour" 588 | 589 | # Web fonts 590 | ExpiresByType application/font-woff "access plus 1 month" 591 | ExpiresByType application/vnd.ms-fontobject "access plus 1 month" 592 | ExpiresByType application/x-font-ttf "access plus 1 month" 593 | ExpiresByType font/opentype "access plus 1 month" 594 | ExpiresByType image/svg+xml "access plus 1 month" 595 | 596 | 597 | 598 | # ------------------------------------------------------------------------------ 599 | # | Filename-based cache busting | 600 | # ------------------------------------------------------------------------------ 601 | 602 | # If you're not using a build process to manage your filename version revving, 603 | # you might want to consider enabling the following directives to route all 604 | # requests such as `/css/style.12345.css` to `/css/style.css`. 605 | 606 | # To understand why this is important and a better idea than `*.css?v231`, read: 607 | # http://stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring 608 | 609 | # 610 | # RewriteCond %{REQUEST_FILENAME} !-f 611 | # RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpe?g|gif)$ $1.$3 [L] 612 | # 613 | 614 | # ------------------------------------------------------------------------------ 615 | # | File concatenation | 616 | # ------------------------------------------------------------------------------ 617 | 618 | # Allow concatenation from within specific CSS and JS files, e.g.: 619 | # Inside of `script.combined.js` you could have 620 | # 621 | # 622 | # and they would be included into this single file. 623 | 624 | # 625 | # 626 | # Options +Includes 627 | # AddOutputFilterByType INCLUDES application/javascript application/json 628 | # SetOutputFilter INCLUDES 629 | # 630 | # 631 | # Options +Includes 632 | # AddOutputFilterByType INCLUDES text/css 633 | # SetOutputFilter INCLUDES 634 | # 635 | # 636 | 637 | # ------------------------------------------------------------------------------ 638 | # | Persistent connections | 639 | # ------------------------------------------------------------------------------ 640 | 641 | # Allow multiple requests to be sent over the same TCP connection: 642 | # http://httpd.apache.org/docs/current/en/mod/core.html#keepalive. 643 | 644 | # Enable if you serve a lot of static content but, be aware of the 645 | # possible disadvantages! 646 | 647 | # 648 | # Header set Connection Keep-Alive 649 | # 650 | --------------------------------------------------------------------------------