Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: third_party/polymer/vulcanized/polymer-elements.js

Issue 236733003: Remove the need for <polymer-selector> in the PDF plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1
2
3 // upgrade polymer-body last so that it can contain other imported elements
4 document.addEventListener('polymer-ready', function() {
5
6 Polymer('polymer-body', Platform.mixin({
7
8 created: function() {
9 this.template = document.createElement('template');
10 var body = wrap(document).body;
11 var c$ = body.childNodes.array();
12 for (var i=0, c; (c=c$[i]); i++) {
13 if (c.localName !== 'script') {
14 this.template.content.appendChild(c);
15 }
16 }
17 // snarf up user defined model
18 window.model = this;
19 },
20
21 parseDeclaration: function(elementElement) {
22 this.lightFromTemplate(this.template);
23 }
24
25 }, window.model));
26
27 });
28
29 ;
30 /**
31 * @license
32 * Copyright (c) 2012-2014 The Polymer Authors. All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions are
36 * met:
37 *
38 * * Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * * Redistributions in binary form must reproduce the above
41 * copyright notice, this list of conditions and the following disclaimer
42 * in the documentation and/or other materials provided with the
43 * distribution.
44 * * Neither the name of Google Inc. nor the names of its
45 * contributors may be used to endorse or promote products derived from
46 * this software without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
51 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
52 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
58 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 */
60 // @version: 0.2.2
61 Polymer={},"function"==typeof window.Polymer&&(Polymer={}),function(a){function b(a,b){return a&&b&&Object.getOwnPropertyNames(b).forEach(function(c){var d=Obje ct.getOwnPropertyDescriptor(b,c);d&&(Object.defineProperty(a,c,d),"function"==ty peof d.value&&(d.value.nom=c))}),a}a.extend=b}(Polymer),function(a){function b(a ,b,d){return a?a.stop():a=new c(this),a.go(b,d),a}var c=function(a){this.context =a,this.boundComplete=this.complete.bind(this)};c.prototype={go:function(a,b){th is.callback=a;var c;b?(c=setTimeout(this.boundComplete,b),this.handle=function() {clearTimeout(c)}):(c=requestAnimationFrame(this.boundComplete),this.handle=func tion(){cancelAnimationFrame(c)})},stop:function(){this.handle&&(this.handle(),th is.handle=null)},complete:function(){this.handle&&(this.stop(),this.callback.cal l(this.context))}},a.job=b}(Polymer),function(){var a={};HTMLElement.register=fu nction(b,c){a[b]=c},HTMLElement.getPrototypeForTag=function(b){var c=b?a[b]:HTML Element.prototype;return c||Object.getPrototypeOf(document.createElement(b))};va r b=Event.prototype.stopPropagation;Event.prototype.stopPropagation=function(){t his.cancelBubble=!0,b.apply(this,arguments)}}(Polymer),function(a){function b(a) {var c=b.caller,g=c.nom,h=c._super;if(h||(g||(g=c.nom=e.call(this,c)),g||console .warn("called super() on a method not installed declaratively (has no .nom prope rty)"),h=d(c,g,f(this))),h){var i=h[g];return i._super||d(i,g,h),i.apply(this,a| |[])}}function c(a,b,c){for(;a;){if(a[b]!==c&&a[b])return a;a=f(a)}}function d(a ,b,d){return a._super=c(d,b,a),a._super&&(a._super[b].nom=b),a._super}function e (a){for(var b=this.__proto__;b&&b!==HTMLElement.prototype;){for(var c,d=Object.g etOwnPropertyNames(b),e=0,f=d.length;f>e&&(c=d[e]);e++){var g=Object.getOwnPrope rtyDescriptor(b,c);if("function"==typeof g.value&&g.value===a)return c}b=b.__pro to__}}function f(a){return a.__proto__}a.super=b}(Polymer),function(a){function b(a,b){var d=typeof b;return b instanceof Date&&(d="date"),c[d](a,b)}var c={stri ng:function(a){return a},date:function(a){return new Date(Date.parse(a)||Date.no w())},"boolean":function(a){return""===a?!0:"false"===a?!1:!!a},number:function( a){var b=parseFloat(a);return 0===b&&(b=parseInt(a)),isNaN(b)?a:b},object:functi on(a,b){if(null===b)return a;try{return JSON.parse(a.replace(/'/g,'"'))}catch(c) {return a}},"function":function(a,b){return b}};a.deserializeValue=b}(Polymer),f unction(a){var b=a.extend,c={};c.declaration={},c.instance={},c.publish=function (a,c){for(var d in a)b(c,a[d])},a.api=c}(Polymer),function(a){var b={async:funct ion(a,b,c){Platform.flush(),b=b&&b.length?b:[b];var d=function(){(this[a]||a).ap ply(this,b)}.bind(this),e=c?setTimeout(d,c):requestAnimationFrame(d);return c?e: ~e},cancelAsync:function(a){0>a?cancelAnimationFrame(~a):clearTimeout(a)},fire:f unction(a,b,c,d,e){var f=c||this,b=b||{},g=new CustomEvent(a,{bubbles:void 0!==d ?d:!0,cancelable:void 0!==e?e:!0,detail:b});return f.dispatchEvent(g),g},asyncFi re:function(){this.async("fire",arguments)},classFollows:function(a,b,c){b&&b.cl assList.remove(c),a&&a.classList.add(c)}},c=function(){},d={};b.asyncMethod=b.as ync,a.api.instance.utils=b,a.nop=c,a.nob=d}(Polymer),function(a){var b=window.lo gFlags||{},c="on-",d={EVENT_PREFIX:c,addHostListeners:function(){var a=this.even tDelegates;b.events&&Object.keys(a).length>0&&console.log("[%s] addHostListeners :",this.localName,a);var d,e,f=this;for(var g in a)e=c+g,(d=PolymerExpressions.p repareEventBinding(Path.get(a[g]),e,{resolveEventHandler:function(a,b){var c=b.g etValueFrom(f);return c?c.bind(f):void 0}}))(this,this,!1)},dispatchMethod:funct ion(a,c,d){if(a){b.events&&console.group("[%s] dispatch [%s]",a.localName,c);var e="function"==typeof c?c:a[c];e&&e[d?"apply":"call"](a,d),b.events&&console.gro upEnd(),Platform.flush()}}};a.api.instance.events=d}(Polymer),function(a){var b= {copyInstanceAttributes:function(){var a=this._instanceAttributes;for(var b in a )this.hasAttribute(b)||this.setAttribute(b,a[b])},takeAttributes:function(){if(t his._publishLC)for(var a,b=0,c=this.attributes,d=c.length;(a=c[b])&&d>b;b++)this .attributeToProperty(a.name,a.value)},attributeToProperty:function(b,c){var b=th is.propertyForAttribute(b);if(b){if(c&&c.search(a.bindPattern)>=0)return;var d=t his[b],c=this.deserializeValue(c,d);c!==d&&(this[b]=c)}},propertyForAttribute:fu nction(a){var b=this._publishLC&&this._publishLC[a];return b},deserializeValue:f unction(b,c){return a.deserializeValue(b,c)},serializeValue:function(a,b){return "boolean"===b?a?"":void 0:"object"!==b&&"function"!==b&&void 0!==a?a:void 0},ref lectPropertyToAttribute:function(a){var b=typeof this[a],c=this.serializeValue(t his[a],b);void 0!==c?this.setAttribute(a,c):"boolean"===b&&this.removeAttribute( a)}};a.api.instance.attributes=b}(Polymer),function(a){function b(a,b,d){c.bind& &console.log(e,inB.localName||"object",inPath,a.localName,b);var f=d.discardChan ges();return(null===f||void 0===f)&&d.setValue(a[b]),Observer.defineComputedProp erty(a,b,d)}var c=window.logFlags||{},d={observeProperties:function(){var a=this ._observeNames,b=this._publishNames;if(a&&a.length||b&&b.length){var c=this._pro pertyObserver=new CompoundObserver;this.registerObservers([c]);for(var d,e=0,f=a .length;f>e&&(d=a[e]);e++){c.addPath(this,d);var g=Object.getOwnPropertyDescript or(this.__proto__,d);g&&g.value&&this.observeArrayValue(d,g.value,null)}for(var d,e=0,f=b.length;f>e&&(d=b[e]);e++)this.observe&&void 0!==this.observe[d]||c.add Path(this,d);c.open(this.notifyPropertyChanges,this)}},notifyPropertyChanges:fun ction(a,b,c){var d,e,f={};for(var g in b)d=c[2*g+1],void 0!==this.publish[d]&&th is.reflectPropertyToAttribute(d),e=this.observe[d],e&&(this.observeArrayValue(d, a[g],b[g]),f[e]||(f[e]=!0,this.invokeMethod(e,[b[g],a[g],arguments])))},observeA rrayValue:function(a,b,d){var e=this.observe[a];if(e&&(Array.isArray(d)&&(c.obse rve&&console.log("[%s] observeArrayValue: unregister observer [%s]",this.localNa me,a),this.closeNamedObserver(a+"__array")),Array.isArray(b))){c.observe&&consol e.log("[%s] observeArrayValue: register observer [%s]",this.localName,a,b);var f =new ArrayObserver(b);f.open(function(a,b){this.invokeMethod(e,[b])},this),this. registerNamedObserver(a+"__array",f)}},bindProperty:function(a,c){return b(this, a,c)},invokeMethod:function(a,b){var c=this[a]||a;"function"==typeof c&&c.apply( this,b)},registerObservers:function(a){this._observers.push(a)},closeObservers:f unction(){for(var a=0,b=this._observers.length;b>a;a++)this.closeObserverArray(t his._observers[a]);this._observers=[]},closeObserverArray:function(a){for(var b, c=0,d=a.length;d>c;c++)b=a[c],b&&b.close&&b.close()},registerNamedObserver:funct ion(a,b){var c=this._namedObservers||(this._namedObservers={});c[a]=b},closeName dObserver:function(a){var b=this._namedObservers;return b&&b[a]?(b[a].close(),b[ a]=null,!0):void 0},closeNamedObservers:function(){if(this._namedObservers){for( var a,b,c=Object.keys(this._namedObservers),d=0,e=c.length;e>d&&(a=c[d]);d++)b=t his._namedObservers[a],b.close();this._namedObservers={}}}},e="[%s]: bindPropert ies: [%s] to [%s].[%s]";a.api.instance.properties=d}(Polymer),function(a){functi on b(a){for(;a.parentNode;){if(a.lightDomController)return a;a=a.parentNode}retu rn a.host}var c=window.logFlags||0,d=(a.api.instance.events,new PolymerExpressio ns);d.resolveEventHandler=function(a,c,d){var e=b(d);if(e){var f=c.getValueFrom( e);if(f)return f.bind(e)}};var e={syntax:d,instanceTemplate:function(a){var b=a. createInstance(this,this.syntax);return this.registerObservers(b.bindings_),b},b ind:function(a,b){var c=this.propertyForAttribute(a);if(c){var d=this.bindProper ty(c,b);return this.reflectPropertyToAttribute(c),Platform.enableBindingsReflect ion&&(d.path=b.path_,this.bindings_=this.bindings_||{},this.bindings_[a]=d),d}re turn this.mixinSuper(arguments)},asyncUnbindAll:function(){this._unbound||(c.unb ind&&console.log("[%s] asyncUnbindAll",this.localName),this._unbindAllJob=this.j ob(this._unbindAllJob,this.unbindAll,0))},unbindAll:function(){this._unbound||(t his.closeObservers(),this.closeNamedObservers(),this._unbound=!0)},cancelUnbindA ll:function(){return this._unbound?void(c.unbind&&console.warn("[%s] already unb ound, cannot cancel unbindAll",this.localName)):(c.unbind&&console.log("[%s] can celUnbindAll",this.localName),void(this._unbindAllJob&&(this._unbindAllJob=this. _unbindAllJob.stop())))}},f=/\{\{([^{}]*)}}/;a.bindPattern=f,a.api.instance.mdv= e}(Polymer),function(a){function b(a){return a.hasOwnProperty("PolymerBase")}fun ction c(){}var d={PolymerBase:!0,job:function(a,b,c){if("string"!=typeof a)retur n Polymer.job.call(this,a,b,c);var d="___"+a;this[d]=Polymer.job.call(this,this[ d],b,c)},"super":Polymer.super,created:function(){},ready:function(){},createdCa llback:function(){this.templateInstance&&console.warn("Attributes on "+this.loca lName+" were data bound prior to Polymer upgrading the element. This may result in incorrect binding types."),this.created(),this.prepareElement()},prepareEleme nt:function(){this._elementPrepared=!0,this.shadowRoots={},this._observers=[],th is.observeProperties(),this.copyInstanceAttributes(),this.takeAttributes(),this. addHostListeners(),this.parseDeclarations(this.__proto__),this.removeAttribute(" unresolved"),this.ready()},attachedCallback:function(){this.cancelUnbindAll(),th is.attached&&this.attached(),this.enteredView&&this.enteredView(),this.hasBeenAt tached||(this.hasBeenAttached=!0,this.domReady&&this.async("domReady"))},detache dCallback:function(){this.preventDispose||this.asyncUnbindAll(),this.detached&&t his.detached(),this.leftView&&this.leftView()},enteredViewCallback:function(){th is.attachedCallback()},leftViewCallback:function(){this.detachedCallback()},ente redDocumentCallback:function(){this.attachedCallback()},leftDocumentCallback:fun ction(){this.detachedCallback()},parseDeclarations:function(a){a&&a.element&&(th is.parseDeclarations(a.__proto__),a.parseDeclaration.call(this,a.element))},pars eDeclaration:function(a){var b=this.fetchTemplate(a);if(b){var c=this.shadowFrom Template(b);this.shadowRoots[a.name]=c}},fetchTemplate:function(a){return a.quer ySelector("template")},shadowFromTemplate:function(a){if(a){var b=this.createSha dowRoot(),c=this.instanceTemplate(a);return b.appendChild(c),this.shadowRootRead y(b,a),b}},lightFromTemplate:function(a,b){if(a){this.lightDomController=!0;var c=this.instanceTemplate(a);return b?this.insertBefore(c,b):this.appendChild(c),t his.shadowRootReady(this),c}},shadowRootReady:function(a){this.marshalNodeRefere nces(a),PointerGestures.register(a)},marshalNodeReferences:function(a){var b=thi s.$=this.$||{};if(a)for(var c,d=a.querySelectorAll("[id]"),e=0,f=d.length;f>e&&( c=d[e]);e++)b[c.id]=c},attributeChangedCallback:function(a){"class"!==a&&"style" !==a&&this.attributeToProperty(a,this.getAttribute(a)),this.attributeChanged&&th is.attributeChanged.apply(this,arguments)},onMutation:function(a,b){var c=new Mu tationObserver(function(a){b.call(this,c,a),c.disconnect()}.bind(this));c.observ e(a,{childList:!0,subtree:!0})}};c.prototype=d,d.constructor=c,a.Base=c,a.isBase =b,a.api.instance.base=d}(Polymer),function(a){function b(a){return a.__proto__} function c(a,b){var c="",d=!1;b&&(c=b.localName,d=b.hasAttribute("is"));var e=Pl atform.ShadowCSS.makeScopeSelector(c,d);return Platform.ShadowCSS.shimCssText(a, e)}var d=(window.logFlags||{},"element"),e="controller",f={STYLE_SCOPE_ATTRIBUTE :d,installControllerStyles:function(){var a=this.findStyleScope();if(a&&!this.sc opeHasNamedStyle(a,this.localName)){for(var c=b(this),d="";c&&c.element;)d+=c.el ement.cssTextForScope(e),c=b(c);d&&this.installScopeCssText(d,a)}},installScopeS tyle:function(a,b,c){var c=c||this.findStyleScope(),b=b||"";if(c&&!this.scopeHas NamedStyle(c,this.localName+b)){var d="";if(a instanceof Array)for(var e,f=0,g=a .length;g>f&&(e=a[f]);f++)d+=e.textContent+"\n\n";else d=a.textContent;this.inst allScopeCssText(d,c,b)}},installScopeCssText:function(a,b,d){if(b=b||this.findSt yleScope(),d=d||"",b){window.ShadowDOMPolyfill&&(a=c(a,b.host));var f=this.eleme nt.cssTextToScopeStyle(a,e);Polymer.applyStyleToScope(f,b),b._scopeStyles[this.l ocalName+d]=!0}},findStyleScope:function(a){for(var b=a||this;b.parentNode;)b=b. parentNode;return b},scopeHasNamedStyle:function(a,b){return a._scopeStyles=a._s copeStyles||{},a._scopeStyles[b]}};a.api.instance.styles=f}(Polymer),function(a) {function b(a,b){if(1===arguments.length&&"string"!=typeof arguments[0]){b=a;var c=document._currentScript;if(a=c&&c.parentNode&&c.parentNode.getAttribute?c.par entNode.getAttribute("name"):"",!a)throw"Element name could not be inferred."}if (f[a])throw"Already registered (Polymer) prototype for element "+a;e(a,b),d(a)}f unction c(a,b){h[a]=b}function d(a){h[a]&&(h[a].registerWhenReady(),delete h[a]) }function e(a,b){return i[a]=b||{}}function f(a){return i[a]}var g=a.extend,h=(a .api,{}),i={};a.getRegisteredPrototype=f,a.waitingForPrototype=c,window.Polymer= b,g(Polymer,a);var j=Platform.deliverDeclarations();if(j)for(var k,l=0,m=j.lengt h;m>l&&(k=j[l]);l++)b.apply(null,k)}(Polymer),function(a){var b={resolveElementP aths:function(a){Platform.urlResolver.resolveDom(a)},addResolvePathApi:function( ){var a=this.getAttribute("assetpath")||"",b=new URL(a,this.ownerDocument.baseUR I);this.prototype.resolvePath=function(a,c){var d=new URL(a,c||b);return d.href} }};a.api.declaration.path=b}(Polymer),function(a){function b(a,b){var c=new URL( a.getAttribute("href"),b).href;return"@import '"+c+"';"}function c(a,b){if(a){b= ==document&&(b=document.head),window.ShadowDOMPolyfill&&(b=document.head);var c= d(a.textContent),e=a.getAttribute(h);e&&c.setAttribute(h,e);var f=b.firstElement Child;if(b===document.head){var g="style["+h+"]",i=document.head.querySelectorAl l(g);i.length&&(f=i[i.length-1].nextElementSibling)}b.insertBefore(c,f)}}functio n d(a,b){b=b||document,b=b.createElement?b:b.ownerDocument;var c=b.createElement ("style");return c.textContent=a,c}function e(a){return a&&a.__resource||""}func tion f(a,b){return p?p.call(a,b):void 0}var g=(window.logFlags||{},a.api.instanc e.styles),h=g.STYLE_SCOPE_ATTRIBUTE,i="style",j="@import",k="link[rel=stylesheet ]",l="global",m="polymer-scope",n={loadStyles:function(a){var b=this.templateCon tent();b&&this.convertSheetsToStyles(b);var c=this.findLoadableStyles(b);c.lengt h?Platform.styleResolver.loadStyles(c,a):a&&a()},convertSheetsToStyles:function( a){for(var c,e,f=a.querySelectorAll(k),g=0,h=f.length;h>g&&(c=f[g]);g++)e=d(b(c, this.ownerDocument.baseURI),this.ownerDocument),this.copySheetAttributes(e,c),c. parentNode.replaceChild(e,c)},copySheetAttributes:function(a,b){for(var c,d=0,e= b.attributes,f=e.length;(c=e[d])&&f>d;d++)"rel"!==c.name&&"href"!==c.name&&a.set Attribute(c.name,c.value)},findLoadableStyles:function(a){var b=[];if(a)for(var c,d=a.querySelectorAll(i),e=0,f=d.length;f>e&&(c=d[e]);e++)c.textContent.match(j )&&b.push(c);return b},installSheets:function(){this.cacheSheets(),this.cacheSty les(),this.installLocalSheets(),this.installGlobalStyles()},cacheSheets:function (){this.sheets=this.findNodes(k),this.sheets.forEach(function(a){a.parentNode&&a .parentNode.removeChild(a)})},cacheStyles:function(){this.styles=this.findNodes( i+"["+m+"]"),this.styles.forEach(function(a){a.parentNode&&a.parentNode.removeCh ild(a)})},installLocalSheets:function(){var a=this.sheets.filter(function(a){ret urn!a.hasAttribute(m)}),b=this.templateContent();if(b){var c="";if(a.forEach(fun ction(a){c+=e(a)+"\n"}),c){var f=d(c,this.ownerDocument);b.insertBefore(f,b.firs tChild)}}},findNodes:function(a,b){var c=this.querySelectorAll(a).array(),d=this .templateContent();if(d){var e=d.querySelectorAll(a).array();c=c.concat(e)}retur n b?c.filter(b):c},templateContent:function(){var a=this.querySelector("template ");return a&&templateContent(a)},installGlobalStyles:function(){var a=this.style ForScope(l);c(a,document.head)},cssTextForScope:function(a){var b="",c="["+m+"=" +a+"]",d=function(a){return f(a,c)},g=this.sheets.filter(d);g.forEach(function(a ){b+=e(a)+"\n\n"});var h=this.styles.filter(d);return h.forEach(function(a){b+=a .textContent+"\n\n"}),b},styleForScope:function(a){var b=this.cssTextForScope(a) ;return this.cssTextToScopeStyle(b,a)},cssTextToScopeStyle:function(a,b){if(a){v ar c=d(a);return c.setAttribute(h,this.getAttribute("name")+"-"+b),c}}},o=HTMLEl ement.prototype,p=o.matches||o.matchesSelector||o.webkitMatchesSelector||o.mozMa tchesSelector;a.api.declaration.styles=n,a.applyStyleToScope=c}(Polymer),functio n(a){var b=(window.logFlags||{},a.api.instance.events),c=b.EVENT_PREFIX,d={parse HostEvents:function(){var a=this.prototype.eventDelegates;this.addAttributeDeleg ates(a)},addAttributeDelegates:function(a){for(var b,c=0;b=this.attributes[c];c+ +)this.hasEventPrefix(b.name)&&(a[this.removeEventPrefix(b.name)]=b.value.replac e("{{","").replace("}}","").trim())},hasEventPrefix:function(a){return a&&"o"=== a[0]&&"n"===a[1]&&"-"===a[2]},removeEventPrefix:function(a){return a.slice(e)}}, e=c.length;a.api.declaration.events=d}(Polymer),function(a){var b={inferObserver s:function(a){var b,c=a.observe;for(var d in a)"Changed"===d.slice(-7)&&(c||(c=a .observe={}),b=d.slice(0,-7),c[b]=c[b]||d)},explodeObservers:function(a){var b=a .observe;if(b){var c={};for(var d in b)for(var e,f=d.split(" "),g=0;e=f[g];g++)c [e]=b[d];a.observe=c}},optimizePropertyMaps:function(a){if(a.observe){var b=a._o bserveNames=[];for(var c in a.observe)for(var d,e=c.split(" "),f=0;d=e[f];f++)b. push(d)}if(a.publish){var b=a._publishNames=[];for(var c in a.publish)b.push(c)} },publishProperties:function(a,b){var c=a.publish;c&&(this.requireProperties(c,a ,b),a._publishLC=this.lowerCaseMap(c))},requireProperties:function(a,b,c){for(va r d in a)void 0===b[d]&&void 0===c[d]&&(b[d]=a[d])},lowerCaseMap:function(a){var b={};for(var c in a)b[c.toLowerCase()]=c;return b}};a.api.declaration.propertie s=b}(Polymer),function(a){var b="attributes",c=/\s|,/,d={inheritAttributesObject s:function(a){this.inheritObject(a,"publishLC"),this.inheritObject(a,"_instanceA ttributes")},publishAttributes:function(a,d){var e=this.getAttribute(b);if(e)for (var f,g=a.publish||(a.publish={}),h=e.split(c),i=0,j=h.length;j>i;i++)f=h[i].tr im(),f&&void 0===g[f]&&void 0===d[f]&&(g[f]=null)},accumulateInstanceAttributes: function(){for(var a,b=this.prototype._instanceAttributes,c=this.attributes,d=0, e=c.length;e>d&&(a=c[d]);d++)this.isInstanceAttribute(a.name)&&(b[a.name]=a.valu e)},isInstanceAttribute:function(a){return!this.blackList[a]&&"on-"!==a.slice(0, 3)},blackList:{name:1,"extends":1,constructor:1,noscript:1,assetpath:1,"cache-cs stext":1}};d.blackList[b]=1,a.api.declaration.attributes=d}(Polymer),function(a) {function b(a){if(!Object.__proto__){var b=Object.getPrototypeOf(a);a.__proto__= b,d(b)&&(b.__proto__=Object.getPrototypeOf(b))}}var c=a.api,d=a.isBase,e=a.exten d,f={register:function(a,b){this.buildPrototype(a,b),this.registerPrototype(a,b) ,this.publishConstructor()},buildPrototype:function(b,c){var d=a.getRegisteredPr ototype(b),e=this.generateBasePrototype(c);this.desugarBeforeChaining(d,e),this. prototype=this.chainPrototypes(d,e),this.desugarAfterChaining(b,c)},desugarBefor eChaining:function(a,b){a.element=this,this.publishAttributes(a,b),this.publishP roperties(a,b),this.inferObservers(a),this.explodeObservers(a)},chainPrototypes: function(a,c){this.inheritMetaData(a,c);var d=this.chainObject(a,c);return b(d), d},inheritMetaData:function(a,b){this.inheritObject("observe",a,b),this.inheritO bject("publish",a,b),this.inheritObject("_publishLC",a,b),this.inheritObject("_i nstanceAttributes",a,b),this.inheritObject("eventDelegates",a,b)},desugarAfterCh aining:function(a,b){this.optimizePropertyMaps(this.prototype),this.installSheet s(),this.resolveElementPaths(this),this.accumulateInstanceAttributes(),this.pars eHostEvents(),this.addResolvePathApi(),window.ShadowDOMPolyfill&&Platform.Shadow CSS.shimStyling(this.templateContent(),a,b),this.prototype.registerCallback&&thi s.prototype.registerCallback(this)},publishConstructor:function(){var a=this.get Attribute("constructor");a&&(window[a]=this.ctor)},generateBasePrototype:functio n(a){var b=this.findBasePrototype(a);if(!b){var b=HTMLElement.getPrototypeForTag (a);b=this.ensureBaseApi(b),g[a]=b}return b},findBasePrototype:function(a){retur n g[a]},ensureBaseApi:function(a){if(a.PolymerBase)return a;var b=Object.create( a);return c.publish(c.instance,b),this.mixinMethod(b,a,c.instance.mdv,"bind"),b} ,mixinMethod:function(a,b,c,d){var e=function(a){return b[d].apply(this,a)};a[d] =function(){return this.mixinSuper=e,c[d].apply(this,arguments)}},inheritObject: function(a,b,c){var d=b[a]||{};b[a]=this.chainObject(d,c[a])},registerPrototype: function(a,b){var c={prototype:this.prototype},d=this.findTypeExtension(b);d&&(c .extends=d),HTMLElement.register(a,this.prototype),this.ctor=document.registerEl ement(a,c)},findTypeExtension:function(a){if(a&&a.indexOf("-")<0)return a;var b= this.findBasePrototype(a);return b.element?this.findTypeExtension(b.element.exte nds):void 0}},g={};f.chainObject=Object.__proto__?function(a,b){return a&&b&&a!= =b&&(a.__proto__=b),a}:function(a,b){if(a&&b&&a!==b){var c=Object.create(b);a=e( c,a)}return a},c.declaration.prototype=f}(Polymer),function(a){function b(a){ret urn document.contains(a)?g:f}function c(){return f.length?f[0]:g[0]}function d(a ){e.waitToReady=!0,CustomElements.ready=!1,HTMLImports.whenImportsReady(function (){e.addReadyCallback(a),e.waitToReady=!1,e.check()})}var e={wait:function(a,b,c ){return-1===this.indexOf(a)&&(this.add(a),a.__check=b,a.__go=c),0!==this.indexO f(a)},add:function(a){b(a).push(a)},indexOf:function(a){var c=b(a).indexOf(a);re turn c>=0&&document.contains(a)&&(c+=HTMLImports.useNative||HTMLImports.ready?f. length:1e9),c},go:function(a){var b=this.remove(a);b&&(b.__go.call(b),b.__check= b.__go=null,this.check())},remove:function(a){var c=this.indexOf(a);if(0===c)ret urn b(a).shift()},check:function(){var a=this.nextElement();return a&&a.__check. call(a),this.canReady()?(this.ready(),!0):void 0},nextElement:function(){return c()},canReady:function(){return!this.waitToReady&&this.isEmpty()},isEmpty:functi on(){return!f.length&&!g.length},ready:function(){if(CustomElements.ready===!1&& (CustomElements.upgradeDocumentTree(document),CustomElements.ready=!0),h)for(var a;h.length;)(a=h.shift())()},addReadyCallback:function(a){a&&h.push(a)},waitToR eady:!0},f=[],g=[],h=[];document.addEventListener("WebComponentsReady",function( ){CustomElements.ready=!1}),a.queue=e,a.whenPolymerReady=d}(Polymer),function(a) {function b(a,b){a?(document.head.appendChild(a),d(b)):b&&b()}function c(a,c){if (a&&a.length){for(var d,e,f=document.createDocumentFragment(),g=0,h=a.length;h>g &&(d=a[g]);g++)e=document.createElement("link"),e.rel="import",e.href=d,f.append Child(e);b(f,c)}else c&&c()}var d=a.whenPolymerReady;a.import=c,a.importElements =b}(Polymer),function(a){function b(a){return Boolean(HTMLElement.getPrototypeFo rTag(a))}function c(a){return a&&a.indexOf("-")>=0}var d=a.extend,e=a.api,f=a.qu eue,g=a.whenPolymerReady,h=a.getRegisteredPrototype,i=a.waitingForPrototype,j=d( Object.create(HTMLElement.prototype),{createdCallback:function(){this.getAttribu te("name")&&this.init()},init:function(){this.name=this.getAttribute("name"),thi s.extends=this.getAttribute("extends"),this.loadResources(),this.registerWhenRea dy()},registerWhenReady:function(){this.registered||this.waitingForPrototype(thi s.name)||this.waitingForQueue()||this.waitingForResources()||f.go(this)},_regist er:function(){c(this.extends)&&!b(this.extends)&&console.warn("%s is attempting to extend %s, an unregistered element or one that was not registered with Polyme r.",this.name,this.extends),this.register(this.name,this.extends),this.registere d=!0},waitingForPrototype:function(a){return h(a)?void 0:(i(a,this),this.handleN oScript(a),!0)},handleNoScript:function(a){if(this.hasAttribute("noscript")&&!th is.noscript)if(this.noscript=!0,window.CustomElements&&!CustomElements.useNative )Polymer(a);else{var b=document.createElement("script");b.textContent="Polymer(' "+a+"');",this.appendChild(b)}},waitingForResources:function(){return this._need sResources},waitingForQueue:function(){return f.wait(this,this.registerWhenReady ,this._register)},loadResources:function(){this._needsResources=!0,this.loadStyl es(function(){this._needsResources=!1,this.registerWhenReady()}.bind(this))}});e .publish(e.declaration,j),a.getRegisteredPrototype=h,g(function(){document.body. removeAttribute("unresolved"),document.dispatchEvent(new CustomEvent("polymer-re ady",{bubbles:!0}))}),document.registerElement("polymer-element",{prototype:j})} (Polymer);
62 //# sourceMappingURL=polymer.js.map;
63
64 Polymer('polymer-selection', {
65 /**
66 * If true, multiple selections are allowed.
67 *
68 * @attribute multi
69 * @type boolean
70 * @default false
71 */
72 multi: false,
73 ready: function() {
74 this.clear();
75 },
76 clear: function() {
77 this.selection = [];
78 },
79 /**
80 * Retrieves the selected item(s).
81 * @method getSelection
82 * @returns Returns the selected item(s). If the multi property is true,
83 * getSelection will return an array, otherwise it will return
84 * the selected item or undefined if there is no selection.
85 */
86 getSelection: function() {
87 return this.multi ? this.selection : this.selection[0];
88 },
89 /**
90 * Indicates if a given item is selected.
91 * @method isSelected
92 * @param {any} item The item whose selection state should be checked.
93 * @returns Returns true if `item` is selected.
94 */
95 isSelected: function(item) {
96 return this.selection.indexOf(item) >= 0;
97 },
98 setItemSelected: function(item, isSelected) {
99 if (item !== undefined && item !== null) {
100 if (isSelected) {
101 this.selection.push(item);
102 } else {
103 var i = this.selection.indexOf(item);
104 if (i >= 0) {
105 this.selection.splice(i, 1);
106 }
107 }
108 this.fire("polymer-select", {isSelected: isSelected, item: item});
109 }
110 },
111 /**
112 * Set the selection state for a given `item`. If the multi property
113 * is true, then the selected state of `item` will be toggled; otherwise
114 * the `item` will be selected.
115 * @method select
116 * @param {any} item: The item to select.
117 */
118 select: function(item) {
119 if (this.multi) {
120 this.toggle(item);
121 } else if (this.getSelection() !== item) {
122 this.setItemSelected(this.getSelection(), false);
123 this.setItemSelected(item, true);
124 }
125 },
126 /**
127 * Toggles the selection state for `item`.
128 * @method toggle
129 * @param {any} item: The item to toggle.
130 */
131 toggle: function(item) {
132 this.setItemSelected(item, !this.isSelected(item));
133 }
134 });
135 ;
136
137 Polymer('polymer-selector', {
138 /**
139 * Gets or sets the selected element. Default to use the index
140 * of the item element.
141 *
142 * If you want a specific attribute value of the element to be
143 * used instead of index, set "valueattr" to that attribute name.
144 *
145 * Example:
146 *
147 * <polymer-selector valueattr="label" selected="foo">
148 * <div label="foo"></div>
149 * <div label="bar"></div>
150 * <div label="zot"></div>
151 * </polymer-selector>
152 *
153 * In multi-selection this should be an array of values.
154 *
155 * Example:
156 *
157 * <polymer-selector id="selector" valueattr="label" multi>
158 * <div label="foo"></div>
159 * <div label="bar"></div>
160 * <div label="zot"></div>
161 * </polymer-selector>
162 *
163 * this.$.selector.selected = ['foo', 'zot'];
164 *
165 * @attribute selected
166 * @type Object
167 * @default null
168 */
169 selected: null,
170 /**
171 * If true, multiple selections are allowed.
172 *
173 * @attribute multi
174 * @type boolean
175 * @default false
176 */
177 multi: false,
178 /**
179 * Specifies the attribute to be used for "selected" attribute.
180 *
181 * @attribute valueattr
182 * @type string
183 * @default 'name'
184 */
185 valueattr: 'name',
186 /**
187 * Specifies the CSS class to be used to add to the selected element.
188 *
189 * @attribute selectedClass
190 * @type string
191 * @default 'polymer-selected'
192 */
193 selectedClass: 'polymer-selected',
194 /**
195 * Specifies the property to be used to set on the selected element
196 * to indicate its active state.
197 *
198 * @attribute selectedProperty
199 * @type string
200 * @default ''
201 */
202 selectedProperty: '',
203 /**
204 * Specifies the property to be used to set on the selected element
205 * to indicate its active state.
206 *
207 * @attribute selectedProperty
208 * @type string
209 * @default 'active'
210 */
211 selectedAttribute: 'active',
212 /**
213 * Returns the currently selected element. In multi-selection this returns
214 * an array of selected elements.
215 *
216 * @attribute selectedItem
217 * @type Object
218 * @default null
219 */
220 selectedItem: null,
221 /**
222 * In single selection, this returns the model associated with the
223 * selected element.
224 *
225 * @attribute selectedModel
226 * @type Object
227 * @default null
228 */
229 selectedModel: null,
230 /**
231 * In single selection, this returns the selected index.
232 *
233 * @attribute selectedIndex
234 * @type number
235 * @default -1
236 */
237 selectedIndex: -1,
238 /**
239 * The target element that contains items. If this is not set
240 * polymer-selector is the container.
241 *
242 * @attribute target
243 * @type Object
244 * @default null
245 */
246 target: null,
247 /**
248 * This can be used to query nodes from the target node to be used for
249 * selection items. Note this only works if the 'target' property is set.
250 *
251 * Example:
252 *
253 * <polymer-selector target="{{$.myForm}}" itemsSelector="input[type=r adio]"></polymer-selector>
254 * <form id="myForm">
255 * <label><input type="radio" name="color" value="red"> Red</label> <br>
256 * <label><input type="radio" name="color" value="green"> Green</lab el> <br>
257 * <label><input type="radio" name="color" value="blue"> Blue</label > <br>
258 * <p>color = {{color}}</p>
259 * </form>
260 *
261 * @attribute itemSelector
262 * @type string
263 * @default ''
264 */
265 itemsSelector: '',
266 /**
267 * The event that would be fired from the item element to indicate
268 * it is being selected.
269 *
270 * @attribute activateEvent
271 * @type string
272 * @default 'tap'
273 */
274 activateEvent: 'tap',
275 notap: false,
276 ready: function() {
277 this.activateListener = this.activateHandler.bind(this);
278 this.observer = new MutationObserver(this.updateSelected.bind(this));
279 if (!this.target) {
280 this.target = this;
281 }
282 },
283 get items() {
284 var nodes = this.target !== this ? (this.itemsSelector ?
285 this.target.querySelectorAll(this.itemsSelector) :
286 this.target.children) : this.$.items.getDistributedNodes();
287 return Array.prototype.filter.call(nodes || [], function(n) {
288 return n && n.localName !== 'template';
289 });
290 },
291 targetChanged: function(old) {
292 if (old) {
293 this.removeListener(old);
294 this.observer.disconnect();
295 }
296 if (this.target) {
297 this.addListener(this.target);
298 this.observer.observe(this.target, {childList: true});
299 }
300 },
301 addListener: function(node) {
302 node.addEventListener(this.activateEvent, this.activateListener);
303 },
304 removeListener: function(node) {
305 node.removeEventListener(this.activateEvent, this.activateListener);
306 },
307 get selection() {
308 return this.$.selection.getSelection();
309 },
310 selectedChanged: function() {
311 this.updateSelected();
312 },
313 updateSelected: function() {
314 this.validateSelected();
315 if (this.multi) {
316 this.clearSelection();
317 this.selected && this.selected.forEach(function(s) {
318 this.valueToSelection(s);
319 }, this);
320 } else {
321 this.valueToSelection(this.selected);
322 }
323 },
324 validateSelected: function() {
325 // convert to an array for multi-selection
326 if (this.multi && !Array.isArray(this.selected) &&
327 this.selected !== null && this.selected !== undefined) {
328 this.selected = [this.selected];
329 }
330 },
331 clearSelection: function() {
332 if (this.multi) {
333 this.selection.slice().forEach(function(s) {
334 this.$.selection.setItemSelected(s, false);
335 }, this);
336 } else {
337 this.$.selection.setItemSelected(this.selection, false);
338 }
339 this.selectedItem = null;
340 this.$.selection.clear();
341 },
342 valueToSelection: function(value) {
343 var item = (value === null || value === undefined) ?
344 null : this.items[this.valueToIndex(value)];
345 this.$.selection.select(item);
346 },
347 updateSelectedItem: function() {
348 this.selectedItem = this.selection;
349 },
350 selectedItemChanged: function() {
351 if (this.selectedItem) {
352 var t = this.selectedItem.templateInstance;
353 this.selectedModel = t ? t.model : undefined;
354 } else {
355 this.selectedModel = null;
356 }
357 this.selectedIndex = this.selectedItem ?
358 parseInt(this.valueToIndex(this.selected)) : -1;
359 },
360 valueToIndex: function(value) {
361 // find an item with value == value and return it's index
362 for (var i=0, items=this.items, c; (c=items[i]); i++) {
363 if (this.valueForNode(c) == value) {
364 return i;
365 }
366 }
367 // if no item found, the value itself is probably the index
368 return value;
369 },
370 valueForNode: function(node) {
371 return node[this.valueattr] || node.getAttribute(this.valueattr);
372 },
373 // events fired from <polymer-selection> object
374 selectionSelect: function(e, detail) {
375 this.updateSelectedItem();
376 if (detail.item) {
377 this.applySelection(detail.item, detail.isSelected);
378 }
379 },
380 applySelection: function(item, isSelected) {
381 if (this.selectedClass) {
382 item.classList.toggle(this.selectedClass, isSelected);
383 }
384 if (this.selectedProperty) {
385 item[this.selectedProperty] = isSelected;
386 }
387 if (this.selectedAttribute && item.setAttribute) {
388 if (isSelected) {
389 item.setAttribute(this.selectedAttribute, '');
390 } else {
391 item.removeAttribute(this.selectedAttribute);
392 }
393 }
394 },
395 // event fired from host
396 activateHandler: function(e) {
397 if (!this.notap) {
398 var i = this.findDistributedTarget(e.target, this.items);
399 if (i >= 0) {
400 var item = this.items[i];
401 var s = this.valueForNode(item) || i;
402 if (this.multi) {
403 if (this.selected) {
404 this.addRemoveSelected(s);
405 } else {
406 this.selected = [s];
407 }
408 } else {
409 this.selected = s;
410 }
411 this.asyncFire('polymer-activate', {item: item});
412 }
413 }
414 },
415 addRemoveSelected: function(value) {
416 var i = this.selected.indexOf(value);
417 if (i >= 0) {
418 this.selected.splice(i, 1);
419 } else {
420 this.selected.push(value);
421 }
422 this.valueToSelection(value);
423 },
424 findDistributedTarget: function(target, nodes) {
425 // find first ancestor of target (including itself) that
426 // is in nodes, if any
427 while (target && target != this) {
428 var i = Array.prototype.indexOf.call(nodes, target);
429 if (i >= 0) {
430 return i;
431 }
432 target = target.parentNode;
433 }
434 }
435 });
OLDNEW
« no previous file with comments | « third_party/polymer/vulcanized/polymer-elements.html ('k') | third_party/polymer/vulcanized/polymer-elements.in.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698