OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright 2013 The Polymer Authors. All rights reserved. |
| 3 Use of this source code is governed by a BSD-style |
| 4 license that can be found in the LICENSE file. |
| 5 --> |
| 6 |
| 7 <!-- |
| 8 /** |
| 9 * Polymer UI Elements |
| 10 * |
| 11 * @module Polymer UI Elements |
| 12 */ |
| 13 /** |
| 14 * polymer-ui-iconset allows users to define their own icon sets. |
| 15 * |
| 16 * Example: |
| 17 * |
| 18 * <polymer-ui-iconset id="my-icons" src="my-icons.png" width="96" iconsize=
"24" |
| 19 * icons="location place starta stopb bus car train walk"> |
| 20 * </polymer-ui-iconset> |
| 21 * |
| 22 * The above will automatically register the icon set "my-icons" to the iconset |
| 23 * database. To use the user-defined icon set, prefix the icon with |
| 24 * the icon set e.g. "my-icons:clock" |
| 25 * |
| 26 * Example: |
| 27 * |
| 28 * <polymer-ui-icon-button icon="my-icons:car"></polymer-ui-icon-button> |
| 29 * |
| 30 * @class polymer-ui-iconset |
| 31 */ |
| 32 --> |
| 33 <link rel="import" href="../polymer-meta/polymer-meta.html"> |
| 34 |
| 35 <polymer-element name="polymer-ui-iconset" extends="polymer-meta" |
| 36 attributes="src width icons iconsize"> |
| 37 <script> |
| 38 Polymer('polymer-ui-iconset', { |
| 39 width: 0, |
| 40 icons: '', |
| 41 iconsize: 0, |
| 42 offsetx: 0, |
| 43 offsety: 0, |
| 44 type: 'iconset', |
| 45 ready: function() { |
| 46 // TODO(sorvell): ensure iconset's src is always relative to the main |
| 47 // document |
| 48 if (this.src && (this.ownerDocument !== document)) { |
| 49 this.src = this.resolvePath(this.src, this.ownerDocument.baseURI); |
| 50 } |
| 51 this.super(); |
| 52 this.iconsChanged(); |
| 53 this.updateThemes(); |
| 54 }, |
| 55 iconsChanged: function() { |
| 56 this.iconMap = {}; |
| 57 var ox = this.offsetx; |
| 58 var oy = this.offsety; |
| 59 this.icons && this.icons.split(/\s+/g).forEach(function(name, i) { |
| 60 this.iconMap[name] = { |
| 61 offsetx: ox, |
| 62 offsety: oy |
| 63 } |
| 64 if (ox + this.iconsize < this.width) { |
| 65 ox += this.iconsize; |
| 66 } else { |
| 67 ox = this.offsetx; |
| 68 oy += this.iconsize; |
| 69 } |
| 70 }, this); |
| 71 }, |
| 72 updateThemes: function() { |
| 73 this.themes = {}; |
| 74 var ts = this.querySelectorAll('property[theme]'); |
| 75 ts && ts.array().forEach(function(t) { |
| 76 this.themes[t.getAttribute('theme')] = { |
| 77 offsetx: parseInt(t.getAttribute('offsetx')) || 0, |
| 78 offsety: parseInt(t.getAttribute('offsety')) || 0 |
| 79 }; |
| 80 }, this); |
| 81 }, |
| 82 // TODO(ffu): support retrived by index e.g. getOffset(10); |
| 83 getOffset: function(icon, theme) { |
| 84 var i = this.iconMap[icon]; |
| 85 var t = this.themes[theme]; |
| 86 if (i && t) { |
| 87 return { |
| 88 offsetx: i.offsetx + t.offsetx, |
| 89 offsety: i.offsety + t.offsety |
| 90 } |
| 91 } |
| 92 return i; |
| 93 } |
| 94 }); |
| 95 </script> |
| 96 </polymer-element> |
OLD | NEW |