| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 function assert(condition, opt_message) { | 4 function assert(condition,opt_message){if(!condition){var message="Assertion fai
led";if(opt_message)message=message+": "+opt_message;var error=new Error(message
);var global=function(){return this}();if(global.traceAssertionsForTesting)conso
le.warn(error.stack);throw error}return condition}function assertNotReached(opt_
message){assert(false,opt_message||"Unreachable code hit")}function assertInstan
ceof(value,type,opt_message){if(!(value instanceof type)){assertNotReached(opt_m
essage||"Value "+value+" is not a[n] "+(type.name||typeof type))}return value} |
| 5 if (!condition) { | |
| 6 var message = 'Assertion failed'; | |
| 7 if (opt_message) message = message + ': ' + opt_message; | |
| 8 var error = new Error(message); | |
| 9 var global = function() { | |
| 10 return this; | |
| 11 }(); | |
| 12 if (global.traceAssertionsForTesting) console.warn(error.stack); | |
| 13 throw error; | |
| 14 } | |
| 15 return condition; | |
| 16 } | |
| 17 | |
| 18 function assertNotReached(opt_message) { | |
| 19 assert(false, opt_message || 'Unreachable code hit'); | |
| 20 } | |
| 21 | |
| 22 function assertInstanceof(value, type, opt_message) { | |
| 23 if (!(value instanceof type)) { | |
| 24 assertNotReached(opt_message || 'Value ' + value + ' is not a[n] ' + (type.n
ame || typeof type)); | |
| 25 } | |
| 26 return value; | |
| 27 } | |
| 28 | |
| 29 // Copyright 2016 The Chromium Authors. All rights reserved. | 5 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 30 // Use of this source code is governed by a BSD-style license that can be | 6 // Use of this source code is governed by a BSD-style license that can be |
| 31 // found in the LICENSE file. | 7 // found in the LICENSE file. |
| 32 function PromiseResolver() { | 8 function PromiseResolver(){this.resolve_;this.reject_;this.promise_=new Promise(
function(resolve,reject){this.resolve_=resolve;this.reject_=reject}.bind(this))}
PromiseResolver.prototype={get promise(){return this.promise_},set promise(p){as
sertNotReached()},get resolve(){return this.resolve_},set resolve(r){assertNotRe
ached()},get reject(){return this.reject_},set reject(s){assertNotReached()}}; |
| 33 this.resolve_; | |
| 34 this.reject_; | |
| 35 this.promise_ = new Promise(function(resolve, reject) { | |
| 36 this.resolve_ = resolve; | |
| 37 this.reject_ = reject; | |
| 38 }.bind(this)); | |
| 39 } | |
| 40 | |
| 41 PromiseResolver.prototype = { | |
| 42 get promise() { | |
| 43 return this.promise_; | |
| 44 }, | |
| 45 set promise(p) { | |
| 46 assertNotReached(); | |
| 47 }, | |
| 48 get resolve() { | |
| 49 return this.resolve_; | |
| 50 }, | |
| 51 set resolve(r) { | |
| 52 assertNotReached(); | |
| 53 }, | |
| 54 get reject() { | |
| 55 return this.reject_; | |
| 56 }, | |
| 57 set reject(s) { | |
| 58 assertNotReached(); | |
| 59 } | |
| 60 }; | |
| 61 | |
| 62 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 63 // Use of this source code is governed by a BSD-style license that can be | 10 // Use of this source code is governed by a BSD-style license that can be |
| 64 // found in the LICENSE file. | 11 // found in the LICENSE file. |
| 65 var global = this; | 12 var global=this;var WebUIListener;var cr=cr||function(){"use strict";function ex
portPath(name,opt_object,opt_objectToExportTo){var parts=name.split(".");var cur
=opt_objectToExportTo||global;for(var part;parts.length&&(part=parts.shift());){
if(!parts.length&&opt_object!==undefined){cur[part]=opt_object}else if(part in c
ur){cur=cur[part]}else{cur=cur[part]={}}}return cur}function dispatchPropertyCha
nge(target,propertyName,newValue,oldValue){var e=new Event(propertyName+"Change"
);e.propertyName=propertyName;e.newValue=newValue;e.oldValue=oldValue;target.dis
patchEvent(e)}function getAttributeName(jsName){return jsName.replace(/([A-Z])/g
,"-$1").toLowerCase()}var PropertyKind={JS:"js",ATTR:"attr",BOOL_ATTR:"boolAttr"
};function getGetter(name,kind){switch(kind){case PropertyKind.JS:var privateNam
e=name+"_";return function(){return this[privateName]};case PropertyKind.ATTR:va
r attributeName=getAttributeName(name);return function(){return this.getAttribut
e(attributeName)};case PropertyKind.BOOL_ATTR:var attributeName=getAttributeName
(name);return function(){return this.hasAttribute(attributeName)}}throw"not reac
hed"}function getSetter(name,kind,opt_setHook){switch(kind){case PropertyKind.JS
:var privateName=name+"_";return function(value){var oldValue=this[name];if(valu
e!==oldValue){this[privateName]=value;if(opt_setHook)opt_setHook.call(this,value
,oldValue);dispatchPropertyChange(this,name,value,oldValue)}};case PropertyKind.
ATTR:var attributeName=getAttributeName(name);return function(value){var oldValu
e=this[name];if(value!==oldValue){if(value==undefined)this.removeAttribute(attri
buteName);else this.setAttribute(attributeName,value);if(opt_setHook)opt_setHook
.call(this,value,oldValue);dispatchPropertyChange(this,name,value,oldValue)}};ca
se PropertyKind.BOOL_ATTR:var attributeName=getAttributeName(name);return functi
on(value){var oldValue=this[name];if(value!==oldValue){if(value)this.setAttribut
e(attributeName,name);else this.removeAttribute(attributeName);if(opt_setHook)op
t_setHook.call(this,value,oldValue);dispatchPropertyChange(this,name,value,oldVa
lue)}}}throw"not reached"}function defineProperty(obj,name,opt_kind,opt_setHook)
{if(typeof obj=="function")obj=obj.prototype;var kind=opt_kind||PropertyKind.JS;
if(!obj.__lookupGetter__(name))obj.__defineGetter__(name,getGetter(name,kind));i
f(!obj.__lookupSetter__(name))obj.__defineSetter__(name,getSetter(name,kind,opt_
setHook))}var uidCounter=1;function createUid(){return uidCounter++}function get
Uid(item){if(item.hasOwnProperty("uid"))return item.uid;return item.uid=createUi
d()}function dispatchSimpleEvent(target,type,opt_bubbles,opt_cancelable){var e=n
ew Event(type,{bubbles:opt_bubbles,cancelable:opt_cancelable===undefined||opt_ca
ncelable});return target.dispatchEvent(e)}function define(name,fun){var obj=expo
rtPath(name);var exports=fun();for(var propertyName in exports){var propertyDesc
riptor=Object.getOwnPropertyDescriptor(exports,propertyName);if(propertyDescript
or)Object.defineProperty(obj,propertyName,propertyDescriptor)}}function addSingl
etonGetter(ctor){ctor.getInstance=function(){return ctor.instance_||(ctor.instan
ce_=new ctor)}}function makePublic(ctor,methods,opt_target){methods.forEach(func
tion(method){ctor[method]=function(){var target=opt_target?document.getElementBy
Id(opt_target):ctor.getInstance();return target[method+"_"].apply(target,argumen
ts)}})}var chromeSendResolverMap={};function webUIResponse(id,isSuccess,response
){var resolver=chromeSendResolverMap[id];delete chromeSendResolverMap[id];if(isS
uccess)resolver.resolve(response);else resolver.reject(response)}function sendWi
thPromise(methodName,var_args){var args=Array.prototype.slice.call(arguments,1);
var promiseResolver=new PromiseResolver;var id=methodName+"_"+createUid();chrome
SendResolverMap[id]=promiseResolver;chrome.send(methodName,[id].concat(args));re
turn promiseResolver.promise}var webUIListenerMap={};function webUIListenerCallb
ack(event,var_args){var eventListenersMap=webUIListenerMap[event];if(!eventListe
nersMap){return}var args=Array.prototype.slice.call(arguments,1);for(var listene
rId in eventListenersMap){eventListenersMap[listenerId].apply(null,args)}}functi
on addWebUIListener(eventName,callback){webUIListenerMap[eventName]=webUIListene
rMap[eventName]||{};var uid=createUid();webUIListenerMap[eventName][uid]=callbac
k;return{eventName:eventName,uid:uid}}function removeWebUIListener(listener){var
listenerExists=webUIListenerMap[listener.eventName]&&webUIListenerMap[listener.
eventName][listener.uid];if(listenerExists){delete webUIListenerMap[listener.eve
ntName][listener.uid];return true}return false}return{addSingletonGetter:addSing
letonGetter,createUid:createUid,define:define,defineProperty:defineProperty,disp
atchPropertyChange:dispatchPropertyChange,dispatchSimpleEvent:dispatchSimpleEven
t,exportPath:exportPath,getUid:getUid,makePublic:makePublic,PropertyKind:Propert
yKind,addWebUIListener:addWebUIListener,removeWebUIListener:removeWebUIListener,
sendWithPromise:sendWithPromise,webUIListenerCallback:webUIListenerCallback,webU
IResponse:webUIResponse,get doc(){return document},get isMac(){return/Mac/.test(
navigator.platform)},get isWindows(){return/Win/.test(navigator.platform)},get i
sChromeOS(){return/CrOS/.test(navigator.userAgent)},get isLinux(){return/Linux/.
test(navigator.userAgent)},get isAndroid(){return/Android/.test(navigator.userAg
ent)},get isIOS(){return/iPad|iPhone|iPod/.test(navigator.platform)}}}(); |
| 66 | |
| 67 var WebUIListener; | |
| 68 | |
| 69 var cr = cr || function() { | |
| 70 'use strict'; | |
| 71 function exportPath(name, opt_object, opt_objectToExportTo) { | |
| 72 var parts = name.split('.'); | |
| 73 var cur = opt_objectToExportTo || global; | |
| 74 for (var part; parts.length && (part = parts.shift()); ) { | |
| 75 if (!parts.length && opt_object !== undefined) { | |
| 76 cur[part] = opt_object; | |
| 77 } else if (part in cur) { | |
| 78 cur = cur[part]; | |
| 79 } else { | |
| 80 cur = cur[part] = {}; | |
| 81 } | |
| 82 } | |
| 83 return cur; | |
| 84 } | |
| 85 function dispatchPropertyChange(target, propertyName, newValue, oldValue) { | |
| 86 var e = new Event(propertyName + 'Change'); | |
| 87 e.propertyName = propertyName; | |
| 88 e.newValue = newValue; | |
| 89 e.oldValue = oldValue; | |
| 90 target.dispatchEvent(e); | |
| 91 } | |
| 92 function getAttributeName(jsName) { | |
| 93 return jsName.replace(/([A-Z])/g, '-$1').toLowerCase(); | |
| 94 } | |
| 95 var PropertyKind = { | |
| 96 JS: 'js', | |
| 97 ATTR: 'attr', | |
| 98 BOOL_ATTR: 'boolAttr' | |
| 99 }; | |
| 100 function getGetter(name, kind) { | |
| 101 switch (kind) { | |
| 102 case PropertyKind.JS: | |
| 103 var privateName = name + '_'; | |
| 104 return function() { | |
| 105 return this[privateName]; | |
| 106 }; | |
| 107 | |
| 108 case PropertyKind.ATTR: | |
| 109 var attributeName = getAttributeName(name); | |
| 110 return function() { | |
| 111 return this.getAttribute(attributeName); | |
| 112 }; | |
| 113 | |
| 114 case PropertyKind.BOOL_ATTR: | |
| 115 var attributeName = getAttributeName(name); | |
| 116 return function() { | |
| 117 return this.hasAttribute(attributeName); | |
| 118 }; | |
| 119 } | |
| 120 throw 'not reached'; | |
| 121 } | |
| 122 function getSetter(name, kind, opt_setHook) { | |
| 123 switch (kind) { | |
| 124 case PropertyKind.JS: | |
| 125 var privateName = name + '_'; | |
| 126 return function(value) { | |
| 127 var oldValue = this[name]; | |
| 128 if (value !== oldValue) { | |
| 129 this[privateName] = value; | |
| 130 if (opt_setHook) opt_setHook.call(this, value, oldValue); | |
| 131 dispatchPropertyChange(this, name, value, oldValue); | |
| 132 } | |
| 133 }; | |
| 134 | |
| 135 case PropertyKind.ATTR: | |
| 136 var attributeName = getAttributeName(name); | |
| 137 return function(value) { | |
| 138 var oldValue = this[name]; | |
| 139 if (value !== oldValue) { | |
| 140 if (value == undefined) this.removeAttribute(attributeName); else this
.setAttribute(attributeName, value); | |
| 141 if (opt_setHook) opt_setHook.call(this, value, oldValue); | |
| 142 dispatchPropertyChange(this, name, value, oldValue); | |
| 143 } | |
| 144 }; | |
| 145 | |
| 146 case PropertyKind.BOOL_ATTR: | |
| 147 var attributeName = getAttributeName(name); | |
| 148 return function(value) { | |
| 149 var oldValue = this[name]; | |
| 150 if (value !== oldValue) { | |
| 151 if (value) this.setAttribute(attributeName, name); else this.removeAtt
ribute(attributeName); | |
| 152 if (opt_setHook) opt_setHook.call(this, value, oldValue); | |
| 153 dispatchPropertyChange(this, name, value, oldValue); | |
| 154 } | |
| 155 }; | |
| 156 } | |
| 157 throw 'not reached'; | |
| 158 } | |
| 159 function defineProperty(obj, name, opt_kind, opt_setHook) { | |
| 160 if (typeof obj == 'function') obj = obj.prototype; | |
| 161 var kind = opt_kind || PropertyKind.JS; | |
| 162 if (!obj.__lookupGetter__(name)) obj.__defineGetter__(name, getGetter(name,
kind)); | |
| 163 if (!obj.__lookupSetter__(name)) obj.__defineSetter__(name, getSetter(name,
kind, opt_setHook)); | |
| 164 } | |
| 165 var uidCounter = 1; | |
| 166 function createUid() { | |
| 167 return uidCounter++; | |
| 168 } | |
| 169 function getUid(item) { | |
| 170 if (item.hasOwnProperty('uid')) return item.uid; | |
| 171 return item.uid = createUid(); | |
| 172 } | |
| 173 function dispatchSimpleEvent(target, type, opt_bubbles, opt_cancelable) { | |
| 174 var e = new Event(type, { | |
| 175 bubbles: opt_bubbles, | |
| 176 cancelable: opt_cancelable === undefined || opt_cancelable | |
| 177 }); | |
| 178 return target.dispatchEvent(e); | |
| 179 } | |
| 180 function define(name, fun) { | |
| 181 var obj = exportPath(name); | |
| 182 var exports = fun(); | |
| 183 for (var propertyName in exports) { | |
| 184 var propertyDescriptor = Object.getOwnPropertyDescriptor(exports, property
Name); | |
| 185 if (propertyDescriptor) Object.defineProperty(obj, propertyName, propertyD
escriptor); | |
| 186 } | |
| 187 } | |
| 188 function addSingletonGetter(ctor) { | |
| 189 ctor.getInstance = function() { | |
| 190 return ctor.instance_ || (ctor.instance_ = new ctor()); | |
| 191 }; | |
| 192 } | |
| 193 function makePublic(ctor, methods, opt_target) { | |
| 194 methods.forEach(function(method) { | |
| 195 ctor[method] = function() { | |
| 196 var target = opt_target ? document.getElementById(opt_target) : ctor.get
Instance(); | |
| 197 return target[method + '_'].apply(target, arguments); | |
| 198 }; | |
| 199 }); | |
| 200 } | |
| 201 var chromeSendResolverMap = {}; | |
| 202 function webUIResponse(id, isSuccess, response) { | |
| 203 var resolver = chromeSendResolverMap[id]; | |
| 204 delete chromeSendResolverMap[id]; | |
| 205 if (isSuccess) resolver.resolve(response); else resolver.reject(response); | |
| 206 } | |
| 207 function sendWithPromise(methodName, var_args) { | |
| 208 var args = Array.prototype.slice.call(arguments, 1); | |
| 209 var promiseResolver = new PromiseResolver(); | |
| 210 var id = methodName + '_' + createUid(); | |
| 211 chromeSendResolverMap[id] = promiseResolver; | |
| 212 chrome.send(methodName, [ id ].concat(args)); | |
| 213 return promiseResolver.promise; | |
| 214 } | |
| 215 var webUIListenerMap = {}; | |
| 216 function webUIListenerCallback(event, var_args) { | |
| 217 var eventListenersMap = webUIListenerMap[event]; | |
| 218 if (!eventListenersMap) { | |
| 219 return; | |
| 220 } | |
| 221 var args = Array.prototype.slice.call(arguments, 1); | |
| 222 for (var listenerId in eventListenersMap) { | |
| 223 eventListenersMap[listenerId].apply(null, args); | |
| 224 } | |
| 225 } | |
| 226 function addWebUIListener(eventName, callback) { | |
| 227 webUIListenerMap[eventName] = webUIListenerMap[eventName] || {}; | |
| 228 var uid = createUid(); | |
| 229 webUIListenerMap[eventName][uid] = callback; | |
| 230 return { | |
| 231 eventName: eventName, | |
| 232 uid: uid | |
| 233 }; | |
| 234 } | |
| 235 function removeWebUIListener(listener) { | |
| 236 var listenerExists = webUIListenerMap[listener.eventName] && webUIListenerMa
p[listener.eventName][listener.uid]; | |
| 237 if (listenerExists) { | |
| 238 delete webUIListenerMap[listener.eventName][listener.uid]; | |
| 239 return true; | |
| 240 } | |
| 241 return false; | |
| 242 } | |
| 243 return { | |
| 244 addSingletonGetter: addSingletonGetter, | |
| 245 createUid: createUid, | |
| 246 define: define, | |
| 247 defineProperty: defineProperty, | |
| 248 dispatchPropertyChange: dispatchPropertyChange, | |
| 249 dispatchSimpleEvent: dispatchSimpleEvent, | |
| 250 exportPath: exportPath, | |
| 251 getUid: getUid, | |
| 252 makePublic: makePublic, | |
| 253 PropertyKind: PropertyKind, | |
| 254 addWebUIListener: addWebUIListener, | |
| 255 removeWebUIListener: removeWebUIListener, | |
| 256 sendWithPromise: sendWithPromise, | |
| 257 webUIListenerCallback: webUIListenerCallback, | |
| 258 webUIResponse: webUIResponse, | |
| 259 get doc() { | |
| 260 return document; | |
| 261 }, | |
| 262 get isMac() { | |
| 263 return /Mac/.test(navigator.platform); | |
| 264 }, | |
| 265 get isWindows() { | |
| 266 return /Win/.test(navigator.platform); | |
| 267 }, | |
| 268 get isChromeOS() { | |
| 269 return /CrOS/.test(navigator.userAgent); | |
| 270 }, | |
| 271 get isLinux() { | |
| 272 return /Linux/.test(navigator.userAgent); | |
| 273 }, | |
| 274 get isAndroid() { | |
| 275 return /Android/.test(navigator.userAgent); | |
| 276 }, | |
| 277 get isIOS() { | |
| 278 return /iPad|iPhone|iPod/.test(navigator.platform); | |
| 279 } | |
| 280 }; | |
| 281 }(); | |
| 282 | |
| 283 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 13 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 284 // Use of this source code is governed by a BSD-style license that can be | 14 // Use of this source code is governed by a BSD-style license that can be |
| 285 // found in the LICENSE file. | 15 // found in the LICENSE file. |
| 286 cr.define('cr.ui', function() { | 16 cr.define("cr.ui",function(){function decorate(source,constr){var elements;if(ty
peof source=="string")elements=cr.doc.querySelectorAll(source);else elements=[so
urce];for(var i=0,el;el=elements[i];i++){if(!(el instanceof constr))constr.decor
ate(el)}}function createElementHelper(tagName,opt_bag){var doc;if(opt_bag&&opt_b
ag.ownerDocument)doc=opt_bag.ownerDocument;else doc=cr.doc;return doc.createElem
ent(tagName)}function define(tagNameOrFunction){var createFunction,tagName;if(ty
peof tagNameOrFunction=="function"){createFunction=tagNameOrFunction;tagName=""}
else{createFunction=createElementHelper;tagName=tagNameOrFunction}function f(opt
_propertyBag){var el=createFunction(tagName,opt_propertyBag);f.decorate(el);for(
var propertyName in opt_propertyBag){el[propertyName]=opt_propertyBag[propertyNa
me]}return el}f.decorate=function(el){el.__proto__=f.prototype;el.decorate()};re
turn f}function limitInputWidth(el,parentEl,min,opt_scale){el.style.width="10px"
;var doc=el.ownerDocument;var win=doc.defaultView;var computedStyle=win.getCompu
tedStyle(el);var parentComputedStyle=win.getComputedStyle(parentEl);var rtl=comp
utedStyle.direction=="rtl";var inputRect=el.getBoundingClientRect();var parentRe
ct=parentEl.getBoundingClientRect();var startPos=rtl?parentRect.right-inputRect.
right:inputRect.left-parentRect.left;var inner=parseInt(computedStyle.borderLeft
Width,10)+parseInt(computedStyle.paddingLeft,10)+parseInt(computedStyle.paddingR
ight,10)+parseInt(computedStyle.borderRightWidth,10);var parentPadding=rtl?parse
Int(parentComputedStyle.paddingLeft,10):parseInt(parentComputedStyle.paddingRigh
t,10);var max=parentEl.clientWidth-startPos-inner-parentPadding;if(opt_scale)max
*=opt_scale;function limit(){if(el.scrollWidth>max){el.style.width=max+"px"}else
{el.style.width=0;var sw=el.scrollWidth;if(sw<min){el.style.width=min+"px"}else{
el.style.width=sw+"px"}}}el.addEventListener("input",limit);limit()}function toC
ssPx(pixels){if(!window.isFinite(pixels))console.error("Pixel value is not a num
ber: "+pixels);return Math.round(pixels)+"px"}function swallowDoubleClick(e){var
doc=e.target.ownerDocument;var counter=Math.min(1,e.detail);function swallow(e)
{e.stopPropagation();e.preventDefault()}function onclick(e){if(e.detail>counter)
{counter=e.detail;swallow(e)}else{doc.removeEventListener("dblclick",swallow,tru
e);doc.removeEventListener("click",onclick,true)}}setTimeout(function(){doc.addE
ventListener("click",onclick,true);doc.addEventListener("dblclick",swallow,true)
},0)}return{decorate:decorate,define:define,limitInputWidth:limitInputWidth,toCs
sPx:toCssPx,swallowDoubleClick:swallowDoubleClick}}); |
| 287 function decorate(source, constr) { | |
| 288 var elements; | |
| 289 if (typeof source == 'string') elements = cr.doc.querySelectorAll(source); e
lse elements = [ source ]; | |
| 290 for (var i = 0, el; el = elements[i]; i++) { | |
| 291 if (!(el instanceof constr)) constr.decorate(el); | |
| 292 } | |
| 293 } | |
| 294 function createElementHelper(tagName, opt_bag) { | |
| 295 var doc; | |
| 296 if (opt_bag && opt_bag.ownerDocument) doc = opt_bag.ownerDocument; else doc
= cr.doc; | |
| 297 return doc.createElement(tagName); | |
| 298 } | |
| 299 function define(tagNameOrFunction) { | |
| 300 var createFunction, tagName; | |
| 301 if (typeof tagNameOrFunction == 'function') { | |
| 302 createFunction = tagNameOrFunction; | |
| 303 tagName = ''; | |
| 304 } else { | |
| 305 createFunction = createElementHelper; | |
| 306 tagName = tagNameOrFunction; | |
| 307 } | |
| 308 function f(opt_propertyBag) { | |
| 309 var el = createFunction(tagName, opt_propertyBag); | |
| 310 f.decorate(el); | |
| 311 for (var propertyName in opt_propertyBag) { | |
| 312 el[propertyName] = opt_propertyBag[propertyName]; | |
| 313 } | |
| 314 return el; | |
| 315 } | |
| 316 f.decorate = function(el) { | |
| 317 el.__proto__ = f.prototype; | |
| 318 el.decorate(); | |
| 319 }; | |
| 320 return f; | |
| 321 } | |
| 322 function limitInputWidth(el, parentEl, min, opt_scale) { | |
| 323 el.style.width = '10px'; | |
| 324 var doc = el.ownerDocument; | |
| 325 var win = doc.defaultView; | |
| 326 var computedStyle = win.getComputedStyle(el); | |
| 327 var parentComputedStyle = win.getComputedStyle(parentEl); | |
| 328 var rtl = computedStyle.direction == 'rtl'; | |
| 329 var inputRect = el.getBoundingClientRect(); | |
| 330 var parentRect = parentEl.getBoundingClientRect(); | |
| 331 var startPos = rtl ? parentRect.right - inputRect.right : inputRect.left - p
arentRect.left; | |
| 332 var inner = parseInt(computedStyle.borderLeftWidth, 10) + parseInt(computedS
tyle.paddingLeft, 10) + parseInt(computedStyle.paddingRight, 10) + parseInt(comp
utedStyle.borderRightWidth, 10); | |
| 333 var parentPadding = rtl ? parseInt(parentComputedStyle.paddingLeft, 10) : pa
rseInt(parentComputedStyle.paddingRight, 10); | |
| 334 var max = parentEl.clientWidth - startPos - inner - parentPadding; | |
| 335 if (opt_scale) max *= opt_scale; | |
| 336 function limit() { | |
| 337 if (el.scrollWidth > max) { | |
| 338 el.style.width = max + 'px'; | |
| 339 } else { | |
| 340 el.style.width = 0; | |
| 341 var sw = el.scrollWidth; | |
| 342 if (sw < min) { | |
| 343 el.style.width = min + 'px'; | |
| 344 } else { | |
| 345 el.style.width = sw + 'px'; | |
| 346 } | |
| 347 } | |
| 348 } | |
| 349 el.addEventListener('input', limit); | |
| 350 limit(); | |
| 351 } | |
| 352 function toCssPx(pixels) { | |
| 353 if (!window.isFinite(pixels)) console.error('Pixel value is not a number: '
+ pixels); | |
| 354 return Math.round(pixels) + 'px'; | |
| 355 } | |
| 356 function swallowDoubleClick(e) { | |
| 357 var doc = e.target.ownerDocument; | |
| 358 var counter = Math.min(1, e.detail); | |
| 359 function swallow(e) { | |
| 360 e.stopPropagation(); | |
| 361 e.preventDefault(); | |
| 362 } | |
| 363 function onclick(e) { | |
| 364 if (e.detail > counter) { | |
| 365 counter = e.detail; | |
| 366 swallow(e); | |
| 367 } else { | |
| 368 doc.removeEventListener('dblclick', swallow, true); | |
| 369 doc.removeEventListener('click', onclick, true); | |
| 370 } | |
| 371 } | |
| 372 setTimeout(function() { | |
| 373 doc.addEventListener('click', onclick, true); | |
| 374 doc.addEventListener('dblclick', swallow, true); | |
| 375 }, 0); | |
| 376 } | |
| 377 return { | |
| 378 decorate: decorate, | |
| 379 define: define, | |
| 380 limitInputWidth: limitInputWidth, | |
| 381 toCssPx: toCssPx, | |
| 382 swallowDoubleClick: swallowDoubleClick | |
| 383 }; | |
| 384 }); | |
| 385 | |
| 386 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 17 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 387 // Use of this source code is governed by a BSD-style license that can be | 18 // Use of this source code is governed by a BSD-style license that can be |
| 388 // found in the LICENSE file. | 19 // found in the LICENSE file. |
| 389 cr.define('cr.ui', function() { | 20 cr.define("cr.ui",function(){function KeyboardShortcut(shortcut){var mods={};var
ident="";shortcut.split("|").forEach(function(part){var partLc=part.toLowerCase
();switch(partLc){case"alt":case"ctrl":case"meta":case"shift":mods[partLc+"Key"]
=true;break;default:if(ident)throw Error("Invalid shortcut");ident=part}});this.
ident_=ident;this.mods_=mods}KeyboardShortcut.prototype={matchesEvent:function(e
){if(e.key==this.ident_){var mods=this.mods_;return["altKey","ctrlKey","metaKey"
,"shiftKey"].every(function(k){return e[k]==!!mods[k]})}return false}};var Comma
nd=cr.ui.define("command");Command.prototype={__proto__:HTMLElement.prototype,de
corate:function(){CommandManager.init(assert(this.ownerDocument));if(this.hasAtt
ribute("shortcut"))this.shortcut=this.getAttribute("shortcut")},execute:function
(opt_element){if(this.disabled)return;var doc=this.ownerDocument;if(doc.activeEl
ement){var e=new Event("command",{bubbles:true});e.command=this;(opt_element||do
c.activeElement).dispatchEvent(e)}},canExecuteChange:function(opt_node){dispatch
CanExecuteEvent(this,opt_node||this.ownerDocument.activeElement)},shortcut_:"",g
et shortcut(){return this.shortcut_},set shortcut(shortcut){var oldShortcut=this
.shortcut_;if(shortcut!==oldShortcut){this.keyboardShortcuts_=shortcut.split(/\s
+/).map(function(shortcut){return new KeyboardShortcut(shortcut)});this.shortcut
_=shortcut;cr.dispatchPropertyChange(this,"shortcut",this.shortcut_,oldShortcut)
}},matchesEvent:function(e){if(!this.keyboardShortcuts_)return false;return this
.keyboardShortcuts_.some(function(keyboardShortcut){return keyboardShortcut.matc
hesEvent(e)})}};cr.defineProperty(Command,"label",cr.PropertyKind.ATTR);cr.defin
eProperty(Command,"disabled",cr.PropertyKind.BOOL_ATTR);cr.defineProperty(Comman
d,"hidden",cr.PropertyKind.BOOL_ATTR);cr.defineProperty(Command,"checked",cr.Pro
pertyKind.BOOL_ATTR);cr.defineProperty(Command,"hideShortcutText",cr.PropertyKin
d.BOOL_ATTR);function dispatchCanExecuteEvent(command,target){var e=new CanExecu
teEvent(command);target.dispatchEvent(e);command.disabled=!e.canExecute}var comm
andManagers={};function CommandManager(doc){doc.addEventListener("focus",this.ha
ndleFocus_.bind(this),true);doc.addEventListener("keydown",this.handleKeyDown_.b
ind(this),false)}CommandManager.init=function(doc){var uid=cr.getUid(doc);if(!(u
id in commandManagers)){commandManagers[uid]=new CommandManager(doc)}};CommandMa
nager.prototype={handleFocus_:function(e){var target=e.target;if(target.menu||ta
rget.command)return;var commands=Array.prototype.slice.call(target.ownerDocument
.querySelectorAll("command"));commands.forEach(function(command){dispatchCanExec
uteEvent(command,target)})},handleKeyDown_:function(e){var target=e.target;var c
ommands=Array.prototype.slice.call(target.ownerDocument.querySelectorAll("comman
d"));for(var i=0,command;command=commands[i];i++){if(command.matchesEvent(e)){co
mmand.canExecuteChange();if(!command.disabled){e.preventDefault();e.stopPropagat
ion();command.execute();return}}}}};function CanExecuteEvent(command){var e=new
Event("canExecute",{bubbles:true,cancelable:true});e.__proto__=CanExecuteEvent.p
rototype;e.command=command;return e}CanExecuteEvent.prototype={__proto__:Event.p
rototype,command:null,canExecute_:false,get canExecute(){return this.canExecute_
},set canExecute(canExecute){this.canExecute_=!!canExecute;this.stopPropagation(
);this.preventDefault()}};return{Command:Command,CanExecuteEvent:CanExecuteEvent
}}); |
| 390 function KeyboardShortcut(shortcut) { | |
| 391 var mods = {}; | |
| 392 var ident = ''; | |
| 393 shortcut.split('|').forEach(function(part) { | |
| 394 var partLc = part.toLowerCase(); | |
| 395 switch (partLc) { | |
| 396 case 'alt': | |
| 397 case 'ctrl': | |
| 398 case 'meta': | |
| 399 case 'shift': | |
| 400 mods[partLc + 'Key'] = true; | |
| 401 break; | |
| 402 | |
| 403 default: | |
| 404 if (ident) throw Error('Invalid shortcut'); | |
| 405 ident = part; | |
| 406 } | |
| 407 }); | |
| 408 this.ident_ = ident; | |
| 409 this.mods_ = mods; | |
| 410 } | |
| 411 KeyboardShortcut.prototype = { | |
| 412 matchesEvent: function(e) { | |
| 413 if (e.key == this.ident_) { | |
| 414 var mods = this.mods_; | |
| 415 return [ 'altKey', 'ctrlKey', 'metaKey', 'shiftKey' ].every(function(k)
{ | |
| 416 return e[k] == !!mods[k]; | |
| 417 }); | |
| 418 } | |
| 419 return false; | |
| 420 } | |
| 421 }; | |
| 422 var Command = cr.ui.define('command'); | |
| 423 Command.prototype = { | |
| 424 __proto__: HTMLElement.prototype, | |
| 425 decorate: function() { | |
| 426 CommandManager.init(assert(this.ownerDocument)); | |
| 427 if (this.hasAttribute('shortcut')) this.shortcut = this.getAttribute('shor
tcut'); | |
| 428 }, | |
| 429 execute: function(opt_element) { | |
| 430 if (this.disabled) return; | |
| 431 var doc = this.ownerDocument; | |
| 432 if (doc.activeElement) { | |
| 433 var e = new Event('command', { | |
| 434 bubbles: true | |
| 435 }); | |
| 436 e.command = this; | |
| 437 (opt_element || doc.activeElement).dispatchEvent(e); | |
| 438 } | |
| 439 }, | |
| 440 canExecuteChange: function(opt_node) { | |
| 441 dispatchCanExecuteEvent(this, opt_node || this.ownerDocument.activeElement
); | |
| 442 }, | |
| 443 shortcut_: '', | |
| 444 get shortcut() { | |
| 445 return this.shortcut_; | |
| 446 }, | |
| 447 set shortcut(shortcut) { | |
| 448 var oldShortcut = this.shortcut_; | |
| 449 if (shortcut !== oldShortcut) { | |
| 450 this.keyboardShortcuts_ = shortcut.split(/\s+/).map(function(shortcut) { | |
| 451 return new KeyboardShortcut(shortcut); | |
| 452 }); | |
| 453 this.shortcut_ = shortcut; | |
| 454 cr.dispatchPropertyChange(this, 'shortcut', this.shortcut_, oldShortcut)
; | |
| 455 } | |
| 456 }, | |
| 457 matchesEvent: function(e) { | |
| 458 if (!this.keyboardShortcuts_) return false; | |
| 459 return this.keyboardShortcuts_.some(function(keyboardShortcut) { | |
| 460 return keyboardShortcut.matchesEvent(e); | |
| 461 }); | |
| 462 } | |
| 463 }; | |
| 464 cr.defineProperty(Command, 'label', cr.PropertyKind.ATTR); | |
| 465 cr.defineProperty(Command, 'disabled', cr.PropertyKind.BOOL_ATTR); | |
| 466 cr.defineProperty(Command, 'hidden', cr.PropertyKind.BOOL_ATTR); | |
| 467 cr.defineProperty(Command, 'checked', cr.PropertyKind.BOOL_ATTR); | |
| 468 cr.defineProperty(Command, 'hideShortcutText', cr.PropertyKind.BOOL_ATTR); | |
| 469 function dispatchCanExecuteEvent(command, target) { | |
| 470 var e = new CanExecuteEvent(command); | |
| 471 target.dispatchEvent(e); | |
| 472 command.disabled = !e.canExecute; | |
| 473 } | |
| 474 var commandManagers = {}; | |
| 475 function CommandManager(doc) { | |
| 476 doc.addEventListener('focus', this.handleFocus_.bind(this), true); | |
| 477 doc.addEventListener('keydown', this.handleKeyDown_.bind(this), false); | |
| 478 } | |
| 479 CommandManager.init = function(doc) { | |
| 480 var uid = cr.getUid(doc); | |
| 481 if (!(uid in commandManagers)) { | |
| 482 commandManagers[uid] = new CommandManager(doc); | |
| 483 } | |
| 484 }; | |
| 485 CommandManager.prototype = { | |
| 486 handleFocus_: function(e) { | |
| 487 var target = e.target; | |
| 488 if (target.menu || target.command) return; | |
| 489 var commands = Array.prototype.slice.call(target.ownerDocument.querySelect
orAll('command')); | |
| 490 commands.forEach(function(command) { | |
| 491 dispatchCanExecuteEvent(command, target); | |
| 492 }); | |
| 493 }, | |
| 494 handleKeyDown_: function(e) { | |
| 495 var target = e.target; | |
| 496 var commands = Array.prototype.slice.call(target.ownerDocument.querySelect
orAll('command')); | |
| 497 for (var i = 0, command; command = commands[i]; i++) { | |
| 498 if (command.matchesEvent(e)) { | |
| 499 command.canExecuteChange(); | |
| 500 if (!command.disabled) { | |
| 501 e.preventDefault(); | |
| 502 e.stopPropagation(); | |
| 503 command.execute(); | |
| 504 return; | |
| 505 } | |
| 506 } | |
| 507 } | |
| 508 } | |
| 509 }; | |
| 510 function CanExecuteEvent(command) { | |
| 511 var e = new Event('canExecute', { | |
| 512 bubbles: true, | |
| 513 cancelable: true | |
| 514 }); | |
| 515 e.__proto__ = CanExecuteEvent.prototype; | |
| 516 e.command = command; | |
| 517 return e; | |
| 518 } | |
| 519 CanExecuteEvent.prototype = { | |
| 520 __proto__: Event.prototype, | |
| 521 command: null, | |
| 522 canExecute_: false, | |
| 523 get canExecute() { | |
| 524 return this.canExecute_; | |
| 525 }, | |
| 526 set canExecute(canExecute) { | |
| 527 this.canExecute_ = !!canExecute; | |
| 528 this.stopPropagation(); | |
| 529 this.preventDefault(); | |
| 530 } | |
| 531 }; | |
| 532 return { | |
| 533 Command: Command, | |
| 534 CanExecuteEvent: CanExecuteEvent | |
| 535 }; | |
| 536 }); | |
| 537 | |
| 538 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 21 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 539 // Use of this source code is governed by a BSD-style license that can be | 22 // Use of this source code is governed by a BSD-style license that can be |
| 540 // found in the LICENSE file. | 23 // found in the LICENSE file. |
| 541 function $(id) { | 24 function $(id){var el=document.getElementById(id);return el?assertInstanceof(el,
HTMLElement):null}function getSVGElement(id){var el=document.getElementById(id);
return el?assertInstanceof(el,Element):null}function announceAccessibleMessage(m
sg){var element=document.createElement("div");element.setAttribute("aria-live","
polite");element.style.position="relative";element.style.left="-9999px";element.
style.height="0px";element.innerText=msg;document.body.appendChild(element);wind
ow.setTimeout(function(){document.body.removeChild(element)},0)}function url(s){
var s2=s.replace(/(\(|\)|\,|\s|\'|\"|\\)/g,"\\$1");if(/\\\\$/.test(s2)){s2+=" "}
return'url("'+s2+'")'}function parseQueryParams(location){var params={};var quer
y=unescape(location.search.substring(1));var vars=query.split("&");for(var i=0;i
<vars.length;i++){var pair=vars[i].split("=");params[pair[0]]=pair[1]}return par
ams}function setQueryParam(location,key,value){var query=parseQueryParams(locati
on);query[encodeURIComponent(key)]=encodeURIComponent(value);var newQuery="";for
(var q in query){newQuery+=(newQuery?"&":"?")+q+"="+query[q]}return location.ori
gin+location.pathname+newQuery+location.hash}function findAncestorByClass(el,cla
ssName){return findAncestor(el,function(el){return el.classList&&el.classList.co
ntains(className)})}function findAncestor(node,predicate){var last=false;while(n
ode!=null&&!(last=predicate(node))){node=node.parentNode}return last?node:null}f
unction swapDomNodes(a,b){var afterA=a.nextSibling;if(afterA==b){swapDomNodes(b,
a);return}var aParent=a.parentNode;b.parentNode.replaceChild(a,b);aParent.insert
Before(b,afterA)}function disableTextSelectAndDrag(opt_allowSelectStart,opt_allo
wDragStart){document.onselectstart=function(e){if(!(opt_allowSelectStart&&opt_al
lowSelectStart.call(this,e)))e.preventDefault()};document.ondragstart=function(e
){if(!(opt_allowDragStart&&opt_allowDragStart.call(this,e)))e.preventDefault()}}
function preventDefaultOnPoundLinkClicks(){document.addEventListener("click",fun
ction(e){var anchor=findAncestor(e.target,function(el){return el.tagName=="A"});
if(anchor&&anchor.getAttribute("href")=="#")e.preventDefault()})}function isRTL(
){return document.documentElement.dir=="rtl"}function getRequiredElement(id){ret
urn assertInstanceof($(id),HTMLElement,"Missing required element: "+id)}function
queryRequiredElement(selectors,opt_context){var element=(opt_context||document)
.querySelector(selectors);return assertInstanceof(element,HTMLElement,"Missing r
equired element: "+selectors)}["click","auxclick"].forEach(function(eventName){d
ocument.addEventListener(eventName,function(e){if(e.button>1)return;if(e.default
Prevented)return;var eventPath=e.path;var anchor=null;if(eventPath){for(var i=0;
i<eventPath.length;i++){var element=eventPath[i];if(element.tagName==="A"&&eleme
nt.href){anchor=element;break}}}var el=e.target;if(!anchor&&el.nodeType==Node.EL
EMENT_NODE&&el.webkitMatchesSelector("A, A *")){while(el.tagName!="A"){el=el.par
entElement}anchor=el}if(!anchor)return;anchor=anchor;if((anchor.protocol=="file:
"||anchor.protocol=="about:")&&(e.button==0||e.button==1)){chrome.send("navigate
ToUrl",[anchor.href,anchor.target,e.button,e.altKey,e.ctrlKey,e.metaKey,e.shiftK
ey]);e.preventDefault()}})});function appendParam(url,key,value){var param=encod
eURIComponent(key)+"="+encodeURIComponent(value);if(url.indexOf("?")==-1)return
url+"?"+param;return url+"&"+param}function createElementWithClassName(type,clas
sName){var elm=document.createElement(type);elm.className=className;return elm}f
unction ensureTransitionEndEvent(el,opt_timeOut){if(opt_timeOut===undefined){var
style=getComputedStyle(el);opt_timeOut=parseFloat(style.transitionDuration)*1e3
;opt_timeOut+=50}var fired=false;el.addEventListener("webkitTransitionEnd",funct
ion f(e){el.removeEventListener("webkitTransitionEnd",f);fired=true});window.set
Timeout(function(){if(!fired)cr.dispatchSimpleEvent(el,"webkitTransitionEnd",tru
e)},opt_timeOut)}function scrollTopForDocument(doc){return doc.documentElement.s
crollTop||doc.body.scrollTop}function setScrollTopForDocument(doc,value){doc.doc
umentElement.scrollTop=doc.body.scrollTop=value}function scrollLeftForDocument(d
oc){return doc.documentElement.scrollLeft||doc.body.scrollLeft}function setScrol
lLeftForDocument(doc,value){doc.documentElement.scrollLeft=doc.body.scrollLeft=v
alue}function HTMLEscape(original){return original.replace(/&/g,"&").replace
(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}
function elide(original,maxLength){if(original.length<=maxLength)return original
;return original.substring(0,maxLength-1)+"…"}function quoteString(str){return s
tr.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g,"\\$1")}function listen
Once(target,eventNames,callback){if(!Array.isArray(eventNames))eventNames=eventN
ames.split(/ +/);var removeAllAndCallCallback=function(event){eventNames.forEach
(function(eventName){target.removeEventListener(eventName,removeAllAndCallCallba
ck,false)});return callback(event)};eventNames.forEach(function(eventName){targe
t.addEventListener(eventName,removeAllAndCallCallback,false)})} |
| 542 var el = document.getElementById(id); | 25 // <if expr="is_ios"> |
| 543 return el ? assertInstanceof(el, HTMLElement) : null; | 26 if(!("key"in KeyboardEvent.prototype)){Object.defineProperty(KeyboardEvent.proto
type,"key",{get:function(){if(this.keyCode>=48&&this.keyCode<=57)return String.f
romCharCode(this.keyCode);if(this.keyCode>=65&&this.keyCode<=90){var result=Stri
ng.fromCharCode(this.keyCode).toLowerCase();if(this.shiftKey)result=result.toUpp
erCase();return result}switch(this.keyCode){case 8:return"Backspace";case 9:retu
rn"Tab";case 13:return"Enter";case 16:return"Shift";case 17:return"Control";case
18:return"Alt";case 27:return"Escape";case 32:return" ";case 33:return"PageUp";
case 34:return"PageDown";case 35:return"End";case 36:return"Home";case 37:return
"ArrowLeft";case 38:return"ArrowUp";case 39:return"ArrowRight";case 40:return"Ar
rowDown";case 45:return"Insert";case 46:return"Delete";case 91:return"Meta";case
112:return"F1";case 113:return"F2";case 114:return"F3";case 115:return"F4";case
116:return"F5";case 117:return"F6";case 118:return"F7";case 119:return"F8";case
120:return"F9";case 121:return"F10";case 122:return"F11";case 123:return"F12";c
ase 187:return"=";case 189:return"-";case 219:return"[";case 221:return"]"}retur
n"Unidentified"}})}else{window.console.log("KeyboardEvent.Key polyfill not requi
red")} |
| 544 } | 27 // </if> /* is_ios */ |
| 28 Polymer.IronResizableBehavior={properties:{_parentResizable:{type:Object,observe
r:"_parentResizableChanged"},_notifyingDescendant:{type:Boolean,value:false}},li
steners:{"iron-request-resize-notifications":"_onIronRequestResizeNotifications"
},created:function(){this._interestedResizables=[];this._boundNotifyResize=this.
notifyResize.bind(this)},attached:function(){this.fire("iron-request-resize-noti
fications",null,{node:this,bubbles:true,cancelable:true});if(!this._parentResiza
ble){window.addEventListener("resize",this._boundNotifyResize);this.notifyResize
()}},detached:function(){if(this._parentResizable){this._parentResizable.stopRes
izeNotificationsFor(this)}else{window.removeEventListener("resize",this._boundNo
tifyResize)}this._parentResizable=null},notifyResize:function(){if(!this.isAttac
hed){return}this._interestedResizables.forEach(function(resizable){if(this.resiz
erShouldNotify(resizable)){this._notifyDescendant(resizable)}},this);this._fireR
esize()},assignParentResizable:function(parentResizable){this._parentResizable=p
arentResizable},stopResizeNotificationsFor:function(target){var index=this._inte
restedResizables.indexOf(target);if(index>-1){this._interestedResizables.splice(
index,1);this.unlisten(target,"iron-resize","_onDescendantIronResize")}},resizer
ShouldNotify:function(element){return true},_onDescendantIronResize:function(eve
nt){if(this._notifyingDescendant){event.stopPropagation();return}if(!Polymer.Set
tings.useShadow){this._fireResize()}},_fireResize:function(){this.fire("iron-res
ize",null,{node:this,bubbles:false})},_onIronRequestResizeNotifications:function
(event){var target=event.path?event.path[0]:event.target;if(target===this){retur
n}if(this._interestedResizables.indexOf(target)===-1){this._interestedResizables
.push(target);this.listen(target,"iron-resize","_onDescendantIronResize")}target
.assignParentResizable(this);this._notifyDescendant(target);event.stopPropagatio
n()},_parentResizableChanged:function(parentResizable){if(parentResizable){windo
w.removeEventListener("resize",this._boundNotifyResize)}},_notifyDescendant:func
tion(descendant){if(!this.isAttached){return}this._notifyingDescendant=true;desc
endant.notifyResize();this._notifyingDescendant=false}};(function(){"use strict"
;var KEY_IDENTIFIER={"U+0008":"backspace","U+0009":"tab","U+001B":"esc","U+0020"
:"space","U+007F":"del"};var KEY_CODE={8:"backspace",9:"tab",13:"enter",27:"esc"
,33:"pageup",34:"pagedown",35:"end",36:"home",32:"space",37:"left",38:"up",39:"r
ight",40:"down",46:"del",106:"*"};var MODIFIER_KEYS={shift:"shiftKey",ctrl:"ctrl
Key",alt:"altKey",meta:"metaKey"};var KEY_CHAR=/[a-z0-9*]/;var IDENT_CHAR=/U\+/;
var ARROW_KEY=/^arrow/;var SPACE_KEY=/^space(bar)?/;var ESC_KEY=/^escape$/;funct
ion transformKey(key,noSpecialChars){var validKey="";if(key){var lKey=key.toLowe
rCase();if(lKey===" "||SPACE_KEY.test(lKey)){validKey="space"}else if(ESC_KEY.te
st(lKey)){validKey="esc"}else if(lKey.length==1){if(!noSpecialChars||KEY_CHAR.te
st(lKey)){validKey=lKey}}else if(ARROW_KEY.test(lKey)){validKey=lKey.replace("ar
row","")}else if(lKey=="multiply"){validKey="*"}else{validKey=lKey}}return valid
Key}function transformKeyIdentifier(keyIdent){var validKey="";if(keyIdent){if(ke
yIdent in KEY_IDENTIFIER){validKey=KEY_IDENTIFIER[keyIdent]}else if(IDENT_CHAR.t
est(keyIdent)){keyIdent=parseInt(keyIdent.replace("U+","0x"),16);validKey=String
.fromCharCode(keyIdent).toLowerCase()}else{validKey=keyIdent.toLowerCase()}}retu
rn validKey}function transformKeyCode(keyCode){var validKey="";if(Number(keyCode
)){if(keyCode>=65&&keyCode<=90){validKey=String.fromCharCode(32+keyCode)}else if
(keyCode>=112&&keyCode<=123){validKey="f"+(keyCode-112)}else if(keyCode>=48&&key
Code<=57){validKey=String(keyCode-48)}else if(keyCode>=96&&keyCode<=105){validKe
y=String(keyCode-96)}else{validKey=KEY_CODE[keyCode]}}return validKey}function n
ormalizedKeyForEvent(keyEvent,noSpecialChars){if(keyEvent.key){return transformK
ey(keyEvent.key,noSpecialChars)}if(keyEvent.detail&&keyEvent.detail.key){return
transformKey(keyEvent.detail.key,noSpecialChars)}return transformKeyIdentifier(k
eyEvent.keyIdentifier)||transformKeyCode(keyEvent.keyCode)||""}function keyCombo
MatchesEvent(keyCombo,event){var keyEvent=normalizedKeyForEvent(event,keyCombo.h
asModifiers);return keyEvent===keyCombo.key&&(!keyCombo.hasModifiers||!!event.sh
iftKey===!!keyCombo.shiftKey&&!!event.ctrlKey===!!keyCombo.ctrlKey&&!!event.altK
ey===!!keyCombo.altKey&&!!event.metaKey===!!keyCombo.metaKey)}function parseKeyC
omboString(keyComboString){if(keyComboString.length===1){return{combo:keyComboSt
ring,key:keyComboString,event:"keydown"}}return keyComboString.split("+").reduce
(function(parsedKeyCombo,keyComboPart){var eventParts=keyComboPart.split(":");va
r keyName=eventParts[0];var event=eventParts[1];if(keyName in MODIFIER_KEYS){par
sedKeyCombo[MODIFIER_KEYS[keyName]]=true;parsedKeyCombo.hasModifiers=true}else{p
arsedKeyCombo.key=keyName;parsedKeyCombo.event=event||"keydown"}return parsedKey
Combo},{combo:keyComboString.split(":").shift()})}function parseEventString(even
tString){return eventString.trim().split(" ").map(function(keyComboString){retur
n parseKeyComboString(keyComboString)})}Polymer.IronA11yKeysBehavior={properties
:{keyEventTarget:{type:Object,value:function(){return this}},stopKeyboardEventPr
opagation:{type:Boolean,value:false},_boundKeyHandlers:{type:Array,value:functio
n(){return[]}},_imperativeKeyBindings:{type:Object,value:function(){return{}}}},
observers:["_resetKeyEventListeners(keyEventTarget, _boundKeyHandlers)"],keyBind
ings:{},registered:function(){this._prepKeyBindings()},attached:function(){this.
_listenKeyEventListeners()},detached:function(){this._unlistenKeyEventListeners(
)},addOwnKeyBinding:function(eventString,handlerName){this._imperativeKeyBinding
s[eventString]=handlerName;this._prepKeyBindings();this._resetKeyEventListeners(
)},removeOwnKeyBindings:function(){this._imperativeKeyBindings={};this._prepKeyB
indings();this._resetKeyEventListeners()},keyboardEventMatchesKeys:function(even
t,eventString){var keyCombos=parseEventString(eventString);for(var i=0;i<keyComb
os.length;++i){if(keyComboMatchesEvent(keyCombos[i],event)){return true}}return
false},_collectKeyBindings:function(){var keyBindings=this.behaviors.map(functio
n(behavior){return behavior.keyBindings});if(keyBindings.indexOf(this.keyBinding
s)===-1){keyBindings.push(this.keyBindings)}return keyBindings},_prepKeyBindings
:function(){this._keyBindings={};this._collectKeyBindings().forEach(function(key
Bindings){for(var eventString in keyBindings){this._addKeyBinding(eventString,ke
yBindings[eventString])}},this);for(var eventString in this._imperativeKeyBindin
gs){this._addKeyBinding(eventString,this._imperativeKeyBindings[eventString])}fo
r(var eventName in this._keyBindings){this._keyBindings[eventName].sort(function
(kb1,kb2){var b1=kb1[0].hasModifiers;var b2=kb2[0].hasModifiers;return b1===b2?0
:b1?-1:1})}},_addKeyBinding:function(eventString,handlerName){parseEventString(e
ventString).forEach(function(keyCombo){this._keyBindings[keyCombo.event]=this._k
eyBindings[keyCombo.event]||[];this._keyBindings[keyCombo.event].push([keyCombo,
handlerName])},this)},_resetKeyEventListeners:function(){this._unlistenKeyEventL
isteners();if(this.isAttached){this._listenKeyEventListeners()}},_listenKeyEvent
Listeners:function(){if(!this.keyEventTarget){return}Object.keys(this._keyBindin
gs).forEach(function(eventName){var keyBindings=this._keyBindings[eventName];var
boundKeyHandler=this._onKeyBindingEvent.bind(this,keyBindings);this._boundKeyHa
ndlers.push([this.keyEventTarget,eventName,boundKeyHandler]);this.keyEventTarget
.addEventListener(eventName,boundKeyHandler)},this)},_unlistenKeyEventListeners:
function(){var keyHandlerTuple;var keyEventTarget;var eventName;var boundKeyHand
ler;while(this._boundKeyHandlers.length){keyHandlerTuple=this._boundKeyHandlers.
pop();keyEventTarget=keyHandlerTuple[0];eventName=keyHandlerTuple[1];boundKeyHan
dler=keyHandlerTuple[2];keyEventTarget.removeEventListener(eventName,boundKeyHan
dler)}},_onKeyBindingEvent:function(keyBindings,event){if(this.stopKeyboardEvent
Propagation){event.stopPropagation()}if(event.defaultPrevented){return}for(var i
=0;i<keyBindings.length;i++){var keyCombo=keyBindings[i][0];var handlerName=keyB
indings[i][1];if(keyComboMatchesEvent(keyCombo,event)){this._triggerKeyHandler(k
eyCombo,handlerName,event);if(event.defaultPrevented){return}}}},_triggerKeyHand
ler:function(keyCombo,handlerName,keyboardEvent){var detail=Object.create(keyCom
bo);detail.keyboardEvent=keyboardEvent;var event=new CustomEvent(keyCombo.event,
{detail:detail,cancelable:true});this[handlerName].call(this,event);if(event.def
aultPrevented){keyboardEvent.preventDefault()}}}})();Polymer.IronScrollTargetBeh
avior={properties:{scrollTarget:{type:HTMLElement,value:function(){return this._
defaultScrollTarget}}},observers:["_scrollTargetChanged(scrollTarget, isAttached
)"],_scrollTargetChanged:function(scrollTarget,isAttached){var eventTarget;if(th
is._oldScrollTarget){eventTarget=this._oldScrollTarget===this._doc?window:this._
oldScrollTarget;eventTarget.removeEventListener("scroll",this._boundScrollHandle
r);this._oldScrollTarget=null}if(!isAttached){return}if(scrollTarget==="document
"){this.scrollTarget=this._doc}else if(typeof scrollTarget==="string"){this.scro
llTarget=this.domHost?this.domHost.$[scrollTarget]:Polymer.dom(this.ownerDocumen
t).querySelector("#"+scrollTarget)}else if(this._isValidScrollTarget()){eventTar
get=scrollTarget===this._doc?window:scrollTarget;this._boundScrollHandler=this._
boundScrollHandler||this._scrollHandler.bind(this);this._oldScrollTarget=scrollT
arget;eventTarget.addEventListener("scroll",this._boundScrollHandler)}},_scrollH
andler:function scrollHandler(){},get _defaultScrollTarget(){return this._doc},g
et _doc(){return this.ownerDocument.documentElement},get _scrollTop(){if(this._i
sValidScrollTarget()){return this.scrollTarget===this._doc?window.pageYOffset:th
is.scrollTarget.scrollTop}return 0},get _scrollLeft(){if(this._isValidScrollTarg
et()){return this.scrollTarget===this._doc?window.pageXOffset:this.scrollTarget.
scrollLeft}return 0},set _scrollTop(top){if(this.scrollTarget===this._doc){windo
w.scrollTo(window.pageXOffset,top)}else if(this._isValidScrollTarget()){this.scr
ollTarget.scrollTop=top}},set _scrollLeft(left){if(this.scrollTarget===this._doc
){window.scrollTo(left,window.pageYOffset)}else if(this._isValidScrollTarget()){
this.scrollTarget.scrollLeft=left}},scroll:function(left,top){if(this.scrollTarg
et===this._doc){window.scrollTo(left,top)}else if(this._isValidScrollTarget()){t
his.scrollTarget.scrollLeft=left;this.scrollTarget.scrollTop=top}},get _scrollTa
rgetWidth(){if(this._isValidScrollTarget()){return this.scrollTarget===this._doc
?window.innerWidth:this.scrollTarget.offsetWidth}return 0},get _scrollTargetHeig
ht(){if(this._isValidScrollTarget()){return this.scrollTarget===this._doc?window
.innerHeight:this.scrollTarget.offsetHeight}return 0},_isValidScrollTarget:funct
ion(){return this.scrollTarget instanceof HTMLElement}};(function(){var IOS=navi
gator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/);var IOS_TOUCH_SCROL
LING=IOS&&IOS[1]>=8;var DEFAULT_PHYSICAL_COUNT=3;var HIDDEN_Y="-10000px";var DEF
AULT_GRID_SIZE=200;var SECRET_TABINDEX=-100;Polymer({is:"iron-list",properties:{
items:{type:Array},maxPhysicalCount:{type:Number,value:500},as:{type:String,valu
e:"item"},indexAs:{type:String,value:"index"},selectedAs:{type:String,value:"sel
ected"},grid:{type:Boolean,value:false,reflectToAttribute:true},selectionEnabled
:{type:Boolean,value:false},selectedItem:{type:Object,notify:true},selectedItems
:{type:Object,notify:true},multiSelection:{type:Boolean,value:false}},observers:
["_itemsChanged(items.*)","_selectionEnabledChanged(selectionEnabled)","_multiSe
lectionChanged(multiSelection)","_setOverflow(scrollTarget)"],behaviors:[Polymer
.Templatizer,Polymer.IronResizableBehavior,Polymer.IronA11yKeysBehavior,Polymer.
IronScrollTargetBehavior],keyBindings:{up:"_didMoveUp",down:"_didMoveDown",enter
:"_didEnter"},_ratio:.5,_scrollerPaddingTop:0,_scrollPosition:0,_physicalSize:0,
_physicalAverage:0,_physicalAverageCount:0,_physicalTop:0,_virtualCount:0,_physi
calIndexForKey:null,_estScrollHeight:0,_scrollHeight:0,_viewportHeight:0,_viewpo
rtWidth:0,_physicalItems:null,_physicalSizes:null,_firstVisibleIndexVal:null,_la
stVisibleIndexVal:null,_collection:null,_maxPages:3,_focusedItem:null,_focusedIn
dex:-1,_offscreenFocusedItem:null,_focusBackfillItem:null,_itemsPerRow:1,_itemWi
dth:0,_rowHeight:0,_templateCost:0,get _physicalBottom(){return this._physicalTo
p+this._physicalSize},get _scrollBottom(){return this._scrollPosition+this._view
portHeight},get _virtualEnd(){return this._virtualStart+this._physicalCount-1},g
et _hiddenContentSize(){var size=this.grid?this._physicalRows*this._rowHeight:th
is._physicalSize;return size-this._viewportHeight},get _maxScrollTop(){return th
is._estScrollHeight-this._viewportHeight+this._scrollerPaddingTop},_minVirtualSt
art:0,get _maxVirtualStart(){return Math.max(0,this._virtualCount-this._physical
Count)},_virtualStartVal:0,set _virtualStart(val){this._virtualStartVal=Math.min
(this._maxVirtualStart,Math.max(this._minVirtualStart,val))},get _virtualStart()
{return this._virtualStartVal||0},_physicalStartVal:0,set _physicalStart(val){th
is._physicalStartVal=val%this._physicalCount;if(this._physicalStartVal<0){this._
physicalStartVal=this._physicalCount+this._physicalStartVal}this._physicalEnd=(t
his._physicalStart+this._physicalCount-1)%this._physicalCount},get _physicalStar
t(){return this._physicalStartVal||0},_physicalCountVal:0,set _physicalCount(val
){this._physicalCountVal=val;this._physicalEnd=(this._physicalStart+this._physic
alCount-1)%this._physicalCount},get _physicalCount(){return this._physicalCountV
al},_physicalEnd:0,get _optPhysicalSize(){if(this.grid){return this._estRowsInVi
ew*this._rowHeight*this._maxPages}return this._viewportHeight*this._maxPages},ge
t _optPhysicalCount(){return this._estRowsInView*this._itemsPerRow*this._maxPage
s},get _isVisible(){return Boolean(this.offsetWidth||this.offsetHeight)},get fir
stVisibleIndex(){if(this._firstVisibleIndexVal===null){var physicalOffset=Math.f
loor(this._physicalTop+this._scrollerPaddingTop);this._firstVisibleIndexVal=this
._iterateItems(function(pidx,vidx){physicalOffset+=this._getPhysicalSizeIncremen
t(pidx);if(physicalOffset>this._scrollPosition){return this.grid?vidx-vidx%this.
_itemsPerRow:vidx}if(this.grid&&this._virtualCount-1===vidx){return vidx-vidx%th
is._itemsPerRow}})||0}return this._firstVisibleIndexVal},get lastVisibleIndex(){
if(this._lastVisibleIndexVal===null){if(this.grid){var lastIndex=this.firstVisib
leIndex+this._estRowsInView*this._itemsPerRow-1;this._lastVisibleIndexVal=Math.m
in(this._virtualCount,lastIndex)}else{var physicalOffset=this._physicalTop;this.
_iterateItems(function(pidx,vidx){if(physicalOffset<this._scrollBottom){this._la
stVisibleIndexVal=vidx}else{return true}physicalOffset+=this._getPhysicalSizeInc
rement(pidx)})}}return this._lastVisibleIndexVal},get _defaultScrollTarget(){ret
urn this},get _virtualRowCount(){return Math.ceil(this._virtualCount/this._items
PerRow)},get _estRowsInView(){return Math.ceil(this._viewportHeight/this._rowHei
ght)},get _physicalRows(){return Math.ceil(this._physicalCount/this._itemsPerRow
)},ready:function(){this.addEventListener("focus",this._didFocus.bind(this),true
)},attached:function(){this.updateViewportBoundaries();if(this._physicalCount===
0){this._debounceTemplate(this._render)}this.listen(this,"iron-resize","_resizeH
andler")},detached:function(){this.unlisten(this,"iron-resize","_resizeHandler")
},_setOverflow:function(scrollTarget){this.style.webkitOverflowScrolling=scrollT
arget===this?"touch":"";this.style.overflow=scrollTarget===this?"auto":""},updat
eViewportBoundaries:function(){this._scrollerPaddingTop=this.scrollTarget===this
?0:parseInt(window.getComputedStyle(this)["padding-top"],10);this._viewportHeigh
t=this._scrollTargetHeight;if(this.grid){this._updateGridMetrics()}},_scrollHand
ler:function(){var scrollTop=Math.max(0,Math.min(this._maxScrollTop,this._scroll
Top));var delta=scrollTop-this._scrollPosition;var tileHeight,tileTop,kth,recycl
edTileSet,scrollBottom,physicalBottom;var ratio=this._ratio;var recycledTiles=0;
var hiddenContentSize=this._hiddenContentSize;var currentRatio=ratio;var movingU
p=[];this._scrollPosition=scrollTop;this._firstVisibleIndexVal=null;this._lastVi
sibleIndexVal=null;scrollBottom=this._scrollBottom;physicalBottom=this._physical
Bottom;if(Math.abs(delta)>this._physicalSize){this._physicalTop+=delta;recycledT
iles=Math.round(delta/this._physicalAverage)}else if(delta<0){var topSpace=scrol
lTop-this._physicalTop;var virtualStart=this._virtualStart;recycledTileSet=[];kt
h=this._physicalEnd;currentRatio=topSpace/hiddenContentSize;while(currentRatio<r
atio&&recycledTiles<this._physicalCount&&virtualStart-recycledTiles>0&&physicalB
ottom-this._getPhysicalSizeIncrement(kth)>scrollBottom){tileHeight=this._getPhys
icalSizeIncrement(kth);currentRatio+=tileHeight/hiddenContentSize;physicalBottom
-=tileHeight;recycledTileSet.push(kth);recycledTiles++;kth=kth===0?this._physica
lCount-1:kth-1}movingUp=recycledTileSet;recycledTiles=-recycledTiles}else if(del
ta>0){var bottomSpace=physicalBottom-scrollBottom;var virtualEnd=this._virtualEn
d;var lastVirtualItemIndex=this._virtualCount-1;recycledTileSet=[];kth=this._phy
sicalStart;currentRatio=bottomSpace/hiddenContentSize;while(currentRatio<ratio&&
recycledTiles<this._physicalCount&&virtualEnd+recycledTiles<lastVirtualItemIndex
&&this._physicalTop+this._getPhysicalSizeIncrement(kth)<scrollTop){tileHeight=th
is._getPhysicalSizeIncrement(kth);currentRatio+=tileHeight/hiddenContentSize;thi
s._physicalTop+=tileHeight;recycledTileSet.push(kth);recycledTiles++;kth=(kth+1)
%this._physicalCount}}if(recycledTiles===0){if(physicalBottom<scrollBottom||this
._physicalTop>scrollTop){this._increasePoolIfNeeded()}}else{this._virtualStart=t
his._virtualStart+recycledTiles;this._physicalStart=this._physicalStart+recycled
Tiles;this._update(recycledTileSet,movingUp)}},_update:function(itemSet,movingUp
){this._manageFocus();this._assignModels(itemSet);this._updateMetrics(itemSet);i
f(movingUp){while(movingUp.length){var idx=movingUp.pop();this._physicalTop-=thi
s._getPhysicalSizeIncrement(idx)}}this._positionItems();this._updateScrollerSize
();this._increasePoolIfNeeded()},_createPool:function(size){var physicalItems=ne
w Array(size);this._ensureTemplatized();for(var i=0;i<size;i++){var inst=this.st
amp(null);physicalItems[i]=inst.root.querySelector("*");Polymer.dom(this).append
Child(inst.root)}return physicalItems},_increasePoolIfNeeded:function(){if(this.
_viewportHeight===0){return false}var self=this;var isClientFull=this._physicalB
ottom>=this._scrollBottom&&this._physicalTop<=this._scrollPosition;if(this._phys
icalSize>=this._optPhysicalSize&&isClientFull){return false}var maxPoolSize=Math
.round(this._physicalCount*.5);if(!isClientFull){this._debounceTemplate(this._in
creasePool.bind(this,maxPoolSize));return true}this._yield(function(){self._incr
easePool(Math.min(maxPoolSize,Math.max(1,Math.round(50/self._templateCost))))});
return true},_yield:function(cb){var g=window;var handle=g.requestIdleCallback?g
.requestIdleCallback(cb):g.setTimeout(cb,16);Polymer.dom.addDebouncer({complete:
function(){g.cancelIdleCallback?g.cancelIdleCallback(handle):g.clearTimeout(hand
le);cb()}})},_increasePool:function(missingItems){var nextPhysicalCount=Math.min
(this._physicalCount+missingItems,this._virtualCount-this._virtualStart,Math.max
(this.maxPhysicalCount,DEFAULT_PHYSICAL_COUNT));var prevPhysicalCount=this._phys
icalCount;var delta=nextPhysicalCount-prevPhysicalCount;var ts=window.performanc
e.now();if(delta<=0){return}[].push.apply(this._physicalItems,this._createPool(d
elta));[].push.apply(this._physicalSizes,new Array(delta));this._physicalCount=p
revPhysicalCount+delta;if(this._physicalStart>this._physicalEnd&&this._isIndexRe
ndered(this._focusedIndex)&&this._getPhysicalIndex(this._focusedIndex)<this._phy
sicalEnd){this._physicalStart=this._physicalStart+delta}this._update();this._tem
plateCost=(window.performance.now()-ts)/delta},_render:function(){if(this.isAtta
ched&&this._isVisible){if(this._physicalCount===0){this._increasePool(DEFAULT_PH
YSICAL_COUNT)}else{this._update()}}},_ensureTemplatized:function(){if(!this.ctor
){var props={};props.__key__=true;props[this.as]=true;props[this.indexAs]=true;p
rops[this.selectedAs]=true;props.tabIndex=true;this._instanceProps=props;this._u
serTemplate=Polymer.dom(this).querySelector("template");if(this._userTemplate){t
his.templatize(this._userTemplate)}else{console.warn("iron-list requires a templ
ate to be provided in light-dom")}}},_getStampedChildren:function(){return this.
_physicalItems},_forwardInstancePath:function(inst,path,value){if(path.indexOf(t
his.as+".")===0){this.notifyPath("items."+inst.__key__+"."+path.slice(this.as.le
ngth+1),value)}},_forwardParentProp:function(prop,value){if(this._physicalItems)
{this._physicalItems.forEach(function(item){item._templateInstance[prop]=value},
this)}},_forwardParentPath:function(path,value){if(this._physicalItems){this._ph
ysicalItems.forEach(function(item){item._templateInstance.notifyPath(path,value,
true)},this)}},_forwardItemPath:function(path,value){if(!this._physicalIndexForK
ey){return}var dot=path.indexOf(".");var key=path.substring(0,dot<0?path.length:
dot);var idx=this._physicalIndexForKey[key];var offscreenItem=this._offscreenFoc
usedItem;var el=offscreenItem&&offscreenItem._templateInstance.__key__===key?off
screenItem:this._physicalItems[idx];if(!el||el._templateInstance.__key__!==key){
return}if(dot>=0){path=this.as+"."+path.substring(dot+1);el._templateInstance.no
tifyPath(path,value,true)}else{var currentItem=el._templateInstance[this.as];if(
Array.isArray(this.selectedItems)){for(var i=0;i<this.selectedItems.length;i++){
if(this.selectedItems[i]===currentItem){this.set("selectedItems."+i,value);break
}}}else if(this.selectedItem===currentItem){this.set("selectedItem",value)}el._t
emplateInstance[this.as]=value}},_itemsChanged:function(change){if(change.path==
="items"){this._virtualStart=0;this._physicalTop=0;this._virtualCount=this.items
?this.items.length:0;this._collection=this.items?Polymer.Collection.get(this.ite
ms):null;this._physicalIndexForKey={};this._firstVisibleIndexVal=null;this._last
VisibleIndexVal=null;this._physicalCount=this._physicalCount||0;this._physicalIt
ems=this._physicalItems||[];this._physicalSizes=this._physicalSizes||[];this._ph
ysicalStart=0;this._resetScrollPosition(0);this._removeFocusedItem();this._debou
nceTemplate(this._render)}else if(change.path==="items.splices"){this._adjustVir
tualIndex(change.value.indexSplices);this._virtualCount=this.items?this.items.le
ngth:0;this._debounceTemplate(this._render)}else{this._forwardItemPath(change.pa
th.split(".").slice(1).join("."),change.value)}},_adjustVirtualIndex:function(sp
lices){splices.forEach(function(splice){splice.removed.forEach(this._removeItem,
this);if(splice.index<this._virtualStart){var delta=Math.max(splice.addedCount-s
plice.removed.length,splice.index-this._virtualStart);this._virtualStart=this._v
irtualStart+delta;if(this._focusedIndex>=0){this._focusedIndex=this._focusedInde
x+delta}}},this)},_removeItem:function(item){this.$.selector.deselect(item);if(t
his._focusedItem&&this._focusedItem._templateInstance[this.as]===item){this._rem
oveFocusedItem()}},_iterateItems:function(fn,itemSet){var pidx,vidx,rtn,i;if(arg
uments.length===2&&itemSet){for(i=0;i<itemSet.length;i++){pidx=itemSet[i];vidx=t
his._computeVidx(pidx);if((rtn=fn.call(this,pidx,vidx))!=null){return rtn}}}else
{pidx=this._physicalStart;vidx=this._virtualStart;for(;pidx<this._physicalCount;
pidx++,vidx++){if((rtn=fn.call(this,pidx,vidx))!=null){return rtn}}for(pidx=0;pi
dx<this._physicalStart;pidx++,vidx++){if((rtn=fn.call(this,pidx,vidx))!=null){re
turn rtn}}}},_computeVidx:function(pidx){if(pidx>=this._physicalStart){return th
is._virtualStart+(pidx-this._physicalStart)}return this._virtualStart+(this._phy
sicalCount-this._physicalStart)+pidx},_assignModels:function(itemSet){this._iter
ateItems(function(pidx,vidx){var el=this._physicalItems[pidx];var inst=el._templ
ateInstance;var item=this.items&&this.items[vidx];if(item!=null){inst[this.as]=i
tem;inst.__key__=this._collection.getKey(item);inst[this.selectedAs]=this.$.sele
ctor.isSelected(item);inst[this.indexAs]=vidx;inst.tabIndex=this._focusedIndex==
=vidx?0:-1;this._physicalIndexForKey[inst.__key__]=pidx;el.removeAttribute("hidd
en")}else{inst.__key__=null;el.setAttribute("hidden","")}},itemSet)},_updateMetr
ics:function(itemSet){Polymer.dom.flush();var newPhysicalSize=0;var oldPhysicalS
ize=0;var prevAvgCount=this._physicalAverageCount;var prevPhysicalAvg=this._phys
icalAverage;this._iterateItems(function(pidx,vidx){oldPhysicalSize+=this._physic
alSizes[pidx]||0;this._physicalSizes[pidx]=this._physicalItems[pidx].offsetHeigh
t;newPhysicalSize+=this._physicalSizes[pidx];this._physicalAverageCount+=this._p
hysicalSizes[pidx]?1:0},itemSet);this._viewportHeight=this._scrollTargetHeight;i
f(this.grid){this._updateGridMetrics();this._physicalSize=Math.ceil(this._physic
alCount/this._itemsPerRow)*this._rowHeight}else{this._physicalSize=this._physica
lSize+newPhysicalSize-oldPhysicalSize}if(this._physicalAverageCount!==prevAvgCou
nt){this._physicalAverage=Math.round((prevPhysicalAvg*prevAvgCount+newPhysicalSi
ze)/this._physicalAverageCount)}},_updateGridMetrics:function(){this._viewportWi
dth=this.$.items.offsetWidth;this._itemWidth=this._physicalCount>0?this._physica
lItems[0].getBoundingClientRect().width:DEFAULT_GRID_SIZE;this._rowHeight=this._
physicalCount>0?this._physicalItems[0].offsetHeight:DEFAULT_GRID_SIZE;this._item
sPerRow=this._itemWidth?Math.floor(this._viewportWidth/this._itemWidth):this._it
emsPerRow},_positionItems:function(){this._adjustScrollPosition();var y=this._ph
ysicalTop;if(this.grid){var totalItemWidth=this._itemsPerRow*this._itemWidth;var
rowOffset=(this._viewportWidth-totalItemWidth)/2;this._iterateItems(function(pi
dx,vidx){var modulus=vidx%this._itemsPerRow;var x=Math.floor(modulus*this._itemW
idth+rowOffset);this.translate3d(x+"px",y+"px",0,this._physicalItems[pidx]);if(t
his._shouldRenderNextRow(vidx)){y+=this._rowHeight}})}else{this._iterateItems(fu
nction(pidx,vidx){this.translate3d(0,y+"px",0,this._physicalItems[pidx]);y+=this
._physicalSizes[pidx]})}},_getPhysicalSizeIncrement:function(pidx){if(!this.grid
){return this._physicalSizes[pidx]}if(this._computeVidx(pidx)%this._itemsPerRow!
==this._itemsPerRow-1){return 0}return this._rowHeight},_shouldRenderNextRow:fun
ction(vidx){return vidx%this._itemsPerRow===this._itemsPerRow-1},_adjustScrollPo
sition:function(){var deltaHeight=this._virtualStart===0?this._physicalTop:Math.
min(this._scrollPosition+this._physicalTop,0);if(deltaHeight){this._physicalTop=
this._physicalTop-deltaHeight;if(!IOS_TOUCH_SCROLLING&&this._physicalTop!==0){th
is._resetScrollPosition(this._scrollTop-deltaHeight)}}},_resetScrollPosition:fun
ction(pos){if(this.scrollTarget){this._scrollTop=pos;this._scrollPosition=this._
scrollTop}},_updateScrollerSize:function(forceUpdate){if(this.grid){this._estScr
ollHeight=this._virtualRowCount*this._rowHeight}else{this._estScrollHeight=this.
_physicalBottom+Math.max(this._virtualCount-this._physicalCount-this._virtualSta
rt,0)*this._physicalAverage}forceUpdate=forceUpdate||this._scrollHeight===0;forc
eUpdate=forceUpdate||this._scrollPosition>=this._estScrollHeight-this._physicalS
ize;forceUpdate=forceUpdate||this.grid&&this.$.items.style.height<this._estScrol
lHeight;if(forceUpdate||Math.abs(this._estScrollHeight-this._scrollHeight)>=this
._optPhysicalSize){this.$.items.style.height=this._estScrollHeight+"px";this._sc
rollHeight=this._estScrollHeight}},scrollToItem:function(item){return this.scrol
lToIndex(this.items.indexOf(item))},scrollToIndex:function(idx){if(typeof idx!==
"number"||idx<0||idx>this.items.length-1){return}Polymer.dom.flush();if(this._ph
ysicalCount===0){return}idx=Math.min(Math.max(idx,0),this._virtualCount-1);if(!t
his._isIndexRendered(idx)||idx>=this._maxVirtualStart){this._virtualStart=this.g
rid?idx-this._itemsPerRow*2:idx-1}this._manageFocus();this._assignModels();this.
_updateMetrics();this._physicalTop=Math.floor(this._virtualStart/this._itemsPerR
ow)*this._physicalAverage;var currentTopItem=this._physicalStart;var currentVirt
ualItem=this._virtualStart;var targetOffsetTop=0;var hiddenContentSize=this._hid
denContentSize;while(currentVirtualItem<idx&&targetOffsetTop<=hiddenContentSize)
{targetOffsetTop=targetOffsetTop+this._getPhysicalSizeIncrement(currentTopItem);
currentTopItem=(currentTopItem+1)%this._physicalCount;currentVirtualItem++}this.
_updateScrollerSize(true);this._positionItems();this._resetScrollPosition(this._
physicalTop+this._scrollerPaddingTop+targetOffsetTop);this._increasePoolIfNeeded
();this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null},_resetAverage
:function(){this._physicalAverage=0;this._physicalAverageCount=0},_resizeHandler
:function(){if(IOS&&Math.abs(this._viewportHeight-this._scrollTargetHeight)<100)
{return}Polymer.dom.addDebouncer(this.debounce("_debounceTemplate",function(){th
is.updateViewportBoundaries();this._render();if(this._physicalCount>0&&this._isV
isible){this._resetAverage();this.scrollToIndex(this.firstVisibleIndex)}}.bind(t
his),1))},_getModelFromItem:function(item){var key=this._collection.getKey(item)
;var pidx=this._physicalIndexForKey[key];if(pidx!=null){return this._physicalIte
ms[pidx]._templateInstance}return null},_getNormalizedItem:function(item){if(thi
s._collection.getKey(item)===undefined){if(typeof item==="number"){item=this.ite
ms[item];if(!item){throw new RangeError("<item> not found")}return item}throw ne
w TypeError("<item> should be a valid item")}return item},selectItem:function(it
em){item=this._getNormalizedItem(item);var model=this._getModelFromItem(item);if
(!this.multiSelection&&this.selectedItem){this.deselectItem(this.selectedItem)}i
f(model){model[this.selectedAs]=true}this.$.selector.select(item);this.updateSiz
eForItem(item)},deselectItem:function(item){item=this._getNormalizedItem(item);v
ar model=this._getModelFromItem(item);if(model){model[this.selectedAs]=false}thi
s.$.selector.deselect(item);this.updateSizeForItem(item)},toggleSelectionForItem
:function(item){item=this._getNormalizedItem(item);if(this.$.selector.isSelected
(item)){this.deselectItem(item)}else{this.selectItem(item)}},clearSelection:func
tion(){function unselect(item){var model=this._getModelFromItem(item);if(model){
model[this.selectedAs]=false}}if(Array.isArray(this.selectedItems)){this.selecte
dItems.forEach(unselect,this)}else if(this.selectedItem){unselect.call(this,this
.selectedItem)}this.$.selector.clearSelection()},_selectionEnabledChanged:functi
on(selectionEnabled){var handler=selectionEnabled?this.listen:this.unlisten;hand
ler.call(this,this,"tap","_selectionHandler")},_selectionHandler:function(e){var
model=this.modelForElement(e.target);if(!model){return}var modelTabIndex,active
ElTabIndex;var target=Polymer.dom(e).path[0];var activeEl=Polymer.dom(this.domHo
st?this.domHost.root:document).activeElement;var physicalItem=this._physicalItem
s[this._getPhysicalIndex(model[this.indexAs])];if(target.localName==="input"||ta
rget.localName==="button"||target.localName==="select"){return}modelTabIndex=mod
el.tabIndex;model.tabIndex=SECRET_TABINDEX;activeElTabIndex=activeEl?activeEl.ta
bIndex:-1;model.tabIndex=modelTabIndex;if(activeEl&&physicalItem!==activeEl&&phy
sicalItem.contains(activeEl)&&activeElTabIndex!==SECRET_TABINDEX){return}this.to
ggleSelectionForItem(model[this.as])},_multiSelectionChanged:function(multiSelec
tion){this.clearSelection();this.$.selector.multi=multiSelection},updateSizeForI
tem:function(item){item=this._getNormalizedItem(item);var key=this._collection.g
etKey(item);var pidx=this._physicalIndexForKey[key];if(pidx!=null){this._updateM
etrics([pidx]);this._positionItems()}},_manageFocus:function(){var fidx=this._fo
cusedIndex;if(fidx>=0&&fidx<this._virtualCount){if(this._isIndexRendered(fidx)){
this._restoreFocusedItem(); |
| 545 | 29 |
| 546 function getSVGElement(id) { | 30 }else{this._createFocusBackfillItem()}}else if(this._virtualCount>0&&this._physi
calCount>0){this._focusedIndex=this._virtualStart;this._focusedItem=this._physic
alItems[this._physicalStart]}},_isIndexRendered:function(idx){return idx>=this._
virtualStart&&idx<=this._virtualEnd},_isIndexVisible:function(idx){return idx>=t
his.firstVisibleIndex&&idx<=this.lastVisibleIndex},_getPhysicalIndex:function(id
x){return this._physicalIndexForKey[this._collection.getKey(this._getNormalizedI
tem(idx))]},_focusPhysicalItem:function(idx){if(idx<0||idx>=this._virtualCount){
return}this._restoreFocusedItem();if(!this._isIndexRendered(idx)){this.scrollToI
ndex(idx)}var physicalItem=this._physicalItems[this._getPhysicalIndex(idx)];var
model=physicalItem._templateInstance;var focusable;model.tabIndex=SECRET_TABINDE
X;if(physicalItem.tabIndex===SECRET_TABINDEX){focusable=physicalItem}if(!focusab
le){focusable=Polymer.dom(physicalItem).querySelector('[tabindex="'+SECRET_TABIN
DEX+'"]')}model.tabIndex=0;this._focusedIndex=idx;focusable&&focusable.focus()},
_removeFocusedItem:function(){if(this._offscreenFocusedItem){Polymer.dom(this).r
emoveChild(this._offscreenFocusedItem)}this._offscreenFocusedItem=null;this._foc
usBackfillItem=null;this._focusedItem=null;this._focusedIndex=-1},_createFocusBa
ckfillItem:function(){var pidx,fidx=this._focusedIndex;if(this._offscreenFocused
Item||fidx<0){return}if(!this._focusBackfillItem){var stampedTemplate=this.stamp
(null);this._focusBackfillItem=stampedTemplate.root.querySelector("*");Polymer.d
om(this).appendChild(stampedTemplate.root)}pidx=this._getPhysicalIndex(fidx);if(
pidx!=null){this._offscreenFocusedItem=this._physicalItems[pidx];this._physicalI
tems[pidx]=this._focusBackfillItem;this.translate3d(0,HIDDEN_Y,0,this._offscreen
FocusedItem)}},_restoreFocusedItem:function(){var pidx,fidx=this._focusedIndex;i
f(!this._offscreenFocusedItem||this._focusedIndex<0){return}this._assignModels()
;pidx=this._getPhysicalIndex(fidx);if(pidx!=null){this._focusBackfillItem=this._
physicalItems[pidx];this._physicalItems[pidx]=this._offscreenFocusedItem;this._o
ffscreenFocusedItem=null;this.translate3d(0,HIDDEN_Y,0,this._focusBackfillItem)}
},_didFocus:function(e){var targetModel=this.modelForElement(e.target);var focus
edModel=this._focusedItem?this._focusedItem._templateInstance:null;var hasOffscr
eenFocusedItem=this._offscreenFocusedItem!==null;var fidx=this._focusedIndex;if(
!targetModel||!focusedModel){return}if(focusedModel===targetModel){if(!this._isI
ndexVisible(fidx)){this.scrollToIndex(fidx)}}else{this._restoreFocusedItem();foc
usedModel.tabIndex=-1;targetModel.tabIndex=0;fidx=targetModel[this.indexAs];this
._focusedIndex=fidx;this._focusedItem=this._physicalItems[this._getPhysicalIndex
(fidx)];if(hasOffscreenFocusedItem&&!this._offscreenFocusedItem){this._update()}
}},_didMoveUp:function(){this._focusPhysicalItem(this._focusedIndex-1)},_didMove
Down:function(e){e.detail.keyboardEvent.preventDefault();this._focusPhysicalItem
(this._focusedIndex+1)},_didEnter:function(e){this._focusPhysicalItem(this._focu
sedIndex);this._selectionHandler(e.detail.keyboardEvent)}})})(); |
| 547 var el = document.getElementById(id); | |
| 548 return el ? assertInstanceof(el, Element) : null; | |
| 549 } | |
| 550 | |
| 551 function announceAccessibleMessage(msg) { | |
| 552 var element = document.createElement('div'); | |
| 553 element.setAttribute('aria-live', 'polite'); | |
| 554 element.style.position = 'relative'; | |
| 555 element.style.left = '-9999px'; | |
| 556 element.style.height = '0px'; | |
| 557 element.innerText = msg; | |
| 558 document.body.appendChild(element); | |
| 559 window.setTimeout(function() { | |
| 560 document.body.removeChild(element); | |
| 561 }, 0); | |
| 562 } | |
| 563 | |
| 564 function url(s) { | |
| 565 var s2 = s.replace(/(\(|\)|\,|\s|\'|\"|\\)/g, '\\$1'); | |
| 566 if (/\\\\$/.test(s2)) { | |
| 567 s2 += ' '; | |
| 568 } | |
| 569 return 'url("' + s2 + '")'; | |
| 570 } | |
| 571 | |
| 572 function parseQueryParams(location) { | |
| 573 var params = {}; | |
| 574 var query = unescape(location.search.substring(1)); | |
| 575 var vars = query.split('&'); | |
| 576 for (var i = 0; i < vars.length; i++) { | |
| 577 var pair = vars[i].split('='); | |
| 578 params[pair[0]] = pair[1]; | |
| 579 } | |
| 580 return params; | |
| 581 } | |
| 582 | |
| 583 function setQueryParam(location, key, value) { | |
| 584 var query = parseQueryParams(location); | |
| 585 query[encodeURIComponent(key)] = encodeURIComponent(value); | |
| 586 var newQuery = ''; | |
| 587 for (var q in query) { | |
| 588 newQuery += (newQuery ? '&' : '?') + q + '=' + query[q]; | |
| 589 } | |
| 590 return location.origin + location.pathname + newQuery + location.hash; | |
| 591 } | |
| 592 | |
| 593 function findAncestorByClass(el, className) { | |
| 594 return findAncestor(el, function(el) { | |
| 595 return el.classList && el.classList.contains(className); | |
| 596 }); | |
| 597 } | |
| 598 | |
| 599 function findAncestor(node, predicate) { | |
| 600 var last = false; | |
| 601 while (node != null && !(last = predicate(node))) { | |
| 602 node = node.parentNode; | |
| 603 } | |
| 604 return last ? node : null; | |
| 605 } | |
| 606 | |
| 607 function swapDomNodes(a, b) { | |
| 608 var afterA = a.nextSibling; | |
| 609 if (afterA == b) { | |
| 610 swapDomNodes(b, a); | |
| 611 return; | |
| 612 } | |
| 613 var aParent = a.parentNode; | |
| 614 b.parentNode.replaceChild(a, b); | |
| 615 aParent.insertBefore(b, afterA); | |
| 616 } | |
| 617 | |
| 618 function disableTextSelectAndDrag(opt_allowSelectStart, opt_allowDragStart) { | |
| 619 document.onselectstart = function(e) { | |
| 620 if (!(opt_allowSelectStart && opt_allowSelectStart.call(this, e))) e.prevent
Default(); | |
| 621 }; | |
| 622 document.ondragstart = function(e) { | |
| 623 if (!(opt_allowDragStart && opt_allowDragStart.call(this, e))) e.preventDefa
ult(); | |
| 624 }; | |
| 625 } | |
| 626 | |
| 627 function preventDefaultOnPoundLinkClicks() { | |
| 628 document.addEventListener('click', function(e) { | |
| 629 var anchor = findAncestor(e.target, function(el) { | |
| 630 return el.tagName == 'A'; | |
| 631 }); | |
| 632 if (anchor && anchor.getAttribute('href') == '#') e.preventDefault(); | |
| 633 }); | |
| 634 } | |
| 635 | |
| 636 function isRTL() { | |
| 637 return document.documentElement.dir == 'rtl'; | |
| 638 } | |
| 639 | |
| 640 function getRequiredElement(id) { | |
| 641 return assertInstanceof($(id), HTMLElement, 'Missing required element: ' + id)
; | |
| 642 } | |
| 643 | |
| 644 function queryRequiredElement(selectors, opt_context) { | |
| 645 var element = (opt_context || document).querySelector(selectors); | |
| 646 return assertInstanceof(element, HTMLElement, 'Missing required element: ' + s
electors); | |
| 647 } | |
| 648 | |
| 649 [ 'click', 'auxclick' ].forEach(function(eventName) { | |
| 650 document.addEventListener(eventName, function(e) { | |
| 651 if (e.button > 1) return; | |
| 652 if (e.defaultPrevented) return; | |
| 653 var eventPath = e.path; | |
| 654 var anchor = null; | |
| 655 if (eventPath) { | |
| 656 for (var i = 0; i < eventPath.length; i++) { | |
| 657 var element = eventPath[i]; | |
| 658 if (element.tagName === 'A' && element.href) { | |
| 659 anchor = element; | |
| 660 break; | |
| 661 } | |
| 662 } | |
| 663 } | |
| 664 var el = e.target; | |
| 665 if (!anchor && el.nodeType == Node.ELEMENT_NODE && el.webkitMatchesSelector(
'A, A *')) { | |
| 666 while (el.tagName != 'A') { | |
| 667 el = el.parentElement; | |
| 668 } | |
| 669 anchor = el; | |
| 670 } | |
| 671 if (!anchor) return; | |
| 672 anchor = anchor; | |
| 673 if ((anchor.protocol == 'file:' || anchor.protocol == 'about:') && (e.button
== 0 || e.button == 1)) { | |
| 674 chrome.send('navigateToUrl', [ anchor.href, anchor.target, e.button, e.alt
Key, e.ctrlKey, e.metaKey, e.shiftKey ]); | |
| 675 e.preventDefault(); | |
| 676 } | |
| 677 }); | |
| 678 }); | |
| 679 | |
| 680 function appendParam(url, key, value) { | |
| 681 var param = encodeURIComponent(key) + '=' + encodeURIComponent(value); | |
| 682 if (url.indexOf('?') == -1) return url + '?' + param; | |
| 683 return url + '&' + param; | |
| 684 } | |
| 685 | |
| 686 function createElementWithClassName(type, className) { | |
| 687 var elm = document.createElement(type); | |
| 688 elm.className = className; | |
| 689 return elm; | |
| 690 } | |
| 691 | |
| 692 function ensureTransitionEndEvent(el, opt_timeOut) { | |
| 693 if (opt_timeOut === undefined) { | |
| 694 var style = getComputedStyle(el); | |
| 695 opt_timeOut = parseFloat(style.transitionDuration) * 1e3; | |
| 696 opt_timeOut += 50; | |
| 697 } | |
| 698 var fired = false; | |
| 699 el.addEventListener('webkitTransitionEnd', function f(e) { | |
| 700 el.removeEventListener('webkitTransitionEnd', f); | |
| 701 fired = true; | |
| 702 }); | |
| 703 window.setTimeout(function() { | |
| 704 if (!fired) cr.dispatchSimpleEvent(el, 'webkitTransitionEnd', true); | |
| 705 }, opt_timeOut); | |
| 706 } | |
| 707 | |
| 708 function scrollTopForDocument(doc) { | |
| 709 return doc.documentElement.scrollTop || doc.body.scrollTop; | |
| 710 } | |
| 711 | |
| 712 function setScrollTopForDocument(doc, value) { | |
| 713 doc.documentElement.scrollTop = doc.body.scrollTop = value; | |
| 714 } | |
| 715 | |
| 716 function scrollLeftForDocument(doc) { | |
| 717 return doc.documentElement.scrollLeft || doc.body.scrollLeft; | |
| 718 } | |
| 719 | |
| 720 function setScrollLeftForDocument(doc, value) { | |
| 721 doc.documentElement.scrollLeft = doc.body.scrollLeft = value; | |
| 722 } | |
| 723 | |
| 724 function HTMLEscape(original) { | |
| 725 return original.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '&g
t;').replace(/"/g, '"').replace(/'/g, '''); | |
| 726 } | |
| 727 | |
| 728 function elide(original, maxLength) { | |
| 729 if (original.length <= maxLength) return original; | |
| 730 return original.substring(0, maxLength - 1) + '…'; | |
| 731 } | |
| 732 | |
| 733 function quoteString(str) { | |
| 734 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1'); | |
| 735 } | |
| 736 | |
| 737 function listenOnce(target, eventNames, callback) { | |
| 738 if (!Array.isArray(eventNames)) eventNames = eventNames.split(/ +/); | |
| 739 var removeAllAndCallCallback = function(event) { | |
| 740 eventNames.forEach(function(eventName) { | |
| 741 target.removeEventListener(eventName, removeAllAndCallCallback, false); | |
| 742 }); | |
| 743 return callback(event); | |
| 744 }; | |
| 745 eventNames.forEach(function(eventName) { | |
| 746 target.addEventListener(eventName, removeAllAndCallCallback, false); | |
| 747 }); | |
| 748 } | |
| 749 | |
| 750 // <if expr="is_ios"> | |
| 751 if (!('key' in KeyboardEvent.prototype)) { | |
| 752 Object.defineProperty(KeyboardEvent.prototype, 'key', { | |
| 753 get: function() { | |
| 754 if (this.keyCode >= 48 && this.keyCode <= 57) return String.fromCharCode(t
his.keyCode); | |
| 755 if (this.keyCode >= 65 && this.keyCode <= 90) { | |
| 756 var result = String.fromCharCode(this.keyCode).toLowerCase(); | |
| 757 if (this.shiftKey) result = result.toUpperCase(); | |
| 758 return result; | |
| 759 } | |
| 760 switch (this.keyCode) { | |
| 761 case 8: | |
| 762 return 'Backspace'; | |
| 763 | |
| 764 case 9: | |
| 765 return 'Tab'; | |
| 766 | |
| 767 case 13: | |
| 768 return 'Enter'; | |
| 769 | |
| 770 case 16: | |
| 771 return 'Shift'; | |
| 772 | |
| 773 case 17: | |
| 774 return 'Control'; | |
| 775 | |
| 776 case 18: | |
| 777 return 'Alt'; | |
| 778 | |
| 779 case 27: | |
| 780 return 'Escape'; | |
| 781 | |
| 782 case 32: | |
| 783 return ' '; | |
| 784 | |
| 785 case 33: | |
| 786 return 'PageUp'; | |
| 787 | |
| 788 case 34: | |
| 789 return 'PageDown'; | |
| 790 | |
| 791 case 35: | |
| 792 return 'End'; | |
| 793 | |
| 794 case 36: | |
| 795 return 'Home'; | |
| 796 | |
| 797 case 37: | |
| 798 return 'ArrowLeft'; | |
| 799 | |
| 800 case 38: | |
| 801 return 'ArrowUp'; | |
| 802 | |
| 803 case 39: | |
| 804 return 'ArrowRight'; | |
| 805 | |
| 806 case 40: | |
| 807 return 'ArrowDown'; | |
| 808 | |
| 809 case 45: | |
| 810 return 'Insert'; | |
| 811 | |
| 812 case 46: | |
| 813 return 'Delete'; | |
| 814 | |
| 815 case 91: | |
| 816 return 'Meta'; | |
| 817 | |
| 818 case 112: | |
| 819 return 'F1'; | |
| 820 | |
| 821 case 113: | |
| 822 return 'F2'; | |
| 823 | |
| 824 case 114: | |
| 825 return 'F3'; | |
| 826 | |
| 827 case 115: | |
| 828 return 'F4'; | |
| 829 | |
| 830 case 116: | |
| 831 return 'F5'; | |
| 832 | |
| 833 case 117: | |
| 834 return 'F6'; | |
| 835 | |
| 836 case 118: | |
| 837 return 'F7'; | |
| 838 | |
| 839 case 119: | |
| 840 return 'F8'; | |
| 841 | |
| 842 case 120: | |
| 843 return 'F9'; | |
| 844 | |
| 845 case 121: | |
| 846 return 'F10'; | |
| 847 | |
| 848 case 122: | |
| 849 return 'F11'; | |
| 850 | |
| 851 case 123: | |
| 852 return 'F12'; | |
| 853 | |
| 854 case 187: | |
| 855 return '='; | |
| 856 | |
| 857 case 189: | |
| 858 return '-'; | |
| 859 | |
| 860 case 219: | |
| 861 return '['; | |
| 862 | |
| 863 case 221: | |
| 864 return ']'; | |
| 865 } | |
| 866 return 'Unidentified'; | |
| 867 } | |
| 868 }); | |
| 869 } else { | |
| 870 window.console.log("KeyboardEvent.Key polyfill not required"); | |
| 871 } | |
| 872 | |
| 873 // </if> /* is_ios */ | |
| 874 Polymer.IronResizableBehavior = { | |
| 875 properties: { | |
| 876 _parentResizable: { | |
| 877 type: Object, | |
| 878 observer: '_parentResizableChanged' | |
| 879 }, | |
| 880 _notifyingDescendant: { | |
| 881 type: Boolean, | |
| 882 value: false | |
| 883 } | |
| 884 }, | |
| 885 listeners: { | |
| 886 'iron-request-resize-notifications': '_onIronRequestResizeNotifications' | |
| 887 }, | |
| 888 created: function() { | |
| 889 this._interestedResizables = []; | |
| 890 this._boundNotifyResize = this.notifyResize.bind(this); | |
| 891 }, | |
| 892 attached: function() { | |
| 893 this.fire('iron-request-resize-notifications', null, { | |
| 894 node: this, | |
| 895 bubbles: true, | |
| 896 cancelable: true | |
| 897 }); | |
| 898 if (!this._parentResizable) { | |
| 899 window.addEventListener('resize', this._boundNotifyResize); | |
| 900 this.notifyResize(); | |
| 901 } | |
| 902 }, | |
| 903 detached: function() { | |
| 904 if (this._parentResizable) { | |
| 905 this._parentResizable.stopResizeNotificationsFor(this); | |
| 906 } else { | |
| 907 window.removeEventListener('resize', this._boundNotifyResize); | |
| 908 } | |
| 909 this._parentResizable = null; | |
| 910 }, | |
| 911 notifyResize: function() { | |
| 912 if (!this.isAttached) { | |
| 913 return; | |
| 914 } | |
| 915 this._interestedResizables.forEach(function(resizable) { | |
| 916 if (this.resizerShouldNotify(resizable)) { | |
| 917 this._notifyDescendant(resizable); | |
| 918 } | |
| 919 }, this); | |
| 920 this._fireResize(); | |
| 921 }, | |
| 922 assignParentResizable: function(parentResizable) { | |
| 923 this._parentResizable = parentResizable; | |
| 924 }, | |
| 925 stopResizeNotificationsFor: function(target) { | |
| 926 var index = this._interestedResizables.indexOf(target); | |
| 927 if (index > -1) { | |
| 928 this._interestedResizables.splice(index, 1); | |
| 929 this.unlisten(target, 'iron-resize', '_onDescendantIronResize'); | |
| 930 } | |
| 931 }, | |
| 932 resizerShouldNotify: function(element) { | |
| 933 return true; | |
| 934 }, | |
| 935 _onDescendantIronResize: function(event) { | |
| 936 if (this._notifyingDescendant) { | |
| 937 event.stopPropagation(); | |
| 938 return; | |
| 939 } | |
| 940 if (!Polymer.Settings.useShadow) { | |
| 941 this._fireResize(); | |
| 942 } | |
| 943 }, | |
| 944 _fireResize: function() { | |
| 945 this.fire('iron-resize', null, { | |
| 946 node: this, | |
| 947 bubbles: false | |
| 948 }); | |
| 949 }, | |
| 950 _onIronRequestResizeNotifications: function(event) { | |
| 951 var target = event.path ? event.path[0] : event.target; | |
| 952 if (target === this) { | |
| 953 return; | |
| 954 } | |
| 955 if (this._interestedResizables.indexOf(target) === -1) { | |
| 956 this._interestedResizables.push(target); | |
| 957 this.listen(target, 'iron-resize', '_onDescendantIronResize'); | |
| 958 } | |
| 959 target.assignParentResizable(this); | |
| 960 this._notifyDescendant(target); | |
| 961 event.stopPropagation(); | |
| 962 }, | |
| 963 _parentResizableChanged: function(parentResizable) { | |
| 964 if (parentResizable) { | |
| 965 window.removeEventListener('resize', this._boundNotifyResize); | |
| 966 } | |
| 967 }, | |
| 968 _notifyDescendant: function(descendant) { | |
| 969 if (!this.isAttached) { | |
| 970 return; | |
| 971 } | |
| 972 this._notifyingDescendant = true; | |
| 973 descendant.notifyResize(); | |
| 974 this._notifyingDescendant = false; | |
| 975 } | |
| 976 }; | |
| 977 | |
| 978 (function() { | |
| 979 'use strict'; | |
| 980 var KEY_IDENTIFIER = { | |
| 981 'U+0008': 'backspace', | |
| 982 'U+0009': 'tab', | |
| 983 'U+001B': 'esc', | |
| 984 'U+0020': 'space', | |
| 985 'U+007F': 'del' | |
| 986 }; | |
| 987 var KEY_CODE = { | |
| 988 8: 'backspace', | |
| 989 9: 'tab', | |
| 990 13: 'enter', | |
| 991 27: 'esc', | |
| 992 33: 'pageup', | |
| 993 34: 'pagedown', | |
| 994 35: 'end', | |
| 995 36: 'home', | |
| 996 32: 'space', | |
| 997 37: 'left', | |
| 998 38: 'up', | |
| 999 39: 'right', | |
| 1000 40: 'down', | |
| 1001 46: 'del', | |
| 1002 106: '*' | |
| 1003 }; | |
| 1004 var MODIFIER_KEYS = { | |
| 1005 shift: 'shiftKey', | |
| 1006 ctrl: 'ctrlKey', | |
| 1007 alt: 'altKey', | |
| 1008 meta: 'metaKey' | |
| 1009 }; | |
| 1010 var KEY_CHAR = /[a-z0-9*]/; | |
| 1011 var IDENT_CHAR = /U\+/; | |
| 1012 var ARROW_KEY = /^arrow/; | |
| 1013 var SPACE_KEY = /^space(bar)?/; | |
| 1014 var ESC_KEY = /^escape$/; | |
| 1015 function transformKey(key, noSpecialChars) { | |
| 1016 var validKey = ''; | |
| 1017 if (key) { | |
| 1018 var lKey = key.toLowerCase(); | |
| 1019 if (lKey === ' ' || SPACE_KEY.test(lKey)) { | |
| 1020 validKey = 'space'; | |
| 1021 } else if (ESC_KEY.test(lKey)) { | |
| 1022 validKey = 'esc'; | |
| 1023 } else if (lKey.length == 1) { | |
| 1024 if (!noSpecialChars || KEY_CHAR.test(lKey)) { | |
| 1025 validKey = lKey; | |
| 1026 } | |
| 1027 } else if (ARROW_KEY.test(lKey)) { | |
| 1028 validKey = lKey.replace('arrow', ''); | |
| 1029 } else if (lKey == 'multiply') { | |
| 1030 validKey = '*'; | |
| 1031 } else { | |
| 1032 validKey = lKey; | |
| 1033 } | |
| 1034 } | |
| 1035 return validKey; | |
| 1036 } | |
| 1037 function transformKeyIdentifier(keyIdent) { | |
| 1038 var validKey = ''; | |
| 1039 if (keyIdent) { | |
| 1040 if (keyIdent in KEY_IDENTIFIER) { | |
| 1041 validKey = KEY_IDENTIFIER[keyIdent]; | |
| 1042 } else if (IDENT_CHAR.test(keyIdent)) { | |
| 1043 keyIdent = parseInt(keyIdent.replace('U+', '0x'), 16); | |
| 1044 validKey = String.fromCharCode(keyIdent).toLowerCase(); | |
| 1045 } else { | |
| 1046 validKey = keyIdent.toLowerCase(); | |
| 1047 } | |
| 1048 } | |
| 1049 return validKey; | |
| 1050 } | |
| 1051 function transformKeyCode(keyCode) { | |
| 1052 var validKey = ''; | |
| 1053 if (Number(keyCode)) { | |
| 1054 if (keyCode >= 65 && keyCode <= 90) { | |
| 1055 validKey = String.fromCharCode(32 + keyCode); | |
| 1056 } else if (keyCode >= 112 && keyCode <= 123) { | |
| 1057 validKey = 'f' + (keyCode - 112); | |
| 1058 } else if (keyCode >= 48 && keyCode <= 57) { | |
| 1059 validKey = String(keyCode - 48); | |
| 1060 } else if (keyCode >= 96 && keyCode <= 105) { | |
| 1061 validKey = String(keyCode - 96); | |
| 1062 } else { | |
| 1063 validKey = KEY_CODE[keyCode]; | |
| 1064 } | |
| 1065 } | |
| 1066 return validKey; | |
| 1067 } | |
| 1068 function normalizedKeyForEvent(keyEvent, noSpecialChars) { | |
| 1069 if (keyEvent.key) { | |
| 1070 return transformKey(keyEvent.key, noSpecialChars); | |
| 1071 } | |
| 1072 if (keyEvent.detail && keyEvent.detail.key) { | |
| 1073 return transformKey(keyEvent.detail.key, noSpecialChars); | |
| 1074 } | |
| 1075 return transformKeyIdentifier(keyEvent.keyIdentifier) || transformKeyCode(ke
yEvent.keyCode) || ''; | |
| 1076 } | |
| 1077 function keyComboMatchesEvent(keyCombo, event) { | |
| 1078 var keyEvent = normalizedKeyForEvent(event, keyCombo.hasModifiers); | |
| 1079 return keyEvent === keyCombo.key && (!keyCombo.hasModifiers || !!event.shift
Key === !!keyCombo.shiftKey && !!event.ctrlKey === !!keyCombo.ctrlKey && !!event
.altKey === !!keyCombo.altKey && !!event.metaKey === !!keyCombo.metaKey); | |
| 1080 } | |
| 1081 function parseKeyComboString(keyComboString) { | |
| 1082 if (keyComboString.length === 1) { | |
| 1083 return { | |
| 1084 combo: keyComboString, | |
| 1085 key: keyComboString, | |
| 1086 event: 'keydown' | |
| 1087 }; | |
| 1088 } | |
| 1089 return keyComboString.split('+').reduce(function(parsedKeyCombo, keyComboPar
t) { | |
| 1090 var eventParts = keyComboPart.split(':'); | |
| 1091 var keyName = eventParts[0]; | |
| 1092 var event = eventParts[1]; | |
| 1093 if (keyName in MODIFIER_KEYS) { | |
| 1094 parsedKeyCombo[MODIFIER_KEYS[keyName]] = true; | |
| 1095 parsedKeyCombo.hasModifiers = true; | |
| 1096 } else { | |
| 1097 parsedKeyCombo.key = keyName; | |
| 1098 parsedKeyCombo.event = event || 'keydown'; | |
| 1099 } | |
| 1100 return parsedKeyCombo; | |
| 1101 }, { | |
| 1102 combo: keyComboString.split(':').shift() | |
| 1103 }); | |
| 1104 } | |
| 1105 function parseEventString(eventString) { | |
| 1106 return eventString.trim().split(' ').map(function(keyComboString) { | |
| 1107 return parseKeyComboString(keyComboString); | |
| 1108 }); | |
| 1109 } | |
| 1110 Polymer.IronA11yKeysBehavior = { | |
| 1111 properties: { | |
| 1112 keyEventTarget: { | |
| 1113 type: Object, | |
| 1114 value: function() { | |
| 1115 return this; | |
| 1116 } | |
| 1117 }, | |
| 1118 stopKeyboardEventPropagation: { | |
| 1119 type: Boolean, | |
| 1120 value: false | |
| 1121 }, | |
| 1122 _boundKeyHandlers: { | |
| 1123 type: Array, | |
| 1124 value: function() { | |
| 1125 return []; | |
| 1126 } | |
| 1127 }, | |
| 1128 _imperativeKeyBindings: { | |
| 1129 type: Object, | |
| 1130 value: function() { | |
| 1131 return {}; | |
| 1132 } | |
| 1133 } | |
| 1134 }, | |
| 1135 observers: [ '_resetKeyEventListeners(keyEventTarget, _boundKeyHandlers)' ], | |
| 1136 keyBindings: {}, | |
| 1137 registered: function() { | |
| 1138 this._prepKeyBindings(); | |
| 1139 }, | |
| 1140 attached: function() { | |
| 1141 this._listenKeyEventListeners(); | |
| 1142 }, | |
| 1143 detached: function() { | |
| 1144 this._unlistenKeyEventListeners(); | |
| 1145 }, | |
| 1146 addOwnKeyBinding: function(eventString, handlerName) { | |
| 1147 this._imperativeKeyBindings[eventString] = handlerName; | |
| 1148 this._prepKeyBindings(); | |
| 1149 this._resetKeyEventListeners(); | |
| 1150 }, | |
| 1151 removeOwnKeyBindings: function() { | |
| 1152 this._imperativeKeyBindings = {}; | |
| 1153 this._prepKeyBindings(); | |
| 1154 this._resetKeyEventListeners(); | |
| 1155 }, | |
| 1156 keyboardEventMatchesKeys: function(event, eventString) { | |
| 1157 var keyCombos = parseEventString(eventString); | |
| 1158 for (var i = 0; i < keyCombos.length; ++i) { | |
| 1159 if (keyComboMatchesEvent(keyCombos[i], event)) { | |
| 1160 return true; | |
| 1161 } | |
| 1162 } | |
| 1163 return false; | |
| 1164 }, | |
| 1165 _collectKeyBindings: function() { | |
| 1166 var keyBindings = this.behaviors.map(function(behavior) { | |
| 1167 return behavior.keyBindings; | |
| 1168 }); | |
| 1169 if (keyBindings.indexOf(this.keyBindings) === -1) { | |
| 1170 keyBindings.push(this.keyBindings); | |
| 1171 } | |
| 1172 return keyBindings; | |
| 1173 }, | |
| 1174 _prepKeyBindings: function() { | |
| 1175 this._keyBindings = {}; | |
| 1176 this._collectKeyBindings().forEach(function(keyBindings) { | |
| 1177 for (var eventString in keyBindings) { | |
| 1178 this._addKeyBinding(eventString, keyBindings[eventString]); | |
| 1179 } | |
| 1180 }, this); | |
| 1181 for (var eventString in this._imperativeKeyBindings) { | |
| 1182 this._addKeyBinding(eventString, this._imperativeKeyBindings[eventString
]); | |
| 1183 } | |
| 1184 for (var eventName in this._keyBindings) { | |
| 1185 this._keyBindings[eventName].sort(function(kb1, kb2) { | |
| 1186 var b1 = kb1[0].hasModifiers; | |
| 1187 var b2 = kb2[0].hasModifiers; | |
| 1188 return b1 === b2 ? 0 : b1 ? -1 : 1; | |
| 1189 }); | |
| 1190 } | |
| 1191 }, | |
| 1192 _addKeyBinding: function(eventString, handlerName) { | |
| 1193 parseEventString(eventString).forEach(function(keyCombo) { | |
| 1194 this._keyBindings[keyCombo.event] = this._keyBindings[keyCombo.event] ||
[]; | |
| 1195 this._keyBindings[keyCombo.event].push([ keyCombo, handlerName ]); | |
| 1196 }, this); | |
| 1197 }, | |
| 1198 _resetKeyEventListeners: function() { | |
| 1199 this._unlistenKeyEventListeners(); | |
| 1200 if (this.isAttached) { | |
| 1201 this._listenKeyEventListeners(); | |
| 1202 } | |
| 1203 }, | |
| 1204 _listenKeyEventListeners: function() { | |
| 1205 if (!this.keyEventTarget) { | |
| 1206 return; | |
| 1207 } | |
| 1208 Object.keys(this._keyBindings).forEach(function(eventName) { | |
| 1209 var keyBindings = this._keyBindings[eventName]; | |
| 1210 var boundKeyHandler = this._onKeyBindingEvent.bind(this, keyBindings); | |
| 1211 this._boundKeyHandlers.push([ this.keyEventTarget, eventName, boundKeyHa
ndler ]); | |
| 1212 this.keyEventTarget.addEventListener(eventName, boundKeyHandler); | |
| 1213 }, this); | |
| 1214 }, | |
| 1215 _unlistenKeyEventListeners: function() { | |
| 1216 var keyHandlerTuple; | |
| 1217 var keyEventTarget; | |
| 1218 var eventName; | |
| 1219 var boundKeyHandler; | |
| 1220 while (this._boundKeyHandlers.length) { | |
| 1221 keyHandlerTuple = this._boundKeyHandlers.pop(); | |
| 1222 keyEventTarget = keyHandlerTuple[0]; | |
| 1223 eventName = keyHandlerTuple[1]; | |
| 1224 boundKeyHandler = keyHandlerTuple[2]; | |
| 1225 keyEventTarget.removeEventListener(eventName, boundKeyHandler); | |
| 1226 } | |
| 1227 }, | |
| 1228 _onKeyBindingEvent: function(keyBindings, event) { | |
| 1229 if (this.stopKeyboardEventPropagation) { | |
| 1230 event.stopPropagation(); | |
| 1231 } | |
| 1232 if (event.defaultPrevented) { | |
| 1233 return; | |
| 1234 } | |
| 1235 for (var i = 0; i < keyBindings.length; i++) { | |
| 1236 var keyCombo = keyBindings[i][0]; | |
| 1237 var handlerName = keyBindings[i][1]; | |
| 1238 if (keyComboMatchesEvent(keyCombo, event)) { | |
| 1239 this._triggerKeyHandler(keyCombo, handlerName, event); | |
| 1240 if (event.defaultPrevented) { | |
| 1241 return; | |
| 1242 } | |
| 1243 } | |
| 1244 } | |
| 1245 }, | |
| 1246 _triggerKeyHandler: function(keyCombo, handlerName, keyboardEvent) { | |
| 1247 var detail = Object.create(keyCombo); | |
| 1248 detail.keyboardEvent = keyboardEvent; | |
| 1249 var event = new CustomEvent(keyCombo.event, { | |
| 1250 detail: detail, | |
| 1251 cancelable: true | |
| 1252 }); | |
| 1253 this[handlerName].call(this, event); | |
| 1254 if (event.defaultPrevented) { | |
| 1255 keyboardEvent.preventDefault(); | |
| 1256 } | |
| 1257 } | |
| 1258 }; | |
| 1259 })(); | |
| 1260 | |
| 1261 Polymer.IronScrollTargetBehavior = { | |
| 1262 properties: { | |
| 1263 scrollTarget: { | |
| 1264 type: HTMLElement, | |
| 1265 value: function() { | |
| 1266 return this._defaultScrollTarget; | |
| 1267 } | |
| 1268 } | |
| 1269 }, | |
| 1270 observers: [ '_scrollTargetChanged(scrollTarget, isAttached)' ], | |
| 1271 _scrollTargetChanged: function(scrollTarget, isAttached) { | |
| 1272 var eventTarget; | |
| 1273 if (this._oldScrollTarget) { | |
| 1274 eventTarget = this._oldScrollTarget === this._doc ? window : this._oldScro
llTarget; | |
| 1275 eventTarget.removeEventListener('scroll', this._boundScrollHandler); | |
| 1276 this._oldScrollTarget = null; | |
| 1277 } | |
| 1278 if (!isAttached) { | |
| 1279 return; | |
| 1280 } | |
| 1281 if (scrollTarget === 'document') { | |
| 1282 this.scrollTarget = this._doc; | |
| 1283 } else if (typeof scrollTarget === 'string') { | |
| 1284 this.scrollTarget = this.domHost ? this.domHost.$[scrollTarget] : Polymer.
dom(this.ownerDocument).querySelector('#' + scrollTarget); | |
| 1285 } else if (this._isValidScrollTarget()) { | |
| 1286 eventTarget = scrollTarget === this._doc ? window : scrollTarget; | |
| 1287 this._boundScrollHandler = this._boundScrollHandler || this._scrollHandler
.bind(this); | |
| 1288 this._oldScrollTarget = scrollTarget; | |
| 1289 eventTarget.addEventListener('scroll', this._boundScrollHandler); | |
| 1290 } | |
| 1291 }, | |
| 1292 _scrollHandler: function scrollHandler() {}, | |
| 1293 get _defaultScrollTarget() { | |
| 1294 return this._doc; | |
| 1295 }, | |
| 1296 get _doc() { | |
| 1297 return this.ownerDocument.documentElement; | |
| 1298 }, | |
| 1299 get _scrollTop() { | |
| 1300 if (this._isValidScrollTarget()) { | |
| 1301 return this.scrollTarget === this._doc ? window.pageYOffset : this.scrollT
arget.scrollTop; | |
| 1302 } | |
| 1303 return 0; | |
| 1304 }, | |
| 1305 get _scrollLeft() { | |
| 1306 if (this._isValidScrollTarget()) { | |
| 1307 return this.scrollTarget === this._doc ? window.pageXOffset : this.scrollT
arget.scrollLeft; | |
| 1308 } | |
| 1309 return 0; | |
| 1310 }, | |
| 1311 set _scrollTop(top) { | |
| 1312 if (this.scrollTarget === this._doc) { | |
| 1313 window.scrollTo(window.pageXOffset, top); | |
| 1314 } else if (this._isValidScrollTarget()) { | |
| 1315 this.scrollTarget.scrollTop = top; | |
| 1316 } | |
| 1317 }, | |
| 1318 set _scrollLeft(left) { | |
| 1319 if (this.scrollTarget === this._doc) { | |
| 1320 window.scrollTo(left, window.pageYOffset); | |
| 1321 } else if (this._isValidScrollTarget()) { | |
| 1322 this.scrollTarget.scrollLeft = left; | |
| 1323 } | |
| 1324 }, | |
| 1325 scroll: function(left, top) { | |
| 1326 if (this.scrollTarget === this._doc) { | |
| 1327 window.scrollTo(left, top); | |
| 1328 } else if (this._isValidScrollTarget()) { | |
| 1329 this.scrollTarget.scrollLeft = left; | |
| 1330 this.scrollTarget.scrollTop = top; | |
| 1331 } | |
| 1332 }, | |
| 1333 get _scrollTargetWidth() { | |
| 1334 if (this._isValidScrollTarget()) { | |
| 1335 return this.scrollTarget === this._doc ? window.innerWidth : this.scrollTa
rget.offsetWidth; | |
| 1336 } | |
| 1337 return 0; | |
| 1338 }, | |
| 1339 get _scrollTargetHeight() { | |
| 1340 if (this._isValidScrollTarget()) { | |
| 1341 return this.scrollTarget === this._doc ? window.innerHeight : this.scrollT
arget.offsetHeight; | |
| 1342 } | |
| 1343 return 0; | |
| 1344 }, | |
| 1345 _isValidScrollTarget: function() { | |
| 1346 return this.scrollTarget instanceof HTMLElement; | |
| 1347 } | |
| 1348 }; | |
| 1349 | |
| 1350 (function() { | |
| 1351 var IOS = navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/); | |
| 1352 var IOS_TOUCH_SCROLLING = IOS && IOS[1] >= 8; | |
| 1353 var DEFAULT_PHYSICAL_COUNT = 3; | |
| 1354 var HIDDEN_Y = '-10000px'; | |
| 1355 var DEFAULT_GRID_SIZE = 200; | |
| 1356 var SECRET_TABINDEX = -100; | |
| 1357 Polymer({ | |
| 1358 is: 'iron-list', | |
| 1359 properties: { | |
| 1360 items: { | |
| 1361 type: Array | |
| 1362 }, | |
| 1363 maxPhysicalCount: { | |
| 1364 type: Number, | |
| 1365 value: 500 | |
| 1366 }, | |
| 1367 as: { | |
| 1368 type: String, | |
| 1369 value: 'item' | |
| 1370 }, | |
| 1371 indexAs: { | |
| 1372 type: String, | |
| 1373 value: 'index' | |
| 1374 }, | |
| 1375 selectedAs: { | |
| 1376 type: String, | |
| 1377 value: 'selected' | |
| 1378 }, | |
| 1379 grid: { | |
| 1380 type: Boolean, | |
| 1381 value: false, | |
| 1382 reflectToAttribute: true | |
| 1383 }, | |
| 1384 selectionEnabled: { | |
| 1385 type: Boolean, | |
| 1386 value: false | |
| 1387 }, | |
| 1388 selectedItem: { | |
| 1389 type: Object, | |
| 1390 notify: true | |
| 1391 }, | |
| 1392 selectedItems: { | |
| 1393 type: Object, | |
| 1394 notify: true | |
| 1395 }, | |
| 1396 multiSelection: { | |
| 1397 type: Boolean, | |
| 1398 value: false | |
| 1399 } | |
| 1400 }, | |
| 1401 observers: [ '_itemsChanged(items.*)', '_selectionEnabledChanged(selectionEn
abled)', '_multiSelectionChanged(multiSelection)', '_setOverflow(scrollTarget)'
], | |
| 1402 behaviors: [ Polymer.Templatizer, Polymer.IronResizableBehavior, Polymer.Iro
nA11yKeysBehavior, Polymer.IronScrollTargetBehavior ], | |
| 1403 keyBindings: { | |
| 1404 up: '_didMoveUp', | |
| 1405 down: '_didMoveDown', | |
| 1406 enter: '_didEnter' | |
| 1407 }, | |
| 1408 _ratio: .5, | |
| 1409 _scrollerPaddingTop: 0, | |
| 1410 _scrollPosition: 0, | |
| 1411 _physicalSize: 0, | |
| 1412 _physicalAverage: 0, | |
| 1413 _physicalAverageCount: 0, | |
| 1414 _physicalTop: 0, | |
| 1415 _virtualCount: 0, | |
| 1416 _physicalIndexForKey: null, | |
| 1417 _estScrollHeight: 0, | |
| 1418 _scrollHeight: 0, | |
| 1419 _viewportHeight: 0, | |
| 1420 _viewportWidth: 0, | |
| 1421 _physicalItems: null, | |
| 1422 _physicalSizes: null, | |
| 1423 _firstVisibleIndexVal: null, | |
| 1424 _lastVisibleIndexVal: null, | |
| 1425 _collection: null, | |
| 1426 _maxPages: 3, | |
| 1427 _focusedItem: null, | |
| 1428 _focusedIndex: -1, | |
| 1429 _offscreenFocusedItem: null, | |
| 1430 _focusBackfillItem: null, | |
| 1431 _itemsPerRow: 1, | |
| 1432 _itemWidth: 0, | |
| 1433 _rowHeight: 0, | |
| 1434 _templateCost: 0, | |
| 1435 get _physicalBottom() { | |
| 1436 return this._physicalTop + this._physicalSize; | |
| 1437 }, | |
| 1438 get _scrollBottom() { | |
| 1439 return this._scrollPosition + this._viewportHeight; | |
| 1440 }, | |
| 1441 get _virtualEnd() { | |
| 1442 return this._virtualStart + this._physicalCount - 1; | |
| 1443 }, | |
| 1444 get _hiddenContentSize() { | |
| 1445 var size = this.grid ? this._physicalRows * this._rowHeight : this._physic
alSize; | |
| 1446 return size - this._viewportHeight; | |
| 1447 }, | |
| 1448 get _maxScrollTop() { | |
| 1449 return this._estScrollHeight - this._viewportHeight + this._scrollerPaddin
gTop; | |
| 1450 }, | |
| 1451 _minVirtualStart: 0, | |
| 1452 get _maxVirtualStart() { | |
| 1453 return Math.max(0, this._virtualCount - this._physicalCount); | |
| 1454 }, | |
| 1455 _virtualStartVal: 0, | |
| 1456 set _virtualStart(val) { | |
| 1457 this._virtualStartVal = Math.min(this._maxVirtualStart, Math.max(this._min
VirtualStart, val)); | |
| 1458 }, | |
| 1459 get _virtualStart() { | |
| 1460 return this._virtualStartVal || 0; | |
| 1461 }, | |
| 1462 _physicalStartVal: 0, | |
| 1463 set _physicalStart(val) { | |
| 1464 this._physicalStartVal = val % this._physicalCount; | |
| 1465 if (this._physicalStartVal < 0) { | |
| 1466 this._physicalStartVal = this._physicalCount + this._physicalStartVal; | |
| 1467 } | |
| 1468 this._physicalEnd = (this._physicalStart + this._physicalCount - 1) % this
._physicalCount; | |
| 1469 }, | |
| 1470 get _physicalStart() { | |
| 1471 return this._physicalStartVal || 0; | |
| 1472 }, | |
| 1473 _physicalCountVal: 0, | |
| 1474 set _physicalCount(val) { | |
| 1475 this._physicalCountVal = val; | |
| 1476 this._physicalEnd = (this._physicalStart + this._physicalCount - 1) % this
._physicalCount; | |
| 1477 }, | |
| 1478 get _physicalCount() { | |
| 1479 return this._physicalCountVal; | |
| 1480 }, | |
| 1481 _physicalEnd: 0, | |
| 1482 get _optPhysicalSize() { | |
| 1483 if (this.grid) { | |
| 1484 return this._estRowsInView * this._rowHeight * this._maxPages; | |
| 1485 } | |
| 1486 return this._viewportHeight * this._maxPages; | |
| 1487 }, | |
| 1488 get _optPhysicalCount() { | |
| 1489 return this._estRowsInView * this._itemsPerRow * this._maxPages; | |
| 1490 }, | |
| 1491 get _isVisible() { | |
| 1492 return Boolean(this.offsetWidth || this.offsetHeight); | |
| 1493 }, | |
| 1494 get firstVisibleIndex() { | |
| 1495 if (this._firstVisibleIndexVal === null) { | |
| 1496 var physicalOffset = Math.floor(this._physicalTop + this._scrollerPaddin
gTop); | |
| 1497 this._firstVisibleIndexVal = this._iterateItems(function(pidx, vidx) { | |
| 1498 physicalOffset += this._getPhysicalSizeIncrement(pidx); | |
| 1499 if (physicalOffset > this._scrollPosition) { | |
| 1500 return this.grid ? vidx - vidx % this._itemsPerRow : vidx; | |
| 1501 } | |
| 1502 if (this.grid && this._virtualCount - 1 === vidx) { | |
| 1503 return vidx - vidx % this._itemsPerRow; | |
| 1504 } | |
| 1505 }) || 0; | |
| 1506 } | |
| 1507 return this._firstVisibleIndexVal; | |
| 1508 }, | |
| 1509 get lastVisibleIndex() { | |
| 1510 if (this._lastVisibleIndexVal === null) { | |
| 1511 if (this.grid) { | |
| 1512 var lastIndex = this.firstVisibleIndex + this._estRowsInView * this._i
temsPerRow - 1; | |
| 1513 this._lastVisibleIndexVal = Math.min(this._virtualCount, lastIndex); | |
| 1514 } else { | |
| 1515 var physicalOffset = this._physicalTop; | |
| 1516 this._iterateItems(function(pidx, vidx) { | |
| 1517 if (physicalOffset < this._scrollBottom) { | |
| 1518 this._lastVisibleIndexVal = vidx; | |
| 1519 } else { | |
| 1520 return true; | |
| 1521 } | |
| 1522 physicalOffset += this._getPhysicalSizeIncrement(pidx); | |
| 1523 }); | |
| 1524 } | |
| 1525 } | |
| 1526 return this._lastVisibleIndexVal; | |
| 1527 }, | |
| 1528 get _defaultScrollTarget() { | |
| 1529 return this; | |
| 1530 }, | |
| 1531 get _virtualRowCount() { | |
| 1532 return Math.ceil(this._virtualCount / this._itemsPerRow); | |
| 1533 }, | |
| 1534 get _estRowsInView() { | |
| 1535 return Math.ceil(this._viewportHeight / this._rowHeight); | |
| 1536 }, | |
| 1537 get _physicalRows() { | |
| 1538 return Math.ceil(this._physicalCount / this._itemsPerRow); | |
| 1539 }, | |
| 1540 ready: function() { | |
| 1541 this.addEventListener('focus', this._didFocus.bind(this), true); | |
| 1542 }, | |
| 1543 attached: function() { | |
| 1544 this.updateViewportBoundaries(); | |
| 1545 if (this._physicalCount === 0) { | |
| 1546 this._debounceTemplate(this._render); | |
| 1547 } | |
| 1548 this.listen(this, 'iron-resize', '_resizeHandler'); | |
| 1549 }, | |
| 1550 detached: function() { | |
| 1551 this.unlisten(this, 'iron-resize', '_resizeHandler'); | |
| 1552 }, | |
| 1553 _setOverflow: function(scrollTarget) { | |
| 1554 this.style.webkitOverflowScrolling = scrollTarget === this ? 'touch' : ''; | |
| 1555 this.style.overflow = scrollTarget === this ? 'auto' : ''; | |
| 1556 }, | |
| 1557 updateViewportBoundaries: function() { | |
| 1558 this._scrollerPaddingTop = this.scrollTarget === this ? 0 : parseInt(windo
w.getComputedStyle(this)['padding-top'], 10); | |
| 1559 this._viewportHeight = this._scrollTargetHeight; | |
| 1560 if (this.grid) { | |
| 1561 this._updateGridMetrics(); | |
| 1562 } | |
| 1563 }, | |
| 1564 _scrollHandler: function() { | |
| 1565 var scrollTop = Math.max(0, Math.min(this._maxScrollTop, this._scrollTop))
; | |
| 1566 var delta = scrollTop - this._scrollPosition; | |
| 1567 var tileHeight, tileTop, kth, recycledTileSet, scrollBottom, physicalBotto
m; | |
| 1568 var ratio = this._ratio; | |
| 1569 var recycledTiles = 0; | |
| 1570 var hiddenContentSize = this._hiddenContentSize; | |
| 1571 var currentRatio = ratio; | |
| 1572 var movingUp = []; | |
| 1573 this._scrollPosition = scrollTop; | |
| 1574 this._firstVisibleIndexVal = null; | |
| 1575 this._lastVisibleIndexVal = null; | |
| 1576 scrollBottom = this._scrollBottom; | |
| 1577 physicalBottom = this._physicalBottom; | |
| 1578 if (Math.abs(delta) > this._physicalSize) { | |
| 1579 this._physicalTop += delta; | |
| 1580 recycledTiles = Math.round(delta / this._physicalAverage); | |
| 1581 } else if (delta < 0) { | |
| 1582 var topSpace = scrollTop - this._physicalTop; | |
| 1583 var virtualStart = this._virtualStart; | |
| 1584 recycledTileSet = []; | |
| 1585 kth = this._physicalEnd; | |
| 1586 currentRatio = topSpace / hiddenContentSize; | |
| 1587 while (currentRatio < ratio && recycledTiles < this._physicalCount && vi
rtualStart - recycledTiles > 0 && physicalBottom - this._getPhysicalSizeIncremen
t(kth) > scrollBottom) { | |
| 1588 tileHeight = this._getPhysicalSizeIncrement(kth); | |
| 1589 currentRatio += tileHeight / hiddenContentSize; | |
| 1590 physicalBottom -= tileHeight; | |
| 1591 recycledTileSet.push(kth); | |
| 1592 recycledTiles++; | |
| 1593 kth = kth === 0 ? this._physicalCount - 1 : kth - 1; | |
| 1594 } | |
| 1595 movingUp = recycledTileSet; | |
| 1596 recycledTiles = -recycledTiles; | |
| 1597 } else if (delta > 0) { | |
| 1598 var bottomSpace = physicalBottom - scrollBottom; | |
| 1599 var virtualEnd = this._virtualEnd; | |
| 1600 var lastVirtualItemIndex = this._virtualCount - 1; | |
| 1601 recycledTileSet = []; | |
| 1602 kth = this._physicalStart; | |
| 1603 currentRatio = bottomSpace / hiddenContentSize; | |
| 1604 while (currentRatio < ratio && recycledTiles < this._physicalCount && vi
rtualEnd + recycledTiles < lastVirtualItemIndex && this._physicalTop + this._get
PhysicalSizeIncrement(kth) < scrollTop) { | |
| 1605 tileHeight = this._getPhysicalSizeIncrement(kth); | |
| 1606 currentRatio += tileHeight / hiddenContentSize; | |
| 1607 this._physicalTop += tileHeight; | |
| 1608 recycledTileSet.push(kth); | |
| 1609 recycledTiles++; | |
| 1610 kth = (kth + 1) % this._physicalCount; | |
| 1611 } | |
| 1612 } | |
| 1613 if (recycledTiles === 0) { | |
| 1614 if (physicalBottom < scrollBottom || this._physicalTop > scrollTop) { | |
| 1615 this._increasePoolIfNeeded(); | |
| 1616 } | |
| 1617 } else { | |
| 1618 this._virtualStart = this._virtualStart + recycledTiles; | |
| 1619 this._physicalStart = this._physicalStart + recycledTiles; | |
| 1620 this._update(recycledTileSet, movingUp); | |
| 1621 } | |
| 1622 }, | |
| 1623 _update: function(itemSet, movingUp) { | |
| 1624 this._manageFocus(); | |
| 1625 this._assignModels(itemSet); | |
| 1626 this._updateMetrics(itemSet); | |
| 1627 if (movingUp) { | |
| 1628 while (movingUp.length) { | |
| 1629 var idx = movingUp.pop(); | |
| 1630 this._physicalTop -= this._getPhysicalSizeIncrement(idx); | |
| 1631 } | |
| 1632 } | |
| 1633 this._positionItems(); | |
| 1634 this._updateScrollerSize(); | |
| 1635 this._increasePoolIfNeeded(); | |
| 1636 }, | |
| 1637 _createPool: function(size) { | |
| 1638 var physicalItems = new Array(size); | |
| 1639 this._ensureTemplatized(); | |
| 1640 for (var i = 0; i < size; i++) { | |
| 1641 var inst = this.stamp(null); | |
| 1642 physicalItems[i] = inst.root.querySelector('*'); | |
| 1643 Polymer.dom(this).appendChild(inst.root); | |
| 1644 } | |
| 1645 return physicalItems; | |
| 1646 }, | |
| 1647 _increasePoolIfNeeded: function() { | |
| 1648 if (this._viewportHeight === 0) { | |
| 1649 return false; | |
| 1650 } | |
| 1651 var self = this; | |
| 1652 var isClientFull = this._physicalBottom >= this._scrollBottom && this._phy
sicalTop <= this._scrollPosition; | |
| 1653 if (this._physicalSize >= this._optPhysicalSize && isClientFull) { | |
| 1654 return false; | |
| 1655 } | |
| 1656 var maxPoolSize = Math.round(this._physicalCount * .5); | |
| 1657 if (!isClientFull) { | |
| 1658 this._debounceTemplate(this._increasePool.bind(this, maxPoolSize)); | |
| 1659 return true; | |
| 1660 } | |
| 1661 this._yield(function() { | |
| 1662 self._increasePool(Math.min(maxPoolSize, Math.max(1, Math.round(50 / sel
f._templateCost)))); | |
| 1663 }); | |
| 1664 return true; | |
| 1665 }, | |
| 1666 _yield: function(cb) { | |
| 1667 var g = window; | |
| 1668 var handle = g.requestIdleCallback ? g.requestIdleCallback(cb) : g.setTime
out(cb, 16); | |
| 1669 Polymer.dom.addDebouncer({ | |
| 1670 complete: function() { | |
| 1671 g.cancelIdleCallback ? g.cancelIdleCallback(handle) : g.clearTimeout(h
andle); | |
| 1672 cb(); | |
| 1673 } | |
| 1674 }); | |
| 1675 }, | |
| 1676 _increasePool: function(missingItems) { | |
| 1677 var nextPhysicalCount = Math.min(this._physicalCount + missingItems, this.
_virtualCount - this._virtualStart, Math.max(this.maxPhysicalCount, DEFAULT_PHYS
ICAL_COUNT)); | |
| 1678 var prevPhysicalCount = this._physicalCount; | |
| 1679 var delta = nextPhysicalCount - prevPhysicalCount; | |
| 1680 var ts = window.performance.now(); | |
| 1681 if (delta <= 0) { | |
| 1682 return; | |
| 1683 } | |
| 1684 [].push.apply(this._physicalItems, this._createPool(delta)); | |
| 1685 [].push.apply(this._physicalSizes, new Array(delta)); | |
| 1686 this._physicalCount = prevPhysicalCount + delta; | |
| 1687 if (this._physicalStart > this._physicalEnd && this._isIndexRendered(this.
_focusedIndex) && this._getPhysicalIndex(this._focusedIndex) < this._physicalEnd
) { | |
| 1688 this._physicalStart = this._physicalStart + delta; | |
| 1689 } | |
| 1690 this._update(); | |
| 1691 this._templateCost = (window.performance.now() - ts) / delta; | |
| 1692 }, | |
| 1693 _render: function() { | |
| 1694 if (this.isAttached && this._isVisible) { | |
| 1695 if (this._physicalCount === 0) { | |
| 1696 this._increasePool(DEFAULT_PHYSICAL_COUNT); | |
| 1697 } else { | |
| 1698 this._update(); | |
| 1699 } | |
| 1700 } | |
| 1701 }, | |
| 1702 _ensureTemplatized: function() { | |
| 1703 if (!this.ctor) { | |
| 1704 var props = {}; | |
| 1705 props.__key__ = true; | |
| 1706 props[this.as] = true; | |
| 1707 props[this.indexAs] = true; | |
| 1708 props[this.selectedAs] = true; | |
| 1709 props.tabIndex = true; | |
| 1710 this._instanceProps = props; | |
| 1711 this._userTemplate = Polymer.dom(this).querySelector('template'); | |
| 1712 if (this._userTemplate) { | |
| 1713 this.templatize(this._userTemplate); | |
| 1714 } else { | |
| 1715 console.warn('iron-list requires a template to be provided in light-do
m'); | |
| 1716 } | |
| 1717 } | |
| 1718 }, | |
| 1719 _getStampedChildren: function() { | |
| 1720 return this._physicalItems; | |
| 1721 }, | |
| 1722 _forwardInstancePath: function(inst, path, value) { | |
| 1723 if (path.indexOf(this.as + '.') === 0) { | |
| 1724 this.notifyPath('items.' + inst.__key__ + '.' + path.slice(this.as.lengt
h + 1), value); | |
| 1725 } | |
| 1726 }, | |
| 1727 _forwardParentProp: function(prop, value) { | |
| 1728 if (this._physicalItems) { | |
| 1729 this._physicalItems.forEach(function(item) { | |
| 1730 item._templateInstance[prop] = value; | |
| 1731 }, this); | |
| 1732 } | |
| 1733 }, | |
| 1734 _forwardParentPath: function(path, value) { | |
| 1735 if (this._physicalItems) { | |
| 1736 this._physicalItems.forEach(function(item) { | |
| 1737 item._templateInstance.notifyPath(path, value, true); | |
| 1738 }, this); | |
| 1739 } | |
| 1740 }, | |
| 1741 _forwardItemPath: function(path, value) { | |
| 1742 if (!this._physicalIndexForKey) { | |
| 1743 return; | |
| 1744 } | |
| 1745 var dot = path.indexOf('.'); | |
| 1746 var key = path.substring(0, dot < 0 ? path.length : dot); | |
| 1747 var idx = this._physicalIndexForKey[key]; | |
| 1748 var offscreenItem = this._offscreenFocusedItem; | |
| 1749 var el = offscreenItem && offscreenItem._templateInstance.__key__ === key
? offscreenItem : this._physicalItems[idx]; | |
| 1750 if (!el || el._templateInstance.__key__ !== key) { | |
| 1751 return; | |
| 1752 } | |
| 1753 if (dot >= 0) { | |
| 1754 path = this.as + '.' + path.substring(dot + 1); | |
| 1755 el._templateInstance.notifyPath(path, value, true); | |
| 1756 } else { | |
| 1757 var currentItem = el._templateInstance[this.as]; | |
| 1758 if (Array.isArray(this.selectedItems)) { | |
| 1759 for (var i = 0; i < this.selectedItems.length; i++) { | |
| 1760 if (this.selectedItems[i] === currentItem) { | |
| 1761 this.set('selectedItems.' + i, value); | |
| 1762 break; | |
| 1763 } | |
| 1764 } | |
| 1765 } else if (this.selectedItem === currentItem) { | |
| 1766 this.set('selectedItem', value); | |
| 1767 } | |
| 1768 el._templateInstance[this.as] = value; | |
| 1769 } | |
| 1770 }, | |
| 1771 _itemsChanged: function(change) { | |
| 1772 if (change.path === 'items') { | |
| 1773 this._virtualStart = 0; | |
| 1774 this._physicalTop = 0; | |
| 1775 this._virtualCount = this.items ? this.items.length : 0; | |
| 1776 this._collection = this.items ? Polymer.Collection.get(this.items) : nul
l; | |
| 1777 this._physicalIndexForKey = {}; | |
| 1778 this._firstVisibleIndexVal = null; | |
| 1779 this._lastVisibleIndexVal = null; | |
| 1780 this._physicalCount = this._physicalCount || 0; | |
| 1781 this._physicalItems = this._physicalItems || []; | |
| 1782 this._physicalSizes = this._physicalSizes || []; | |
| 1783 this._physicalStart = 0; | |
| 1784 this._resetScrollPosition(0); | |
| 1785 this._removeFocusedItem(); | |
| 1786 this._debounceTemplate(this._render); | |
| 1787 } else if (change.path === 'items.splices') { | |
| 1788 this._adjustVirtualIndex(change.value.indexSplices); | |
| 1789 this._virtualCount = this.items ? this.items.length : 0; | |
| 1790 this._debounceTemplate(this._render); | |
| 1791 } else { | |
| 1792 this._forwardItemPath(change.path.split('.').slice(1).join('.'), change.
value); | |
| 1793 } | |
| 1794 }, | |
| 1795 _adjustVirtualIndex: function(splices) { | |
| 1796 splices.forEach(function(splice) { | |
| 1797 splice.removed.forEach(this._removeItem, this); | |
| 1798 if (splice.index < this._virtualStart) { | |
| 1799 var delta = Math.max(splice.addedCount - splice.removed.length, splice
.index - this._virtualStart); | |
| 1800 this._virtualStart = this._virtualStart + delta; | |
| 1801 if (this._focusedIndex >= 0) { | |
| 1802 this._focusedIndex = this._focusedIndex + delta; | |
| 1803 } | |
| 1804 } | |
| 1805 }, this); | |
| 1806 }, | |
| 1807 _removeItem: function(item) { | |
| 1808 this.$.selector.deselect(item); | |
| 1809 if (this._focusedItem && this._focusedItem._templateInstance[this.as] ===
item) { | |
| 1810 this._removeFocusedItem(); | |
| 1811 } | |
| 1812 }, | |
| 1813 _iterateItems: function(fn, itemSet) { | |
| 1814 var pidx, vidx, rtn, i; | |
| 1815 if (arguments.length === 2 && itemSet) { | |
| 1816 for (i = 0; i < itemSet.length; i++) { | |
| 1817 pidx = itemSet[i]; | |
| 1818 vidx = this._computeVidx(pidx); | |
| 1819 if ((rtn = fn.call(this, pidx, vidx)) != null) { | |
| 1820 return rtn; | |
| 1821 } | |
| 1822 } | |
| 1823 } else { | |
| 1824 pidx = this._physicalStart; | |
| 1825 vidx = this._virtualStart; | |
| 1826 for (;pidx < this._physicalCount; pidx++, vidx++) { | |
| 1827 if ((rtn = fn.call(this, pidx, vidx)) != null) { | |
| 1828 return rtn; | |
| 1829 } | |
| 1830 } | |
| 1831 for (pidx = 0; pidx < this._physicalStart; pidx++, vidx++) { | |
| 1832 if ((rtn = fn.call(this, pidx, vidx)) != null) { | |
| 1833 return rtn; | |
| 1834 } | |
| 1835 } | |
| 1836 } | |
| 1837 }, | |
| 1838 _computeVidx: function(pidx) { | |
| 1839 if (pidx >= this._physicalStart) { | |
| 1840 return this._virtualStart + (pidx - this._physicalStart); | |
| 1841 } | |
| 1842 return this._virtualStart + (this._physicalCount - this._physicalStart) +
pidx; | |
| 1843 }, | |
| 1844 _assignModels: function(itemSet) { | |
| 1845 this._iterateItems(function(pidx, vidx) { | |
| 1846 var el = this._physicalItems[pidx]; | |
| 1847 var inst = el._templateInstance; | |
| 1848 var item = this.items && this.items[vidx]; | |
| 1849 if (item != null) { | |
| 1850 inst[this.as] = item; | |
| 1851 inst.__key__ = this._collection.getKey(item); | |
| 1852 inst[this.selectedAs] = this.$.selector.isSelected(item); | |
| 1853 inst[this.indexAs] = vidx; | |
| 1854 inst.tabIndex = this._focusedIndex === vidx ? 0 : -1; | |
| 1855 this._physicalIndexForKey[inst.__key__] = pidx; | |
| 1856 el.removeAttribute('hidden'); | |
| 1857 } else { | |
| 1858 inst.__key__ = null; | |
| 1859 el.setAttribute('hidden', ''); | |
| 1860 } | |
| 1861 }, itemSet); | |
| 1862 }, | |
| 1863 _updateMetrics: function(itemSet) { | |
| 1864 Polymer.dom.flush(); | |
| 1865 var newPhysicalSize = 0; | |
| 1866 var oldPhysicalSize = 0; | |
| 1867 var prevAvgCount = this._physicalAverageCount; | |
| 1868 var prevPhysicalAvg = this._physicalAverage; | |
| 1869 this._iterateItems(function(pidx, vidx) { | |
| 1870 oldPhysicalSize += this._physicalSizes[pidx] || 0; | |
| 1871 this._physicalSizes[pidx] = this._physicalItems[pidx].offsetHeight; | |
| 1872 newPhysicalSize += this._physicalSizes[pidx]; | |
| 1873 this._physicalAverageCount += this._physicalSizes[pidx] ? 1 : 0; | |
| 1874 }, itemSet); | |
| 1875 this._viewportHeight = this._scrollTargetHeight; | |
| 1876 if (this.grid) { | |
| 1877 this._updateGridMetrics(); | |
| 1878 this._physicalSize = Math.ceil(this._physicalCount / this._itemsPerRow)
* this._rowHeight; | |
| 1879 } else { | |
| 1880 this._physicalSize = this._physicalSize + newPhysicalSize - oldPhysicalS
ize; | |
| 1881 } | |
| 1882 if (this._physicalAverageCount !== prevAvgCount) { | |
| 1883 this._physicalAverage = Math.round((prevPhysicalAvg * prevAvgCount + new
PhysicalSize) / this._physicalAverageCount); | |
| 1884 } | |
| 1885 }, | |
| 1886 _updateGridMetrics: function() { | |
| 1887 this._viewportWidth = this.$.items.offsetWidth; | |
| 1888 this._itemWidth = this._physicalCount > 0 ? this._physicalItems[0].getBoun
dingClientRect().width : DEFAULT_GRID_SIZE; | |
| 1889 this._rowHeight = this._physicalCount > 0 ? this._physicalItems[0].offsetH
eight : DEFAULT_GRID_SIZE; | |
| 1890 this._itemsPerRow = this._itemWidth ? Math.floor(this._viewportWidth / thi
s._itemWidth) : this._itemsPerRow; | |
| 1891 }, | |
| 1892 _positionItems: function() { | |
| 1893 this._adjustScrollPosition(); | |
| 1894 var y = this._physicalTop; | |
| 1895 if (this.grid) { | |
| 1896 var totalItemWidth = this._itemsPerRow * this._itemWidth; | |
| 1897 var rowOffset = (this._viewportWidth - totalItemWidth) / 2; | |
| 1898 this._iterateItems(function(pidx, vidx) { | |
| 1899 var modulus = vidx % this._itemsPerRow; | |
| 1900 var x = Math.floor(modulus * this._itemWidth + rowOffset); | |
| 1901 this.translate3d(x + 'px', y + 'px', 0, this._physicalItems[pidx]); | |
| 1902 if (this._shouldRenderNextRow(vidx)) { | |
| 1903 y += this._rowHeight; | |
| 1904 } | |
| 1905 }); | |
| 1906 } else { | |
| 1907 this._iterateItems(function(pidx, vidx) { | |
| 1908 this.translate3d(0, y + 'px', 0, this._physicalItems[pidx]); | |
| 1909 y += this._physicalSizes[pidx]; | |
| 1910 }); | |
| 1911 } | |
| 1912 }, | |
| 1913 _getPhysicalSizeIncrement: function(pidx) { | |
| 1914 if (!this.grid) { | |
| 1915 return this._physicalSizes[pidx]; | |
| 1916 } | |
| 1917 if (this._computeVidx(pidx) % this._itemsPerRow !== this._itemsPerRow - 1)
{ | |
| 1918 return 0; | |
| 1919 } | |
| 1920 return this._rowHeight; | |
| 1921 }, | |
| 1922 _shouldRenderNextRow: function(vidx) { | |
| 1923 return vidx % this._itemsPerRow === this._itemsPerRow - 1; | |
| 1924 }, | |
| 1925 _adjustScrollPosition: function() { | |
| 1926 var deltaHeight = this._virtualStart === 0 ? this._physicalTop : Math.min(
this._scrollPosition + this._physicalTop, 0); | |
| 1927 if (deltaHeight) { | |
| 1928 this._physicalTop = this._physicalTop - deltaHeight; | |
| 1929 if (!IOS_TOUCH_SCROLLING && this._physicalTop !== 0) { | |
| 1930 this._resetScrollPosition(this._scrollTop - deltaHeight); | |
| 1931 } | |
| 1932 } | |
| 1933 }, | |
| 1934 _resetScrollPosition: function(pos) { | |
| 1935 if (this.scrollTarget) { | |
| 1936 this._scrollTop = pos; | |
| 1937 this._scrollPosition = this._scrollTop; | |
| 1938 } | |
| 1939 }, | |
| 1940 _updateScrollerSize: function(forceUpdate) { | |
| 1941 if (this.grid) { | |
| 1942 this._estScrollHeight = this._virtualRowCount * this._rowHeight; | |
| 1943 } else { | |
| 1944 this._estScrollHeight = this._physicalBottom + Math.max(this._virtualCou
nt - this._physicalCount - this._virtualStart, 0) * this._physicalAverage; | |
| 1945 } | |
| 1946 forceUpdate = forceUpdate || this._scrollHeight === 0; | |
| 1947 forceUpdate = forceUpdate || this._scrollPosition >= this._estScrollHeight
- this._physicalSize; | |
| 1948 forceUpdate = forceUpdate || this.grid && this.$.items.style.height < this
._estScrollHeight; | |
| 1949 if (forceUpdate || Math.abs(this._estScrollHeight - this._scrollHeight) >=
this._optPhysicalSize) { | |
| 1950 this.$.items.style.height = this._estScrollHeight + 'px'; | |
| 1951 this._scrollHeight = this._estScrollHeight; | |
| 1952 } | |
| 1953 }, | |
| 1954 scrollToItem: function(item) { | |
| 1955 return this.scrollToIndex(this.items.indexOf(item)); | |
| 1956 }, | |
| 1957 scrollToIndex: function(idx) { | |
| 1958 if (typeof idx !== 'number' || idx < 0 || idx > this.items.length - 1) { | |
| 1959 return; | |
| 1960 } | |
| 1961 Polymer.dom.flush(); | |
| 1962 if (this._physicalCount === 0) { | |
| 1963 return; | |
| 1964 } | |
| 1965 idx = Math.min(Math.max(idx, 0), this._virtualCount - 1); | |
| 1966 if (!this._isIndexRendered(idx) || idx >= this._maxVirtualStart) { | |
| 1967 this._virtualStart = this.grid ? idx - this._itemsPerRow * 2 : idx - 1; | |
| 1968 } | |
| 1969 this._manageFocus(); | |
| 1970 this._assignModels(); | |
| 1971 this._updateMetrics(); | |
| 1972 this._physicalTop = Math.floor(this._virtualStart / this._itemsPerRow) * t
his._physicalAverage; | |
| 1973 var currentTopItem = this._physicalStart; | |
| 1974 var currentVirtualItem = this._virtualStart; | |
| 1975 var targetOffsetTop = 0; | |
| 1976 var hiddenContentSize = this._hiddenContentSize; | |
| 1977 while (currentVirtualItem < idx && targetOffsetTop <= hiddenContentSize) { | |
| 1978 targetOffsetTop = targetOffsetTop + this._getPhysicalSizeIncrement(curre
ntTopItem); | |
| 1979 currentTopItem = (currentTopItem + 1) % this._physicalCount; | |
| 1980 currentVirtualItem++; | |
| 1981 } | |
| 1982 this._updateScrollerSize(true); | |
| 1983 this._positionItems(); | |
| 1984 this._resetScrollPosition(this._physicalTop + this._scrollerPaddingTop + t
argetOffsetTop); | |
| 1985 this._increasePoolIfNeeded(); | |
| 1986 this._firstVisibleIndexVal = null; | |
| 1987 this._lastVisibleIndexVal = null; | |
| 1988 }, | |
| 1989 _resetAverage: function() { | |
| 1990 this._physicalAverage = 0; | |
| 1991 this._physicalAverageCount = 0; | |
| 1992 }, | |
| 1993 _resizeHandler: function() { | |
| 1994 if (IOS && Math.abs(this._viewportHeight - this._scrollTargetHeight) < 100
) { | |
| 1995 return; | |
| 1996 } | |
| 1997 Polymer.dom.addDebouncer(this.debounce('_debounceTemplate', function() { | |
| 1998 this.updateViewportBoundaries(); | |
| 1999 this._render(); | |
| 2000 if (this._physicalCount > 0 && this._isVisible) { | |
| 2001 this._resetAverage(); | |
| 2002 this.scrollToIndex(this.firstVisibleIndex); | |
| 2003 } | |
| 2004 }.bind(this), 1)); | |
| 2005 }, | |
| 2006 _getModelFromItem: function(item) { | |
| 2007 var key = this._collection.getKey(item); | |
| 2008 var pidx = this._physicalIndexForKey[key]; | |
| 2009 if (pidx != null) { | |
| 2010 return this._physicalItems[pidx]._templateInstance; | |
| 2011 } | |
| 2012 return null; | |
| 2013 }, | |
| 2014 _getNormalizedItem: function(item) { | |
| 2015 if (this._collection.getKey(item) === undefined) { | |
| 2016 if (typeof item === 'number') { | |
| 2017 item = this.items[item]; | |
| 2018 if (!item) { | |
| 2019 throw new RangeError('<item> not found'); | |
| 2020 } | |
| 2021 return item; | |
| 2022 } | |
| 2023 throw new TypeError('<item> should be a valid item'); | |
| 2024 } | |
| 2025 return item; | |
| 2026 }, | |
| 2027 selectItem: function(item) { | |
| 2028 item = this._getNormalizedItem(item); | |
| 2029 var model = this._getModelFromItem(item); | |
| 2030 if (!this.multiSelection && this.selectedItem) { | |
| 2031 this.deselectItem(this.selectedItem); | |
| 2032 } | |
| 2033 if (model) { | |
| 2034 model[this.selectedAs] = true; | |
| 2035 } | |
| 2036 this.$.selector.select(item); | |
| 2037 this.updateSizeForItem(item); | |
| 2038 }, | |
| 2039 deselectItem: function(item) { | |
| 2040 item = this._getNormalizedItem(item); | |
| 2041 var model = this._getModelFromItem(item); | |
| 2042 if (model) { | |
| 2043 model[this.selectedAs] = false; | |
| 2044 } | |
| 2045 this.$.selector.deselect(item); | |
| 2046 this.updateSizeForItem(item); | |
| 2047 }, | |
| 2048 toggleSelectionForItem: function(item) { | |
| 2049 item = this._getNormalizedItem(item); | |
| 2050 if (this.$.selector.isSelected(item)) { | |
| 2051 this.deselectItem(item); | |
| 2052 } else { | |
| 2053 this.selectItem(item); | |
| 2054 } | |
| 2055 }, | |
| 2056 clearSelection: function() { | |
| 2057 function unselect(item) { | |
| 2058 var model = this._getModelFromItem(item); | |
| 2059 if (model) { | |
| 2060 model[this.selectedAs] = false; | |
| 2061 } | |
| 2062 } | |
| 2063 if (Array.isArray(this.selectedItems)) { | |
| 2064 this.selectedItems.forEach(unselect, this); | |
| 2065 } else if (this.selectedItem) { | |
| 2066 unselect.call(this, this.selectedItem); | |
| 2067 } | |
| 2068 this.$.selector.clearSelection(); | |
| 2069 }, | |
| 2070 _selectionEnabledChanged: function(selectionEnabled) { | |
| 2071 var handler = selectionEnabled ? this.listen : this.unlisten; | |
| 2072 handler.call(this, this, 'tap', '_selectionHandler'); | |
| 2073 }, | |
| 2074 _selectionHandler: function(e) { | |
| 2075 var model = this.modelForElement(e.target); | |
| 2076 if (!model) { | |
| 2077 return; | |
| 2078 } | |
| 2079 var modelTabIndex, activeElTabIndex; | |
| 2080 var target = Polymer.dom(e).path[0]; | |
| 2081 var activeEl = Polymer.dom(this.domHost ? this.domHost.root : document).ac
tiveElement; | |
| 2082 var physicalItem = this._physicalItems[this._getPhysicalIndex(model[this.i
ndexAs])]; | |
| 2083 if (target.localName === 'input' || target.localName === 'button' || targe
t.localName === 'select') { | |
| 2084 return; | |
| 2085 } | |
| 2086 modelTabIndex = model.tabIndex; | |
| 2087 model.tabIndex = SECRET_TABINDEX; | |
| 2088 activeElTabIndex = activeEl ? activeEl.tabIndex : -1; | |
| 2089 model.tabIndex = modelTabIndex; | |
| 2090 if (activeEl && physicalItem !== activeEl && physicalItem.contains(activeE
l) && activeElTabIndex !== SECRET_TABINDEX) { | |
| 2091 return; | |
| 2092 } | |
| 2093 this.toggleSelectionForItem(model[this.as]); | |
| 2094 }, | |
| 2095 _multiSelectionChanged: function(multiSelection) { | |
| 2096 this.clearSelection(); | |
| 2097 this.$.selector.multi = multiSelection; | |
| 2098 }, | |
| 2099 updateSizeForItem: function(item) { | |
| 2100 item = this._getNormalizedItem(item); | |
| 2101 var key = this._collection.getKey(item); | |
| 2102 var pidx = this._physicalIndexForKey[key]; | |
| 2103 if (pidx != null) { | |
| 2104 this._updateMetrics([ pidx ]); | |
| 2105 this._positionItems(); | |
| 2106 } | |
| 2107 }, | |
| 2108 _manageFocus: function() { | |
| 2109 var fidx = this._focusedIndex; | |
| 2110 if (fidx >= 0 && fidx < this._virtualCount) { | |
| 2111 if (this._isIndexRendered(fidx)) { | |
| 2112 this._restoreFocusedItem(); | |
| 2113 } else { | |
| 2114 this._createFocusBackfillItem(); | |
| 2115 } | |
| 2116 } else if (this._virtualCount > 0 && this._physicalCount > 0) { | |
| 2117 this._focusedIndex = this._virtualStart; | |
| 2118 this._focusedItem = this._physicalItems[this._physicalStart]; | |
| 2119 } | |
| 2120 }, | |
| 2121 _isIndexRendered: function(idx) { | |
| 2122 return idx >= this._virtualStart && idx <= this._virtualEnd; | |
| 2123 }, | |
| 2124 _isIndexVisible: function(idx) { | |
| 2125 return idx >= this.firstVisibleIndex && idx <= this.lastVisibleIndex; | |
| 2126 }, | |
| 2127 _getPhysicalIndex: function(idx) { | |
| 2128 return this._physicalIndexForKey[this._collection.getKey(this._getNormaliz
edItem(idx))]; | |
| 2129 }, | |
| 2130 _focusPhysicalItem: function(idx) { | |
| 2131 if (idx < 0 || idx >= this._virtualCount) { | |
| 2132 return; | |
| 2133 } | |
| 2134 this._restoreFocusedItem(); | |
| 2135 if (!this._isIndexRendered(idx)) { | |
| 2136 this.scrollToIndex(idx); | |
| 2137 } | |
| 2138 var physicalItem = this._physicalItems[this._getPhysicalIndex(idx)]; | |
| 2139 var model = physicalItem._templateInstance; | |
| 2140 var focusable; | |
| 2141 model.tabIndex = SECRET_TABINDEX; | |
| 2142 if (physicalItem.tabIndex === SECRET_TABINDEX) { | |
| 2143 focusable = physicalItem; | |
| 2144 } | |
| 2145 if (!focusable) { | |
| 2146 focusable = Polymer.dom(physicalItem).querySelector('[tabindex="' + SECR
ET_TABINDEX + '"]'); | |
| 2147 } | |
| 2148 model.tabIndex = 0; | |
| 2149 this._focusedIndex = idx; | |
| 2150 focusable && focusable.focus(); | |
| 2151 }, | |
| 2152 _removeFocusedItem: function() { | |
| 2153 if (this._offscreenFocusedItem) { | |
| 2154 Polymer.dom(this).removeChild(this._offscreenFocusedItem); | |
| 2155 } | |
| 2156 this._offscreenFocusedItem = null; | |
| 2157 this._focusBackfillItem = null; | |
| 2158 this._focusedItem = null; | |
| 2159 this._focusedIndex = -1; | |
| 2160 }, | |
| 2161 _createFocusBackfillItem: function() { | |
| 2162 var pidx, fidx = this._focusedIndex; | |
| 2163 if (this._offscreenFocusedItem || fidx < 0) { | |
| 2164 return; | |
| 2165 } | |
| 2166 if (!this._focusBackfillItem) { | |
| 2167 var stampedTemplate = this.stamp(null); | |
| 2168 this._focusBackfillItem = stampedTemplate.root.querySelector('*'); | |
| 2169 Polymer.dom(this).appendChild(stampedTemplate.root); | |
| 2170 } | |
| 2171 pidx = this._getPhysicalIndex(fidx); | |
| 2172 if (pidx != null) { | |
| 2173 this._offscreenFocusedItem = this._physicalItems[pidx]; | |
| 2174 this._physicalItems[pidx] = this._focusBackfillItem; | |
| 2175 this.translate3d(0, HIDDEN_Y, 0, this._offscreenFocusedItem); | |
| 2176 } | |
| 2177 }, | |
| 2178 _restoreFocusedItem: function() { | |
| 2179 var pidx, fidx = this._focusedIndex; | |
| 2180 if (!this._offscreenFocusedItem || this._focusedIndex < 0) { | |
| 2181 return; | |
| 2182 } | |
| 2183 this._assignModels(); | |
| 2184 pidx = this._getPhysicalIndex(fidx); | |
| 2185 if (pidx != null) { | |
| 2186 this._focusBackfillItem = this._physicalItems[pidx]; | |
| 2187 this._physicalItems[pidx] = this._offscreenFocusedItem; | |
| 2188 this._offscreenFocusedItem = null; | |
| 2189 this.translate3d(0, HIDDEN_Y, 0, this._focusBackfillItem); | |
| 2190 } | |
| 2191 }, | |
| 2192 _didFocus: function(e) { | |
| 2193 var targetModel = this.modelForElement(e.target); | |
| 2194 var focusedModel = this._focusedItem ? this._focusedItem._templateInstance
: null; | |
| 2195 var hasOffscreenFocusedItem = this._offscreenFocusedItem !== null; | |
| 2196 var fidx = this._focusedIndex; | |
| 2197 if (!targetModel || !focusedModel) { | |
| 2198 return; | |
| 2199 } | |
| 2200 if (focusedModel === targetModel) { | |
| 2201 if (!this._isIndexVisible(fidx)) { | |
| 2202 this.scrollToIndex(fidx); | |
| 2203 } | |
| 2204 } else { | |
| 2205 this._restoreFocusedItem(); | |
| 2206 focusedModel.tabIndex = -1; | |
| 2207 targetModel.tabIndex = 0; | |
| 2208 fidx = targetModel[this.indexAs]; | |
| 2209 this._focusedIndex = fidx; | |
| 2210 this._focusedItem = this._physicalItems[this._getPhysicalIndex(fidx)]; | |
| 2211 if (hasOffscreenFocusedItem && !this._offscreenFocusedItem) { | |
| 2212 this._update(); | |
| 2213 } | |
| 2214 } | |
| 2215 }, | |
| 2216 _didMoveUp: function() { | |
| 2217 this._focusPhysicalItem(this._focusedIndex - 1); | |
| 2218 }, | |
| 2219 _didMoveDown: function(e) { | |
| 2220 e.detail.keyboardEvent.preventDefault(); | |
| 2221 this._focusPhysicalItem(this._focusedIndex + 1); | |
| 2222 }, | |
| 2223 _didEnter: function(e) { | |
| 2224 this._focusPhysicalItem(this._focusedIndex); | |
| 2225 this._selectionHandler(e.detail.keyboardEvent); | |
| 2226 } | |
| 2227 }); | |
| 2228 })(); | |
| 2229 | |
| 2230 // Copyright 2015 The Chromium Authors. All rights reserved. | 31 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2231 // Use of this source code is governed by a BSD-style license that can be | 32 // Use of this source code is governed by a BSD-style license that can be |
| 2232 // found in the LICENSE file. | 33 // found in the LICENSE file. |
| 2233 cr.define('downloads', function() { | 34 cr.define("downloads",function(){function chromeSendWithId(chromeSendName){retur
n function(id){chrome.send(chromeSendName,[id])}}function ActionService(){this.s
earchTerms_=[]}function trim(s){return s.trim()}function truthy(value){return!!v
alue}ActionService.splitTerms=function(searchText){return searchText.split(/"([^
"]*)"/).map(trim).filter(truthy)};ActionService.prototype={cancel:chromeSendWith
Id("cancel"),clearAll:function(){if(loadTimeData.getBoolean("allowDeletingHistor
y")){chrome.send("clearAll");this.search("")}},discardDangerous:chromeSendWithId
("discardDangerous"),download:function(url){var a=document.createElement("a");a.
href=url;a.setAttribute("download","");a.click()},drag:chromeSendWithId("drag"),
loadMore:function(){chrome.send("getDownloads",this.searchTerms_)},isSearching:f
unction(){return this.searchTerms_.length>0},openDownloadsFolder:chrome.send.bin
d(chrome,"openDownloadsFolder"),openFile:chromeSendWithId("openFile"),pause:chro
meSendWithId("pause"),remove:chromeSendWithId("remove"),resume:chromeSendWithId(
"resume"),saveDangerous:chromeSendWithId("saveDangerous"),search:function(search
Text){var searchTerms=ActionService.splitTerms(searchText);var sameTerms=searchT
erms.length==this.searchTerms_.length;for(var i=0;sameTerms&&i<searchTerms.lengt
h;++i){if(searchTerms[i]!=this.searchTerms_[i])sameTerms=false}if(sameTerms)retu
rn false;this.searchTerms_=searchTerms;this.loadMore();return true},show:chromeS
endWithId("show"),undo:chrome.send.bind(chrome,"undo")};cr.addSingletonGetter(Ac
tionService);return{ActionService:ActionService}}); |
| 2234 function chromeSendWithId(chromeSendName) { | |
| 2235 return function(id) { | |
| 2236 chrome.send(chromeSendName, [ id ]); | |
| 2237 }; | |
| 2238 } | |
| 2239 function ActionService() { | |
| 2240 this.searchTerms_ = []; | |
| 2241 } | |
| 2242 function trim(s) { | |
| 2243 return s.trim(); | |
| 2244 } | |
| 2245 function truthy(value) { | |
| 2246 return !!value; | |
| 2247 } | |
| 2248 ActionService.splitTerms = function(searchText) { | |
| 2249 return searchText.split(/"([^"]*)"/).map(trim).filter(truthy); | |
| 2250 }; | |
| 2251 ActionService.prototype = { | |
| 2252 cancel: chromeSendWithId('cancel'), | |
| 2253 clearAll: function() { | |
| 2254 if (loadTimeData.getBoolean('allowDeletingHistory')) { | |
| 2255 chrome.send('clearAll'); | |
| 2256 this.search(''); | |
| 2257 } | |
| 2258 }, | |
| 2259 discardDangerous: chromeSendWithId('discardDangerous'), | |
| 2260 download: function(url) { | |
| 2261 var a = document.createElement('a'); | |
| 2262 a.href = url; | |
| 2263 a.setAttribute('download', ''); | |
| 2264 a.click(); | |
| 2265 }, | |
| 2266 drag: chromeSendWithId('drag'), | |
| 2267 loadMore: function() { | |
| 2268 chrome.send('getDownloads', this.searchTerms_); | |
| 2269 }, | |
| 2270 isSearching: function() { | |
| 2271 return this.searchTerms_.length > 0; | |
| 2272 }, | |
| 2273 openDownloadsFolder: chrome.send.bind(chrome, 'openDownloadsFolder'), | |
| 2274 openFile: chromeSendWithId('openFile'), | |
| 2275 pause: chromeSendWithId('pause'), | |
| 2276 remove: chromeSendWithId('remove'), | |
| 2277 resume: chromeSendWithId('resume'), | |
| 2278 saveDangerous: chromeSendWithId('saveDangerous'), | |
| 2279 search: function(searchText) { | |
| 2280 var searchTerms = ActionService.splitTerms(searchText); | |
| 2281 var sameTerms = searchTerms.length == this.searchTerms_.length; | |
| 2282 for (var i = 0; sameTerms && i < searchTerms.length; ++i) { | |
| 2283 if (searchTerms[i] != this.searchTerms_[i]) sameTerms = false; | |
| 2284 } | |
| 2285 if (sameTerms) return false; | |
| 2286 this.searchTerms_ = searchTerms; | |
| 2287 this.loadMore(); | |
| 2288 return true; | |
| 2289 }, | |
| 2290 show: chromeSendWithId('show'), | |
| 2291 undo: chrome.send.bind(chrome, 'undo') | |
| 2292 }; | |
| 2293 cr.addSingletonGetter(ActionService); | |
| 2294 return { | |
| 2295 ActionService: ActionService | |
| 2296 }; | |
| 2297 }); | |
| 2298 | |
| 2299 // Copyright 2015 The Chromium Authors. All rights reserved. | 35 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2300 // Use of this source code is governed by a BSD-style license that can be | 36 // Use of this source code is governed by a BSD-style license that can be |
| 2301 // found in the LICENSE file. | 37 // found in the LICENSE file. |
| 2302 cr.define('downloads', function() { | 38 cr.define("downloads",function(){var DangerType={NOT_DANGEROUS:"NOT_DANGEROUS",D
ANGEROUS_FILE:"DANGEROUS_FILE",DANGEROUS_URL:"DANGEROUS_URL",DANGEROUS_CONTENT:"
DANGEROUS_CONTENT",UNCOMMON_CONTENT:"UNCOMMON_CONTENT",DANGEROUS_HOST:"DANGEROUS
_HOST",POTENTIALLY_UNWANTED:"POTENTIALLY_UNWANTED"};var States={IN_PROGRESS:"IN_
PROGRESS",CANCELLED:"CANCELLED",COMPLETE:"COMPLETE",PAUSED:"PAUSED",DANGEROUS:"D
ANGEROUS",INTERRUPTED:"INTERRUPTED"};return{DangerType:DangerType,States:States}
}); |
| 2303 var DangerType = { | |
| 2304 NOT_DANGEROUS: 'NOT_DANGEROUS', | |
| 2305 DANGEROUS_FILE: 'DANGEROUS_FILE', | |
| 2306 DANGEROUS_URL: 'DANGEROUS_URL', | |
| 2307 DANGEROUS_CONTENT: 'DANGEROUS_CONTENT', | |
| 2308 UNCOMMON_CONTENT: 'UNCOMMON_CONTENT', | |
| 2309 DANGEROUS_HOST: 'DANGEROUS_HOST', | |
| 2310 POTENTIALLY_UNWANTED: 'POTENTIALLY_UNWANTED' | |
| 2311 }; | |
| 2312 var States = { | |
| 2313 IN_PROGRESS: 'IN_PROGRESS', | |
| 2314 CANCELLED: 'CANCELLED', | |
| 2315 COMPLETE: 'COMPLETE', | |
| 2316 PAUSED: 'PAUSED', | |
| 2317 DANGEROUS: 'DANGEROUS', | |
| 2318 INTERRUPTED: 'INTERRUPTED' | |
| 2319 }; | |
| 2320 return { | |
| 2321 DangerType: DangerType, | |
| 2322 States: States | |
| 2323 }; | |
| 2324 }); | |
| 2325 | |
| 2326 // Copyright 2014 The Chromium Authors. All rights reserved. | 39 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2327 // Use of this source code is governed by a BSD-style license that can be | 40 // Use of this source code is governed by a BSD-style license that can be |
| 2328 // found in the LICENSE file. | 41 // found in the LICENSE file. |
| 2329 var ActionLink = document.registerElement('action-link', { | 42 var ActionLink=document.registerElement("action-link",{prototype:{__proto__:HTML
AnchorElement.prototype,createdCallback:function(){this.tabIndex=this.disabled?-
1:0;if(!this.hasAttribute("role"))this.setAttribute("role","link");this.addEvent
Listener("keydown",function(e){if(!this.disabled&&e.key=="Enter"&&!this.href){wi
ndow.setTimeout(this.click.bind(this),0)}});function preventDefault(e){e.prevent
Default()}function removePreventDefault(){document.removeEventListener("selectst
art",preventDefault);document.removeEventListener("mouseup",removePreventDefault
)}this.addEventListener("mousedown",function(){document.addEventListener("select
start",preventDefault);document.addEventListener("mouseup",removePreventDefault)
;if(document.activeElement!=this)this.classList.add("no-outline")});this.addEven
tListener("blur",function(){this.classList.remove("no-outline")})},set disabled(
disabled){if(disabled)HTMLAnchorElement.prototype.setAttribute.call(this,"disabl
ed","");else HTMLAnchorElement.prototype.removeAttribute.call(this,"disabled");t
his.tabIndex=disabled?-1:0},get disabled(){return this.hasAttribute("disabled")}
,setAttribute:function(attr,val){if(attr.toLowerCase()=="disabled")this.disabled
=true;else HTMLAnchorElement.prototype.setAttribute.apply(this,arguments)},remov
eAttribute:function(attr){if(attr.toLowerCase()=="disabled")this.disabled=false;
else HTMLAnchorElement.prototype.removeAttribute.apply(this,arguments)}},"extend
s":"a"});(function(){var metaDatas={};var metaArrays={};var singleton=null;Polym
er.IronMeta=Polymer({is:"iron-meta",properties:{type:{type:String,value:"default
",observer:"_typeChanged"},key:{type:String,observer:"_keyChanged"},value:{type:
Object,notify:true,observer:"_valueChanged"},self:{type:Boolean,observer:"_selfC
hanged"},list:{type:Array,notify:true}},hostAttributes:{hidden:true},factoryImpl
:function(config){if(config){for(var n in config){switch(n){case"type":case"key"
:case"value":this[n]=config[n];break}}}},created:function(){this._metaDatas=meta
Datas;this._metaArrays=metaArrays},_keyChanged:function(key,old){this._resetRegi
stration(old)},_valueChanged:function(value){this._resetRegistration(this.key)},
_selfChanged:function(self){if(self){this.value=this}},_typeChanged:function(typ
e){this._unregisterKey(this.key);if(!metaDatas[type]){metaDatas[type]={}}this._m
etaData=metaDatas[type];if(!metaArrays[type]){metaArrays[type]=[]}this.list=meta
Arrays[type];this._registerKeyValue(this.key,this.value)},byKey:function(key){re
turn this._metaData&&this._metaData[key]},_resetRegistration:function(oldKey){th
is._unregisterKey(oldKey);this._registerKeyValue(this.key,this.value)},_unregist
erKey:function(key){this._unregister(key,this._metaData,this.list)},_registerKey
Value:function(key,value){this._register(key,value,this._metaData,this.list)},_r
egister:function(key,value,data,list){if(key&&data&&value!==undefined){data[key]
=value;list.push(value)}},_unregister:function(key,data,list){if(key&&data){if(k
ey in data){var value=data[key];delete data[key];this.arrayDelete(list,value)}}}
});Polymer.IronMeta.getIronMeta=function getIronMeta(){if(singleton===null){sing
leton=new Polymer.IronMeta}return singleton};Polymer.IronMetaQuery=Polymer({is:"
iron-meta-query",properties:{type:{type:String,value:"default",observer:"_typeCh
anged"},key:{type:String,observer:"_keyChanged"},value:{type:Object,notify:true,
readOnly:true},list:{type:Array,notify:true}},factoryImpl:function(config){if(co
nfig){for(var n in config){switch(n){case"type":case"key":this[n]=config[n];brea
k}}}},created:function(){this._metaDatas=metaDatas;this._metaArrays=metaArrays},
_keyChanged:function(key){this._setValue(this._metaData&&this._metaData[key])},_
typeChanged:function(type){this._metaData=metaDatas[type];this.list=metaArrays[t
ype];if(this.key){this._keyChanged(this.key)}},byKey:function(key){return this._
metaData&&this._metaData[key]}})})();Polymer({is:"iron-icon",properties:{icon:{t
ype:String,observer:"_iconChanged"},theme:{type:String,observer:"_updateIcon"},s
rc:{type:String,observer:"_srcChanged"},_meta:{value:Polymer.Base.create("iron-m
eta",{type:"iconset"}),observer:"_updateIcon"}},_DEFAULT_ICONSET:"icons",_iconCh
anged:function(icon){var parts=(icon||"").split(":");this._iconName=parts.pop();
this._iconsetName=parts.pop()||this._DEFAULT_ICONSET;this._updateIcon()},_srcCha
nged:function(src){this._updateIcon()},_usesIconset:function(){return this.icon|
|!this.src},_updateIcon:function(){if(this._usesIconset()){if(this._img&&this._i
mg.parentNode){Polymer.dom(this.root).removeChild(this._img)}if(this._iconName==
=""){if(this._iconset){this._iconset.removeIcon(this)}}else if(this._iconsetName
&&this._meta){this._iconset=this._meta.byKey(this._iconsetName);if(this._iconset
){this._iconset.applyIcon(this,this._iconName,this.theme);this.unlisten(window,"
iron-iconset-added","_updateIcon")}else{this.listen(window,"iron-iconset-added",
"_updateIcon")}}}else{if(this._iconset){this._iconset.removeIcon(this)}if(!this.
_img){this._img=document.createElement("img");this._img.style.width="100%";this.
_img.style.height="100%";this._img.draggable=false}this._img.src=this.src;Polyme
r.dom(this.root).appendChild(this._img)}}});Polymer.IronControlState={properties
:{focused:{type:Boolean,value:false,notify:true,readOnly:true,reflectToAttribute
:true},disabled:{type:Boolean,value:false,notify:true,observer:"_disabledChanged
",reflectToAttribute:true},_oldTabIndex:{type:Number},_boundFocusBlurHandler:{ty
pe:Function,value:function(){return this._focusBlurHandler.bind(this)}}},observe
rs:["_changedControlState(focused, disabled)"],ready:function(){this.addEventLis
tener("focus",this._boundFocusBlurHandler,true);this.addEventListener("blur",thi
s._boundFocusBlurHandler,true)},_focusBlurHandler:function(event){if(event.targe
t===this){this._setFocused(event.type==="focus")}else if(!this.shadowRoot){var t
arget=Polymer.dom(event).localTarget;if(!this.isLightDescendant(target)){this.fi
re(event.type,{sourceEvent:event},{node:this,bubbles:event.bubbles,cancelable:ev
ent.cancelable})}}},_disabledChanged:function(disabled,old){this.setAttribute("a
ria-disabled",disabled?"true":"false");this.style.pointerEvents=disabled?"none":
"";if(disabled){this._oldTabIndex=this.tabIndex;this._setFocused(false);this.tab
Index=-1;this.blur()}else if(this._oldTabIndex!==undefined){this.tabIndex=this._
oldTabIndex}},_changedControlState:function(){if(this._controlStateChanged){this
._controlStateChanged()}}};Polymer.IronButtonStateImpl={properties:{pressed:{typ
e:Boolean,readOnly:true,value:false,reflectToAttribute:true,observer:"_pressedCh
anged"},toggles:{type:Boolean,value:false,reflectToAttribute:true},active:{type:
Boolean,value:false,notify:true,reflectToAttribute:true},pointerDown:{type:Boole
an,readOnly:true,value:false},receivedFocusFromKeyboard:{type:Boolean,readOnly:t
rue},ariaActiveAttribute:{type:String,value:"aria-pressed",observer:"_ariaActive
AttributeChanged"}},listeners:{down:"_downHandler",up:"_upHandler",tap:"_tapHand
ler"},observers:["_detectKeyboardFocus(focused)","_activeChanged(active, ariaAct
iveAttribute)"],keyBindings:{"enter:keydown":"_asyncClick","space:keydown":"_spa
ceKeyDownHandler","space:keyup":"_spaceKeyUpHandler"},_mouseEventRe:/^mouse/,_ta
pHandler:function(){if(this.toggles){this._userActivate(!this.active)}else{this.
active=false}},_detectKeyboardFocus:function(focused){this._setReceivedFocusFrom
Keyboard(!this.pointerDown&&focused)},_userActivate:function(active){if(this.act
ive!==active){this.active=active;this.fire("change")}},_downHandler:function(eve
nt){this._setPointerDown(true);this._setPressed(true);this._setReceivedFocusFrom
Keyboard(false)},_upHandler:function(){this._setPointerDown(false);this._setPres
sed(false)},_spaceKeyDownHandler:function(event){var keyboardEvent=event.detail.
keyboardEvent;var target=Polymer.dom(keyboardEvent).localTarget;if(this.isLightD
escendant(target))return;keyboardEvent.preventDefault();keyboardEvent.stopImmedi
atePropagation();this._setPressed(true)},_spaceKeyUpHandler:function(event){var
keyboardEvent=event.detail.keyboardEvent;var target=Polymer.dom(keyboardEvent).l
ocalTarget;if(this.isLightDescendant(target))return;if(this.pressed){this._async
Click()}this._setPressed(false)},_asyncClick:function(){this.async(function(){th
is.click()},1)},_pressedChanged:function(pressed){this._changedButtonState()},_a
riaActiveAttributeChanged:function(value,oldValue){if(oldValue&&oldValue!=value&
&this.hasAttribute(oldValue)){this.removeAttribute(oldValue)}},_activeChanged:fu
nction(active,ariaActiveAttribute){if(this.toggles){this.setAttribute(this.ariaA
ctiveAttribute,active?"true":"false")}else{this.removeAttribute(this.ariaActiveA
ttribute)}this._changedButtonState()},_controlStateChanged:function(){if(this.di
sabled){this._setPressed(false)}else{this._changedButtonState()}},_changedButton
State:function(){if(this._buttonStateChanged){this._buttonStateChanged()}}};Poly
mer.IronButtonState=[Polymer.IronA11yKeysBehavior,Polymer.IronButtonStateImpl];(
function(){var Utility={distance:function(x1,y1,x2,y2){var xDelta=x1-x2;var yDel
ta=y1-y2;return Math.sqrt(xDelta*xDelta+yDelta*yDelta)},now:window.performance&&
window.performance.now?window.performance.now.bind(window.performance):Date.now}
;function ElementMetrics(element){this.element=element;this.width=this.boundingR
ect.width;this.height=this.boundingRect.height;this.size=Math.max(this.width,thi
s.height)}ElementMetrics.prototype={get boundingRect(){return this.element.getBo
undingClientRect()},furthestCornerDistanceFrom:function(x,y){var topLeft=Utility
.distance(x,y,0,0);var topRight=Utility.distance(x,y,this.width,0);var bottomLef
t=Utility.distance(x,y,0,this.height);var bottomRight=Utility.distance(x,y,this.
width,this.height);return Math.max(topLeft,topRight,bottomLeft,bottomRight)}};fu
nction Ripple(element){this.element=element;this.color=window.getComputedStyle(e
lement).color;this.wave=document.createElement("div");this.waveContainer=documen
t.createElement("div");this.wave.style.backgroundColor=this.color;this.wave.clas
sList.add("wave");this.waveContainer.classList.add("wave-container");Polymer.dom
(this.waveContainer).appendChild(this.wave);this.resetInteractionState()}Ripple.
MAX_RADIUS=300;Ripple.prototype={get recenters(){return this.element.recenters},
get center(){return this.element.center},get mouseDownElapsed(){var elapsed;if(!
this.mouseDownStart){return 0}elapsed=Utility.now()-this.mouseDownStart;if(this.
mouseUpStart){elapsed-=this.mouseUpElapsed}return elapsed},get mouseUpElapsed(){
return this.mouseUpStart?Utility.now()-this.mouseUpStart:0},get mouseDownElapsed
Seconds(){return this.mouseDownElapsed/1e3},get mouseUpElapsedSeconds(){return t
his.mouseUpElapsed/1e3},get mouseInteractionSeconds(){return this.mouseDownElaps
edSeconds+this.mouseUpElapsedSeconds},get initialOpacity(){return this.element.i
nitialOpacity},get opacityDecayVelocity(){return this.element.opacityDecayVeloci
ty},get radius(){var width2=this.containerMetrics.width*this.containerMetrics.wi
dth;var height2=this.containerMetrics.height*this.containerMetrics.height;var wa
veRadius=Math.min(Math.sqrt(width2+height2),Ripple.MAX_RADIUS)*1.1+5;var duratio
n=1.1-.2*(waveRadius/Ripple.MAX_RADIUS);var timeNow=this.mouseInteractionSeconds
/duration;var size=waveRadius*(1-Math.pow(80,-timeNow));return Math.abs(size)},g
et opacity(){if(!this.mouseUpStart){return this.initialOpacity}return Math.max(0
,this.initialOpacity-this.mouseUpElapsedSeconds*this.opacityDecayVelocity)},get
outerOpacity(){var outerOpacity=this.mouseUpElapsedSeconds*.3;var waveOpacity=th
is.opacity;return Math.max(0,Math.min(outerOpacity,waveOpacity))},get isOpacityF
ullyDecayed(){return this.opacity<.01&&this.radius>=Math.min(this.maxRadius,Ripp
le.MAX_RADIUS)},get isRestingAtMaxRadius(){return this.opacity>=this.initialOpac
ity&&this.radius>=Math.min(this.maxRadius,Ripple.MAX_RADIUS)},get isAnimationCom
plete(){return this.mouseUpStart?this.isOpacityFullyDecayed:this.isRestingAtMaxR
adius},get translationFraction(){return Math.min(1,this.radius/this.containerMet
rics.size*2/Math.sqrt(2))},get xNow(){if(this.xEnd){return this.xStart+this.tran
slationFraction*(this.xEnd-this.xStart)}return this.xStart},get yNow(){if(this.y
End){return this.yStart+this.translationFraction*(this.yEnd-this.yStart)}return
this.yStart},get isMouseDown(){return this.mouseDownStart&&!this.mouseUpStart},r
esetInteractionState:function(){this.maxRadius=0;this.mouseDownStart=0;this.mous
eUpStart=0;this.xStart=0;this.yStart=0;this.xEnd=0;this.yEnd=0;this.slideDistanc
e=0;this.containerMetrics=new ElementMetrics(this.element)},draw:function(){var
scale;var translateString;var dx;var dy;this.wave.style.opacity=this.opacity;sca
le=this.radius/(this.containerMetrics.size/2);dx=this.xNow-this.containerMetrics
.width/2;dy=this.yNow-this.containerMetrics.height/2;this.waveContainer.style.we
bkitTransform="translate("+dx+"px, "+dy+"px)";this.waveContainer.style.transform
="translate3d("+dx+"px, "+dy+"px, 0)";this.wave.style.webkitTransform="scale("+s
cale+","+scale+")";this.wave.style.transform="scale3d("+scale+","+scale+",1)"},d
ownAction:function(event){var xCenter=this.containerMetrics.width/2;var yCenter=
this.containerMetrics.height/2;this.resetInteractionState();this.mouseDownStart=
Utility.now();if(this.center){this.xStart=xCenter;this.yStart=yCenter;this.slide
Distance=Utility.distance(this.xStart,this.yStart,this.xEnd,this.yEnd)}else{this
.xStart=event?event.detail.x-this.containerMetrics.boundingRect.left:this.contai
nerMetrics.width/2;this.yStart=event?event.detail.y-this.containerMetrics.boundi
ngRect.top:this.containerMetrics.height/2}if(this.recenters){this.xEnd=xCenter;t
his.yEnd=yCenter;this.slideDistance=Utility.distance(this.xStart,this.yStart,thi
s.xEnd,this.yEnd)}this.maxRadius=this.containerMetrics.furthestCornerDistanceFro
m(this.xStart,this.yStart);this.waveContainer.style.top=(this.containerMetrics.h
eight-this.containerMetrics.size)/2+"px";this.waveContainer.style.left=(this.con
tainerMetrics.width-this.containerMetrics.size)/2+"px";this.waveContainer.style.
width=this.containerMetrics.size+"px";this.waveContainer.style.height=this.conta
inerMetrics.size+"px"},upAction:function(event){if(!this.isMouseDown){return}thi
s.mouseUpStart=Utility.now()},remove:function(){Polymer.dom(this.waveContainer.p
arentNode).removeChild(this.waveContainer)}};Polymer({is:"paper-ripple",behavior
s:[Polymer.IronA11yKeysBehavior],properties:{initialOpacity:{type:Number,value:.
25},opacityDecayVelocity:{type:Number,value:.8},recenters:{type:Boolean,value:fa
lse},center:{type:Boolean,value:false},ripples:{type:Array,value:function(){retu
rn[]}},animating:{type:Boolean,readOnly:true,reflectToAttribute:true,value:false
},holdDown:{type:Boolean,value:false,observer:"_holdDownChanged"},noink:{type:Bo
olean,value:false},_animating:{type:Boolean},_boundAnimate:{type:Function,value:
function(){return this.animate.bind(this)}}},get target(){return this.keyEventTa
rget},keyBindings:{"enter:keydown":"_onEnterKeydown","space:keydown":"_onSpaceKe
ydown","space:keyup":"_onSpaceKeyup"},attached:function(){if(this.parentNode.nod
eType==11){this.keyEventTarget=Polymer.dom(this).getOwnerRoot().host}else{this.k
eyEventTarget=this.parentNode}var keyEventTarget=this.keyEventTarget;this.listen
(keyEventTarget,"up","uiUpAction");this.listen(keyEventTarget,"down","uiDownActi
on")},detached:function(){this.unlisten(this.keyEventTarget,"up","uiUpAction");t
his.unlisten(this.keyEventTarget,"down","uiDownAction");this.keyEventTarget=null
},get shouldKeepAnimating(){for(var index=0;index<this.ripples.length;++index){i
f(!this.ripples[index].isAnimationComplete){return true}}return false},simulated
Ripple:function(){this.downAction(null);this.async(function(){this.upAction()},1
)},uiDownAction:function(event){if(!this.noink){this.downAction(event)}},downAct
ion:function(event){if(this.holdDown&&this.ripples.length>0){return}var ripple=t
his.addRipple();ripple.downAction(event);if(!this._animating){this._animating=tr
ue;this.animate()}},uiUpAction:function(event){if(!this.noink){this.upAction(eve
nt)}},upAction:function(event){if(this.holdDown){return}this.ripples.forEach(fun
ction(ripple){ripple.upAction(event)});this._animating=true;this.animate()},onAn
imationComplete:function(){this._animating=false;this.$.background.style.backgro
undColor=null;this.fire("transitionend")},addRipple:function(){var ripple=new Ri
pple(this);Polymer.dom(this.$.waves).appendChild(ripple.waveContainer);this.$.ba
ckground.style.backgroundColor=ripple.color;this.ripples.push(ripple);this._setA
nimating(true);return ripple},removeRipple:function(ripple){var rippleIndex=this
.ripples.indexOf(ripple);if(rippleIndex<0){return}this.ripples.splice(rippleInde
x,1);ripple.remove();if(!this.ripples.length){this._setAnimating(false)}},animat
e:function(){if(!this._animating){return}var index;var ripple;for(index=0;index<
this.ripples.length;++index){ripple=this.ripples[index];ripple.draw();this.$.bac
kground.style.opacity=ripple.outerOpacity;if(ripple.isOpacityFullyDecayed&&!ripp
le.isRestingAtMaxRadius){this.removeRipple(ripple)}}if(!this.shouldKeepAnimating
&&this.ripples.length===0){this.onAnimationComplete()}else{window.requestAnimati
onFrame(this._boundAnimate)}},_onEnterKeydown:function(){this.uiDownAction();thi
s.async(this.uiUpAction,1)},_onSpaceKeydown:function(){this.uiDownAction()},_onS
paceKeyup:function(){this.uiUpAction()},_holdDownChanged:function(newVal,oldVal)
{if(oldVal===undefined){return}if(newVal){this.downAction()}else{this.upAction()
}}})})();Polymer.PaperRippleBehavior={properties:{noink:{type:Boolean,observer:"
_noinkChanged"},_rippleContainer:{type:Object}},_buttonStateChanged:function(){i
f(this.focused){this.ensureRipple()}},_downHandler:function(event){Polymer.IronB
uttonStateImpl._downHandler.call(this,event);if(this.pressed){this.ensureRipple(
event)}},ensureRipple:function(optTriggeringEvent){if(!this.hasRipple()){this._r
ipple=this._createRipple();this._ripple.noink=this.noink;var rippleContainer=thi
s._rippleContainer||this.root;if(rippleContainer){Polymer.dom(rippleContainer).a
ppendChild(this._ripple)}if(optTriggeringEvent){var domContainer=Polymer.dom(thi
s._rippleContainer||this);var target=Polymer.dom(optTriggeringEvent).rootTarget;
if(domContainer.deepContains(target)){this._ripple.uiDownAction(optTriggeringEve
nt)}}}},getRipple:function(){this.ensureRipple();return this._ripple},hasRipple:
function(){return Boolean(this._ripple)},_createRipple:function(){return documen
t.createElement("paper-ripple")},_noinkChanged:function(noink){if(this.hasRipple
()){this._ripple.noink=noink}}};Polymer.PaperButtonBehaviorImpl={properties:{ele
vation:{type:Number,reflectToAttribute:true,readOnly:true}},observers:["_calcula
teElevation(focused, disabled, active, pressed, receivedFocusFromKeyboard)","_co
mputeKeyboardClass(receivedFocusFromKeyboard)"],hostAttributes:{role:"button",ta
bindex:"0",animated:true},_calculateElevation:function(){var e=1;if(this.disable
d){e=0}else if(this.active||this.pressed){e=4}else if(this.receivedFocusFromKeyb
oard){e=3}this._setElevation(e)},_computeKeyboardClass:function(receivedFocusFro
mKeyboard){this.toggleClass("keyboard-focus",receivedFocusFromKeyboard)},_spaceK
eyDownHandler:function(event){Polymer.IronButtonStateImpl._spaceKeyDownHandler.c
all(this,event);if(this.hasRipple()&&this.getRipple().ripples.length<1){this._ri
pple.uiDownAction()}},_spaceKeyUpHandler:function(event){Polymer.IronButtonState
Impl._spaceKeyUpHandler.call(this,event);if(this.hasRipple()){this._ripple.uiUpA
ction()}}};Polymer.PaperButtonBehavior=[Polymer.IronButtonState,Polymer.IronCont
rolState,Polymer.PaperRippleBehavior,Polymer.PaperButtonBehaviorImpl];Polymer({i
s:"paper-button",behaviors:[Polymer.PaperButtonBehavior],properties:{raised:{typ
e:Boolean,reflectToAttribute:true,value:false,observer:"_calculateElevation"}},_
calculateElevation:function(){if(!this.raised){this._setElevation(0)}else{Polyme
r.PaperButtonBehaviorImpl._calculateElevation.apply(this)}}});Polymer({is:"paper
-icon-button-light","extends":"button",behaviors:[Polymer.PaperRippleBehavior],l
isteners:{down:"_rippleDown",up:"_rippleUp",focus:"_rippleDown",blur:"_rippleUp"
},_rippleDown:function(){this.getRipple().downAction()},_rippleUp:function(){thi
s.getRipple().upAction()},ensureRipple:function(var_args){var lastRipple=this._r
ipple;Polymer.PaperRippleBehavior.ensureRipple.apply(this,arguments);if(this._ri
pple&&this._ripple!==lastRipple){this._ripple.center=true;this._ripple.classList
.add("circle")}}});Polymer.IronRangeBehavior={properties:{value:{type:Number,val
ue:0,notify:true,reflectToAttribute:true},min:{type:Number,value:0,notify:true},
max:{type:Number,value:100,notify:true},step:{type:Number,value:1,notify:true},r
atio:{type:Number,value:0,readOnly:true,notify:true}},observers:["_update(value,
min, max, step)"],_calcRatio:function(value){return(this._clampValue(value)-thi
s.min)/(this.max-this.min)},_clampValue:function(value){return Math.min(this.max
,Math.max(this.min,this._calcStep(value)))},_calcStep:function(value){value=pars
eFloat(value);if(!this.step){return value}var numSteps=Math.round((value-this.mi
n)/this.step);if(this.step<1){return numSteps/(1/this.step)+this.min}else{return
numSteps*this.step+this.min}},_validateValue:function(){var v=this._clampValue(
this.value);this.value=this.oldValue=isNaN(v)?this.oldValue:v;return this.value!
==v},_update:function(){this._validateValue();this._setRatio(this._calcRatio(thi
s.value)*100)}};Polymer({is:"paper-progress",behaviors:[Polymer.IronRangeBehavio
r],properties:{secondaryProgress:{type:Number,value:0},secondaryRatio:{type:Numb
er,value:0,readOnly:true},indeterminate:{type:Boolean,value:false,observer:"_tog
gleIndeterminate"},disabled:{type:Boolean,value:false,reflectToAttribute:true,ob
server:"_disabledChanged"}},observers:["_progressChanged(secondaryProgress, valu
e, min, max)"],hostAttributes:{role:"progressbar"},_toggleIndeterminate:function
(indeterminate){this.toggleClass("indeterminate",indeterminate,this.$.primaryPro
gress)},_transformProgress:function(progress,ratio){var transform="scaleX("+rati
o/100+")";progress.style.transform=progress.style.webkitTransform=transform},_ma
inRatioChanged:function(ratio){this._transformProgress(this.$.primaryProgress,ra
tio)},_progressChanged:function(secondaryProgress,value,min,max){secondaryProgre
ss=this._clampValue(secondaryProgress);value=this._clampValue(value);var seconda
ryRatio=this._calcRatio(secondaryProgress)*100;var mainRatio=this._calcRatio(val
ue)*100;this._setSecondaryRatio(secondaryRatio);this._transformProgress(this.$.s
econdaryProgress,secondaryRatio);this._transformProgress(this.$.primaryProgress,
mainRatio);this.secondaryProgress=secondaryProgress;this.setAttribute("aria-valu
enow",value);this.setAttribute("aria-valuemin",min);this.setAttribute("aria-valu
emax",max)},_disabledChanged:function(disabled){this.setAttribute("aria-disabled
",disabled?"true":"false")},_hideSecondaryProgress:function(secondaryRatio){retu
rn secondaryRatio===0}});Polymer({is:"iron-iconset-svg",properties:{name:{type:S
tring,observer:"_nameChanged"},size:{type:Number,value:24}},attached:function(){
this.style.display="none"},getIconNames:function(){this._icons=this._createIconM
ap();return Object.keys(this._icons).map(function(n){return this.name+":"+n},thi
s)},applyIcon:function(element,iconName){element=element.root||element;this.remo
veIcon(element);var svg=this._cloneIcon(iconName);if(svg){var pde=Polymer.dom(el
ement);pde.insertBefore(svg,pde.childNodes[0]);return element._svgIcon=svg}retur
n null},removeIcon:function(element){if(element._svgIcon){Polymer.dom(element).r
emoveChild(element._svgIcon);element._svgIcon=null}},_nameChanged:function(){new
Polymer.IronMeta({type:"iconset",key:this.name,value:this});this.async(function
(){this.fire("iron-iconset-added",this,{node:window})})},_createIconMap:function
(){var icons=Object.create(null);Polymer.dom(this).querySelectorAll("[id]").forE
ach(function(icon){icons[icon.id]=icon});return icons},_cloneIcon:function(id){t
his._icons=this._icons||this._createIconMap();return this._prepareSvgClone(this.
_icons[id],this.size)},_prepareSvgClone:function(sourceSvg,size){if(sourceSvg){v
ar content=sourceSvg.cloneNode(true),svg=document.createElementNS("http://www.w3
.org/2000/svg","svg"),viewBox=content.getAttribute("viewBox")||"0 0 "+size+" "+s
ize;svg.setAttribute("viewBox",viewBox);svg.setAttribute("preserveAspectRatio","
xMidYMid meet");svg.style.cssText="pointer-events: none; display: block; width:
100%; height: 100%;";svg.appendChild(content).removeAttribute("id");return svg}r
eturn null}}); |
| 2330 prototype: { | |
| 2331 __proto__: HTMLAnchorElement.prototype, | |
| 2332 createdCallback: function() { | |
| 2333 this.tabIndex = this.disabled ? -1 : 0; | |
| 2334 if (!this.hasAttribute('role')) this.setAttribute('role', 'link'); | |
| 2335 this.addEventListener('keydown', function(e) { | |
| 2336 if (!this.disabled && e.key == 'Enter' && !this.href) { | |
| 2337 window.setTimeout(this.click.bind(this), 0); | |
| 2338 } | |
| 2339 }); | |
| 2340 function preventDefault(e) { | |
| 2341 e.preventDefault(); | |
| 2342 } | |
| 2343 function removePreventDefault() { | |
| 2344 document.removeEventListener('selectstart', preventDefault); | |
| 2345 document.removeEventListener('mouseup', removePreventDefault); | |
| 2346 } | |
| 2347 this.addEventListener('mousedown', function() { | |
| 2348 document.addEventListener('selectstart', preventDefault); | |
| 2349 document.addEventListener('mouseup', removePreventDefault); | |
| 2350 if (document.activeElement != this) this.classList.add('no-outline'); | |
| 2351 }); | |
| 2352 this.addEventListener('blur', function() { | |
| 2353 this.classList.remove('no-outline'); | |
| 2354 }); | |
| 2355 }, | |
| 2356 set disabled(disabled) { | |
| 2357 if (disabled) HTMLAnchorElement.prototype.setAttribute.call(this, 'disable
d', ''); else HTMLAnchorElement.prototype.removeAttribute.call(this, 'disabled')
; | |
| 2358 this.tabIndex = disabled ? -1 : 0; | |
| 2359 }, | |
| 2360 get disabled() { | |
| 2361 return this.hasAttribute('disabled'); | |
| 2362 }, | |
| 2363 setAttribute: function(attr, val) { | |
| 2364 if (attr.toLowerCase() == 'disabled') this.disabled = true; else HTMLAncho
rElement.prototype.setAttribute.apply(this, arguments); | |
| 2365 }, | |
| 2366 removeAttribute: function(attr) { | |
| 2367 if (attr.toLowerCase() == 'disabled') this.disabled = false; else HTMLAnch
orElement.prototype.removeAttribute.apply(this, arguments); | |
| 2368 } | |
| 2369 }, | |
| 2370 "extends": 'a' | |
| 2371 }); | |
| 2372 | |
| 2373 (function() { | |
| 2374 var metaDatas = {}; | |
| 2375 var metaArrays = {}; | |
| 2376 var singleton = null; | |
| 2377 Polymer.IronMeta = Polymer({ | |
| 2378 is: 'iron-meta', | |
| 2379 properties: { | |
| 2380 type: { | |
| 2381 type: String, | |
| 2382 value: 'default', | |
| 2383 observer: '_typeChanged' | |
| 2384 }, | |
| 2385 key: { | |
| 2386 type: String, | |
| 2387 observer: '_keyChanged' | |
| 2388 }, | |
| 2389 value: { | |
| 2390 type: Object, | |
| 2391 notify: true, | |
| 2392 observer: '_valueChanged' | |
| 2393 }, | |
| 2394 self: { | |
| 2395 type: Boolean, | |
| 2396 observer: '_selfChanged' | |
| 2397 }, | |
| 2398 list: { | |
| 2399 type: Array, | |
| 2400 notify: true | |
| 2401 } | |
| 2402 }, | |
| 2403 hostAttributes: { | |
| 2404 hidden: true | |
| 2405 }, | |
| 2406 factoryImpl: function(config) { | |
| 2407 if (config) { | |
| 2408 for (var n in config) { | |
| 2409 switch (n) { | |
| 2410 case 'type': | |
| 2411 case 'key': | |
| 2412 case 'value': | |
| 2413 this[n] = config[n]; | |
| 2414 break; | |
| 2415 } | |
| 2416 } | |
| 2417 } | |
| 2418 }, | |
| 2419 created: function() { | |
| 2420 this._metaDatas = metaDatas; | |
| 2421 this._metaArrays = metaArrays; | |
| 2422 }, | |
| 2423 _keyChanged: function(key, old) { | |
| 2424 this._resetRegistration(old); | |
| 2425 }, | |
| 2426 _valueChanged: function(value) { | |
| 2427 this._resetRegistration(this.key); | |
| 2428 }, | |
| 2429 _selfChanged: function(self) { | |
| 2430 if (self) { | |
| 2431 this.value = this; | |
| 2432 } | |
| 2433 }, | |
| 2434 _typeChanged: function(type) { | |
| 2435 this._unregisterKey(this.key); | |
| 2436 if (!metaDatas[type]) { | |
| 2437 metaDatas[type] = {}; | |
| 2438 } | |
| 2439 this._metaData = metaDatas[type]; | |
| 2440 if (!metaArrays[type]) { | |
| 2441 metaArrays[type] = []; | |
| 2442 } | |
| 2443 this.list = metaArrays[type]; | |
| 2444 this._registerKeyValue(this.key, this.value); | |
| 2445 }, | |
| 2446 byKey: function(key) { | |
| 2447 return this._metaData && this._metaData[key]; | |
| 2448 }, | |
| 2449 _resetRegistration: function(oldKey) { | |
| 2450 this._unregisterKey(oldKey); | |
| 2451 this._registerKeyValue(this.key, this.value); | |
| 2452 }, | |
| 2453 _unregisterKey: function(key) { | |
| 2454 this._unregister(key, this._metaData, this.list); | |
| 2455 }, | |
| 2456 _registerKeyValue: function(key, value) { | |
| 2457 this._register(key, value, this._metaData, this.list); | |
| 2458 }, | |
| 2459 _register: function(key, value, data, list) { | |
| 2460 if (key && data && value !== undefined) { | |
| 2461 data[key] = value; | |
| 2462 list.push(value); | |
| 2463 } | |
| 2464 }, | |
| 2465 _unregister: function(key, data, list) { | |
| 2466 if (key && data) { | |
| 2467 if (key in data) { | |
| 2468 var value = data[key]; | |
| 2469 delete data[key]; | |
| 2470 this.arrayDelete(list, value); | |
| 2471 } | |
| 2472 } | |
| 2473 } | |
| 2474 }); | |
| 2475 Polymer.IronMeta.getIronMeta = function getIronMeta() { | |
| 2476 if (singleton === null) { | |
| 2477 singleton = new Polymer.IronMeta(); | |
| 2478 } | |
| 2479 return singleton; | |
| 2480 }; | |
| 2481 Polymer.IronMetaQuery = Polymer({ | |
| 2482 is: 'iron-meta-query', | |
| 2483 properties: { | |
| 2484 type: { | |
| 2485 type: String, | |
| 2486 value: 'default', | |
| 2487 observer: '_typeChanged' | |
| 2488 }, | |
| 2489 key: { | |
| 2490 type: String, | |
| 2491 observer: '_keyChanged' | |
| 2492 }, | |
| 2493 value: { | |
| 2494 type: Object, | |
| 2495 notify: true, | |
| 2496 readOnly: true | |
| 2497 }, | |
| 2498 list: { | |
| 2499 type: Array, | |
| 2500 notify: true | |
| 2501 } | |
| 2502 }, | |
| 2503 factoryImpl: function(config) { | |
| 2504 if (config) { | |
| 2505 for (var n in config) { | |
| 2506 switch (n) { | |
| 2507 case 'type': | |
| 2508 case 'key': | |
| 2509 this[n] = config[n]; | |
| 2510 break; | |
| 2511 } | |
| 2512 } | |
| 2513 } | |
| 2514 }, | |
| 2515 created: function() { | |
| 2516 this._metaDatas = metaDatas; | |
| 2517 this._metaArrays = metaArrays; | |
| 2518 }, | |
| 2519 _keyChanged: function(key) { | |
| 2520 this._setValue(this._metaData && this._metaData[key]); | |
| 2521 }, | |
| 2522 _typeChanged: function(type) { | |
| 2523 this._metaData = metaDatas[type]; | |
| 2524 this.list = metaArrays[type]; | |
| 2525 if (this.key) { | |
| 2526 this._keyChanged(this.key); | |
| 2527 } | |
| 2528 }, | |
| 2529 byKey: function(key) { | |
| 2530 return this._metaData && this._metaData[key]; | |
| 2531 } | |
| 2532 }); | |
| 2533 })(); | |
| 2534 | |
| 2535 Polymer({ | |
| 2536 is: 'iron-icon', | |
| 2537 properties: { | |
| 2538 icon: { | |
| 2539 type: String, | |
| 2540 observer: '_iconChanged' | |
| 2541 }, | |
| 2542 theme: { | |
| 2543 type: String, | |
| 2544 observer: '_updateIcon' | |
| 2545 }, | |
| 2546 src: { | |
| 2547 type: String, | |
| 2548 observer: '_srcChanged' | |
| 2549 }, | |
| 2550 _meta: { | |
| 2551 value: Polymer.Base.create('iron-meta', { | |
| 2552 type: 'iconset' | |
| 2553 }), | |
| 2554 observer: '_updateIcon' | |
| 2555 } | |
| 2556 }, | |
| 2557 _DEFAULT_ICONSET: 'icons', | |
| 2558 _iconChanged: function(icon) { | |
| 2559 var parts = (icon || '').split(':'); | |
| 2560 this._iconName = parts.pop(); | |
| 2561 this._iconsetName = parts.pop() || this._DEFAULT_ICONSET; | |
| 2562 this._updateIcon(); | |
| 2563 }, | |
| 2564 _srcChanged: function(src) { | |
| 2565 this._updateIcon(); | |
| 2566 }, | |
| 2567 _usesIconset: function() { | |
| 2568 return this.icon || !this.src; | |
| 2569 }, | |
| 2570 _updateIcon: function() { | |
| 2571 if (this._usesIconset()) { | |
| 2572 if (this._img && this._img.parentNode) { | |
| 2573 Polymer.dom(this.root).removeChild(this._img); | |
| 2574 } | |
| 2575 if (this._iconName === "") { | |
| 2576 if (this._iconset) { | |
| 2577 this._iconset.removeIcon(this); | |
| 2578 } | |
| 2579 } else if (this._iconsetName && this._meta) { | |
| 2580 this._iconset = this._meta.byKey(this._iconsetName); | |
| 2581 if (this._iconset) { | |
| 2582 this._iconset.applyIcon(this, this._iconName, this.theme); | |
| 2583 this.unlisten(window, 'iron-iconset-added', '_updateIcon'); | |
| 2584 } else { | |
| 2585 this.listen(window, 'iron-iconset-added', '_updateIcon'); | |
| 2586 } | |
| 2587 } | |
| 2588 } else { | |
| 2589 if (this._iconset) { | |
| 2590 this._iconset.removeIcon(this); | |
| 2591 } | |
| 2592 if (!this._img) { | |
| 2593 this._img = document.createElement('img'); | |
| 2594 this._img.style.width = '100%'; | |
| 2595 this._img.style.height = '100%'; | |
| 2596 this._img.draggable = false; | |
| 2597 } | |
| 2598 this._img.src = this.src; | |
| 2599 Polymer.dom(this.root).appendChild(this._img); | |
| 2600 } | |
| 2601 } | |
| 2602 }); | |
| 2603 | |
| 2604 Polymer.IronControlState = { | |
| 2605 properties: { | |
| 2606 focused: { | |
| 2607 type: Boolean, | |
| 2608 value: false, | |
| 2609 notify: true, | |
| 2610 readOnly: true, | |
| 2611 reflectToAttribute: true | |
| 2612 }, | |
| 2613 disabled: { | |
| 2614 type: Boolean, | |
| 2615 value: false, | |
| 2616 notify: true, | |
| 2617 observer: '_disabledChanged', | |
| 2618 reflectToAttribute: true | |
| 2619 }, | |
| 2620 _oldTabIndex: { | |
| 2621 type: Number | |
| 2622 }, | |
| 2623 _boundFocusBlurHandler: { | |
| 2624 type: Function, | |
| 2625 value: function() { | |
| 2626 return this._focusBlurHandler.bind(this); | |
| 2627 } | |
| 2628 } | |
| 2629 }, | |
| 2630 observers: [ '_changedControlState(focused, disabled)' ], | |
| 2631 ready: function() { | |
| 2632 this.addEventListener('focus', this._boundFocusBlurHandler, true); | |
| 2633 this.addEventListener('blur', this._boundFocusBlurHandler, true); | |
| 2634 }, | |
| 2635 _focusBlurHandler: function(event) { | |
| 2636 if (event.target === this) { | |
| 2637 this._setFocused(event.type === 'focus'); | |
| 2638 } else if (!this.shadowRoot) { | |
| 2639 var target = Polymer.dom(event).localTarget; | |
| 2640 if (!this.isLightDescendant(target)) { | |
| 2641 this.fire(event.type, { | |
| 2642 sourceEvent: event | |
| 2643 }, { | |
| 2644 node: this, | |
| 2645 bubbles: event.bubbles, | |
| 2646 cancelable: event.cancelable | |
| 2647 }); | |
| 2648 } | |
| 2649 } | |
| 2650 }, | |
| 2651 _disabledChanged: function(disabled, old) { | |
| 2652 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); | |
| 2653 this.style.pointerEvents = disabled ? 'none' : ''; | |
| 2654 if (disabled) { | |
| 2655 this._oldTabIndex = this.tabIndex; | |
| 2656 this._setFocused(false); | |
| 2657 this.tabIndex = -1; | |
| 2658 this.blur(); | |
| 2659 } else if (this._oldTabIndex !== undefined) { | |
| 2660 this.tabIndex = this._oldTabIndex; | |
| 2661 } | |
| 2662 }, | |
| 2663 _changedControlState: function() { | |
| 2664 if (this._controlStateChanged) { | |
| 2665 this._controlStateChanged(); | |
| 2666 } | |
| 2667 } | |
| 2668 }; | |
| 2669 | |
| 2670 Polymer.IronButtonStateImpl = { | |
| 2671 properties: { | |
| 2672 pressed: { | |
| 2673 type: Boolean, | |
| 2674 readOnly: true, | |
| 2675 value: false, | |
| 2676 reflectToAttribute: true, | |
| 2677 observer: '_pressedChanged' | |
| 2678 }, | |
| 2679 toggles: { | |
| 2680 type: Boolean, | |
| 2681 value: false, | |
| 2682 reflectToAttribute: true | |
| 2683 }, | |
| 2684 active: { | |
| 2685 type: Boolean, | |
| 2686 value: false, | |
| 2687 notify: true, | |
| 2688 reflectToAttribute: true | |
| 2689 }, | |
| 2690 pointerDown: { | |
| 2691 type: Boolean, | |
| 2692 readOnly: true, | |
| 2693 value: false | |
| 2694 }, | |
| 2695 receivedFocusFromKeyboard: { | |
| 2696 type: Boolean, | |
| 2697 readOnly: true | |
| 2698 }, | |
| 2699 ariaActiveAttribute: { | |
| 2700 type: String, | |
| 2701 value: 'aria-pressed', | |
| 2702 observer: '_ariaActiveAttributeChanged' | |
| 2703 } | |
| 2704 }, | |
| 2705 listeners: { | |
| 2706 down: '_downHandler', | |
| 2707 up: '_upHandler', | |
| 2708 tap: '_tapHandler' | |
| 2709 }, | |
| 2710 observers: [ '_detectKeyboardFocus(focused)', '_activeChanged(active, ariaActi
veAttribute)' ], | |
| 2711 keyBindings: { | |
| 2712 'enter:keydown': '_asyncClick', | |
| 2713 'space:keydown': '_spaceKeyDownHandler', | |
| 2714 'space:keyup': '_spaceKeyUpHandler' | |
| 2715 }, | |
| 2716 _mouseEventRe: /^mouse/, | |
| 2717 _tapHandler: function() { | |
| 2718 if (this.toggles) { | |
| 2719 this._userActivate(!this.active); | |
| 2720 } else { | |
| 2721 this.active = false; | |
| 2722 } | |
| 2723 }, | |
| 2724 _detectKeyboardFocus: function(focused) { | |
| 2725 this._setReceivedFocusFromKeyboard(!this.pointerDown && focused); | |
| 2726 }, | |
| 2727 _userActivate: function(active) { | |
| 2728 if (this.active !== active) { | |
| 2729 this.active = active; | |
| 2730 this.fire('change'); | |
| 2731 } | |
| 2732 }, | |
| 2733 _downHandler: function(event) { | |
| 2734 this._setPointerDown(true); | |
| 2735 this._setPressed(true); | |
| 2736 this._setReceivedFocusFromKeyboard(false); | |
| 2737 }, | |
| 2738 _upHandler: function() { | |
| 2739 this._setPointerDown(false); | |
| 2740 this._setPressed(false); | |
| 2741 }, | |
| 2742 _spaceKeyDownHandler: function(event) { | |
| 2743 var keyboardEvent = event.detail.keyboardEvent; | |
| 2744 var target = Polymer.dom(keyboardEvent).localTarget; | |
| 2745 if (this.isLightDescendant(target)) return; | |
| 2746 keyboardEvent.preventDefault(); | |
| 2747 keyboardEvent.stopImmediatePropagation(); | |
| 2748 this._setPressed(true); | |
| 2749 }, | |
| 2750 _spaceKeyUpHandler: function(event) { | |
| 2751 var keyboardEvent = event.detail.keyboardEvent; | |
| 2752 var target = Polymer.dom(keyboardEvent).localTarget; | |
| 2753 if (this.isLightDescendant(target)) return; | |
| 2754 if (this.pressed) { | |
| 2755 this._asyncClick(); | |
| 2756 } | |
| 2757 this._setPressed(false); | |
| 2758 }, | |
| 2759 _asyncClick: function() { | |
| 2760 this.async(function() { | |
| 2761 this.click(); | |
| 2762 }, 1); | |
| 2763 }, | |
| 2764 _pressedChanged: function(pressed) { | |
| 2765 this._changedButtonState(); | |
| 2766 }, | |
| 2767 _ariaActiveAttributeChanged: function(value, oldValue) { | |
| 2768 if (oldValue && oldValue != value && this.hasAttribute(oldValue)) { | |
| 2769 this.removeAttribute(oldValue); | |
| 2770 } | |
| 2771 }, | |
| 2772 _activeChanged: function(active, ariaActiveAttribute) { | |
| 2773 if (this.toggles) { | |
| 2774 this.setAttribute(this.ariaActiveAttribute, active ? 'true' : 'false'); | |
| 2775 } else { | |
| 2776 this.removeAttribute(this.ariaActiveAttribute); | |
| 2777 } | |
| 2778 this._changedButtonState(); | |
| 2779 }, | |
| 2780 _controlStateChanged: function() { | |
| 2781 if (this.disabled) { | |
| 2782 this._setPressed(false); | |
| 2783 } else { | |
| 2784 this._changedButtonState(); | |
| 2785 } | |
| 2786 }, | |
| 2787 _changedButtonState: function() { | |
| 2788 if (this._buttonStateChanged) { | |
| 2789 this._buttonStateChanged(); | |
| 2790 } | |
| 2791 } | |
| 2792 }; | |
| 2793 | |
| 2794 Polymer.IronButtonState = [ Polymer.IronA11yKeysBehavior, Polymer.IronButtonStat
eImpl ]; | |
| 2795 | |
| 2796 (function() { | |
| 2797 var Utility = { | |
| 2798 distance: function(x1, y1, x2, y2) { | |
| 2799 var xDelta = x1 - x2; | |
| 2800 var yDelta = y1 - y2; | |
| 2801 return Math.sqrt(xDelta * xDelta + yDelta * yDelta); | |
| 2802 }, | |
| 2803 now: window.performance && window.performance.now ? window.performance.now.b
ind(window.performance) : Date.now | |
| 2804 }; | |
| 2805 function ElementMetrics(element) { | |
| 2806 this.element = element; | |
| 2807 this.width = this.boundingRect.width; | |
| 2808 this.height = this.boundingRect.height; | |
| 2809 this.size = Math.max(this.width, this.height); | |
| 2810 } | |
| 2811 ElementMetrics.prototype = { | |
| 2812 get boundingRect() { | |
| 2813 return this.element.getBoundingClientRect(); | |
| 2814 }, | |
| 2815 furthestCornerDistanceFrom: function(x, y) { | |
| 2816 var topLeft = Utility.distance(x, y, 0, 0); | |
| 2817 var topRight = Utility.distance(x, y, this.width, 0); | |
| 2818 var bottomLeft = Utility.distance(x, y, 0, this.height); | |
| 2819 var bottomRight = Utility.distance(x, y, this.width, this.height); | |
| 2820 return Math.max(topLeft, topRight, bottomLeft, bottomRight); | |
| 2821 } | |
| 2822 }; | |
| 2823 function Ripple(element) { | |
| 2824 this.element = element; | |
| 2825 this.color = window.getComputedStyle(element).color; | |
| 2826 this.wave = document.createElement('div'); | |
| 2827 this.waveContainer = document.createElement('div'); | |
| 2828 this.wave.style.backgroundColor = this.color; | |
| 2829 this.wave.classList.add('wave'); | |
| 2830 this.waveContainer.classList.add('wave-container'); | |
| 2831 Polymer.dom(this.waveContainer).appendChild(this.wave); | |
| 2832 this.resetInteractionState(); | |
| 2833 } | |
| 2834 Ripple.MAX_RADIUS = 300; | |
| 2835 Ripple.prototype = { | |
| 2836 get recenters() { | |
| 2837 return this.element.recenters; | |
| 2838 }, | |
| 2839 get center() { | |
| 2840 return this.element.center; | |
| 2841 }, | |
| 2842 get mouseDownElapsed() { | |
| 2843 var elapsed; | |
| 2844 if (!this.mouseDownStart) { | |
| 2845 return 0; | |
| 2846 } | |
| 2847 elapsed = Utility.now() - this.mouseDownStart; | |
| 2848 if (this.mouseUpStart) { | |
| 2849 elapsed -= this.mouseUpElapsed; | |
| 2850 } | |
| 2851 return elapsed; | |
| 2852 }, | |
| 2853 get mouseUpElapsed() { | |
| 2854 return this.mouseUpStart ? Utility.now() - this.mouseUpStart : 0; | |
| 2855 }, | |
| 2856 get mouseDownElapsedSeconds() { | |
| 2857 return this.mouseDownElapsed / 1e3; | |
| 2858 }, | |
| 2859 get mouseUpElapsedSeconds() { | |
| 2860 return this.mouseUpElapsed / 1e3; | |
| 2861 }, | |
| 2862 get mouseInteractionSeconds() { | |
| 2863 return this.mouseDownElapsedSeconds + this.mouseUpElapsedSeconds; | |
| 2864 }, | |
| 2865 get initialOpacity() { | |
| 2866 return this.element.initialOpacity; | |
| 2867 }, | |
| 2868 get opacityDecayVelocity() { | |
| 2869 return this.element.opacityDecayVelocity; | |
| 2870 }, | |
| 2871 get radius() { | |
| 2872 var width2 = this.containerMetrics.width * this.containerMetrics.width; | |
| 2873 var height2 = this.containerMetrics.height * this.containerMetrics.height; | |
| 2874 var waveRadius = Math.min(Math.sqrt(width2 + height2), Ripple.MAX_RADIUS)
* 1.1 + 5; | |
| 2875 var duration = 1.1 - .2 * (waveRadius / Ripple.MAX_RADIUS); | |
| 2876 var timeNow = this.mouseInteractionSeconds / duration; | |
| 2877 var size = waveRadius * (1 - Math.pow(80, -timeNow)); | |
| 2878 return Math.abs(size); | |
| 2879 }, | |
| 2880 get opacity() { | |
| 2881 if (!this.mouseUpStart) { | |
| 2882 return this.initialOpacity; | |
| 2883 } | |
| 2884 return Math.max(0, this.initialOpacity - this.mouseUpElapsedSeconds * this
.opacityDecayVelocity); | |
| 2885 }, | |
| 2886 get outerOpacity() { | |
| 2887 var outerOpacity = this.mouseUpElapsedSeconds * .3; | |
| 2888 var waveOpacity = this.opacity; | |
| 2889 return Math.max(0, Math.min(outerOpacity, waveOpacity)); | |
| 2890 }, | |
| 2891 get isOpacityFullyDecayed() { | |
| 2892 return this.opacity < .01 && this.radius >= Math.min(this.maxRadius, Rippl
e.MAX_RADIUS); | |
| 2893 }, | |
| 2894 get isRestingAtMaxRadius() { | |
| 2895 return this.opacity >= this.initialOpacity && this.radius >= Math.min(this
.maxRadius, Ripple.MAX_RADIUS); | |
| 2896 }, | |
| 2897 get isAnimationComplete() { | |
| 2898 return this.mouseUpStart ? this.isOpacityFullyDecayed : this.isRestingAtMa
xRadius; | |
| 2899 }, | |
| 2900 get translationFraction() { | |
| 2901 return Math.min(1, this.radius / this.containerMetrics.size * 2 / Math.sqr
t(2)); | |
| 2902 }, | |
| 2903 get xNow() { | |
| 2904 if (this.xEnd) { | |
| 2905 return this.xStart + this.translationFraction * (this.xEnd - this.xStart
); | |
| 2906 } | |
| 2907 return this.xStart; | |
| 2908 }, | |
| 2909 get yNow() { | |
| 2910 if (this.yEnd) { | |
| 2911 return this.yStart + this.translationFraction * (this.yEnd - this.yStart
); | |
| 2912 } | |
| 2913 return this.yStart; | |
| 2914 }, | |
| 2915 get isMouseDown() { | |
| 2916 return this.mouseDownStart && !this.mouseUpStart; | |
| 2917 }, | |
| 2918 resetInteractionState: function() { | |
| 2919 this.maxRadius = 0; | |
| 2920 this.mouseDownStart = 0; | |
| 2921 this.mouseUpStart = 0; | |
| 2922 this.xStart = 0; | |
| 2923 this.yStart = 0; | |
| 2924 this.xEnd = 0; | |
| 2925 this.yEnd = 0; | |
| 2926 this.slideDistance = 0; | |
| 2927 this.containerMetrics = new ElementMetrics(this.element); | |
| 2928 }, | |
| 2929 draw: function() { | |
| 2930 var scale; | |
| 2931 var translateString; | |
| 2932 var dx; | |
| 2933 var dy; | |
| 2934 this.wave.style.opacity = this.opacity; | |
| 2935 scale = this.radius / (this.containerMetrics.size / 2); | |
| 2936 dx = this.xNow - this.containerMetrics.width / 2; | |
| 2937 dy = this.yNow - this.containerMetrics.height / 2; | |
| 2938 this.waveContainer.style.webkitTransform = 'translate(' + dx + 'px, ' + dy
+ 'px)'; | |
| 2939 this.waveContainer.style.transform = 'translate3d(' + dx + 'px, ' + dy + '
px, 0)'; | |
| 2940 this.wave.style.webkitTransform = 'scale(' + scale + ',' + scale + ')'; | |
| 2941 this.wave.style.transform = 'scale3d(' + scale + ',' + scale + ',1)'; | |
| 2942 }, | |
| 2943 downAction: function(event) { | |
| 2944 var xCenter = this.containerMetrics.width / 2; | |
| 2945 var yCenter = this.containerMetrics.height / 2; | |
| 2946 this.resetInteractionState(); | |
| 2947 this.mouseDownStart = Utility.now(); | |
| 2948 if (this.center) { | |
| 2949 this.xStart = xCenter; | |
| 2950 this.yStart = yCenter; | |
| 2951 this.slideDistance = Utility.distance(this.xStart, this.yStart, this.xEn
d, this.yEnd); | |
| 2952 } else { | |
| 2953 this.xStart = event ? event.detail.x - this.containerMetrics.boundingRec
t.left : this.containerMetrics.width / 2; | |
| 2954 this.yStart = event ? event.detail.y - this.containerMetrics.boundingRec
t.top : this.containerMetrics.height / 2; | |
| 2955 } | |
| 2956 if (this.recenters) { | |
| 2957 this.xEnd = xCenter; | |
| 2958 this.yEnd = yCenter; | |
| 2959 this.slideDistance = Utility.distance(this.xStart, this.yStart, this.xEn
d, this.yEnd); | |
| 2960 } | |
| 2961 this.maxRadius = this.containerMetrics.furthestCornerDistanceFrom(this.xSt
art, this.yStart); | |
| 2962 this.waveContainer.style.top = (this.containerMetrics.height - this.contai
nerMetrics.size) / 2 + 'px'; | |
| 2963 this.waveContainer.style.left = (this.containerMetrics.width - this.contai
nerMetrics.size) / 2 + 'px'; | |
| 2964 this.waveContainer.style.width = this.containerMetrics.size + 'px'; | |
| 2965 this.waveContainer.style.height = this.containerMetrics.size + 'px'; | |
| 2966 }, | |
| 2967 upAction: function(event) { | |
| 2968 if (!this.isMouseDown) { | |
| 2969 return; | |
| 2970 } | |
| 2971 this.mouseUpStart = Utility.now(); | |
| 2972 }, | |
| 2973 remove: function() { | |
| 2974 Polymer.dom(this.waveContainer.parentNode).removeChild(this.waveContainer)
; | |
| 2975 } | |
| 2976 }; | |
| 2977 Polymer({ | |
| 2978 is: 'paper-ripple', | |
| 2979 behaviors: [ Polymer.IronA11yKeysBehavior ], | |
| 2980 properties: { | |
| 2981 initialOpacity: { | |
| 2982 type: Number, | |
| 2983 value: .25 | |
| 2984 }, | |
| 2985 opacityDecayVelocity: { | |
| 2986 type: Number, | |
| 2987 value: .8 | |
| 2988 }, | |
| 2989 recenters: { | |
| 2990 type: Boolean, | |
| 2991 value: false | |
| 2992 }, | |
| 2993 center: { | |
| 2994 type: Boolean, | |
| 2995 value: false | |
| 2996 }, | |
| 2997 ripples: { | |
| 2998 type: Array, | |
| 2999 value: function() { | |
| 3000 return []; | |
| 3001 } | |
| 3002 }, | |
| 3003 animating: { | |
| 3004 type: Boolean, | |
| 3005 readOnly: true, | |
| 3006 reflectToAttribute: true, | |
| 3007 value: false | |
| 3008 }, | |
| 3009 holdDown: { | |
| 3010 type: Boolean, | |
| 3011 value: false, | |
| 3012 observer: '_holdDownChanged' | |
| 3013 }, | |
| 3014 noink: { | |
| 3015 type: Boolean, | |
| 3016 value: false | |
| 3017 }, | |
| 3018 _animating: { | |
| 3019 type: Boolean | |
| 3020 }, | |
| 3021 _boundAnimate: { | |
| 3022 type: Function, | |
| 3023 value: function() { | |
| 3024 return this.animate.bind(this); | |
| 3025 } | |
| 3026 } | |
| 3027 }, | |
| 3028 get target() { | |
| 3029 return this.keyEventTarget; | |
| 3030 }, | |
| 3031 keyBindings: { | |
| 3032 'enter:keydown': '_onEnterKeydown', | |
| 3033 'space:keydown': '_onSpaceKeydown', | |
| 3034 'space:keyup': '_onSpaceKeyup' | |
| 3035 }, | |
| 3036 attached: function() { | |
| 3037 if (this.parentNode.nodeType == 11) { | |
| 3038 this.keyEventTarget = Polymer.dom(this).getOwnerRoot().host; | |
| 3039 } else { | |
| 3040 this.keyEventTarget = this.parentNode; | |
| 3041 } | |
| 3042 var keyEventTarget = this.keyEventTarget; | |
| 3043 this.listen(keyEventTarget, 'up', 'uiUpAction'); | |
| 3044 this.listen(keyEventTarget, 'down', 'uiDownAction'); | |
| 3045 }, | |
| 3046 detached: function() { | |
| 3047 this.unlisten(this.keyEventTarget, 'up', 'uiUpAction'); | |
| 3048 this.unlisten(this.keyEventTarget, 'down', 'uiDownAction'); | |
| 3049 this.keyEventTarget = null; | |
| 3050 }, | |
| 3051 get shouldKeepAnimating() { | |
| 3052 for (var index = 0; index < this.ripples.length; ++index) { | |
| 3053 if (!this.ripples[index].isAnimationComplete) { | |
| 3054 return true; | |
| 3055 } | |
| 3056 } | |
| 3057 return false; | |
| 3058 }, | |
| 3059 simulatedRipple: function() { | |
| 3060 this.downAction(null); | |
| 3061 this.async(function() { | |
| 3062 this.upAction(); | |
| 3063 }, 1); | |
| 3064 }, | |
| 3065 uiDownAction: function(event) { | |
| 3066 if (!this.noink) { | |
| 3067 this.downAction(event); | |
| 3068 } | |
| 3069 }, | |
| 3070 downAction: function(event) { | |
| 3071 if (this.holdDown && this.ripples.length > 0) { | |
| 3072 return; | |
| 3073 } | |
| 3074 var ripple = this.addRipple(); | |
| 3075 ripple.downAction(event); | |
| 3076 if (!this._animating) { | |
| 3077 this._animating = true; | |
| 3078 this.animate(); | |
| 3079 } | |
| 3080 }, | |
| 3081 uiUpAction: function(event) { | |
| 3082 if (!this.noink) { | |
| 3083 this.upAction(event); | |
| 3084 } | |
| 3085 }, | |
| 3086 upAction: function(event) { | |
| 3087 if (this.holdDown) { | |
| 3088 return; | |
| 3089 } | |
| 3090 this.ripples.forEach(function(ripple) { | |
| 3091 ripple.upAction(event); | |
| 3092 }); | |
| 3093 this._animating = true; | |
| 3094 this.animate(); | |
| 3095 }, | |
| 3096 onAnimationComplete: function() { | |
| 3097 this._animating = false; | |
| 3098 this.$.background.style.backgroundColor = null; | |
| 3099 this.fire('transitionend'); | |
| 3100 }, | |
| 3101 addRipple: function() { | |
| 3102 var ripple = new Ripple(this); | |
| 3103 Polymer.dom(this.$.waves).appendChild(ripple.waveContainer); | |
| 3104 this.$.background.style.backgroundColor = ripple.color; | |
| 3105 this.ripples.push(ripple); | |
| 3106 this._setAnimating(true); | |
| 3107 return ripple; | |
| 3108 }, | |
| 3109 removeRipple: function(ripple) { | |
| 3110 var rippleIndex = this.ripples.indexOf(ripple); | |
| 3111 if (rippleIndex < 0) { | |
| 3112 return; | |
| 3113 } | |
| 3114 this.ripples.splice(rippleIndex, 1); | |
| 3115 ripple.remove(); | |
| 3116 if (!this.ripples.length) { | |
| 3117 this._setAnimating(false); | |
| 3118 } | |
| 3119 }, | |
| 3120 animate: function() { | |
| 3121 if (!this._animating) { | |
| 3122 return; | |
| 3123 } | |
| 3124 var index; | |
| 3125 var ripple; | |
| 3126 for (index = 0; index < this.ripples.length; ++index) { | |
| 3127 ripple = this.ripples[index]; | |
| 3128 ripple.draw(); | |
| 3129 this.$.background.style.opacity = ripple.outerOpacity; | |
| 3130 if (ripple.isOpacityFullyDecayed && !ripple.isRestingAtMaxRadius) { | |
| 3131 this.removeRipple(ripple); | |
| 3132 } | |
| 3133 } | |
| 3134 if (!this.shouldKeepAnimating && this.ripples.length === 0) { | |
| 3135 this.onAnimationComplete(); | |
| 3136 } else { | |
| 3137 window.requestAnimationFrame(this._boundAnimate); | |
| 3138 } | |
| 3139 }, | |
| 3140 _onEnterKeydown: function() { | |
| 3141 this.uiDownAction(); | |
| 3142 this.async(this.uiUpAction, 1); | |
| 3143 }, | |
| 3144 _onSpaceKeydown: function() { | |
| 3145 this.uiDownAction(); | |
| 3146 }, | |
| 3147 _onSpaceKeyup: function() { | |
| 3148 this.uiUpAction(); | |
| 3149 }, | |
| 3150 _holdDownChanged: function(newVal, oldVal) { | |
| 3151 if (oldVal === undefined) { | |
| 3152 return; | |
| 3153 } | |
| 3154 if (newVal) { | |
| 3155 this.downAction(); | |
| 3156 } else { | |
| 3157 this.upAction(); | |
| 3158 } | |
| 3159 } | |
| 3160 }); | |
| 3161 })(); | |
| 3162 | |
| 3163 Polymer.PaperRippleBehavior = { | |
| 3164 properties: { | |
| 3165 noink: { | |
| 3166 type: Boolean, | |
| 3167 observer: '_noinkChanged' | |
| 3168 }, | |
| 3169 _rippleContainer: { | |
| 3170 type: Object | |
| 3171 } | |
| 3172 }, | |
| 3173 _buttonStateChanged: function() { | |
| 3174 if (this.focused) { | |
| 3175 this.ensureRipple(); | |
| 3176 } | |
| 3177 }, | |
| 3178 _downHandler: function(event) { | |
| 3179 Polymer.IronButtonStateImpl._downHandler.call(this, event); | |
| 3180 if (this.pressed) { | |
| 3181 this.ensureRipple(event); | |
| 3182 } | |
| 3183 }, | |
| 3184 ensureRipple: function(optTriggeringEvent) { | |
| 3185 if (!this.hasRipple()) { | |
| 3186 this._ripple = this._createRipple(); | |
| 3187 this._ripple.noink = this.noink; | |
| 3188 var rippleContainer = this._rippleContainer || this.root; | |
| 3189 if (rippleContainer) { | |
| 3190 Polymer.dom(rippleContainer).appendChild(this._ripple); | |
| 3191 } | |
| 3192 if (optTriggeringEvent) { | |
| 3193 var domContainer = Polymer.dom(this._rippleContainer || this); | |
| 3194 var target = Polymer.dom(optTriggeringEvent).rootTarget; | |
| 3195 if (domContainer.deepContains(target)) { | |
| 3196 this._ripple.uiDownAction(optTriggeringEvent); | |
| 3197 } | |
| 3198 } | |
| 3199 } | |
| 3200 }, | |
| 3201 getRipple: function() { | |
| 3202 this.ensureRipple(); | |
| 3203 return this._ripple; | |
| 3204 }, | |
| 3205 hasRipple: function() { | |
| 3206 return Boolean(this._ripple); | |
| 3207 }, | |
| 3208 _createRipple: function() { | |
| 3209 return document.createElement('paper-ripple'); | |
| 3210 }, | |
| 3211 _noinkChanged: function(noink) { | |
| 3212 if (this.hasRipple()) { | |
| 3213 this._ripple.noink = noink; | |
| 3214 } | |
| 3215 } | |
| 3216 }; | |
| 3217 | |
| 3218 Polymer.PaperButtonBehaviorImpl = { | |
| 3219 properties: { | |
| 3220 elevation: { | |
| 3221 type: Number, | |
| 3222 reflectToAttribute: true, | |
| 3223 readOnly: true | |
| 3224 } | |
| 3225 }, | |
| 3226 observers: [ '_calculateElevation(focused, disabled, active, pressed, received
FocusFromKeyboard)', '_computeKeyboardClass(receivedFocusFromKeyboard)' ], | |
| 3227 hostAttributes: { | |
| 3228 role: 'button', | |
| 3229 tabindex: '0', | |
| 3230 animated: true | |
| 3231 }, | |
| 3232 _calculateElevation: function() { | |
| 3233 var e = 1; | |
| 3234 if (this.disabled) { | |
| 3235 e = 0; | |
| 3236 } else if (this.active || this.pressed) { | |
| 3237 e = 4; | |
| 3238 } else if (this.receivedFocusFromKeyboard) { | |
| 3239 e = 3; | |
| 3240 } | |
| 3241 this._setElevation(e); | |
| 3242 }, | |
| 3243 _computeKeyboardClass: function(receivedFocusFromKeyboard) { | |
| 3244 this.toggleClass('keyboard-focus', receivedFocusFromKeyboard); | |
| 3245 }, | |
| 3246 _spaceKeyDownHandler: function(event) { | |
| 3247 Polymer.IronButtonStateImpl._spaceKeyDownHandler.call(this, event); | |
| 3248 if (this.hasRipple() && this.getRipple().ripples.length < 1) { | |
| 3249 this._ripple.uiDownAction(); | |
| 3250 } | |
| 3251 }, | |
| 3252 _spaceKeyUpHandler: function(event) { | |
| 3253 Polymer.IronButtonStateImpl._spaceKeyUpHandler.call(this, event); | |
| 3254 if (this.hasRipple()) { | |
| 3255 this._ripple.uiUpAction(); | |
| 3256 } | |
| 3257 } | |
| 3258 }; | |
| 3259 | |
| 3260 Polymer.PaperButtonBehavior = [ Polymer.IronButtonState, Polymer.IronControlStat
e, Polymer.PaperRippleBehavior, Polymer.PaperButtonBehaviorImpl ]; | |
| 3261 | |
| 3262 Polymer({ | |
| 3263 is: 'paper-button', | |
| 3264 behaviors: [ Polymer.PaperButtonBehavior ], | |
| 3265 properties: { | |
| 3266 raised: { | |
| 3267 type: Boolean, | |
| 3268 reflectToAttribute: true, | |
| 3269 value: false, | |
| 3270 observer: '_calculateElevation' | |
| 3271 } | |
| 3272 }, | |
| 3273 _calculateElevation: function() { | |
| 3274 if (!this.raised) { | |
| 3275 this._setElevation(0); | |
| 3276 } else { | |
| 3277 Polymer.PaperButtonBehaviorImpl._calculateElevation.apply(this); | |
| 3278 } | |
| 3279 } | |
| 3280 }); | |
| 3281 | |
| 3282 Polymer({ | |
| 3283 is: 'paper-icon-button-light', | |
| 3284 "extends": 'button', | |
| 3285 behaviors: [ Polymer.PaperRippleBehavior ], | |
| 3286 listeners: { | |
| 3287 down: '_rippleDown', | |
| 3288 up: '_rippleUp', | |
| 3289 focus: '_rippleDown', | |
| 3290 blur: '_rippleUp' | |
| 3291 }, | |
| 3292 _rippleDown: function() { | |
| 3293 this.getRipple().downAction(); | |
| 3294 }, | |
| 3295 _rippleUp: function() { | |
| 3296 this.getRipple().upAction(); | |
| 3297 }, | |
| 3298 ensureRipple: function(var_args) { | |
| 3299 var lastRipple = this._ripple; | |
| 3300 Polymer.PaperRippleBehavior.ensureRipple.apply(this, arguments); | |
| 3301 if (this._ripple && this._ripple !== lastRipple) { | |
| 3302 this._ripple.center = true; | |
| 3303 this._ripple.classList.add('circle'); | |
| 3304 } | |
| 3305 } | |
| 3306 }); | |
| 3307 | |
| 3308 Polymer.IronRangeBehavior = { | |
| 3309 properties: { | |
| 3310 value: { | |
| 3311 type: Number, | |
| 3312 value: 0, | |
| 3313 notify: true, | |
| 3314 reflectToAttribute: true | |
| 3315 }, | |
| 3316 min: { | |
| 3317 type: Number, | |
| 3318 value: 0, | |
| 3319 notify: true | |
| 3320 }, | |
| 3321 max: { | |
| 3322 type: Number, | |
| 3323 value: 100, | |
| 3324 notify: true | |
| 3325 }, | |
| 3326 step: { | |
| 3327 type: Number, | |
| 3328 value: 1, | |
| 3329 notify: true | |
| 3330 }, | |
| 3331 ratio: { | |
| 3332 type: Number, | |
| 3333 value: 0, | |
| 3334 readOnly: true, | |
| 3335 notify: true | |
| 3336 } | |
| 3337 }, | |
| 3338 observers: [ '_update(value, min, max, step)' ], | |
| 3339 _calcRatio: function(value) { | |
| 3340 return (this._clampValue(value) - this.min) / (this.max - this.min); | |
| 3341 }, | |
| 3342 _clampValue: function(value) { | |
| 3343 return Math.min(this.max, Math.max(this.min, this._calcStep(value))); | |
| 3344 }, | |
| 3345 _calcStep: function(value) { | |
| 3346 value = parseFloat(value); | |
| 3347 if (!this.step) { | |
| 3348 return value; | |
| 3349 } | |
| 3350 var numSteps = Math.round((value - this.min) / this.step); | |
| 3351 if (this.step < 1) { | |
| 3352 return numSteps / (1 / this.step) + this.min; | |
| 3353 } else { | |
| 3354 return numSteps * this.step + this.min; | |
| 3355 } | |
| 3356 }, | |
| 3357 _validateValue: function() { | |
| 3358 var v = this._clampValue(this.value); | |
| 3359 this.value = this.oldValue = isNaN(v) ? this.oldValue : v; | |
| 3360 return this.value !== v; | |
| 3361 }, | |
| 3362 _update: function() { | |
| 3363 this._validateValue(); | |
| 3364 this._setRatio(this._calcRatio(this.value) * 100); | |
| 3365 } | |
| 3366 }; | |
| 3367 | |
| 3368 Polymer({ | |
| 3369 is: 'paper-progress', | |
| 3370 behaviors: [ Polymer.IronRangeBehavior ], | |
| 3371 properties: { | |
| 3372 secondaryProgress: { | |
| 3373 type: Number, | |
| 3374 value: 0 | |
| 3375 }, | |
| 3376 secondaryRatio: { | |
| 3377 type: Number, | |
| 3378 value: 0, | |
| 3379 readOnly: true | |
| 3380 }, | |
| 3381 indeterminate: { | |
| 3382 type: Boolean, | |
| 3383 value: false, | |
| 3384 observer: '_toggleIndeterminate' | |
| 3385 }, | |
| 3386 disabled: { | |
| 3387 type: Boolean, | |
| 3388 value: false, | |
| 3389 reflectToAttribute: true, | |
| 3390 observer: '_disabledChanged' | |
| 3391 } | |
| 3392 }, | |
| 3393 observers: [ '_progressChanged(secondaryProgress, value, min, max)' ], | |
| 3394 hostAttributes: { | |
| 3395 role: 'progressbar' | |
| 3396 }, | |
| 3397 _toggleIndeterminate: function(indeterminate) { | |
| 3398 this.toggleClass('indeterminate', indeterminate, this.$.primaryProgress); | |
| 3399 }, | |
| 3400 _transformProgress: function(progress, ratio) { | |
| 3401 var transform = 'scaleX(' + ratio / 100 + ')'; | |
| 3402 progress.style.transform = progress.style.webkitTransform = transform; | |
| 3403 }, | |
| 3404 _mainRatioChanged: function(ratio) { | |
| 3405 this._transformProgress(this.$.primaryProgress, ratio); | |
| 3406 }, | |
| 3407 _progressChanged: function(secondaryProgress, value, min, max) { | |
| 3408 secondaryProgress = this._clampValue(secondaryProgress); | |
| 3409 value = this._clampValue(value); | |
| 3410 var secondaryRatio = this._calcRatio(secondaryProgress) * 100; | |
| 3411 var mainRatio = this._calcRatio(value) * 100; | |
| 3412 this._setSecondaryRatio(secondaryRatio); | |
| 3413 this._transformProgress(this.$.secondaryProgress, secondaryRatio); | |
| 3414 this._transformProgress(this.$.primaryProgress, mainRatio); | |
| 3415 this.secondaryProgress = secondaryProgress; | |
| 3416 this.setAttribute('aria-valuenow', value); | |
| 3417 this.setAttribute('aria-valuemin', min); | |
| 3418 this.setAttribute('aria-valuemax', max); | |
| 3419 }, | |
| 3420 _disabledChanged: function(disabled) { | |
| 3421 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); | |
| 3422 }, | |
| 3423 _hideSecondaryProgress: function(secondaryRatio) { | |
| 3424 return secondaryRatio === 0; | |
| 3425 } | |
| 3426 }); | |
| 3427 | |
| 3428 Polymer({ | |
| 3429 is: 'iron-iconset-svg', | |
| 3430 properties: { | |
| 3431 name: { | |
| 3432 type: String, | |
| 3433 observer: '_nameChanged' | |
| 3434 }, | |
| 3435 size: { | |
| 3436 type: Number, | |
| 3437 value: 24 | |
| 3438 } | |
| 3439 }, | |
| 3440 attached: function() { | |
| 3441 this.style.display = 'none'; | |
| 3442 }, | |
| 3443 getIconNames: function() { | |
| 3444 this._icons = this._createIconMap(); | |
| 3445 return Object.keys(this._icons).map(function(n) { | |
| 3446 return this.name + ':' + n; | |
| 3447 }, this); | |
| 3448 }, | |
| 3449 applyIcon: function(element, iconName) { | |
| 3450 element = element.root || element; | |
| 3451 this.removeIcon(element); | |
| 3452 var svg = this._cloneIcon(iconName); | |
| 3453 if (svg) { | |
| 3454 var pde = Polymer.dom(element); | |
| 3455 pde.insertBefore(svg, pde.childNodes[0]); | |
| 3456 return element._svgIcon = svg; | |
| 3457 } | |
| 3458 return null; | |
| 3459 }, | |
| 3460 removeIcon: function(element) { | |
| 3461 if (element._svgIcon) { | |
| 3462 Polymer.dom(element).removeChild(element._svgIcon); | |
| 3463 element._svgIcon = null; | |
| 3464 } | |
| 3465 }, | |
| 3466 _nameChanged: function() { | |
| 3467 new Polymer.IronMeta({ | |
| 3468 type: 'iconset', | |
| 3469 key: this.name, | |
| 3470 value: this | |
| 3471 }); | |
| 3472 this.async(function() { | |
| 3473 this.fire('iron-iconset-added', this, { | |
| 3474 node: window | |
| 3475 }); | |
| 3476 }); | |
| 3477 }, | |
| 3478 _createIconMap: function() { | |
| 3479 var icons = Object.create(null); | |
| 3480 Polymer.dom(this).querySelectorAll('[id]').forEach(function(icon) { | |
| 3481 icons[icon.id] = icon; | |
| 3482 }); | |
| 3483 return icons; | |
| 3484 }, | |
| 3485 _cloneIcon: function(id) { | |
| 3486 this._icons = this._icons || this._createIconMap(); | |
| 3487 return this._prepareSvgClone(this._icons[id], this.size); | |
| 3488 }, | |
| 3489 _prepareSvgClone: function(sourceSvg, size) { | |
| 3490 if (sourceSvg) { | |
| 3491 var content = sourceSvg.cloneNode(true), svg = document.createElementNS('h
ttp://www.w3.org/2000/svg', 'svg'), viewBox = content.getAttribute('viewBox') ||
'0 0 ' + size + ' ' + size; | |
| 3492 svg.setAttribute('viewBox', viewBox); | |
| 3493 svg.setAttribute('preserveAspectRatio', 'xMidYMid meet'); | |
| 3494 svg.style.cssText = 'pointer-events: none; display: block; width: 100%; he
ight: 100%;'; | |
| 3495 svg.appendChild(content).removeAttribute('id'); | |
| 3496 return svg; | |
| 3497 } | |
| 3498 return null; | |
| 3499 } | |
| 3500 }); | |
| 3501 | |
| 3502 // Copyright 2015 The Chromium Authors. All rights reserved. | 43 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 3503 // Use of this source code is governed by a BSD-style license that can be | 44 // Use of this source code is governed by a BSD-style license that can be |
| 3504 // found in the LICENSE file. | 45 // found in the LICENSE file. |
| 3505 cr.define('downloads', function() { | 46 cr.define("downloads",function(){var Item=Polymer({is:"downloads-item",propertie
s:{data:{type:Object},completelyOnDisk_:{computed:"computeCompletelyOnDisk_("+"d
ata.state, data.file_externally_removed)",type:Boolean,value:true},controlledBy_
:{computed:"computeControlledBy_(data.by_ext_id, data.by_ext_name)",type:String,
value:""},isActive_:{computed:"computeIsActive_("+"data.state, data.file_externa
lly_removed)",type:Boolean,value:true},isDangerous_:{computed:"computeIsDangerou
s_(data.state)",type:Boolean,value:false},isMalware_:{computed:"computeIsMalware
_(isDangerous_, data.danger_type)",type:Boolean,value:false},isInProgress_:{comp
uted:"computeIsInProgress_(data.state)",type:Boolean,value:false},pauseOrResumeT
ext_:{computed:"computePauseOrResumeText_(isInProgress_, data.resume)",type:Stri
ng},showCancel_:{computed:"computeShowCancel_(data.state)",type:Boolean,value:fa
lse},showProgress_:{computed:"computeShowProgress_(showCancel_, data.percent)",t
ype:Boolean,value:false}},observers:["observeControlledBy_(controlledBy_)","obse
rveIsDangerous_(isDangerous_, data)"],ready:function(){this.content=this.$.conte
nt},computeClass_:function(){var classes=[];if(this.isActive_)classes.push("is-a
ctive");if(this.isDangerous_)classes.push("dangerous");if(this.showProgress_)cla
sses.push("show-progress");return classes.join(" ")},computeCompletelyOnDisk_:fu
nction(){return this.data.state==downloads.States.COMPLETE&&!this.data.file_exte
rnally_removed},computeControlledBy_:function(){if(!this.data.by_ext_id||!this.d
ata.by_ext_name)return"";var url="chrome://extensions#"+this.data.by_ext_id;var
name=this.data.by_ext_name;return loadTimeData.getStringF("controlledByUrl",url,
name)},computeDangerIcon_:function(){if(!this.isDangerous_)return"";switch(this.
data.danger_type){case downloads.DangerType.DANGEROUS_CONTENT:case downloads.Dan
gerType.DANGEROUS_HOST:case downloads.DangerType.DANGEROUS_URL:case downloads.Da
ngerType.POTENTIALLY_UNWANTED:case downloads.DangerType.UNCOMMON_CONTENT:return"
downloads:remove-circle";default:return"cr:warning"}},computeDate_:function(){as
sert(typeof this.data.hideDate=="boolean");if(this.data.hideDate)return"";return
assert(this.data.since_string||this.data.date_string)},computeDescription_:func
tion(){var data=this.data;switch(data.state){case downloads.States.DANGEROUS:var
fileName=data.file_name;switch(data.danger_type){case downloads.DangerType.DANG
EROUS_FILE:return loadTimeData.getString("dangerFileDesc");case downloads.Danger
Type.DANGEROUS_URL:case downloads.DangerType.DANGEROUS_CONTENT:case downloads.Da
ngerType.DANGEROUS_HOST:return loadTimeData.getString("dangerDownloadDesc");case
downloads.DangerType.UNCOMMON_CONTENT:return loadTimeData.getString("dangerUnco
mmonDesc");case downloads.DangerType.POTENTIALLY_UNWANTED:return loadTimeData.ge
tString("dangerSettingsDesc")}break;case downloads.States.IN_PROGRESS:case downl
oads.States.PAUSED:return data.progress_status_text}return""},computeIsActive_:f
unction(){return this.data.state!=downloads.States.CANCELLED&&this.data.state!=d
ownloads.States.INTERRUPTED&&!this.data.file_externally_removed},computeIsDanger
ous_:function(){return this.data.state==downloads.States.DANGEROUS},computeIsInP
rogress_:function(){return this.data.state==downloads.States.IN_PROGRESS},comput
eIsMalware_:function(){return this.isDangerous_&&(this.data.danger_type==downloa
ds.DangerType.DANGEROUS_CONTENT||this.data.danger_type==downloads.DangerType.DAN
GEROUS_HOST||this.data.danger_type==downloads.DangerType.DANGEROUS_URL||this.dat
a.danger_type==downloads.DangerType.POTENTIALLY_UNWANTED)},computePauseOrResumeT
ext_:function(){if(this.isInProgress_)return loadTimeData.getString("controlPaus
e");if(this.data.resume)return loadTimeData.getString("controlResume");return""}
,computeRemoveStyle_:function(){var canDelete=loadTimeData.getBoolean("allowDele
tingHistory");var hideRemove=this.isDangerous_||this.showCancel_||!canDelete;ret
urn hideRemove?"visibility: hidden":""},computeShowCancel_:function(){return thi
s.data.state==downloads.States.IN_PROGRESS||this.data.state==downloads.States.PA
USED},computeShowProgress_:function(){return this.showCancel_&&this.data.percent
>=-1},computeTag_:function(){switch(this.data.state){case downloads.States.CANCE
LLED:return loadTimeData.getString("statusCancelled");case downloads.States.INTE
RRUPTED:return this.data.last_reason_text;case downloads.States.COMPLETE:return
this.data.file_externally_removed?loadTimeData.getString("statusRemoved"):""}ret
urn""},isIndeterminate_:function(){return this.data.percent==-1},observeControll
edBy_:function(){this.$["controlled-by"].innerHTML=this.controlledBy_},observeIs
Dangerous_:function(){if(!this.data)return;if(this.isDangerous_){this.$.url.remo
veAttribute("href")}else{this.$.url.href=assert(this.data.url);var filePath=enco
deURIComponent(this.data.file_path);var scaleFactor="?scale="+window.devicePixel
Ratio+"x";this.$["file-icon"].src="chrome://fileicon/"+filePath+scaleFactor}},on
CancelTap_:function(){downloads.ActionService.getInstance().cancel(this.data.id)
},onDiscardDangerousTap_:function(){downloads.ActionService.getInstance().discar
dDangerous(this.data.id)},onDragStart_:function(e){e.preventDefault();downloads.
ActionService.getInstance().drag(this.data.id)},onFileLinkTap_:function(e){e.pre
ventDefault();downloads.ActionService.getInstance().openFile(this.data.id)},onPa
useOrResumeTap_:function(){if(this.isInProgress_)downloads.ActionService.getInst
ance().pause(this.data.id);else downloads.ActionService.getInstance().resume(thi
s.data.id)},onRemoveTap_:function(){downloads.ActionService.getInstance().remove
(this.data.id)},onRetryTap_:function(){downloads.ActionService.getInstance().dow
nload(this.data.url)},onSaveDangerousTap_:function(){downloads.ActionService.get
Instance().saveDangerous(this.data.id)},onShowTap_:function(){downloads.ActionSe
rvice.getInstance().show(this.data.id)}});return{Item:Item}});Polymer.PaperItemB
ehaviorImpl={hostAttributes:{role:"option",tabindex:"0"}};Polymer.PaperItemBehav
ior=[Polymer.IronButtonState,Polymer.IronControlState,Polymer.PaperItemBehaviorI
mpl];Polymer({is:"paper-item",behaviors:[Polymer.PaperItemBehavior]});Polymer.Ir
onSelection=function(selectCallback){this.selection=[];this.selectCallback=selec
tCallback};Polymer.IronSelection.prototype={get:function(){return this.multi?thi
s.selection.slice():this.selection[0]},clear:function(excludes){this.selection.s
lice().forEach(function(item){if(!excludes||excludes.indexOf(item)<0){this.setIt
emSelected(item,false)}},this)},isSelected:function(item){return this.selection.
indexOf(item)>=0},setItemSelected:function(item,isSelected){if(item!=null){if(is
Selected!==this.isSelected(item)){if(isSelected){this.selection.push(item)}else{
var i=this.selection.indexOf(item);if(i>=0){this.selection.splice(i,1)}}if(this.
selectCallback){this.selectCallback(item,isSelected)}}}},select:function(item){i
f(this.multi){this.toggle(item)}else if(this.get()!==item){this.setItemSelected(
this.get(),false);this.setItemSelected(item,true)}},toggle:function(item){this.s
etItemSelected(item,!this.isSelected(item))}};Polymer.IronSelectableBehavior={pr
operties:{attrForSelected:{type:String,value:null},selected:{type:String,notify:
true},selectedItem:{type:Object,readOnly:true,notify:true},activateEvent:{type:S
tring,value:"tap",observer:"_activateEventChanged"},selectable:String,selectedCl
ass:{type:String,value:"iron-selected"},selectedAttribute:{type:String,value:nul
l},fallbackSelection:{type:String,value:null},items:{type:Array,readOnly:true,no
tify:true,value:function(){return[]}},_excludedLocalNames:{type:Object,value:fun
ction(){return{template:1}}}},observers:["_updateAttrForSelected(attrForSelected
)","_updateSelected(selected)","_checkFallback(fallbackSelection)"],created:func
tion(){this._bindFilterItem=this._filterItem.bind(this);this._selection=new Poly
mer.IronSelection(this._applySelection.bind(this))},attached:function(){this._ob
server=this._observeItems(this);this._updateItems();if(!this._shouldUpdateSelect
ion){this._updateSelected()}this._addListener(this.activateEvent)},detached:func
tion(){if(this._observer){Polymer.dom(this).unobserveNodes(this._observer)}this.
_removeListener(this.activateEvent)},indexOf:function(item){return this.items.in
dexOf(item)},select:function(value){this.selected=value},selectPrevious:function
(){var length=this.items.length;var index=(Number(this._valueToIndex(this.select
ed))-1+length)%length;this.selected=this._indexToValue(index)},selectNext:functi
on(){var index=(Number(this._valueToIndex(this.selected))+1)%this.items.length;t
his.selected=this._indexToValue(index)},selectIndex:function(index){this.select(
this._indexToValue(index))},forceSynchronousItemUpdate:function(){this._updateIt
ems()},get _shouldUpdateSelection(){return this.selected!=null},_checkFallback:f
unction(){if(this._shouldUpdateSelection){this._updateSelected()}},_addListener:
function(eventName){this.listen(this,eventName,"_activateHandler")},_removeListe
ner:function(eventName){this.unlisten(this,eventName,"_activateHandler")},_activ
ateEventChanged:function(eventName,old){this._removeListener(old);this._addListe
ner(eventName)},_updateItems:function(){var nodes=Polymer.dom(this).queryDistrib
utedElements(this.selectable||"*");nodes=Array.prototype.filter.call(nodes,this.
_bindFilterItem);this._setItems(nodes)},_updateAttrForSelected:function(){if(thi
s._shouldUpdateSelection){this.selected=this._indexToValue(this.indexOf(this.sel
ectedItem))}},_updateSelected:function(){this._selectSelected(this.selected)},_s
electSelected:function(selected){this._selection.select(this._valueToItem(this.s
elected));if(this.fallbackSelection&&this.items.length&&this._selection.get()===
undefined){this.selected=this.fallbackSelection}},_filterItem:function(node){ret
urn!this._excludedLocalNames[node.localName]},_valueToItem:function(value){retur
n value==null?null:this.items[this._valueToIndex(value)]},_valueToIndex:function
(value){if(this.attrForSelected){for(var i=0,item;item=this.items[i];i++){if(thi
s._valueForItem(item)==value){return i}}}else{return Number(value)}},_indexToVal
ue:function(index){if(this.attrForSelected){var item=this.items[index];if(item){
return this._valueForItem(item)}}else{return index}},_valueForItem:function(item
){var propValue=item[Polymer.CaseMap.dashToCamelCase(this.attrForSelected)];retu
rn propValue!=undefined?propValue:item.getAttribute(this.attrForSelected)},_appl
ySelection:function(item,isSelected){if(this.selectedClass){this.toggleClass(thi
s.selectedClass,isSelected,item)}if(this.selectedAttribute){this.toggleAttribute
(this.selectedAttribute,isSelected,item)}this._selectionChange();this.fire("iron
-"+(isSelected?"select":"deselect"),{item:item})},_selectionChange:function(){th
is._setSelectedItem(this._selection.get())},_observeItems:function(node){return
Polymer.dom(node).observeNodes(function(mutation){this._updateItems();if(this._s
houldUpdateSelection){this._updateSelected()}this.fire("iron-items-changed",muta
tion,{bubbles:false,cancelable:false})})},_activateHandler:function(e){var t=e.t
arget;var items=this.items;while(t&&t!=this){var i=items.indexOf(t);if(i>=0){var
value=this._indexToValue(i);this._itemActivate(value,t);return}t=t.parentNode}}
,_itemActivate:function(value,item){if(!this.fire("iron-activate",{selected:valu
e,item:item},{cancelable:true}).defaultPrevented){this.select(value)}}};Polymer.
IronMultiSelectableBehaviorImpl={properties:{multi:{type:Boolean,value:false,obs
erver:"multiChanged"},selectedValues:{type:Array,notify:true},selectedItems:{typ
e:Array,readOnly:true,notify:true}},observers:["_updateSelected(selectedValues.s
plices)"],select:function(value){if(this.multi){if(this.selectedValues){this._to
ggleSelected(value)}else{this.selectedValues=[value]}}else{this.selected=value}}
,multiChanged:function(multi){this._selection.multi=multi},get _shouldUpdateSele
ction(){return this.selected!=null||this.selectedValues!=null&&this.selectedValu
es.length},_updateAttrForSelected:function(){if(!this.multi){Polymer.IronSelecta
bleBehavior._updateAttrForSelected.apply(this)}else if(this._shouldUpdateSelecti
on){this.selectedValues=this.selectedItems.map(function(selectedItem){return thi
s._indexToValue(this.indexOf(selectedItem))},this).filter(function(unfilteredVal
ue){return unfilteredValue!=null},this)}},_updateSelected:function(){if(this.mul
ti){this._selectMulti(this.selectedValues)}else{this._selectSelected(this.select
ed)}},_selectMulti:function(values){if(values){var selectedItems=this._valuesToI
tems(values);this._selection.clear(selectedItems);for(var i=0;i<selectedItems.le
ngth;i++){this._selection.setItemSelected(selectedItems[i],true)}if(this.fallbac
kSelection&&this.items.length&&!this._selection.get().length){var fallback=this.
_valueToItem(this.fallbackSelection);if(fallback){this.selectedValues=[this.fall
backSelection]}}}else{this._selection.clear()}},_selectionChange:function(){var
s=this._selection.get();if(this.multi){this._setSelectedItems(s)}else{this._setS
electedItems([s]);this._setSelectedItem(s)}},_toggleSelected:function(value){var
i=this.selectedValues.indexOf(value);var unselected=i<0;if(unselected){this.pus
h("selectedValues",value)}else{this.splice("selectedValues",i,1)}},_valuesToItem
s:function(values){return values==null?null:values.map(function(value){return th
is._valueToItem(value)},this)}};Polymer.IronMultiSelectableBehavior=[Polymer.Iro
nSelectableBehavior,Polymer.IronMultiSelectableBehaviorImpl];Polymer.IronMenuBeh
aviorImpl={properties:{focusedItem:{observer:"_focusedItemChanged",readOnly:true
,type:Object},attrForItemTitle:{type:String}},hostAttributes:{role:"menu",tabind
ex:"0"},observers:["_updateMultiselectable(multi)"],listeners:{focus:"_onFocus",
keydown:"_onKeydown","iron-items-changed":"_onIronItemsChanged"},keyBindings:{up
:"_onUpKey",down:"_onDownKey",esc:"_onEscKey","shift+tab:keydown":"_onShiftTabDo
wn"},attached:function(){this._resetTabindices()},select:function(value){if(this
._defaultFocusAsync){this.cancelAsync(this._defaultFocusAsync);this._defaultFocu
sAsync=null}var item=this._valueToItem(value);if(item&&item.hasAttribute("disabl
ed"))return;this._setFocusedItem(item);Polymer.IronMultiSelectableBehaviorImpl.s
elect.apply(this,arguments)},_resetTabindices:function(){var selectedItem=this.m
ulti?this.selectedItems&&this.selectedItems[0]:this.selectedItem;this.items.forE
ach(function(item){item.setAttribute("tabindex",item===selectedItem?"0":"-1")},t
his)},_updateMultiselectable:function(multi){if(multi){this.setAttribute("aria-m
ultiselectable","true")}else{this.removeAttribute("aria-multiselectable")}},_foc
usWithKeyboardEvent:function(event){for(var i=0,item;item=this.items[i];i++){var
attr=this.attrForItemTitle||"textContent";var title=item[attr]||item.getAttribu
te(attr);if(!item.hasAttribute("disabled")&&title&&title.trim().charAt(0).toLowe
rCase()===String.fromCharCode(event.keyCode).toLowerCase()){this._setFocusedItem
(item);break}}},_focusPrevious:function(){var length=this.items.length;var curFo
cusIndex=Number(this.indexOf(this.focusedItem));for(var i=1;i<length+1;i++){var
item=this.items[(curFocusIndex-i+length)%length];if(!item.hasAttribute("disabled
")){var owner=Polymer.dom(item).getOwnerRoot()||document;this._setFocusedItem(it
em);if(Polymer.dom(owner).activeElement==item){return}}}},_focusNext:function(){
var length=this.items.length;var curFocusIndex=Number(this.indexOf(this.focusedI
tem));for(var i=1;i<length+1;i++){var item=this.items[(curFocusIndex+i)%length];
if(!item.hasAttribute("disabled")){var owner=Polymer.dom(item).getOwnerRoot()||d
ocument;this._setFocusedItem(item);if(Polymer.dom(owner).activeElement==item){re
turn}}}},_applySelection:function(item,isSelected){if(isSelected){item.setAttrib
ute("aria-selected","true")}else{item.removeAttribute("aria-selected")}Polymer.I
ronSelectableBehavior._applySelection.apply(this,arguments)},_focusedItemChanged
:function(focusedItem,old){old&&old.setAttribute("tabindex","-1");if(focusedItem
){focusedItem.setAttribute("tabindex","0");focusedItem.focus()}},_onIronItemsCha
nged:function(event){if(event.detail.addedNodes.length){this._resetTabindices()}
},_onShiftTabDown:function(event){var oldTabIndex=this.getAttribute("tabindex");
Polymer.IronMenuBehaviorImpl._shiftTabPressed=true;this._setFocusedItem(null);th
is.setAttribute("tabindex","-1");this.async(function(){this.setAttribute("tabind
ex",oldTabIndex);Polymer.IronMenuBehaviorImpl._shiftTabPressed=false},1)},_onFoc
us:function(event){if(Polymer.IronMenuBehaviorImpl._shiftTabPressed){return}var
rootTarget=Polymer.dom(event).rootTarget;if(rootTarget!==this&&typeof rootTarget
.tabIndex!=="undefined"&&!this.isLightDescendant(rootTarget)){return}this._defau
ltFocusAsync=this.async(function(){var selectedItem=this.multi?this.selectedItem
s&&this.selectedItems[0]:this.selectedItem;this._setFocusedItem(null);if(selecte
dItem){this._setFocusedItem(selectedItem)}else if(this.items[0]){this._focusNext
()}})},_onUpKey:function(event){this._focusPrevious();event.detail.keyboardEvent
.preventDefault()},_onDownKey:function(event){this._focusNext();event.detail.key
boardEvent.preventDefault()},_onEscKey:function(event){this.focusedItem.blur()},
_onKeydown:function(event){if(!this.keyboardEventMatchesKeys(event,"up down esc"
)){this._focusWithKeyboardEvent(event)}event.stopPropagation()},_activateHandler
:function(event){Polymer.IronSelectableBehavior._activateHandler.call(this,event
);event.stopPropagation()}};Polymer.IronMenuBehaviorImpl._shiftTabPressed=false;
Polymer.IronMenuBehavior=[Polymer.IronMultiSelectableBehavior,Polymer.IronA11yKe
ysBehavior,Polymer.IronMenuBehaviorImpl];(function(){Polymer({is:"paper-menu",be
haviors:[Polymer.IronMenuBehavior]})})();Polymer.IronFitBehavior={properties:{si
zingTarget:{type:Object,value:function(){return this}},fitInto:{type:Object,valu
e:window},noOverlap:{type:Boolean},positionTarget:{type:Element},horizontalAlign
:{type:String},verticalAlign:{type:String},dynamicAlign:{type:Boolean},horizonta
lOffset:{type:Number,value:0,notify:true},verticalOffset:{type:Number,value:0,no
tify:true},autoFitOnAttach:{type:Boolean,value:false},_fitInfo:{type:Object}},ge
t _fitWidth(){var fitWidth;if(this.fitInto===window){fitWidth=this.fitInto.inner
Width}else{fitWidth=this.fitInto.getBoundingClientRect().width}return fitWidth},
get _fitHeight(){var fitHeight;if(this.fitInto===window){fitHeight=this.fitInto.
innerHeight}else{fitHeight=this.fitInto.getBoundingClientRect().height}return fi
tHeight},get _fitLeft(){var fitLeft;if(this.fitInto===window){fitLeft=0}else{fit
Left=this.fitInto.getBoundingClientRect().left}return fitLeft},get _fitTop(){var
fitTop;if(this.fitInto===window){fitTop=0}else{fitTop=this.fitInto.getBoundingC
lientRect().top}return fitTop},get _defaultPositionTarget(){var parent=Polymer.d
om(this).parentNode;if(parent&&parent.nodeType===Node.DOCUMENT_FRAGMENT_NODE){pa
rent=parent.host}return parent},get _localeHorizontalAlign(){if(this._isRTL){if(
this.horizontalAlign==="right"){return"left"}if(this.horizontalAlign==="left"){r
eturn"right"}}return this.horizontalAlign},attached:function(){this._isRTL=windo
w.getComputedStyle(this).direction=="rtl";this.positionTarget=this.positionTarge
t||this._defaultPositionTarget;if(this.autoFitOnAttach){if(window.getComputedSty
le(this).display==="none"){setTimeout(function(){this.fit()}.bind(this))}else{th
is.fit()}}},fit:function(){this.position();this.constrain();this.center()},_disc
overInfo:function(){if(this._fitInfo){return}var target=window.getComputedStyle(
this);var sizer=window.getComputedStyle(this.sizingTarget);this._fitInfo={inline
Style:{top:this.style.top||"",left:this.style.left||"",position:this.style.posit
ion||""},sizerInlineStyle:{maxWidth:this.sizingTarget.style.maxWidth||"",maxHeig
ht:this.sizingTarget.style.maxHeight||"",boxSizing:this.sizingTarget.style.boxSi
zing||""},positionedBy:{vertically:target.top!=="auto"?"top":target.bottom!=="au
to"?"bottom":null,horizontally:target.left!=="auto"?"left":target.right!=="auto"
?"right":null},sizedBy:{height:sizer.maxHeight!=="none",width:sizer.maxWidth!=="
none",minWidth:parseInt(sizer.minWidth,10)||0,minHeight:parseInt(sizer.minHeight
,10)||0},margin:{top:parseInt(target.marginTop,10)||0,right:parseInt(target.marg
inRight,10)||0,bottom:parseInt(target.marginBottom,10)||0,left:parseInt(target.m
arginLeft,10)||0}};if(this.verticalOffset){this._fitInfo.margin.top=this._fitInf
o.margin.bottom=this.verticalOffset;this._fitInfo.inlineStyle.marginTop=this.sty
le.marginTop||"";this._fitInfo.inlineStyle.marginBottom=this.style.marginBottom|
|"";this.style.marginTop=this.style.marginBottom=this.verticalOffset+"px"}if(thi
s.horizontalOffset){this._fitInfo.margin.left=this._fitInfo.margin.right=this.ho
rizontalOffset;this._fitInfo.inlineStyle.marginLeft=this.style.marginLeft||"";th
is._fitInfo.inlineStyle.marginRight=this.style.marginRight||"";this.style.margin
Left=this.style.marginRight=this.horizontalOffset+"px"}},resetFit:function(){var
info=this._fitInfo||{};for(var property in info.sizerInlineStyle){this.sizingTa
rget.style[property]=info.sizerInlineStyle[property]}for(var property in info.in
lineStyle){this.style[property]=info.inlineStyle[property]}this._fitInfo=null},r
efit:function(){var scrollLeft=this.sizingTarget.scrollLeft;var scrollTop=this.s
izingTarget.scrollTop;this.resetFit();this.fit();this.sizingTarget.scrollLeft=sc
rollLeft;this.sizingTarget.scrollTop=scrollTop},position:function(){if(!this.hor
izontalAlign&&!this.verticalAlign){return}this._discoverInfo();this.style.positi
on="fixed";this.sizingTarget.style.boxSizing="border-box";this.style.left="0px";
this.style.top="0px";var rect=this.getBoundingClientRect();var positionRect=this
.__getNormalizedRect(this.positionTarget);var fitRect=this.__getNormalizedRect(t
his.fitInto);var margin=this._fitInfo.margin;var size={width:rect.width+margin.l
eft+margin.right,height:rect.height+margin.top+margin.bottom};var position=this.
__getPosition(this._localeHorizontalAlign,this.verticalAlign,size,positionRect,f
itRect);var left=position.left+margin.left;var top=position.top+margin.top;var r
ight=Math.min(fitRect.right-margin.right,left+rect.width);var bottom=Math.min(fi
tRect.bottom-margin.bottom,top+rect.height);var minWidth=this._fitInfo.sizedBy.m
inWidth;var minHeight=this._fitInfo.sizedBy.minHeight;if(left<margin.left){left=
margin.left;if(right-left<minWidth){left=right-minWidth}}if(top<margin.top){top=
margin.top;if(bottom-top<minHeight){top=bottom-minHeight}}this.sizingTarget.styl
e.maxWidth=right-left+"px";this.sizingTarget.style.maxHeight=bottom-top+"px";thi
s.style.left=left-rect.left+"px";this.style.top=top-rect.top+"px"},constrain:fun
ction(){if(this.horizontalAlign||this.verticalAlign){return}this._discoverInfo()
;var info=this._fitInfo;if(!info.positionedBy.vertically){this.style.position="f
ixed";this.style.top="0px"}if(!info.positionedBy.horizontally){this.style.positi
on="fixed";this.style.left="0px"}this.sizingTarget.style.boxSizing="border-box";
var rect=this.getBoundingClientRect();if(!info.sizedBy.height){this.__sizeDimens
ion(rect,info.positionedBy.vertically,"top","bottom","Height")}if(!info.sizedBy.
width){this.__sizeDimension(rect,info.positionedBy.horizontally,"left","right","
Width")}},_sizeDimension:function(rect,positionedBy,start,end,extent){this.__siz
eDimension(rect,positionedBy,start,end,extent)},__sizeDimension:function(rect,po
sitionedBy,start,end,extent){var info=this._fitInfo;var fitRect=this.__getNormal
izedRect(this.fitInto);var max=extent==="Width"?fitRect.width:fitRect.height;var
flip=positionedBy===end;var offset=flip?max-rect[end]:rect[start];var margin=in
fo.margin[flip?start:end];var offsetExtent="offset"+extent;var sizingOffset=this
[offsetExtent]-this.sizingTarget[offsetExtent];this.sizingTarget.style["max"+ext
ent]=max-margin-offset-sizingOffset+"px"},center:function(){if(this.horizontalAl
ign||this.verticalAlign){return}this._discoverInfo();var positionedBy=this._fitI
nfo.positionedBy;if(positionedBy.vertically&&positionedBy.horizontally){return}t
his.style.position="fixed";if(!positionedBy.vertically){this.style.top="0px"}if(
!positionedBy.horizontally){this.style.left="0px"}var rect=this.getBoundingClien
tRect();var fitRect=this.__getNormalizedRect(this.fitInto);if(!positionedBy.vert
ically){var top=fitRect.top-rect.top+(fitRect.height-rect.height)/2;this.style.t
op=top+"px"}if(!positionedBy.horizontally){var left=fitRect.left-rect.left+(fitR
ect.width-rect.width)/2;this.style.left=left+"px"}},__getNormalizedRect:function
(target){if(target===document.documentElement||target===window){return{top:0,lef
t:0,width:window.innerWidth,height:window.innerHeight,right:window.innerWidth,bo
ttom:window.innerHeight}}return target.getBoundingClientRect()},__getCroppedArea
:function(position,size,fitRect){var verticalCrop=Math.min(0,position.top)+Math.
min(0,fitRect.bottom-(position.top+size.height));var horizontalCrop=Math.min(0,p
osition.left)+Math.min(0,fitRect.right-(position.left+size.width));return Math.a
bs(verticalCrop)*size.width+Math.abs(horizontalCrop)*size.height},__getPosition:
function(hAlign,vAlign,size,positionRect,fitRect){var positions=[{verticalAlign:
"top",horizontalAlign:"left",top:positionRect.top,left:positionRect.left},{verti
calAlign:"top",horizontalAlign:"right",top:positionRect.top,left:positionRect.ri
ght-size.width},{verticalAlign:"bottom",horizontalAlign:"left",top:positionRect.
bottom-size.height,left:positionRect.left},{verticalAlign:"bottom",horizontalAli
gn:"right",top:positionRect.bottom-size.height,left:positionRect.right-size.widt
h}];if(this.noOverlap){for(var i=0,l=positions.length;i<l;i++){var copy={};for(v
ar key in positions[i]){copy[key]=positions[i][key]}positions.push(copy)}positio
ns[0].top=positions[1].top+=positionRect.height;positions[2].top=positions[3].to
p-=positionRect.height;positions[4].left=positions[6].left+=positionRect.width;p
ositions[5].left=positions[7].left-=positionRect.width}vAlign=vAlign==="auto"?nu
ll:vAlign;hAlign=hAlign==="auto"?null:hAlign;var position;for(var i=0;i<position
s.length;i++){var pos=positions[i];if(!this.dynamicAlign&&!this.noOverlap&&pos.v
erticalAlign===vAlign&&pos.horizontalAlign===hAlign){position=pos;break}var alig
nOk=(!vAlign||pos.verticalAlign===vAlign)&&(!hAlign||pos.horizontalAlign===hAlig
n);if(!this.dynamicAlign&&!alignOk){continue}position=position||pos;pos.croppedA
rea=this.__getCroppedArea(pos,size,fitRect);var diff=pos.croppedArea-position.cr
oppedArea;if(diff<0||diff===0&&alignOk){position=pos}if(position.croppedArea===0
&&alignOk){break}}return position}};(function(){"use strict";Polymer({is:"iron-o
verlay-backdrop",properties:{opened:{reflectToAttribute:true,type:Boolean,value:
false,observer:"_openedChanged"}},listeners:{transitionend:"_onTransitionend"},c
reated:function(){this.__openedRaf=null},attached:function(){this.opened&&this._
openedChanged(this.opened)},prepare:function(){if(this.opened&&!this.parentNode)
{Polymer.dom(document.body).appendChild(this)}},open:function(){this.opened=true
},close:function(){this.opened=false},complete:function(){if(!this.opened&&this.
parentNode===document.body){Polymer.dom(this.parentNode).removeChild(this)}},_on
Transitionend:function(event){if(event&&event.target===this){this.complete()}},_
openedChanged:function(opened){if(opened){this.prepare()}else{var cs=window.getC
omputedStyle(this);if(cs.transitionDuration==="0s"||cs.opacity==0){this.complete
()}}if(!this.isAttached){return}if(this.__openedRaf){window.cancelAnimationFrame
(this.__openedRaf);this.__openedRaf=null}this.scrollTop=this.scrollTop;this.__op
enedRaf=window.requestAnimationFrame(function(){this.__openedRaf=null;this.toggl
eClass("opened",this.opened)}.bind(this))}})})();Polymer.IronOverlayManagerClass
=function(){this._overlays=[];this._minimumZ=101;this._backdropElement=null;Poly
mer.Gestures.add(document,"tap",this._onCaptureClick.bind(this));document.addEve
ntListener("focus",this._onCaptureFocus.bind(this),true);document.addEventListen
er("keydown",this._onCaptureKeyDown.bind(this),true)};Polymer.IronOverlayManager
Class.prototype={constructor:Polymer.IronOverlayManagerClass,get backdropElement
(){if(!this._backdropElement){this._backdropElement=document.createElement("iron
-overlay-backdrop")}return this._backdropElement},get deepActiveElement(){var ac
tive=document.activeElement||document.body;while(active.root&&Polymer.dom(active
.root).activeElement){active=Polymer.dom(active.root).activeElement}return activ
e},_bringOverlayAtIndexToFront:function(i){var overlay=this._overlays[i];if(!ove
rlay){return}var lastI=this._overlays.length-1;var currentOverlay=this._overlays
[lastI];if(currentOverlay&&this._shouldBeBehindOverlay(overlay,currentOverlay)){
lastI--}if(i>=lastI){return}var minimumZ=Math.max(this.currentOverlayZ(),this._m
inimumZ);if(this._getZ(overlay)<=minimumZ){this._applyOverlayZ(overlay,minimumZ)
}while(i<lastI){this._overlays[i]=this._overlays[i+1];i++}this._overlays[lastI]=
overlay},addOrRemoveOverlay:function(overlay){if(overlay.opened){this.addOverlay
(overlay)}else{this.removeOverlay(overlay)}},addOverlay:function(overlay){var i=
this._overlays.indexOf(overlay);if(i>=0){this._bringOverlayAtIndexToFront(i);thi
s.trackBackdrop();return}var insertionIndex=this._overlays.length;var currentOve
rlay=this._overlays[insertionIndex-1];var minimumZ=Math.max(this._getZ(currentOv
erlay),this._minimumZ);var newZ=this._getZ(overlay);if(currentOverlay&&this._sho
uldBeBehindOverlay(overlay,currentOverlay)){this._applyOverlayZ(currentOverlay,m
inimumZ);insertionIndex--;var previousOverlay=this._overlays[insertionIndex-1];m
inimumZ=Math.max(this._getZ(previousOverlay),this._minimumZ)}if(newZ<=minimumZ){
this._applyOverlayZ(overlay,minimumZ)}this._overlays.splice(insertionIndex,0,ove
rlay);this.trackBackdrop()},removeOverlay:function(overlay){var i=this._overlays
.indexOf(overlay);if(i===-1){return}this._overlays.splice(i,1);this.trackBackdro
p()},currentOverlay:function(){var i=this._overlays.length-1;return this._overla
ys[i]},currentOverlayZ:function(){return this._getZ(this.currentOverlay())},ensu
reMinimumZ:function(minimumZ){this._minimumZ=Math.max(this._minimumZ,minimumZ)},
focusOverlay:function(){var current=this.currentOverlay();if(current){current._a
pplyFocus()}},trackBackdrop:function(){var overlay=this._overlayWithBackdrop();i
f(!overlay&&!this._backdropElement){return}this.backdropElement.style.zIndex=thi
s._getZ(overlay)-1;this.backdropElement.opened=!!overlay},getBackdrops:function(
){var backdrops=[];for(var i=0;i<this._overlays.length;i++){if(this._overlays[i]
.withBackdrop){backdrops.push(this._overlays[i])}}return backdrops},backdropZ:fu
nction(){return this._getZ(this._overlayWithBackdrop())-1},_overlayWithBackdrop:
function(){for(var i=0;i<this._overlays.length;i++){if(this._overlays[i].withBac
kdrop){return this._overlays[i]}}},_getZ:function(overlay){var z=this._minimumZ;
if(overlay){var z1=Number(overlay.style.zIndex||window.getComputedStyle(overlay)
.zIndex);if(z1===z1){z=z1}}return z},_setZ:function(element,z){element.style.zIn
dex=z},_applyOverlayZ:function(overlay,aboveZ){this._setZ(overlay,aboveZ+2)},_ov
erlayInPath:function(path){path=path||[];for(var i=0;i<path.length;i++){if(path[
i]._manager===this){return path[i]}}},_onCaptureClick:function(event){var overla
y=this.currentOverlay();if(overlay&&this._overlayInPath(Polymer.dom(event).path)
!==overlay){overlay._onCaptureClick(event)}},_onCaptureFocus:function(event){var
overlay=this.currentOverlay();if(overlay){overlay._onCaptureFocus(event)}},_onC
aptureKeyDown:function(event){var overlay=this.currentOverlay();if(overlay){if(P
olymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(event,"esc")){overlay._onCa
ptureEsc(event)}else if(Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(ev
ent,"tab")){overlay._onCaptureTab(event)}}},_shouldBeBehindOverlay:function(over
lay1,overlay2){return!overlay1.alwaysOnTop&&overlay2.alwaysOnTop}};Polymer.IronO
verlayManager=new Polymer.IronOverlayManagerClass;(function(){"use strict";Polym
er.IronOverlayBehaviorImpl={properties:{opened:{observer:"_openedChanged",type:B
oolean,value:false,notify:true},canceled:{observer:"_canceledChanged",readOnly:t
rue, |
| 3506 var Item = Polymer({ | 47 type:Boolean,value:false},withBackdrop:{observer:"_withBackdropChanged",type:Boo
lean},noAutoFocus:{type:Boolean,value:false},noCancelOnEscKey:{type:Boolean,valu
e:false},noCancelOnOutsideClick:{type:Boolean,value:false},closingReason:{type:O
bject},restoreFocusOnClose:{type:Boolean,value:false},alwaysOnTop:{type:Boolean}
,_manager:{type:Object,value:Polymer.IronOverlayManager},_focusedChild:{type:Obj
ect}},listeners:{"iron-resize":"_onIronResize"},get backdropElement(){return thi
s._manager.backdropElement},get _focusNode(){return this._focusedChild||Polymer.
dom(this).querySelector("[autofocus]")||this},get _focusableNodes(){var FOCUSABL
E_WITH_DISABLED=["a[href]","area[href]","iframe","[tabindex]","[contentEditable=
true]"];var FOCUSABLE_WITHOUT_DISABLED=["input","select","textarea","button"];va
r selector=FOCUSABLE_WITH_DISABLED.join(':not([tabindex="-1"]),')+':not([tabinde
x="-1"]),'+FOCUSABLE_WITHOUT_DISABLED.join(':not([disabled]):not([tabindex="-1"]
),')+':not([disabled]):not([tabindex="-1"])';var focusables=Polymer.dom(this).qu
erySelectorAll(selector);if(this.tabIndex>=0){focusables.splice(0,0,this)}return
focusables.sort(function(a,b){if(a.tabIndex===b.tabIndex){return 0}if(a.tabInde
x===0||a.tabIndex>b.tabIndex){return 1}return-1})},ready:function(){this.__isAni
mating=false;this.__shouldRemoveTabIndex=false;this.__firstFocusableNode=this.__
lastFocusableNode=null;this.__raf=null;this.__restoreFocusNode=null;this._ensure
Setup()},attached:function(){if(this.opened){this._openedChanged(this.opened)}th
is._observer=Polymer.dom(this).observeNodes(this._onNodesChange)},detached:funct
ion(){Polymer.dom(this).unobserveNodes(this._observer);this._observer=null;if(th
is.__raf){window.cancelAnimationFrame(this.__raf);this.__raf=null}this._manager.
removeOverlay(this)},toggle:function(){this._setCanceled(false);this.opened=!thi
s.opened},open:function(){this._setCanceled(false);this.opened=true},close:funct
ion(){this._setCanceled(false);this.opened=false},cancel:function(event){var can
celEvent=this.fire("iron-overlay-canceled",event,{cancelable:true});if(cancelEve
nt.defaultPrevented){return}this._setCanceled(true);this.opened=false},_ensureSe
tup:function(){if(this._overlaySetup){return}this._overlaySetup=true;this.style.
outline="none";this.style.display="none"},_openedChanged:function(opened){if(ope
ned){this.removeAttribute("aria-hidden")}else{this.setAttribute("aria-hidden","t
rue")}if(!this.isAttached){return}this.__isAnimating=true;this.__onNextAnimation
Frame(this.__openedChanged)},_canceledChanged:function(){this.closingReason=this
.closingReason||{};this.closingReason.canceled=this.canceled},_withBackdropChang
ed:function(){if(this.withBackdrop&&!this.hasAttribute("tabindex")){this.setAttr
ibute("tabindex","-1");this.__shouldRemoveTabIndex=true}else if(this.__shouldRem
oveTabIndex){this.removeAttribute("tabindex");this.__shouldRemoveTabIndex=false}
if(this.opened&&this.isAttached){this._manager.trackBackdrop()}},_prepareRenderO
pened:function(){this.__restoreFocusNode=this._manager.deepActiveElement;this._p
reparePositioning();this.refit();this._finishPositioning();if(this.noAutoFocus&&
document.activeElement===this._focusNode){this._focusNode.blur();this.__restoreF
ocusNode.focus()}},_renderOpened:function(){this._finishRenderOpened()},_renderC
losed:function(){this._finishRenderClosed()},_finishRenderOpened:function(){this
.notifyResize();this.__isAnimating=false;var focusableNodes=this._focusableNodes
;this.__firstFocusableNode=focusableNodes[0];this.__lastFocusableNode=focusableN
odes[focusableNodes.length-1];this.fire("iron-overlay-opened")},_finishRenderClo
sed:function(){this.style.display="none";this.style.zIndex="";this.notifyResize(
);this.__isAnimating=false;this.fire("iron-overlay-closed",this.closingReason)},
_preparePositioning:function(){this.style.transition=this.style.webkitTransition
="none";this.style.transform=this.style.webkitTransform="none";this.style.displa
y=""},_finishPositioning:function(){this.style.display="none";this.scrollTop=thi
s.scrollTop;this.style.transition=this.style.webkitTransition="";this.style.tran
sform=this.style.webkitTransform="";this.style.display="";this.scrollTop=this.sc
rollTop},_applyFocus:function(){if(this.opened){if(!this.noAutoFocus){this._focu
sNode.focus()}}else{this._focusNode.blur();this._focusedChild=null;if(this.resto
reFocusOnClose&&this.__restoreFocusNode){this.__restoreFocusNode.focus()}this.__
restoreFocusNode=null;var currentOverlay=this._manager.currentOverlay();if(curre
ntOverlay&&this!==currentOverlay){currentOverlay._applyFocus()}}},_onCaptureClic
k:function(event){if(!this.noCancelOnOutsideClick){this.cancel(event)}},_onCaptu
reFocus:function(event){if(!this.withBackdrop){return}var path=Polymer.dom(event
).path;if(path.indexOf(this)===-1){event.stopPropagation();this._applyFocus()}el
se{this._focusedChild=path[0]}},_onCaptureEsc:function(event){if(!this.noCancelO
nEscKey){this.cancel(event)}},_onCaptureTab:function(event){if(!this.withBackdro
p){return}var shift=event.shiftKey;var nodeToCheck=shift?this.__firstFocusableNo
de:this.__lastFocusableNode;var nodeToSet=shift?this.__lastFocusableNode:this.__
firstFocusableNode;var shouldWrap=false;if(nodeToCheck===nodeToSet){shouldWrap=t
rue}else{var focusedNode=this._manager.deepActiveElement;shouldWrap=focusedNode=
==nodeToCheck||focusedNode===this}if(shouldWrap){event.preventDefault();this._fo
cusedChild=nodeToSet;this._applyFocus()}},_onIronResize:function(){if(this.opene
d&&!this.__isAnimating){this.__onNextAnimationFrame(this.refit)}},_onNodesChange
:function(){if(this.opened&&!this.__isAnimating){this.notifyResize()}},__openedC
hanged:function(){if(this.opened){this._prepareRenderOpened();this._manager.addO
verlay(this);this._applyFocus();this._renderOpened()}else{this._manager.removeOv
erlay(this);this._applyFocus();this._renderClosed()}},__onNextAnimationFrame:fun
ction(callback){if(this.__raf){window.cancelAnimationFrame(this.__raf)}var self=
this;this.__raf=window.requestAnimationFrame(function nextAnimationFrame(){self.
__raf=null;callback.call(self)})}};Polymer.IronOverlayBehavior=[Polymer.IronFitB
ehavior,Polymer.IronResizableBehavior,Polymer.IronOverlayBehaviorImpl]})();Polym
er.NeonAnimatableBehavior={properties:{animationConfig:{type:Object},entryAnimat
ion:{observer:"_entryAnimationChanged",type:String},exitAnimation:{observer:"_ex
itAnimationChanged",type:String}},_entryAnimationChanged:function(){this.animati
onConfig=this.animationConfig||{};this.animationConfig["entry"]=[{name:this.entr
yAnimation,node:this}]},_exitAnimationChanged:function(){this.animationConfig=th
is.animationConfig||{};this.animationConfig["exit"]=[{name:this.exitAnimation,no
de:this}]},_copyProperties:function(config1,config2){for(var property in config2
){config1[property]=config2[property]}},_cloneConfig:function(config){var clone=
{isClone:true};this._copyProperties(clone,config);return clone},_getAnimationCon
figRecursive:function(type,map,allConfigs){if(!this.animationConfig){return}if(t
his.animationConfig.value&&typeof this.animationConfig.value==="function"){this.
_warn(this._logf("playAnimation","Please put 'animationConfig' inside of your co
mponents 'properties' object instead of outside of it."));return}var thisConfig;
if(type){thisConfig=this.animationConfig[type]}else{thisConfig=this.animationCon
fig}if(!Array.isArray(thisConfig)){thisConfig=[thisConfig]}if(thisConfig){for(va
r config,index=0;config=thisConfig[index];index++){if(config.animatable){config.
animatable._getAnimationConfigRecursive(config.type||type,map,allConfigs)}else{i
f(config.id){var cachedConfig=map[config.id];if(cachedConfig){if(!cachedConfig.i
sClone){map[config.id]=this._cloneConfig(cachedConfig);cachedConfig=map[config.i
d]}this._copyProperties(cachedConfig,config)}else{map[config.id]=config}}else{al
lConfigs.push(config)}}}}},getAnimationConfig:function(type){var map={};var allC
onfigs=[];this._getAnimationConfigRecursive(type,map,allConfigs);for(var key in
map){allConfigs.push(map[key])}return allConfigs}};Polymer.NeonAnimationRunnerBe
haviorImpl={_configureAnimations:function(configs){var results=[];if(configs.len
gth>0){for(var config,index=0;config=configs[index];index++){var neonAnimation=d
ocument.createElement(config.name);if(neonAnimation.isNeonAnimation){var result=
null;try{result=neonAnimation.configure(config);if(typeof result.cancel!="functi
on"){result=document.timeline.play(result)}}catch(e){result=null;console.warn("C
ouldnt play","(",config.name,").",e)}if(result){results.push({neonAnimation:neon
Animation,config:config,animation:result})}}else{console.warn(this.is+":",config
.name,"not found!")}}}return results},_shouldComplete:function(activeEntries){va
r finished=true;for(var i=0;i<activeEntries.length;i++){if(activeEntries[i].anim
ation.playState!="finished"){finished=false;break}}return finished},_complete:fu
nction(activeEntries){for(var i=0;i<activeEntries.length;i++){activeEntries[i].n
eonAnimation.complete(activeEntries[i].config)}for(var i=0;i<activeEntries.lengt
h;i++){activeEntries[i].animation.cancel()}},playAnimation:function(type,cookie)
{var configs=this.getAnimationConfig(type);if(!configs){return}this._active=this
._active||{};if(this._active[type]){this._complete(this._active[type]);delete th
is._active[type]}var activeEntries=this._configureAnimations(configs);if(activeE
ntries.length==0){this.fire("neon-animation-finish",cookie,{bubbles:false});retu
rn}this._active[type]=activeEntries;for(var i=0;i<activeEntries.length;i++){acti
veEntries[i].animation.onfinish=function(){if(this._shouldComplete(activeEntries
)){this._complete(activeEntries);delete this._active[type];this.fire("neon-anima
tion-finish",cookie,{bubbles:false})}}.bind(this)}},cancelAnimation:function(){f
or(var k in this._animations){this._animations[k].cancel()}this._animations={}}}
;Polymer.NeonAnimationRunnerBehavior=[Polymer.NeonAnimatableBehavior,Polymer.Neo
nAnimationRunnerBehaviorImpl];Polymer.NeonAnimationBehavior={properties:{animati
onTiming:{type:Object,value:function(){return{duration:500,easing:"cubic-bezier(
0.4, 0, 0.2, 1)",fill:"both"}}}},isNeonAnimation:true,timingFromConfig:function(
config){if(config.timing){for(var property in config.timing){this.animationTimin
g[property]=config.timing[property]}}return this.animationTiming},setPrefixedPro
perty:function(node,property,value){var map={transform:["webkitTransform"],trans
formOrigin:["mozTransformOrigin","webkitTransformOrigin"]};var prefixes=map[prop
erty];for(var prefix,index=0;prefix=prefixes[index];index++){node.style[prefix]=
value}node.style[property]=value},complete:function(){}};Polymer({is:"opaque-ani
mation",behaviors:[Polymer.NeonAnimationBehavior],configure:function(config){var
node=config.node;this._effect=new KeyframeEffect(node,[{opacity:"1"},{opacity:"
1"}],this.timingFromConfig(config));node.style.opacity="0";return this._effect},
complete:function(config){config.node.style.opacity=""}});(function(){"use stric
t";var LAST_TOUCH_POSITION={pageX:0,pageY:0};var ROOT_TARGET=null;var SCROLLABLE
_NODES=[];Polymer.IronDropdownScrollManager={get currentLockingElement(){return
this._lockingElements[this._lockingElements.length-1]},elementIsScrollLocked:fun
ction(element){var currentLockingElement=this.currentLockingElement;if(currentLo
ckingElement===undefined)return false;var scrollLocked;if(this._hasCachedLockedE
lement(element)){return true}if(this._hasCachedUnlockedElement(element)){return
false}scrollLocked=!!currentLockingElement&¤tLockingElement!==element&&!th
is._composedTreeContains(currentLockingElement,element);if(scrollLocked){this._l
ockedElementCache.push(element)}else{this._unlockedElementCache.push(element)}re
turn scrollLocked},pushScrollLock:function(element){if(this._lockingElements.ind
exOf(element)>=0){return}if(this._lockingElements.length===0){this._lockScrollIn
teractions()}this._lockingElements.push(element);this._lockedElementCache=[];thi
s._unlockedElementCache=[]},removeScrollLock:function(element){var index=this._l
ockingElements.indexOf(element);if(index===-1){return}this._lockingElements.spli
ce(index,1);this._lockedElementCache=[];this._unlockedElementCache=[];if(this._l
ockingElements.length===0){this._unlockScrollInteractions()}},_lockingElements:[
],_lockedElementCache:null,_unlockedElementCache:null,_hasCachedLockedElement:fu
nction(element){return this._lockedElementCache.indexOf(element)>-1},_hasCachedU
nlockedElement:function(element){return this._unlockedElementCache.indexOf(eleme
nt)>-1},_composedTreeContains:function(element,child){var contentElements;var di
stributedNodes;var contentIndex;var nodeIndex;if(element.contains(child)){return
true}contentElements=Polymer.dom(element).querySelectorAll("content");for(conte
ntIndex=0;contentIndex<contentElements.length;++contentIndex){distributedNodes=P
olymer.dom(contentElements[contentIndex]).getDistributedNodes();for(nodeIndex=0;
nodeIndex<distributedNodes.length;++nodeIndex){if(this._composedTreeContains(dis
tributedNodes[nodeIndex],child)){return true}}}return false},_scrollInteractionH
andler:function(event){if(event.cancelable&&this._shouldPreventScrolling(event))
{event.preventDefault()}if(event.targetTouches){var touch=event.targetTouches[0]
;LAST_TOUCH_POSITION.pageX=touch.pageX;LAST_TOUCH_POSITION.pageY=touch.pageY}},_
lockScrollInteractions:function(){this._boundScrollHandler=this._boundScrollHand
ler||this._scrollInteractionHandler.bind(this);document.addEventListener("wheel"
,this._boundScrollHandler,true);document.addEventListener("mousewheel",this._bou
ndScrollHandler,true);document.addEventListener("DOMMouseScroll",this._boundScro
llHandler,true);document.addEventListener("touchstart",this._boundScrollHandler,
true);document.addEventListener("touchmove",this._boundScrollHandler,true)},_unl
ockScrollInteractions:function(){document.removeEventListener("wheel",this._boun
dScrollHandler,true);document.removeEventListener("mousewheel",this._boundScroll
Handler,true);document.removeEventListener("DOMMouseScroll",this._boundScrollHan
dler,true);document.removeEventListener("touchstart",this._boundScrollHandler,tr
ue);document.removeEventListener("touchmove",this._boundScrollHandler,true)},_sh
ouldPreventScrolling:function(event){var target=Polymer.dom(event).rootTarget;if
(event.type!=="touchmove"&&ROOT_TARGET!==target){ROOT_TARGET=target;SCROLLABLE_N
ODES=this._getScrollableNodes(Polymer.dom(event).path)}if(!SCROLLABLE_NODES.leng
th){return true}if(event.type==="touchstart"){return false}var info=this._getScr
ollInfo(event);return!this._getScrollingNode(SCROLLABLE_NODES,info.deltaX,info.d
eltaY)},_getScrollableNodes:function(nodes){var scrollables=[];var lockingIndex=
nodes.indexOf(this.currentLockingElement);for(var i=0;i<=lockingIndex;i++){var n
ode=nodes[i];if(node.nodeType===11){continue}var style=node.style;if(style.overf
low!=="scroll"&&style.overflow!=="auto"){style=window.getComputedStyle(node)}if(
style.overflow==="scroll"||style.overflow==="auto"){scrollables.push(node)}}retu
rn scrollables},_getScrollingNode:function(nodes,deltaX,deltaY){if(!deltaX&&!del
taY){return}var verticalScroll=Math.abs(deltaY)>=Math.abs(deltaX);for(var i=0;i<
nodes.length;i++){var node=nodes[i];var canScroll=false;if(verticalScroll){canSc
roll=deltaY<0?node.scrollTop>0:node.scrollTop<node.scrollHeight-node.clientHeigh
t}else{canScroll=deltaX<0?node.scrollLeft>0:node.scrollLeft<node.scrollWidth-nod
e.clientWidth}if(canScroll){return node}}},_getScrollInfo:function(event){var in
fo={deltaX:event.deltaX,deltaY:event.deltaY};if("deltaX"in event){}else if("whee
lDeltaX"in event){info.deltaX=-event.wheelDeltaX;info.deltaY=-event.wheelDeltaY}
else if("axis"in event){info.deltaX=event.axis===1?event.detail:0;info.deltaY=ev
ent.axis===2?event.detail:0}else if(event.targetTouches){var touch=event.targetT
ouches[0];info.deltaX=LAST_TOUCH_POSITION.pageX-touch.pageX;info.deltaY=LAST_TOU
CH_POSITION.pageY-touch.pageY}return info}}})();(function(){"use strict";Polymer
({is:"iron-dropdown",behaviors:[Polymer.IronControlState,Polymer.IronA11yKeysBeh
avior,Polymer.IronOverlayBehavior,Polymer.NeonAnimationRunnerBehavior],propertie
s:{horizontalAlign:{type:String,value:"left",reflectToAttribute:true},verticalAl
ign:{type:String,value:"top",reflectToAttribute:true},openAnimationConfig:{type:
Object},closeAnimationConfig:{type:Object},focusTarget:{type:Object},noAnimation
s:{type:Boolean,value:false},allowOutsideScroll:{type:Boolean,value:false},_boun
dOnCaptureScroll:{type:Function,value:function(){return this._onCaptureScroll.bi
nd(this)}}},listeners:{"neon-animation-finish":"_onNeonAnimationFinish"},observe
rs:["_updateOverlayPosition(positionTarget, verticalAlign, horizontalAlign, vert
icalOffset, horizontalOffset)"],get containedElement(){return Polymer.dom(this.$
.content).getDistributedNodes()[0]},get _focusTarget(){return this.focusTarget||
this.containedElement},ready:function(){this._scrollTop=0;this._scrollLeft=0;thi
s._refitOnScrollRAF=null},attached:function(){if(!this.sizingTarget||this.sizing
Target===this){this.sizingTarget=this.containedElement}},detached:function(){thi
s.cancelAnimation();document.removeEventListener("scroll",this._boundOnCaptureSc
roll);Polymer.IronDropdownScrollManager.removeScrollLock(this)},_openedChanged:f
unction(){if(this.opened&&this.disabled){this.cancel()}else{this.cancelAnimation
();this._updateAnimationConfig();this._saveScrollPosition();if(this.opened){docu
ment.addEventListener("scroll",this._boundOnCaptureScroll);!this.allowOutsideScr
oll&&Polymer.IronDropdownScrollManager.pushScrollLock(this)}else{document.remove
EventListener("scroll",this._boundOnCaptureScroll);Polymer.IronDropdownScrollMan
ager.removeScrollLock(this)}Polymer.IronOverlayBehaviorImpl._openedChanged.apply
(this,arguments)}},_renderOpened:function(){if(!this.noAnimations&&this.animatio
nConfig.open){this.$.contentWrapper.classList.add("animating");this.playAnimatio
n("open")}else{Polymer.IronOverlayBehaviorImpl._renderOpened.apply(this,argument
s)}},_renderClosed:function(){if(!this.noAnimations&&this.animationConfig.close)
{this.$.contentWrapper.classList.add("animating");this.playAnimation("close")}el
se{Polymer.IronOverlayBehaviorImpl._renderClosed.apply(this,arguments)}},_onNeon
AnimationFinish:function(){this.$.contentWrapper.classList.remove("animating");i
f(this.opened){this._finishRenderOpened()}else{this._finishRenderClosed()}},_onC
aptureScroll:function(){if(!this.allowOutsideScroll){this._restoreScrollPosition
()}else{this._refitOnScrollRAF&&window.cancelAnimationFrame(this._refitOnScrollR
AF);this._refitOnScrollRAF=window.requestAnimationFrame(this.refit.bind(this))}}
,_saveScrollPosition:function(){if(document.scrollingElement){this._scrollTop=do
cument.scrollingElement.scrollTop;this._scrollLeft=document.scrollingElement.scr
ollLeft}else{this._scrollTop=Math.max(document.documentElement.scrollTop,documen
t.body.scrollTop);this._scrollLeft=Math.max(document.documentElement.scrollLeft,
document.body.scrollLeft)}},_restoreScrollPosition:function(){if(document.scroll
ingElement){document.scrollingElement.scrollTop=this._scrollTop;document.scrolli
ngElement.scrollLeft=this._scrollLeft}else{document.documentElement.scrollTop=th
is._scrollTop;document.documentElement.scrollLeft=this._scrollLeft;document.body
.scrollTop=this._scrollTop;document.body.scrollLeft=this._scrollLeft}},_updateAn
imationConfig:function(){var animations=(this.openAnimationConfig||[]).concat(th
is.closeAnimationConfig||[]);for(var i=0;i<animations.length;i++){animations[i].
node=this.containedElement}this.animationConfig={open:this.openAnimationConfig,c
lose:this.closeAnimationConfig}},_updateOverlayPosition:function(){if(this.isAtt
ached){this.notifyResize()}},_applyFocus:function(){var focusTarget=this.focusTa
rget||this.containedElement;if(focusTarget&&this.opened&&!this.noAutoFocus){focu
sTarget.focus()}else{Polymer.IronOverlayBehaviorImpl._applyFocus.apply(this,argu
ments)}}})})();Polymer({is:"fade-in-animation",behaviors:[Polymer.NeonAnimationB
ehavior],configure:function(config){var node=config.node;this._effect=new Keyfra
meEffect(node,[{opacity:"0"},{opacity:"1"}],this.timingFromConfig(config));retur
n this._effect}});Polymer({is:"fade-out-animation",behaviors:[Polymer.NeonAnimat
ionBehavior],configure:function(config){var node=config.node;this._effect=new Ke
yframeEffect(node,[{opacity:"1"},{opacity:"0"}],this.timingFromConfig(config));r
eturn this._effect}});Polymer({is:"paper-menu-grow-height-animation",behaviors:[
Polymer.NeonAnimationBehavior],configure:function(config){var node=config.node;v
ar rect=node.getBoundingClientRect();var height=rect.height;this._effect=new Key
frameEffect(node,[{height:height/2+"px"},{height:height+"px"}],this.timingFromCo
nfig(config));return this._effect}});Polymer({is:"paper-menu-grow-width-animatio
n",behaviors:[Polymer.NeonAnimationBehavior],configure:function(config){var node
=config.node;var rect=node.getBoundingClientRect();var width=rect.width;this._ef
fect=new KeyframeEffect(node,[{width:width/2+"px"},{width:width+"px"}],this.timi
ngFromConfig(config));return this._effect}});Polymer({is:"paper-menu-shrink-widt
h-animation",behaviors:[Polymer.NeonAnimationBehavior],configure:function(config
){var node=config.node;var rect=node.getBoundingClientRect();var width=rect.widt
h;this._effect=new KeyframeEffect(node,[{width:width+"px"},{width:width-width/20
+"px"}],this.timingFromConfig(config));return this._effect}});Polymer({is:"paper
-menu-shrink-height-animation",behaviors:[Polymer.NeonAnimationBehavior],configu
re:function(config){var node=config.node;var rect=node.getBoundingClientRect();v
ar height=rect.height;var top=rect.top;this.setPrefixedProperty(node,"transformO
rigin","0 0");this._effect=new KeyframeEffect(node,[{height:height+"px",transfor
m:"translateY(0)"},{height:height/2+"px",transform:"translateY(-20px)"}],this.ti
mingFromConfig(config));return this._effect}});(function(){"use strict";var conf
ig={ANIMATION_CUBIC_BEZIER:"cubic-bezier(.3,.95,.5,1)",MAX_ANIMATION_TIME_MS:400
};var PaperMenuButton=Polymer({is:"paper-menu-button",behaviors:[Polymer.IronA11
yKeysBehavior,Polymer.IronControlState],properties:{opened:{type:Boolean,value:f
alse,notify:true,observer:"_openedChanged"},horizontalAlign:{type:String,value:"
left",reflectToAttribute:true},verticalAlign:{type:String,value:"top",reflectToA
ttribute:true},dynamicAlign:{type:Boolean},horizontalOffset:{type:Number,value:0
,notify:true},verticalOffset:{type:Number,value:0,notify:true},noOverlap:{type:B
oolean},noAnimations:{type:Boolean,value:false},ignoreSelect:{type:Boolean,value
:false},closeOnActivate:{type:Boolean,value:false},openAnimationConfig:{type:Obj
ect,value:function(){return[{name:"fade-in-animation",timing:{delay:100,duration
:200}},{name:"paper-menu-grow-width-animation",timing:{delay:100,duration:150,ea
sing:config.ANIMATION_CUBIC_BEZIER}},{name:"paper-menu-grow-height-animation",ti
ming:{delay:100,duration:275,easing:config.ANIMATION_CUBIC_BEZIER}}]}},closeAnim
ationConfig:{type:Object,value:function(){return[{name:"fade-out-animation",timi
ng:{duration:150}},{name:"paper-menu-shrink-width-animation",timing:{delay:100,d
uration:50,easing:config.ANIMATION_CUBIC_BEZIER}},{name:"paper-menu-shrink-heigh
t-animation",timing:{duration:200,easing:"ease-in"}}]}},allowOutsideScroll:{type
:Boolean,value:false},restoreFocusOnClose:{type:Boolean,value:true},_dropdownCon
tent:{type:Object}},hostAttributes:{role:"group","aria-haspopup":"true"},listene
rs:{"iron-activate":"_onIronActivate","iron-select":"_onIronSelect"},get content
Element(){return Polymer.dom(this.$.content).getDistributedNodes()[0]},toggle:fu
nction(){if(this.opened){this.close()}else{this.open()}},open:function(){if(this
.disabled){return}this.$.dropdown.open()},close:function(){this.$.dropdown.close
()},_onIronSelect:function(event){if(!this.ignoreSelect){this.close()}},_onIronA
ctivate:function(event){if(this.closeOnActivate){this.close()}},_openedChanged:f
unction(opened,oldOpened){if(opened){this._dropdownContent=this.contentElement;t
his.fire("paper-dropdown-open")}else if(oldOpened!=null){this.fire("paper-dropdo
wn-close")}},_disabledChanged:function(disabled){Polymer.IronControlState._disab
ledChanged.apply(this,arguments);if(disabled&&this.opened){this.close()}},__onIr
onOverlayCanceled:function(event){var uiEvent=event.detail;var target=Polymer.do
m(uiEvent).rootTarget;var trigger=this.$.trigger;var path=Polymer.dom(uiEvent).p
ath;if(path.indexOf(trigger)>-1){event.preventDefault()}}});Object.keys(config).
forEach(function(key){PaperMenuButton[key]=config[key]});Polymer.PaperMenuButton
=PaperMenuButton})();Polymer.PaperInkyFocusBehaviorImpl={observers:["_focusedCha
nged(receivedFocusFromKeyboard)"],_focusedChanged:function(receivedFocusFromKeyb
oard){if(receivedFocusFromKeyboard){this.ensureRipple()}if(this.hasRipple()){thi
s._ripple.holdDown=receivedFocusFromKeyboard}},_createRipple:function(){var ripp
le=Polymer.PaperRippleBehavior._createRipple();ripple.id="ink";ripple.setAttribu
te("center","");ripple.classList.add("circle");return ripple}};Polymer.PaperInky
FocusBehavior=[Polymer.IronButtonState,Polymer.IronControlState,Polymer.PaperRip
pleBehavior,Polymer.PaperInkyFocusBehaviorImpl];Polymer({is:"paper-icon-button",
hostAttributes:{role:"button",tabindex:"0"},behaviors:[Polymer.PaperInkyFocusBeh
avior],properties:{src:{type:String},icon:{type:String},alt:{type:String,observe
r:"_altChanged"}},_altChanged:function(newValue,oldValue){var label=this.getAttr
ibute("aria-label");if(!label||oldValue==label){this.setAttribute("aria-label",n
ewValue)}}});Polymer({is:"iron-media-query",properties:{queryMatches:{type:Boole
an,value:false,readOnly:true,notify:true},query:{type:String,observer:"queryChan
ged"},full:{type:Boolean,value:false},_boundMQHandler:{value:function(){return t
his.queryHandler.bind(this)}},_mq:{value:null}},attached:function(){this.style.d
isplay="none";this.queryChanged()},detached:function(){this._remove()},_add:func
tion(){if(this._mq){this._mq.addListener(this._boundMQHandler)}},_remove:functio
n(){if(this._mq){this._mq.removeListener(this._boundMQHandler)}this._mq=null},qu
eryChanged:function(){this._remove();var query=this.query;if(!query){return}if(!
this.full&&query[0]!=="("){query="("+query+")"}this._mq=window.matchMedia(query)
;this._add();this.queryHandler(this._mq)},queryHandler:function(mq){this._setQue
ryMatches(mq.matches)}});(function(){"use strict";Polymer.IronA11yAnnouncer=Poly
mer({is:"iron-a11y-announcer",properties:{mode:{type:String,value:"polite"},_tex
t:{type:String,value:""}},created:function(){if(!Polymer.IronA11yAnnouncer.insta
nce){Polymer.IronA11yAnnouncer.instance=this}document.body.addEventListener("iro
n-announce",this._onIronAnnounce.bind(this))},announce:function(text){this._text
="";this.async(function(){this._text=text},100)},_onIronAnnounce:function(event)
{if(event.detail&&event.detail.text){this.announce(event.detail.text)}}});Polyme
r.IronA11yAnnouncer.instance=null;Polymer.IronA11yAnnouncer.requestAvailability=
function(){if(!Polymer.IronA11yAnnouncer.instance){Polymer.IronA11yAnnouncer.ins
tance=document.createElement("iron-a11y-announcer")}document.body.appendChild(Po
lymer.IronA11yAnnouncer.instance)}})();Polymer.IronValidatableBehaviorMeta=null;
Polymer.IronValidatableBehavior={properties:{validator:{type:String},invalid:{no
tify:true,reflectToAttribute:true,type:Boolean,value:false},_validatorMeta:{type
:Object},validatorType:{type:String,value:"validator"},_validator:{type:Object,c
omputed:"__computeValidator(validator)"}},observers:["_invalidChanged(invalid)"]
,registered:function(){Polymer.IronValidatableBehaviorMeta=new Polymer.IronMeta(
{type:"validator"})},_invalidChanged:function(){if(this.invalid){this.setAttribu
te("aria-invalid","true")}else{this.removeAttribute("aria-invalid")}},hasValidat
or:function(){return this._validator!=null},validate:function(value){this.invali
d=!this._getValidity(value);return!this.invalid},_getValidity:function(value){if
(this.hasValidator()){return this._validator.validate(value)}return true},__comp
uteValidator:function(){return Polymer.IronValidatableBehaviorMeta&&Polymer.Iron
ValidatableBehaviorMeta.byKey(this.validator)}};Polymer({is:"iron-input","extend
s":"input",behaviors:[Polymer.IronValidatableBehavior],properties:{bindValue:{ob
server:"_bindValueChanged",type:String},preventInvalidInput:{type:Boolean},allow
edPattern:{type:String,observer:"_allowedPatternChanged"},_previousValidInput:{t
ype:String,value:""},_patternAlreadyChecked:{type:Boolean,value:false}},listener
s:{input:"_onInput",keypress:"_onKeypress"},registered:function(){if(!this._canD
ispatchEventOnDisabled()){this._origDispatchEvent=this.dispatchEvent;this.dispat
chEvent=this._dispatchEventFirefoxIE}},created:function(){Polymer.IronA11yAnnoun
cer.requestAvailability()},_canDispatchEventOnDisabled:function(){var input=docu
ment.createElement("input");var canDispatch=false;input.disabled=true;input.addE
ventListener("feature-check-dispatch-event",function(){canDispatch=true});try{in
put.dispatchEvent(new Event("feature-check-dispatch-event"))}catch(e){}return ca
nDispatch},_dispatchEventFirefoxIE:function(){var disabled=this.disabled;this.di
sabled=false;this._origDispatchEvent.apply(this,arguments);this.disabled=disable
d},get _patternRegExp(){var pattern;if(this.allowedPattern){pattern=new RegExp(t
his.allowedPattern)}else{switch(this.type){case"number":pattern=/[0-9.,e-]/;brea
k}}return pattern},ready:function(){this.bindValue=this.value},_bindValueChanged
:function(){if(this.value!==this.bindValue){this.value=!(this.bindValue||this.bi
ndValue===0||this.bindValue===false)?"":this.bindValue}this.fire("bind-value-cha
nged",{value:this.bindValue})},_allowedPatternChanged:function(){this.preventInv
alidInput=this.allowedPattern?true:false},_onInput:function(){if(this.preventInv
alidInput&&!this._patternAlreadyChecked){var valid=this._checkPatternValidity();
if(!valid){this._announceInvalidCharacter("Invalid string of characters not ente
red.");this.value=this._previousValidInput}}this.bindValue=this.value;this._prev
iousValidInput=this.value;this._patternAlreadyChecked=false},_isPrintable:functi
on(event){var anyNonPrintable=event.keyCode==8||event.keyCode==9||event.keyCode=
=13||event.keyCode==27;var mozNonPrintable=event.keyCode==19||event.keyCode==20|
|event.keyCode==45||event.keyCode==46||event.keyCode==144||event.keyCode==145||e
vent.keyCode>32&&event.keyCode<41||event.keyCode>111&&event.keyCode<124;return!a
nyNonPrintable&&!(event.charCode==0&&mozNonPrintable)},_onKeypress:function(even
t){if(!this.preventInvalidInput&&this.type!=="number"){return}var regexp=this._p
atternRegExp;if(!regexp){return}if(event.metaKey||event.ctrlKey||event.altKey)re
turn;this._patternAlreadyChecked=true;var thisChar=String.fromCharCode(event.cha
rCode);if(this._isPrintable(event)&&!regexp.test(thisChar)){event.preventDefault
();this._announceInvalidCharacter("Invalid character "+thisChar+" not entered.")
}},_checkPatternValidity:function(){var regexp=this._patternRegExp;if(!regexp){r
eturn true}for(var i=0;i<this.value.length;i++){if(!regexp.test(this.value[i])){
return false}}return true},validate:function(){var valid=this.checkValidity();if
(valid){if(this.required&&this.value===""){valid=false}else if(this.hasValidator
()){valid=Polymer.IronValidatableBehavior.validate.call(this,this.value)}}this.i
nvalid=!valid;this.fire("iron-input-validate");return valid},_announceInvalidCha
racter:function(message){this.fire("iron-announce",{text:message})}});Polymer({i
s:"paper-input-container",properties:{noLabelFloat:{type:Boolean,value:false},al
waysFloatLabel:{type:Boolean,value:false},attrForValue:{type:String,value:"bind-
value"},autoValidate:{type:Boolean,value:false},invalid:{observer:"_invalidChang
ed",type:Boolean,value:false},focused:{readOnly:true,type:Boolean,value:false,no
tify:true},_addons:{type:Array},_inputHasContent:{type:Boolean,value:false},_inp
utSelector:{type:String,value:"input,textarea,.paper-input-input"},_boundOnFocus
:{type:Function,value:function(){return this._onFocus.bind(this)}},_boundOnBlur:
{type:Function,value:function(){return this._onBlur.bind(this)}},_boundOnInput:{
type:Function,value:function(){return this._onInput.bind(this)}},_boundValueChan
ged:{ |
| 3507 is: 'downloads-item', | 48 type:Function,value:function(){return this._onValueChanged.bind(this)}}},listene
rs:{"addon-attached":"_onAddonAttached","iron-input-validate":"_onIronInputValid
ate"},get _valueChangedEvent(){return this.attrForValue+"-changed"},get _propert
yForValue(){return Polymer.CaseMap.dashToCamelCase(this.attrForValue)},get _inpu
tElement(){return Polymer.dom(this).querySelector(this._inputSelector)},get _inp
utElementValue(){return this._inputElement[this._propertyForValue]||this._inputE
lement.value},ready:function(){if(!this._addons){this._addons=[]}this.addEventLi
stener("focus",this._boundOnFocus,true);this.addEventListener("blur",this._bound
OnBlur,true)},attached:function(){if(this.attrForValue){this._inputElement.addEv
entListener(this._valueChangedEvent,this._boundValueChanged)}else{this.addEventL
istener("input",this._onInput)}if(this._inputElementValue!=""){this._handleValue
AndAutoValidate(this._inputElement)}else{this._handleValue(this._inputElement)}}
,_onAddonAttached:function(event){if(!this._addons){this._addons=[]}var target=e
vent.target;if(this._addons.indexOf(target)===-1){this._addons.push(target);if(t
his.isAttached){this._handleValue(this._inputElement)}}},_onFocus:function(){thi
s._setFocused(true)},_onBlur:function(){this._setFocused(false);this._handleValu
eAndAutoValidate(this._inputElement)},_onInput:function(event){this._handleValue
AndAutoValidate(event.target)},_onValueChanged:function(event){this._handleValue
AndAutoValidate(event.target)},_handleValue:function(inputElement){var value=thi
s._inputElementValue;if(value||value===0||inputElement.type==="number"&&!inputEl
ement.checkValidity()){this._inputHasContent=true}else{this._inputHasContent=fal
se}this.updateAddons({inputElement:inputElement,value:value,invalid:this.invalid
})},_handleValueAndAutoValidate:function(inputElement){if(this.autoValidate){var
valid;if(inputElement.validate){valid=inputElement.validate(this._inputElementV
alue)}else{valid=inputElement.checkValidity()}this.invalid=!valid}this._handleVa
lue(inputElement)},_onIronInputValidate:function(event){this.invalid=this._input
Element.invalid},_invalidChanged:function(){if(this._addons){this.updateAddons({
invalid:this.invalid})}},updateAddons:function(state){for(var addon,index=0;addo
n=this._addons[index];index++){addon.update(state)}},_computeInputContentClass:f
unction(noLabelFloat,alwaysFloatLabel,focused,invalid,_inputHasContent){var cls=
"input-content";if(!noLabelFloat){var label=this.querySelector("label");if(alway
sFloatLabel||_inputHasContent){cls+=" label-is-floating";this.$.labelAndInputCon
tainer.style.position="static";if(invalid){cls+=" is-invalid"}else if(focused){c
ls+=" label-is-highlighted"}}else{if(label){this.$.labelAndInputContainer.style.
position="relative"}}}else{if(_inputHasContent){cls+=" label-is-hidden"}}return
cls},_computeUnderlineClass:function(focused,invalid){var cls="underline";if(inv
alid){cls+=" is-invalid"}else if(focused){cls+=" is-highlighted"}return cls},_co
mputeAddOnContentClass:function(focused,invalid){var cls="add-on-content";if(inv
alid){cls+=" is-invalid"}else if(focused){cls+=" is-highlighted"}return cls}});P
olymer.PaperSpinnerBehavior={listeners:{animationend:"__reset",webkitAnimationEn
d:"__reset"},properties:{active:{type:Boolean,value:false,reflectToAttribute:tru
e,observer:"__activeChanged"},alt:{type:String,value:"loading",observer:"__altCh
anged"},__coolingDown:{type:Boolean,value:false}},__computeContainerClasses:func
tion(active,coolingDown){return[active||coolingDown?"active":"",coolingDown?"coo
ldown":""].join(" ")},__activeChanged:function(active,old){this.__setAriaHidden(
!active);this.__coolingDown=!active&&old},__altChanged:function(alt){if(alt===th
is.getPropertyInfo("alt").value){this.alt=this.getAttribute("aria-label")||alt}e
lse{this.__setAriaHidden(alt==="");this.setAttribute("aria-label",alt)}},__setAr
iaHidden:function(hidden){var attr="aria-hidden";if(hidden){this.setAttribute(at
tr,"true")}else{this.removeAttribute(attr)}},__reset:function(){this.active=fals
e;this.__coolingDown=false}};Polymer({is:"paper-spinner-lite",behaviors:[Polymer
.PaperSpinnerBehavior]}); |
| 3508 properties: { | |
| 3509 data: { | |
| 3510 type: Object | |
| 3511 }, | |
| 3512 completelyOnDisk_: { | |
| 3513 computed: 'computeCompletelyOnDisk_(' + 'data.state, data.file_externall
y_removed)', | |
| 3514 type: Boolean, | |
| 3515 value: true | |
| 3516 }, | |
| 3517 controlledBy_: { | |
| 3518 computed: 'computeControlledBy_(data.by_ext_id, data.by_ext_name)', | |
| 3519 type: String, | |
| 3520 value: '' | |
| 3521 }, | |
| 3522 isActive_: { | |
| 3523 computed: 'computeIsActive_(' + 'data.state, data.file_externally_remove
d)', | |
| 3524 type: Boolean, | |
| 3525 value: true | |
| 3526 }, | |
| 3527 isDangerous_: { | |
| 3528 computed: 'computeIsDangerous_(data.state)', | |
| 3529 type: Boolean, | |
| 3530 value: false | |
| 3531 }, | |
| 3532 isMalware_: { | |
| 3533 computed: 'computeIsMalware_(isDangerous_, data.danger_type)', | |
| 3534 type: Boolean, | |
| 3535 value: false | |
| 3536 }, | |
| 3537 isInProgress_: { | |
| 3538 computed: 'computeIsInProgress_(data.state)', | |
| 3539 type: Boolean, | |
| 3540 value: false | |
| 3541 }, | |
| 3542 pauseOrResumeText_: { | |
| 3543 computed: 'computePauseOrResumeText_(isInProgress_, data.resume)', | |
| 3544 type: String | |
| 3545 }, | |
| 3546 showCancel_: { | |
| 3547 computed: 'computeShowCancel_(data.state)', | |
| 3548 type: Boolean, | |
| 3549 value: false | |
| 3550 }, | |
| 3551 showProgress_: { | |
| 3552 computed: 'computeShowProgress_(showCancel_, data.percent)', | |
| 3553 type: Boolean, | |
| 3554 value: false | |
| 3555 } | |
| 3556 }, | |
| 3557 observers: [ 'observeControlledBy_(controlledBy_)', 'observeIsDangerous_(isD
angerous_, data)' ], | |
| 3558 ready: function() { | |
| 3559 this.content = this.$.content; | |
| 3560 }, | |
| 3561 computeClass_: function() { | |
| 3562 var classes = []; | |
| 3563 if (this.isActive_) classes.push('is-active'); | |
| 3564 if (this.isDangerous_) classes.push('dangerous'); | |
| 3565 if (this.showProgress_) classes.push('show-progress'); | |
| 3566 return classes.join(' '); | |
| 3567 }, | |
| 3568 computeCompletelyOnDisk_: function() { | |
| 3569 return this.data.state == downloads.States.COMPLETE && !this.data.file_ext
ernally_removed; | |
| 3570 }, | |
| 3571 computeControlledBy_: function() { | |
| 3572 if (!this.data.by_ext_id || !this.data.by_ext_name) return ''; | |
| 3573 var url = 'chrome://extensions#' + this.data.by_ext_id; | |
| 3574 var name = this.data.by_ext_name; | |
| 3575 return loadTimeData.getStringF('controlledByUrl', url, name); | |
| 3576 }, | |
| 3577 computeDangerIcon_: function() { | |
| 3578 if (!this.isDangerous_) return ''; | |
| 3579 switch (this.data.danger_type) { | |
| 3580 case downloads.DangerType.DANGEROUS_CONTENT: | |
| 3581 case downloads.DangerType.DANGEROUS_HOST: | |
| 3582 case downloads.DangerType.DANGEROUS_URL: | |
| 3583 case downloads.DangerType.POTENTIALLY_UNWANTED: | |
| 3584 case downloads.DangerType.UNCOMMON_CONTENT: | |
| 3585 return 'downloads:remove-circle'; | |
| 3586 | |
| 3587 default: | |
| 3588 return 'cr:warning'; | |
| 3589 } | |
| 3590 }, | |
| 3591 computeDate_: function() { | |
| 3592 assert(typeof this.data.hideDate == 'boolean'); | |
| 3593 if (this.data.hideDate) return ''; | |
| 3594 return assert(this.data.since_string || this.data.date_string); | |
| 3595 }, | |
| 3596 computeDescription_: function() { | |
| 3597 var data = this.data; | |
| 3598 switch (data.state) { | |
| 3599 case downloads.States.DANGEROUS: | |
| 3600 var fileName = data.file_name; | |
| 3601 switch (data.danger_type) { | |
| 3602 case downloads.DangerType.DANGEROUS_FILE: | |
| 3603 return loadTimeData.getString('dangerFileDesc'); | |
| 3604 | |
| 3605 case downloads.DangerType.DANGEROUS_URL: | |
| 3606 case downloads.DangerType.DANGEROUS_CONTENT: | |
| 3607 case downloads.DangerType.DANGEROUS_HOST: | |
| 3608 return loadTimeData.getString('dangerDownloadDesc'); | |
| 3609 | |
| 3610 case downloads.DangerType.UNCOMMON_CONTENT: | |
| 3611 return loadTimeData.getString('dangerUncommonDesc'); | |
| 3612 | |
| 3613 case downloads.DangerType.POTENTIALLY_UNWANTED: | |
| 3614 return loadTimeData.getString('dangerSettingsDesc'); | |
| 3615 } | |
| 3616 break; | |
| 3617 | |
| 3618 case downloads.States.IN_PROGRESS: | |
| 3619 case downloads.States.PAUSED: | |
| 3620 return data.progress_status_text; | |
| 3621 } | |
| 3622 return ''; | |
| 3623 }, | |
| 3624 computeIsActive_: function() { | |
| 3625 return this.data.state != downloads.States.CANCELLED && this.data.state !=
downloads.States.INTERRUPTED && !this.data.file_externally_removed; | |
| 3626 }, | |
| 3627 computeIsDangerous_: function() { | |
| 3628 return this.data.state == downloads.States.DANGEROUS; | |
| 3629 }, | |
| 3630 computeIsInProgress_: function() { | |
| 3631 return this.data.state == downloads.States.IN_PROGRESS; | |
| 3632 }, | |
| 3633 computeIsMalware_: function() { | |
| 3634 return this.isDangerous_ && (this.data.danger_type == downloads.DangerType
.DANGEROUS_CONTENT || this.data.danger_type == downloads.DangerType.DANGEROUS_HO
ST || this.data.danger_type == downloads.DangerType.DANGEROUS_URL || this.data.d
anger_type == downloads.DangerType.POTENTIALLY_UNWANTED); | |
| 3635 }, | |
| 3636 computePauseOrResumeText_: function() { | |
| 3637 if (this.isInProgress_) return loadTimeData.getString('controlPause'); | |
| 3638 if (this.data.resume) return loadTimeData.getString('controlResume'); | |
| 3639 return ''; | |
| 3640 }, | |
| 3641 computeRemoveStyle_: function() { | |
| 3642 var canDelete = loadTimeData.getBoolean('allowDeletingHistory'); | |
| 3643 var hideRemove = this.isDangerous_ || this.showCancel_ || !canDelete; | |
| 3644 return hideRemove ? 'visibility: hidden' : ''; | |
| 3645 }, | |
| 3646 computeShowCancel_: function() { | |
| 3647 return this.data.state == downloads.States.IN_PROGRESS || this.data.state
== downloads.States.PAUSED; | |
| 3648 }, | |
| 3649 computeShowProgress_: function() { | |
| 3650 return this.showCancel_ && this.data.percent >= -1; | |
| 3651 }, | |
| 3652 computeTag_: function() { | |
| 3653 switch (this.data.state) { | |
| 3654 case downloads.States.CANCELLED: | |
| 3655 return loadTimeData.getString('statusCancelled'); | |
| 3656 | |
| 3657 case downloads.States.INTERRUPTED: | |
| 3658 return this.data.last_reason_text; | |
| 3659 | |
| 3660 case downloads.States.COMPLETE: | |
| 3661 return this.data.file_externally_removed ? loadTimeData.getString('statu
sRemoved') : ''; | |
| 3662 } | |
| 3663 return ''; | |
| 3664 }, | |
| 3665 isIndeterminate_: function() { | |
| 3666 return this.data.percent == -1; | |
| 3667 }, | |
| 3668 observeControlledBy_: function() { | |
| 3669 this.$['controlled-by'].innerHTML = this.controlledBy_; | |
| 3670 }, | |
| 3671 observeIsDangerous_: function() { | |
| 3672 if (!this.data) return; | |
| 3673 if (this.isDangerous_) { | |
| 3674 this.$.url.removeAttribute('href'); | |
| 3675 } else { | |
| 3676 this.$.url.href = assert(this.data.url); | |
| 3677 var filePath = encodeURIComponent(this.data.file_path); | |
| 3678 var scaleFactor = '?scale=' + window.devicePixelRatio + 'x'; | |
| 3679 this.$['file-icon'].src = 'chrome://fileicon/' + filePath + scaleFactor; | |
| 3680 } | |
| 3681 }, | |
| 3682 onCancelTap_: function() { | |
| 3683 downloads.ActionService.getInstance().cancel(this.data.id); | |
| 3684 }, | |
| 3685 onDiscardDangerousTap_: function() { | |
| 3686 downloads.ActionService.getInstance().discardDangerous(this.data.id); | |
| 3687 }, | |
| 3688 onDragStart_: function(e) { | |
| 3689 e.preventDefault(); | |
| 3690 downloads.ActionService.getInstance().drag(this.data.id); | |
| 3691 }, | |
| 3692 onFileLinkTap_: function(e) { | |
| 3693 e.preventDefault(); | |
| 3694 downloads.ActionService.getInstance().openFile(this.data.id); | |
| 3695 }, | |
| 3696 onPauseOrResumeTap_: function() { | |
| 3697 if (this.isInProgress_) downloads.ActionService.getInstance().pause(this.d
ata.id); else downloads.ActionService.getInstance().resume(this.data.id); | |
| 3698 }, | |
| 3699 onRemoveTap_: function() { | |
| 3700 downloads.ActionService.getInstance().remove(this.data.id); | |
| 3701 }, | |
| 3702 onRetryTap_: function() { | |
| 3703 downloads.ActionService.getInstance().download(this.data.url); | |
| 3704 }, | |
| 3705 onSaveDangerousTap_: function() { | |
| 3706 downloads.ActionService.getInstance().saveDangerous(this.data.id); | |
| 3707 }, | |
| 3708 onShowTap_: function() { | |
| 3709 downloads.ActionService.getInstance().show(this.data.id); | |
| 3710 } | |
| 3711 }); | |
| 3712 return { | |
| 3713 Item: Item | |
| 3714 }; | |
| 3715 }); | |
| 3716 | |
| 3717 Polymer.PaperItemBehaviorImpl = { | |
| 3718 hostAttributes: { | |
| 3719 role: 'option', | |
| 3720 tabindex: '0' | |
| 3721 } | |
| 3722 }; | |
| 3723 | |
| 3724 Polymer.PaperItemBehavior = [ Polymer.IronButtonState, Polymer.IronControlState,
Polymer.PaperItemBehaviorImpl ]; | |
| 3725 | |
| 3726 Polymer({ | |
| 3727 is: 'paper-item', | |
| 3728 behaviors: [ Polymer.PaperItemBehavior ] | |
| 3729 }); | |
| 3730 | |
| 3731 Polymer.IronSelection = function(selectCallback) { | |
| 3732 this.selection = []; | |
| 3733 this.selectCallback = selectCallback; | |
| 3734 }; | |
| 3735 | |
| 3736 Polymer.IronSelection.prototype = { | |
| 3737 get: function() { | |
| 3738 return this.multi ? this.selection.slice() : this.selection[0]; | |
| 3739 }, | |
| 3740 clear: function(excludes) { | |
| 3741 this.selection.slice().forEach(function(item) { | |
| 3742 if (!excludes || excludes.indexOf(item) < 0) { | |
| 3743 this.setItemSelected(item, false); | |
| 3744 } | |
| 3745 }, this); | |
| 3746 }, | |
| 3747 isSelected: function(item) { | |
| 3748 return this.selection.indexOf(item) >= 0; | |
| 3749 }, | |
| 3750 setItemSelected: function(item, isSelected) { | |
| 3751 if (item != null) { | |
| 3752 if (isSelected !== this.isSelected(item)) { | |
| 3753 if (isSelected) { | |
| 3754 this.selection.push(item); | |
| 3755 } else { | |
| 3756 var i = this.selection.indexOf(item); | |
| 3757 if (i >= 0) { | |
| 3758 this.selection.splice(i, 1); | |
| 3759 } | |
| 3760 } | |
| 3761 if (this.selectCallback) { | |
| 3762 this.selectCallback(item, isSelected); | |
| 3763 } | |
| 3764 } | |
| 3765 } | |
| 3766 }, | |
| 3767 select: function(item) { | |
| 3768 if (this.multi) { | |
| 3769 this.toggle(item); | |
| 3770 } else if (this.get() !== item) { | |
| 3771 this.setItemSelected(this.get(), false); | |
| 3772 this.setItemSelected(item, true); | |
| 3773 } | |
| 3774 }, | |
| 3775 toggle: function(item) { | |
| 3776 this.setItemSelected(item, !this.isSelected(item)); | |
| 3777 } | |
| 3778 }; | |
| 3779 | |
| 3780 Polymer.IronSelectableBehavior = { | |
| 3781 properties: { | |
| 3782 attrForSelected: { | |
| 3783 type: String, | |
| 3784 value: null | |
| 3785 }, | |
| 3786 selected: { | |
| 3787 type: String, | |
| 3788 notify: true | |
| 3789 }, | |
| 3790 selectedItem: { | |
| 3791 type: Object, | |
| 3792 readOnly: true, | |
| 3793 notify: true | |
| 3794 }, | |
| 3795 activateEvent: { | |
| 3796 type: String, | |
| 3797 value: 'tap', | |
| 3798 observer: '_activateEventChanged' | |
| 3799 }, | |
| 3800 selectable: String, | |
| 3801 selectedClass: { | |
| 3802 type: String, | |
| 3803 value: 'iron-selected' | |
| 3804 }, | |
| 3805 selectedAttribute: { | |
| 3806 type: String, | |
| 3807 value: null | |
| 3808 }, | |
| 3809 fallbackSelection: { | |
| 3810 type: String, | |
| 3811 value: null | |
| 3812 }, | |
| 3813 items: { | |
| 3814 type: Array, | |
| 3815 readOnly: true, | |
| 3816 notify: true, | |
| 3817 value: function() { | |
| 3818 return []; | |
| 3819 } | |
| 3820 }, | |
| 3821 _excludedLocalNames: { | |
| 3822 type: Object, | |
| 3823 value: function() { | |
| 3824 return { | |
| 3825 template: 1 | |
| 3826 }; | |
| 3827 } | |
| 3828 } | |
| 3829 }, | |
| 3830 observers: [ '_updateAttrForSelected(attrForSelected)', '_updateSelected(selec
ted)', '_checkFallback(fallbackSelection)' ], | |
| 3831 created: function() { | |
| 3832 this._bindFilterItem = this._filterItem.bind(this); | |
| 3833 this._selection = new Polymer.IronSelection(this._applySelection.bind(this))
; | |
| 3834 }, | |
| 3835 attached: function() { | |
| 3836 this._observer = this._observeItems(this); | |
| 3837 this._updateItems(); | |
| 3838 if (!this._shouldUpdateSelection) { | |
| 3839 this._updateSelected(); | |
| 3840 } | |
| 3841 this._addListener(this.activateEvent); | |
| 3842 }, | |
| 3843 detached: function() { | |
| 3844 if (this._observer) { | |
| 3845 Polymer.dom(this).unobserveNodes(this._observer); | |
| 3846 } | |
| 3847 this._removeListener(this.activateEvent); | |
| 3848 }, | |
| 3849 indexOf: function(item) { | |
| 3850 return this.items.indexOf(item); | |
| 3851 }, | |
| 3852 select: function(value) { | |
| 3853 this.selected = value; | |
| 3854 }, | |
| 3855 selectPrevious: function() { | |
| 3856 var length = this.items.length; | |
| 3857 var index = (Number(this._valueToIndex(this.selected)) - 1 + length) % lengt
h; | |
| 3858 this.selected = this._indexToValue(index); | |
| 3859 }, | |
| 3860 selectNext: function() { | |
| 3861 var index = (Number(this._valueToIndex(this.selected)) + 1) % this.items.len
gth; | |
| 3862 this.selected = this._indexToValue(index); | |
| 3863 }, | |
| 3864 selectIndex: function(index) { | |
| 3865 this.select(this._indexToValue(index)); | |
| 3866 }, | |
| 3867 forceSynchronousItemUpdate: function() { | |
| 3868 this._updateItems(); | |
| 3869 }, | |
| 3870 get _shouldUpdateSelection() { | |
| 3871 return this.selected != null; | |
| 3872 }, | |
| 3873 _checkFallback: function() { | |
| 3874 if (this._shouldUpdateSelection) { | |
| 3875 this._updateSelected(); | |
| 3876 } | |
| 3877 }, | |
| 3878 _addListener: function(eventName) { | |
| 3879 this.listen(this, eventName, '_activateHandler'); | |
| 3880 }, | |
| 3881 _removeListener: function(eventName) { | |
| 3882 this.unlisten(this, eventName, '_activateHandler'); | |
| 3883 }, | |
| 3884 _activateEventChanged: function(eventName, old) { | |
| 3885 this._removeListener(old); | |
| 3886 this._addListener(eventName); | |
| 3887 }, | |
| 3888 _updateItems: function() { | |
| 3889 var nodes = Polymer.dom(this).queryDistributedElements(this.selectable || '*
'); | |
| 3890 nodes = Array.prototype.filter.call(nodes, this._bindFilterItem); | |
| 3891 this._setItems(nodes); | |
| 3892 }, | |
| 3893 _updateAttrForSelected: function() { | |
| 3894 if (this._shouldUpdateSelection) { | |
| 3895 this.selected = this._indexToValue(this.indexOf(this.selectedItem)); | |
| 3896 } | |
| 3897 }, | |
| 3898 _updateSelected: function() { | |
| 3899 this._selectSelected(this.selected); | |
| 3900 }, | |
| 3901 _selectSelected: function(selected) { | |
| 3902 this._selection.select(this._valueToItem(this.selected)); | |
| 3903 if (this.fallbackSelection && this.items.length && this._selection.get() ===
undefined) { | |
| 3904 this.selected = this.fallbackSelection; | |
| 3905 } | |
| 3906 }, | |
| 3907 _filterItem: function(node) { | |
| 3908 return !this._excludedLocalNames[node.localName]; | |
| 3909 }, | |
| 3910 _valueToItem: function(value) { | |
| 3911 return value == null ? null : this.items[this._valueToIndex(value)]; | |
| 3912 }, | |
| 3913 _valueToIndex: function(value) { | |
| 3914 if (this.attrForSelected) { | |
| 3915 for (var i = 0, item; item = this.items[i]; i++) { | |
| 3916 if (this._valueForItem(item) == value) { | |
| 3917 return i; | |
| 3918 } | |
| 3919 } | |
| 3920 } else { | |
| 3921 return Number(value); | |
| 3922 } | |
| 3923 }, | |
| 3924 _indexToValue: function(index) { | |
| 3925 if (this.attrForSelected) { | |
| 3926 var item = this.items[index]; | |
| 3927 if (item) { | |
| 3928 return this._valueForItem(item); | |
| 3929 } | |
| 3930 } else { | |
| 3931 return index; | |
| 3932 } | |
| 3933 }, | |
| 3934 _valueForItem: function(item) { | |
| 3935 var propValue = item[Polymer.CaseMap.dashToCamelCase(this.attrForSelected)]; | |
| 3936 return propValue != undefined ? propValue : item.getAttribute(this.attrForSe
lected); | |
| 3937 }, | |
| 3938 _applySelection: function(item, isSelected) { | |
| 3939 if (this.selectedClass) { | |
| 3940 this.toggleClass(this.selectedClass, isSelected, item); | |
| 3941 } | |
| 3942 if (this.selectedAttribute) { | |
| 3943 this.toggleAttribute(this.selectedAttribute, isSelected, item); | |
| 3944 } | |
| 3945 this._selectionChange(); | |
| 3946 this.fire('iron-' + (isSelected ? 'select' : 'deselect'), { | |
| 3947 item: item | |
| 3948 }); | |
| 3949 }, | |
| 3950 _selectionChange: function() { | |
| 3951 this._setSelectedItem(this._selection.get()); | |
| 3952 }, | |
| 3953 _observeItems: function(node) { | |
| 3954 return Polymer.dom(node).observeNodes(function(mutation) { | |
| 3955 this._updateItems(); | |
| 3956 if (this._shouldUpdateSelection) { | |
| 3957 this._updateSelected(); | |
| 3958 } | |
| 3959 this.fire('iron-items-changed', mutation, { | |
| 3960 bubbles: false, | |
| 3961 cancelable: false | |
| 3962 }); | |
| 3963 }); | |
| 3964 }, | |
| 3965 _activateHandler: function(e) { | |
| 3966 var t = e.target; | |
| 3967 var items = this.items; | |
| 3968 while (t && t != this) { | |
| 3969 var i = items.indexOf(t); | |
| 3970 if (i >= 0) { | |
| 3971 var value = this._indexToValue(i); | |
| 3972 this._itemActivate(value, t); | |
| 3973 return; | |
| 3974 } | |
| 3975 t = t.parentNode; | |
| 3976 } | |
| 3977 }, | |
| 3978 _itemActivate: function(value, item) { | |
| 3979 if (!this.fire('iron-activate', { | |
| 3980 selected: value, | |
| 3981 item: item | |
| 3982 }, { | |
| 3983 cancelable: true | |
| 3984 }).defaultPrevented) { | |
| 3985 this.select(value); | |
| 3986 } | |
| 3987 } | |
| 3988 }; | |
| 3989 | |
| 3990 Polymer.IronMultiSelectableBehaviorImpl = { | |
| 3991 properties: { | |
| 3992 multi: { | |
| 3993 type: Boolean, | |
| 3994 value: false, | |
| 3995 observer: 'multiChanged' | |
| 3996 }, | |
| 3997 selectedValues: { | |
| 3998 type: Array, | |
| 3999 notify: true | |
| 4000 }, | |
| 4001 selectedItems: { | |
| 4002 type: Array, | |
| 4003 readOnly: true, | |
| 4004 notify: true | |
| 4005 } | |
| 4006 }, | |
| 4007 observers: [ '_updateSelected(selectedValues.splices)' ], | |
| 4008 select: function(value) { | |
| 4009 if (this.multi) { | |
| 4010 if (this.selectedValues) { | |
| 4011 this._toggleSelected(value); | |
| 4012 } else { | |
| 4013 this.selectedValues = [ value ]; | |
| 4014 } | |
| 4015 } else { | |
| 4016 this.selected = value; | |
| 4017 } | |
| 4018 }, | |
| 4019 multiChanged: function(multi) { | |
| 4020 this._selection.multi = multi; | |
| 4021 }, | |
| 4022 get _shouldUpdateSelection() { | |
| 4023 return this.selected != null || this.selectedValues != null && this.selected
Values.length; | |
| 4024 }, | |
| 4025 _updateAttrForSelected: function() { | |
| 4026 if (!this.multi) { | |
| 4027 Polymer.IronSelectableBehavior._updateAttrForSelected.apply(this); | |
| 4028 } else if (this._shouldUpdateSelection) { | |
| 4029 this.selectedValues = this.selectedItems.map(function(selectedItem) { | |
| 4030 return this._indexToValue(this.indexOf(selectedItem)); | |
| 4031 }, this).filter(function(unfilteredValue) { | |
| 4032 return unfilteredValue != null; | |
| 4033 }, this); | |
| 4034 } | |
| 4035 }, | |
| 4036 _updateSelected: function() { | |
| 4037 if (this.multi) { | |
| 4038 this._selectMulti(this.selectedValues); | |
| 4039 } else { | |
| 4040 this._selectSelected(this.selected); | |
| 4041 } | |
| 4042 }, | |
| 4043 _selectMulti: function(values) { | |
| 4044 if (values) { | |
| 4045 var selectedItems = this._valuesToItems(values); | |
| 4046 this._selection.clear(selectedItems); | |
| 4047 for (var i = 0; i < selectedItems.length; i++) { | |
| 4048 this._selection.setItemSelected(selectedItems[i], true); | |
| 4049 } | |
| 4050 if (this.fallbackSelection && this.items.length && !this._selection.get().
length) { | |
| 4051 var fallback = this._valueToItem(this.fallbackSelection); | |
| 4052 if (fallback) { | |
| 4053 this.selectedValues = [ this.fallbackSelection ]; | |
| 4054 } | |
| 4055 } | |
| 4056 } else { | |
| 4057 this._selection.clear(); | |
| 4058 } | |
| 4059 }, | |
| 4060 _selectionChange: function() { | |
| 4061 var s = this._selection.get(); | |
| 4062 if (this.multi) { | |
| 4063 this._setSelectedItems(s); | |
| 4064 } else { | |
| 4065 this._setSelectedItems([ s ]); | |
| 4066 this._setSelectedItem(s); | |
| 4067 } | |
| 4068 }, | |
| 4069 _toggleSelected: function(value) { | |
| 4070 var i = this.selectedValues.indexOf(value); | |
| 4071 var unselected = i < 0; | |
| 4072 if (unselected) { | |
| 4073 this.push('selectedValues', value); | |
| 4074 } else { | |
| 4075 this.splice('selectedValues', i, 1); | |
| 4076 } | |
| 4077 }, | |
| 4078 _valuesToItems: function(values) { | |
| 4079 return values == null ? null : values.map(function(value) { | |
| 4080 return this._valueToItem(value); | |
| 4081 }, this); | |
| 4082 } | |
| 4083 }; | |
| 4084 | |
| 4085 Polymer.IronMultiSelectableBehavior = [ Polymer.IronSelectableBehavior, Polymer.
IronMultiSelectableBehaviorImpl ]; | |
| 4086 | |
| 4087 Polymer.IronMenuBehaviorImpl = { | |
| 4088 properties: { | |
| 4089 focusedItem: { | |
| 4090 observer: '_focusedItemChanged', | |
| 4091 readOnly: true, | |
| 4092 type: Object | |
| 4093 }, | |
| 4094 attrForItemTitle: { | |
| 4095 type: String | |
| 4096 } | |
| 4097 }, | |
| 4098 hostAttributes: { | |
| 4099 role: 'menu', | |
| 4100 tabindex: '0' | |
| 4101 }, | |
| 4102 observers: [ '_updateMultiselectable(multi)' ], | |
| 4103 listeners: { | |
| 4104 focus: '_onFocus', | |
| 4105 keydown: '_onKeydown', | |
| 4106 'iron-items-changed': '_onIronItemsChanged' | |
| 4107 }, | |
| 4108 keyBindings: { | |
| 4109 up: '_onUpKey', | |
| 4110 down: '_onDownKey', | |
| 4111 esc: '_onEscKey', | |
| 4112 'shift+tab:keydown': '_onShiftTabDown' | |
| 4113 }, | |
| 4114 attached: function() { | |
| 4115 this._resetTabindices(); | |
| 4116 }, | |
| 4117 select: function(value) { | |
| 4118 if (this._defaultFocusAsync) { | |
| 4119 this.cancelAsync(this._defaultFocusAsync); | |
| 4120 this._defaultFocusAsync = null; | |
| 4121 } | |
| 4122 var item = this._valueToItem(value); | |
| 4123 if (item && item.hasAttribute('disabled')) return; | |
| 4124 this._setFocusedItem(item); | |
| 4125 Polymer.IronMultiSelectableBehaviorImpl.select.apply(this, arguments); | |
| 4126 }, | |
| 4127 _resetTabindices: function() { | |
| 4128 var selectedItem = this.multi ? this.selectedItems && this.selectedItems[0]
: this.selectedItem; | |
| 4129 this.items.forEach(function(item) { | |
| 4130 item.setAttribute('tabindex', item === selectedItem ? '0' : '-1'); | |
| 4131 }, this); | |
| 4132 }, | |
| 4133 _updateMultiselectable: function(multi) { | |
| 4134 if (multi) { | |
| 4135 this.setAttribute('aria-multiselectable', 'true'); | |
| 4136 } else { | |
| 4137 this.removeAttribute('aria-multiselectable'); | |
| 4138 } | |
| 4139 }, | |
| 4140 _focusWithKeyboardEvent: function(event) { | |
| 4141 for (var i = 0, item; item = this.items[i]; i++) { | |
| 4142 var attr = this.attrForItemTitle || 'textContent'; | |
| 4143 var title = item[attr] || item.getAttribute(attr); | |
| 4144 if (!item.hasAttribute('disabled') && title && title.trim().charAt(0).toLo
werCase() === String.fromCharCode(event.keyCode).toLowerCase()) { | |
| 4145 this._setFocusedItem(item); | |
| 4146 break; | |
| 4147 } | |
| 4148 } | |
| 4149 }, | |
| 4150 _focusPrevious: function() { | |
| 4151 var length = this.items.length; | |
| 4152 var curFocusIndex = Number(this.indexOf(this.focusedItem)); | |
| 4153 for (var i = 1; i < length + 1; i++) { | |
| 4154 var item = this.items[(curFocusIndex - i + length) % length]; | |
| 4155 if (!item.hasAttribute('disabled')) { | |
| 4156 var owner = Polymer.dom(item).getOwnerRoot() || document; | |
| 4157 this._setFocusedItem(item); | |
| 4158 if (Polymer.dom(owner).activeElement == item) { | |
| 4159 return; | |
| 4160 } | |
| 4161 } | |
| 4162 } | |
| 4163 }, | |
| 4164 _focusNext: function() { | |
| 4165 var length = this.items.length; | |
| 4166 var curFocusIndex = Number(this.indexOf(this.focusedItem)); | |
| 4167 for (var i = 1; i < length + 1; i++) { | |
| 4168 var item = this.items[(curFocusIndex + i) % length]; | |
| 4169 if (!item.hasAttribute('disabled')) { | |
| 4170 var owner = Polymer.dom(item).getOwnerRoot() || document; | |
| 4171 this._setFocusedItem(item); | |
| 4172 if (Polymer.dom(owner).activeElement == item) { | |
| 4173 return; | |
| 4174 } | |
| 4175 } | |
| 4176 } | |
| 4177 }, | |
| 4178 _applySelection: function(item, isSelected) { | |
| 4179 if (isSelected) { | |
| 4180 item.setAttribute('aria-selected', 'true'); | |
| 4181 } else { | |
| 4182 item.removeAttribute('aria-selected'); | |
| 4183 } | |
| 4184 Polymer.IronSelectableBehavior._applySelection.apply(this, arguments); | |
| 4185 }, | |
| 4186 _focusedItemChanged: function(focusedItem, old) { | |
| 4187 old && old.setAttribute('tabindex', '-1'); | |
| 4188 if (focusedItem) { | |
| 4189 focusedItem.setAttribute('tabindex', '0'); | |
| 4190 focusedItem.focus(); | |
| 4191 } | |
| 4192 }, | |
| 4193 _onIronItemsChanged: function(event) { | |
| 4194 if (event.detail.addedNodes.length) { | |
| 4195 this._resetTabindices(); | |
| 4196 } | |
| 4197 }, | |
| 4198 _onShiftTabDown: function(event) { | |
| 4199 var oldTabIndex = this.getAttribute('tabindex'); | |
| 4200 Polymer.IronMenuBehaviorImpl._shiftTabPressed = true; | |
| 4201 this._setFocusedItem(null); | |
| 4202 this.setAttribute('tabindex', '-1'); | |
| 4203 this.async(function() { | |
| 4204 this.setAttribute('tabindex', oldTabIndex); | |
| 4205 Polymer.IronMenuBehaviorImpl._shiftTabPressed = false; | |
| 4206 }, 1); | |
| 4207 }, | |
| 4208 _onFocus: function(event) { | |
| 4209 if (Polymer.IronMenuBehaviorImpl._shiftTabPressed) { | |
| 4210 return; | |
| 4211 } | |
| 4212 var rootTarget = Polymer.dom(event).rootTarget; | |
| 4213 if (rootTarget !== this && typeof rootTarget.tabIndex !== "undefined" && !th
is.isLightDescendant(rootTarget)) { | |
| 4214 return; | |
| 4215 } | |
| 4216 this._defaultFocusAsync = this.async(function() { | |
| 4217 var selectedItem = this.multi ? this.selectedItems && this.selectedItems[0
] : this.selectedItem; | |
| 4218 this._setFocusedItem(null); | |
| 4219 if (selectedItem) { | |
| 4220 this._setFocusedItem(selectedItem); | |
| 4221 } else if (this.items[0]) { | |
| 4222 this._focusNext(); | |
| 4223 } | |
| 4224 }); | |
| 4225 }, | |
| 4226 _onUpKey: function(event) { | |
| 4227 this._focusPrevious(); | |
| 4228 event.detail.keyboardEvent.preventDefault(); | |
| 4229 }, | |
| 4230 _onDownKey: function(event) { | |
| 4231 this._focusNext(); | |
| 4232 event.detail.keyboardEvent.preventDefault(); | |
| 4233 }, | |
| 4234 _onEscKey: function(event) { | |
| 4235 this.focusedItem.blur(); | |
| 4236 }, | |
| 4237 _onKeydown: function(event) { | |
| 4238 if (!this.keyboardEventMatchesKeys(event, 'up down esc')) { | |
| 4239 this._focusWithKeyboardEvent(event); | |
| 4240 } | |
| 4241 event.stopPropagation(); | |
| 4242 }, | |
| 4243 _activateHandler: function(event) { | |
| 4244 Polymer.IronSelectableBehavior._activateHandler.call(this, event); | |
| 4245 event.stopPropagation(); | |
| 4246 } | |
| 4247 }; | |
| 4248 | |
| 4249 Polymer.IronMenuBehaviorImpl._shiftTabPressed = false; | |
| 4250 | |
| 4251 Polymer.IronMenuBehavior = [ Polymer.IronMultiSelectableBehavior, Polymer.IronA1
1yKeysBehavior, Polymer.IronMenuBehaviorImpl ]; | |
| 4252 | |
| 4253 (function() { | |
| 4254 Polymer({ | |
| 4255 is: 'paper-menu', | |
| 4256 behaviors: [ Polymer.IronMenuBehavior ] | |
| 4257 }); | |
| 4258 })(); | |
| 4259 | |
| 4260 Polymer.IronFitBehavior = { | |
| 4261 properties: { | |
| 4262 sizingTarget: { | |
| 4263 type: Object, | |
| 4264 value: function() { | |
| 4265 return this; | |
| 4266 } | |
| 4267 }, | |
| 4268 fitInto: { | |
| 4269 type: Object, | |
| 4270 value: window | |
| 4271 }, | |
| 4272 noOverlap: { | |
| 4273 type: Boolean | |
| 4274 }, | |
| 4275 positionTarget: { | |
| 4276 type: Element | |
| 4277 }, | |
| 4278 horizontalAlign: { | |
| 4279 type: String | |
| 4280 }, | |
| 4281 verticalAlign: { | |
| 4282 type: String | |
| 4283 }, | |
| 4284 dynamicAlign: { | |
| 4285 type: Boolean | |
| 4286 }, | |
| 4287 horizontalOffset: { | |
| 4288 type: Number, | |
| 4289 value: 0, | |
| 4290 notify: true | |
| 4291 }, | |
| 4292 verticalOffset: { | |
| 4293 type: Number, | |
| 4294 value: 0, | |
| 4295 notify: true | |
| 4296 }, | |
| 4297 autoFitOnAttach: { | |
| 4298 type: Boolean, | |
| 4299 value: false | |
| 4300 }, | |
| 4301 _fitInfo: { | |
| 4302 type: Object | |
| 4303 } | |
| 4304 }, | |
| 4305 get _fitWidth() { | |
| 4306 var fitWidth; | |
| 4307 if (this.fitInto === window) { | |
| 4308 fitWidth = this.fitInto.innerWidth; | |
| 4309 } else { | |
| 4310 fitWidth = this.fitInto.getBoundingClientRect().width; | |
| 4311 } | |
| 4312 return fitWidth; | |
| 4313 }, | |
| 4314 get _fitHeight() { | |
| 4315 var fitHeight; | |
| 4316 if (this.fitInto === window) { | |
| 4317 fitHeight = this.fitInto.innerHeight; | |
| 4318 } else { | |
| 4319 fitHeight = this.fitInto.getBoundingClientRect().height; | |
| 4320 } | |
| 4321 return fitHeight; | |
| 4322 }, | |
| 4323 get _fitLeft() { | |
| 4324 var fitLeft; | |
| 4325 if (this.fitInto === window) { | |
| 4326 fitLeft = 0; | |
| 4327 } else { | |
| 4328 fitLeft = this.fitInto.getBoundingClientRect().left; | |
| 4329 } | |
| 4330 return fitLeft; | |
| 4331 }, | |
| 4332 get _fitTop() { | |
| 4333 var fitTop; | |
| 4334 if (this.fitInto === window) { | |
| 4335 fitTop = 0; | |
| 4336 } else { | |
| 4337 fitTop = this.fitInto.getBoundingClientRect().top; | |
| 4338 } | |
| 4339 return fitTop; | |
| 4340 }, | |
| 4341 get _defaultPositionTarget() { | |
| 4342 var parent = Polymer.dom(this).parentNode; | |
| 4343 if (parent && parent.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | |
| 4344 parent = parent.host; | |
| 4345 } | |
| 4346 return parent; | |
| 4347 }, | |
| 4348 get _localeHorizontalAlign() { | |
| 4349 if (this._isRTL) { | |
| 4350 if (this.horizontalAlign === 'right') { | |
| 4351 return 'left'; | |
| 4352 } | |
| 4353 if (this.horizontalAlign === 'left') { | |
| 4354 return 'right'; | |
| 4355 } | |
| 4356 } | |
| 4357 return this.horizontalAlign; | |
| 4358 }, | |
| 4359 attached: function() { | |
| 4360 this._isRTL = window.getComputedStyle(this).direction == 'rtl'; | |
| 4361 this.positionTarget = this.positionTarget || this._defaultPositionTarget; | |
| 4362 if (this.autoFitOnAttach) { | |
| 4363 if (window.getComputedStyle(this).display === 'none') { | |
| 4364 setTimeout(function() { | |
| 4365 this.fit(); | |
| 4366 }.bind(this)); | |
| 4367 } else { | |
| 4368 this.fit(); | |
| 4369 } | |
| 4370 } | |
| 4371 }, | |
| 4372 fit: function() { | |
| 4373 this.position(); | |
| 4374 this.constrain(); | |
| 4375 this.center(); | |
| 4376 }, | |
| 4377 _discoverInfo: function() { | |
| 4378 if (this._fitInfo) { | |
| 4379 return; | |
| 4380 } | |
| 4381 var target = window.getComputedStyle(this); | |
| 4382 var sizer = window.getComputedStyle(this.sizingTarget); | |
| 4383 this._fitInfo = { | |
| 4384 inlineStyle: { | |
| 4385 top: this.style.top || '', | |
| 4386 left: this.style.left || '', | |
| 4387 position: this.style.position || '' | |
| 4388 }, | |
| 4389 sizerInlineStyle: { | |
| 4390 maxWidth: this.sizingTarget.style.maxWidth || '', | |
| 4391 maxHeight: this.sizingTarget.style.maxHeight || '', | |
| 4392 boxSizing: this.sizingTarget.style.boxSizing || '' | |
| 4393 }, | |
| 4394 positionedBy: { | |
| 4395 vertically: target.top !== 'auto' ? 'top' : target.bottom !== 'auto' ? '
bottom' : null, | |
| 4396 horizontally: target.left !== 'auto' ? 'left' : target.right !== 'auto'
? 'right' : null | |
| 4397 }, | |
| 4398 sizedBy: { | |
| 4399 height: sizer.maxHeight !== 'none', | |
| 4400 width: sizer.maxWidth !== 'none', | |
| 4401 minWidth: parseInt(sizer.minWidth, 10) || 0, | |
| 4402 minHeight: parseInt(sizer.minHeight, 10) || 0 | |
| 4403 }, | |
| 4404 margin: { | |
| 4405 top: parseInt(target.marginTop, 10) || 0, | |
| 4406 right: parseInt(target.marginRight, 10) || 0, | |
| 4407 bottom: parseInt(target.marginBottom, 10) || 0, | |
| 4408 left: parseInt(target.marginLeft, 10) || 0 | |
| 4409 } | |
| 4410 }; | |
| 4411 if (this.verticalOffset) { | |
| 4412 this._fitInfo.margin.top = this._fitInfo.margin.bottom = this.verticalOffs
et; | |
| 4413 this._fitInfo.inlineStyle.marginTop = this.style.marginTop || ''; | |
| 4414 this._fitInfo.inlineStyle.marginBottom = this.style.marginBottom || ''; | |
| 4415 this.style.marginTop = this.style.marginBottom = this.verticalOffset + 'px
'; | |
| 4416 } | |
| 4417 if (this.horizontalOffset) { | |
| 4418 this._fitInfo.margin.left = this._fitInfo.margin.right = this.horizontalOf
fset; | |
| 4419 this._fitInfo.inlineStyle.marginLeft = this.style.marginLeft || ''; | |
| 4420 this._fitInfo.inlineStyle.marginRight = this.style.marginRight || ''; | |
| 4421 this.style.marginLeft = this.style.marginRight = this.horizontalOffset + '
px'; | |
| 4422 } | |
| 4423 }, | |
| 4424 resetFit: function() { | |
| 4425 var info = this._fitInfo || {}; | |
| 4426 for (var property in info.sizerInlineStyle) { | |
| 4427 this.sizingTarget.style[property] = info.sizerInlineStyle[property]; | |
| 4428 } | |
| 4429 for (var property in info.inlineStyle) { | |
| 4430 this.style[property] = info.inlineStyle[property]; | |
| 4431 } | |
| 4432 this._fitInfo = null; | |
| 4433 }, | |
| 4434 refit: function() { | |
| 4435 var scrollLeft = this.sizingTarget.scrollLeft; | |
| 4436 var scrollTop = this.sizingTarget.scrollTop; | |
| 4437 this.resetFit(); | |
| 4438 this.fit(); | |
| 4439 this.sizingTarget.scrollLeft = scrollLeft; | |
| 4440 this.sizingTarget.scrollTop = scrollTop; | |
| 4441 }, | |
| 4442 position: function() { | |
| 4443 if (!this.horizontalAlign && !this.verticalAlign) { | |
| 4444 return; | |
| 4445 } | |
| 4446 this._discoverInfo(); | |
| 4447 this.style.position = 'fixed'; | |
| 4448 this.sizingTarget.style.boxSizing = 'border-box'; | |
| 4449 this.style.left = '0px'; | |
| 4450 this.style.top = '0px'; | |
| 4451 var rect = this.getBoundingClientRect(); | |
| 4452 var positionRect = this.__getNormalizedRect(this.positionTarget); | |
| 4453 var fitRect = this.__getNormalizedRect(this.fitInto); | |
| 4454 var margin = this._fitInfo.margin; | |
| 4455 var size = { | |
| 4456 width: rect.width + margin.left + margin.right, | |
| 4457 height: rect.height + margin.top + margin.bottom | |
| 4458 }; | |
| 4459 var position = this.__getPosition(this._localeHorizontalAlign, this.vertical
Align, size, positionRect, fitRect); | |
| 4460 var left = position.left + margin.left; | |
| 4461 var top = position.top + margin.top; | |
| 4462 var right = Math.min(fitRect.right - margin.right, left + rect.width); | |
| 4463 var bottom = Math.min(fitRect.bottom - margin.bottom, top + rect.height); | |
| 4464 var minWidth = this._fitInfo.sizedBy.minWidth; | |
| 4465 var minHeight = this._fitInfo.sizedBy.minHeight; | |
| 4466 if (left < margin.left) { | |
| 4467 left = margin.left; | |
| 4468 if (right - left < minWidth) { | |
| 4469 left = right - minWidth; | |
| 4470 } | |
| 4471 } | |
| 4472 if (top < margin.top) { | |
| 4473 top = margin.top; | |
| 4474 if (bottom - top < minHeight) { | |
| 4475 top = bottom - minHeight; | |
| 4476 } | |
| 4477 } | |
| 4478 this.sizingTarget.style.maxWidth = right - left + 'px'; | |
| 4479 this.sizingTarget.style.maxHeight = bottom - top + 'px'; | |
| 4480 this.style.left = left - rect.left + 'px'; | |
| 4481 this.style.top = top - rect.top + 'px'; | |
| 4482 }, | |
| 4483 constrain: function() { | |
| 4484 if (this.horizontalAlign || this.verticalAlign) { | |
| 4485 return; | |
| 4486 } | |
| 4487 this._discoverInfo(); | |
| 4488 var info = this._fitInfo; | |
| 4489 if (!info.positionedBy.vertically) { | |
| 4490 this.style.position = 'fixed'; | |
| 4491 this.style.top = '0px'; | |
| 4492 } | |
| 4493 if (!info.positionedBy.horizontally) { | |
| 4494 this.style.position = 'fixed'; | |
| 4495 this.style.left = '0px'; | |
| 4496 } | |
| 4497 this.sizingTarget.style.boxSizing = 'border-box'; | |
| 4498 var rect = this.getBoundingClientRect(); | |
| 4499 if (!info.sizedBy.height) { | |
| 4500 this.__sizeDimension(rect, info.positionedBy.vertically, 'top', 'bottom',
'Height'); | |
| 4501 } | |
| 4502 if (!info.sizedBy.width) { | |
| 4503 this.__sizeDimension(rect, info.positionedBy.horizontally, 'left', 'right'
, 'Width'); | |
| 4504 } | |
| 4505 }, | |
| 4506 _sizeDimension: function(rect, positionedBy, start, end, extent) { | |
| 4507 this.__sizeDimension(rect, positionedBy, start, end, extent); | |
| 4508 }, | |
| 4509 __sizeDimension: function(rect, positionedBy, start, end, extent) { | |
| 4510 var info = this._fitInfo; | |
| 4511 var fitRect = this.__getNormalizedRect(this.fitInto); | |
| 4512 var max = extent === 'Width' ? fitRect.width : fitRect.height; | |
| 4513 var flip = positionedBy === end; | |
| 4514 var offset = flip ? max - rect[end] : rect[start]; | |
| 4515 var margin = info.margin[flip ? start : end]; | |
| 4516 var offsetExtent = 'offset' + extent; | |
| 4517 var sizingOffset = this[offsetExtent] - this.sizingTarget[offsetExtent]; | |
| 4518 this.sizingTarget.style['max' + extent] = max - margin - offset - sizingOffs
et + 'px'; | |
| 4519 }, | |
| 4520 center: function() { | |
| 4521 if (this.horizontalAlign || this.verticalAlign) { | |
| 4522 return; | |
| 4523 } | |
| 4524 this._discoverInfo(); | |
| 4525 var positionedBy = this._fitInfo.positionedBy; | |
| 4526 if (positionedBy.vertically && positionedBy.horizontally) { | |
| 4527 return; | |
| 4528 } | |
| 4529 this.style.position = 'fixed'; | |
| 4530 if (!positionedBy.vertically) { | |
| 4531 this.style.top = '0px'; | |
| 4532 } | |
| 4533 if (!positionedBy.horizontally) { | |
| 4534 this.style.left = '0px'; | |
| 4535 } | |
| 4536 var rect = this.getBoundingClientRect(); | |
| 4537 var fitRect = this.__getNormalizedRect(this.fitInto); | |
| 4538 if (!positionedBy.vertically) { | |
| 4539 var top = fitRect.top - rect.top + (fitRect.height - rect.height) / 2; | |
| 4540 this.style.top = top + 'px'; | |
| 4541 } | |
| 4542 if (!positionedBy.horizontally) { | |
| 4543 var left = fitRect.left - rect.left + (fitRect.width - rect.width) / 2; | |
| 4544 this.style.left = left + 'px'; | |
| 4545 } | |
| 4546 }, | |
| 4547 __getNormalizedRect: function(target) { | |
| 4548 if (target === document.documentElement || target === window) { | |
| 4549 return { | |
| 4550 top: 0, | |
| 4551 left: 0, | |
| 4552 width: window.innerWidth, | |
| 4553 height: window.innerHeight, | |
| 4554 right: window.innerWidth, | |
| 4555 bottom: window.innerHeight | |
| 4556 }; | |
| 4557 } | |
| 4558 return target.getBoundingClientRect(); | |
| 4559 }, | |
| 4560 __getCroppedArea: function(position, size, fitRect) { | |
| 4561 var verticalCrop = Math.min(0, position.top) + Math.min(0, fitRect.bottom -
(position.top + size.height)); | |
| 4562 var horizontalCrop = Math.min(0, position.left) + Math.min(0, fitRect.right
- (position.left + size.width)); | |
| 4563 return Math.abs(verticalCrop) * size.width + Math.abs(horizontalCrop) * size
.height; | |
| 4564 }, | |
| 4565 __getPosition: function(hAlign, vAlign, size, positionRect, fitRect) { | |
| 4566 var positions = [ { | |
| 4567 verticalAlign: 'top', | |
| 4568 horizontalAlign: 'left', | |
| 4569 top: positionRect.top, | |
| 4570 left: positionRect.left | |
| 4571 }, { | |
| 4572 verticalAlign: 'top', | |
| 4573 horizontalAlign: 'right', | |
| 4574 top: positionRect.top, | |
| 4575 left: positionRect.right - size.width | |
| 4576 }, { | |
| 4577 verticalAlign: 'bottom', | |
| 4578 horizontalAlign: 'left', | |
| 4579 top: positionRect.bottom - size.height, | |
| 4580 left: positionRect.left | |
| 4581 }, { | |
| 4582 verticalAlign: 'bottom', | |
| 4583 horizontalAlign: 'right', | |
| 4584 top: positionRect.bottom - size.height, | |
| 4585 left: positionRect.right - size.width | |
| 4586 } ]; | |
| 4587 if (this.noOverlap) { | |
| 4588 for (var i = 0, l = positions.length; i < l; i++) { | |
| 4589 var copy = {}; | |
| 4590 for (var key in positions[i]) { | |
| 4591 copy[key] = positions[i][key]; | |
| 4592 } | |
| 4593 positions.push(copy); | |
| 4594 } | |
| 4595 positions[0].top = positions[1].top += positionRect.height; | |
| 4596 positions[2].top = positions[3].top -= positionRect.height; | |
| 4597 positions[4].left = positions[6].left += positionRect.width; | |
| 4598 positions[5].left = positions[7].left -= positionRect.width; | |
| 4599 } | |
| 4600 vAlign = vAlign === 'auto' ? null : vAlign; | |
| 4601 hAlign = hAlign === 'auto' ? null : hAlign; | |
| 4602 var position; | |
| 4603 for (var i = 0; i < positions.length; i++) { | |
| 4604 var pos = positions[i]; | |
| 4605 if (!this.dynamicAlign && !this.noOverlap && pos.verticalAlign === vAlign
&& pos.horizontalAlign === hAlign) { | |
| 4606 position = pos; | |
| 4607 break; | |
| 4608 } | |
| 4609 var alignOk = (!vAlign || pos.verticalAlign === vAlign) && (!hAlign || pos
.horizontalAlign === hAlign); | |
| 4610 if (!this.dynamicAlign && !alignOk) { | |
| 4611 continue; | |
| 4612 } | |
| 4613 position = position || pos; | |
| 4614 pos.croppedArea = this.__getCroppedArea(pos, size, fitRect); | |
| 4615 var diff = pos.croppedArea - position.croppedArea; | |
| 4616 if (diff < 0 || diff === 0 && alignOk) { | |
| 4617 position = pos; | |
| 4618 } | |
| 4619 if (position.croppedArea === 0 && alignOk) { | |
| 4620 break; | |
| 4621 } | |
| 4622 } | |
| 4623 return position; | |
| 4624 } | |
| 4625 }; | |
| 4626 | |
| 4627 (function() { | |
| 4628 'use strict'; | |
| 4629 Polymer({ | |
| 4630 is: 'iron-overlay-backdrop', | |
| 4631 properties: { | |
| 4632 opened: { | |
| 4633 reflectToAttribute: true, | |
| 4634 type: Boolean, | |
| 4635 value: false, | |
| 4636 observer: '_openedChanged' | |
| 4637 } | |
| 4638 }, | |
| 4639 listeners: { | |
| 4640 transitionend: '_onTransitionend' | |
| 4641 }, | |
| 4642 created: function() { | |
| 4643 this.__openedRaf = null; | |
| 4644 }, | |
| 4645 attached: function() { | |
| 4646 this.opened && this._openedChanged(this.opened); | |
| 4647 }, | |
| 4648 prepare: function() { | |
| 4649 if (this.opened && !this.parentNode) { | |
| 4650 Polymer.dom(document.body).appendChild(this); | |
| 4651 } | |
| 4652 }, | |
| 4653 open: function() { | |
| 4654 this.opened = true; | |
| 4655 }, | |
| 4656 close: function() { | |
| 4657 this.opened = false; | |
| 4658 }, | |
| 4659 complete: function() { | |
| 4660 if (!this.opened && this.parentNode === document.body) { | |
| 4661 Polymer.dom(this.parentNode).removeChild(this); | |
| 4662 } | |
| 4663 }, | |
| 4664 _onTransitionend: function(event) { | |
| 4665 if (event && event.target === this) { | |
| 4666 this.complete(); | |
| 4667 } | |
| 4668 }, | |
| 4669 _openedChanged: function(opened) { | |
| 4670 if (opened) { | |
| 4671 this.prepare(); | |
| 4672 } else { | |
| 4673 var cs = window.getComputedStyle(this); | |
| 4674 if (cs.transitionDuration === '0s' || cs.opacity == 0) { | |
| 4675 this.complete(); | |
| 4676 } | |
| 4677 } | |
| 4678 if (!this.isAttached) { | |
| 4679 return; | |
| 4680 } | |
| 4681 if (this.__openedRaf) { | |
| 4682 window.cancelAnimationFrame(this.__openedRaf); | |
| 4683 this.__openedRaf = null; | |
| 4684 } | |
| 4685 this.scrollTop = this.scrollTop; | |
| 4686 this.__openedRaf = window.requestAnimationFrame(function() { | |
| 4687 this.__openedRaf = null; | |
| 4688 this.toggleClass('opened', this.opened); | |
| 4689 }.bind(this)); | |
| 4690 } | |
| 4691 }); | |
| 4692 })(); | |
| 4693 | |
| 4694 Polymer.IronOverlayManagerClass = function() { | |
| 4695 this._overlays = []; | |
| 4696 this._minimumZ = 101; | |
| 4697 this._backdropElement = null; | |
| 4698 Polymer.Gestures.add(document, 'tap', this._onCaptureClick.bind(this)); | |
| 4699 document.addEventListener('focus', this._onCaptureFocus.bind(this), true); | |
| 4700 document.addEventListener('keydown', this._onCaptureKeyDown.bind(this), true); | |
| 4701 }; | |
| 4702 | |
| 4703 Polymer.IronOverlayManagerClass.prototype = { | |
| 4704 constructor: Polymer.IronOverlayManagerClass, | |
| 4705 get backdropElement() { | |
| 4706 if (!this._backdropElement) { | |
| 4707 this._backdropElement = document.createElement('iron-overlay-backdrop'); | |
| 4708 } | |
| 4709 return this._backdropElement; | |
| 4710 }, | |
| 4711 get deepActiveElement() { | |
| 4712 var active = document.activeElement || document.body; | |
| 4713 while (active.root && Polymer.dom(active.root).activeElement) { | |
| 4714 active = Polymer.dom(active.root).activeElement; | |
| 4715 } | |
| 4716 return active; | |
| 4717 }, | |
| 4718 _bringOverlayAtIndexToFront: function(i) { | |
| 4719 var overlay = this._overlays[i]; | |
| 4720 if (!overlay) { | |
| 4721 return; | |
| 4722 } | |
| 4723 var lastI = this._overlays.length - 1; | |
| 4724 var currentOverlay = this._overlays[lastI]; | |
| 4725 if (currentOverlay && this._shouldBeBehindOverlay(overlay, currentOverlay))
{ | |
| 4726 lastI--; | |
| 4727 } | |
| 4728 if (i >= lastI) { | |
| 4729 return; | |
| 4730 } | |
| 4731 var minimumZ = Math.max(this.currentOverlayZ(), this._minimumZ); | |
| 4732 if (this._getZ(overlay) <= minimumZ) { | |
| 4733 this._applyOverlayZ(overlay, minimumZ); | |
| 4734 } | |
| 4735 while (i < lastI) { | |
| 4736 this._overlays[i] = this._overlays[i + 1]; | |
| 4737 i++; | |
| 4738 } | |
| 4739 this._overlays[lastI] = overlay; | |
| 4740 }, | |
| 4741 addOrRemoveOverlay: function(overlay) { | |
| 4742 if (overlay.opened) { | |
| 4743 this.addOverlay(overlay); | |
| 4744 } else { | |
| 4745 this.removeOverlay(overlay); | |
| 4746 } | |
| 4747 }, | |
| 4748 addOverlay: function(overlay) { | |
| 4749 var i = this._overlays.indexOf(overlay); | |
| 4750 if (i >= 0) { | |
| 4751 this._bringOverlayAtIndexToFront(i); | |
| 4752 this.trackBackdrop(); | |
| 4753 return; | |
| 4754 } | |
| 4755 var insertionIndex = this._overlays.length; | |
| 4756 var currentOverlay = this._overlays[insertionIndex - 1]; | |
| 4757 var minimumZ = Math.max(this._getZ(currentOverlay), this._minimumZ); | |
| 4758 var newZ = this._getZ(overlay); | |
| 4759 if (currentOverlay && this._shouldBeBehindOverlay(overlay, currentOverlay))
{ | |
| 4760 this._applyOverlayZ(currentOverlay, minimumZ); | |
| 4761 insertionIndex--; | |
| 4762 var previousOverlay = this._overlays[insertionIndex - 1]; | |
| 4763 minimumZ = Math.max(this._getZ(previousOverlay), this._minimumZ); | |
| 4764 } | |
| 4765 if (newZ <= minimumZ) { | |
| 4766 this._applyOverlayZ(overlay, minimumZ); | |
| 4767 } | |
| 4768 this._overlays.splice(insertionIndex, 0, overlay); | |
| 4769 this.trackBackdrop(); | |
| 4770 }, | |
| 4771 removeOverlay: function(overlay) { | |
| 4772 var i = this._overlays.indexOf(overlay); | |
| 4773 if (i === -1) { | |
| 4774 return; | |
| 4775 } | |
| 4776 this._overlays.splice(i, 1); | |
| 4777 this.trackBackdrop(); | |
| 4778 }, | |
| 4779 currentOverlay: function() { | |
| 4780 var i = this._overlays.length - 1; | |
| 4781 return this._overlays[i]; | |
| 4782 }, | |
| 4783 currentOverlayZ: function() { | |
| 4784 return this._getZ(this.currentOverlay()); | |
| 4785 }, | |
| 4786 ensureMinimumZ: function(minimumZ) { | |
| 4787 this._minimumZ = Math.max(this._minimumZ, minimumZ); | |
| 4788 }, | |
| 4789 focusOverlay: function() { | |
| 4790 var current = this.currentOverlay(); | |
| 4791 if (current) { | |
| 4792 current._applyFocus(); | |
| 4793 } | |
| 4794 }, | |
| 4795 trackBackdrop: function() { | |
| 4796 var overlay = this._overlayWithBackdrop(); | |
| 4797 if (!overlay && !this._backdropElement) { | |
| 4798 return; | |
| 4799 } | |
| 4800 this.backdropElement.style.zIndex = this._getZ(overlay) - 1; | |
| 4801 this.backdropElement.opened = !!overlay; | |
| 4802 }, | |
| 4803 getBackdrops: function() { | |
| 4804 var backdrops = []; | |
| 4805 for (var i = 0; i < this._overlays.length; i++) { | |
| 4806 if (this._overlays[i].withBackdrop) { | |
| 4807 backdrops.push(this._overlays[i]); | |
| 4808 } | |
| 4809 } | |
| 4810 return backdrops; | |
| 4811 }, | |
| 4812 backdropZ: function() { | |
| 4813 return this._getZ(this._overlayWithBackdrop()) - 1; | |
| 4814 }, | |
| 4815 _overlayWithBackdrop: function() { | |
| 4816 for (var i = 0; i < this._overlays.length; i++) { | |
| 4817 if (this._overlays[i].withBackdrop) { | |
| 4818 return this._overlays[i]; | |
| 4819 } | |
| 4820 } | |
| 4821 }, | |
| 4822 _getZ: function(overlay) { | |
| 4823 var z = this._minimumZ; | |
| 4824 if (overlay) { | |
| 4825 var z1 = Number(overlay.style.zIndex || window.getComputedStyle(overlay).z
Index); | |
| 4826 if (z1 === z1) { | |
| 4827 z = z1; | |
| 4828 } | |
| 4829 } | |
| 4830 return z; | |
| 4831 }, | |
| 4832 _setZ: function(element, z) { | |
| 4833 element.style.zIndex = z; | |
| 4834 }, | |
| 4835 _applyOverlayZ: function(overlay, aboveZ) { | |
| 4836 this._setZ(overlay, aboveZ + 2); | |
| 4837 }, | |
| 4838 _overlayInPath: function(path) { | |
| 4839 path = path || []; | |
| 4840 for (var i = 0; i < path.length; i++) { | |
| 4841 if (path[i]._manager === this) { | |
| 4842 return path[i]; | |
| 4843 } | |
| 4844 } | |
| 4845 }, | |
| 4846 _onCaptureClick: function(event) { | |
| 4847 var overlay = this.currentOverlay(); | |
| 4848 if (overlay && this._overlayInPath(Polymer.dom(event).path) !== overlay) { | |
| 4849 overlay._onCaptureClick(event); | |
| 4850 } | |
| 4851 }, | |
| 4852 _onCaptureFocus: function(event) { | |
| 4853 var overlay = this.currentOverlay(); | |
| 4854 if (overlay) { | |
| 4855 overlay._onCaptureFocus(event); | |
| 4856 } | |
| 4857 }, | |
| 4858 _onCaptureKeyDown: function(event) { | |
| 4859 var overlay = this.currentOverlay(); | |
| 4860 if (overlay) { | |
| 4861 if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(event, 'esc')) { | |
| 4862 overlay._onCaptureEsc(event); | |
| 4863 } else if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(event, 't
ab')) { | |
| 4864 overlay._onCaptureTab(event); | |
| 4865 } | |
| 4866 } | |
| 4867 }, | |
| 4868 _shouldBeBehindOverlay: function(overlay1, overlay2) { | |
| 4869 return !overlay1.alwaysOnTop && overlay2.alwaysOnTop; | |
| 4870 } | |
| 4871 }; | |
| 4872 | |
| 4873 Polymer.IronOverlayManager = new Polymer.IronOverlayManagerClass(); | |
| 4874 | |
| 4875 (function() { | |
| 4876 'use strict'; | |
| 4877 Polymer.IronOverlayBehaviorImpl = { | |
| 4878 properties: { | |
| 4879 opened: { | |
| 4880 observer: '_openedChanged', | |
| 4881 type: Boolean, | |
| 4882 value: false, | |
| 4883 notify: true | |
| 4884 }, | |
| 4885 canceled: { | |
| 4886 observer: '_canceledChanged', | |
| 4887 readOnly: true, | |
| 4888 type: Boolean, | |
| 4889 value: false | |
| 4890 }, | |
| 4891 withBackdrop: { | |
| 4892 observer: '_withBackdropChanged', | |
| 4893 type: Boolean | |
| 4894 }, | |
| 4895 noAutoFocus: { | |
| 4896 type: Boolean, | |
| 4897 value: false | |
| 4898 }, | |
| 4899 noCancelOnEscKey: { | |
| 4900 type: Boolean, | |
| 4901 value: false | |
| 4902 }, | |
| 4903 noCancelOnOutsideClick: { | |
| 4904 type: Boolean, | |
| 4905 value: false | |
| 4906 }, | |
| 4907 closingReason: { | |
| 4908 type: Object | |
| 4909 }, | |
| 4910 restoreFocusOnClose: { | |
| 4911 type: Boolean, | |
| 4912 value: false | |
| 4913 }, | |
| 4914 alwaysOnTop: { | |
| 4915 type: Boolean | |
| 4916 }, | |
| 4917 _manager: { | |
| 4918 type: Object, | |
| 4919 value: Polymer.IronOverlayManager | |
| 4920 }, | |
| 4921 _focusedChild: { | |
| 4922 type: Object | |
| 4923 } | |
| 4924 }, | |
| 4925 listeners: { | |
| 4926 'iron-resize': '_onIronResize' | |
| 4927 }, | |
| 4928 get backdropElement() { | |
| 4929 return this._manager.backdropElement; | |
| 4930 }, | |
| 4931 get _focusNode() { | |
| 4932 return this._focusedChild || Polymer.dom(this).querySelector('[autofocus]'
) || this; | |
| 4933 }, | |
| 4934 get _focusableNodes() { | |
| 4935 var FOCUSABLE_WITH_DISABLED = [ 'a[href]', 'area[href]', 'iframe', '[tabin
dex]', '[contentEditable=true]' ]; | |
| 4936 var FOCUSABLE_WITHOUT_DISABLED = [ 'input', 'select', 'textarea', 'button'
]; | |
| 4937 var selector = FOCUSABLE_WITH_DISABLED.join(':not([tabindex="-1"]),') + ':
not([tabindex="-1"]),' + FOCUSABLE_WITHOUT_DISABLED.join(':not([disabled]):not([
tabindex="-1"]),') + ':not([disabled]):not([tabindex="-1"])'; | |
| 4938 var focusables = Polymer.dom(this).querySelectorAll(selector); | |
| 4939 if (this.tabIndex >= 0) { | |
| 4940 focusables.splice(0, 0, this); | |
| 4941 } | |
| 4942 return focusables.sort(function(a, b) { | |
| 4943 if (a.tabIndex === b.tabIndex) { | |
| 4944 return 0; | |
| 4945 } | |
| 4946 if (a.tabIndex === 0 || a.tabIndex > b.tabIndex) { | |
| 4947 return 1; | |
| 4948 } | |
| 4949 return -1; | |
| 4950 }); | |
| 4951 }, | |
| 4952 ready: function() { | |
| 4953 this.__isAnimating = false; | |
| 4954 this.__shouldRemoveTabIndex = false; | |
| 4955 this.__firstFocusableNode = this.__lastFocusableNode = null; | |
| 4956 this.__raf = null; | |
| 4957 this.__restoreFocusNode = null; | |
| 4958 this._ensureSetup(); | |
| 4959 }, | |
| 4960 attached: function() { | |
| 4961 if (this.opened) { | |
| 4962 this._openedChanged(this.opened); | |
| 4963 } | |
| 4964 this._observer = Polymer.dom(this).observeNodes(this._onNodesChange); | |
| 4965 }, | |
| 4966 detached: function() { | |
| 4967 Polymer.dom(this).unobserveNodes(this._observer); | |
| 4968 this._observer = null; | |
| 4969 if (this.__raf) { | |
| 4970 window.cancelAnimationFrame(this.__raf); | |
| 4971 this.__raf = null; | |
| 4972 } | |
| 4973 this._manager.removeOverlay(this); | |
| 4974 }, | |
| 4975 toggle: function() { | |
| 4976 this._setCanceled(false); | |
| 4977 this.opened = !this.opened; | |
| 4978 }, | |
| 4979 open: function() { | |
| 4980 this._setCanceled(false); | |
| 4981 this.opened = true; | |
| 4982 }, | |
| 4983 close: function() { | |
| 4984 this._setCanceled(false); | |
| 4985 this.opened = false; | |
| 4986 }, | |
| 4987 cancel: function(event) { | |
| 4988 var cancelEvent = this.fire('iron-overlay-canceled', event, { | |
| 4989 cancelable: true | |
| 4990 }); | |
| 4991 if (cancelEvent.defaultPrevented) { | |
| 4992 return; | |
| 4993 } | |
| 4994 this._setCanceled(true); | |
| 4995 this.opened = false; | |
| 4996 }, | |
| 4997 _ensureSetup: function() { | |
| 4998 if (this._overlaySetup) { | |
| 4999 return; | |
| 5000 } | |
| 5001 this._overlaySetup = true; | |
| 5002 this.style.outline = 'none'; | |
| 5003 this.style.display = 'none'; | |
| 5004 }, | |
| 5005 _openedChanged: function(opened) { | |
| 5006 if (opened) { | |
| 5007 this.removeAttribute('aria-hidden'); | |
| 5008 } else { | |
| 5009 this.setAttribute('aria-hidden', 'true'); | |
| 5010 } | |
| 5011 if (!this.isAttached) { | |
| 5012 return; | |
| 5013 } | |
| 5014 this.__isAnimating = true; | |
| 5015 this.__onNextAnimationFrame(this.__openedChanged); | |
| 5016 }, | |
| 5017 _canceledChanged: function() { | |
| 5018 this.closingReason = this.closingReason || {}; | |
| 5019 this.closingReason.canceled = this.canceled; | |
| 5020 }, | |
| 5021 _withBackdropChanged: function() { | |
| 5022 if (this.withBackdrop && !this.hasAttribute('tabindex')) { | |
| 5023 this.setAttribute('tabindex', '-1'); | |
| 5024 this.__shouldRemoveTabIndex = true; | |
| 5025 } else if (this.__shouldRemoveTabIndex) { | |
| 5026 this.removeAttribute('tabindex'); | |
| 5027 this.__shouldRemoveTabIndex = false; | |
| 5028 } | |
| 5029 if (this.opened && this.isAttached) { | |
| 5030 this._manager.trackBackdrop(); | |
| 5031 } | |
| 5032 }, | |
| 5033 _prepareRenderOpened: function() { | |
| 5034 this.__restoreFocusNode = this._manager.deepActiveElement; | |
| 5035 this._preparePositioning(); | |
| 5036 this.refit(); | |
| 5037 this._finishPositioning(); | |
| 5038 if (this.noAutoFocus && document.activeElement === this._focusNode) { | |
| 5039 this._focusNode.blur(); | |
| 5040 this.__restoreFocusNode.focus(); | |
| 5041 } | |
| 5042 }, | |
| 5043 _renderOpened: function() { | |
| 5044 this._finishRenderOpened(); | |
| 5045 }, | |
| 5046 _renderClosed: function() { | |
| 5047 this._finishRenderClosed(); | |
| 5048 }, | |
| 5049 _finishRenderOpened: function() { | |
| 5050 this.notifyResize(); | |
| 5051 this.__isAnimating = false; | |
| 5052 var focusableNodes = this._focusableNodes; | |
| 5053 this.__firstFocusableNode = focusableNodes[0]; | |
| 5054 this.__lastFocusableNode = focusableNodes[focusableNodes.length - 1]; | |
| 5055 this.fire('iron-overlay-opened'); | |
| 5056 }, | |
| 5057 _finishRenderClosed: function() { | |
| 5058 this.style.display = 'none'; | |
| 5059 this.style.zIndex = ''; | |
| 5060 this.notifyResize(); | |
| 5061 this.__isAnimating = false; | |
| 5062 this.fire('iron-overlay-closed', this.closingReason); | |
| 5063 }, | |
| 5064 _preparePositioning: function() { | |
| 5065 this.style.transition = this.style.webkitTransition = 'none'; | |
| 5066 this.style.transform = this.style.webkitTransform = 'none'; | |
| 5067 this.style.display = ''; | |
| 5068 }, | |
| 5069 _finishPositioning: function() { | |
| 5070 this.style.display = 'none'; | |
| 5071 this.scrollTop = this.scrollTop; | |
| 5072 this.style.transition = this.style.webkitTransition = ''; | |
| 5073 this.style.transform = this.style.webkitTransform = ''; | |
| 5074 this.style.display = ''; | |
| 5075 this.scrollTop = this.scrollTop; | |
| 5076 }, | |
| 5077 _applyFocus: function() { | |
| 5078 if (this.opened) { | |
| 5079 if (!this.noAutoFocus) { | |
| 5080 this._focusNode.focus(); | |
| 5081 } | |
| 5082 } else { | |
| 5083 this._focusNode.blur(); | |
| 5084 this._focusedChild = null; | |
| 5085 if (this.restoreFocusOnClose && this.__restoreFocusNode) { | |
| 5086 this.__restoreFocusNode.focus(); | |
| 5087 } | |
| 5088 this.__restoreFocusNode = null; | |
| 5089 var currentOverlay = this._manager.currentOverlay(); | |
| 5090 if (currentOverlay && this !== currentOverlay) { | |
| 5091 currentOverlay._applyFocus(); | |
| 5092 } | |
| 5093 } | |
| 5094 }, | |
| 5095 _onCaptureClick: function(event) { | |
| 5096 if (!this.noCancelOnOutsideClick) { | |
| 5097 this.cancel(event); | |
| 5098 } | |
| 5099 }, | |
| 5100 _onCaptureFocus: function(event) { | |
| 5101 if (!this.withBackdrop) { | |
| 5102 return; | |
| 5103 } | |
| 5104 var path = Polymer.dom(event).path; | |
| 5105 if (path.indexOf(this) === -1) { | |
| 5106 event.stopPropagation(); | |
| 5107 this._applyFocus(); | |
| 5108 } else { | |
| 5109 this._focusedChild = path[0]; | |
| 5110 } | |
| 5111 }, | |
| 5112 _onCaptureEsc: function(event) { | |
| 5113 if (!this.noCancelOnEscKey) { | |
| 5114 this.cancel(event); | |
| 5115 } | |
| 5116 }, | |
| 5117 _onCaptureTab: function(event) { | |
| 5118 if (!this.withBackdrop) { | |
| 5119 return; | |
| 5120 } | |
| 5121 var shift = event.shiftKey; | |
| 5122 var nodeToCheck = shift ? this.__firstFocusableNode : this.__lastFocusable
Node; | |
| 5123 var nodeToSet = shift ? this.__lastFocusableNode : this.__firstFocusableNo
de; | |
| 5124 var shouldWrap = false; | |
| 5125 if (nodeToCheck === nodeToSet) { | |
| 5126 shouldWrap = true; | |
| 5127 } else { | |
| 5128 var focusedNode = this._manager.deepActiveElement; | |
| 5129 shouldWrap = focusedNode === nodeToCheck || focusedNode === this; | |
| 5130 } | |
| 5131 if (shouldWrap) { | |
| 5132 event.preventDefault(); | |
| 5133 this._focusedChild = nodeToSet; | |
| 5134 this._applyFocus(); | |
| 5135 } | |
| 5136 }, | |
| 5137 _onIronResize: function() { | |
| 5138 if (this.opened && !this.__isAnimating) { | |
| 5139 this.__onNextAnimationFrame(this.refit); | |
| 5140 } | |
| 5141 }, | |
| 5142 _onNodesChange: function() { | |
| 5143 if (this.opened && !this.__isAnimating) { | |
| 5144 this.notifyResize(); | |
| 5145 } | |
| 5146 }, | |
| 5147 __openedChanged: function() { | |
| 5148 if (this.opened) { | |
| 5149 this._prepareRenderOpened(); | |
| 5150 this._manager.addOverlay(this); | |
| 5151 this._applyFocus(); | |
| 5152 this._renderOpened(); | |
| 5153 } else { | |
| 5154 this._manager.removeOverlay(this); | |
| 5155 this._applyFocus(); | |
| 5156 this._renderClosed(); | |
| 5157 } | |
| 5158 }, | |
| 5159 __onNextAnimationFrame: function(callback) { | |
| 5160 if (this.__raf) { | |
| 5161 window.cancelAnimationFrame(this.__raf); | |
| 5162 } | |
| 5163 var self = this; | |
| 5164 this.__raf = window.requestAnimationFrame(function nextAnimationFrame() { | |
| 5165 self.__raf = null; | |
| 5166 callback.call(self); | |
| 5167 }); | |
| 5168 } | |
| 5169 }; | |
| 5170 Polymer.IronOverlayBehavior = [ Polymer.IronFitBehavior, Polymer.IronResizable
Behavior, Polymer.IronOverlayBehaviorImpl ]; | |
| 5171 })(); | |
| 5172 | |
| 5173 Polymer.NeonAnimatableBehavior = { | |
| 5174 properties: { | |
| 5175 animationConfig: { | |
| 5176 type: Object | |
| 5177 }, | |
| 5178 entryAnimation: { | |
| 5179 observer: '_entryAnimationChanged', | |
| 5180 type: String | |
| 5181 }, | |
| 5182 exitAnimation: { | |
| 5183 observer: '_exitAnimationChanged', | |
| 5184 type: String | |
| 5185 } | |
| 5186 }, | |
| 5187 _entryAnimationChanged: function() { | |
| 5188 this.animationConfig = this.animationConfig || {}; | |
| 5189 this.animationConfig['entry'] = [ { | |
| 5190 name: this.entryAnimation, | |
| 5191 node: this | |
| 5192 } ]; | |
| 5193 }, | |
| 5194 _exitAnimationChanged: function() { | |
| 5195 this.animationConfig = this.animationConfig || {}; | |
| 5196 this.animationConfig['exit'] = [ { | |
| 5197 name: this.exitAnimation, | |
| 5198 node: this | |
| 5199 } ]; | |
| 5200 }, | |
| 5201 _copyProperties: function(config1, config2) { | |
| 5202 for (var property in config2) { | |
| 5203 config1[property] = config2[property]; | |
| 5204 } | |
| 5205 }, | |
| 5206 _cloneConfig: function(config) { | |
| 5207 var clone = { | |
| 5208 isClone: true | |
| 5209 }; | |
| 5210 this._copyProperties(clone, config); | |
| 5211 return clone; | |
| 5212 }, | |
| 5213 _getAnimationConfigRecursive: function(type, map, allConfigs) { | |
| 5214 if (!this.animationConfig) { | |
| 5215 return; | |
| 5216 } | |
| 5217 if (this.animationConfig.value && typeof this.animationConfig.value === 'fun
ction') { | |
| 5218 this._warn(this._logf('playAnimation', "Please put 'animationConfig' insid
e of your components 'properties' object instead of outside of it.")); | |
| 5219 return; | |
| 5220 } | |
| 5221 var thisConfig; | |
| 5222 if (type) { | |
| 5223 thisConfig = this.animationConfig[type]; | |
| 5224 } else { | |
| 5225 thisConfig = this.animationConfig; | |
| 5226 } | |
| 5227 if (!Array.isArray(thisConfig)) { | |
| 5228 thisConfig = [ thisConfig ]; | |
| 5229 } | |
| 5230 if (thisConfig) { | |
| 5231 for (var config, index = 0; config = thisConfig[index]; index++) { | |
| 5232 if (config.animatable) { | |
| 5233 config.animatable._getAnimationConfigRecursive(config.type || type, ma
p, allConfigs); | |
| 5234 } else { | |
| 5235 if (config.id) { | |
| 5236 var cachedConfig = map[config.id]; | |
| 5237 if (cachedConfig) { | |
| 5238 if (!cachedConfig.isClone) { | |
| 5239 map[config.id] = this._cloneConfig(cachedConfig); | |
| 5240 cachedConfig = map[config.id]; | |
| 5241 } | |
| 5242 this._copyProperties(cachedConfig, config); | |
| 5243 } else { | |
| 5244 map[config.id] = config; | |
| 5245 } | |
| 5246 } else { | |
| 5247 allConfigs.push(config); | |
| 5248 } | |
| 5249 } | |
| 5250 } | |
| 5251 } | |
| 5252 }, | |
| 5253 getAnimationConfig: function(type) { | |
| 5254 var map = {}; | |
| 5255 var allConfigs = []; | |
| 5256 this._getAnimationConfigRecursive(type, map, allConfigs); | |
| 5257 for (var key in map) { | |
| 5258 allConfigs.push(map[key]); | |
| 5259 } | |
| 5260 return allConfigs; | |
| 5261 } | |
| 5262 }; | |
| 5263 | |
| 5264 Polymer.NeonAnimationRunnerBehaviorImpl = { | |
| 5265 _configureAnimations: function(configs) { | |
| 5266 var results = []; | |
| 5267 if (configs.length > 0) { | |
| 5268 for (var config, index = 0; config = configs[index]; index++) { | |
| 5269 var neonAnimation = document.createElement(config.name); | |
| 5270 if (neonAnimation.isNeonAnimation) { | |
| 5271 var result = null; | |
| 5272 try { | |
| 5273 result = neonAnimation.configure(config); | |
| 5274 if (typeof result.cancel != 'function') { | |
| 5275 result = document.timeline.play(result); | |
| 5276 } | |
| 5277 } catch (e) { | |
| 5278 result = null; | |
| 5279 console.warn('Couldnt play', '(', config.name, ').', e); | |
| 5280 } | |
| 5281 if (result) { | |
| 5282 results.push({ | |
| 5283 neonAnimation: neonAnimation, | |
| 5284 config: config, | |
| 5285 animation: result | |
| 5286 }); | |
| 5287 } | |
| 5288 } else { | |
| 5289 console.warn(this.is + ':', config.name, 'not found!'); | |
| 5290 } | |
| 5291 } | |
| 5292 } | |
| 5293 return results; | |
| 5294 }, | |
| 5295 _shouldComplete: function(activeEntries) { | |
| 5296 var finished = true; | |
| 5297 for (var i = 0; i < activeEntries.length; i++) { | |
| 5298 if (activeEntries[i].animation.playState != 'finished') { | |
| 5299 finished = false; | |
| 5300 break; | |
| 5301 } | |
| 5302 } | |
| 5303 return finished; | |
| 5304 }, | |
| 5305 _complete: function(activeEntries) { | |
| 5306 for (var i = 0; i < activeEntries.length; i++) { | |
| 5307 activeEntries[i].neonAnimation.complete(activeEntries[i].config); | |
| 5308 } | |
| 5309 for (var i = 0; i < activeEntries.length; i++) { | |
| 5310 activeEntries[i].animation.cancel(); | |
| 5311 } | |
| 5312 }, | |
| 5313 playAnimation: function(type, cookie) { | |
| 5314 var configs = this.getAnimationConfig(type); | |
| 5315 if (!configs) { | |
| 5316 return; | |
| 5317 } | |
| 5318 this._active = this._active || {}; | |
| 5319 if (this._active[type]) { | |
| 5320 this._complete(this._active[type]); | |
| 5321 delete this._active[type]; | |
| 5322 } | |
| 5323 var activeEntries = this._configureAnimations(configs); | |
| 5324 if (activeEntries.length == 0) { | |
| 5325 this.fire('neon-animation-finish', cookie, { | |
| 5326 bubbles: false | |
| 5327 }); | |
| 5328 return; | |
| 5329 } | |
| 5330 this._active[type] = activeEntries; | |
| 5331 for (var i = 0; i < activeEntries.length; i++) { | |
| 5332 activeEntries[i].animation.onfinish = function() { | |
| 5333 if (this._shouldComplete(activeEntries)) { | |
| 5334 this._complete(activeEntries); | |
| 5335 delete this._active[type]; | |
| 5336 this.fire('neon-animation-finish', cookie, { | |
| 5337 bubbles: false | |
| 5338 }); | |
| 5339 } | |
| 5340 }.bind(this); | |
| 5341 } | |
| 5342 }, | |
| 5343 cancelAnimation: function() { | |
| 5344 for (var k in this._animations) { | |
| 5345 this._animations[k].cancel(); | |
| 5346 } | |
| 5347 this._animations = {}; | |
| 5348 } | |
| 5349 }; | |
| 5350 | |
| 5351 Polymer.NeonAnimationRunnerBehavior = [ Polymer.NeonAnimatableBehavior, Polymer.
NeonAnimationRunnerBehaviorImpl ]; | |
| 5352 | |
| 5353 Polymer.NeonAnimationBehavior = { | |
| 5354 properties: { | |
| 5355 animationTiming: { | |
| 5356 type: Object, | |
| 5357 value: function() { | |
| 5358 return { | |
| 5359 duration: 500, | |
| 5360 easing: 'cubic-bezier(0.4, 0, 0.2, 1)', | |
| 5361 fill: 'both' | |
| 5362 }; | |
| 5363 } | |
| 5364 } | |
| 5365 }, | |
| 5366 isNeonAnimation: true, | |
| 5367 timingFromConfig: function(config) { | |
| 5368 if (config.timing) { | |
| 5369 for (var property in config.timing) { | |
| 5370 this.animationTiming[property] = config.timing[property]; | |
| 5371 } | |
| 5372 } | |
| 5373 return this.animationTiming; | |
| 5374 }, | |
| 5375 setPrefixedProperty: function(node, property, value) { | |
| 5376 var map = { | |
| 5377 transform: [ 'webkitTransform' ], | |
| 5378 transformOrigin: [ 'mozTransformOrigin', 'webkitTransformOrigin' ] | |
| 5379 }; | |
| 5380 var prefixes = map[property]; | |
| 5381 for (var prefix, index = 0; prefix = prefixes[index]; index++) { | |
| 5382 node.style[prefix] = value; | |
| 5383 } | |
| 5384 node.style[property] = value; | |
| 5385 }, | |
| 5386 complete: function() {} | |
| 5387 }; | |
| 5388 | |
| 5389 Polymer({ | |
| 5390 is: 'opaque-animation', | |
| 5391 behaviors: [ Polymer.NeonAnimationBehavior ], | |
| 5392 configure: function(config) { | |
| 5393 var node = config.node; | |
| 5394 this._effect = new KeyframeEffect(node, [ { | |
| 5395 opacity: '1' | |
| 5396 }, { | |
| 5397 opacity: '1' | |
| 5398 } ], this.timingFromConfig(config)); | |
| 5399 node.style.opacity = '0'; | |
| 5400 return this._effect; | |
| 5401 }, | |
| 5402 complete: function(config) { | |
| 5403 config.node.style.opacity = ''; | |
| 5404 } | |
| 5405 }); | |
| 5406 | |
| 5407 (function() { | |
| 5408 'use strict'; | |
| 5409 var LAST_TOUCH_POSITION = { | |
| 5410 pageX: 0, | |
| 5411 pageY: 0 | |
| 5412 }; | |
| 5413 var ROOT_TARGET = null; | |
| 5414 var SCROLLABLE_NODES = []; | |
| 5415 Polymer.IronDropdownScrollManager = { | |
| 5416 get currentLockingElement() { | |
| 5417 return this._lockingElements[this._lockingElements.length - 1]; | |
| 5418 }, | |
| 5419 elementIsScrollLocked: function(element) { | |
| 5420 var currentLockingElement = this.currentLockingElement; | |
| 5421 if (currentLockingElement === undefined) return false; | |
| 5422 var scrollLocked; | |
| 5423 if (this._hasCachedLockedElement(element)) { | |
| 5424 return true; | |
| 5425 } | |
| 5426 if (this._hasCachedUnlockedElement(element)) { | |
| 5427 return false; | |
| 5428 } | |
| 5429 scrollLocked = !!currentLockingElement && currentLockingElement !== elemen
t && !this._composedTreeContains(currentLockingElement, element); | |
| 5430 if (scrollLocked) { | |
| 5431 this._lockedElementCache.push(element); | |
| 5432 } else { | |
| 5433 this._unlockedElementCache.push(element); | |
| 5434 } | |
| 5435 return scrollLocked; | |
| 5436 }, | |
| 5437 pushScrollLock: function(element) { | |
| 5438 if (this._lockingElements.indexOf(element) >= 0) { | |
| 5439 return; | |
| 5440 } | |
| 5441 if (this._lockingElements.length === 0) { | |
| 5442 this._lockScrollInteractions(); | |
| 5443 } | |
| 5444 this._lockingElements.push(element); | |
| 5445 this._lockedElementCache = []; | |
| 5446 this._unlockedElementCache = []; | |
| 5447 }, | |
| 5448 removeScrollLock: function(element) { | |
| 5449 var index = this._lockingElements.indexOf(element); | |
| 5450 if (index === -1) { | |
| 5451 return; | |
| 5452 } | |
| 5453 this._lockingElements.splice(index, 1); | |
| 5454 this._lockedElementCache = []; | |
| 5455 this._unlockedElementCache = []; | |
| 5456 if (this._lockingElements.length === 0) { | |
| 5457 this._unlockScrollInteractions(); | |
| 5458 } | |
| 5459 }, | |
| 5460 _lockingElements: [], | |
| 5461 _lockedElementCache: null, | |
| 5462 _unlockedElementCache: null, | |
| 5463 _hasCachedLockedElement: function(element) { | |
| 5464 return this._lockedElementCache.indexOf(element) > -1; | |
| 5465 }, | |
| 5466 _hasCachedUnlockedElement: function(element) { | |
| 5467 return this._unlockedElementCache.indexOf(element) > -1; | |
| 5468 }, | |
| 5469 _composedTreeContains: function(element, child) { | |
| 5470 var contentElements; | |
| 5471 var distributedNodes; | |
| 5472 var contentIndex; | |
| 5473 var nodeIndex; | |
| 5474 if (element.contains(child)) { | |
| 5475 return true; | |
| 5476 } | |
| 5477 contentElements = Polymer.dom(element).querySelectorAll('content'); | |
| 5478 for (contentIndex = 0; contentIndex < contentElements.length; ++contentInd
ex) { | |
| 5479 distributedNodes = Polymer.dom(contentElements[contentIndex]).getDistrib
utedNodes(); | |
| 5480 for (nodeIndex = 0; nodeIndex < distributedNodes.length; ++nodeIndex) { | |
| 5481 if (this._composedTreeContains(distributedNodes[nodeIndex], child)) { | |
| 5482 return true; | |
| 5483 } | |
| 5484 } | |
| 5485 } | |
| 5486 return false; | |
| 5487 }, | |
| 5488 _scrollInteractionHandler: function(event) { | |
| 5489 if (event.cancelable && this._shouldPreventScrolling(event)) { | |
| 5490 event.preventDefault(); | |
| 5491 } | |
| 5492 if (event.targetTouches) { | |
| 5493 var touch = event.targetTouches[0]; | |
| 5494 LAST_TOUCH_POSITION.pageX = touch.pageX; | |
| 5495 LAST_TOUCH_POSITION.pageY = touch.pageY; | |
| 5496 } | |
| 5497 }, | |
| 5498 _lockScrollInteractions: function() { | |
| 5499 this._boundScrollHandler = this._boundScrollHandler || this._scrollInterac
tionHandler.bind(this); | |
| 5500 document.addEventListener('wheel', this._boundScrollHandler, true); | |
| 5501 document.addEventListener('mousewheel', this._boundScrollHandler, true); | |
| 5502 document.addEventListener('DOMMouseScroll', this._boundScrollHandler, true
); | |
| 5503 document.addEventListener('touchstart', this._boundScrollHandler, true); | |
| 5504 document.addEventListener('touchmove', this._boundScrollHandler, true); | |
| 5505 }, | |
| 5506 _unlockScrollInteractions: function() { | |
| 5507 document.removeEventListener('wheel', this._boundScrollHandler, true); | |
| 5508 document.removeEventListener('mousewheel', this._boundScrollHandler, true)
; | |
| 5509 document.removeEventListener('DOMMouseScroll', this._boundScrollHandler, t
rue); | |
| 5510 document.removeEventListener('touchstart', this._boundScrollHandler, true)
; | |
| 5511 document.removeEventListener('touchmove', this._boundScrollHandler, true); | |
| 5512 }, | |
| 5513 _shouldPreventScrolling: function(event) { | |
| 5514 var target = Polymer.dom(event).rootTarget; | |
| 5515 if (event.type !== 'touchmove' && ROOT_TARGET !== target) { | |
| 5516 ROOT_TARGET = target; | |
| 5517 SCROLLABLE_NODES = this._getScrollableNodes(Polymer.dom(event).path); | |
| 5518 } | |
| 5519 if (!SCROLLABLE_NODES.length) { | |
| 5520 return true; | |
| 5521 } | |
| 5522 if (event.type === 'touchstart') { | |
| 5523 return false; | |
| 5524 } | |
| 5525 var info = this._getScrollInfo(event); | |
| 5526 return !this._getScrollingNode(SCROLLABLE_NODES, info.deltaX, info.deltaY)
; | |
| 5527 }, | |
| 5528 _getScrollableNodes: function(nodes) { | |
| 5529 var scrollables = []; | |
| 5530 var lockingIndex = nodes.indexOf(this.currentLockingElement); | |
| 5531 for (var i = 0; i <= lockingIndex; i++) { | |
| 5532 var node = nodes[i]; | |
| 5533 if (node.nodeType === 11) { | |
| 5534 continue; | |
| 5535 } | |
| 5536 var style = node.style; | |
| 5537 if (style.overflow !== 'scroll' && style.overflow !== 'auto') { | |
| 5538 style = window.getComputedStyle(node); | |
| 5539 } | |
| 5540 if (style.overflow === 'scroll' || style.overflow === 'auto') { | |
| 5541 scrollables.push(node); | |
| 5542 } | |
| 5543 } | |
| 5544 return scrollables; | |
| 5545 }, | |
| 5546 _getScrollingNode: function(nodes, deltaX, deltaY) { | |
| 5547 if (!deltaX && !deltaY) { | |
| 5548 return; | |
| 5549 } | |
| 5550 var verticalScroll = Math.abs(deltaY) >= Math.abs(deltaX); | |
| 5551 for (var i = 0; i < nodes.length; i++) { | |
| 5552 var node = nodes[i]; | |
| 5553 var canScroll = false; | |
| 5554 if (verticalScroll) { | |
| 5555 canScroll = deltaY < 0 ? node.scrollTop > 0 : node.scrollTop < node.sc
rollHeight - node.clientHeight; | |
| 5556 } else { | |
| 5557 canScroll = deltaX < 0 ? node.scrollLeft > 0 : node.scrollLeft < node.
scrollWidth - node.clientWidth; | |
| 5558 } | |
| 5559 if (canScroll) { | |
| 5560 return node; | |
| 5561 } | |
| 5562 } | |
| 5563 }, | |
| 5564 _getScrollInfo: function(event) { | |
| 5565 var info = { | |
| 5566 deltaX: event.deltaX, | |
| 5567 deltaY: event.deltaY | |
| 5568 }; | |
| 5569 if ('deltaX' in event) {} else if ('wheelDeltaX' in event) { | |
| 5570 info.deltaX = -event.wheelDeltaX; | |
| 5571 info.deltaY = -event.wheelDeltaY; | |
| 5572 } else if ('axis' in event) { | |
| 5573 info.deltaX = event.axis === 1 ? event.detail : 0; | |
| 5574 info.deltaY = event.axis === 2 ? event.detail : 0; | |
| 5575 } else if (event.targetTouches) { | |
| 5576 var touch = event.targetTouches[0]; | |
| 5577 info.deltaX = LAST_TOUCH_POSITION.pageX - touch.pageX; | |
| 5578 info.deltaY = LAST_TOUCH_POSITION.pageY - touch.pageY; | |
| 5579 } | |
| 5580 return info; | |
| 5581 } | |
| 5582 }; | |
| 5583 })(); | |
| 5584 | |
| 5585 (function() { | |
| 5586 'use strict'; | |
| 5587 Polymer({ | |
| 5588 is: 'iron-dropdown', | |
| 5589 behaviors: [ Polymer.IronControlState, Polymer.IronA11yKeysBehavior, Polymer
.IronOverlayBehavior, Polymer.NeonAnimationRunnerBehavior ], | |
| 5590 properties: { | |
| 5591 horizontalAlign: { | |
| 5592 type: String, | |
| 5593 value: 'left', | |
| 5594 reflectToAttribute: true | |
| 5595 }, | |
| 5596 verticalAlign: { | |
| 5597 type: String, | |
| 5598 value: 'top', | |
| 5599 reflectToAttribute: true | |
| 5600 }, | |
| 5601 openAnimationConfig: { | |
| 5602 type: Object | |
| 5603 }, | |
| 5604 closeAnimationConfig: { | |
| 5605 type: Object | |
| 5606 }, | |
| 5607 focusTarget: { | |
| 5608 type: Object | |
| 5609 }, | |
| 5610 noAnimations: { | |
| 5611 type: Boolean, | |
| 5612 value: false | |
| 5613 }, | |
| 5614 allowOutsideScroll: { | |
| 5615 type: Boolean, | |
| 5616 value: false | |
| 5617 }, | |
| 5618 _boundOnCaptureScroll: { | |
| 5619 type: Function, | |
| 5620 value: function() { | |
| 5621 return this._onCaptureScroll.bind(this); | |
| 5622 } | |
| 5623 } | |
| 5624 }, | |
| 5625 listeners: { | |
| 5626 'neon-animation-finish': '_onNeonAnimationFinish' | |
| 5627 }, | |
| 5628 observers: [ '_updateOverlayPosition(positionTarget, verticalAlign, horizont
alAlign, verticalOffset, horizontalOffset)' ], | |
| 5629 get containedElement() { | |
| 5630 return Polymer.dom(this.$.content).getDistributedNodes()[0]; | |
| 5631 }, | |
| 5632 get _focusTarget() { | |
| 5633 return this.focusTarget || this.containedElement; | |
| 5634 }, | |
| 5635 ready: function() { | |
| 5636 this._scrollTop = 0; | |
| 5637 this._scrollLeft = 0; | |
| 5638 this._refitOnScrollRAF = null; | |
| 5639 }, | |
| 5640 attached: function() { | |
| 5641 if (!this.sizingTarget || this.sizingTarget === this) { | |
| 5642 this.sizingTarget = this.containedElement; | |
| 5643 } | |
| 5644 }, | |
| 5645 detached: function() { | |
| 5646 this.cancelAnimation(); | |
| 5647 document.removeEventListener('scroll', this._boundOnCaptureScroll); | |
| 5648 Polymer.IronDropdownScrollManager.removeScrollLock(this); | |
| 5649 }, | |
| 5650 _openedChanged: function() { | |
| 5651 if (this.opened && this.disabled) { | |
| 5652 this.cancel(); | |
| 5653 } else { | |
| 5654 this.cancelAnimation(); | |
| 5655 this._updateAnimationConfig(); | |
| 5656 this._saveScrollPosition(); | |
| 5657 if (this.opened) { | |
| 5658 document.addEventListener('scroll', this._boundOnCaptureScroll); | |
| 5659 !this.allowOutsideScroll && Polymer.IronDropdownScrollManager.pushScro
llLock(this); | |
| 5660 } else { | |
| 5661 document.removeEventListener('scroll', this._boundOnCaptureScroll); | |
| 5662 Polymer.IronDropdownScrollManager.removeScrollLock(this); | |
| 5663 } | |
| 5664 Polymer.IronOverlayBehaviorImpl._openedChanged.apply(this, arguments); | |
| 5665 } | |
| 5666 }, | |
| 5667 _renderOpened: function() { | |
| 5668 if (!this.noAnimations && this.animationConfig.open) { | |
| 5669 this.$.contentWrapper.classList.add('animating'); | |
| 5670 this.playAnimation('open'); | |
| 5671 } else { | |
| 5672 Polymer.IronOverlayBehaviorImpl._renderOpened.apply(this, arguments); | |
| 5673 } | |
| 5674 }, | |
| 5675 _renderClosed: function() { | |
| 5676 if (!this.noAnimations && this.animationConfig.close) { | |
| 5677 this.$.contentWrapper.classList.add('animating'); | |
| 5678 this.playAnimation('close'); | |
| 5679 } else { | |
| 5680 Polymer.IronOverlayBehaviorImpl._renderClosed.apply(this, arguments); | |
| 5681 } | |
| 5682 }, | |
| 5683 _onNeonAnimationFinish: function() { | |
| 5684 this.$.contentWrapper.classList.remove('animating'); | |
| 5685 if (this.opened) { | |
| 5686 this._finishRenderOpened(); | |
| 5687 } else { | |
| 5688 this._finishRenderClosed(); | |
| 5689 } | |
| 5690 }, | |
| 5691 _onCaptureScroll: function() { | |
| 5692 if (!this.allowOutsideScroll) { | |
| 5693 this._restoreScrollPosition(); | |
| 5694 } else { | |
| 5695 this._refitOnScrollRAF && window.cancelAnimationFrame(this._refitOnScrol
lRAF); | |
| 5696 this._refitOnScrollRAF = window.requestAnimationFrame(this.refit.bind(th
is)); | |
| 5697 } | |
| 5698 }, | |
| 5699 _saveScrollPosition: function() { | |
| 5700 if (document.scrollingElement) { | |
| 5701 this._scrollTop = document.scrollingElement.scrollTop; | |
| 5702 this._scrollLeft = document.scrollingElement.scrollLeft; | |
| 5703 } else { | |
| 5704 this._scrollTop = Math.max(document.documentElement.scrollTop, document.
body.scrollTop); | |
| 5705 this._scrollLeft = Math.max(document.documentElement.scrollLeft, documen
t.body.scrollLeft); | |
| 5706 } | |
| 5707 }, | |
| 5708 _restoreScrollPosition: function() { | |
| 5709 if (document.scrollingElement) { | |
| 5710 document.scrollingElement.scrollTop = this._scrollTop; | |
| 5711 document.scrollingElement.scrollLeft = this._scrollLeft; | |
| 5712 } else { | |
| 5713 document.documentElement.scrollTop = this._scrollTop; | |
| 5714 document.documentElement.scrollLeft = this._scrollLeft; | |
| 5715 document.body.scrollTop = this._scrollTop; | |
| 5716 document.body.scrollLeft = this._scrollLeft; | |
| 5717 } | |
| 5718 }, | |
| 5719 _updateAnimationConfig: function() { | |
| 5720 var animations = (this.openAnimationConfig || []).concat(this.closeAnimati
onConfig || []); | |
| 5721 for (var i = 0; i < animations.length; i++) { | |
| 5722 animations[i].node = this.containedElement; | |
| 5723 } | |
| 5724 this.animationConfig = { | |
| 5725 open: this.openAnimationConfig, | |
| 5726 close: this.closeAnimationConfig | |
| 5727 }; | |
| 5728 }, | |
| 5729 _updateOverlayPosition: function() { | |
| 5730 if (this.isAttached) { | |
| 5731 this.notifyResize(); | |
| 5732 } | |
| 5733 }, | |
| 5734 _applyFocus: function() { | |
| 5735 var focusTarget = this.focusTarget || this.containedElement; | |
| 5736 if (focusTarget && this.opened && !this.noAutoFocus) { | |
| 5737 focusTarget.focus(); | |
| 5738 } else { | |
| 5739 Polymer.IronOverlayBehaviorImpl._applyFocus.apply(this, arguments); | |
| 5740 } | |
| 5741 } | |
| 5742 }); | |
| 5743 })(); | |
| 5744 | |
| 5745 Polymer({ | |
| 5746 is: 'fade-in-animation', | |
| 5747 behaviors: [ Polymer.NeonAnimationBehavior ], | |
| 5748 configure: function(config) { | |
| 5749 var node = config.node; | |
| 5750 this._effect = new KeyframeEffect(node, [ { | |
| 5751 opacity: '0' | |
| 5752 }, { | |
| 5753 opacity: '1' | |
| 5754 } ], this.timingFromConfig(config)); | |
| 5755 return this._effect; | |
| 5756 } | |
| 5757 }); | |
| 5758 | |
| 5759 Polymer({ | |
| 5760 is: 'fade-out-animation', | |
| 5761 behaviors: [ Polymer.NeonAnimationBehavior ], | |
| 5762 configure: function(config) { | |
| 5763 var node = config.node; | |
| 5764 this._effect = new KeyframeEffect(node, [ { | |
| 5765 opacity: '1' | |
| 5766 }, { | |
| 5767 opacity: '0' | |
| 5768 } ], this.timingFromConfig(config)); | |
| 5769 return this._effect; | |
| 5770 } | |
| 5771 }); | |
| 5772 | |
| 5773 Polymer({ | |
| 5774 is: 'paper-menu-grow-height-animation', | |
| 5775 behaviors: [ Polymer.NeonAnimationBehavior ], | |
| 5776 configure: function(config) { | |
| 5777 var node = config.node; | |
| 5778 var rect = node.getBoundingClientRect(); | |
| 5779 var height = rect.height; | |
| 5780 this._effect = new KeyframeEffect(node, [ { | |
| 5781 height: height / 2 + 'px' | |
| 5782 }, { | |
| 5783 height: height + 'px' | |
| 5784 } ], this.timingFromConfig(config)); | |
| 5785 return this._effect; | |
| 5786 } | |
| 5787 }); | |
| 5788 | |
| 5789 Polymer({ | |
| 5790 is: 'paper-menu-grow-width-animation', | |
| 5791 behaviors: [ Polymer.NeonAnimationBehavior ], | |
| 5792 configure: function(config) { | |
| 5793 var node = config.node; | |
| 5794 var rect = node.getBoundingClientRect(); | |
| 5795 var width = rect.width; | |
| 5796 this._effect = new KeyframeEffect(node, [ { | |
| 5797 width: width / 2 + 'px' | |
| 5798 }, { | |
| 5799 width: width + 'px' | |
| 5800 } ], this.timingFromConfig(config)); | |
| 5801 return this._effect; | |
| 5802 } | |
| 5803 }); | |
| 5804 | |
| 5805 Polymer({ | |
| 5806 is: 'paper-menu-shrink-width-animation', | |
| 5807 behaviors: [ Polymer.NeonAnimationBehavior ], | |
| 5808 configure: function(config) { | |
| 5809 var node = config.node; | |
| 5810 var rect = node.getBoundingClientRect(); | |
| 5811 var width = rect.width; | |
| 5812 this._effect = new KeyframeEffect(node, [ { | |
| 5813 width: width + 'px' | |
| 5814 }, { | |
| 5815 width: width - width / 20 + 'px' | |
| 5816 } ], this.timingFromConfig(config)); | |
| 5817 return this._effect; | |
| 5818 } | |
| 5819 }); | |
| 5820 | |
| 5821 Polymer({ | |
| 5822 is: 'paper-menu-shrink-height-animation', | |
| 5823 behaviors: [ Polymer.NeonAnimationBehavior ], | |
| 5824 configure: function(config) { | |
| 5825 var node = config.node; | |
| 5826 var rect = node.getBoundingClientRect(); | |
| 5827 var height = rect.height; | |
| 5828 var top = rect.top; | |
| 5829 this.setPrefixedProperty(node, 'transformOrigin', '0 0'); | |
| 5830 this._effect = new KeyframeEffect(node, [ { | |
| 5831 height: height + 'px', | |
| 5832 transform: 'translateY(0)' | |
| 5833 }, { | |
| 5834 height: height / 2 + 'px', | |
| 5835 transform: 'translateY(-20px)' | |
| 5836 } ], this.timingFromConfig(config)); | |
| 5837 return this._effect; | |
| 5838 } | |
| 5839 }); | |
| 5840 | |
| 5841 (function() { | |
| 5842 'use strict'; | |
| 5843 var config = { | |
| 5844 ANIMATION_CUBIC_BEZIER: 'cubic-bezier(.3,.95,.5,1)', | |
| 5845 MAX_ANIMATION_TIME_MS: 400 | |
| 5846 }; | |
| 5847 var PaperMenuButton = Polymer({ | |
| 5848 is: 'paper-menu-button', | |
| 5849 behaviors: [ Polymer.IronA11yKeysBehavior, Polymer.IronControlState ], | |
| 5850 properties: { | |
| 5851 opened: { | |
| 5852 type: Boolean, | |
| 5853 value: false, | |
| 5854 notify: true, | |
| 5855 observer: '_openedChanged' | |
| 5856 }, | |
| 5857 horizontalAlign: { | |
| 5858 type: String, | |
| 5859 value: 'left', | |
| 5860 reflectToAttribute: true | |
| 5861 }, | |
| 5862 verticalAlign: { | |
| 5863 type: String, | |
| 5864 value: 'top', | |
| 5865 reflectToAttribute: true | |
| 5866 }, | |
| 5867 dynamicAlign: { | |
| 5868 type: Boolean | |
| 5869 }, | |
| 5870 horizontalOffset: { | |
| 5871 type: Number, | |
| 5872 value: 0, | |
| 5873 notify: true | |
| 5874 }, | |
| 5875 verticalOffset: { | |
| 5876 type: Number, | |
| 5877 value: 0, | |
| 5878 notify: true | |
| 5879 }, | |
| 5880 noOverlap: { | |
| 5881 type: Boolean | |
| 5882 }, | |
| 5883 noAnimations: { | |
| 5884 type: Boolean, | |
| 5885 value: false | |
| 5886 }, | |
| 5887 ignoreSelect: { | |
| 5888 type: Boolean, | |
| 5889 value: false | |
| 5890 }, | |
| 5891 closeOnActivate: { | |
| 5892 type: Boolean, | |
| 5893 value: false | |
| 5894 }, | |
| 5895 openAnimationConfig: { | |
| 5896 type: Object, | |
| 5897 value: function() { | |
| 5898 return [ { | |
| 5899 name: 'fade-in-animation', | |
| 5900 timing: { | |
| 5901 delay: 100, | |
| 5902 duration: 200 | |
| 5903 } | |
| 5904 }, { | |
| 5905 name: 'paper-menu-grow-width-animation', | |
| 5906 timing: { | |
| 5907 delay: 100, | |
| 5908 duration: 150, | |
| 5909 easing: config.ANIMATION_CUBIC_BEZIER | |
| 5910 } | |
| 5911 }, { | |
| 5912 name: 'paper-menu-grow-height-animation', | |
| 5913 timing: { | |
| 5914 delay: 100, | |
| 5915 duration: 275, | |
| 5916 easing: config.ANIMATION_CUBIC_BEZIER | |
| 5917 } | |
| 5918 } ]; | |
| 5919 } | |
| 5920 }, | |
| 5921 closeAnimationConfig: { | |
| 5922 type: Object, | |
| 5923 value: function() { | |
| 5924 return [ { | |
| 5925 name: 'fade-out-animation', | |
| 5926 timing: { | |
| 5927 duration: 150 | |
| 5928 } | |
| 5929 }, { | |
| 5930 name: 'paper-menu-shrink-width-animation', | |
| 5931 timing: { | |
| 5932 delay: 100, | |
| 5933 duration: 50, | |
| 5934 easing: config.ANIMATION_CUBIC_BEZIER | |
| 5935 } | |
| 5936 }, { | |
| 5937 name: 'paper-menu-shrink-height-animation', | |
| 5938 timing: { | |
| 5939 duration: 200, | |
| 5940 easing: 'ease-in' | |
| 5941 } | |
| 5942 } ]; | |
| 5943 } | |
| 5944 }, | |
| 5945 allowOutsideScroll: { | |
| 5946 type: Boolean, | |
| 5947 value: false | |
| 5948 }, | |
| 5949 restoreFocusOnClose: { | |
| 5950 type: Boolean, | |
| 5951 value: true | |
| 5952 }, | |
| 5953 _dropdownContent: { | |
| 5954 type: Object | |
| 5955 } | |
| 5956 }, | |
| 5957 hostAttributes: { | |
| 5958 role: 'group', | |
| 5959 'aria-haspopup': 'true' | |
| 5960 }, | |
| 5961 listeners: { | |
| 5962 'iron-activate': '_onIronActivate', | |
| 5963 'iron-select': '_onIronSelect' | |
| 5964 }, | |
| 5965 get contentElement() { | |
| 5966 return Polymer.dom(this.$.content).getDistributedNodes()[0]; | |
| 5967 }, | |
| 5968 toggle: function() { | |
| 5969 if (this.opened) { | |
| 5970 this.close(); | |
| 5971 } else { | |
| 5972 this.open(); | |
| 5973 } | |
| 5974 }, | |
| 5975 open: function() { | |
| 5976 if (this.disabled) { | |
| 5977 return; | |
| 5978 } | |
| 5979 this.$.dropdown.open(); | |
| 5980 }, | |
| 5981 close: function() { | |
| 5982 this.$.dropdown.close(); | |
| 5983 }, | |
| 5984 _onIronSelect: function(event) { | |
| 5985 if (!this.ignoreSelect) { | |
| 5986 this.close(); | |
| 5987 } | |
| 5988 }, | |
| 5989 _onIronActivate: function(event) { | |
| 5990 if (this.closeOnActivate) { | |
| 5991 this.close(); | |
| 5992 } | |
| 5993 }, | |
| 5994 _openedChanged: function(opened, oldOpened) { | |
| 5995 if (opened) { | |
| 5996 this._dropdownContent = this.contentElement; | |
| 5997 this.fire('paper-dropdown-open'); | |
| 5998 } else if (oldOpened != null) { | |
| 5999 this.fire('paper-dropdown-close'); | |
| 6000 } | |
| 6001 }, | |
| 6002 _disabledChanged: function(disabled) { | |
| 6003 Polymer.IronControlState._disabledChanged.apply(this, arguments); | |
| 6004 if (disabled && this.opened) { | |
| 6005 this.close(); | |
| 6006 } | |
| 6007 }, | |
| 6008 __onIronOverlayCanceled: function(event) { | |
| 6009 var uiEvent = event.detail; | |
| 6010 var target = Polymer.dom(uiEvent).rootTarget; | |
| 6011 var trigger = this.$.trigger; | |
| 6012 var path = Polymer.dom(uiEvent).path; | |
| 6013 if (path.indexOf(trigger) > -1) { | |
| 6014 event.preventDefault(); | |
| 6015 } | |
| 6016 } | |
| 6017 }); | |
| 6018 Object.keys(config).forEach(function(key) { | |
| 6019 PaperMenuButton[key] = config[key]; | |
| 6020 }); | |
| 6021 Polymer.PaperMenuButton = PaperMenuButton; | |
| 6022 })(); | |
| 6023 | |
| 6024 Polymer.PaperInkyFocusBehaviorImpl = { | |
| 6025 observers: [ '_focusedChanged(receivedFocusFromKeyboard)' ], | |
| 6026 _focusedChanged: function(receivedFocusFromKeyboard) { | |
| 6027 if (receivedFocusFromKeyboard) { | |
| 6028 this.ensureRipple(); | |
| 6029 } | |
| 6030 if (this.hasRipple()) { | |
| 6031 this._ripple.holdDown = receivedFocusFromKeyboard; | |
| 6032 } | |
| 6033 }, | |
| 6034 _createRipple: function() { | |
| 6035 var ripple = Polymer.PaperRippleBehavior._createRipple(); | |
| 6036 ripple.id = 'ink'; | |
| 6037 ripple.setAttribute('center', ''); | |
| 6038 ripple.classList.add('circle'); | |
| 6039 return ripple; | |
| 6040 } | |
| 6041 }; | |
| 6042 | |
| 6043 Polymer.PaperInkyFocusBehavior = [ Polymer.IronButtonState, Polymer.IronControlS
tate, Polymer.PaperRippleBehavior, Polymer.PaperInkyFocusBehaviorImpl ]; | |
| 6044 | |
| 6045 Polymer({ | |
| 6046 is: 'paper-icon-button', | |
| 6047 hostAttributes: { | |
| 6048 role: 'button', | |
| 6049 tabindex: '0' | |
| 6050 }, | |
| 6051 behaviors: [ Polymer.PaperInkyFocusBehavior ], | |
| 6052 properties: { | |
| 6053 src: { | |
| 6054 type: String | |
| 6055 }, | |
| 6056 icon: { | |
| 6057 type: String | |
| 6058 }, | |
| 6059 alt: { | |
| 6060 type: String, | |
| 6061 observer: "_altChanged" | |
| 6062 } | |
| 6063 }, | |
| 6064 _altChanged: function(newValue, oldValue) { | |
| 6065 var label = this.getAttribute('aria-label'); | |
| 6066 if (!label || oldValue == label) { | |
| 6067 this.setAttribute('aria-label', newValue); | |
| 6068 } | |
| 6069 } | |
| 6070 }); | |
| 6071 | |
| 6072 Polymer({ | |
| 6073 is: 'iron-media-query', | |
| 6074 properties: { | |
| 6075 queryMatches: { | |
| 6076 type: Boolean, | |
| 6077 value: false, | |
| 6078 readOnly: true, | |
| 6079 notify: true | |
| 6080 }, | |
| 6081 query: { | |
| 6082 type: String, | |
| 6083 observer: 'queryChanged' | |
| 6084 }, | |
| 6085 full: { | |
| 6086 type: Boolean, | |
| 6087 value: false | |
| 6088 }, | |
| 6089 _boundMQHandler: { | |
| 6090 value: function() { | |
| 6091 return this.queryHandler.bind(this); | |
| 6092 } | |
| 6093 }, | |
| 6094 _mq: { | |
| 6095 value: null | |
| 6096 } | |
| 6097 }, | |
| 6098 attached: function() { | |
| 6099 this.style.display = 'none'; | |
| 6100 this.queryChanged(); | |
| 6101 }, | |
| 6102 detached: function() { | |
| 6103 this._remove(); | |
| 6104 }, | |
| 6105 _add: function() { | |
| 6106 if (this._mq) { | |
| 6107 this._mq.addListener(this._boundMQHandler); | |
| 6108 } | |
| 6109 }, | |
| 6110 _remove: function() { | |
| 6111 if (this._mq) { | |
| 6112 this._mq.removeListener(this._boundMQHandler); | |
| 6113 } | |
| 6114 this._mq = null; | |
| 6115 }, | |
| 6116 queryChanged: function() { | |
| 6117 this._remove(); | |
| 6118 var query = this.query; | |
| 6119 if (!query) { | |
| 6120 return; | |
| 6121 } | |
| 6122 if (!this.full && query[0] !== '(') { | |
| 6123 query = '(' + query + ')'; | |
| 6124 } | |
| 6125 this._mq = window.matchMedia(query); | |
| 6126 this._add(); | |
| 6127 this.queryHandler(this._mq); | |
| 6128 }, | |
| 6129 queryHandler: function(mq) { | |
| 6130 this._setQueryMatches(mq.matches); | |
| 6131 } | |
| 6132 }); | |
| 6133 | |
| 6134 (function() { | |
| 6135 'use strict'; | |
| 6136 Polymer.IronA11yAnnouncer = Polymer({ | |
| 6137 is: 'iron-a11y-announcer', | |
| 6138 properties: { | |
| 6139 mode: { | |
| 6140 type: String, | |
| 6141 value: 'polite' | |
| 6142 }, | |
| 6143 _text: { | |
| 6144 type: String, | |
| 6145 value: '' | |
| 6146 } | |
| 6147 }, | |
| 6148 created: function() { | |
| 6149 if (!Polymer.IronA11yAnnouncer.instance) { | |
| 6150 Polymer.IronA11yAnnouncer.instance = this; | |
| 6151 } | |
| 6152 document.body.addEventListener('iron-announce', this._onIronAnnounce.bind(
this)); | |
| 6153 }, | |
| 6154 announce: function(text) { | |
| 6155 this._text = ''; | |
| 6156 this.async(function() { | |
| 6157 this._text = text; | |
| 6158 }, 100); | |
| 6159 }, | |
| 6160 _onIronAnnounce: function(event) { | |
| 6161 if (event.detail && event.detail.text) { | |
| 6162 this.announce(event.detail.text); | |
| 6163 } | |
| 6164 } | |
| 6165 }); | |
| 6166 Polymer.IronA11yAnnouncer.instance = null; | |
| 6167 Polymer.IronA11yAnnouncer.requestAvailability = function() { | |
| 6168 if (!Polymer.IronA11yAnnouncer.instance) { | |
| 6169 Polymer.IronA11yAnnouncer.instance = document.createElement('iron-a11y-ann
ouncer'); | |
| 6170 } | |
| 6171 document.body.appendChild(Polymer.IronA11yAnnouncer.instance); | |
| 6172 }; | |
| 6173 })(); | |
| 6174 | |
| 6175 Polymer.IronValidatableBehaviorMeta = null; | |
| 6176 | |
| 6177 Polymer.IronValidatableBehavior = { | |
| 6178 properties: { | |
| 6179 validator: { | |
| 6180 type: String | |
| 6181 }, | |
| 6182 invalid: { | |
| 6183 notify: true, | |
| 6184 reflectToAttribute: true, | |
| 6185 type: Boolean, | |
| 6186 value: false | |
| 6187 }, | |
| 6188 _validatorMeta: { | |
| 6189 type: Object | |
| 6190 }, | |
| 6191 validatorType: { | |
| 6192 type: String, | |
| 6193 value: 'validator' | |
| 6194 }, | |
| 6195 _validator: { | |
| 6196 type: Object, | |
| 6197 computed: '__computeValidator(validator)' | |
| 6198 } | |
| 6199 }, | |
| 6200 observers: [ '_invalidChanged(invalid)' ], | |
| 6201 registered: function() { | |
| 6202 Polymer.IronValidatableBehaviorMeta = new Polymer.IronMeta({ | |
| 6203 type: 'validator' | |
| 6204 }); | |
| 6205 }, | |
| 6206 _invalidChanged: function() { | |
| 6207 if (this.invalid) { | |
| 6208 this.setAttribute('aria-invalid', 'true'); | |
| 6209 } else { | |
| 6210 this.removeAttribute('aria-invalid'); | |
| 6211 } | |
| 6212 }, | |
| 6213 hasValidator: function() { | |
| 6214 return this._validator != null; | |
| 6215 }, | |
| 6216 validate: function(value) { | |
| 6217 this.invalid = !this._getValidity(value); | |
| 6218 return !this.invalid; | |
| 6219 }, | |
| 6220 _getValidity: function(value) { | |
| 6221 if (this.hasValidator()) { | |
| 6222 return this._validator.validate(value); | |
| 6223 } | |
| 6224 return true; | |
| 6225 }, | |
| 6226 __computeValidator: function() { | |
| 6227 return Polymer.IronValidatableBehaviorMeta && Polymer.IronValidatableBehavio
rMeta.byKey(this.validator); | |
| 6228 } | |
| 6229 }; | |
| 6230 | |
| 6231 Polymer({ | |
| 6232 is: 'iron-input', | |
| 6233 "extends": 'input', | |
| 6234 behaviors: [ Polymer.IronValidatableBehavior ], | |
| 6235 properties: { | |
| 6236 bindValue: { | |
| 6237 observer: '_bindValueChanged', | |
| 6238 type: String | |
| 6239 }, | |
| 6240 preventInvalidInput: { | |
| 6241 type: Boolean | |
| 6242 }, | |
| 6243 allowedPattern: { | |
| 6244 type: String, | |
| 6245 observer: "_allowedPatternChanged" | |
| 6246 }, | |
| 6247 _previousValidInput: { | |
| 6248 type: String, | |
| 6249 value: '' | |
| 6250 }, | |
| 6251 _patternAlreadyChecked: { | |
| 6252 type: Boolean, | |
| 6253 value: false | |
| 6254 } | |
| 6255 }, | |
| 6256 listeners: { | |
| 6257 input: '_onInput', | |
| 6258 keypress: '_onKeypress' | |
| 6259 }, | |
| 6260 registered: function() { | |
| 6261 if (!this._canDispatchEventOnDisabled()) { | |
| 6262 this._origDispatchEvent = this.dispatchEvent; | |
| 6263 this.dispatchEvent = this._dispatchEventFirefoxIE; | |
| 6264 } | |
| 6265 }, | |
| 6266 created: function() { | |
| 6267 Polymer.IronA11yAnnouncer.requestAvailability(); | |
| 6268 }, | |
| 6269 _canDispatchEventOnDisabled: function() { | |
| 6270 var input = document.createElement('input'); | |
| 6271 var canDispatch = false; | |
| 6272 input.disabled = true; | |
| 6273 input.addEventListener('feature-check-dispatch-event', function() { | |
| 6274 canDispatch = true; | |
| 6275 }); | |
| 6276 try { | |
| 6277 input.dispatchEvent(new Event('feature-check-dispatch-event')); | |
| 6278 } catch (e) {} | |
| 6279 return canDispatch; | |
| 6280 }, | |
| 6281 _dispatchEventFirefoxIE: function() { | |
| 6282 var disabled = this.disabled; | |
| 6283 this.disabled = false; | |
| 6284 this._origDispatchEvent.apply(this, arguments); | |
| 6285 this.disabled = disabled; | |
| 6286 }, | |
| 6287 get _patternRegExp() { | |
| 6288 var pattern; | |
| 6289 if (this.allowedPattern) { | |
| 6290 pattern = new RegExp(this.allowedPattern); | |
| 6291 } else { | |
| 6292 switch (this.type) { | |
| 6293 case 'number': | |
| 6294 pattern = /[0-9.,e-]/; | |
| 6295 break; | |
| 6296 } | |
| 6297 } | |
| 6298 return pattern; | |
| 6299 }, | |
| 6300 ready: function() { | |
| 6301 this.bindValue = this.value; | |
| 6302 }, | |
| 6303 _bindValueChanged: function() { | |
| 6304 if (this.value !== this.bindValue) { | |
| 6305 this.value = !(this.bindValue || this.bindValue === 0 || this.bindValue ==
= false) ? '' : this.bindValue; | |
| 6306 } | |
| 6307 this.fire('bind-value-changed', { | |
| 6308 value: this.bindValue | |
| 6309 }); | |
| 6310 }, | |
| 6311 _allowedPatternChanged: function() { | |
| 6312 this.preventInvalidInput = this.allowedPattern ? true : false; | |
| 6313 }, | |
| 6314 _onInput: function() { | |
| 6315 if (this.preventInvalidInput && !this._patternAlreadyChecked) { | |
| 6316 var valid = this._checkPatternValidity(); | |
| 6317 if (!valid) { | |
| 6318 this._announceInvalidCharacter('Invalid string of characters not entered
.'); | |
| 6319 this.value = this._previousValidInput; | |
| 6320 } | |
| 6321 } | |
| 6322 this.bindValue = this.value; | |
| 6323 this._previousValidInput = this.value; | |
| 6324 this._patternAlreadyChecked = false; | |
| 6325 }, | |
| 6326 _isPrintable: function(event) { | |
| 6327 var anyNonPrintable = event.keyCode == 8 || event.keyCode == 9 || event.keyC
ode == 13 || event.keyCode == 27; | |
| 6328 var mozNonPrintable = event.keyCode == 19 || event.keyCode == 20 || event.ke
yCode == 45 || event.keyCode == 46 || event.keyCode == 144 || event.keyCode == 1
45 || event.keyCode > 32 && event.keyCode < 41 || event.keyCode > 111 && event.k
eyCode < 124; | |
| 6329 return !anyNonPrintable && !(event.charCode == 0 && mozNonPrintable); | |
| 6330 }, | |
| 6331 _onKeypress: function(event) { | |
| 6332 if (!this.preventInvalidInput && this.type !== 'number') { | |
| 6333 return; | |
| 6334 } | |
| 6335 var regexp = this._patternRegExp; | |
| 6336 if (!regexp) { | |
| 6337 return; | |
| 6338 } | |
| 6339 if (event.metaKey || event.ctrlKey || event.altKey) return; | |
| 6340 this._patternAlreadyChecked = true; | |
| 6341 var thisChar = String.fromCharCode(event.charCode); | |
| 6342 if (this._isPrintable(event) && !regexp.test(thisChar)) { | |
| 6343 event.preventDefault(); | |
| 6344 this._announceInvalidCharacter('Invalid character ' + thisChar + ' not ent
ered.'); | |
| 6345 } | |
| 6346 }, | |
| 6347 _checkPatternValidity: function() { | |
| 6348 var regexp = this._patternRegExp; | |
| 6349 if (!regexp) { | |
| 6350 return true; | |
| 6351 } | |
| 6352 for (var i = 0; i < this.value.length; i++) { | |
| 6353 if (!regexp.test(this.value[i])) { | |
| 6354 return false; | |
| 6355 } | |
| 6356 } | |
| 6357 return true; | |
| 6358 }, | |
| 6359 validate: function() { | |
| 6360 var valid = this.checkValidity(); | |
| 6361 if (valid) { | |
| 6362 if (this.required && this.value === '') { | |
| 6363 valid = false; | |
| 6364 } else if (this.hasValidator()) { | |
| 6365 valid = Polymer.IronValidatableBehavior.validate.call(this, this.value); | |
| 6366 } | |
| 6367 } | |
| 6368 this.invalid = !valid; | |
| 6369 this.fire('iron-input-validate'); | |
| 6370 return valid; | |
| 6371 }, | |
| 6372 _announceInvalidCharacter: function(message) { | |
| 6373 this.fire('iron-announce', { | |
| 6374 text: message | |
| 6375 }); | |
| 6376 } | |
| 6377 }); | |
| 6378 | |
| 6379 Polymer({ | |
| 6380 is: 'paper-input-container', | |
| 6381 properties: { | |
| 6382 noLabelFloat: { | |
| 6383 type: Boolean, | |
| 6384 value: false | |
| 6385 }, | |
| 6386 alwaysFloatLabel: { | |
| 6387 type: Boolean, | |
| 6388 value: false | |
| 6389 }, | |
| 6390 attrForValue: { | |
| 6391 type: String, | |
| 6392 value: 'bind-value' | |
| 6393 }, | |
| 6394 autoValidate: { | |
| 6395 type: Boolean, | |
| 6396 value: false | |
| 6397 }, | |
| 6398 invalid: { | |
| 6399 observer: '_invalidChanged', | |
| 6400 type: Boolean, | |
| 6401 value: false | |
| 6402 }, | |
| 6403 focused: { | |
| 6404 readOnly: true, | |
| 6405 type: Boolean, | |
| 6406 value: false, | |
| 6407 notify: true | |
| 6408 }, | |
| 6409 _addons: { | |
| 6410 type: Array | |
| 6411 }, | |
| 6412 _inputHasContent: { | |
| 6413 type: Boolean, | |
| 6414 value: false | |
| 6415 }, | |
| 6416 _inputSelector: { | |
| 6417 type: String, | |
| 6418 value: 'input,textarea,.paper-input-input' | |
| 6419 }, | |
| 6420 _boundOnFocus: { | |
| 6421 type: Function, | |
| 6422 value: function() { | |
| 6423 return this._onFocus.bind(this); | |
| 6424 } | |
| 6425 }, | |
| 6426 _boundOnBlur: { | |
| 6427 type: Function, | |
| 6428 value: function() { | |
| 6429 return this._onBlur.bind(this); | |
| 6430 } | |
| 6431 }, | |
| 6432 _boundOnInput: { | |
| 6433 type: Function, | |
| 6434 value: function() { | |
| 6435 return this._onInput.bind(this); | |
| 6436 } | |
| 6437 }, | |
| 6438 _boundValueChanged: { | |
| 6439 type: Function, | |
| 6440 value: function() { | |
| 6441 return this._onValueChanged.bind(this); | |
| 6442 } | |
| 6443 } | |
| 6444 }, | |
| 6445 listeners: { | |
| 6446 'addon-attached': '_onAddonAttached', | |
| 6447 'iron-input-validate': '_onIronInputValidate' | |
| 6448 }, | |
| 6449 get _valueChangedEvent() { | |
| 6450 return this.attrForValue + '-changed'; | |
| 6451 }, | |
| 6452 get _propertyForValue() { | |
| 6453 return Polymer.CaseMap.dashToCamelCase(this.attrForValue); | |
| 6454 }, | |
| 6455 get _inputElement() { | |
| 6456 return Polymer.dom(this).querySelector(this._inputSelector); | |
| 6457 }, | |
| 6458 get _inputElementValue() { | |
| 6459 return this._inputElement[this._propertyForValue] || this._inputElement.valu
e; | |
| 6460 }, | |
| 6461 ready: function() { | |
| 6462 if (!this._addons) { | |
| 6463 this._addons = []; | |
| 6464 } | |
| 6465 this.addEventListener('focus', this._boundOnFocus, true); | |
| 6466 this.addEventListener('blur', this._boundOnBlur, true); | |
| 6467 }, | |
| 6468 attached: function() { | |
| 6469 if (this.attrForValue) { | |
| 6470 this._inputElement.addEventListener(this._valueChangedEvent, this._boundVa
lueChanged); | |
| 6471 } else { | |
| 6472 this.addEventListener('input', this._onInput); | |
| 6473 } | |
| 6474 if (this._inputElementValue != '') { | |
| 6475 this._handleValueAndAutoValidate(this._inputElement); | |
| 6476 } else { | |
| 6477 this._handleValue(this._inputElement); | |
| 6478 } | |
| 6479 }, | |
| 6480 _onAddonAttached: function(event) { | |
| 6481 if (!this._addons) { | |
| 6482 this._addons = []; | |
| 6483 } | |
| 6484 var target = event.target; | |
| 6485 if (this._addons.indexOf(target) === -1) { | |
| 6486 this._addons.push(target); | |
| 6487 if (this.isAttached) { | |
| 6488 this._handleValue(this._inputElement); | |
| 6489 } | |
| 6490 } | |
| 6491 }, | |
| 6492 _onFocus: function() { | |
| 6493 this._setFocused(true); | |
| 6494 }, | |
| 6495 _onBlur: function() { | |
| 6496 this._setFocused(false); | |
| 6497 this._handleValueAndAutoValidate(this._inputElement); | |
| 6498 }, | |
| 6499 _onInput: function(event) { | |
| 6500 this._handleValueAndAutoValidate(event.target); | |
| 6501 }, | |
| 6502 _onValueChanged: function(event) { | |
| 6503 this._handleValueAndAutoValidate(event.target); | |
| 6504 }, | |
| 6505 _handleValue: function(inputElement) { | |
| 6506 var value = this._inputElementValue; | |
| 6507 if (value || value === 0 || inputElement.type === 'number' && !inputElement.
checkValidity()) { | |
| 6508 this._inputHasContent = true; | |
| 6509 } else { | |
| 6510 this._inputHasContent = false; | |
| 6511 } | |
| 6512 this.updateAddons({ | |
| 6513 inputElement: inputElement, | |
| 6514 value: value, | |
| 6515 invalid: this.invalid | |
| 6516 }); | |
| 6517 }, | |
| 6518 _handleValueAndAutoValidate: function(inputElement) { | |
| 6519 if (this.autoValidate) { | |
| 6520 var valid; | |
| 6521 if (inputElement.validate) { | |
| 6522 valid = inputElement.validate(this._inputElementValue); | |
| 6523 } else { | |
| 6524 valid = inputElement.checkValidity(); | |
| 6525 } | |
| 6526 this.invalid = !valid; | |
| 6527 } | |
| 6528 this._handleValue(inputElement); | |
| 6529 }, | |
| 6530 _onIronInputValidate: function(event) { | |
| 6531 this.invalid = this._inputElement.invalid; | |
| 6532 }, | |
| 6533 _invalidChanged: function() { | |
| 6534 if (this._addons) { | |
| 6535 this.updateAddons({ | |
| 6536 invalid: this.invalid | |
| 6537 }); | |
| 6538 } | |
| 6539 }, | |
| 6540 updateAddons: function(state) { | |
| 6541 for (var addon, index = 0; addon = this._addons[index]; index++) { | |
| 6542 addon.update(state); | |
| 6543 } | |
| 6544 }, | |
| 6545 _computeInputContentClass: function(noLabelFloat, alwaysFloatLabel, focused, i
nvalid, _inputHasContent) { | |
| 6546 var cls = 'input-content'; | |
| 6547 if (!noLabelFloat) { | |
| 6548 var label = this.querySelector('label'); | |
| 6549 if (alwaysFloatLabel || _inputHasContent) { | |
| 6550 cls += ' label-is-floating'; | |
| 6551 this.$.labelAndInputContainer.style.position = 'static'; | |
| 6552 if (invalid) { | |
| 6553 cls += ' is-invalid'; | |
| 6554 } else if (focused) { | |
| 6555 cls += " label-is-highlighted"; | |
| 6556 } | |
| 6557 } else { | |
| 6558 if (label) { | |
| 6559 this.$.labelAndInputContainer.style.position = 'relative'; | |
| 6560 } | |
| 6561 } | |
| 6562 } else { | |
| 6563 if (_inputHasContent) { | |
| 6564 cls += ' label-is-hidden'; | |
| 6565 } | |
| 6566 } | |
| 6567 return cls; | |
| 6568 }, | |
| 6569 _computeUnderlineClass: function(focused, invalid) { | |
| 6570 var cls = 'underline'; | |
| 6571 if (invalid) { | |
| 6572 cls += ' is-invalid'; | |
| 6573 } else if (focused) { | |
| 6574 cls += ' is-highlighted'; | |
| 6575 } | |
| 6576 return cls; | |
| 6577 }, | |
| 6578 _computeAddOnContentClass: function(focused, invalid) { | |
| 6579 var cls = 'add-on-content'; | |
| 6580 if (invalid) { | |
| 6581 cls += ' is-invalid'; | |
| 6582 } else if (focused) { | |
| 6583 cls += ' is-highlighted'; | |
| 6584 } | |
| 6585 return cls; | |
| 6586 } | |
| 6587 }); | |
| 6588 | |
| 6589 Polymer.PaperSpinnerBehavior = { | |
| 6590 listeners: { | |
| 6591 animationend: '__reset', | |
| 6592 webkitAnimationEnd: '__reset' | |
| 6593 }, | |
| 6594 properties: { | |
| 6595 active: { | |
| 6596 type: Boolean, | |
| 6597 value: false, | |
| 6598 reflectToAttribute: true, | |
| 6599 observer: '__activeChanged' | |
| 6600 }, | |
| 6601 alt: { | |
| 6602 type: String, | |
| 6603 value: 'loading', | |
| 6604 observer: '__altChanged' | |
| 6605 }, | |
| 6606 __coolingDown: { | |
| 6607 type: Boolean, | |
| 6608 value: false | |
| 6609 } | |
| 6610 }, | |
| 6611 __computeContainerClasses: function(active, coolingDown) { | |
| 6612 return [ active || coolingDown ? 'active' : '', coolingDown ? 'cooldown' : '
' ].join(' '); | |
| 6613 }, | |
| 6614 __activeChanged: function(active, old) { | |
| 6615 this.__setAriaHidden(!active); | |
| 6616 this.__coolingDown = !active && old; | |
| 6617 }, | |
| 6618 __altChanged: function(alt) { | |
| 6619 if (alt === this.getPropertyInfo('alt').value) { | |
| 6620 this.alt = this.getAttribute('aria-label') || alt; | |
| 6621 } else { | |
| 6622 this.__setAriaHidden(alt === ''); | |
| 6623 this.setAttribute('aria-label', alt); | |
| 6624 } | |
| 6625 }, | |
| 6626 __setAriaHidden: function(hidden) { | |
| 6627 var attr = 'aria-hidden'; | |
| 6628 if (hidden) { | |
| 6629 this.setAttribute(attr, 'true'); | |
| 6630 } else { | |
| 6631 this.removeAttribute(attr); | |
| 6632 } | |
| 6633 }, | |
| 6634 __reset: function() { | |
| 6635 this.active = false; | |
| 6636 this.__coolingDown = false; | |
| 6637 } | |
| 6638 }; | |
| 6639 | |
| 6640 Polymer({ | |
| 6641 is: 'paper-spinner-lite', | |
| 6642 behaviors: [ Polymer.PaperSpinnerBehavior ] | |
| 6643 }); | |
| 6644 | |
| 6645 // Copyright 2016 The Chromium Authors. All rights reserved. | 49 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 6646 // Use of this source code is governed by a BSD-style license that can be | 50 // Use of this source code is governed by a BSD-style license that can be |
| 6647 // found in the LICENSE file. | 51 // found in the LICENSE file. |
| 6648 var CrSearchFieldBehavior = { | 52 var CrSearchFieldBehavior={properties:{label:{type:String,value:""},clearLabel:{
type:String,value:""},showingSearch:{type:Boolean,value:false,notify:true,observ
er:"showingSearchChanged_",reflectToAttribute:true},lastValue_:{type:String,valu
e:""}},getSearchInput:function(){},getValue:function(){return this.getSearchInpu
t().value},setValue:function(value){this.getSearchInput().bindValue=value;this.o
nValueChanged_(value)},showAndFocus:function(){this.showingSearch=true;this.focu
s_()},focus_:function(){this.getSearchInput().focus()},onSearchTermSearch:functi
on(){this.onValueChanged_(this.getValue())},onValueChanged_:function(newValue){i
f(newValue==this.lastValue_)return;this.fire("search-changed",newValue);this.las
tValue_=newValue},onSearchTermKeydown:function(e){if(e.key=="Escape")this.showin
gSearch=false},showingSearchChanged_:function(){if(this.showingSearch){this.focu
s_();return}this.setValue("");this.getSearchInput().blur()}}; |
| 6649 properties: { | |
| 6650 label: { | |
| 6651 type: String, | |
| 6652 value: '' | |
| 6653 }, | |
| 6654 clearLabel: { | |
| 6655 type: String, | |
| 6656 value: '' | |
| 6657 }, | |
| 6658 showingSearch: { | |
| 6659 type: Boolean, | |
| 6660 value: false, | |
| 6661 notify: true, | |
| 6662 observer: 'showingSearchChanged_', | |
| 6663 reflectToAttribute: true | |
| 6664 }, | |
| 6665 lastValue_: { | |
| 6666 type: String, | |
| 6667 value: '' | |
| 6668 } | |
| 6669 }, | |
| 6670 getSearchInput: function() {}, | |
| 6671 getValue: function() { | |
| 6672 return this.getSearchInput().value; | |
| 6673 }, | |
| 6674 setValue: function(value) { | |
| 6675 this.getSearchInput().bindValue = value; | |
| 6676 this.onValueChanged_(value); | |
| 6677 }, | |
| 6678 showAndFocus: function() { | |
| 6679 this.showingSearch = true; | |
| 6680 this.focus_(); | |
| 6681 }, | |
| 6682 focus_: function() { | |
| 6683 this.getSearchInput().focus(); | |
| 6684 }, | |
| 6685 onSearchTermSearch: function() { | |
| 6686 this.onValueChanged_(this.getValue()); | |
| 6687 }, | |
| 6688 onValueChanged_: function(newValue) { | |
| 6689 if (newValue == this.lastValue_) return; | |
| 6690 this.fire('search-changed', newValue); | |
| 6691 this.lastValue_ = newValue; | |
| 6692 }, | |
| 6693 onSearchTermKeydown: function(e) { | |
| 6694 if (e.key == 'Escape') this.showingSearch = false; | |
| 6695 }, | |
| 6696 showingSearchChanged_: function() { | |
| 6697 if (this.showingSearch) { | |
| 6698 this.focus_(); | |
| 6699 return; | |
| 6700 } | |
| 6701 this.setValue(''); | |
| 6702 this.getSearchInput().blur(); | |
| 6703 } | |
| 6704 }; | |
| 6705 | |
| 6706 // Copyright 2016 The Chromium Authors. All rights reserved. | 53 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 6707 // Use of this source code is governed by a BSD-style license that can be | 54 // Use of this source code is governed by a BSD-style license that can be |
| 6708 // found in the LICENSE file. | 55 // found in the LICENSE file. |
| 6709 Polymer({ | 56 Polymer({is:"cr-toolbar-search-field",behaviors:[CrSearchFieldBehavior],properti
es:{narrow:{type:Boolean,reflectToAttribute:true},label:String,clearLabel:String
,spinnerActive:{type:Boolean,reflectToAttribute:true},hasSearchText_:Boolean,isS
pinnerShown_:{type:Boolean,computed:"computeIsSpinnerShown_(spinnerActive, showi
ngSearch)"}},listeners:{tap:"showSearch_","searchInput.bind-value-changed":"onBi
ndValueChanged_"},getSearchInput:function(){return this.$.searchInput},isSearchF
ocused:function(){return this.$.searchTerm.focused},computeIconTabIndex_:functio
n(narrow){return narrow?0:-1},computeIsSpinnerShown_:function(){return this.spin
nerActive&&this.showingSearch},onInputBlur_:function(){if(!this.hasSearchText_)t
his.showingSearch=false},onBindValueChanged_:function(){var newValue=this.$.sear
chInput.bindValue;this.hasSearchText_=newValue!="";if(newValue!="")this.showingS
earch=true},showSearch_:function(e){if(e.target!=this.$.clearSearch)this.showing
Search=true},hideSearch_:function(e){this.showingSearch=false;e.stopPropagation(
)}}); |
| 6710 is: 'cr-toolbar-search-field', | |
| 6711 behaviors: [ CrSearchFieldBehavior ], | |
| 6712 properties: { | |
| 6713 narrow: { | |
| 6714 type: Boolean, | |
| 6715 reflectToAttribute: true | |
| 6716 }, | |
| 6717 label: String, | |
| 6718 clearLabel: String, | |
| 6719 spinnerActive: { | |
| 6720 type: Boolean, | |
| 6721 reflectToAttribute: true | |
| 6722 }, | |
| 6723 hasSearchText_: Boolean, | |
| 6724 isSpinnerShown_: { | |
| 6725 type: Boolean, | |
| 6726 computed: 'computeIsSpinnerShown_(spinnerActive, showingSearch)' | |
| 6727 } | |
| 6728 }, | |
| 6729 listeners: { | |
| 6730 tap: 'showSearch_', | |
| 6731 'searchInput.bind-value-changed': 'onBindValueChanged_' | |
| 6732 }, | |
| 6733 getSearchInput: function() { | |
| 6734 return this.$.searchInput; | |
| 6735 }, | |
| 6736 isSearchFocused: function() { | |
| 6737 return this.$.searchTerm.focused; | |
| 6738 }, | |
| 6739 computeIconTabIndex_: function(narrow) { | |
| 6740 return narrow ? 0 : -1; | |
| 6741 }, | |
| 6742 computeIsSpinnerShown_: function() { | |
| 6743 return this.spinnerActive && this.showingSearch; | |
| 6744 }, | |
| 6745 onInputBlur_: function() { | |
| 6746 if (!this.hasSearchText_) this.showingSearch = false; | |
| 6747 }, | |
| 6748 onBindValueChanged_: function() { | |
| 6749 var newValue = this.$.searchInput.bindValue; | |
| 6750 this.hasSearchText_ = newValue != ''; | |
| 6751 if (newValue != '') this.showingSearch = true; | |
| 6752 }, | |
| 6753 showSearch_: function(e) { | |
| 6754 if (e.target != this.$.clearSearch) this.showingSearch = true; | |
| 6755 }, | |
| 6756 hideSearch_: function(e) { | |
| 6757 this.showingSearch = false; | |
| 6758 e.stopPropagation(); | |
| 6759 } | |
| 6760 }); | |
| 6761 | |
| 6762 // Copyright 2016 The Chromium Authors. All rights reserved. | 57 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 6763 // Use of this source code is governed by a BSD-style license that can be | 58 // Use of this source code is governed by a BSD-style license that can be |
| 6764 // found in the LICENSE file. | 59 // found in the LICENSE file. |
| 6765 Polymer({ | 60 Polymer({is:"cr-toolbar",properties:{pageName:String,searchPrompt:String,clearLa
bel:String,menuLabel:String,menuPromo:String,spinnerActive:Boolean,showMenu:{typ
e:Boolean,value:false},showMenuPromo:{type:Boolean,value:false},closeMenuPromo:S
tring,narrow_:{type:Boolean,reflectToAttribute:true},showingSearch_:{type:Boolea
n,reflectToAttribute:true}},observers:["possiblyShowMenuPromo_(showMenu, showMen
uPromo, showingSearch_)"],getSearchField:function(){return this.$.search},onClos
ePromoTap_:function(){this.showMenuPromo=false},onMenuTap_:function(){this.fire(
"cr-menu-tap");this.onClosePromoTap_()},possiblyShowMenuPromo_:function(){Polyme
r.RenderStatus.afterNextRender(this,function(){if(this.showMenu&&this.showMenuPr
omo&&!this.showingSearch_){this.$$("#menuPromo").animate({opacity:[0,.9]},{durat
ion:500,fill:"forwards"});this.fire("cr-menu-promo-shown")}}.bind(this))},titleI
fNotShowMenuPromo_:function(title,showMenuPromo){return showMenuPromo?"":title}}
); |
| 6766 is: 'cr-toolbar', | |
| 6767 properties: { | |
| 6768 pageName: String, | |
| 6769 searchPrompt: String, | |
| 6770 clearLabel: String, | |
| 6771 menuLabel: String, | |
| 6772 menuPromo: String, | |
| 6773 spinnerActive: Boolean, | |
| 6774 showMenu: { | |
| 6775 type: Boolean, | |
| 6776 value: false | |
| 6777 }, | |
| 6778 showMenuPromo: { | |
| 6779 type: Boolean, | |
| 6780 value: false | |
| 6781 }, | |
| 6782 closeMenuPromo: String, | |
| 6783 narrow_: { | |
| 6784 type: Boolean, | |
| 6785 reflectToAttribute: true | |
| 6786 }, | |
| 6787 showingSearch_: { | |
| 6788 type: Boolean, | |
| 6789 reflectToAttribute: true | |
| 6790 } | |
| 6791 }, | |
| 6792 observers: [ 'possiblyShowMenuPromo_(showMenu, showMenuPromo, showingSearch_)'
], | |
| 6793 getSearchField: function() { | |
| 6794 return this.$.search; | |
| 6795 }, | |
| 6796 onClosePromoTap_: function() { | |
| 6797 this.showMenuPromo = false; | |
| 6798 }, | |
| 6799 onMenuTap_: function() { | |
| 6800 this.fire('cr-menu-tap'); | |
| 6801 this.onClosePromoTap_(); | |
| 6802 }, | |
| 6803 possiblyShowMenuPromo_: function() { | |
| 6804 Polymer.RenderStatus.afterNextRender(this, function() { | |
| 6805 if (this.showMenu && this.showMenuPromo && !this.showingSearch_) { | |
| 6806 this.$$('#menuPromo').animate({ | |
| 6807 opacity: [ 0, .9 ] | |
| 6808 }, { | |
| 6809 duration: 500, | |
| 6810 fill: 'forwards' | |
| 6811 }); | |
| 6812 this.fire('cr-menu-promo-shown'); | |
| 6813 } | |
| 6814 }.bind(this)); | |
| 6815 }, | |
| 6816 titleIfNotShowMenuPromo_: function(title, showMenuPromo) { | |
| 6817 return showMenuPromo ? '' : title; | |
| 6818 } | |
| 6819 }); | |
| 6820 | |
| 6821 // Copyright 2015 The Chromium Authors. All rights reserved. | 61 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 6822 // Use of this source code is governed by a BSD-style license that can be | 62 // Use of this source code is governed by a BSD-style license that can be |
| 6823 // found in the LICENSE file. | 63 // found in the LICENSE file. |
| 6824 cr.define('downloads', function() { | 64 cr.define("downloads",function(){var Toolbar=Polymer({is:"downloads-toolbar",pro
perties:{downloadsShowing:{reflectToAttribute:true,type:Boolean,value:false,obse
rver:"downloadsShowingChanged_"},spinnerActive:{type:Boolean,notify:true}},liste
ners:{"paper-dropdown-close":"onPaperDropdownClose_","paper-dropdown-open":"onPa
perDropdownOpen_"},canUndo:function(){return!this.$.toolbar.getSearchField().isS
earchFocused()},canClearAll:function(){return!this.$.toolbar.getSearchField().ge
tValue()&&this.downloadsShowing},onFindCommand:function(){this.$.toolbar.getSear
chField().showAndFocus()},closeMoreActions_:function(){this.$.more.close()},down
loadsShowingChanged_:function(){this.updateClearAll_()},onClearAllTap_:function(
){assert(this.canClearAll());downloads.ActionService.getInstance().clearAll()},o
nPaperDropdownClose_:function(){window.removeEventListener("resize",assert(this.
boundClose_))},onItemBlur_:function(e){var menu=this.$$("paper-menu");if(menu.it
ems.indexOf(e.relatedTarget)>=0)return;this.$.more.restoreFocusOnClose=false;thi
s.closeMoreActions_();this.$.more.restoreFocusOnClose=true},onPaperDropdownOpen_
:function(){this.boundClose_=this.boundClose_||this.closeMoreActions_.bind(this)
;window.addEventListener("resize",this.boundClose_)},onSearchChanged_:function(e
vent){var actionService=downloads.ActionService.getInstance();if(actionService.s
earch(event.detail))this.spinnerActive=actionService.isSearching();this.updateCl
earAll_()},onOpenDownloadsFolderTap_:function(){downloads.ActionService.getInsta
nce().openDownloadsFolder()},updateClearAll_:function(){this.$$("paper-menu .cle
ar-all").hidden=!this.canClearAll()}});return{Toolbar:Toolbar}}); |
| 6825 var Toolbar = Polymer({ | |
| 6826 is: 'downloads-toolbar', | |
| 6827 properties: { | |
| 6828 downloadsShowing: { | |
| 6829 reflectToAttribute: true, | |
| 6830 type: Boolean, | |
| 6831 value: false, | |
| 6832 observer: 'downloadsShowingChanged_' | |
| 6833 }, | |
| 6834 spinnerActive: { | |
| 6835 type: Boolean, | |
| 6836 notify: true | |
| 6837 } | |
| 6838 }, | |
| 6839 listeners: { | |
| 6840 'paper-dropdown-close': 'onPaperDropdownClose_', | |
| 6841 'paper-dropdown-open': 'onPaperDropdownOpen_' | |
| 6842 }, | |
| 6843 canUndo: function() { | |
| 6844 return !this.$.toolbar.getSearchField().isSearchFocused(); | |
| 6845 }, | |
| 6846 canClearAll: function() { | |
| 6847 return !this.$.toolbar.getSearchField().getValue() && this.downloadsShowin
g; | |
| 6848 }, | |
| 6849 onFindCommand: function() { | |
| 6850 this.$.toolbar.getSearchField().showAndFocus(); | |
| 6851 }, | |
| 6852 closeMoreActions_: function() { | |
| 6853 this.$.more.close(); | |
| 6854 }, | |
| 6855 downloadsShowingChanged_: function() { | |
| 6856 this.updateClearAll_(); | |
| 6857 }, | |
| 6858 onClearAllTap_: function() { | |
| 6859 assert(this.canClearAll()); | |
| 6860 downloads.ActionService.getInstance().clearAll(); | |
| 6861 }, | |
| 6862 onPaperDropdownClose_: function() { | |
| 6863 window.removeEventListener('resize', assert(this.boundClose_)); | |
| 6864 }, | |
| 6865 onItemBlur_: function(e) { | |
| 6866 var menu = this.$$('paper-menu'); | |
| 6867 if (menu.items.indexOf(e.relatedTarget) >= 0) return; | |
| 6868 this.$.more.restoreFocusOnClose = false; | |
| 6869 this.closeMoreActions_(); | |
| 6870 this.$.more.restoreFocusOnClose = true; | |
| 6871 }, | |
| 6872 onPaperDropdownOpen_: function() { | |
| 6873 this.boundClose_ = this.boundClose_ || this.closeMoreActions_.bind(this); | |
| 6874 window.addEventListener('resize', this.boundClose_); | |
| 6875 }, | |
| 6876 onSearchChanged_: function(event) { | |
| 6877 var actionService = downloads.ActionService.getInstance(); | |
| 6878 if (actionService.search(event.detail)) this.spinnerActive = actionService
.isSearching(); | |
| 6879 this.updateClearAll_(); | |
| 6880 }, | |
| 6881 onOpenDownloadsFolderTap_: function() { | |
| 6882 downloads.ActionService.getInstance().openDownloadsFolder(); | |
| 6883 }, | |
| 6884 updateClearAll_: function() { | |
| 6885 this.$$('paper-menu .clear-all').hidden = !this.canClearAll(); | |
| 6886 } | |
| 6887 }); | |
| 6888 return { | |
| 6889 Toolbar: Toolbar | |
| 6890 }; | |
| 6891 }); | |
| 6892 | |
| 6893 // Copyright 2015 The Chromium Authors. All rights reserved. | 65 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 6894 // Use of this source code is governed by a BSD-style license that can be | 66 // Use of this source code is governed by a BSD-style license that can be |
| 6895 // found in the LICENSE file. | 67 // found in the LICENSE file. |
| 6896 cr.define('downloads', function() { | 68 cr.define("downloads",function(){var Manager=Polymer({is:"downloads-manager",pro
perties:{hasDownloads_:{observer:"hasDownloadsChanged_",type:Boolean},hasShadow_
:{type:Boolean,value:false,reflectToAttribute:true},items_:{type:Array,value:fun
ction(){return[]}},spinnerActive_:{type:Boolean,notify:true}},hostAttributes:{lo
ading:true},listeners:{"downloads-list.scroll":"onListScroll_"},observers:["item
sChanged_(items_.*)"],clearAll_:function(){this.set("items_",[])},hasDownloadsCh
anged_:function(){if(loadTimeData.getBoolean("allowDeletingHistory"))this.$.tool
bar.downloadsShowing=this.hasDownloads_;if(this.hasDownloads_){this.$["downloads
-list"].fire("iron-resize")}else{var isSearching=downloads.ActionService.getInst
ance().isSearching();var messageToShow=isSearching?"noSearchResults":"noDownload
s";this.$["no-downloads"].querySelector("span").textContent=loadTimeData.getStri
ng(messageToShow)}},insertItems_:function(index,list){this.splice.apply(this,["i
tems_",index,0].concat(list));this.updateHideDates_(index,index+list.length);thi
s.removeAttribute("loading");this.spinnerActive_=false},itemsChanged_:function()
{this.hasDownloads_=this.items_.length>0},onCanExecute_:function(e){e=e;switch(e
.command.id){case"undo-command":e.canExecute=this.$.toolbar.canUndo();break;case
"clear-all-command":e.canExecute=this.$.toolbar.canClearAll();break;case"find-co
mmand":e.canExecute=true;break}},onCommand_:function(e){if(e.command.id=="clear-
all-command")downloads.ActionService.getInstance().clearAll();else if(e.command.
id=="undo-command")downloads.ActionService.getInstance().undo();else if(e.comman
d.id=="find-command")this.$.toolbar.onFindCommand()},onListScroll_:function(){va
r list=this.$["downloads-list"];if(list.scrollHeight-list.scrollTop-list.offsetH
eight<=100){downloads.ActionService.getInstance().loadMore()}this.hasShadow_=lis
t.scrollTop>0},onLoad_:function(){cr.ui.decorate("command",cr.ui.Command);docume
nt.addEventListener("canExecute",this.onCanExecute_.bind(this));document.addEven
tListener("command",this.onCommand_.bind(this));downloads.ActionService.getInsta
nce().loadMore()},removeItem_:function(index){this.splice("items_",index,1);this
.updateHideDates_(index,index);this.onListScroll_()},updateHideDates_:function(s
tart,end){for(var i=start;i<=end;++i){var current=this.items_[i];if(!current)con
tinue;var prev=this.items_[i-1];current.hideDate=!!prev&&prev.date_string==curre
nt.date_string}},updateItem_:function(index,data){this.set("items_."+index,data)
;this.updateHideDates_(index,index);var list=this.$["downloads-list"];list.updat
eSizeForItem(index)}});Manager.clearAll=function(){Manager.get().clearAll_()};Ma
nager.get=function(){return queryRequiredElement("downloads-manager")};Manager.i
nsertItems=function(index,list){Manager.get().insertItems_(index,list)};Manager.
onLoad=function(){Manager.get().onLoad_()};Manager.removeItem=function(index){Ma
nager.get().removeItem_(index)};Manager.updateItem=function(index,data){Manager.
get().updateItem_(index,data)};return{Manager:Manager}}); |
| 6897 var Manager = Polymer({ | |
| 6898 is: 'downloads-manager', | |
| 6899 properties: { | |
| 6900 hasDownloads_: { | |
| 6901 observer: 'hasDownloadsChanged_', | |
| 6902 type: Boolean | |
| 6903 }, | |
| 6904 hasShadow_: { | |
| 6905 type: Boolean, | |
| 6906 value: false, | |
| 6907 reflectToAttribute: true | |
| 6908 }, | |
| 6909 items_: { | |
| 6910 type: Array, | |
| 6911 value: function() { | |
| 6912 return []; | |
| 6913 } | |
| 6914 }, | |
| 6915 spinnerActive_: { | |
| 6916 type: Boolean, | |
| 6917 notify: true | |
| 6918 } | |
| 6919 }, | |
| 6920 hostAttributes: { | |
| 6921 loading: true | |
| 6922 }, | |
| 6923 listeners: { | |
| 6924 'downloads-list.scroll': 'onListScroll_' | |
| 6925 }, | |
| 6926 observers: [ 'itemsChanged_(items_.*)' ], | |
| 6927 clearAll_: function() { | |
| 6928 this.set('items_', []); | |
| 6929 }, | |
| 6930 hasDownloadsChanged_: function() { | |
| 6931 if (loadTimeData.getBoolean('allowDeletingHistory')) this.$.toolbar.downlo
adsShowing = this.hasDownloads_; | |
| 6932 if (this.hasDownloads_) { | |
| 6933 this.$['downloads-list'].fire('iron-resize'); | |
| 6934 } else { | |
| 6935 var isSearching = downloads.ActionService.getInstance().isSearching(); | |
| 6936 var messageToShow = isSearching ? 'noSearchResults' : 'noDownloads'; | |
| 6937 this.$['no-downloads'].querySelector('span').textContent = loadTimeData.
getString(messageToShow); | |
| 6938 } | |
| 6939 }, | |
| 6940 insertItems_: function(index, list) { | |
| 6941 this.splice.apply(this, [ 'items_', index, 0 ].concat(list)); | |
| 6942 this.updateHideDates_(index, index + list.length); | |
| 6943 this.removeAttribute('loading'); | |
| 6944 this.spinnerActive_ = false; | |
| 6945 }, | |
| 6946 itemsChanged_: function() { | |
| 6947 this.hasDownloads_ = this.items_.length > 0; | |
| 6948 }, | |
| 6949 onCanExecute_: function(e) { | |
| 6950 e = e; | |
| 6951 switch (e.command.id) { | |
| 6952 case 'undo-command': | |
| 6953 e.canExecute = this.$.toolbar.canUndo(); | |
| 6954 break; | |
| 6955 | |
| 6956 case 'clear-all-command': | |
| 6957 e.canExecute = this.$.toolbar.canClearAll(); | |
| 6958 break; | |
| 6959 | |
| 6960 case 'find-command': | |
| 6961 e.canExecute = true; | |
| 6962 break; | |
| 6963 } | |
| 6964 }, | |
| 6965 onCommand_: function(e) { | |
| 6966 if (e.command.id == 'clear-all-command') downloads.ActionService.getInstan
ce().clearAll(); else if (e.command.id == 'undo-command') downloads.ActionServic
e.getInstance().undo(); else if (e.command.id == 'find-command') this.$.toolbar.
onFindCommand(); | |
| 6967 }, | |
| 6968 onListScroll_: function() { | |
| 6969 var list = this.$['downloads-list']; | |
| 6970 if (list.scrollHeight - list.scrollTop - list.offsetHeight <= 100) { | |
| 6971 downloads.ActionService.getInstance().loadMore(); | |
| 6972 } | |
| 6973 this.hasShadow_ = list.scrollTop > 0; | |
| 6974 }, | |
| 6975 onLoad_: function() { | |
| 6976 cr.ui.decorate('command', cr.ui.Command); | |
| 6977 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); | |
| 6978 document.addEventListener('command', this.onCommand_.bind(this)); | |
| 6979 downloads.ActionService.getInstance().loadMore(); | |
| 6980 }, | |
| 6981 removeItem_: function(index) { | |
| 6982 this.splice('items_', index, 1); | |
| 6983 this.updateHideDates_(index, index); | |
| 6984 this.onListScroll_(); | |
| 6985 }, | |
| 6986 updateHideDates_: function(start, end) { | |
| 6987 for (var i = start; i <= end; ++i) { | |
| 6988 var current = this.items_[i]; | |
| 6989 if (!current) continue; | |
| 6990 var prev = this.items_[i - 1]; | |
| 6991 current.hideDate = !!prev && prev.date_string == current.date_string; | |
| 6992 } | |
| 6993 }, | |
| 6994 updateItem_: function(index, data) { | |
| 6995 this.set('items_.' + index, data); | |
| 6996 this.updateHideDates_(index, index); | |
| 6997 var list = this.$['downloads-list']; | |
| 6998 list.updateSizeForItem(index); | |
| 6999 } | |
| 7000 }); | |
| 7001 Manager.clearAll = function() { | |
| 7002 Manager.get().clearAll_(); | |
| 7003 }; | |
| 7004 Manager.get = function() { | |
| 7005 return queryRequiredElement('downloads-manager'); | |
| 7006 }; | |
| 7007 Manager.insertItems = function(index, list) { | |
| 7008 Manager.get().insertItems_(index, list); | |
| 7009 }; | |
| 7010 Manager.onLoad = function() { | |
| 7011 Manager.get().onLoad_(); | |
| 7012 }; | |
| 7013 Manager.removeItem = function(index) { | |
| 7014 Manager.get().removeItem_(index); | |
| 7015 }; | |
| 7016 Manager.updateItem = function(index, data) { | |
| 7017 Manager.get().updateItem_(index, data); | |
| 7018 }; | |
| 7019 return { | |
| 7020 Manager: Manager | |
| 7021 }; | |
| 7022 }); | |
| 7023 | |
| 7024 // Copyright 2015 The Chromium Authors. All rights reserved. | 69 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 7025 // Use of this source code is governed by a BSD-style license that can be | 70 // Use of this source code is governed by a BSD-style license that can be |
| 7026 // found in the LICENSE file. | 71 // found in the LICENSE file. |
| 7027 window.addEventListener('load', function() { | 72 window.addEventListener("load",function(){downloads.Manager.onLoad();document.fo
nts.load("bold 12px Roboto")}); |
| 7028 downloads.Manager.onLoad(); | |
| 7029 document.fonts.load('bold 12px Roboto'); | |
| 7030 }); | |
| OLD | NEW |