| 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){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} | 4 function assert(condition, opt_message) { |
| 5 if (!condition) { |
| 6 var message = "Assertion failed"; |
| 7 if (opt_message) |
| 8 message = message + ": " + opt_message; |
| 9 var error = new Error(message); |
| 10 var global = function() { |
| 11 return this |
| 12 }(); |
| 13 if (global.traceAssertionsForTesting) |
| 14 console.warn(error.stack); |
| 15 throw error |
| 16 } |
| 17 return condition |
| 18 } |
| 19 function assertNotReached(opt_message) { |
| 20 assert(false, opt_message || "Unreachable code hit") |
| 21 } |
| 22 function assertInstanceof(value, type, opt_message) { |
| 23 if (!(value instanceof type)) { |
| 24 assertNotReached( |
| 25 opt_message || |
| 26 "Value " + value + " is not a[n] " + (type.name || typeof type)) |
| 27 } |
| 28 return value |
| 29 } |
| 5 // Copyright 2016 The Chromium Authors. All rights reserved. | 30 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 6 // Use of this source code is governed by a BSD-style license that can be | 31 // Use of this source code is governed by a BSD-style license that can be |
| 7 // found in the LICENSE file. | 32 // found in the LICENSE file. |
| 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 function PromiseResolver() { |
| 34 this.resolve_; |
| 35 this.reject_; |
| 36 this.promise_ = new Promise(function(resolve, reject) { |
| 37 this.resolve_ = resolve; |
| 38 this.reject_ = reject |
| 39 }.bind(this)) |
| 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 }; |
| 9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 61 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 10 // 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 |
| 11 // found in the LICENSE file. | 63 // found in the LICENSE file. |
| 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)}}}(); | 64 var global = this; |
| 65 var WebUIListener; |
| 66 var cr = cr || function() { |
| 67 "use strict"; |
| 68 function exportPath(name, opt_object, opt_objectToExportTo) { |
| 69 var parts = name.split("."); |
| 70 var cur = opt_objectToExportTo || global; |
| 71 for (var part; parts.length && (part = parts.shift());) { |
| 72 if (!parts.length && opt_object !== undefined) { |
| 73 cur[part] = opt_object |
| 74 } else if (part in cur) { |
| 75 cur = cur[part] |
| 76 } else { |
| 77 cur = cur[part] = {} |
| 78 } |
| 79 } |
| 80 return cur |
| 81 } |
| 82 function dispatchPropertyChange(target, propertyName, newValue, oldValue) { |
| 83 var e = new Event(propertyName + "Change"); |
| 84 e.propertyName = propertyName; |
| 85 e.newValue = newValue; |
| 86 e.oldValue = oldValue; |
| 87 target.dispatchEvent(e) |
| 88 } |
| 89 function getAttributeName(jsName) { |
| 90 return jsName.replace(/([A-Z])/g, "-$1").toLowerCase() |
| 91 } |
| 92 var PropertyKind = {JS: "js", ATTR: "attr", BOOL_ATTR: "boolAttr"}; |
| 93 function getGetter(name, kind) { |
| 94 switch (kind) { |
| 95 case PropertyKind.JS: |
| 96 var privateName = name + "_"; |
| 97 return function() { |
| 98 return this[privateName] |
| 99 }; |
| 100 case PropertyKind.ATTR: |
| 101 var attributeName = getAttributeName(name); |
| 102 return function() { |
| 103 return this.getAttribute(attributeName) |
| 104 }; |
| 105 case PropertyKind.BOOL_ATTR: |
| 106 var attributeName = getAttributeName(name); |
| 107 return function() { |
| 108 return this.hasAttribute(attributeName) |
| 109 } |
| 110 } |
| 111 throw "not reached" |
| 112 } |
| 113 function getSetter(name, kind, opt_setHook) { |
| 114 switch (kind) { |
| 115 case PropertyKind.JS: |
| 116 var privateName = name + "_"; |
| 117 return function(value) { |
| 118 var oldValue = this[name]; |
| 119 if (value !== oldValue) { |
| 120 this[privateName] = value; |
| 121 if (opt_setHook) |
| 122 opt_setHook.call(this, value, oldValue); |
| 123 dispatchPropertyChange(this, name, value, oldValue) |
| 124 } |
| 125 }; |
| 126 case PropertyKind.ATTR: |
| 127 var attributeName = getAttributeName(name); |
| 128 return function(value) { |
| 129 var oldValue = this[name]; |
| 130 if (value !== oldValue) { |
| 131 if (value == undefined) |
| 132 this.removeAttribute(attributeName); |
| 133 else |
| 134 this.setAttribute(attributeName, value); |
| 135 if (opt_setHook) |
| 136 opt_setHook.call(this, value, oldValue); |
| 137 dispatchPropertyChange(this, name, value, oldValue) |
| 138 } |
| 139 }; |
| 140 case PropertyKind.BOOL_ATTR: |
| 141 var attributeName = getAttributeName(name); |
| 142 return function(value) { |
| 143 var oldValue = this[name]; |
| 144 if (value !== oldValue) { |
| 145 if (value) |
| 146 this.setAttribute(attributeName, name); |
| 147 else |
| 148 this.removeAttribute(attributeName); |
| 149 if (opt_setHook) |
| 150 opt_setHook.call(this, value, oldValue); |
| 151 dispatchPropertyChange(this, name, value, oldValue) |
| 152 } |
| 153 } |
| 154 } |
| 155 throw "not reached" |
| 156 } |
| 157 function defineProperty(obj, name, opt_kind, opt_setHook) { |
| 158 if (typeof obj == "function") |
| 159 obj = obj.prototype; |
| 160 var kind = opt_kind || PropertyKind.JS; |
| 161 if (!obj.__lookupGetter__(name)) |
| 162 obj.__defineGetter__(name, getGetter(name, kind)); |
| 163 if (!obj.__lookupSetter__(name)) |
| 164 obj.__defineSetter__(name, getSetter(name, kind, opt_setHook)) |
| 165 } |
| 166 var uidCounter = 1; |
| 167 function createUid() { |
| 168 return uidCounter++ |
| 169 } |
| 170 function getUid(item) { |
| 171 if (item.hasOwnProperty("uid")) |
| 172 return item.uid; |
| 173 return item.uid = createUid() |
| 174 } |
| 175 function dispatchSimpleEvent(target, type, opt_bubbles, opt_cancelable) { |
| 176 var e = new Event(type, { |
| 177 bubbles: opt_bubbles, |
| 178 cancelable: opt_cancelable === undefined || opt_cancelable |
| 179 }); |
| 180 return target.dispatchEvent(e) |
| 181 } |
| 182 function define(name, fun) { |
| 183 var obj = exportPath(name); |
| 184 var exports = fun(); |
| 185 for (var propertyName in exports) { |
| 186 var propertyDescriptor = |
| 187 Object.getOwnPropertyDescriptor(exports, propertyName); |
| 188 if (propertyDescriptor) |
| 189 Object.defineProperty(obj, propertyName, propertyDescriptor) |
| 190 } |
| 191 } |
| 192 function addSingletonGetter(ctor) { |
| 193 ctor.getInstance = function() { |
| 194 return ctor.instance_ || (ctor.instance_ = new ctor) |
| 195 } |
| 196 } |
| 197 function makePublic(ctor, methods, opt_target) { |
| 198 methods.forEach(function(method) { |
| 199 ctor[method] = function() { |
| 200 var target = opt_target ? document.getElementById(opt_target) : |
| 201 ctor.getInstance(); |
| 202 return target[method + "_"].apply(target, arguments) |
| 203 } |
| 204 }) |
| 205 } |
| 206 var chromeSendResolverMap = {}; |
| 207 function webUIResponse(id, isSuccess, response) { |
| 208 var resolver = chromeSendResolverMap[id]; |
| 209 delete chromeSendResolverMap[id]; |
| 210 if (isSuccess) |
| 211 resolver.resolve(response); |
| 212 else |
| 213 resolver.reject(response) |
| 214 } |
| 215 function sendWithPromise(methodName, var_args) { |
| 216 var args = Array.prototype.slice.call(arguments, 1); |
| 217 var promiseResolver = new PromiseResolver; |
| 218 var id = methodName + "_" + createUid(); |
| 219 chromeSendResolverMap[id] = promiseResolver; |
| 220 chrome.send(methodName, [id].concat(args)); |
| 221 return promiseResolver.promise |
| 222 } |
| 223 var webUIListenerMap = {}; |
| 224 function webUIListenerCallback(event, var_args) { |
| 225 var eventListenersMap = webUIListenerMap[event]; |
| 226 if (!eventListenersMap) { |
| 227 return |
| 228 } |
| 229 var args = Array.prototype.slice.call(arguments, 1); |
| 230 for (var listenerId in eventListenersMap) { |
| 231 eventListenersMap[listenerId].apply(null, args) |
| 232 } |
| 233 } |
| 234 function addWebUIListener(eventName, callback) { |
| 235 webUIListenerMap[eventName] = webUIListenerMap[eventName] || {}; |
| 236 var uid = createUid(); |
| 237 webUIListenerMap[eventName][uid] = callback; |
| 238 return { |
| 239 eventName: eventName, uid: uid |
| 240 } |
| 241 } |
| 242 function removeWebUIListener(listener) { |
| 243 var listenerExists = webUIListenerMap[listener.eventName] && |
| 244 webUIListenerMap[listener.eventName][listener.uid]; |
| 245 if (listenerExists) { |
| 246 delete webUIListenerMap[listener.eventName][listener.uid]; |
| 247 return true |
| 248 } |
| 249 return false |
| 250 } |
| 251 return { |
| 252 addSingletonGetter: addSingletonGetter, createUid: createUid, |
| 253 define: define, defineProperty: defineProperty, |
| 254 dispatchPropertyChange: dispatchPropertyChange, |
| 255 dispatchSimpleEvent: dispatchSimpleEvent, exportPath: exportPath, |
| 256 getUid: getUid, makePublic: makePublic, PropertyKind: PropertyKind, |
| 257 addWebUIListener: addWebUIListener, |
| 258 removeWebUIListener: removeWebUIListener, |
| 259 sendWithPromise: sendWithPromise, |
| 260 webUIListenerCallback: webUIListenerCallback, |
| 261 webUIResponse: webUIResponse, get doc(){return document}, |
| 262 get isMac(){return /Mac/.test(navigator.platform)}, |
| 263 get isWindows(){return /Win/.test(navigator.platform)}, |
| 264 get isChromeOS(){return /CrOS/.test(navigator.userAgent)}, |
| 265 get isLinux(){return /Linux/.test(navigator.userAgent)}, |
| 266 get isAndroid(){return /Android/.test(navigator.userAgent)}, |
| 267 get isIOS() { |
| 268 return /iPad|iPhone|iPod/.test(navigator.platform) |
| 269 } |
| 270 } |
| 271 }(); |
| 13 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 272 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 14 // Use of this source code is governed by a BSD-style license that can be | 273 // Use of this source code is governed by a BSD-style license that can be |
| 15 // found in the LICENSE file. | 274 // found in the LICENSE file. |
| 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}}); | 275 cr.define("cr.ui", function() { |
| 276 function decorate(source, constr) { |
| 277 var elements; |
| 278 if (typeof source == "string") |
| 279 elements = cr.doc.querySelectorAll(source); |
| 280 else |
| 281 elements = [source]; |
| 282 for (var i = 0, el; el = elements[i]; i++) { |
| 283 if (!(el instanceof constr)) |
| 284 constr.decorate(el) |
| 285 } |
| 286 } |
| 287 function createElementHelper(tagName, opt_bag) { |
| 288 var doc; |
| 289 if (opt_bag && opt_bag.ownerDocument) |
| 290 doc = opt_bag.ownerDocument; |
| 291 else |
| 292 doc = cr.doc; |
| 293 return doc.createElement(tagName) |
| 294 } |
| 295 function define(tagNameOrFunction) { |
| 296 var createFunction, tagName; |
| 297 if (typeof tagNameOrFunction == "function") { |
| 298 createFunction = tagNameOrFunction; |
| 299 tagName = "" |
| 300 } else { |
| 301 createFunction = createElementHelper; |
| 302 tagName = tagNameOrFunction |
| 303 } |
| 304 function f(opt_propertyBag) { |
| 305 var el = createFunction(tagName, opt_propertyBag); |
| 306 f.decorate(el); |
| 307 for (var propertyName in opt_propertyBag) { |
| 308 el[propertyName] = opt_propertyBag[propertyName] |
| 309 } |
| 310 return el |
| 311 } |
| 312 f.decorate = function(el) { |
| 313 el.__proto__ = f.prototype; |
| 314 el.decorate() |
| 315 }; |
| 316 return f |
| 317 } |
| 318 function limitInputWidth(el, parentEl, min, opt_scale) { |
| 319 el.style.width = "10px"; |
| 320 var doc = el.ownerDocument; |
| 321 var win = doc.defaultView; |
| 322 var computedStyle = win.getComputedStyle(el); |
| 323 var parentComputedStyle = win.getComputedStyle(parentEl); |
| 324 var rtl = computedStyle.direction == "rtl"; |
| 325 var inputRect = el.getBoundingClientRect(); |
| 326 var parentRect = parentEl.getBoundingClientRect(); |
| 327 var startPos = rtl ? parentRect.right - inputRect.right : |
| 328 inputRect.left - parentRect.left; |
| 329 var inner = parseInt(computedStyle.borderLeftWidth, 10) + |
| 330 parseInt(computedStyle.paddingLeft, 10) + |
| 331 parseInt(computedStyle.paddingRight, 10) + |
| 332 parseInt(computedStyle.borderRightWidth, 10); |
| 333 var parentPadding = rtl ? parseInt(parentComputedStyle.paddingLeft, 10) : |
| 334 parseInt(parentComputedStyle.paddingRight, 10); |
| 335 var max = parentEl.clientWidth - startPos - inner - parentPadding; |
| 336 if (opt_scale) |
| 337 max *= opt_scale; |
| 338 function limit() { |
| 339 if (el.scrollWidth > max) { |
| 340 el.style.width = max + "px" |
| 341 } else { |
| 342 el.style.width = 0; |
| 343 var sw = el.scrollWidth; |
| 344 if (sw < min) { |
| 345 el.style.width = min + "px" |
| 346 } else { |
| 347 el.style.width = sw + "px" |
| 348 } |
| 349 } |
| 350 } |
| 351 el.addEventListener("input", limit); |
| 352 limit() |
| 353 } |
| 354 function toCssPx(pixels) { |
| 355 if (!window.isFinite(pixels)) |
| 356 console.error("Pixel value is not a number: " + pixels); |
| 357 return Math.round(pixels) + "px" |
| 358 } |
| 359 function swallowDoubleClick(e) { |
| 360 var doc = e.target.ownerDocument; |
| 361 var counter = Math.min(1, e.detail); |
| 362 function swallow(e) { |
| 363 e.stopPropagation(); |
| 364 e.preventDefault() |
| 365 } |
| 366 function onclick(e) { |
| 367 if (e.detail > counter) { |
| 368 counter = e.detail; |
| 369 swallow(e) |
| 370 } else { |
| 371 doc.removeEventListener("dblclick", swallow, true); |
| 372 doc.removeEventListener("click", onclick, true) |
| 373 } |
| 374 } |
| 375 setTimeout(function() { |
| 376 doc.addEventListener("click", onclick, true); |
| 377 doc.addEventListener("dblclick", swallow, true) |
| 378 }, 0) |
| 379 } |
| 380 return { |
| 381 decorate: decorate, define: define, limitInputWidth: limitInputWidth, |
| 382 toCssPx: toCssPx, swallowDoubleClick: swallowDoubleClick |
| 383 } |
| 384 }); |
| 17 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 385 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 18 // Use of this source code is governed by a BSD-style license that can be | 386 // Use of this source code is governed by a BSD-style license that can be |
| 19 // found in the LICENSE file. | 387 // found in the LICENSE file. |
| 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
}}); | 388 cr.define("cr.ui", function() { |
| 389 function KeyboardShortcut(shortcut) { |
| 390 var mods = {}; |
| 391 var ident = ""; |
| 392 shortcut.split("|").forEach(function(part) { |
| 393 var partLc = part.toLowerCase(); |
| 394 switch (partLc) { |
| 395 case "alt": |
| 396 case "ctrl": |
| 397 case "meta": |
| 398 case "shift": |
| 399 mods[partLc + "Key"] = true; |
| 400 break; |
| 401 default: |
| 402 if (ident) |
| 403 throw Error("Invalid shortcut"); |
| 404 ident = part |
| 405 } |
| 406 }); |
| 407 this.ident_ = ident; |
| 408 this.mods_ = mods |
| 409 } |
| 410 KeyboardShortcut.prototype = { |
| 411 matchesEvent: function(e) { |
| 412 if (e.key == this.ident_) { |
| 413 var mods = this.mods_; |
| 414 return ["altKey", "ctrlKey", "metaKey", "shiftKey"].every(function(k) { |
| 415 return e[k] == !!mods[k] |
| 416 }) |
| 417 } |
| 418 return false |
| 419 } |
| 420 }; |
| 421 var Command = cr.ui.define("command"); |
| 422 Command.prototype = { |
| 423 __proto__: HTMLElement.prototype, |
| 424 decorate: function() { |
| 425 CommandManager.init(assert(this.ownerDocument)); |
| 426 if (this.hasAttribute("shortcut")) |
| 427 this.shortcut = this.getAttribute("shortcut") |
| 428 }, |
| 429 execute: function(opt_element) { |
| 430 if (this.disabled) |
| 431 return; |
| 432 var doc = this.ownerDocument; |
| 433 if (doc.activeElement) { |
| 434 var e = new Event("command", {bubbles: true}); |
| 435 e.command = this; |
| 436 (opt_element || doc.activeElement).dispatchEvent(e) |
| 437 } |
| 438 }, |
| 439 canExecuteChange: function(opt_node) { |
| 440 dispatchCanExecuteEvent( |
| 441 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_) |
| 459 return false; |
| 460 return this.keyboardShortcuts_.some(function(keyboardShortcut) { |
| 461 return keyboardShortcut.matchesEvent(e) |
| 462 }) |
| 463 } |
| 464 }; |
| 465 cr.defineProperty(Command, "label", cr.PropertyKind.ATTR); |
| 466 cr.defineProperty(Command, "disabled", cr.PropertyKind.BOOL_ATTR); |
| 467 cr.defineProperty(Command, "hidden", cr.PropertyKind.BOOL_ATTR); |
| 468 cr.defineProperty(Command, "checked", cr.PropertyKind.BOOL_ATTR); |
| 469 cr.defineProperty(Command, "hideShortcutText", cr.PropertyKind.BOOL_ATTR); |
| 470 function dispatchCanExecuteEvent(command, target) { |
| 471 var e = new CanExecuteEvent(command); |
| 472 target.dispatchEvent(e); |
| 473 command.disabled = !e.canExecute |
| 474 } |
| 475 var commandManagers = {}; |
| 476 function CommandManager(doc) { |
| 477 doc.addEventListener("focus", this.handleFocus_.bind(this), true); |
| 478 doc.addEventListener("keydown", this.handleKeyDown_.bind(this), false) |
| 479 } |
| 480 CommandManager.init = function(doc) { |
| 481 var uid = cr.getUid(doc); |
| 482 if (!(uid in commandManagers)) { |
| 483 commandManagers[uid] = new CommandManager(doc) |
| 484 } |
| 485 }; |
| 486 CommandManager.prototype = { |
| 487 handleFocus_: function(e) { |
| 488 var target = e.target; |
| 489 if (target.menu || target.command) |
| 490 return; |
| 491 var commands = Array.prototype.slice.call( |
| 492 target.ownerDocument.querySelectorAll("command")); |
| 493 commands.forEach(function(command) { |
| 494 dispatchCanExecuteEvent(command, target) |
| 495 }) |
| 496 }, |
| 497 handleKeyDown_: function(e) { |
| 498 var target = e.target; |
| 499 var commands = Array.prototype.slice.call( |
| 500 target.ownerDocument.querySelectorAll("command")); |
| 501 for (var i = 0, command; command = commands[i]; i++) { |
| 502 if (command.matchesEvent(e)) { |
| 503 command.canExecuteChange(); |
| 504 if (!command.disabled) { |
| 505 e.preventDefault(); |
| 506 e.stopPropagation(); |
| 507 command.execute(); |
| 508 return |
| 509 } |
| 510 } |
| 511 } |
| 512 } |
| 513 }; |
| 514 function CanExecuteEvent(command) { |
| 515 var e = new Event("canExecute", {bubbles: true, cancelable: true}); |
| 516 e.__proto__ = CanExecuteEvent.prototype; |
| 517 e.command = command; |
| 518 return e |
| 519 } |
| 520 CanExecuteEvent.prototype = { |
| 521 __proto__: Event.prototype, |
| 522 command: null, |
| 523 canExecute_: false, |
| 524 get canExecute() { |
| 525 return this.canExecute_ |
| 526 }, |
| 527 set canExecute(canExecute) { |
| 528 this.canExecute_ = !!canExecute; |
| 529 this.stopPropagation(); |
| 530 this.preventDefault() |
| 531 } |
| 532 }; |
| 533 return { |
| 534 Command: Command, CanExecuteEvent: CanExecuteEvent |
| 535 } |
| 536 }); |
| 21 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 537 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 22 // Use of this source code is governed by a BSD-style license that can be | 538 // Use of this source code is governed by a BSD-style license that can be |
| 23 // found in the LICENSE file. | 539 // found in the LICENSE file. |
| 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="fixed";element.style.left="-9999px";element.sty
le.height="0px";element.innerText=msg;document.body.appendChild(element);window.
setTimeout(function(){document.body.removeChild(element)},0)}function url(s){var
s2=s.replace(/(\(|\)|\,|\s|\'|\"|\\)/g,"\\$1");if(/\\\\$/.test(s2)){s2+=" "}ret
urn'url("'+s2+'")'}function parseQueryParams(location){var params={};var query=u
nescape(location.search.substring(1));var vars=query.split("&");for(var i=0;i<va
rs.length;i++){var pair=vars[i].split("=");params[pair[0]]=pair[1]}return params
}function setQueryParam(location,key,value){var query=parseQueryParams(location)
;query[encodeURIComponent(key)]=encodeURIComponent(value);var newQuery="";for(va
r q in query){newQuery+=(newQuery?"&":"?")+q+"="+query[q]}return location.origin
+location.pathname+newQuery+location.hash}function findAncestorByClass(el,classN
ame){return findAncestor(el,function(el){return el.classList&&el.classList.conta
ins(className)})}function findAncestor(node,predicate){var last=false;while(node
!=null&&!(last=predicate(node))){node=node.parentNode}return last?node:null}func
tion swapDomNodes(a,b){var afterA=a.nextSibling;if(afterA==b){swapDomNodes(b,a);
return}var aParent=a.parentNode;b.parentNode.replaceChild(a,b);aParent.insertBef
ore(b,afterA)}function disableTextSelectAndDrag(opt_allowSelectStart,opt_allowDr
agStart){document.onselectstart=function(e){if(!(opt_allowSelectStart&&opt_allow
SelectStart.call(this,e)))e.preventDefault()};document.ondragstart=function(e){i
f(!(opt_allowDragStart&&opt_allowDragStart.call(this,e)))e.preventDefault()}}fun
ction preventDefaultOnPoundLinkClicks(){document.addEventListener("click",functi
on(e){var anchor=findAncestor(e.target,function(el){return el.tagName=="A"});if(
anchor&&anchor.getAttribute("href")=="#")e.preventDefault()})}function isRTL(){r
eturn document.documentElement.dir=="rtl"}function getRequiredElement(id){return
assertInstanceof($(id),HTMLElement,"Missing required element: "+id)}function qu
eryRequiredElement(selectors,opt_context){var element=(opt_context||document).qu
erySelector(selectors);return assertInstanceof(element,HTMLElement,"Missing requ
ired element: "+selectors)}["click","auxclick"].forEach(function(eventName){docu
ment.addEventListener(eventName,function(e){if(e.button>1)return;if(e.defaultPre
vented)return;var eventPath=e.path;var anchor=null;if(eventPath){for(var i=0;i<e
ventPath.length;i++){var element=eventPath[i];if(element.tagName==="A"&&element.
href){anchor=element;break}}}var el=e.target;if(!anchor&&el.nodeType==Node.ELEME
NT_NODE&&el.webkitMatchesSelector("A, A *")){while(el.tagName!="A"){el=el.parent
Element}anchor=el}if(!anchor)return;anchor=anchor;if((anchor.protocol=="file:"||
anchor.protocol=="about:")&&(e.button==0||e.button==1)){chrome.send("navigateToU
rl",[anchor.href,anchor.target,e.button,e.altKey,e.ctrlKey,e.metaKey,e.shiftKey]
);e.preventDefault()}})});function appendParam(url,key,value){var param=encodeUR
IComponent(key)+"="+encodeURIComponent(value);if(url.indexOf("?")==-1)return url
+"?"+param;return url+"&"+param}function createElementWithClassName(type,classNa
me){var elm=document.createElement(type);elm.className=className;return elm}func
tion ensureTransitionEndEvent(el,opt_timeOut){if(opt_timeOut===undefined){var st
yle=getComputedStyle(el);opt_timeOut=parseFloat(style.transitionDuration)*1e3;op
t_timeOut+=50}var fired=false;el.addEventListener("webkitTransitionEnd",function
f(e){el.removeEventListener("webkitTransitionEnd",f);fired=true});window.setTim
eout(function(){if(!fired)cr.dispatchSimpleEvent(el,"webkitTransitionEnd",true)}
,opt_timeOut)}function scrollTopForDocument(doc){return doc.documentElement.scro
llTop||doc.body.scrollTop}function setScrollTopForDocument(doc,value){doc.docume
ntElement.scrollTop=doc.body.scrollTop=value}function scrollLeftForDocument(doc)
{return doc.documentElement.scrollLeft||doc.body.scrollLeft}function setScrollLe
ftForDocument(doc,value){doc.documentElement.scrollLeft=doc.body.scrollLeft=valu
e}function HTMLEscape(original){return original.replace(/&/g,"&").replace(/<
/g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}fun
ction elide(original,maxLength){if(original.length<=maxLength)return original;re
turn original.substring(0,maxLength-1)+"…"}function quoteString(str){return str.
replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g,"\\$1")}function listenOnc
e(target,eventNames,callback){if(!Array.isArray(eventNames))eventNames=eventName
s.split(/ +/);var removeAllAndCallCallback=function(event){eventNames.forEach(fu
nction(eventName){target.removeEventListener(eventName,removeAllAndCallCallback,
false)});return callback(event)};eventNames.forEach(function(eventName){target.a
ddEventListener(eventName,removeAllAndCallCallback,false)})} | 540 function $(id) { |
| 541 var el = document.getElementById(id); |
| 542 return el ? assertInstanceof(el, HTMLElement) : null |
| 543 } |
| 544 function getSVGElement(id) { |
| 545 var el = document.getElementById(id); |
| 546 return el ? assertInstanceof(el, Element) : null |
| 547 } |
| 548 function announceAccessibleMessage(msg) { |
| 549 var element = document.createElement("div"); |
| 550 element.setAttribute("aria-live", "polite"); |
| 551 element.style.position = "fixed"; |
| 552 element.style.left = "-9999px"; |
| 553 element.style.height = "0px"; |
| 554 element.innerText = msg; |
| 555 document.body.appendChild(element); |
| 556 window.setTimeout(function() { |
| 557 document.body.removeChild(element) |
| 558 }, 0) |
| 559 } |
| 560 function url(s) { |
| 561 var s2 = s.replace(/(\(|\)|\,|\s|\'|\"|\\)/g, "\\$1"); |
| 562 if (/\\\\$/.test(s2)) { |
| 563 s2 += " " |
| 564 } |
| 565 return 'url("' + s2 + '")' |
| 566 } |
| 567 function parseQueryParams(location) { |
| 568 var params = {}; |
| 569 var query = unescape(location.search.substring(1)); |
| 570 var vars = query.split("&"); |
| 571 for (var i = 0; i < vars.length; i++) { |
| 572 var pair = vars[i].split("="); |
| 573 params[pair[0]] = pair[1] |
| 574 } |
| 575 return params |
| 576 } |
| 577 function setQueryParam(location, key, value) { |
| 578 var query = parseQueryParams(location); |
| 579 query[encodeURIComponent(key)] = encodeURIComponent(value); |
| 580 var newQuery = ""; |
| 581 for (var q in query) { |
| 582 newQuery += (newQuery ? "&" : "?") + q + "=" + query[q] |
| 583 } |
| 584 return location.origin + location.pathname + newQuery + location.hash |
| 585 } |
| 586 function findAncestorByClass(el, className) { |
| 587 return findAncestor(el, function(el) { |
| 588 return el.classList && el.classList.contains(className) |
| 589 }) |
| 590 } |
| 591 function findAncestor(node, predicate) { |
| 592 var last = false; |
| 593 while (node != null && !(last = predicate(node))) { |
| 594 node = node.parentNode |
| 595 } |
| 596 return last ? node : null |
| 597 } |
| 598 function swapDomNodes(a, b) { |
| 599 var afterA = a.nextSibling; |
| 600 if (afterA == b) { |
| 601 swapDomNodes(b, a); |
| 602 return |
| 603 } |
| 604 var aParent = a.parentNode; |
| 605 b.parentNode.replaceChild(a, b); |
| 606 aParent.insertBefore(b, afterA) |
| 607 } |
| 608 function disableTextSelectAndDrag(opt_allowSelectStart, opt_allowDragStart) { |
| 609 document.onselectstart = function(e) { |
| 610 if (!(opt_allowSelectStart && opt_allowSelectStart.call(this, e))) |
| 611 e.preventDefault() |
| 612 }; |
| 613 document.ondragstart = function(e) { |
| 614 if (!(opt_allowDragStart && opt_allowDragStart.call(this, e))) |
| 615 e.preventDefault() |
| 616 } |
| 617 } |
| 618 function preventDefaultOnPoundLinkClicks() { |
| 619 document.addEventListener("click", function(e) { |
| 620 var anchor = findAncestor(e.target, function(el) { |
| 621 return el.tagName == "A" |
| 622 }); |
| 623 if (anchor && anchor.getAttribute("href") == "#") |
| 624 e.preventDefault() |
| 625 }) |
| 626 } |
| 627 function isRTL() { |
| 628 return document.documentElement.dir == "rtl" |
| 629 } |
| 630 function getRequiredElement(id) { |
| 631 return assertInstanceof($(id), HTMLElement, "Missing required element: " + id) |
| 632 } |
| 633 function queryRequiredElement(selectors, opt_context) { |
| 634 var element = (opt_context || document).querySelector(selectors); |
| 635 return assertInstanceof( |
| 636 element, HTMLElement, "Missing required element: " + selectors) |
| 637 } |
| 638 ["click", "auxclick"].forEach(function(eventName) { |
| 639 document.addEventListener(eventName, function(e) { |
| 640 if (e.button > 1) |
| 641 return; |
| 642 if (e.defaultPrevented) |
| 643 return; |
| 644 var eventPath = e.path; |
| 645 var anchor = null; |
| 646 if (eventPath) { |
| 647 for (var i = 0; i < eventPath.length; i++) { |
| 648 var element = eventPath[i]; |
| 649 if (element.tagName === "A" && element.href) { |
| 650 anchor = element; |
| 651 break |
| 652 } |
| 653 } |
| 654 } |
| 655 var el = e.target; |
| 656 if (!anchor && el.nodeType == Node.ELEMENT_NODE && |
| 657 el.webkitMatchesSelector("A, A *")) { |
| 658 while (el.tagName != "A") { |
| 659 el = el.parentElement |
| 660 } |
| 661 anchor = el |
| 662 } |
| 663 if (!anchor) |
| 664 return; |
| 665 anchor = anchor; |
| 666 if ((anchor.protocol == "file:" || anchor.protocol == "about:") && |
| 667 (e.button == 0 || e.button == 1)) { |
| 668 chrome.send("navigateToUrl", [ |
| 669 anchor.href, anchor.target, e.button, e.altKey, e.ctrlKey, e.metaKey, |
| 670 e.shiftKey |
| 671 ]); |
| 672 e.preventDefault() |
| 673 } |
| 674 }) |
| 675 }); |
| 676 function appendParam(url, key, value) { |
| 677 var param = encodeURIComponent(key) + "=" + encodeURIComponent(value); |
| 678 if (url.indexOf("?") == -1) |
| 679 return url + "?" + param; |
| 680 return url + "&" + param |
| 681 } |
| 682 function createElementWithClassName(type, className) { |
| 683 var elm = document.createElement(type); |
| 684 elm.className = className; |
| 685 return elm |
| 686 } |
| 687 function ensureTransitionEndEvent(el, opt_timeOut) { |
| 688 if (opt_timeOut === undefined) { |
| 689 var style = getComputedStyle(el); |
| 690 opt_timeOut = parseFloat(style.transitionDuration) * 1e3; |
| 691 opt_timeOut += 50 |
| 692 } |
| 693 var fired = false; |
| 694 el.addEventListener("webkitTransitionEnd", function f(e) { |
| 695 el.removeEventListener("webkitTransitionEnd", f); |
| 696 fired = true |
| 697 }); |
| 698 window.setTimeout(function() { |
| 699 if (!fired) |
| 700 cr.dispatchSimpleEvent(el, "webkitTransitionEnd", true) |
| 701 }, opt_timeOut) |
| 702 } |
| 703 function scrollTopForDocument(doc) { |
| 704 return doc.documentElement.scrollTop || doc.body.scrollTop |
| 705 } |
| 706 function setScrollTopForDocument(doc, value) { |
| 707 doc.documentElement.scrollTop = doc.body.scrollTop = value |
| 708 } |
| 709 function scrollLeftForDocument(doc) { |
| 710 return doc.documentElement.scrollLeft || doc.body.scrollLeft |
| 711 } |
| 712 function setScrollLeftForDocument(doc, value) { |
| 713 doc.documentElement.scrollLeft = doc.body.scrollLeft = value |
| 714 } |
| 715 function HTMLEscape(original) { |
| 716 return original.replace(/&/g, "&") |
| 717 .replace(/</g, "<") |
| 718 .replace(/>/g, ">") |
| 719 .replace(/"/g, """) |
| 720 .replace(/'/g, "'") |
| 721 } |
| 722 function elide(original, maxLength) { |
| 723 if (original.length <= maxLength) |
| 724 return original; |
| 725 return original.substring(0, maxLength - 1) + "…" |
| 726 } |
| 727 function quoteString(str) { |
| 728 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1") |
| 729 } |
| 730 function listenOnce(target, eventNames, callback) { |
| 731 if (!Array.isArray(eventNames)) |
| 732 eventNames = eventNames.split(/ +/); |
| 733 var removeAllAndCallCallback = function(event) { |
| 734 eventNames.forEach(function(eventName) { |
| 735 target.removeEventListener(eventName, removeAllAndCallCallback, false) |
| 736 }); |
| 737 return callback(event) |
| 738 }; |
| 739 eventNames.forEach(function(eventName) { |
| 740 target.addEventListener(eventName, removeAllAndCallCallback, false) |
| 741 }) |
| 742 } |
| 25 // <if expr="is_ios"> | 743 // <if expr="is_ios"> |
| 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")} | 744 if (!("key" in KeyboardEvent.prototype)) { |
| 27 // </if> /* is_ios */ | 745 Object.defineProperty(KeyboardEvent.prototype, "key", { |
| 28 function importModules(moduleNames){return new Promise(function(resolve){define(
moduleNames,function(){resolve(Array.from(arguments))})})}function hasKeyModifie
rs(e){return!!(e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)}Polymer.IronResizable
Behavior={properties:{_parentResizable:{type:Object,observer:"_parentResizableCh
anged"},_notifyingDescendant:{type:Boolean,value:false}},listeners:{"iron-reques
t-resize-notifications":"_onIronRequestResizeNotifications"},created:function(){
this._interestedResizables=[];this._boundNotifyResize=this.notifyResize.bind(thi
s)},attached:function(){this.fire("iron-request-resize-notifications",null,{node
:this,bubbles:true,cancelable:true});if(!this._parentResizable){window.addEventL
istener("resize",this._boundNotifyResize);this.notifyResize()}},detached:functio
n(){if(this._parentResizable){this._parentResizable.stopResizeNotificationsFor(t
his)}else{window.removeEventListener("resize",this._boundNotifyResize)}this._par
entResizable=null},notifyResize:function(){if(!this.isAttached){return}this._int
erestedResizables.forEach(function(resizable){if(this.resizerShouldNotify(resiza
ble)){this._notifyDescendant(resizable)}},this);this._fireResize()},assignParent
Resizable:function(parentResizable){this._parentResizable=parentResizable},stopR
esizeNotificationsFor:function(target){var index=this._interestedResizables.inde
xOf(target);if(index>-1){this._interestedResizables.splice(index,1);this.unliste
n(target,"iron-resize","_onDescendantIronResize")}},resizerShouldNotify:function
(element){return true},_onDescendantIronResize:function(event){if(this._notifyin
gDescendant){event.stopPropagation();return}if(!Polymer.Settings.useShadow){this
._fireResize()}},_fireResize:function(){this.fire("iron-resize",null,{node:this,
bubbles:false})},_onIronRequestResizeNotifications:function(event){var target=ev
ent.path?event.path[0]:event.target;if(target===this){return}if(this._interested
Resizables.indexOf(target)===-1){this._interestedResizables.push(target);this.li
sten(target,"iron-resize","_onDescendantIronResize")}target.assignParentResizabl
e(this);this._notifyDescendant(target);event.stopPropagation()},_parentResizable
Changed:function(parentResizable){if(parentResizable){window.removeEventListener
("resize",this._boundNotifyResize)}},_notifyDescendant:function(descendant){if(!
this.isAttached){return}this._notifyingDescendant=true;descendant.notifyResize()
;this._notifyingDescendant=false}};(function(){"use strict";var KEY_IDENTIFIER={
"U+0008":"backspace","U+0009":"tab","U+001B":"esc","U+0020":"space","U+007F":"de
l"};var KEY_CODE={8:"backspace",9:"tab",13:"enter",27:"esc",33:"pageup",34:"page
down",35:"end",36:"home",32:"space",37:"left",38:"up",39:"right",40:"down",46:"d
el",106:"*"};var MODIFIER_KEYS={shift:"shiftKey",ctrl:"ctrlKey",alt:"altKey",met
a:"metaKey"};var KEY_CHAR=/[a-z0-9*]/;var IDENT_CHAR=/U\+/;var ARROW_KEY=/^arrow
/;var SPACE_KEY=/^space(bar)?/;var ESC_KEY=/^escape$/;function transformKey(key,
noSpecialChars){var validKey="";if(key){var lKey=key.toLowerCase();if(lKey===" "
||SPACE_KEY.test(lKey)){validKey="space"}else if(ESC_KEY.test(lKey)){validKey="e
sc"}else if(lKey.length==1){if(!noSpecialChars||KEY_CHAR.test(lKey)){validKey=lK
ey}}else if(ARROW_KEY.test(lKey)){validKey=lKey.replace("arrow","")}else if(lKey
=="multiply"){validKey="*"}else{validKey=lKey}}return validKey}function transfor
mKeyIdentifier(keyIdent){var validKey="";if(keyIdent){if(keyIdent in KEY_IDENTIF
IER){validKey=KEY_IDENTIFIER[keyIdent]}else if(IDENT_CHAR.test(keyIdent)){keyIde
nt=parseInt(keyIdent.replace("U+","0x"),16);validKey=String.fromCharCode(keyIden
t).toLowerCase()}else{validKey=keyIdent.toLowerCase()}}return validKey}function
transformKeyCode(keyCode){var validKey="";if(Number(keyCode)){if(keyCode>=65&&ke
yCode<=90){validKey=String.fromCharCode(32+keyCode)}else if(keyCode>=112&&keyCod
e<=123){validKey="f"+(keyCode-112)}else if(keyCode>=48&&keyCode<=57){validKey=St
ring(keyCode-48)}else if(keyCode>=96&&keyCode<=105){validKey=String(keyCode-96)}
else{validKey=KEY_CODE[keyCode]}}return validKey}function normalizedKeyForEvent(
keyEvent,noSpecialChars){if(keyEvent.key){return transformKey(keyEvent.key,noSpe
cialChars)}if(keyEvent.detail&&keyEvent.detail.key){return transformKey(keyEvent
.detail.key,noSpecialChars)}return transformKeyIdentifier(keyEvent.keyIdentifier
)||transformKeyCode(keyEvent.keyCode)||""}function keyComboMatchesEvent(keyCombo
,event){var keyEvent=normalizedKeyForEvent(event,keyCombo.hasModifiers);return k
eyEvent===keyCombo.key&&(!keyCombo.hasModifiers||!!event.shiftKey===!!keyCombo.s
hiftKey&&!!event.ctrlKey===!!keyCombo.ctrlKey&&!!event.altKey===!!keyCombo.altKe
y&&!!event.metaKey===!!keyCombo.metaKey)}function parseKeyComboString(keyComboSt
ring){if(keyComboString.length===1){return{combo:keyComboString,key:keyComboStri
ng,event:"keydown"}}return keyComboString.split("+").reduce(function(parsedKeyCo
mbo,keyComboPart){var eventParts=keyComboPart.split(":");var keyName=eventParts[
0];var event=eventParts[1];if(keyName in MODIFIER_KEYS){parsedKeyCombo[MODIFIER_
KEYS[keyName]]=true;parsedKeyCombo.hasModifiers=true}else{parsedKeyCombo.key=key
Name;parsedKeyCombo.event=event||"keydown"}return parsedKeyCombo},{combo:keyComb
oString.split(":").shift()})}function parseEventString(eventString){return event
String.trim().split(" ").map(function(keyComboString){return parseKeyComboString
(keyComboString)})}Polymer.IronA11yKeysBehavior={properties:{keyEventTarget:{typ
e:Object,value:function(){return this}},stopKeyboardEventPropagation:{type:Boole
an,value:false},_boundKeyHandlers:{type:Array,value:function(){return[]}},_imper
ativeKeyBindings:{type:Object,value:function(){return{}}}},observers:["_resetKey
EventListeners(keyEventTarget, _boundKeyHandlers)"],keyBindings:{},registered:fu
nction(){this._prepKeyBindings()},attached:function(){this._listenKeyEventListen
ers()},detached:function(){this._unlistenKeyEventListeners()},addOwnKeyBinding:f
unction(eventString,handlerName){this._imperativeKeyBindings[eventString]=handle
rName;this._prepKeyBindings();this._resetKeyEventListeners()},removeOwnKeyBindin
gs:function(){this._imperativeKeyBindings={};this._prepKeyBindings();this._reset
KeyEventListeners()},keyboardEventMatchesKeys:function(event,eventString){var ke
yCombos=parseEventString(eventString);for(var i=0;i<keyCombos.length;++i){if(key
ComboMatchesEvent(keyCombos[i],event)){return true}}return false},_collectKeyBin
dings:function(){var keyBindings=this.behaviors.map(function(behavior){return be
havior.keyBindings});if(keyBindings.indexOf(this.keyBindings)===-1){keyBindings.
push(this.keyBindings)}return keyBindings},_prepKeyBindings:function(){this._key
Bindings={};this._collectKeyBindings().forEach(function(keyBindings){for(var eve
ntString in keyBindings){this._addKeyBinding(eventString,keyBindings[eventString
])}},this);for(var eventString in this._imperativeKeyBindings){this._addKeyBindi
ng(eventString,this._imperativeKeyBindings[eventString])}for(var eventName in th
is._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})}},_addKeyB
inding:function(eventString,handlerName){parseEventString(eventString).forEach(f
unction(keyCombo){this._keyBindings[keyCombo.event]=this._keyBindings[keyCombo.e
vent]||[];this._keyBindings[keyCombo.event].push([keyCombo,handlerName])},this)}
,_resetKeyEventListeners:function(){this._unlistenKeyEventListeners();if(this.is
Attached){this._listenKeyEventListeners()}},_listenKeyEventListeners:function(){
if(!this.keyEventTarget){return}Object.keys(this._keyBindings).forEach(function(
eventName){var keyBindings=this._keyBindings[eventName];var boundKeyHandler=this
._onKeyBindingEvent.bind(this,keyBindings);this._boundKeyHandlers.push([this.key
EventTarget,eventName,boundKeyHandler]);this.keyEventTarget.addEventListener(eve
ntName,boundKeyHandler)},this)},_unlistenKeyEventListeners:function(){var keyHan
dlerTuple;var keyEventTarget;var eventName;var boundKeyHandler;while(this._bound
KeyHandlers.length){keyHandlerTuple=this._boundKeyHandlers.pop();keyEventTarget=
keyHandlerTuple[0];eventName=keyHandlerTuple[1];boundKeyHandler=keyHandlerTuple[
2];keyEventTarget.removeEventListener(eventName,boundKeyHandler)}},_onKeyBinding
Event:function(keyBindings,event){if(this.stopKeyboardEventPropagation){event.st
opPropagation()}if(event.defaultPrevented){return}for(var i=0;i<keyBindings.leng
th;i++){var keyCombo=keyBindings[i][0];var handlerName=keyBindings[i][1];if(keyC
omboMatchesEvent(keyCombo,event)){this._triggerKeyHandler(keyCombo,handlerName,e
vent);if(event.defaultPrevented){return}}}},_triggerKeyHandler:function(keyCombo
,handlerName,keyboardEvent){var detail=Object.create(keyCombo);detail.keyboardEv
ent=keyboardEvent;var event=new CustomEvent(keyCombo.event,{detail:detail,cancel
able:true});this[handlerName].call(this,event);if(event.defaultPrevented){keyboa
rdEvent.preventDefault()}}}})();Polymer.IronScrollTargetBehavior={properties:{sc
rollTarget:{type:HTMLElement,value:function(){return this._defaultScrollTarget}}
},observers:["_scrollTargetChanged(scrollTarget, isAttached)"],_shouldHaveListen
er:true,_scrollTargetChanged:function(scrollTarget,isAttached){var eventTarget;i
f(this._oldScrollTarget){this._toggleScrollListener(false,this._oldScrollTarget)
;this._oldScrollTarget=null}if(!isAttached){return}if(scrollTarget==="document")
{this.scrollTarget=this._doc}else if(typeof scrollTarget==="string"){this.scroll
Target=this.domHost?this.domHost.$[scrollTarget]:Polymer.dom(this.ownerDocument)
.querySelector("#"+scrollTarget)}else if(this._isValidScrollTarget()){this._boun
dScrollHandler=this._boundScrollHandler||this._scrollHandler.bind(this);this._ol
dScrollTarget=scrollTarget;this._toggleScrollListener(this._shouldHaveListener,s
crollTarget)}},_scrollHandler:function scrollHandler(){},get _defaultScrollTarge
t(){return this._doc},get _doc(){return this.ownerDocument.documentElement},get
_scrollTop(){if(this._isValidScrollTarget()){return this.scrollTarget===this._do
c?window.pageYOffset:this.scrollTarget.scrollTop}return 0},get _scrollLeft(){if(
this._isValidScrollTarget()){return this.scrollTarget===this._doc?window.pageXOf
fset:this.scrollTarget.scrollLeft}return 0},set _scrollTop(top){if(this.scrollTa
rget===this._doc){window.scrollTo(window.pageXOffset,top)}else if(this._isValidS
crollTarget()){this.scrollTarget.scrollTop=top}},set _scrollLeft(left){if(this.s
crollTarget===this._doc){window.scrollTo(left,window.pageYOffset)}else if(this._
isValidScrollTarget()){this.scrollTarget.scrollLeft=left}},scroll:function(left,
top){if(this.scrollTarget===this._doc){window.scrollTo(left,top)}else if(this._i
sValidScrollTarget()){this.scrollTarget.scrollLeft=left;this.scrollTarget.scroll
Top=top}},get _scrollTargetWidth(){if(this._isValidScrollTarget()){return this.s
crollTarget===this._doc?window.innerWidth:this.scrollTarget.offsetWidth}return 0
},get _scrollTargetHeight(){if(this._isValidScrollTarget()){return this.scrollTa
rget===this._doc?window.innerHeight:this.scrollTarget.offsetHeight}return 0},_is
ValidScrollTarget:function(){return this.scrollTarget instanceof HTMLElement},_t
oggleScrollListener:function(yes,scrollTarget){if(!this._boundScrollHandler){ret
urn}var eventTarget=scrollTarget===this._doc?window:scrollTarget;if(yes){eventTa
rget.addEventListener("scroll",this._boundScrollHandler)}else{eventTarget.remove
EventListener("scroll",this._boundScrollHandler)}},toggleScrollListener:function
(yes){this._shouldHaveListener=yes;this._toggleScrollListener(yes,this.scrollTar
get)}};(function(){var IOS=navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU)
OS (\d+)/);var IOS_TOUCH_SCROLLING=IOS&&IOS[1]>=8;var DEFAULT_PHYSICAL_COUNT=3;
var HIDDEN_Y="-10000px";var ITEM_WIDTH=0;var ITEM_HEIGHT=1;var SECRET_TABINDEX=-
100;Polymer({is:"iron-list",properties:{items:{type:Array},maxPhysicalCount:{typ
e:Number,value:500},as:{type:String,value:"item"},indexAs:{type:String,value:"in
dex"},selectedAs:{type:String,value:"selected"},grid:{type:Boolean,value:false,r
eflectToAttribute:true},selectionEnabled:{type:Boolean,value:false},selectedItem
:{type:Object,notify:true},selectedItems:{type:Object,notify:true},multiSelectio
n:{type:Boolean,value:false}},observers:["_itemsChanged(items.*)","_selectionEna
bledChanged(selectionEnabled)","_multiSelectionChanged(multiSelection)","_setOve
rflow(scrollTarget)"],behaviors:[Polymer.Templatizer,Polymer.IronResizableBehavi
or,Polymer.IronA11yKeysBehavior,Polymer.IronScrollTargetBehavior],keyBindings:{u
p:"_didMoveUp",down:"_didMoveDown",enter:"_didEnter"},_ratio:.5,_scrollerPadding
Top:0,_scrollPosition:0,_physicalSize:0,_physicalAverage:0,_physicalAverageCount
:0,_physicalTop:0,_virtualCount:0,_physicalIndexForKey:null,_estScrollHeight:0,_
scrollHeight:0,_viewportHeight:0,_viewportWidth:0,_physicalItems:null,_physicalS
izes:null,_firstVisibleIndexVal:null,_lastVisibleIndexVal:null,_collection:null,
_maxPages:2,_focusedItem:null,_focusedIndex:-1,_offscreenFocusedItem:null,_focus
BackfillItem:null,_itemsPerRow:1,_itemWidth:0,_rowHeight:0,_templateCost:0,get _
physicalBottom(){return this._physicalTop+this._physicalSize},get _scrollBottom(
){return this._scrollPosition+this._viewportHeight},get _virtualEnd(){return thi
s._virtualStart+this._physicalCount-1},get _hiddenContentSize(){var size=this.gr
id?this._physicalRows*this._rowHeight:this._physicalSize;return size-this._viewp
ortHeight},get _maxScrollTop(){return this._estScrollHeight-this._viewportHeight
+this._scrollerPaddingTop},_minVirtualStart:0,get _maxVirtualStart(){return Math
.max(0,this._virtualCount-this._physicalCount)},_virtualStartVal:0,set _virtualS
tart(val){this._virtualStartVal=Math.min(this._maxVirtualStart,Math.max(this._mi
nVirtualStart,val))},get _virtualStart(){return this._virtualStartVal||0},_physi
calStartVal:0,set _physicalStart(val){this._physicalStartVal=val%this._physicalC
ount;if(this._physicalStartVal<0){this._physicalStartVal=this._physicalCount+thi
s._physicalStartVal}this._physicalEnd=(this._physicalStart+this._physicalCount-1
)%this._physicalCount},get _physicalStart(){return this._physicalStartVal||0},_p
hysicalCountVal:0,set _physicalCount(val){this._physicalCountVal=val;this._physi
calEnd=(this._physicalStart+this._physicalCount-1)%this._physicalCount},get _phy
sicalCount(){return this._physicalCountVal},_physicalEnd:0,get _optPhysicalSize(
){if(this.grid){return this._estRowsInView*this._rowHeight*this._maxPages}return
this._viewportHeight*this._maxPages},get _isVisible(){return Boolean(this.offse
tWidth||this.offsetHeight)},get firstVisibleIndex(){if(this._firstVisibleIndexVa
l===null){var physicalOffset=Math.floor(this._physicalTop+this._scrollerPaddingT
op);this._firstVisibleIndexVal=this._iterateItems(function(pidx,vidx){physicalOf
fset+=this._getPhysicalSizeIncrement(pidx);if(physicalOffset>this._scrollPositio
n){return this.grid?vidx-vidx%this._itemsPerRow:vidx}if(this.grid&&this._virtual
Count-1===vidx){return vidx-vidx%this._itemsPerRow}})||0}return this._firstVisib
leIndexVal},get lastVisibleIndex(){if(this._lastVisibleIndexVal===null){if(this.
grid){var lastIndex=this.firstVisibleIndex+this._estRowsInView*this._itemsPerRow
-1;this._lastVisibleIndexVal=Math.min(this._virtualCount,lastIndex)}else{var phy
sicalOffset=this._physicalTop;this._iterateItems(function(pidx,vidx){if(physical
Offset<this._scrollBottom){this._lastVisibleIndexVal=vidx}else{return true}physi
calOffset+=this._getPhysicalSizeIncrement(pidx)})}}return this._lastVisibleIndex
Val},get _defaultScrollTarget(){return this},get _virtualRowCount(){return Math.
ceil(this._virtualCount/this._itemsPerRow)},get _estRowsInView(){return Math.cei
l(this._viewportHeight/this._rowHeight)},get _physicalRows(){return Math.ceil(th
is._physicalCount/this._itemsPerRow)},ready:function(){this.addEventListener("fo
cus",this._didFocus.bind(this),true)},attached:function(){if(this._physicalCount
===0){this._debounceTemplate(this._render)}this.listen(this,"iron-resize","_resi
zeHandler")},detached:function(){this.unlisten(this,"iron-resize","_resizeHandle
r")},_setOverflow:function(scrollTarget){this.style.webkitOverflowScrolling=scro
llTarget===this?"touch":"";this.style.overflow=scrollTarget===this?"auto":""},up
dateViewportBoundaries:function(){this._scrollerPaddingTop=this.scrollTarget===t
his?0:parseInt(window.getComputedStyle(this)["padding-top"],10);this._viewportWi
dth=this.$.items.offsetWidth;this._viewportHeight=this._scrollTargetHeight;this.
grid&&this._updateGridMetrics()},_scrollHandler:function(){var scrollTop=Math.ma
x(0,Math.min(this._maxScrollTop,this._scrollTop));var delta=scrollTop-this._scro
llPosition;var isScrollingDown=delta>=0;this._scrollPosition=scrollTop;this._fir
stVisibleIndexVal=null;this._lastVisibleIndexVal=null;if(Math.abs(delta)>this._p
hysicalSize){var idxAdjustment=Math.round(delta/this._physicalAverage)*this._ite
msPerRow;this._physicalTop=this._physicalTop+delta;this._virtualStart=this._virt
ualStart+idxAdjustment;this._physicalStart=this._physicalStart+idxAdjustment;thi
s._update()}else{var reusables=this._getReusables(isScrollingDown);if(isScrollin
gDown){this._physicalTop=reusables.physicalTop;this._virtualStart=this._virtualS
tart+reusables.indexes.length;this._physicalStart=this._physicalStart+reusables.
indexes.length}else{this._virtualStart=this._virtualStart-reusables.indexes.leng
th;this._physicalStart=this._physicalStart-reusables.indexes.length}if(reusables
.indexes.length===0){this._increasePoolIfNeeded()}else{this._update(reusables.in
dexes,isScrollingDown?null:reusables.indexes)}}},_getReusables:function(fromTop)
{var ith,lastIth,offsetContent,physicalItemHeight;var idxs=[];var protectedOffse
tContent=this._hiddenContentSize*this._ratio;var virtualStart=this._virtualStart
;var virtualEnd=this._virtualEnd;var physicalCount=this._physicalCount;var physi
calTop=this._physicalTop+this._scrollerPaddingTop;var scrollTop=this._scrollTop;
var scrollBottom=this._scrollBottom;if(fromTop){ith=this._physicalStart;lastIth=
this._physicalEnd;offsetContent=scrollTop-physicalTop}else{ith=this._physicalEnd
;lastIth=this._physicalStart;offsetContent=this._physicalBottom-scrollBottom}whi
le(true){physicalItemHeight=this._getPhysicalSizeIncrement(ith);offsetContent=of
fsetContent-physicalItemHeight;if(idxs.length>=physicalCount||offsetContent<=pro
tectedOffsetContent){break}if(fromTop){if(virtualEnd+idxs.length+1>=this._virtua
lCount){break}if(physicalTop+physicalItemHeight>=scrollTop){break}idxs.push(ith)
;physicalTop=physicalTop+physicalItemHeight;ith=(ith+1)%physicalCount}else{if(vi
rtualStart-idxs.length<=0){break}if(physicalTop+this._physicalSize-physicalItemH
eight<=scrollBottom){break}idxs.push(ith);physicalTop=physicalTop-physicalItemHe
ight;ith=ith===0?physicalCount-1:ith-1}}return{indexes:idxs,physicalTop:physical
Top-this._scrollerPaddingTop}},_update:function(itemSet,movingUp){if(itemSet&&it
emSet.length===0){return}this._manageFocus();this._assignModels(itemSet);this._u
pdateMetrics(itemSet);if(movingUp){while(movingUp.length){var idx=movingUp.pop()
;this._physicalTop-=this._getPhysicalSizeIncrement(idx)}}this._positionItems();t
his._updateScrollerSize();this._increasePoolIfNeeded()},_createPool:function(siz
e){var physicalItems=new Array(size);this._ensureTemplatized();for(var i=0;i<siz
e;i++){var inst=this.stamp(null);physicalItems[i]=inst.root.querySelector("*");P
olymer.dom(this).appendChild(inst.root)}return physicalItems},_increasePoolIfNee
ded:function(){if(this._viewportHeight===0){return false}var self=this;var isCli
entFull=this._physicalBottom>=this._scrollBottom&&this._physicalTop<=this._scrol
lPosition;if(this._physicalSize>=this._optPhysicalSize&&isClientFull){return fal
se}var maxPoolSize=Math.round(this._physicalCount*.5);if(!isClientFull){this._de
bounceTemplate(this._increasePool.bind(this,maxPoolSize));return true}this._yiel
d(function(){self._increasePool(Math.min(maxPoolSize,Math.max(1,Math.round(50/se
lf._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(hand
le):g.clearTimeout(handle);cb()}})},_increasePool:function(missingItems){var nex
tPhysicalCount=Math.min(this._physicalCount+missingItems,this._virtualCount-this
._virtualStart,Math.max(this.maxPhysicalCount,DEFAULT_PHYSICAL_COUNT));var prevP
hysicalCount=this._physicalCount;var delta=nextPhysicalCount-prevPhysicalCount;v
ar ts=window.performance.now();if(delta<=0){return}[].push.apply(this._physicalI
tems,this._createPool(delta));[].push.apply(this._physicalSizes,new Array(delta)
);this._physicalCount=prevPhysicalCount+delta;if(this._physicalStart>this._physi
calEnd&&this._isIndexRendered(this._focusedIndex)&&this._getPhysicalIndex(this._
focusedIndex)<this._physicalEnd){this._physicalStart=this._physicalStart+delta}t
his._update();this._templateCost=(window.performance.now()-ts)/delta},_render:fu
nction(){if(this.isAttached&&this._isVisible){if(this._physicalCount===0){this.u
pdateViewportBoundaries();this._increasePool(DEFAULT_PHYSICAL_COUNT)}else{var re
usables=this._getReusables(true);this._physicalTop=reusables.physicalTop;this._v
irtualStart=this._virtualStart+reusables.indexes.length;this._physicalStart=this
._physicalStart+reusables.indexes.length;this._update(reusables.indexes);this._u
pdate()}}},_ensureTemplatized:function(){if(!this.ctor){var props={};props.__key
__=true;props[this.as]=true;props[this.indexAs]=true;props[this.selectedAs]=true
;props.tabIndex=true;this._instanceProps=props;this._userTemplate=Polymer.dom(th
is).querySelector("template");if(this._userTemplate){this.templatize(this._userT
emplate)}else{console.warn("iron-list requires a template to be provided in ligh
t-dom")}}},_getStampedChildren:function(){return this._physicalItems},_forwardIn
stancePath:function(inst,path,value){if(path.indexOf(this.as+".")===0){this.noti
fyPath("items."+inst.__key__+"."+path.slice(this.as.length+1),value)}},_forwardP
arentProp:function(prop,value){if(this._physicalItems){this._physicalItems.forEa
ch(function(item){item._templateInstance[prop]=value},this)}},_forwardParentPath
:function(path,value){if(this._physicalItems){this._physicalItems.forEach(functi
on(item){item._templateInstance.notifyPath(path,value,true)},this)}},_forwardIte
mPath:function(path,value){if(!this._physicalIndexForKey){return}var dot=path.in
dexOf(".");var key=path.substring(0,dot<0?path.length:dot);var idx=this._physica
lIndexForKey[key];var offscreenItem=this._offscreenFocusedItem;var el=offscreenI
tem&&offscreenItem._templateInstance.__key__===key?offscreenItem:this._physicalI
tems[idx];if(!el||el._templateInstance.__key__!==key){return}if(dot>=0){path=thi
s.as+"."+path.substring(dot+1);el._templateInstance.notifyPath(path,value,true)}
else{var currentItem=el._templateInstance[this.as];if(Array.isArray(this.selecte
dItems)){for(var i=0;i<this.selectedItems.length;i++){if(this.selectedItems[i]==
=currentItem){this.set("selectedItems."+i,value);break}}}else if(this.selectedIt
em===currentItem){this.set("selectedItem",value)}el._templateInstance[this.as]=v
alue}},_itemsChanged:function(change){if(change.path==="items"){this._virtualSta
rt=0;this._physicalTop=0;this._virtualCount=this.items?this.items.length:0;this.
_collection=this.items?Polymer.Collection.get(this.items):null;this._physicalInd
exForKey={};this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null;this.
_physicalCount=this._physicalCount||0;this._physicalItems=this._physicalItems||[
];this._physicalSizes=this._physicalSizes||[];this._physicalStart=0;this._resetS
crollPosition(0);this._removeFocusedItem();this._debounceTemplate(this._render)}
else if(change.path==="items.splices"){this._adjustVirtualIndex(change.value.ind
exSplices);this._virtualCount=this.items?this.items.length:0;this._debounceTempl
ate(this._render)}else{this._forwardItemPath(change.path.split(".").slice(1).joi
n("."),change.value)}},_adjustVirtualIndex:function(splices){splices.forEach(fun
ction(splice){splice.removed.forEach(this._removeItem,this);if(splice.index<this
._virtualStart){var delta=Math.max(splice.addedCount-splice.removed.length,splic
e.index-this._virtualStart);this._virtualStart=this._virtualStart+delta;if(this.
_focusedIndex>=0){this._focusedIndex=this._focusedIndex+delta}}},this)},_removeI
tem:function(item){this.$.selector.deselect(item);if(this._focusedItem&&this._fo
cusedItem._templateInstance[this.as]===item){this._removeFocusedItem()}},_iterat
eItems:function(fn,itemSet){var pidx,vidx,rtn,i;if(arguments.length===2&&itemSet
){for(i=0;i<itemSet.length;i++){pidx=itemSet[i];vidx=this._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;pidx<this._physicalStart;pid
x++,vidx++){if((rtn=fn.call(this,pidx,vidx))!=null){return rtn}}}},_computeVidx:
function(pidx){if(pidx>=this._physicalStart){return this._virtualStart+(pidx-thi
s._physicalStart)}return this._virtualStart+(this._physicalCount-this._physicalS
tart)+pidx},_assignModels:function(itemSet){this._iterateItems(function(pidx,vid
x){var el=this._physicalItems[pidx];var inst=el._templateInstance;var item=this.
items&&this.items[vidx];if(item!=null){inst[this.as]=item;inst.__key__=this._col
lection.getKey(item);inst[this.selectedAs]=this.$.selector.isSelected(item);inst
[this.indexAs]=vidx;inst.tabIndex=this._focusedIndex===vidx?0:-1;this._physicalI
ndexForKey[inst.__key__]=pidx;el.removeAttribute("hidden")}else{inst.__key__=nul
l;el.setAttribute("hidden","")}},itemSet)},_updateMetrics:function(itemSet){Poly
mer.dom.flush();var newPhysicalSize=0;var oldPhysicalSize=0;var prevAvgCount=thi
s._physicalAverageCount;var prevPhysicalAvg=this._physicalAverage;this._iterateI
tems(function(pidx,vidx){oldPhysicalSize+=this._physicalSizes[pidx]||0;this._phy
sicalSizes[pidx]=this._physicalItems[pidx].offsetHeight;newPhysicalSize+=this._p
hysicalSizes[pidx];this._physicalAverageCount+=this._physicalSizes[pidx]?1:0},it
emSet);if(this.grid){this._updateGridMetrics();this._physicalSize=Math.ceil(this
._physicalCount/this._itemsPerRow)*this._rowHeight}else{this._physicalSize=this.
_physicalSize+newPhysicalSize-oldPhysicalSize}if(this._physicalAverageCount!==pr
evAvgCount){this._physicalAverage=Math.round((prevPhysicalAvg*prevAvgCount+newPh
ysicalSize)/this._physicalAverageCount)}},_updateGridMetrics:function(){this._it
emWidth=this._physicalCount>0?this._physicalItems[0].getBoundingClientRect().wid
th:200;this._rowHeight=this._physicalCount>0?this._physicalItems[0].offsetHeight
:200;this._itemsPerRow=this._itemWidth?Math.floor(this._viewportWidth/this._item
Width):this._itemsPerRow},_positionItems:function(){this._adjustScrollPosition()
;var y=this._physicalTop;if(this.grid){var totalItemWidth=this._itemsPerRow*this
._itemWidth;var rowOffset=(this._viewportWidth-totalItemWidth)/2;this._iterateIt
ems(function(pidx,vidx){var modulus=vidx%this._itemsPerRow;var x=Math.floor(modu
lus*this._itemWidth+rowOffset);this.translate3d(x+"px",y+"px",0,this._physicalIt
ems[pidx]);if(this._shouldRenderNextRow(vidx)){y+=this._rowHeight}})}else{this._
iterateItems(function(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)%thi
s._itemsPerRow!==this._itemsPerRow-1){return 0}return this._rowHeight},_shouldRe
nderNextRow:function(vidx){return vidx%this._itemsPerRow===this._itemsPerRow-1},
_adjustScrollPosition:function(){var deltaHeight=this._virtualStart===0?this._ph
ysicalTop:Math.min(this._scrollPosition+this._physicalTop,0);if(deltaHeight){thi
s._physicalTop=this._physicalTop-deltaHeight;if(!IOS_TOUCH_SCROLLING&&this._phys
icalTop!==0){this._resetScrollPosition(this._scrollTop-deltaHeight)}}},_resetScr
ollPosition:function(pos){if(this.scrollTarget){this._scrollTop=pos;this._scroll
Position=this._scrollTop}},_updateScrollerSize:function(forceUpdate){if(this.gri
d){this._estScrollHeight=this._virtualRowCount*this._rowHeight}else{this._estScr
ollHeight=this._physicalBottom+Math.max(this._virtualCount-this._physicalCount-t
his._virtualStart,0)*this._physicalAverage}forceUpdate=forceUpdate||this._scroll
Height===0;forceUpdate=forceUpdate||this._scrollPosition>=this._estScrollHeight-
this._physicalSize;forceUpdate=forceUpdate||this.grid&&this.$.items.style.height
<this._estScrollHeight;if(forceUpdate||Math.abs(this._estScrollHeight-this._scro
llHeight)>=this._optPhysicalSize){this.$.items.style.height=this._estScrollHeigh
t+"px";this._scrollHeight=this._estScrollHeight}},scrollToItem:function(item){re
turn this.scrollToIndex(this.items.indexOf(item))},scrollToIndex:function(idx){i
f(typeof idx!=="number"||idx<0||idx>this.items.length-1){return}Polymer.dom.flus
h();if(this._physicalCount===0){return}idx=Math.min(Math.max(idx,0),this._virtua
lCount-1);if(!this._isIndexRendered(idx)||idx>=this._maxVirtualStart){this._virt
ualStart=this.grid?idx-this._itemsPerRow*2:idx-1}this._manageFocus();this._assig
nModels();this._updateMetrics();this._physicalTop=Math.floor(this._virtualStart/
this._itemsPerRow)*this._physicalAverage;var currentTopItem=this._physicalStart;
var currentVirtualItem=this._virtualStart;var targetOffsetTop=0;var hiddenConten
tSize=this._hiddenContentSize;while(currentVirtualItem<idx&&targetOffsetTop<=hid
denContentSize){targetOffsetTop=targetOffsetTop+this._getPhysicalSizeIncrement(c
urrentTopItem);currentTopItem=(currentTopItem+1)%this._physicalCount;currentVirt
ualItem++}this._updateScrollerSize(true);this._positionItems();this._resetScroll
Position(this._physicalTop+this._scrollerPaddingTop+targetOffsetTop);this._incre
asePoolIfNeeded();this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null
},_resetAverage:function(){this._physicalAverage=0;this._physicalAverageCount=0}
,_resizeHandler:function(){var delta=Math.abs(this._viewportHeight-this._scrollT
argetHeight);if(IOS&&delta>0&&delta<100){return}Polymer.dom.addDebouncer(this.de
bounce("_debounceTemplate",function(){this.updateViewportBoundaries();this._rend
er();if(this._isVisible){this.toggleScrollListener(true);if(this._physicalCount>
0){this._resetAverage();this.scrollToIndex(this.firstVisibleIndex)}}else{this.to
ggleScrollListener(false)}}.bind(this),1))},_getModelFromItem:function(item){var
key=this._collection.getKey(item);var pidx=this._physicalIndexForKey[key];if(pi
dx!=null){return this._physicalItems[pidx]._templateInstance}return null},_getNo
rmalizedItem:function(item){if(this._collection.getKey(item)===undefined){if(typ
eof item==="number"){item=this.items[item];if(!item){throw new RangeError("<item
> not found")}return item}throw new TypeError("<item> should be a valid item")}r
eturn item},selectItem:function(item){item=this._getNormalizedItem(item);var mod
el=this._getModelFromItem(item);if(!this.multiSelection&&this.selectedItem){this
.deselectItem(this.selectedItem)}if(model){model[this.selectedAs]=true}this.$.se
lector.select(item);this.updateSizeForItem(item)},deselectItem:function(item){it
em=this._getNormalizedItem(item);var model=this._getModelFromItem(item);if(model
){model[this.selectedAs]=false}this.$.selector.deselect(item);this.updateSizeFor
Item(item)},toggleSelectionForItem:function(item){item=this._getNormalizedItem(i
tem);if(this.$.selector.isSelected(item)){this.deselectItem(item)}else{this.sele
ctItem(item)}},clearSelection:function(){function unselect(item){var model=this.
_getModelFromItem(item);if(model){model[this.selectedAs]=false}}if(Array.isArray
(this.selectedItems)){this.selectedItems.forEach(unselect,this)}else if(this.sel
ectedItem){unselect.call(this,this.selectedItem)}this.$.selector.clearSelection(
)},_selectionEnabledChanged:function(selectionEnabled){var handler=selectionEnab
led?this.listen:this.unlisten;handler.call(this,this,"tap","_selectionHandler")}
,_selectionHandler:function(e){var model=this.modelForElement(e.target);if(!mode
l){return}var modelTabIndex,activeElTabIndex;var target=Polymer.dom(e).path[0];v
ar activeEl=Polymer.dom(this.domHost?this.domHost.root:document).activeElement; | 746 get: function() { |
| 747 if (this.keyCode >= 48 && this.keyCode <= 57) |
| 748 return String.fromCharCode(this.keyCode); |
| 749 if (this.keyCode >= 65 && this.keyCode <= 90) { |
| 750 var result = String.fromCharCode(this.keyCode).toLowerCase(); |
| 751 if (this.shiftKey) |
| 752 result = result.toUpperCase(); |
| 753 return result |
| 754 } |
| 755 switch (this.keyCode) { |
| 756 case 8: |
| 757 return "Backspace"; |
| 758 case 9: |
| 759 return "Tab"; |
| 760 case 13: |
| 761 return "Enter"; |
| 762 case 16: |
| 763 return "Shift"; |
| 764 case 17: |
| 765 return "Control"; |
| 766 case 18: |
| 767 return "Alt"; |
| 768 case 27: |
| 769 return "Escape"; |
| 770 case 32: |
| 771 return " "; |
| 772 case 33: |
| 773 return "PageUp"; |
| 774 case 34: |
| 775 return "PageDown"; |
| 776 case 35: |
| 777 return "End"; |
| 778 case 36: |
| 779 return "Home"; |
| 780 case 37: |
| 781 return "ArrowLeft"; |
| 782 case 38: |
| 783 return "ArrowUp"; |
| 784 case 39: |
| 785 return "ArrowRight"; |
| 786 case 40: |
| 787 return "ArrowDown"; |
| 788 case 45: |
| 789 return "Insert"; |
| 790 case 46: |
| 791 return "Delete"; |
| 792 case 91: |
| 793 return "Meta"; |
| 794 case 112: |
| 795 return "F1"; |
| 796 case 113: |
| 797 return "F2"; |
| 798 case 114: |
| 799 return "F3"; |
| 800 case 115: |
| 801 return "F4"; |
| 802 case 116: |
| 803 return "F5"; |
| 804 case 117: |
| 805 return "F6"; |
| 806 case 118: |
| 807 return "F7"; |
| 808 case 119: |
| 809 return "F8"; |
| 810 case 120: |
| 811 return "F9"; |
| 812 case 121: |
| 813 return "F10"; |
| 814 case 122: |
| 815 return "F11"; |
| 816 case 123: |
| 817 return "F12"; |
| 818 case 187: |
| 819 return "="; |
| 820 case 189: |
| 821 return "-"; |
| 822 case 219: |
| 823 return "["; |
| 824 case 221: |
| 825 return "]" |
| 826 } |
| 827 return "Unidentified" |
| 828 } |
| 829 }) |
| 830 } else { |
| 831 window.console.log("KeyboardEvent.Key polyfill not required") |
| 832 } |
| 833 // /* </if> */ /* is_ios */ |
| 834 function importModules(moduleNames) { |
| 835 return new Promise(function(resolve) { |
| 836 define(moduleNames, function() { |
| 837 resolve(Array.from(arguments)) |
| 838 }) |
| 839 }) |
| 840 } |
| 841 function hasKeyModifiers(e) { |
| 842 return !!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) |
| 843 } |
| 844 Polymer.IronResizableBehavior = { |
| 845 properties: { |
| 846 _parentResizable: {type: Object, observer: "_parentResizableChanged"}, |
| 847 _notifyingDescendant: {type: Boolean, value: false} |
| 848 }, |
| 849 listeners: { |
| 850 "iron-request-resize-notifications": "_onIronRequestResizeNotifications" |
| 851 }, |
| 852 created: function() { |
| 853 this._interestedResizables = []; |
| 854 this._boundNotifyResize = this.notifyResize.bind(this) |
| 855 }, |
| 856 attached: function() { |
| 857 this.fire( |
| 858 "iron-request-resize-notifications", null, |
| 859 {node: this, bubbles: true, cancelable: true}); |
| 860 if (!this._parentResizable) { |
| 861 window.addEventListener("resize", this._boundNotifyResize); |
| 862 this.notifyResize() |
| 863 } |
| 864 }, |
| 865 detached: function() { |
| 866 if (this._parentResizable) { |
| 867 this._parentResizable.stopResizeNotificationsFor(this) |
| 868 } else { |
| 869 window.removeEventListener("resize", this._boundNotifyResize) |
| 870 } |
| 871 this._parentResizable = null |
| 872 }, |
| 873 notifyResize: function() { |
| 874 if (!this.isAttached) { |
| 875 return |
| 876 } |
| 877 this._interestedResizables.forEach(function(resizable) { |
| 878 if (this.resizerShouldNotify(resizable)) { |
| 879 this._notifyDescendant(resizable) |
| 880 } |
| 881 }, this); |
| 882 this._fireResize() |
| 883 }, |
| 884 assignParentResizable: function(parentResizable) { |
| 885 this._parentResizable = parentResizable |
| 886 }, |
| 887 stopResizeNotificationsFor: function(target) { |
| 888 var index = this._interestedResizables.indexOf(target); |
| 889 if (index > -1) { |
| 890 this._interestedResizables.splice(index, 1); |
| 891 this.unlisten(target, "iron-resize", "_onDescendantIronResize") |
| 892 } |
| 893 }, |
| 894 resizerShouldNotify: function(element) { |
| 895 return true |
| 896 }, |
| 897 _onDescendantIronResize: function(event) { |
| 898 if (this._notifyingDescendant) { |
| 899 event.stopPropagation(); |
| 900 return |
| 901 } |
| 902 if (!Polymer.Settings.useShadow) { |
| 903 this._fireResize() |
| 904 } |
| 905 }, |
| 906 _fireResize: function() { |
| 907 this.fire("iron-resize", null, {node: this, bubbles: false}) |
| 908 }, |
| 909 _onIronRequestResizeNotifications: function(event) { |
| 910 var target = event.path ? event.path[0] : event.target; |
| 911 if (target === this) { |
| 912 return |
| 913 } |
| 914 if (this._interestedResizables.indexOf(target) === -1) { |
| 915 this._interestedResizables.push(target); |
| 916 this.listen(target, "iron-resize", "_onDescendantIronResize") |
| 917 } |
| 918 target.assignParentResizable(this); |
| 919 this._notifyDescendant(target); |
| 920 event.stopPropagation() |
| 921 }, |
| 922 _parentResizableChanged: function(parentResizable) { |
| 923 if (parentResizable) { |
| 924 window.removeEventListener("resize", this._boundNotifyResize) |
| 925 } |
| 926 }, |
| 927 _notifyDescendant: function(descendant) { |
| 928 if (!this.isAttached) { |
| 929 return |
| 930 } |
| 931 this._notifyingDescendant = true; |
| 932 descendant.notifyResize(); |
| 933 this._notifyingDescendant = false |
| 934 } |
| 935 }; |
| 936 (function() { |
| 937 "use strict"; |
| 938 var KEY_IDENTIFIER = { |
| 939 "U+0008": "backspace", |
| 940 "U+0009": "tab", |
| 941 "U+001B": "esc", |
| 942 "U+0020": "space", |
| 943 "U+007F": "del" |
| 944 }; |
| 945 var KEY_CODE = { |
| 946 8: "backspace", |
| 947 9: "tab", |
| 948 13: "enter", |
| 949 27: "esc", |
| 950 33: "pageup", |
| 951 34: "pagedown", |
| 952 35: "end", |
| 953 36: "home", |
| 954 32: "space", |
| 955 37: "left", |
| 956 38: "up", |
| 957 39: "right", |
| 958 40: "down", |
| 959 46: "del", |
| 960 106: "*" |
| 961 }; |
| 962 var MODIFIER_KEYS = |
| 963 {shift: "shiftKey", ctrl: "ctrlKey", alt: "altKey", meta: "metaKey"}; |
| 964 var KEY_CHAR = /[a-z0-9*]/; |
| 965 var IDENT_CHAR = /U\+/; |
| 966 var ARROW_KEY = /^arrow/; |
| 967 var SPACE_KEY = /^space(bar)?/; |
| 968 var ESC_KEY = /^escape$/; |
| 969 function transformKey(key, noSpecialChars) { |
| 970 var validKey = ""; |
| 971 if (key) { |
| 972 var lKey = key.toLowerCase(); |
| 973 if (lKey === " " || SPACE_KEY.test(lKey)) { |
| 974 validKey = "space" |
| 975 } else if (ESC_KEY.test(lKey)) { |
| 976 validKey = "esc" |
| 977 } else if (lKey.length == 1) { |
| 978 if (!noSpecialChars || KEY_CHAR.test(lKey)) { |
| 979 validKey = lKey |
| 980 } |
| 981 } else if (ARROW_KEY.test(lKey)) { |
| 982 validKey = lKey.replace("arrow", "") |
| 983 } else if (lKey == "multiply") { |
| 984 validKey = "*" |
| 985 } else { |
| 986 validKey = lKey |
| 987 } |
| 988 } |
| 989 return validKey |
| 990 } |
| 991 function transformKeyIdentifier(keyIdent) { |
| 992 var validKey = ""; |
| 993 if (keyIdent) { |
| 994 if (keyIdent in KEY_IDENTIFIER) { |
| 995 validKey = KEY_IDENTIFIER[keyIdent] |
| 996 } else if (IDENT_CHAR.test(keyIdent)) { |
| 997 keyIdent = parseInt(keyIdent.replace("U+", "0x"), 16); |
| 998 validKey = String.fromCharCode(keyIdent).toLowerCase() |
| 999 } else { |
| 1000 validKey = keyIdent.toLowerCase() |
| 1001 } |
| 1002 } |
| 1003 return validKey |
| 1004 } |
| 1005 function transformKeyCode(keyCode) { |
| 1006 var validKey = ""; |
| 1007 if (Number(keyCode)) { |
| 1008 if (keyCode >= 65 && keyCode <= 90) { |
| 1009 validKey = String.fromCharCode(32 + keyCode) |
| 1010 } else if (keyCode >= 112 && keyCode <= 123) { |
| 1011 validKey = "f" + (keyCode - 112) |
| 1012 } else if (keyCode >= 48 && keyCode <= 57) { |
| 1013 validKey = String(keyCode - 48) |
| 1014 } else if (keyCode >= 96 && keyCode <= 105) { |
| 1015 validKey = String(keyCode - 96) |
| 1016 } else { |
| 1017 validKey = KEY_CODE[keyCode] |
| 1018 } |
| 1019 } |
| 1020 return validKey |
| 1021 } |
| 1022 function normalizedKeyForEvent(keyEvent, noSpecialChars) { |
| 1023 if (keyEvent.key) { |
| 1024 return transformKey(keyEvent.key, noSpecialChars) |
| 1025 } |
| 1026 if (keyEvent.detail && keyEvent.detail.key) { |
| 1027 return transformKey(keyEvent.detail.key, noSpecialChars) |
| 1028 } |
| 1029 return transformKeyIdentifier(keyEvent.keyIdentifier) || |
| 1030 transformKeyCode(keyEvent.keyCode) || "" |
| 1031 } |
| 1032 function keyComboMatchesEvent(keyCombo, event) { |
| 1033 var keyEvent = normalizedKeyForEvent(event, keyCombo.hasModifiers); |
| 1034 return keyEvent === keyCombo.key && |
| 1035 (!keyCombo.hasModifiers || |
| 1036 !!event.shiftKey === !!keyCombo.shiftKey && |
| 1037 !!event.ctrlKey === !!keyCombo.ctrlKey && |
| 1038 !!event.altKey === !!keyCombo.altKey && |
| 1039 !!event.metaKey === !!keyCombo.metaKey) |
| 1040 } |
| 1041 function parseKeyComboString(keyComboString) { |
| 1042 if (keyComboString.length === 1) { |
| 1043 return { |
| 1044 combo: keyComboString, key: keyComboString, event: "keydown" |
| 1045 } |
| 1046 } |
| 1047 return keyComboString.split("+") |
| 1048 .reduce(function(parsedKeyCombo, keyComboPart) { |
| 1049 var eventParts = keyComboPart.split(":"); |
| 1050 var keyName = eventParts[0]; |
| 1051 var event = eventParts[1]; |
| 1052 if (keyName in MODIFIER_KEYS) { |
| 1053 parsedKeyCombo[MODIFIER_KEYS[keyName]] = true; |
| 1054 parsedKeyCombo.hasModifiers = true |
| 1055 } else { |
| 1056 parsedKeyCombo.key = keyName; |
| 1057 parsedKeyCombo.event = event || "keydown" |
| 1058 } |
| 1059 return parsedKeyCombo |
| 1060 }, {combo: keyComboString.split(":").shift()}) |
| 1061 } |
| 1062 function parseEventString(eventString) { |
| 1063 return eventString.trim().split(" ").map(function(keyComboString) { |
| 1064 return parseKeyComboString(keyComboString) |
| 1065 }) |
| 1066 } |
| 1067 Polymer.IronA11yKeysBehavior = { |
| 1068 properties: { |
| 1069 keyEventTarget: { |
| 1070 type: Object, |
| 1071 value: function() { |
| 1072 return this |
| 1073 } |
| 1074 }, |
| 1075 stopKeyboardEventPropagation: {type: Boolean, value: false}, |
| 1076 _boundKeyHandlers: { |
| 1077 type: Array, |
| 1078 value: function() { |
| 1079 return [] |
| 1080 } |
| 1081 }, |
| 1082 _imperativeKeyBindings: { |
| 1083 type: Object, |
| 1084 value: function() { |
| 1085 return {} |
| 1086 } |
| 1087 } |
| 1088 }, |
| 1089 observers: ["_resetKeyEventListeners(keyEventTarget, _boundKeyHandlers)"], |
| 1090 keyBindings: {}, |
| 1091 registered: function() { |
| 1092 this._prepKeyBindings() |
| 1093 }, |
| 1094 attached: function() { |
| 1095 this._listenKeyEventListeners() |
| 1096 }, |
| 1097 detached: function() { |
| 1098 this._unlistenKeyEventListeners() |
| 1099 }, |
| 1100 addOwnKeyBinding: function(eventString, handlerName) { |
| 1101 this._imperativeKeyBindings[eventString] = handlerName; |
| 1102 this._prepKeyBindings(); |
| 1103 this._resetKeyEventListeners() |
| 1104 }, |
| 1105 removeOwnKeyBindings: function() { |
| 1106 this._imperativeKeyBindings = {}; |
| 1107 this._prepKeyBindings(); |
| 1108 this._resetKeyEventListeners() |
| 1109 }, |
| 1110 keyboardEventMatchesKeys: function(event, eventString) { |
| 1111 var keyCombos = parseEventString(eventString); |
| 1112 for (var i = 0; i < keyCombos.length; ++i) { |
| 1113 if (keyComboMatchesEvent(keyCombos[i], event)) { |
| 1114 return true |
| 1115 } |
| 1116 } |
| 1117 return false |
| 1118 }, |
| 1119 _collectKeyBindings: function() { |
| 1120 var keyBindings = this.behaviors.map(function(behavior) { |
| 1121 return behavior.keyBindings |
| 1122 }); |
| 1123 if (keyBindings.indexOf(this.keyBindings) === -1) { |
| 1124 keyBindings.push(this.keyBindings) |
| 1125 } |
| 1126 return keyBindings |
| 1127 }, |
| 1128 _prepKeyBindings: function() { |
| 1129 this._keyBindings = {}; |
| 1130 this._collectKeyBindings().forEach(function(keyBindings) { |
| 1131 for (var eventString in keyBindings) { |
| 1132 this._addKeyBinding(eventString, keyBindings[eventString]) |
| 1133 } |
| 1134 }, this); |
| 1135 for (var eventString in this._imperativeKeyBindings) { |
| 1136 this._addKeyBinding( |
| 1137 eventString, this._imperativeKeyBindings[eventString]) |
| 1138 } |
| 1139 for (var eventName in this._keyBindings) { |
| 1140 this._keyBindings[eventName].sort(function(kb1, kb2) { |
| 1141 var b1 = kb1[0].hasModifiers; |
| 1142 var b2 = kb2[0].hasModifiers; |
| 1143 return b1 === b2 ? 0 : b1 ? -1 : 1 |
| 1144 }) |
| 1145 } |
| 1146 }, |
| 1147 _addKeyBinding: function(eventString, handlerName) { |
| 1148 parseEventString(eventString).forEach(function(keyCombo) { |
| 1149 this._keyBindings[keyCombo.event] = |
| 1150 this._keyBindings[keyCombo.event] || []; |
| 1151 this._keyBindings[keyCombo.event].push([keyCombo, handlerName]) |
| 1152 }, this) |
| 1153 }, |
| 1154 _resetKeyEventListeners: function() { |
| 1155 this._unlistenKeyEventListeners(); |
| 1156 if (this.isAttached) { |
| 1157 this._listenKeyEventListeners() |
| 1158 } |
| 1159 }, |
| 1160 _listenKeyEventListeners: function() { |
| 1161 if (!this.keyEventTarget) { |
| 1162 return |
| 1163 } |
| 1164 Object.keys(this._keyBindings).forEach(function(eventName) { |
| 1165 var keyBindings = this._keyBindings[eventName]; |
| 1166 var boundKeyHandler = this._onKeyBindingEvent.bind(this, keyBindings); |
| 1167 this._boundKeyHandlers.push( |
| 1168 [this.keyEventTarget, eventName, boundKeyHandler]); |
| 1169 this.keyEventTarget.addEventListener(eventName, boundKeyHandler) |
| 1170 }, this) |
| 1171 }, |
| 1172 _unlistenKeyEventListeners: function() { |
| 1173 var keyHandlerTuple; |
| 1174 var keyEventTarget; |
| 1175 var eventName; |
| 1176 var boundKeyHandler; |
| 1177 while (this._boundKeyHandlers.length) { |
| 1178 keyHandlerTuple = this._boundKeyHandlers.pop(); |
| 1179 keyEventTarget = keyHandlerTuple[0]; |
| 1180 eventName = keyHandlerTuple[1]; |
| 1181 boundKeyHandler = keyHandlerTuple[2]; |
| 1182 keyEventTarget.removeEventListener(eventName, boundKeyHandler) |
| 1183 } |
| 1184 }, |
| 1185 _onKeyBindingEvent: function(keyBindings, event) { |
| 1186 if (this.stopKeyboardEventPropagation) { |
| 1187 event.stopPropagation() |
| 1188 } |
| 1189 if (event.defaultPrevented) { |
| 1190 return |
| 1191 } |
| 1192 for (var i = 0; i < keyBindings.length; i++) { |
| 1193 var keyCombo = keyBindings[i][0]; |
| 1194 var handlerName = keyBindings[i][1]; |
| 1195 if (keyComboMatchesEvent(keyCombo, event)) { |
| 1196 this._triggerKeyHandler(keyCombo, handlerName, event); |
| 1197 if (event.defaultPrevented) { |
| 1198 return |
| 1199 } |
| 1200 } |
| 1201 } |
| 1202 }, |
| 1203 _triggerKeyHandler: function(keyCombo, handlerName, keyboardEvent) { |
| 1204 var detail = Object.create(keyCombo); |
| 1205 detail.keyboardEvent = keyboardEvent; |
| 1206 var event = |
| 1207 new CustomEvent(keyCombo.event, {detail: detail, cancelable: true}); |
| 1208 this[handlerName].call(this, event); |
| 1209 if (event.defaultPrevented) { |
| 1210 keyboardEvent.preventDefault() |
| 1211 } |
| 1212 } |
| 1213 } |
| 1214 })(); |
| 1215 Polymer.IronScrollTargetBehavior = { |
| 1216 properties: { |
| 1217 scrollTarget: { |
| 1218 type: HTMLElement, |
| 1219 value: function() { |
| 1220 return this._defaultScrollTarget |
| 1221 } |
| 1222 } |
| 1223 }, |
| 1224 observers: ["_scrollTargetChanged(scrollTarget, isAttached)"], |
| 1225 _shouldHaveListener: true, |
| 1226 _scrollTargetChanged: function(scrollTarget, isAttached) { |
| 1227 var eventTarget; |
| 1228 if (this._oldScrollTarget) { |
| 1229 this._toggleScrollListener(false, this._oldScrollTarget); |
| 1230 this._oldScrollTarget = null |
| 1231 } |
| 1232 if (!isAttached) { |
| 1233 return |
| 1234 } |
| 1235 if (scrollTarget === "document") { |
| 1236 this.scrollTarget = this._doc |
| 1237 } else if (typeof scrollTarget === "string") { |
| 1238 this.scrollTarget = this.domHost ? |
| 1239 this.domHost.$[scrollTarget] : |
| 1240 Polymer.dom(this.ownerDocument).querySelector("#" + scrollTarget) |
| 1241 } else if (this._isValidScrollTarget()) { |
| 1242 this._boundScrollHandler = |
| 1243 this._boundScrollHandler || this._scrollHandler.bind(this); |
| 1244 this._oldScrollTarget = scrollTarget; |
| 1245 this._toggleScrollListener(this._shouldHaveListener, scrollTarget) |
| 1246 } |
| 1247 }, |
| 1248 _scrollHandler: function scrollHandler() {}, |
| 1249 get _defaultScrollTarget() { |
| 1250 return this._doc |
| 1251 }, |
| 1252 get _doc() { |
| 1253 return this.ownerDocument.documentElement |
| 1254 }, |
| 1255 get _scrollTop() { |
| 1256 if (this._isValidScrollTarget()) { |
| 1257 return this.scrollTarget === this._doc ? window.pageYOffset : |
| 1258 this.scrollTarget.scrollTop |
| 1259 } |
| 1260 return 0 |
| 1261 }, |
| 1262 get _scrollLeft() { |
| 1263 if (this._isValidScrollTarget()) { |
| 1264 return this.scrollTarget === this._doc ? window.pageXOffset : |
| 1265 this.scrollTarget.scrollLeft |
| 1266 } |
| 1267 return 0 |
| 1268 }, |
| 1269 set _scrollTop(top) { |
| 1270 if (this.scrollTarget === this._doc) { |
| 1271 window.scrollTo(window.pageXOffset, top) |
| 1272 } else if (this._isValidScrollTarget()) { |
| 1273 this.scrollTarget.scrollTop = top |
| 1274 } |
| 1275 }, |
| 1276 set _scrollLeft(left) { |
| 1277 if (this.scrollTarget === this._doc) { |
| 1278 window.scrollTo(left, window.pageYOffset) |
| 1279 } else if (this._isValidScrollTarget()) { |
| 1280 this.scrollTarget.scrollLeft = left |
| 1281 } |
| 1282 }, |
| 1283 scroll: function(left, top) { |
| 1284 if (this.scrollTarget === this._doc) { |
| 1285 window.scrollTo(left, top) |
| 1286 } else if (this._isValidScrollTarget()) { |
| 1287 this.scrollTarget.scrollLeft = left; |
| 1288 this.scrollTarget.scrollTop = top |
| 1289 } |
| 1290 }, |
| 1291 get _scrollTargetWidth() { |
| 1292 if (this._isValidScrollTarget()) { |
| 1293 return this.scrollTarget === this._doc ? window.innerWidth : |
| 1294 this.scrollTarget.offsetWidth |
| 1295 } |
| 1296 return 0 |
| 1297 }, |
| 1298 get _scrollTargetHeight() { |
| 1299 if (this._isValidScrollTarget()) { |
| 1300 return this.scrollTarget === this._doc ? window.innerHeight : |
| 1301 this.scrollTarget.offsetHeight |
| 1302 } |
| 1303 return 0 |
| 1304 }, |
| 1305 _isValidScrollTarget: function() { |
| 1306 return this.scrollTarget instanceof HTMLElement |
| 1307 }, |
| 1308 _toggleScrollListener: function(yes, scrollTarget) { |
| 1309 if (!this._boundScrollHandler) { |
| 1310 return |
| 1311 } |
| 1312 var eventTarget = scrollTarget === this._doc ? window : scrollTarget; |
| 1313 if (yes) { |
| 1314 eventTarget.addEventListener("scroll", this._boundScrollHandler) |
| 1315 } else { |
| 1316 eventTarget.removeEventListener("scroll", this._boundScrollHandler) |
| 1317 } |
| 1318 }, |
| 1319 toggleScrollListener: function(yes) { |
| 1320 this._shouldHaveListener = yes; |
| 1321 this._toggleScrollListener(yes, this.scrollTarget) |
| 1322 } |
| 1323 }; |
| 1324 (function() { |
| 1325 var IOS = navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/); |
| 1326 var IOS_TOUCH_SCROLLING = IOS && IOS[1] >= 8; |
| 1327 var DEFAULT_PHYSICAL_COUNT = 3; |
| 1328 var HIDDEN_Y = "-10000px"; |
| 1329 var ITEM_WIDTH = 0; |
| 1330 var ITEM_HEIGHT = 1; |
| 1331 var SECRET_TABINDEX = -100; |
| 1332 Polymer({is:"iron-list",properties:{items:{type:Array},maxPhysicalCount:{type:
Number,value:500},as:{type:String,value:"item"},indexAs:{type:String,value:"inde
x"},selectedAs:{type:String,value:"selected"},grid:{type:Boolean,value:false,ref
lectToAttribute:true},selectionEnabled:{type:Boolean,value:false},selectedItem:{
type:Object,notify:true},selectedItems:{type:Object,notify:true},multiSelection:
{type:Boolean,value:false}},observers:["_itemsChanged(items.*)","_selectionEnabl
edChanged(selectionEnabled)","_multiSelectionChanged(multiSelection)","_setOverf
low(scrollTarget)"],behaviors:[Polymer.Templatizer,Polymer.IronResizableBehavior
,Polymer.IronA11yKeysBehavior,Polymer.IronScrollTargetBehavior],keyBindings:{up:
"_didMoveUp",down:"_didMoveDown",enter:"_didEnter"},_ratio:.5,_scrollerPaddingTo
p:0,_scrollPosition:0,_physicalSize:0,_physicalAverage:0,_physicalAverageCount:0
,_physicalTop:0,_virtualCount:0,_physicalIndexForKey:null,_estScrollHeight:0,_sc
rollHeight:0,_viewportHeight:0,_viewportWidth:0,_physicalItems:null,_physicalSiz
es:null,_firstVisibleIndexVal:null,_lastVisibleIndexVal:null,_collection:null,_m
axPages:2,_focusedItem:null,_focusedIndex:-1,_offscreenFocusedItem:null,_focusBa
ckfillItem:null,_itemsPerRow:1,_itemWidth:0,_rowHeight:0,_templateCost:0,get _ph
ysicalBottom(){return this._physicalTop+this._physicalSize},get _scrollBottom(){
return this._scrollPosition+this._viewportHeight},get _virtualEnd(){return this.
_virtualStart+this._physicalCount-1},get _hiddenContentSize(){var size=this.grid
?this._physicalRows*this._rowHeight:this._physicalSize;return size-this._viewpor
tHeight},get _maxScrollTop(){return this._estScrollHeight-this._viewportHeight+t
his._scrollerPaddingTop},_minVirtualStart:0,get _maxVirtualStart(){return Math.m
ax(0,this._virtualCount-this._physicalCount)},_virtualStartVal:0,set _virtualSta
rt(val){this._virtualStartVal=Math.min(this._maxVirtualStart,Math.max(this._minV
irtualStart,val))},get _virtualStart(){return this._virtualStartVal||0},_physica
lStartVal:0,set _physicalStart(val){this._physicalStartVal=val%this._physicalCou
nt;if(this._physicalStartVal<0){this._physicalStartVal=this._physicalCount+this.
_physicalStartVal}this._physicalEnd=(this._physicalStart+this._physicalCount-1)%
this._physicalCount},get _physicalStart(){return this._physicalStartVal||0},_phy
sicalCountVal:0,set _physicalCount(val){this._physicalCountVal=val;this._physica
lEnd=(this._physicalStart+this._physicalCount-1)%this._physicalCount},get _physi
calCount(){return this._physicalCountVal},_physicalEnd:0,get _optPhysicalSize(){
if(this.grid){return this._estRowsInView*this._rowHeight*this._maxPages}return t
his._viewportHeight*this._maxPages},get _isVisible(){return Boolean(this.offsetW
idth||this.offsetHeight)},get firstVisibleIndex(){if(this._firstVisibleIndexVal=
==null){var physicalOffset=Math.floor(this._physicalTop+this._scrollerPaddingTop
);this._firstVisibleIndexVal=this._iterateItems(function(pidx,vidx){physicalOffs
et+=this._getPhysicalSizeIncrement(pidx);if(physicalOffset>this._scrollPosition)
{return this.grid?vidx-vidx%this._itemsPerRow:vidx}if(this.grid&&this._virtualCo
unt-1===vidx){return vidx-vidx%this._itemsPerRow}})||0}return this._firstVisible
IndexVal},get lastVisibleIndex(){if(this._lastVisibleIndexVal===null){if(this.gr
id){var lastIndex=this.firstVisibleIndex+this._estRowsInView*this._itemsPerRow-1
;this._lastVisibleIndexVal=Math.min(this._virtualCount,lastIndex)}else{var physi
calOffset=this._physicalTop;this._iterateItems(function(pidx,vidx){if(physicalOf
fset<this._scrollBottom){this._lastVisibleIndexVal=vidx}else{return true}physica
lOffset+=this._getPhysicalSizeIncrement(pidx)})}}return this._lastVisibleIndexVa
l},get _defaultScrollTarget(){return this},get _virtualRowCount(){return Math.ce
il(this._virtualCount/this._itemsPerRow)},get _estRowsInView(){return Math.ceil(
this._viewportHeight/this._rowHeight)},get _physicalRows(){return Math.ceil(this
._physicalCount/this._itemsPerRow)},ready:function(){this.addEventListener("focu
s",this._didFocus.bind(this),true)},attached:function(){if(this._physicalCount==
=0){this._debounceTemplate(this._render)}this.listen(this,"iron-resize","_resize
Handler")},detached:function(){this.unlisten(this,"iron-resize","_resizeHandler"
)},_setOverflow:function(scrollTarget){this.style.webkitOverflowScrolling=scroll
Target===this?"touch":"";this.style.overflow=scrollTarget===this?"auto":""},upda
teViewportBoundaries:function(){this._scrollerPaddingTop=this.scrollTarget===thi
s?0:parseInt(window.getComputedStyle(this)["padding-top"],10);this._viewportWidt
h=this.$.items.offsetWidth;this._viewportHeight=this._scrollTargetHeight;this.gr
id&&this._updateGridMetrics()},_scrollHandler:function(){var scrollTop=Math.max(
0,Math.min(this._maxScrollTop,this._scrollTop));var delta=scrollTop-this._scroll
Position;var isScrollingDown=delta>=0;this._scrollPosition=scrollTop;this._first
VisibleIndexVal=null;this._lastVisibleIndexVal=null;if(Math.abs(delta)>this._phy
sicalSize){var idxAdjustment=Math.round(delta/this._physicalAverage)*this._items
PerRow;this._physicalTop=this._physicalTop+delta;this._virtualStart=this._virtua
lStart+idxAdjustment;this._physicalStart=this._physicalStart+idxAdjustment;this.
_update()}else{var reusables=this._getReusables(isScrollingDown);if(isScrollingD
own){this._physicalTop=reusables.physicalTop;this._virtualStart=this._virtualSta
rt+reusables.indexes.length;this._physicalStart=this._physicalStart+reusables.in
dexes.length}else{this._virtualStart=this._virtualStart-reusables.indexes.length
;this._physicalStart=this._physicalStart-reusables.indexes.length}if(reusables.i
ndexes.length===0){this._increasePoolIfNeeded()}else{this._update(reusables.inde
xes,isScrollingDown?null:reusables.indexes)}}},_getReusables:function(fromTop){v
ar ith,lastIth,offsetContent,physicalItemHeight;var idxs=[];var protectedOffsetC
ontent=this._hiddenContentSize*this._ratio;var virtualStart=this._virtualStart;v
ar virtualEnd=this._virtualEnd;var physicalCount=this._physicalCount;var physica
lTop=this._physicalTop+this._scrollerPaddingTop;var scrollTop=this._scrollTop;va
r scrollBottom=this._scrollBottom;if(fromTop){ith=this._physicalStart;lastIth=th
is._physicalEnd;offsetContent=scrollTop-physicalTop}else{ith=this._physicalEnd;l
astIth=this._physicalStart;offsetContent=this._physicalBottom-scrollBottom}while
(true){physicalItemHeight=this._getPhysicalSizeIncrement(ith);offsetContent=offs
etContent-physicalItemHeight;if(idxs.length>=physicalCount||offsetContent<=prote
ctedOffsetContent){break}if(fromTop){if(virtualEnd+idxs.length+1>=this._virtualC
ount){break}if(physicalTop+physicalItemHeight>=scrollTop){break}idxs.push(ith);p
hysicalTop=physicalTop+physicalItemHeight;ith=(ith+1)%physicalCount}else{if(virt
ualStart-idxs.length<=0){break}if(physicalTop+this._physicalSize-physicalItemHei
ght<=scrollBottom){break}idxs.push(ith);physicalTop=physicalTop-physicalItemHeig
ht;ith=ith===0?physicalCount-1:ith-1}}return{indexes:idxs,physicalTop:physicalTo
p-this._scrollerPaddingTop}},_update:function(itemSet,movingUp){if(itemSet&&item
Set.length===0){return}this._manageFocus();this._assignModels(itemSet);this._upd
ateMetrics(itemSet);if(movingUp){while(movingUp.length){var idx=movingUp.pop();t
his._physicalTop-=this._getPhysicalSizeIncrement(idx)}}this._positionItems();thi
s._updateScrollerSize();this._increasePoolIfNeeded()},_createPool:function(size)
{var physicalItems=new Array(size);this._ensureTemplatized();for(var i=0;i<size;
i++){var inst=this.stamp(null);physicalItems[i]=inst.root.querySelector("*");Pol
ymer.dom(this).appendChild(inst.root)}return physicalItems},_increasePoolIfNeede
d:function(){if(this._viewportHeight===0){return false}var self=this;var isClien
tFull=this._physicalBottom>=this._scrollBottom&&this._physicalTop<=this._scrollP
osition;if(this._physicalSize>=this._optPhysicalSize&&isClientFull){return false
}var maxPoolSize=Math.round(this._physicalCount*.5);if(!isClientFull){this._debo
unceTemplate(this._increasePool.bind(this,maxPoolSize));return true}this._yield(
function(){self._increasePool(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.ad
dDebouncer({complete:function(){g.cancelIdleCallback?g.cancelIdleCallback(handle
):g.clearTimeout(handle);cb()}})},_increasePool:function(missingItems){var nextP
hysicalCount=Math.min(this._physicalCount+missingItems,this._virtualCount-this._
virtualStart,Math.max(this.maxPhysicalCount,DEFAULT_PHYSICAL_COUNT));var prevPhy
sicalCount=this._physicalCount;var delta=nextPhysicalCount-prevPhysicalCount;var
ts=window.performance.now();if(delta<=0){return}[].push.apply(this._physicalIte
ms,this._createPool(delta));[].push.apply(this._physicalSizes,new Array(delta));
this._physicalCount=prevPhysicalCount+delta;if(this._physicalStart>this._physica
lEnd&&this._isIndexRendered(this._focusedIndex)&&this._getPhysicalIndex(this._fo
cusedIndex)<this._physicalEnd){this._physicalStart=this._physicalStart+delta}thi
s._update();this._templateCost=(window.performance.now()-ts)/delta},_render:func
tion(){if(this.isAttached&&this._isVisible){if(this._physicalCount===0){this.upd
ateViewportBoundaries();this._increasePool(DEFAULT_PHYSICAL_COUNT)}else{var reus
ables=this._getReusables(true);this._physicalTop=reusables.physicalTop;this._vir
tualStart=this._virtualStart+reusables.indexes.length;this._physicalStart=this._
physicalStart+reusables.indexes.length;this._update(reusables.indexes);this._upd
ate()}}},_ensureTemplatized:function(){if(!this.ctor){var props={};props.__key__
=true;props[this.as]=true;props[this.indexAs]=true;props[this.selectedAs]=true;p
rops.tabIndex=true;this._instanceProps=props;this._userTemplate=Polymer.dom(this
).querySelector("template");if(this._userTemplate){this.templatize(this._userTem
plate)}else{console.warn("iron-list requires a template to be provided in light-
dom")}}},_getStampedChildren:function(){return this._physicalItems},_forwardInst
ancePath:function(inst,path,value){if(path.indexOf(this.as+".")===0){this.notify
Path("items."+inst.__key__+"."+path.slice(this.as.length+1),value)}},_forwardPar
entProp:function(prop,value){if(this._physicalItems){this._physicalItems.forEach
(function(item){item._templateInstance[prop]=value},this)}},_forwardParentPath:f
unction(path,value){if(this._physicalItems){this._physicalItems.forEach(function
(item){item._templateInstance.notifyPath(path,value,true)},this)}},_forwardItemP
ath:function(path,value){if(!this._physicalIndexForKey){return}var dot=path.inde
xOf(".");var key=path.substring(0,dot<0?path.length:dot);var idx=this._physicalI
ndexForKey[key];var offscreenItem=this._offscreenFocusedItem;var el=offscreenIte
m&&offscreenItem._templateInstance.__key__===key?offscreenItem:this._physicalIte
ms[idx];if(!el||el._templateInstance.__key__!==key){return}if(dot>=0){path=this.
as+"."+path.substring(dot+1);el._templateInstance.notifyPath(path,value,true)}el
se{var currentItem=el._templateInstance[this.as];if(Array.isArray(this.selectedI
tems)){for(var i=0;i<this.selectedItems.length;i++){if(this.selectedItems[i]===c
urrentItem){this.set("selectedItems."+i,value);break}}}else if(this.selectedItem
===currentItem){this.set("selectedItem",value)}el._templateInstance[this.as]=val
ue}},_itemsChanged:function(change){if(change.path==="items"){this._virtualStart
=0;this._physicalTop=0;this._virtualCount=this.items?this.items.length:0;this._c
ollection=this.items?Polymer.Collection.get(this.items):null;this._physicalIndex
ForKey={};this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null;this._p
hysicalCount=this._physicalCount||0;this._physicalItems=this._physicalItems||[];
this._physicalSizes=this._physicalSizes||[];this._physicalStart=0;this._resetScr
ollPosition(0);this._removeFocusedItem();this._debounceTemplate(this._render)}el
se if(change.path==="items.splices"){this._adjustVirtualIndex(change.value.index
Splices);this._virtualCount=this.items?this.items.length:0;this._debounceTemplat
e(this._render)}else{this._forwardItemPath(change.path.split(".").slice(1).join(
"."),change.value)}},_adjustVirtualIndex:function(splices){splices.forEach(funct
ion(splice){splice.removed.forEach(this._removeItem,this);if(splice.index<this._
virtualStart){var delta=Math.max(splice.addedCount-splice.removed.length,splice.
index-this._virtualStart);this._virtualStart=this._virtualStart+delta;if(this._f
ocusedIndex>=0){this._focusedIndex=this._focusedIndex+delta}}},this)},_removeIte
m:function(item){this.$.selector.deselect(item);if(this._focusedItem&&this._focu
sedItem._templateInstance[this.as]===item){this._removeFocusedItem()}},_iterateI
tems:function(fn,itemSet){var pidx,vidx,rtn,i;if(arguments.length===2&&itemSet){
for(i=0;i<itemSet.length;i++){pidx=itemSet[i];vidx=this._computeVidx(pidx);if((r
tn=fn.call(this,pidx,vidx))!=null){return rtn}}}else{pidx=this._physicalStart;vi
dx=this._virtualStart;for(;pidx<this._physicalCount;pidx++,vidx++){if((rtn=fn.ca
ll(this,pidx,vidx))!=null){return rtn}}for(pidx=0;pidx<this._physicalStart;pidx+
+,vidx++){if((rtn=fn.call(this,pidx,vidx))!=null){return rtn}}}},_computeVidx:fu
nction(pidx){if(pidx>=this._physicalStart){return this._virtualStart+(pidx-this.
_physicalStart)}return this._virtualStart+(this._physicalCount-this._physicalSta
rt)+pidx},_assignModels:function(itemSet){this._iterateItems(function(pidx,vidx)
{var el=this._physicalItems[pidx];var inst=el._templateInstance;var item=this.it
ems&&this.items[vidx];if(item!=null){inst[this.as]=item;inst.__key__=this._colle
ction.getKey(item);inst[this.selectedAs]=this.$.selector.isSelected(item);inst[t
his.indexAs]=vidx;inst.tabIndex=this._focusedIndex===vidx?0:-1;this._physicalInd
exForKey[inst.__key__]=pidx;el.removeAttribute("hidden")}else{inst.__key__=null;
el.setAttribute("hidden","")}},itemSet)},_updateMetrics:function(itemSet){Polyme
r.dom.flush();var newPhysicalSize=0;var oldPhysicalSize=0;var prevAvgCount=this.
_physicalAverageCount;var prevPhysicalAvg=this._physicalAverage;this._iterateIte
ms(function(pidx,vidx){oldPhysicalSize+=this._physicalSizes[pidx]||0;this._physi
calSizes[pidx]=this._physicalItems[pidx].offsetHeight;newPhysicalSize+=this._phy
sicalSizes[pidx];this._physicalAverageCount+=this._physicalSizes[pidx]?1:0},item
Set);if(this.grid){this._updateGridMetrics();this._physicalSize=Math.ceil(this._
physicalCount/this._itemsPerRow)*this._rowHeight}else{this._physicalSize=this._p
hysicalSize+newPhysicalSize-oldPhysicalSize}if(this._physicalAverageCount!==prev
AvgCount){this._physicalAverage=Math.round((prevPhysicalAvg*prevAvgCount+newPhys
icalSize)/this._physicalAverageCount)}},_updateGridMetrics:function(){this._item
Width=this._physicalCount>0?this._physicalItems[0].getBoundingClientRect().width
:200;this._rowHeight=this._physicalCount>0?this._physicalItems[0].offsetHeight:2
00;this._itemsPerRow=this._itemWidth?Math.floor(this._viewportWidth/this._itemWi
dth):this._itemsPerRow},_positionItems:function(){this._adjustScrollPosition();v
ar y=this._physicalTop;if(this.grid){var totalItemWidth=this._itemsPerRow*this._
itemWidth;var rowOffset=(this._viewportWidth-totalItemWidth)/2;this._iterateItem
s(function(pidx,vidx){var modulus=vidx%this._itemsPerRow;var x=Math.floor(modulu
s*this._itemWidth+rowOffset);this.translate3d(x+"px",y+"px",0,this._physicalItem
s[pidx]);if(this._shouldRenderNextRow(vidx)){y+=this._rowHeight}})}else{this._it
erateItems(function(pidx,vidx){this.translate3d(0,y+"px",0,this._physicalItems[p
idx]);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},_shouldRend
erNextRow:function(vidx){return vidx%this._itemsPerRow===this._itemsPerRow-1},_a
djustScrollPosition:function(){var deltaHeight=this._virtualStart===0?this._phys
icalTop:Math.min(this._scrollPosition+this._physicalTop,0);if(deltaHeight){this.
_physicalTop=this._physicalTop-deltaHeight;if(!IOS_TOUCH_SCROLLING&&this._physic
alTop!==0){this._resetScrollPosition(this._scrollTop-deltaHeight)}}},_resetScrol
lPosition:function(pos){if(this.scrollTarget){this._scrollTop=pos;this._scrollPo
sition=this._scrollTop}},_updateScrollerSize:function(forceUpdate){if(this.grid)
{this._estScrollHeight=this._virtualRowCount*this._rowHeight}else{this._estScrol
lHeight=this._physicalBottom+Math.max(this._virtualCount-this._physicalCount-thi
s._virtualStart,0)*this._physicalAverage}forceUpdate=forceUpdate||this._scrollHe
ight===0;forceUpdate=forceUpdate||this._scrollPosition>=this._estScrollHeight-th
is._physicalSize;forceUpdate=forceUpdate||this.grid&&this.$.items.style.height<t
his._estScrollHeight;if(forceUpdate||Math.abs(this._estScrollHeight-this._scroll
Height)>=this._optPhysicalSize){this.$.items.style.height=this._estScrollHeight+
"px";this._scrollHeight=this._estScrollHeight}},scrollToItem:function(item){retu
rn this.scrollToIndex(this.items.indexOf(item))},scrollToIndex:function(idx){if(
typeof idx!=="number"||idx<0||idx>this.items.length-1){return}Polymer.dom.flush(
);if(this._physicalCount===0){return}idx=Math.min(Math.max(idx,0),this._virtualC
ount-1);if(!this._isIndexRendered(idx)||idx>=this._maxVirtualStart){this._virtua
lStart=this.grid?idx-this._itemsPerRow*2:idx-1}this._manageFocus();this._assignM
odels();this._updateMetrics();this._physicalTop=Math.floor(this._virtualStart/th
is._itemsPerRow)*this._physicalAverage;var currentTopItem=this._physicalStart;va
r currentVirtualItem=this._virtualStart;var targetOffsetTop=0;var hiddenContentS
ize=this._hiddenContentSize;while(currentVirtualItem<idx&&targetOffsetTop<=hidde
nContentSize){targetOffsetTop=targetOffsetTop+this._getPhysicalSizeIncrement(cur
rentTopItem);currentTopItem=(currentTopItem+1)%this._physicalCount;currentVirtua
lItem++}this._updateScrollerSize(true);this._positionItems();this._resetScrollPo
sition(this._physicalTop+this._scrollerPaddingTop+targetOffsetTop);this._increas
ePoolIfNeeded();this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null},
_resetAverage:function(){this._physicalAverage=0;this._physicalAverageCount=0},_
resizeHandler:function(){var delta=Math.abs(this._viewportHeight-this._scrollTar
getHeight);if(IOS&&delta>0&&delta<100){return}Polymer.dom.addDebouncer(this.debo
unce("_debounceTemplate",function(){this.updateViewportBoundaries();this._render
();if(this._isVisible){this.toggleScrollListener(true);if(this._physicalCount>0)
{this._resetAverage();this.scrollToIndex(this.firstVisibleIndex)}}else{this.togg
leScrollListener(false)}}.bind(this),1))},_getModelFromItem:function(item){var k
ey=this._collection.getKey(item);var pidx=this._physicalIndexForKey[key];if(pidx
!=null){return this._physicalItems[pidx]._templateInstance}return null},_getNorm
alizedItem:function(item){if(this._collection.getKey(item)===undefined){if(typeo
f item==="number"){item=this.items[item];if(!item){throw new RangeError("<item>
not found")}return item}throw new TypeError("<item> should be a valid item")}ret
urn item},selectItem:function(item){item=this._getNormalizedItem(item);var model
=this._getModelFromItem(item);if(!this.multiSelection&&this.selectedItem){this.d
eselectItem(this.selectedItem)}if(model){model[this.selectedAs]=true}this.$.sele
ctor.select(item);this.updateSizeForItem(item)},deselectItem:function(item){item
=this._getNormalizedItem(item);var model=this._getModelFromItem(item);if(model){
model[this.selectedAs]=false}this.$.selector.deselect(item);this.updateSizeForIt
em(item)},toggleSelectionForItem:function(item){item=this._getNormalizedItem(ite
m);if(this.$.selector.isSelected(item)){this.deselectItem(item)}else{this.select
Item(item)}},clearSelection:function(){function unselect(item){var model=this._g
etModelFromItem(item);if(model){model[this.selectedAs]=false}}if(Array.isArray(t
his.selectedItems)){this.selectedItems.forEach(unselect,this)}else if(this.selec
tedItem){unselect.call(this,this.selectedItem)}this.$.selector.clearSelection()}
,_selectionEnabledChanged:function(selectionEnabled){var handler=selectionEnable
d?this.listen:this.unlisten;handler.call(this,this,"tap","_selectionHandler")},_
selectionHandler:function(e){var model=this.modelForElement(e.target);if(!model)
{return}var modelTabIndex,activeElTabIndex;var target=Polymer.dom(e).path[0];var
activeEl=Polymer.dom(this.domHost?this.domHost.root:document).activeElement; |
| 29 | 1333 |
| 30 var physicalItem=this._physicalItems[this._getPhysicalIndex(model[this.indexAs])
];if(target.localName==="input"||target.localName==="button"||target.localName==
="select"){return}modelTabIndex=model.tabIndex;model.tabIndex=SECRET_TABINDEX;ac
tiveElTabIndex=activeEl?activeEl.tabIndex:-1;model.tabIndex=modelTabIndex;if(act
iveEl&&physicalItem!==activeEl&&physicalItem.contains(activeEl)&&activeElTabInde
x!==SECRET_TABINDEX){return}this.toggleSelectionForItem(model[this.as])},_multiS
electionChanged:function(multiSelection){this.clearSelection();this.$.selector.m
ulti=multiSelection},updateSizeForItem:function(item){item=this._getNormalizedIt
em(item);var key=this._collection.getKey(item);var pidx=this._physicalIndexForKe
y[key];if(pidx!=null){this._updateMetrics([pidx]);this._positionItems()}},_manag
eFocus:function(){var fidx=this._focusedIndex;if(fidx>=0&&fidx<this._virtualCoun
t){if(this._isIndexRendered(fidx)){this._restoreFocusedItem()}else{this._createF
ocusBackfillItem()}}else if(this._virtualCount>0&&this._physicalCount>0){this._f
ocusedIndex=this._virtualStart;this._focusedItem=this._physicalItems[this._physi
calStart]}},_isIndexRendered:function(idx){return idx>=this._virtualStart&&idx<=
this._virtualEnd},_isIndexVisible:function(idx){return idx>=this.firstVisibleInd
ex&&idx<=this.lastVisibleIndex},_getPhysicalIndex:function(idx){return this._phy
sicalIndexForKey[this._collection.getKey(this._getNormalizedItem(idx))]},_focusP
hysicalItem:function(idx){if(idx<0||idx>=this._virtualCount){return}this._restor
eFocusedItem();if(!this._isIndexRendered(idx)){this.scrollToIndex(idx)}var physi
calItem=this._physicalItems[this._getPhysicalIndex(idx)];var model=physicalItem.
_templateInstance;var focusable;model.tabIndex=SECRET_TABINDEX;if(physicalItem.t
abIndex===SECRET_TABINDEX){focusable=physicalItem}if(!focusable){focusable=Polym
er.dom(physicalItem).querySelector('[tabindex="'+SECRET_TABINDEX+'"]')}model.tab
Index=0;this._focusedIndex=idx;focusable&&focusable.focus()},_removeFocusedItem:
function(){if(this._offscreenFocusedItem){Polymer.dom(this).removeChild(this._of
fscreenFocusedItem)}this._offscreenFocusedItem=null;this._focusBackfillItem=null
;this._focusedItem=null;this._focusedIndex=-1},_createFocusBackfillItem:function
(){var fidx=this._focusedIndex;var pidx=this._getPhysicalIndex(fidx);if(this._of
fscreenFocusedItem||pidx==null||fidx<0){return}if(!this._focusBackfillItem){var
stampedTemplate=this.stamp(null);this._focusBackfillItem=stampedTemplate.root.qu
erySelector("*");Polymer.dom(this).appendChild(stampedTemplate.root)}this._offsc
reenFocusedItem=this._physicalItems[pidx];this._offscreenFocusedItem._templateIn
stance.tabIndex=0;this._physicalItems[pidx]=this._focusBackfillItem;this.transla
te3d(0,HIDDEN_Y,0,this._offscreenFocusedItem)},_restoreFocusedItem:function(){va
r pidx,fidx=this._focusedIndex;if(!this._offscreenFocusedItem||this._focusedInde
x<0){return}this._assignModels();pidx=this._getPhysicalIndex(fidx);if(pidx!=null
){this._focusBackfillItem=this._physicalItems[pidx];this._focusBackfillItem._tem
plateInstance.tabIndex=-1;this._physicalItems[pidx]=this._offscreenFocusedItem;t
his._offscreenFocusedItem=null;this.translate3d(0,HIDDEN_Y,0,this._focusBackfill
Item)}},_didFocus:function(e){var targetModel=this.modelForElement(e.target);var
focusedModel=this._focusedItem?this._focusedItem._templateInstance:null;var has
OffscreenFocusedItem=this._offscreenFocusedItem!==null;var fidx=this._focusedInd
ex;if(!targetModel||!focusedModel){return}if(focusedModel===targetModel){if(!thi
s._isIndexVisible(fidx)){this.scrollToIndex(fidx)}}else{this._restoreFocusedItem
();focusedModel.tabIndex=-1;targetModel.tabIndex=0;fidx=targetModel[this.indexAs
];this._focusedIndex=fidx;this._focusedItem=this._physicalItems[this._getPhysica
lIndex(fidx)];if(hasOffscreenFocusedItem&&!this._offscreenFocusedItem){this._upd
ate()}}},_didMoveUp:function(){this._focusPhysicalItem(this._focusedIndex-1)},_d
idMoveDown:function(e){e.detail.keyboardEvent.preventDefault();this._focusPhysic
alItem(this._focusedIndex+1)},_didEnter:function(e){this._focusPhysicalItem(this
._focusedIndex);this._selectionHandler(e.detail.keyboardEvent)}})})(); | 1334 var physicalItem=this._physicalItems[this._getPhysicalIndex(model[this.indexAs])
];if(target.localName==="input"||target.localName==="button"||target.localName==
="select"){return}modelTabIndex=model.tabIndex;model.tabIndex=SECRET_TABINDEX;ac
tiveElTabIndex=activeEl?activeEl.tabIndex:-1;model.tabIndex=modelTabIndex;if(act
iveEl&&physicalItem!==activeEl&&physicalItem.contains(activeEl)&&activeElTabInde
x!==SECRET_TABINDEX){return}this.toggleSelectionForItem(model[this.as])},_multiS
electionChanged:function(multiSelection){this.clearSelection();this.$.selector.m
ulti=multiSelection},updateSizeForItem:function(item){item=this._getNormalizedIt
em(item);var key=this._collection.getKey(item);var pidx=this._physicalIndexForKe
y[key];if(pidx!=null){this._updateMetrics([pidx]);this._positionItems()}},_manag
eFocus:function(){var fidx=this._focusedIndex;if(fidx>=0&&fidx<this._virtualCoun
t){if(this._isIndexRendered(fidx)){this._restoreFocusedItem()}else{this._createF
ocusBackfillItem()}}else if(this._virtualCount>0&&this._physicalCount>0){this._f
ocusedIndex=this._virtualStart;this._focusedItem=this._physicalItems[this._physi
calStart]}},_isIndexRendered:function(idx){return idx>=this._virtualStart&&idx<=
this._virtualEnd},_isIndexVisible:function(idx){return idx>=this.firstVisibleInd
ex&&idx<=this.lastVisibleIndex},_getPhysicalIndex:function(idx){return this._phy
sicalIndexForKey[this._collection.getKey(this._getNormalizedItem(idx))]},_focusP
hysicalItem:function(idx){if(idx<0||idx>=this._virtualCount){return}this._restor
eFocusedItem();if(!this._isIndexRendered(idx)){this.scrollToIndex(idx)}var physi
calItem=this._physicalItems[this._getPhysicalIndex(idx)];var model=physicalItem.
_templateInstance;var focusable;model.tabIndex=SECRET_TABINDEX;if(physicalItem.t
abIndex===SECRET_TABINDEX){focusable=physicalItem}if(!focusable){focusable=Polym
er.dom(physicalItem).querySelector('[tabindex="'+SECRET_TABINDEX+'"]')}model.tab
Index=0;this._focusedIndex=idx;focusable&&focusable.focus()},_removeFocusedItem:
function(){if(this._offscreenFocusedItem){Polymer.dom(this).removeChild(this._of
fscreenFocusedItem)}this._offscreenFocusedItem=null;this._focusBackfillItem=null
;this._focusedItem=null;this._focusedIndex=-1},_createFocusBackfillItem:function
(){var fidx=this._focusedIndex;var pidx=this._getPhysicalIndex(fidx);if(this._of
fscreenFocusedItem||pidx==null||fidx<0){return}if(!this._focusBackfillItem){var
stampedTemplate=this.stamp(null);this._focusBackfillItem=stampedTemplate.root.qu
erySelector("*");Polymer.dom(this).appendChild(stampedTemplate.root)}this._offsc
reenFocusedItem=this._physicalItems[pidx];this._offscreenFocusedItem._templateIn
stance.tabIndex=0;this._physicalItems[pidx]=this._focusBackfillItem;this.transla
te3d(0,HIDDEN_Y,0,this._offscreenFocusedItem)},_restoreFocusedItem:function(){va
r pidx,fidx=this._focusedIndex;if(!this._offscreenFocusedItem||this._focusedInde
x<0){return}this._assignModels();pidx=this._getPhysicalIndex(fidx);if(pidx!=null
){this._focusBackfillItem=this._physicalItems[pidx];this._focusBackfillItem._tem
plateInstance.tabIndex=-1;this._physicalItems[pidx]=this._offscreenFocusedItem;t
his._offscreenFocusedItem=null;this.translate3d(0,HIDDEN_Y,0,this._focusBackfill
Item)}},_didFocus:function(e){var targetModel=this.modelForElement(e.target);var
focusedModel=this._focusedItem?this._focusedItem._templateInstance:null;var has
OffscreenFocusedItem=this._offscreenFocusedItem!==null;var fidx=this._focusedInd
ex;if(!targetModel||!focusedModel){return}if(focusedModel===targetModel){if(!thi
s._isIndexVisible(fidx)){this.scrollToIndex(fidx)}}else{this._restoreFocusedItem
();focusedModel.tabIndex=-1;targetModel.tabIndex=0;fidx=targetModel[this.indexAs
];this._focusedIndex=fidx;this._focusedItem=this._physicalItems[this._getPhysica
lIndex(fidx)];if(hasOffscreenFocusedItem&&!this._offscreenFocusedItem){this._upd
ate()}}},_didMoveUp:function(){this._focusPhysicalItem(this._focusedIndex-1)},_d
idMoveDown:function(e){e.detail.keyboardEvent.preventDefault();this._focusPhysic
alItem(this._focusedIndex+1)},_didEnter:function(e){this._focusPhysicalItem(this
._focusedIndex);this._selectionHandler(e.detail.keyboardEvent)}}) |
| 1335 })(); |
| 31 // Copyright 2015 The Chromium Authors. All rights reserved. | 1336 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 32 // Use of this source code is governed by a BSD-style license that can be | 1337 // Use of this source code is governed by a BSD-style license that can be |
| 33 // found in the LICENSE file. | 1338 // found in the LICENSE file. |
| 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:function(){chro
me.send("openDownloadsFolderRequiringGesture")},openFile:chromeSendWithId("openF
ileRequiringGesture"),pause:chromeSendWithId("pause"),remove:chromeSendWithId("r
emove"),resume:chromeSendWithId("resume"),saveDangerous:chromeSendWithId("saveDa
ngerousRequiringGesture"),search:function(searchText){var searchTerms=ActionServ
ice.splitTerms(searchText);var sameTerms=searchTerms.length==this.searchTerms_.l
ength;for(var i=0;sameTerms&&i<searchTerms.length;++i){if(searchTerms[i]!=this.s
earchTerms_[i])sameTerms=false}if(sameTerms)return false;this.searchTerms_=searc
hTerms;this.loadMore();return true},show:chromeSendWithId("show"),undo:chrome.se
nd.bind(chrome,"undo")};cr.addSingletonGetter(ActionService);return{ActionServic
e:ActionService}}); | 1339 cr.define("downloads", function() { |
| 1340 function chromeSendWithId(chromeSendName) { |
| 1341 return function(id) { |
| 1342 chrome.send(chromeSendName, [id]) |
| 1343 } |
| 1344 } |
| 1345 function ActionService() { |
| 1346 this.searchTerms_ = [] |
| 1347 } |
| 1348 function trim(s) { |
| 1349 return s.trim() |
| 1350 } |
| 1351 function truthy(value) { |
| 1352 return !!value |
| 1353 } |
| 1354 ActionService.splitTerms = function(searchText) { |
| 1355 return searchText.split(/"([^"]*)"/).map(trim).filter(truthy) |
| 1356 }; |
| 1357 ActionService.prototype = { |
| 1358 cancel: chromeSendWithId("cancel"), |
| 1359 clearAll: function() { |
| 1360 if (loadTimeData.getBoolean("allowDeletingHistory")) { |
| 1361 chrome.send("clearAll"); |
| 1362 this.search("") |
| 1363 } |
| 1364 }, |
| 1365 discardDangerous: chromeSendWithId("discardDangerous"), |
| 1366 download: function(url) { |
| 1367 var a = document.createElement("a"); |
| 1368 a.href = url; |
| 1369 a.setAttribute("download", ""); |
| 1370 a.click() |
| 1371 }, |
| 1372 drag: chromeSendWithId("drag"), |
| 1373 loadMore: function() { |
| 1374 chrome.send("getDownloads", this.searchTerms_) |
| 1375 }, |
| 1376 isSearching: function() { |
| 1377 return this.searchTerms_.length > 0 |
| 1378 }, |
| 1379 openDownloadsFolder: function() { |
| 1380 chrome.send("openDownloadsFolderRequiringGesture") |
| 1381 }, |
| 1382 openFile: chromeSendWithId("openFileRequiringGesture"), |
| 1383 pause: chromeSendWithId("pause"), |
| 1384 remove: chromeSendWithId("remove"), |
| 1385 resume: chromeSendWithId("resume"), |
| 1386 saveDangerous: chromeSendWithId("saveDangerousRequiringGesture"), |
| 1387 search: function(searchText) { |
| 1388 var searchTerms = ActionService.splitTerms(searchText); |
| 1389 var sameTerms = searchTerms.length == this.searchTerms_.length; |
| 1390 for (var i = 0; sameTerms && i < searchTerms.length; ++i) { |
| 1391 if (searchTerms[i] != this.searchTerms_[i]) |
| 1392 sameTerms = false |
| 1393 } |
| 1394 if (sameTerms) |
| 1395 return false; |
| 1396 this.searchTerms_ = searchTerms; |
| 1397 this.loadMore(); |
| 1398 return true |
| 1399 }, |
| 1400 show: chromeSendWithId("show"), |
| 1401 undo: chrome.send.bind(chrome, "undo") |
| 1402 }; |
| 1403 cr.addSingletonGetter(ActionService); |
| 1404 return { |
| 1405 ActionService: ActionService |
| 1406 } |
| 1407 }); |
| 35 // Copyright 2015 The Chromium Authors. All rights reserved. | 1408 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 36 // Use of this source code is governed by a BSD-style license that can be | 1409 // Use of this source code is governed by a BSD-style license that can be |
| 37 // found in the LICENSE file. | 1410 // found in the LICENSE file. |
| 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}
}); | 1411 cr.define("downloads", function() { |
| 1412 var DangerType = { |
| 1413 NOT_DANGEROUS: "NOT_DANGEROUS", |
| 1414 DANGEROUS_FILE: "DANGEROUS_FILE", |
| 1415 DANGEROUS_URL: "DANGEROUS_URL", |
| 1416 DANGEROUS_CONTENT: "DANGEROUS_CONTENT", |
| 1417 UNCOMMON_CONTENT: "UNCOMMON_CONTENT", |
| 1418 DANGEROUS_HOST: "DANGEROUS_HOST", |
| 1419 POTENTIALLY_UNWANTED: "POTENTIALLY_UNWANTED" |
| 1420 }; |
| 1421 var States = { |
| 1422 IN_PROGRESS: "IN_PROGRESS", |
| 1423 CANCELLED: "CANCELLED", |
| 1424 COMPLETE: "COMPLETE", |
| 1425 PAUSED: "PAUSED", |
| 1426 DANGEROUS: "DANGEROUS", |
| 1427 INTERRUPTED: "INTERRUPTED" |
| 1428 }; |
| 1429 return { |
| 1430 DangerType: DangerType, States: States |
| 1431 } |
| 1432 }); |
| 39 // Copyright 2014 The Chromium Authors. All rights reserved. | 1433 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 40 // Use of this source code is governed by a BSD-style license that can be | 1434 // Use of this source code is governed by a BSD-style license that can be |
| 41 // found in the LICENSE file. | 1435 // found in the LICENSE file. |
| 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},rtlMirroring:{type:Bo
olean,value:false}},_targetIsRTL:function(target){if(target&&target.nodeType!==N
ode.ELEMENT_NODE){target=target.host}return target&&window.getComputedStyle(targ
et)["direction"]==="rtl"},attached:function(){this.style.display="none"},getIcon
Names:function(){this._icons=this._createIconMap();return Object.keys(this._icon
s).map(function(n){return this.name+":"+n},this)},applyIcon:function(element,ico
nName){element=element.root||element;this.removeIcon(element);var svg=this._clon
eIcon(iconName,this.rtlMirroring&&this._targetIsRTL(element));if(svg){var pde=Po
lymer.dom(element);pde.insertBefore(svg,pde.childNodes[0]);return element._svgIc
on=svg}return null},removeIcon:function(element){element=element.root||element;i
f(element._svgIcon){Polymer.dom(element).removeChild(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);Polym
er.dom(this).querySelectorAll("[id]").forEach(function(icon){icons[icon.id]=icon
});return icons},_cloneIcon:function(id,mirrorAllowed){this._icons=this._icons||
this._createIconMap();return this._prepareSvgClone(this._icons[id],this.size,mir
rorAllowed)},_prepareSvgClone:function(sourceSvg,size,mirrorAllowed){if(sourceSv
g){var content=sourceSvg.cloneNode(true),svg=document.createElementNS("http://ww
w.w3.org/2000/svg","svg"),viewBox=content.getAttribute("viewBox")||"0 0 "+size+"
"+size,cssText="pointer-events: none; display: block; width: 100%; height: 100%
;";if(mirrorAllowed&&content.hasAttribute("mirror-in-rtl")){cssText+="-webkit-tr
ansform:scale(-1,1);transform:scale(-1,1);"}svg.setAttribute("viewBox",viewBox);
svg.setAttribute("preserveAspectRatio","xMidYMid meet");svg.style.cssText=cssTex
t;svg.appendChild(content).removeAttribute("id");return svg}return null}}); | 1436 var ActionLink = document.registerElement("action-link", { |
| 1437 prototype: { |
| 1438 __proto__: HTMLAnchorElement.prototype, |
| 1439 createdCallback: function() { |
| 1440 this.tabIndex = this.disabled ? -1 : 0; |
| 1441 if (!this.hasAttribute("role")) |
| 1442 this.setAttribute("role", "link"); |
| 1443 this.addEventListener("keydown", function(e) { |
| 1444 if (!this.disabled && e.key == "Enter" && !this.href) { |
| 1445 window.setTimeout(this.click.bind(this), 0) |
| 1446 } |
| 1447 }); |
| 1448 function preventDefault(e) { |
| 1449 e.preventDefault() |
| 1450 } |
| 1451 function removePreventDefault() { |
| 1452 document.removeEventListener("selectstart", preventDefault); |
| 1453 document.removeEventListener("mouseup", removePreventDefault) |
| 1454 } |
| 1455 this.addEventListener("mousedown", function() { |
| 1456 document.addEventListener("selectstart", preventDefault); |
| 1457 document.addEventListener("mouseup", removePreventDefault); |
| 1458 if (document.activeElement != this) |
| 1459 this.classList.add("no-outline") |
| 1460 }); |
| 1461 this.addEventListener("blur", function() { |
| 1462 this.classList.remove("no-outline") |
| 1463 }) |
| 1464 }, |
| 1465 set disabled(disabled) { |
| 1466 if (disabled) |
| 1467 HTMLAnchorElement.prototype.setAttribute.call(this, "disabled", ""); |
| 1468 else |
| 1469 HTMLAnchorElement.prototype.removeAttribute.call(this, "disabled"); |
| 1470 this.tabIndex = disabled ? -1 : 0 |
| 1471 }, |
| 1472 get disabled() { |
| 1473 return this.hasAttribute("disabled") |
| 1474 }, |
| 1475 setAttribute: function(attr, val) { |
| 1476 if (attr.toLowerCase() == "disabled") |
| 1477 this.disabled = true; |
| 1478 else |
| 1479 HTMLAnchorElement.prototype.setAttribute.apply(this, arguments) |
| 1480 }, |
| 1481 removeAttribute: function(attr) { |
| 1482 if (attr.toLowerCase() == "disabled") |
| 1483 this.disabled = false; |
| 1484 else |
| 1485 HTMLAnchorElement.prototype.removeAttribute.apply(this, arguments) |
| 1486 } |
| 1487 }, |
| 1488 "extends": "a" |
| 1489 }); |
| 1490 (function() { |
| 1491 var metaDatas = {}; |
| 1492 var metaArrays = {}; |
| 1493 var singleton = null; |
| 1494 Polymer.IronMeta = Polymer({ |
| 1495 is: "iron-meta", |
| 1496 properties: { |
| 1497 type: {type: String, value: "default", observer: "_typeChanged"}, |
| 1498 key: {type: String, observer: "_keyChanged"}, |
| 1499 value: {type: Object, notify: true, observer: "_valueChanged"}, |
| 1500 self: {type: Boolean, observer: "_selfChanged"}, |
| 1501 list: {type: Array, notify: true} |
| 1502 }, |
| 1503 hostAttributes: {hidden: true}, |
| 1504 factoryImpl: function(config) { |
| 1505 if (config) { |
| 1506 for (var n in config) { |
| 1507 switch (n) { |
| 1508 case "type": |
| 1509 case "key": |
| 1510 case "value": |
| 1511 this[n] = config[n]; |
| 1512 break |
| 1513 } |
| 1514 } |
| 1515 } |
| 1516 }, |
| 1517 created: function() { |
| 1518 this._metaDatas = metaDatas; |
| 1519 this._metaArrays = metaArrays |
| 1520 }, |
| 1521 _keyChanged: function(key, old) { |
| 1522 this._resetRegistration(old) |
| 1523 }, |
| 1524 _valueChanged: function(value) { |
| 1525 this._resetRegistration(this.key) |
| 1526 }, |
| 1527 _selfChanged: function(self) { |
| 1528 if (self) { |
| 1529 this.value = this |
| 1530 } |
| 1531 }, |
| 1532 _typeChanged: function(type) { |
| 1533 this._unregisterKey(this.key); |
| 1534 if (!metaDatas[type]) { |
| 1535 metaDatas[type] = {} |
| 1536 } |
| 1537 this._metaData = metaDatas[type]; |
| 1538 if (!metaArrays[type]) { |
| 1539 metaArrays[type] = [] |
| 1540 } |
| 1541 this.list = metaArrays[type]; |
| 1542 this._registerKeyValue(this.key, this.value) |
| 1543 }, |
| 1544 byKey: function(key) { |
| 1545 return this._metaData && this._metaData[key] |
| 1546 }, |
| 1547 _resetRegistration: function(oldKey) { |
| 1548 this._unregisterKey(oldKey); |
| 1549 this._registerKeyValue(this.key, this.value) |
| 1550 }, |
| 1551 _unregisterKey: function(key) { |
| 1552 this._unregister(key, this._metaData, this.list) |
| 1553 }, |
| 1554 _registerKeyValue: function(key, value) { |
| 1555 this._register(key, value, this._metaData, this.list) |
| 1556 }, |
| 1557 _register: function(key, value, data, list) { |
| 1558 if (key && data && value !== undefined) { |
| 1559 data[key] = value; |
| 1560 list.push(value) |
| 1561 } |
| 1562 }, |
| 1563 _unregister: function(key, data, list) { |
| 1564 if (key && data) { |
| 1565 if (key in data) { |
| 1566 var value = data[key]; |
| 1567 delete data[key]; |
| 1568 this.arrayDelete(list, value) |
| 1569 } |
| 1570 } |
| 1571 } |
| 1572 }); |
| 1573 Polymer.IronMeta.getIronMeta = function getIronMeta() { |
| 1574 if (singleton === null) { |
| 1575 singleton = new Polymer.IronMeta |
| 1576 } |
| 1577 return singleton |
| 1578 }; |
| 1579 Polymer.IronMetaQuery = Polymer({ |
| 1580 is: "iron-meta-query", |
| 1581 properties: { |
| 1582 type: {type: String, value: "default", observer: "_typeChanged"}, |
| 1583 key: {type: String, observer: "_keyChanged"}, |
| 1584 value: {type: Object, notify: true, readOnly: true}, |
| 1585 list: {type: Array, notify: true} |
| 1586 }, |
| 1587 factoryImpl: function(config) { |
| 1588 if (config) { |
| 1589 for (var n in config) { |
| 1590 switch (n) { |
| 1591 case "type": |
| 1592 case "key": |
| 1593 this[n] = config[n]; |
| 1594 break |
| 1595 } |
| 1596 } |
| 1597 } |
| 1598 }, |
| 1599 created: function() { |
| 1600 this._metaDatas = metaDatas; |
| 1601 this._metaArrays = metaArrays |
| 1602 }, |
| 1603 _keyChanged: function(key) { |
| 1604 this._setValue(this._metaData && this._metaData[key]) |
| 1605 }, |
| 1606 _typeChanged: function(type) { |
| 1607 this._metaData = metaDatas[type]; |
| 1608 this.list = metaArrays[type]; |
| 1609 if (this.key) { |
| 1610 this._keyChanged(this.key) |
| 1611 } |
| 1612 }, |
| 1613 byKey: function(key) { |
| 1614 return this._metaData && this._metaData[key] |
| 1615 } |
| 1616 }) |
| 1617 })(); |
| 1618 Polymer({ |
| 1619 is: "iron-icon", |
| 1620 properties: { |
| 1621 icon: {type: String, observer: "_iconChanged"}, |
| 1622 theme: {type: String, observer: "_updateIcon"}, |
| 1623 src: {type: String, observer: "_srcChanged"}, |
| 1624 _meta: { |
| 1625 value: Polymer.Base.create("iron-meta", {type: "iconset"}), |
| 1626 observer: "_updateIcon" |
| 1627 } |
| 1628 }, |
| 1629 _DEFAULT_ICONSET: "icons", |
| 1630 _iconChanged: function(icon) { |
| 1631 var parts = (icon || "").split(":"); |
| 1632 this._iconName = parts.pop(); |
| 1633 this._iconsetName = parts.pop() || this._DEFAULT_ICONSET; |
| 1634 this._updateIcon() |
| 1635 }, |
| 1636 _srcChanged: function(src) { |
| 1637 this._updateIcon() |
| 1638 }, |
| 1639 _usesIconset: function() { |
| 1640 return this.icon || !this.src |
| 1641 }, |
| 1642 _updateIcon: function() { |
| 1643 if (this._usesIconset()) { |
| 1644 if (this._img && this._img.parentNode) { |
| 1645 Polymer.dom(this.root).removeChild(this._img) |
| 1646 } |
| 1647 if (this._iconName === "") { |
| 1648 if (this._iconset) { |
| 1649 this._iconset.removeIcon(this) |
| 1650 } |
| 1651 } else if (this._iconsetName && this._meta) { |
| 1652 this._iconset = this._meta.byKey(this._iconsetName); |
| 1653 if (this._iconset) { |
| 1654 this._iconset.applyIcon(this, this._iconName, this.theme); |
| 1655 this.unlisten(window, "iron-iconset-added", "_updateIcon") |
| 1656 } else { |
| 1657 this.listen(window, "iron-iconset-added", "_updateIcon") |
| 1658 } |
| 1659 } |
| 1660 } else { |
| 1661 if (this._iconset) { |
| 1662 this._iconset.removeIcon(this) |
| 1663 } |
| 1664 if (!this._img) { |
| 1665 this._img = document.createElement("img"); |
| 1666 this._img.style.width = "100%"; |
| 1667 this._img.style.height = "100%"; |
| 1668 this._img.draggable = false |
| 1669 } |
| 1670 this._img.src = this.src; |
| 1671 Polymer.dom(this.root).appendChild(this._img) |
| 1672 } |
| 1673 } |
| 1674 }); |
| 1675 Polymer.IronControlState = { |
| 1676 properties: { |
| 1677 focused: { |
| 1678 type: Boolean, |
| 1679 value: false, |
| 1680 notify: true, |
| 1681 readOnly: true, |
| 1682 reflectToAttribute: true |
| 1683 }, |
| 1684 disabled: { |
| 1685 type: Boolean, |
| 1686 value: false, |
| 1687 notify: true, |
| 1688 observer: "_disabledChanged", |
| 1689 reflectToAttribute: true |
| 1690 }, |
| 1691 _oldTabIndex: {type: Number}, |
| 1692 _boundFocusBlurHandler: { |
| 1693 type: Function, |
| 1694 value: function() { |
| 1695 return this._focusBlurHandler.bind(this) |
| 1696 } |
| 1697 } |
| 1698 }, |
| 1699 observers: ["_changedControlState(focused, disabled)"], |
| 1700 ready: function() { |
| 1701 this.addEventListener("focus", this._boundFocusBlurHandler, true); |
| 1702 this.addEventListener("blur", this._boundFocusBlurHandler, true) |
| 1703 }, |
| 1704 _focusBlurHandler: function(event) { |
| 1705 if (event.target === this) { |
| 1706 this._setFocused(event.type === "focus") |
| 1707 } else if (!this.shadowRoot) { |
| 1708 var target = Polymer.dom(event).localTarget; |
| 1709 if (!this.isLightDescendant(target)) { |
| 1710 this.fire( |
| 1711 event.type, {sourceEvent: event}, |
| 1712 {node: this, bubbles: event.bubbles, cancelable: event.cancelable}) |
| 1713 } |
| 1714 } |
| 1715 }, |
| 1716 _disabledChanged: function(disabled, old) { |
| 1717 this.setAttribute("aria-disabled", disabled ? "true" : "false"); |
| 1718 this.style.pointerEvents = disabled ? "none" : ""; |
| 1719 if (disabled) { |
| 1720 this._oldTabIndex = this.tabIndex; |
| 1721 this._setFocused(false); |
| 1722 this.tabIndex = -1; |
| 1723 this.blur() |
| 1724 } else if (this._oldTabIndex !== undefined) { |
| 1725 this.tabIndex = this._oldTabIndex |
| 1726 } |
| 1727 }, |
| 1728 _changedControlState: function() { |
| 1729 if (this._controlStateChanged) { |
| 1730 this._controlStateChanged() |
| 1731 } |
| 1732 } |
| 1733 }; |
| 1734 Polymer.IronButtonStateImpl = { |
| 1735 properties: { |
| 1736 pressed: { |
| 1737 type: Boolean, |
| 1738 readOnly: true, |
| 1739 value: false, |
| 1740 reflectToAttribute: true, |
| 1741 observer: "_pressedChanged" |
| 1742 }, |
| 1743 toggles: {type: Boolean, value: false, reflectToAttribute: true}, |
| 1744 active: |
| 1745 {type: Boolean, value: false, notify: true, reflectToAttribute: true}, |
| 1746 pointerDown: {type: Boolean, readOnly: true, value: false}, |
| 1747 receivedFocusFromKeyboard: {type: Boolean, readOnly: true}, |
| 1748 ariaActiveAttribute: { |
| 1749 type: String, |
| 1750 value: "aria-pressed", |
| 1751 observer: "_ariaActiveAttributeChanged" |
| 1752 } |
| 1753 }, |
| 1754 listeners: {down: "_downHandler", up: "_upHandler", tap: "_tapHandler"}, |
| 1755 observers: [ |
| 1756 "_detectKeyboardFocus(focused)", |
| 1757 "_activeChanged(active, ariaActiveAttribute)" |
| 1758 ], |
| 1759 keyBindings: { |
| 1760 "enter:keydown": "_asyncClick", |
| 1761 "space:keydown": "_spaceKeyDownHandler", |
| 1762 "space:keyup": "_spaceKeyUpHandler" |
| 1763 }, |
| 1764 _mouseEventRe: /^mouse/, |
| 1765 _tapHandler: function() { |
| 1766 if (this.toggles) { |
| 1767 this._userActivate(!this.active) |
| 1768 } else { |
| 1769 this.active = false |
| 1770 } |
| 1771 }, |
| 1772 _detectKeyboardFocus: function(focused) { |
| 1773 this._setReceivedFocusFromKeyboard(!this.pointerDown && focused) |
| 1774 }, |
| 1775 _userActivate: function(active) { |
| 1776 if (this.active !== active) { |
| 1777 this.active = active; |
| 1778 this.fire("change") |
| 1779 } |
| 1780 }, |
| 1781 _downHandler: function(event) { |
| 1782 this._setPointerDown(true); |
| 1783 this._setPressed(true); |
| 1784 this._setReceivedFocusFromKeyboard(false) |
| 1785 }, |
| 1786 _upHandler: function() { |
| 1787 this._setPointerDown(false); |
| 1788 this._setPressed(false) |
| 1789 }, |
| 1790 _spaceKeyDownHandler: function(event) { |
| 1791 var keyboardEvent = event.detail.keyboardEvent; |
| 1792 var target = Polymer.dom(keyboardEvent).localTarget; |
| 1793 if (this.isLightDescendant(target)) |
| 1794 return; |
| 1795 keyboardEvent.preventDefault(); |
| 1796 keyboardEvent.stopImmediatePropagation(); |
| 1797 this._setPressed(true) |
| 1798 }, |
| 1799 _spaceKeyUpHandler: function(event) { |
| 1800 var keyboardEvent = event.detail.keyboardEvent; |
| 1801 var target = Polymer.dom(keyboardEvent).localTarget; |
| 1802 if (this.isLightDescendant(target)) |
| 1803 return; |
| 1804 if (this.pressed) { |
| 1805 this._asyncClick() |
| 1806 } |
| 1807 this._setPressed(false) |
| 1808 }, |
| 1809 _asyncClick: function() { |
| 1810 this.async(function() { |
| 1811 this.click() |
| 1812 }, 1) |
| 1813 }, |
| 1814 _pressedChanged: function(pressed) { |
| 1815 this._changedButtonState() |
| 1816 }, |
| 1817 _ariaActiveAttributeChanged: function(value, oldValue) { |
| 1818 if (oldValue && oldValue != value && this.hasAttribute(oldValue)) { |
| 1819 this.removeAttribute(oldValue) |
| 1820 } |
| 1821 }, |
| 1822 _activeChanged: function(active, ariaActiveAttribute) { |
| 1823 if (this.toggles) { |
| 1824 this.setAttribute(this.ariaActiveAttribute, active ? "true" : "false") |
| 1825 } else { |
| 1826 this.removeAttribute(this.ariaActiveAttribute) |
| 1827 } |
| 1828 this._changedButtonState() |
| 1829 }, |
| 1830 _controlStateChanged: function() { |
| 1831 if (this.disabled) { |
| 1832 this._setPressed(false) |
| 1833 } else { |
| 1834 this._changedButtonState() |
| 1835 } |
| 1836 }, |
| 1837 _changedButtonState: function() { |
| 1838 if (this._buttonStateChanged) { |
| 1839 this._buttonStateChanged() |
| 1840 } |
| 1841 } |
| 1842 }; |
| 1843 Polymer.IronButtonState = |
| 1844 [Polymer.IronA11yKeysBehavior, Polymer.IronButtonStateImpl]; |
| 1845 (function() { |
| 1846 var Utility = { |
| 1847 distance: function(x1, y1, x2, y2) { |
| 1848 var xDelta = x1 - x2; |
| 1849 var yDelta = y1 - y2; |
| 1850 return Math.sqrt(xDelta * xDelta + yDelta * yDelta) |
| 1851 }, |
| 1852 now: window.performance && window.performance.now ? |
| 1853 window.performance.now.bind(window.performance) : |
| 1854 Date.now |
| 1855 }; |
| 1856 function ElementMetrics(element) { |
| 1857 this.element = element; |
| 1858 this.width = this.boundingRect.width; |
| 1859 this.height = this.boundingRect.height; |
| 1860 this.size = Math.max(this.width, this.height) |
| 1861 } |
| 1862 ElementMetrics.prototype = { |
| 1863 get boundingRect() { |
| 1864 return this.element.getBoundingClientRect() |
| 1865 }, |
| 1866 furthestCornerDistanceFrom: function(x, y) { |
| 1867 var topLeft = Utility.distance(x, y, 0, 0); |
| 1868 var topRight = Utility.distance(x, y, this.width, 0); |
| 1869 var bottomLeft = Utility.distance(x, y, 0, this.height); |
| 1870 var bottomRight = Utility.distance(x, y, this.width, this.height); |
| 1871 return Math.max(topLeft, topRight, bottomLeft, bottomRight) |
| 1872 } |
| 1873 }; |
| 1874 function Ripple(element) { |
| 1875 this.element = element; |
| 1876 this.color = window.getComputedStyle(element).color; |
| 1877 this.wave = document.createElement("div"); |
| 1878 this.waveContainer = document.createElement("div"); |
| 1879 this.wave.style.backgroundColor = this.color; |
| 1880 this.wave.classList.add("wave"); |
| 1881 this.waveContainer.classList.add("wave-container"); |
| 1882 Polymer.dom(this.waveContainer).appendChild(this.wave); |
| 1883 this.resetInteractionState() |
| 1884 } |
| 1885 Ripple.MAX_RADIUS = 300; |
| 1886 Ripple.prototype = { |
| 1887 get recenters() { |
| 1888 return this.element.recenters |
| 1889 }, |
| 1890 get center() { |
| 1891 return this.element.center |
| 1892 }, |
| 1893 get mouseDownElapsed() { |
| 1894 var elapsed; |
| 1895 if (!this.mouseDownStart) { |
| 1896 return 0 |
| 1897 } |
| 1898 elapsed = Utility.now() - this.mouseDownStart; |
| 1899 if (this.mouseUpStart) { |
| 1900 elapsed -= this.mouseUpElapsed |
| 1901 } |
| 1902 return elapsed |
| 1903 }, |
| 1904 get mouseUpElapsed() { |
| 1905 return this.mouseUpStart ? Utility.now() - this.mouseUpStart : 0 |
| 1906 }, |
| 1907 get mouseDownElapsedSeconds() { |
| 1908 return this.mouseDownElapsed / 1e3 |
| 1909 }, |
| 1910 get mouseUpElapsedSeconds() { |
| 1911 return this.mouseUpElapsed / 1e3 |
| 1912 }, |
| 1913 get mouseInteractionSeconds() { |
| 1914 return this.mouseDownElapsedSeconds + this.mouseUpElapsedSeconds |
| 1915 }, |
| 1916 get initialOpacity() { |
| 1917 return this.element.initialOpacity |
| 1918 }, |
| 1919 get opacityDecayVelocity() { |
| 1920 return this.element.opacityDecayVelocity |
| 1921 }, |
| 1922 get radius() { |
| 1923 var width2 = this.containerMetrics.width * this.containerMetrics.width; |
| 1924 var height2 = this.containerMetrics.height * this.containerMetrics.height; |
| 1925 var waveRadius = |
| 1926 Math.min(Math.sqrt(width2 + height2), Ripple.MAX_RADIUS) * 1.1 + 5; |
| 1927 var duration = 1.1 - .2 * (waveRadius / Ripple.MAX_RADIUS); |
| 1928 var timeNow = this.mouseInteractionSeconds / duration; |
| 1929 var size = waveRadius * (1 - Math.pow(80, -timeNow)); |
| 1930 return Math.abs(size) |
| 1931 }, |
| 1932 get opacity() { |
| 1933 if (!this.mouseUpStart) { |
| 1934 return this.initialOpacity |
| 1935 } |
| 1936 return Math.max( |
| 1937 0, this.initialOpacity - |
| 1938 this.mouseUpElapsedSeconds * this.opacityDecayVelocity) |
| 1939 }, |
| 1940 get outerOpacity() { |
| 1941 var outerOpacity = this.mouseUpElapsedSeconds * .3; |
| 1942 var waveOpacity = this.opacity; |
| 1943 return Math.max(0, Math.min(outerOpacity, waveOpacity)) |
| 1944 }, |
| 1945 get isOpacityFullyDecayed() { |
| 1946 return this.opacity < .01 && |
| 1947 this.radius >= Math.min(this.maxRadius, Ripple.MAX_RADIUS) |
| 1948 }, |
| 1949 get isRestingAtMaxRadius() { |
| 1950 return this.opacity >= this.initialOpacity && |
| 1951 this.radius >= Math.min(this.maxRadius, Ripple.MAX_RADIUS) |
| 1952 }, |
| 1953 get isAnimationComplete() { |
| 1954 return this.mouseUpStart ? this.isOpacityFullyDecayed : |
| 1955 this.isRestingAtMaxRadius |
| 1956 }, |
| 1957 get translationFraction() { |
| 1958 return Math.min( |
| 1959 1, this.radius / this.containerMetrics.size * 2 / Math.sqrt(2)) |
| 1960 }, |
| 1961 get xNow() { |
| 1962 if (this.xEnd) { |
| 1963 return this.xStart + |
| 1964 this.translationFraction * (this.xEnd - this.xStart) |
| 1965 } |
| 1966 return this.xStart |
| 1967 }, |
| 1968 get yNow() { |
| 1969 if (this.yEnd) { |
| 1970 return this.yStart + |
| 1971 this.translationFraction * (this.yEnd - this.yStart) |
| 1972 } |
| 1973 return this.yStart |
| 1974 }, |
| 1975 get isMouseDown() { |
| 1976 return this.mouseDownStart && !this.mouseUpStart |
| 1977 }, |
| 1978 resetInteractionState: function() { |
| 1979 this.maxRadius = 0; |
| 1980 this.mouseDownStart = 0; |
| 1981 this.mouseUpStart = 0; |
| 1982 this.xStart = 0; |
| 1983 this.yStart = 0; |
| 1984 this.xEnd = 0; |
| 1985 this.yEnd = 0; |
| 1986 this.slideDistance = 0; |
| 1987 this.containerMetrics = new ElementMetrics(this.element) |
| 1988 }, |
| 1989 draw: function() { |
| 1990 var scale; |
| 1991 var translateString; |
| 1992 var dx; |
| 1993 var dy; |
| 1994 this.wave.style.opacity = this.opacity; |
| 1995 scale = this.radius / (this.containerMetrics.size / 2); |
| 1996 dx = this.xNow - this.containerMetrics.width / 2; |
| 1997 dy = this.yNow - this.containerMetrics.height / 2; |
| 1998 this.waveContainer.style.webkitTransform = |
| 1999 "translate(" + dx + "px, " + dy + "px)"; |
| 2000 this.waveContainer.style.transform = |
| 2001 "translate3d(" + dx + "px, " + dy + "px, 0)"; |
| 2002 this.wave.style.webkitTransform = "scale(" + scale + "," + scale + ")"; |
| 2003 this.wave.style.transform = "scale3d(" + scale + "," + scale + ",1)" |
| 2004 }, |
| 2005 downAction: function(event) { |
| 2006 var xCenter = this.containerMetrics.width / 2; |
| 2007 var yCenter = this.containerMetrics.height / 2; |
| 2008 this.resetInteractionState(); |
| 2009 this.mouseDownStart = Utility.now(); |
| 2010 if (this.center) { |
| 2011 this.xStart = xCenter; |
| 2012 this.yStart = yCenter; |
| 2013 this.slideDistance = |
| 2014 Utility.distance(this.xStart, this.yStart, this.xEnd, this.yEnd) |
| 2015 } else { |
| 2016 this.xStart = event ? |
| 2017 event.detail.x - this.containerMetrics.boundingRect.left : |
| 2018 this.containerMetrics.width / 2; |
| 2019 this.yStart = event ? |
| 2020 event.detail.y - this.containerMetrics.boundingRect.top : |
| 2021 this.containerMetrics.height / 2 |
| 2022 } |
| 2023 if (this.recenters) { |
| 2024 this.xEnd = xCenter; |
| 2025 this.yEnd = yCenter; |
| 2026 this.slideDistance = |
| 2027 Utility.distance(this.xStart, this.yStart, this.xEnd, this.yEnd) |
| 2028 } |
| 2029 this.maxRadius = this.containerMetrics.furthestCornerDistanceFrom( |
| 2030 this.xStart, this.yStart); |
| 2031 this.waveContainer.style.top = |
| 2032 (this.containerMetrics.height - this.containerMetrics.size) / 2 + |
| 2033 "px"; |
| 2034 this.waveContainer.style.left = |
| 2035 (this.containerMetrics.width - this.containerMetrics.size) / 2 + "px"; |
| 2036 this.waveContainer.style.width = this.containerMetrics.size + "px"; |
| 2037 this.waveContainer.style.height = this.containerMetrics.size + "px" |
| 2038 }, |
| 2039 upAction: function(event) { |
| 2040 if (!this.isMouseDown) { |
| 2041 return |
| 2042 } |
| 2043 this.mouseUpStart = Utility.now() |
| 2044 }, |
| 2045 remove: function() { |
| 2046 Polymer.dom(this.waveContainer.parentNode).removeChild(this.waveContainer) |
| 2047 } |
| 2048 }; |
| 2049 Polymer({ |
| 2050 is: "paper-ripple", |
| 2051 behaviors: [Polymer.IronA11yKeysBehavior], |
| 2052 properties: { |
| 2053 initialOpacity: {type: Number, value: .25}, |
| 2054 opacityDecayVelocity: {type: Number, value: .8}, |
| 2055 recenters: {type: Boolean, value: false}, |
| 2056 center: {type: Boolean, value: false}, |
| 2057 ripples: { |
| 2058 type: Array, |
| 2059 value: function() { |
| 2060 return [] |
| 2061 } |
| 2062 }, |
| 2063 animating: { |
| 2064 type: Boolean, |
| 2065 readOnly: true, |
| 2066 reflectToAttribute: true, |
| 2067 value: false |
| 2068 }, |
| 2069 holdDown: {type: Boolean, value: false, observer: "_holdDownChanged"}, |
| 2070 noink: {type: Boolean, value: false}, |
| 2071 _animating: {type: Boolean}, |
| 2072 _boundAnimate: { |
| 2073 type: Function, |
| 2074 value: function() { |
| 2075 return this.animate.bind(this) |
| 2076 } |
| 2077 } |
| 2078 }, |
| 2079 get target() { |
| 2080 return this.keyEventTarget |
| 2081 }, |
| 2082 keyBindings: { |
| 2083 "enter:keydown": "_onEnterKeydown", |
| 2084 "space:keydown": "_onSpaceKeydown", |
| 2085 "space:keyup": "_onSpaceKeyup" |
| 2086 }, |
| 2087 attached: function() { |
| 2088 if (this.parentNode.nodeType == 11) { |
| 2089 this.keyEventTarget = Polymer.dom(this).getOwnerRoot().host |
| 2090 } else { |
| 2091 this.keyEventTarget = this.parentNode |
| 2092 } |
| 2093 var keyEventTarget = this.keyEventTarget; |
| 2094 this.listen(keyEventTarget, "up", "uiUpAction"); |
| 2095 this.listen(keyEventTarget, "down", "uiDownAction") |
| 2096 }, |
| 2097 detached: function() { |
| 2098 this.unlisten(this.keyEventTarget, "up", "uiUpAction"); |
| 2099 this.unlisten(this.keyEventTarget, "down", "uiDownAction"); |
| 2100 this.keyEventTarget = null |
| 2101 }, |
| 2102 get shouldKeepAnimating() { |
| 2103 for (var index = 0; index < this.ripples.length; ++index) { |
| 2104 if (!this.ripples[index].isAnimationComplete) { |
| 2105 return true |
| 2106 } |
| 2107 } |
| 2108 return false |
| 2109 }, |
| 2110 simulatedRipple: function() { |
| 2111 this.downAction(null); |
| 2112 this.async(function() { |
| 2113 this.upAction() |
| 2114 }, 1) |
| 2115 }, |
| 2116 uiDownAction: function(event) { |
| 2117 if (!this.noink) { |
| 2118 this.downAction(event) |
| 2119 } |
| 2120 }, |
| 2121 downAction: function(event) { |
| 2122 if (this.holdDown && this.ripples.length > 0) { |
| 2123 return |
| 2124 } |
| 2125 var ripple = this.addRipple(); |
| 2126 ripple.downAction(event); |
| 2127 if (!this._animating) { |
| 2128 this._animating = true; |
| 2129 this.animate() |
| 2130 } |
| 2131 }, |
| 2132 uiUpAction: function(event) { |
| 2133 if (!this.noink) { |
| 2134 this.upAction(event) |
| 2135 } |
| 2136 }, |
| 2137 upAction: function(event) { |
| 2138 if (this.holdDown) { |
| 2139 return |
| 2140 } |
| 2141 this.ripples.forEach(function(ripple) { |
| 2142 ripple.upAction(event) |
| 2143 }); |
| 2144 this._animating = true; |
| 2145 this.animate() |
| 2146 }, |
| 2147 onAnimationComplete: function() { |
| 2148 this._animating = false; |
| 2149 this.$.background.style.backgroundColor = null; |
| 2150 this.fire("transitionend") |
| 2151 }, |
| 2152 addRipple: function() { |
| 2153 var ripple = new Ripple(this); |
| 2154 Polymer.dom(this.$.waves).appendChild(ripple.waveContainer); |
| 2155 this.$.background.style.backgroundColor = ripple.color; |
| 2156 this.ripples.push(ripple); |
| 2157 this._setAnimating(true); |
| 2158 return ripple |
| 2159 }, |
| 2160 removeRipple: function(ripple) { |
| 2161 var rippleIndex = this.ripples.indexOf(ripple); |
| 2162 if (rippleIndex < 0) { |
| 2163 return |
| 2164 } |
| 2165 this.ripples.splice(rippleIndex, 1); |
| 2166 ripple.remove(); |
| 2167 if (!this.ripples.length) { |
| 2168 this._setAnimating(false) |
| 2169 } |
| 2170 }, |
| 2171 animate: function() { |
| 2172 if (!this._animating) { |
| 2173 return |
| 2174 } |
| 2175 var index; |
| 2176 var ripple; |
| 2177 for (index = 0; index < this.ripples.length; ++index) { |
| 2178 ripple = this.ripples[index]; |
| 2179 ripple.draw(); |
| 2180 this.$.background.style.opacity = ripple.outerOpacity; |
| 2181 if (ripple.isOpacityFullyDecayed && !ripple.isRestingAtMaxRadius) { |
| 2182 this.removeRipple(ripple) |
| 2183 } |
| 2184 } |
| 2185 if (!this.shouldKeepAnimating && this.ripples.length === 0) { |
| 2186 this.onAnimationComplete() |
| 2187 } else { |
| 2188 window.requestAnimationFrame(this._boundAnimate) |
| 2189 } |
| 2190 }, |
| 2191 _onEnterKeydown: function() { |
| 2192 this.uiDownAction(); |
| 2193 this.async(this.uiUpAction, 1) |
| 2194 }, |
| 2195 _onSpaceKeydown: function() { |
| 2196 this.uiDownAction() |
| 2197 }, |
| 2198 _onSpaceKeyup: function() { |
| 2199 this.uiUpAction() |
| 2200 }, |
| 2201 _holdDownChanged: function(newVal, oldVal) { |
| 2202 if (oldVal === undefined) { |
| 2203 return |
| 2204 } |
| 2205 if (newVal) { |
| 2206 this.downAction() |
| 2207 } else { |
| 2208 this.upAction() |
| 2209 } |
| 2210 } |
| 2211 }) |
| 2212 })(); |
| 2213 Polymer.PaperRippleBehavior = { |
| 2214 properties: { |
| 2215 noink: {type: Boolean, observer: "_noinkChanged"}, |
| 2216 _rippleContainer: {type: Object} |
| 2217 }, |
| 2218 _buttonStateChanged: function() { |
| 2219 if (this.focused) { |
| 2220 this.ensureRipple() |
| 2221 } |
| 2222 }, |
| 2223 _downHandler: function(event) { |
| 2224 Polymer.IronButtonStateImpl._downHandler.call(this, event); |
| 2225 if (this.pressed) { |
| 2226 this.ensureRipple(event) |
| 2227 } |
| 2228 }, |
| 2229 ensureRipple: function(optTriggeringEvent) { |
| 2230 if (!this.hasRipple()) { |
| 2231 this._ripple = this._createRipple(); |
| 2232 this._ripple.noink = this.noink; |
| 2233 var rippleContainer = this._rippleContainer || this.root; |
| 2234 if (rippleContainer) { |
| 2235 Polymer.dom(rippleContainer).appendChild(this._ripple) |
| 2236 } |
| 2237 if (optTriggeringEvent) { |
| 2238 var domContainer = Polymer.dom(this._rippleContainer || this); |
| 2239 var target = Polymer.dom(optTriggeringEvent).rootTarget; |
| 2240 if (domContainer.deepContains(target)) { |
| 2241 this._ripple.uiDownAction(optTriggeringEvent) |
| 2242 } |
| 2243 } |
| 2244 } |
| 2245 }, |
| 2246 getRipple: function() { |
| 2247 this.ensureRipple(); |
| 2248 return this._ripple |
| 2249 }, |
| 2250 hasRipple: function() { |
| 2251 return Boolean(this._ripple) |
| 2252 }, |
| 2253 _createRipple: function() { |
| 2254 return document.createElement("paper-ripple") |
| 2255 }, |
| 2256 _noinkChanged: function(noink) { |
| 2257 if (this.hasRipple()) { |
| 2258 this._ripple.noink = noink |
| 2259 } |
| 2260 } |
| 2261 }; |
| 2262 Polymer.PaperButtonBehaviorImpl = { |
| 2263 properties: |
| 2264 {elevation: {type: Number, reflectToAttribute: true, readOnly: true}}, |
| 2265 observers: [ |
| 2266 "_calculateElevation(focused, disabled, active, pressed, receivedFocusFromKe
yboard)", |
| 2267 "_computeKeyboardClass(receivedFocusFromKeyboard)" |
| 2268 ], |
| 2269 hostAttributes: {role: "button", tabindex: "0", animated: true}, |
| 2270 _calculateElevation: function() { |
| 2271 var e = 1; |
| 2272 if (this.disabled) { |
| 2273 e = 0 |
| 2274 } else if (this.active || this.pressed) { |
| 2275 e = 4 |
| 2276 } else if (this.receivedFocusFromKeyboard) { |
| 2277 e = 3 |
| 2278 } |
| 2279 this._setElevation(e) |
| 2280 }, |
| 2281 _computeKeyboardClass: function(receivedFocusFromKeyboard) { |
| 2282 this.toggleClass("keyboard-focus", receivedFocusFromKeyboard) |
| 2283 }, |
| 2284 _spaceKeyDownHandler: function(event) { |
| 2285 Polymer.IronButtonStateImpl._spaceKeyDownHandler.call(this, event); |
| 2286 if (this.hasRipple() && this.getRipple().ripples.length < 1) { |
| 2287 this._ripple.uiDownAction() |
| 2288 } |
| 2289 }, |
| 2290 _spaceKeyUpHandler: function(event) { |
| 2291 Polymer.IronButtonStateImpl._spaceKeyUpHandler.call(this, event); |
| 2292 if (this.hasRipple()) { |
| 2293 this._ripple.uiUpAction() |
| 2294 } |
| 2295 } |
| 2296 }; |
| 2297 Polymer.PaperButtonBehavior = [ |
| 2298 Polymer.IronButtonState, Polymer.IronControlState, |
| 2299 Polymer.PaperRippleBehavior, Polymer.PaperButtonBehaviorImpl |
| 2300 ]; |
| 2301 Polymer({ |
| 2302 is: "paper-button", |
| 2303 behaviors: [Polymer.PaperButtonBehavior], |
| 2304 properties: { |
| 2305 raised: { |
| 2306 type: Boolean, |
| 2307 reflectToAttribute: true, |
| 2308 value: false, |
| 2309 observer: "_calculateElevation" |
| 2310 } |
| 2311 }, |
| 2312 _calculateElevation: function() { |
| 2313 if (!this.raised) { |
| 2314 this._setElevation(0) |
| 2315 } else { |
| 2316 Polymer.PaperButtonBehaviorImpl._calculateElevation.apply(this) |
| 2317 } |
| 2318 } |
| 2319 }); |
| 2320 Polymer({ |
| 2321 is: "paper-icon-button-light", |
| 2322 "extends": "button", |
| 2323 behaviors: [Polymer.PaperRippleBehavior], |
| 2324 listeners: { |
| 2325 down: "_rippleDown", |
| 2326 up: "_rippleUp", |
| 2327 focus: "_rippleDown", |
| 2328 blur: "_rippleUp" |
| 2329 }, |
| 2330 _rippleDown: function() { |
| 2331 this.getRipple().downAction() |
| 2332 }, |
| 2333 _rippleUp: function() { |
| 2334 this.getRipple().upAction() |
| 2335 }, |
| 2336 ensureRipple: function(var_args) { |
| 2337 var lastRipple = this._ripple; |
| 2338 Polymer.PaperRippleBehavior.ensureRipple.apply(this, arguments); |
| 2339 if (this._ripple && this._ripple !== lastRipple) { |
| 2340 this._ripple.center = true; |
| 2341 this._ripple.classList.add("circle") |
| 2342 } |
| 2343 } |
| 2344 }); |
| 2345 Polymer.IronRangeBehavior = { |
| 2346 properties: { |
| 2347 value: {type: Number, value: 0, notify: true, reflectToAttribute: true}, |
| 2348 min: {type: Number, value: 0, notify: true}, |
| 2349 max: {type: Number, value: 100, notify: true}, |
| 2350 step: {type: Number, value: 1, notify: true}, |
| 2351 ratio: {type: Number, value: 0, readOnly: true, notify: true} |
| 2352 }, |
| 2353 observers: ["_update(value, min, max, step)"], |
| 2354 _calcRatio: function(value) { |
| 2355 return (this._clampValue(value) - this.min) / (this.max - this.min) |
| 2356 }, |
| 2357 _clampValue: function(value) { |
| 2358 return Math.min(this.max, Math.max(this.min, this._calcStep(value))) |
| 2359 }, |
| 2360 _calcStep: function(value) { |
| 2361 value = parseFloat(value); |
| 2362 if (!this.step) { |
| 2363 return value |
| 2364 } |
| 2365 var numSteps = Math.round((value - this.min) / this.step); |
| 2366 if (this.step < 1) { |
| 2367 return numSteps / (1 / this.step) + this.min |
| 2368 } else { |
| 2369 return numSteps * this.step + this.min |
| 2370 } |
| 2371 }, |
| 2372 _validateValue: function() { |
| 2373 var v = this._clampValue(this.value); |
| 2374 this.value = this.oldValue = isNaN(v) ? this.oldValue : v; |
| 2375 return this.value !== v |
| 2376 }, |
| 2377 _update: function() { |
| 2378 this._validateValue(); |
| 2379 this._setRatio(this._calcRatio(this.value) * 100) |
| 2380 } |
| 2381 }; |
| 2382 Polymer({ |
| 2383 is: "paper-progress", |
| 2384 behaviors: [Polymer.IronRangeBehavior], |
| 2385 properties: { |
| 2386 secondaryProgress: {type: Number, value: 0}, |
| 2387 secondaryRatio: {type: Number, value: 0, readOnly: true}, |
| 2388 indeterminate: |
| 2389 {type: Boolean, value: false, observer: "_toggleIndeterminate"}, |
| 2390 disabled: { |
| 2391 type: Boolean, |
| 2392 value: false, |
| 2393 reflectToAttribute: true, |
| 2394 observer: "_disabledChanged" |
| 2395 } |
| 2396 }, |
| 2397 observers: ["_progressChanged(secondaryProgress, value, min, max)"], |
| 2398 hostAttributes: {role: "progressbar"}, |
| 2399 _toggleIndeterminate: function(indeterminate) { |
| 2400 this.toggleClass("indeterminate", indeterminate, this.$.primaryProgress) |
| 2401 }, |
| 2402 _transformProgress: function(progress, ratio) { |
| 2403 var transform = "scaleX(" + ratio / 100 + ")"; |
| 2404 progress.style.transform = progress.style.webkitTransform = transform |
| 2405 }, |
| 2406 _mainRatioChanged: function(ratio) { |
| 2407 this._transformProgress(this.$.primaryProgress, ratio) |
| 2408 }, |
| 2409 _progressChanged: function(secondaryProgress, value, min, max) { |
| 2410 secondaryProgress = this._clampValue(secondaryProgress); |
| 2411 value = this._clampValue(value); |
| 2412 var secondaryRatio = this._calcRatio(secondaryProgress) * 100; |
| 2413 var mainRatio = this._calcRatio(value) * 100; |
| 2414 this._setSecondaryRatio(secondaryRatio); |
| 2415 this._transformProgress(this.$.secondaryProgress, secondaryRatio); |
| 2416 this._transformProgress(this.$.primaryProgress, mainRatio); |
| 2417 this.secondaryProgress = secondaryProgress; |
| 2418 this.setAttribute("aria-valuenow", value); |
| 2419 this.setAttribute("aria-valuemin", min); |
| 2420 this.setAttribute("aria-valuemax", max) |
| 2421 }, |
| 2422 _disabledChanged: function(disabled) { |
| 2423 this.setAttribute("aria-disabled", disabled ? "true" : "false") |
| 2424 }, |
| 2425 _hideSecondaryProgress: function(secondaryRatio) { |
| 2426 return secondaryRatio === 0 |
| 2427 } |
| 2428 }); |
| 2429 Polymer({ |
| 2430 is: "iron-iconset-svg", |
| 2431 properties: { |
| 2432 name: {type: String, observer: "_nameChanged"}, |
| 2433 size: {type: Number, value: 24}, |
| 2434 rtlMirroring: {type: Boolean, value: false} |
| 2435 }, |
| 2436 _targetIsRTL: function(target) { |
| 2437 if (target && target.nodeType !== Node.ELEMENT_NODE) { |
| 2438 target = target.host |
| 2439 } |
| 2440 return target && window.getComputedStyle(target)["direction"] === "rtl" |
| 2441 }, |
| 2442 attached: function() { |
| 2443 this.style.display = "none" |
| 2444 }, |
| 2445 getIconNames: function() { |
| 2446 this._icons = this._createIconMap(); |
| 2447 return Object.keys(this._icons).map(function(n) { |
| 2448 return this.name + ":" + n |
| 2449 }, this) |
| 2450 }, |
| 2451 applyIcon: function(element, iconName) { |
| 2452 element = element.root || element; |
| 2453 this.removeIcon(element); |
| 2454 var svg = this._cloneIcon( |
| 2455 iconName, this.rtlMirroring && this._targetIsRTL(element)); |
| 2456 if (svg) { |
| 2457 var pde = Polymer.dom(element); |
| 2458 pde.insertBefore(svg, pde.childNodes[0]); |
| 2459 return element._svgIcon = svg |
| 2460 } |
| 2461 return null |
| 2462 }, |
| 2463 removeIcon: function(element) { |
| 2464 element = element.root || element; |
| 2465 if (element._svgIcon) { |
| 2466 Polymer.dom(element).removeChild(element._svgIcon); |
| 2467 element._svgIcon = null |
| 2468 } |
| 2469 }, |
| 2470 _nameChanged: function() { |
| 2471 new Polymer.IronMeta({type: "iconset", key: this.name, value: this}); |
| 2472 this.async(function() { |
| 2473 this.fire("iron-iconset-added", this, {node: window}) |
| 2474 }) |
| 2475 }, |
| 2476 _createIconMap: function() { |
| 2477 var icons = Object.create(null); |
| 2478 Polymer.dom(this).querySelectorAll("[id]").forEach(function(icon) { |
| 2479 icons[icon.id] = icon |
| 2480 }); |
| 2481 return icons |
| 2482 }, |
| 2483 _cloneIcon: function(id, mirrorAllowed) { |
| 2484 this._icons = this._icons || this._createIconMap(); |
| 2485 return this._prepareSvgClone(this._icons[id], this.size, mirrorAllowed) |
| 2486 }, |
| 2487 _prepareSvgClone: function(sourceSvg, size, mirrorAllowed) { |
| 2488 if (sourceSvg) { |
| 2489 var content = sourceSvg.cloneNode(true), |
| 2490 svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), |
| 2491 viewBox = |
| 2492 content.getAttribute("viewBox") || "0 0 " + size + " " + size, |
| 2493 cssText = |
| 2494 "pointer-events: none; display: block; width: 100%; height: 100%;"
; |
| 2495 if (mirrorAllowed && content.hasAttribute("mirror-in-rtl")) { |
| 2496 cssText += "-webkit-transform:scale(-1,1);transform:scale(-1,1);" |
| 2497 } |
| 2498 svg.setAttribute("viewBox", viewBox); |
| 2499 svg.setAttribute("preserveAspectRatio", "xMidYMid meet"); |
| 2500 svg.style.cssText = cssText; |
| 2501 svg.appendChild(content).removeAttribute("id"); |
| 2502 return svg |
| 2503 } |
| 2504 return null |
| 2505 } |
| 2506 }); |
| 43 // Copyright 2015 The Chromium Authors. All rights reserved. | 2507 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 44 // Use of this source code is governed by a BSD-style license that can be | 2508 // Use of this source code is governed by a BSD-style license that can be |
| 45 // found in the LICENSE file. | 2509 // found in the LICENSE file. |
| 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},chopUrl_:function(url){return url.slice(0,300)},computeClass_:function(){var
classes=[];if(this.isActive_)classes.push("is-active");if(this.isDangerous_)cla
sses.push("dangerous");if(this.showProgress_)classes.push("show-progress");retur
n classes.join(" ")},computeCompletelyOnDisk_:function(){return this.data.state=
=downloads.States.COMPLETE&&!this.data.file_externally_removed},computeControlle
dBy_:function(){if(!this.data.by_ext_id||!this.data.by_ext_name)return"";var url
="chrome://extensions#"+this.data.by_ext_id;var name=this.data.by_ext_name;retur
n loadTimeData.getStringF("controlledByUrl",url,HTMLEscape(name))},computeDanger
Icon_:function(){return this.isDangerous_?"cr:warning":""},computeDate_:function
(){assert(typeof this.data.hideDate=="boolean");if(this.data.hideDate)return"";r
eturn assert(this.data.since_string||this.data.date_string)},computeDescription_
:function(){var data=this.data;switch(data.state){case downloads.States.DANGEROU
S:var fileName=data.file_name;switch(data.danger_type){case downloads.DangerType
.DANGEROUS_FILE:return loadTimeData.getString("dangerFileDesc");case downloads.D
angerType.DANGEROUS_URL:case downloads.DangerType.DANGEROUS_CONTENT:case downloa
ds.DangerType.DANGEROUS_HOST:return loadTimeData.getString("dangerDownloadDesc")
;case downloads.DangerType.UNCOMMON_CONTENT:return loadTimeData.getString("dange
rUncommonDesc");case downloads.DangerType.POTENTIALLY_UNWANTED:return loadTimeDa
ta.getString("dangerSettingsDesc")}break;case downloads.States.IN_PROGRESS:case
downloads.States.PAUSED:return data.progress_status_text}return""},computeIsActi
ve_:function(){return this.data.state!=downloads.States.CANCELLED&&this.data.sta
te!=downloads.States.INTERRUPTED&&!this.data.file_externally_removed},computeIsD
angerous_:function(){return this.data.state==downloads.States.DANGEROUS},compute
IsInProgress_:function(){return this.data.state==downloads.States.IN_PROGRESS},c
omputeIsMalware_:function(){return this.isDangerous_&&(this.data.danger_type==do
wnloads.DangerType.DANGEROUS_CONTENT||this.data.danger_type==downloads.DangerTyp
e.DANGEROUS_HOST||this.data.danger_type==downloads.DangerType.DANGEROUS_URL||thi
s.data.danger_type==downloads.DangerType.POTENTIALLY_UNWANTED)},computePauseOrRe
sumeText_:function(){if(this.isInProgress_)return loadTimeData.getString("contro
lPause");if(this.data.resume)return loadTimeData.getString("controlResume");retu
rn""},computeRemoveStyle_:function(){var canDelete=loadTimeData.getBoolean("allo
wDeletingHistory");var hideRemove=this.isDangerous_||this.showCancel_||!canDelet
e;return hideRemove?"visibility: hidden":""},computeShowCancel_:function(){retur
n this.data.state==downloads.States.IN_PROGRESS||this.data.state==downloads.Stat
es.PAUSED},computeShowProgress_:function(){return this.showCancel_&&this.data.pe
rcent>=-1},computeTag_:function(){switch(this.data.state){case downloads.States.
CANCELLED:return loadTimeData.getString("statusCancelled");case downloads.States
.INTERRUPTED:return this.data.last_reason_text;case downloads.States.COMPLETE:re
turn this.data.file_externally_removed?loadTimeData.getString("statusRemoved"):"
"}return""},isIndeterminate_:function(){return this.data.percent==-1},observeCon
trolledBy_:function(){this.$["controlled-by"].innerHTML=this.controlledBy_},obse
rveIsDangerous_:function(){if(!this.data)return;if(this.isDangerous_){this.$.url
.removeAttribute("href")}else{this.$.url.href=assert(this.data.url);var filePath
=encodeURIComponent(this.data.file_path);var scaleFactor="?scale="+window.device
PixelRatio+"x";this.$["file-icon"].src="chrome://fileicon/"+filePath+scaleFactor
}},onCancelTap_:function(){downloads.ActionService.getInstance().cancel(this.dat
a.id)},onDiscardDangerousTap_:function(){downloads.ActionService.getInstance().d
iscardDangerous(this.data.id)},onDragStart_:function(e){e.preventDefault();downl
oads.ActionService.getInstance().drag(this.data.id)},onFileLinkTap_:function(e){
e.preventDefault();downloads.ActionService.getInstance().openFile(this.data.id)}
,onPauseOrResumeTap_:function(){if(this.isInProgress_)downloads.ActionService.ge
tInstance().pause(this.data.id);else downloads.ActionService.getInstance().resum
e(this.data.id)},onRemoveTap_:function(){downloads.ActionService.getInstance().r
emove(this.data.id)},onRetryTap_:function(){downloads.ActionService.getInstance(
).download(this.data.url)},onSaveDangerousTap_:function(){downloads.ActionServic
e.getInstance().saveDangerous(this.data.id)},onShowTap_:function(){downloads.Act
ionService.getInstance().show(this.data.id)}});return{Item:Item}});Polymer.Paper
ItemBehaviorImpl={hostAttributes:{role:"option",tabindex:"0"}};Polymer.PaperItem
Behavior=[Polymer.IronButtonState,Polymer.IronControlState,Polymer.PaperItemBeha
viorImpl];Polymer({is:"paper-item",behaviors:[Polymer.PaperItemBehavior]});Polym
er.IronSelection=function(selectCallback){this.selection=[];this.selectCallback=
selectCallback};Polymer.IronSelection.prototype={get:function(){return this.mult
i?this.selection.slice():this.selection[0]},clear:function(excludes){this.select
ion.slice().forEach(function(item){if(!excludes||excludes.indexOf(item)<0){this.
setItemSelected(item,false)}},this)},isSelected:function(item){return this.selec
tion.indexOf(item)>=0},setItemSelected:function(item,isSelected){if(item!=null){
if(isSelected!==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(it
em){if(this.multi){this.toggle(item)}else if(this.get()!==item){this.setItemSele
cted(this.get(),false);this.setItemSelected(item,true)}},toggle:function(item){t
his.setItemSelected(item,!this.isSelected(item))}};Polymer.IronSelectableBehavio
r={properties:{attrForSelected:{type:String,value:null},selected:{type:String,no
tify:true},selectedItem:{type:Object,readOnly:true,notify:true},activateEvent:{t
ype:String,value:"tap",observer:"_activateEventChanged"},selectable:String,selec
tedClass:{type:String,value:"iron-selected"},selectedAttribute:{type:String,valu
e:null},fallbackSelection:{type:String,value:null},items:{type:Array,readOnly:tr
ue,notify:true,value:function(){return[]}},_excludedLocalNames:{type:Object,valu
e:function(){return{template:1}}}},observers:["_updateAttrForSelected(attrForSel
ected)","_updateSelected(selected)","_checkFallback(fallbackSelection)"],created
:function(){this._bindFilterItem=this._filterItem.bind(this);this._selection=new
Polymer.IronSelection(this._applySelection.bind(this))},attached:function(){thi
s._observer=this._observeItems(this);this._updateItems();if(!this._shouldUpdateS
election){this._updateSelected()}this._addListener(this.activateEvent)},detached
:function(){if(this._observer){Polymer.dom(this).unobserveNodes(this._observer)}
this._removeListener(this.activateEvent)},indexOf:function(item){return this.ite
ms.indexOf(item)},select:function(value){this.selected=value},selectPrevious:fun
ction(){var length=this.items.length;var index=(Number(this._valueToIndex(this.s
elected))-1+length)%length;this.selected=this._indexToValue(index)},selectNext:f
unction(){var index=(Number(this._valueToIndex(this.selected))+1)%this.items.len
gth;this.selected=this._indexToValue(index)},selectIndex:function(index){this.se
lect(this._indexToValue(index))},forceSynchronousItemUpdate:function(){this._upd
ateItems()},get _shouldUpdateSelection(){return this.selected!=null},_checkFallb
ack:function(){if(this._shouldUpdateSelection){this._updateSelected()}},_addList
ener:function(eventName){this.listen(this,eventName,"_activateHandler")},_remove
Listener:function(eventName){this.unlisten(this,eventName,"_activateHandler")},_
activateEventChanged:function(eventName,old){this._removeListener(old);this._add
Listener(eventName)},_updateItems:function(){var nodes=Polymer.dom(this).queryDi
stributedElements(this.selectable||"*");nodes=Array.prototype.filter.call(nodes,
this._bindFilterItem);this._setItems(nodes)},_updateAttrForSelected:function(){i
f(this._shouldUpdateSelection){this.selected=this._indexToValue(this.indexOf(thi
s.selectedItem))}},_updateSelected:function(){this._selectSelected(this.selected
)},_selectSelected:function(selected){this._selection.select(this._valueToItem(t
his.selected));if(this.fallbackSelection&&this.items.length&&this._selection.get
()===undefined){this.selected=this.fallbackSelection}},_filterItem:function(node
){return!this._excludedLocalNames[node.localName]},_valueToItem:function(value){
return value==null?null:this.items[this._valueToIndex(value)]},_valueToIndex:fun
ction(value){if(this.attrForSelected){for(var i=0,item;item=this.items[i];i++){i
f(this._valueForItem(item)==value){return i}}}else{return Number(value)}},_index
ToValue:function(index){if(this.attrForSelected){var item=this.items[index];if(i
tem){return this._valueForItem(item)}}else{return index}},_valueForItem:function
(item){var propValue=item[Polymer.CaseMap.dashToCamelCase(this.attrForSelected)]
;return propValue!=undefined?propValue:item.getAttribute(this.attrForSelected)},
_applySelection:function(item,isSelected){if(this.selectedClass){this.toggleClas
s(this.selectedClass,isSelected,item)}if(this.selectedAttribute){this.toggleAttr
ibute(this.selectedAttribute,isSelected,item)}this._selectionChange();this.fire(
"iron-"+(isSelected?"select":"deselect"),{item:item})},_selectionChange:function
(){this._setSelectedItem(this._selection.get())},_observeItems:function(node){re
turn Polymer.dom(node).observeNodes(function(mutation){this._updateItems();if(th
is._shouldUpdateSelection){this._updateSelected()}this.fire("iron-items-changed"
,mutation,{bubbles:false,cancelable:false})})},_activateHandler:function(e){var
t=e.target;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.parentN
ode}},_itemActivate:function(value,item){if(!this.fire("iron-activate",{selected
:value,item:item},{cancelable:true}).defaultPrevented){this.select(value)}}};Pol
ymer.IronMultiSelectableBehaviorImpl={properties:{multi:{type:Boolean,value:fals
e,observer:"multiChanged"},selectedValues:{type:Array,notify:true},selectedItems
:{type:Array,readOnly:true,notify:true}},observers:["_updateSelected(selectedVal
ues.splices)"],select:function(value){if(this.multi){if(this.selectedValues){thi
s._toggleSelected(value)}else{this.selectedValues=[value]}}else{this.selected=va
lue}},multiChanged:function(multi){this._selection.multi=multi},get _shouldUpdat
eSelection(){return this.selected!=null||this.selectedValues!=null&&this.selecte
dValues.length},_updateAttrForSelected:function(){if(!this.multi){Polymer.IronSe
lectableBehavior._updateAttrForSelected.apply(this)}else if(this._shouldUpdateSe
lection){this.selectedValues=this.selectedItems.map(function(selectedItem){retur
n this._indexToValue(this.indexOf(selectedItem))},this).filter(function(unfilter
edValue){return unfilteredValue!=null},this)}},_updateSelected:function(){if(thi
s.multi){this._selectMulti(this.selectedValues)}else{this._selectSelected(this.s
elected)}},_selectMulti:function(values){if(values){var selectedItems=this._valu
esToItems(values);this._selection.clear(selectedItems);for(var i=0;i<selectedIte
ms.length;i++){this._selection.setItemSelected(selectedItems[i],true)}if(this.fa
llbackSelection&&this.items.length&&!this._selection.get().length){var fallback=
this._valueToItem(this.fallbackSelection);if(fallback){this.selectedValues=[this
.fallbackSelection]}}}else{this._selection.clear()}},_selectionChange:function()
{var s=this._selection.get();if(this.multi){this._setSelectedItems(s)}else{this.
_setSelectedItems([s]);this._setSelectedItem(s)}},_toggleSelected:function(value
){var i=this.selectedValues.indexOf(value);var unselected=i<0;if(unselected){thi
s.push("selectedValues",value)}else{this.splice("selectedValues",i,1)}},_valuesT
oItems:function(values){return values==null?null:values.map(function(value){retu
rn this._valueToItem(value)},this)}};Polymer.IronMultiSelectableBehavior=[Polyme
r.IronSelectableBehavior,Polymer.IronMultiSelectableBehaviorImpl];Polymer.IronMe
nuBehaviorImpl={properties:{focusedItem:{observer:"_focusedItemChanged",readOnly
:true,type:Object},attrForItemTitle:{type:String}},hostAttributes:{role:"menu",t
abindex:"0"},observers:["_updateMultiselectable(multi)"],listeners:{focus:"_onFo
cus",keydown:"_onKeydown","iron-items-changed":"_onIronItemsChanged"},keyBinding
s:{up:"_onUpKey",down:"_onDownKey",esc:"_onEscKey","shift+tab:keydown":"_onShift
TabDown"},attached:function(){this._resetTabindices()},select:function(value){if
(this._defaultFocusAsync){this.cancelAsync(this._defaultFocusAsync);this._defaul
tFocusAsync=null}var item=this._valueToItem(value);if(item&&item.hasAttribute("d
isabled"))return;this._setFocusedItem(item);Polymer.IronMultiSelectableBehaviorI
mpl.select.apply(this,arguments)},_resetTabindices:function(){var selectedItem=t
his.multi?this.selectedItems&&this.selectedItems[0]:this.selectedItem;this.items
.forEach(function(item){item.setAttribute("tabindex",item===selectedItem?"0":"-1
")},this)},_updateMultiselectable:function(multi){if(multi){this.setAttribute("a
ria-multiselectable","true")}else{this.removeAttribute("aria-multiselectable")}}
,_focusWithKeyboardEvent:function(event){for(var i=0,item;item=this.items[i];i++
){var attr=this.attrForItemTitle||"textContent";var title=item[attr]||item.getAt
tribute(attr);if(!item.hasAttribute("disabled")&&title&&title.trim().charAt(0).t
oLowerCase()===String.fromCharCode(event.keyCode).toLowerCase()){this._setFocuse
dItem(item);break}}},_focusPrevious:function(){var length=this.items.length;var
curFocusIndex=Number(this.indexOf(this.focusedItem));for(var i=1;i<length+1;i++)
{var item=this.items[(curFocusIndex-i+length)%length];if(!item.hasAttribute("dis
abled")){var owner=Polymer.dom(item).getOwnerRoot()||document;this._setFocusedIt
em(item);if(Polymer.dom(owner).activeElement==item){return}}}},_focusNext:functi
on(){var length=this.items.length;var curFocusIndex=Number(this.indexOf(this.foc
usedItem));for(var i=1;i<length+1;i++){var item=this.items[(curFocusIndex+i)%len
gth];if(!item.hasAttribute("disabled")){var owner=Polymer.dom(item).getOwnerRoot
()||document;this._setFocusedItem(item);if(Polymer.dom(owner).activeElement==ite
m){return}}}},_applySelection:function(item,isSelected){if(isSelected){item.setA
ttribute("aria-selected","true")}else{item.removeAttribute("aria-selected")}Poly
mer.IronSelectableBehavior._applySelection.apply(this,arguments)},_focusedItemCh
anged:function(focusedItem,old){old&&old.setAttribute("tabindex","-1");if(focuse
dItem){focusedItem.setAttribute("tabindex","0");focusedItem.focus()}},_onIronIte
msChanged:function(event){if(event.detail.addedNodes.length){this._resetTabindic
es()}},_onShiftTabDown:function(event){var oldTabIndex=this.getAttribute("tabind
ex");Polymer.IronMenuBehaviorImpl._shiftTabPressed=true;this._setFocusedItem(nul
l);this.setAttribute("tabindex","-1");this.async(function(){this.setAttribute("t
abindex",oldTabIndex);Polymer.IronMenuBehaviorImpl._shiftTabPressed=false},1)},_
onFocus:function(event){if(Polymer.IronMenuBehaviorImpl._shiftTabPressed){return
}var rootTarget=Polymer.dom(event).rootTarget;if(rootTarget!==this&&typeof rootT
arget.tabIndex!=="undefined"&&!this.isLightDescendant(rootTarget)){return}this._
defaultFocusAsync=this.async(function(){var selectedItem=this.multi?this.selecte
dItems&&this.selectedItems[0]:this.selectedItem;this._setFocusedItem(null);if(se
lectedItem){this._setFocusedItem(selectedItem)}else if(this.items[0]){this._focu
sNext()}})},_onUpKey:function(event){this._focusPrevious();event.detail.keyboard
Event.preventDefault()},_onDownKey:function(event){this._focusNext();event.detai
l.keyboardEvent.preventDefault()},_onEscKey:function(event){this.focusedItem.blu
r()},_onKeydown:function(event){if(!this.keyboardEventMatchesKeys(event,"up down
esc")){this._focusWithKeyboardEvent(event)}event.stopPropagation()},_activateHa
ndler:function(event){Polymer.IronSelectableBehavior._activateHandler.call(this,
event);event.stopPropagation()}};Polymer.IronMenuBehaviorImpl._shiftTabPressed=f
alse;Polymer.IronMenuBehavior=[Polymer.IronMultiSelectableBehavior,Polymer.IronA
11yKeysBehavior,Polymer.IronMenuBehaviorImpl];(function(){Polymer({is:"paper-men
u",behaviors:[Polymer.IronMenuBehavior]})})();Polymer.IronFitBehavior={propertie
s:{sizingTarget:{type:Object,value:function(){return this}},fitInto:{type:Object
,value:window},noOverlap:{type:Boolean},positionTarget:{type:Element},horizontal
Align:{type:String},verticalAlign:{type:String},dynamicAlign:{type:Boolean},hori
zontalOffset:{type:Number,value:0,notify:true},verticalOffset:{type:Number,value
:0,notify:true},autoFitOnAttach:{type:Boolean,value:false},_fitInfo:{type:Object
}},get _fitWidth(){var fitWidth;if(this.fitInto===window){fitWidth=this.fitInto.
innerWidth}else{fitWidth=this.fitInto.getBoundingClientRect().width}return fitWi
dth},get _fitHeight(){var fitHeight;if(this.fitInto===window){fitHeight=this.fit
Into.innerHeight}else{fitHeight=this.fitInto.getBoundingClientRect().height}retu
rn fitHeight},get _fitLeft(){var fitLeft;if(this.fitInto===window){fitLeft=0}els
e{fitLeft=this.fitInto.getBoundingClientRect().left}return fitLeft},get _fitTop(
){var fitTop;if(this.fitInto===window){fitTop=0}else{fitTop=this.fitInto.getBoun
dingClientRect().top}return fitTop},get _defaultPositionTarget(){var parent=Poly
mer.dom(this).parentNode;if(parent&&parent.nodeType===Node.DOCUMENT_FRAGMENT_NOD
E){parent=parent.host}return parent},get _localeHorizontalAlign(){if(this._isRTL
){if(this.horizontalAlign==="right"){return"left"}if(this.horizontalAlign==="lef
t"){return"right"}}return this.horizontalAlign},attached:function(){this._isRTL=
window.getComputedStyle(this).direction=="rtl";this.positionTarget=this.position
Target||this._defaultPositionTarget;if(this.autoFitOnAttach){if(window.getComput
edStyle(this).display==="none"){setTimeout(function(){this.fit()}.bind(this))}el
se{this.fit()}}},fit:function(){this.position();this.constrain();this.center()},
_discoverInfo:function(){if(this._fitInfo){return}var target=window.getComputedS
tyle(this);var sizer=window.getComputedStyle(this.sizingTarget);this._fitInfo={i
nlineStyle:{top:this.style.top||"",left:this.style.left||"",position:this.style.
position||""},sizerInlineStyle:{maxWidth:this.sizingTarget.style.maxWidth||"",ma
xHeight:this.sizingTarget.style.maxHeight||"",boxSizing:this.sizingTarget.style.
boxSizing||""},positionedBy:{vertically:target.top!=="auto"?"top":target.bottom!
=="auto"?"bottom":null,horizontally:target.left!=="auto"?"left":target.right!=="
auto"?"right":null},sizedBy:{height:sizer.maxHeight!=="none",width:sizer.maxWidt
h!=="none",minWidth:parseInt(sizer.minWidth,10)||0,minHeight:parseInt(sizer.minH
eight,10)||0},margin:{top:parseInt(target.marginTop,10)||0,right:parseInt(target
.marginRight,10)||0,bottom:parseInt(target.marginBottom,10)||0,left:parseInt(tar
get.marginLeft,10)||0}};if(this.verticalOffset){this._fitInfo.margin.top=this._f
itInfo.margin.bottom=this.verticalOffset;this._fitInfo.inlineStyle.marginTop=thi
s.style.marginTop||"";this._fitInfo.inlineStyle.marginBottom=this.style.marginBo
ttom||"";this.style.marginTop=this.style.marginBottom=this.verticalOffset+"px"}i
f(this.horizontalOffset){this._fitInfo.margin.left=this._fitInfo.margin.right=th
is.horizontalOffset;this._fitInfo.inlineStyle.marginLeft=this.style.marginLeft||
"";this._fitInfo.inlineStyle.marginRight=this.style.marginRight||"";this.style.m
arginLeft=this.style.marginRight=this.horizontalOffset+"px"}},resetFit:function(
){var info=this._fitInfo||{};for(var property in info.sizerInlineStyle){this.siz
ingTarget.style[property]=info.sizerInlineStyle[property]}for(var property in in
fo.inlineStyle){this.style[property]=info.inlineStyle[property]}this._fitInfo=nu
ll},refit:function(){var scrollLeft=this.sizingTarget.scrollLeft;var scrollTop=t
his.sizingTarget.scrollTop;this.resetFit();this.fit();this.sizingTarget.scrollLe
ft=scrollLeft;this.sizingTarget.scrollTop=scrollTop},position:function(){if(!thi
s.horizontalAlign&&!this.verticalAlign){return}this._discoverInfo();this.style.p
osition="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.__getNormalizedR
ect(this.fitInto);var margin=this._fitInfo.margin;var size={width:rect.width+mar
gin.left+margin.right,height:rect.height+margin.top+margin.bottom};var position=
this.__getPosition(this._localeHorizontalAlign,this.verticalAlign,size,positionR
ect,fitRect);var left=position.left+margin.left;var top=position.top+margin.top;
var right=Math.min(fitRect.right-margin.right,left+rect.width);var bottom=Math.m
in(fitRect.bottom-margin.bottom,top+rect.height);var minWidth=this._fitInfo.size
dBy.minWidth;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
.style.maxWidth=right-left+"px";this.sizingTarget.style.maxHeight=bottom-top+"px
";this.style.left=left-rect.left+"px";this.style.top=top-rect.top+"px"},constrai
n:function(){if(this.horizontalAlign||this.verticalAlign){return}this._discoverI
nfo();var info=this._fitInfo;if(!info.positionedBy.vertically){this.style.positi
on="fixed";this.style.top="0px"}if(!info.positionedBy.horizontally){this.style.p
osition="fixed";this.style.left="0px"}this.sizingTarget.style.boxSizing="border-
box";var rect=this.getBoundingClientRect();if(!info.sizedBy.height){this.__sizeD
imension(rect,info.positionedBy.vertically,"top","bottom","Height")}if(!info.siz
edBy.width){this.__sizeDimension(rect,info.positionedBy.horizontally,"left","rig
ht","Width")}},_sizeDimension:function(rect,positionedBy,start,end,extent){this.
__sizeDimension(rect,positionedBy,start,end,extent)},__sizeDimension:function(re
ct,positionedBy,start,end,extent){var info=this._fitInfo;var fitRect=this.__getN
ormalizedRect(this.fitInto);var max=extent==="Width"?fitRect.width:fitRect.heigh
t;var flip=positionedBy===end;var offset=flip?max-rect[end]:rect[start];var marg
in=info.margin[flip?start:end];var offsetExtent="offset"+extent;var sizingOffset
=this[offsetExtent]-this.sizingTarget[offsetExtent];this.sizingTarget.style["max
"+extent]=max-margin-offset-sizingOffset+"px"},center:function(){if(this.horizon
talAlign||this.verticalAlign){return}this._discoverInfo();var positionedBy=this.
_fitInfo.positionedBy;if(positionedBy.vertically&&positionedBy.horizontally){ret
urn}this.style.position="fixed";if(!positionedBy.vertically){this.style.top="0px
"}if(!positionedBy.horizontally){this.style.left="0px"}var rect=this.getBounding
ClientRect();var fitRect=this.__getNormalizedRect(this.fitInto);if(!positionedBy
.vertically){var top=fitRect.top-rect.top+(fitRect.height-rect.height)/2;this.st
yle.top=top+"px"}if(!positionedBy.horizontally){var left=fitRect.left-rect.left+
(fitRect.width-rect.width)/2;this.style.left=left+"px"}},__getNormalizedRect:fun
ction(target){if(target===document.documentElement||target===window){return{top:
0,left:0,width:window.innerWidth,height:window.innerHeight,right:window.innerWid
th,bottom:window.innerHeight}}return target.getBoundingClientRect()},__getCroppe
dArea:function(position,size,fitRect){var verticalCrop=Math.min(0,position.top)+
Math.min(0,fitRect.bottom-(position.top+size.height));var horizontalCrop=Math.mi
n(0,position.left)+Math.min(0,fitRect.right-(position.left+size.width));return M
ath.abs(verticalCrop)*size.width+Math.abs(horizontalCrop)*size.height},__getPosi
tion:function(hAlign,vAlign,size,positionRect,fitRect){var positions=[{verticalA
lign:"top",horizontalAlign:"left",top:positionRect.top,left:positionRect.left},{
verticalAlign:"top",horizontalAlign:"right",top:positionRect.top,left:positionRe
ct.right-size.width},{verticalAlign:"bottom",horizontalAlign:"left",top:position
Rect.bottom-size.height,left:positionRect.left},{verticalAlign:"bottom",horizont
alAlign:"right",top:positionRect.bottom-size.height,left:positionRect.right-size
.width}];if(this.noOverlap){for(var i=0,l=positions.length;i<l;i++){var copy={};
for(var key in positions[i]){copy[key]=positions[i][key]}positions.push(copy)}po
sitions[0].top=positions[1].top+=positionRect.height;positions[2].top=positions[
3].top-=positionRect.height;positions[4].left=positions[6].left+=positionRect.wi
dth;positions[5].left=positions[7].left-=positionRect.width}vAlign=vAlign==="aut
o"?null:vAlign;hAlign=hAlign==="auto"?null:hAlign;var position;for(var i=0;i<pos
itions.length;i++){var pos=positions[i];if(!this.dynamicAlign&&!this.noOverlap&&
pos.verticalAlign===vAlign&&pos.horizontalAlign===hAlign){position=pos;break}var
alignOk=(!vAlign||pos.verticalAlign===vAlign)&&(!hAlign||pos.horizontalAlign===
hAlign);if(!this.dynamicAlign&&!alignOk){continue}position=position||pos;pos.cro
ppedArea=this.__getCroppedArea(pos,size,fitRect);var diff=pos.croppedArea-positi
on.croppedArea;if(diff<0||diff===0&&alignOk){position=pos}if(position.croppedAre
a===0&&alignOk){break}}return position}};(function(){"use strict";Polymer({is:"i
ron-overlay-backdrop",properties:{opened:{reflectToAttribute:true,type:Boolean,v
alue:false,observer:"_openedChanged"}},listeners:{transitionend:"_onTransitionen
d"},created:function(){this.__openedRaf=null},attached:function(){this.opened&&t
his._openedChanged(this.opened)},prepare:function(){if(this.opened&&!this.parent
Node){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)}
},_onTransitionend:function(event){if(event&&event.target===this){this.complete(
)}},_openedChanged:function(opened){if(opened){this.prepare()}else{var cs=window
.getComputedStyle(this);if(cs.transitionDuration==="0s"||cs.opacity==0){this.com
plete()}}if(!this.isAttached){return}if(this.__openedRaf){window.cancelAnimation
Frame(this.__openedRaf);this.__openedRaf=null}this.scrollTop=this.scrollTop;this
.__openedRaf=window.requestAnimationFrame(function(){this.__openedRaf=null;this.
toggleClass("opened",this.opened)}.bind(this))}})})();Polymer.IronOverlayManager
Class=function(){this._overlays=[];this._minimumZ=101;this._backdropElement=null
;Polymer.Gestures.add(document,"tap",this._onCaptureClick.bind(this));document.a
ddEventListener("focus",this._onCaptureFocus.bind(this),true);document.addEventL
istener("keydown",this._onCaptureKeyDown.bind(this),true)};Polymer.IronOverlayMa
nagerClass.prototype={constructor:Polymer.IronOverlayManagerClass,get backdropEl
ement(){if(!this._backdropElement){this._backdropElement=document.createElement(
"iron-overlay-backdrop")}return this._backdropElement},get deepActiveElement(){v
ar active=document.activeElement||document.body;while(active.root&&Polymer.dom(a
ctive.root).activeElement){active=Polymer.dom(active.root).activeElement}return
active},_bringOverlayAtIndexToFront:function(i){var overlay=this._overlays[i];if
(!overlay){return}var lastI=this._overlays.length-1;var currentOverlay=this._ove
rlays[lastI];if(currentOverlay&&this._shouldBeBehindOverlay(overlay,currentOverl
ay)){lastI--}if(i>=lastI){return}var minimumZ=Math.max(this.currentOverlayZ(),th
is._minimumZ);if(this._getZ(overlay)<=minimumZ){this._applyOverlayZ(overlay,mini
mumZ)}while(i<lastI){this._overlays[i]=this._overlays[i+1];i++}this._overlays[la
stI]=overlay},addOrRemoveOverlay:function(overlay){if(overlay.opened){this.addOv
erlay(overlay)}else{this.removeOverlay(overlay)}},addOverlay:function(overlay){v
ar i=this._overlays.indexOf(overlay);if(i>=0){this._bringOverlayAtIndexToFront(i
);this.trackBackdrop();return}var insertionIndex=this._overlays.length;var curre
ntOverlay=this._overlays[insertionIndex-1];var minimumZ=Math.max(this._getZ(curr
entOverlay),this._minimumZ);var newZ=this._getZ(overlay);if(currentOverlay&&this
._shouldBeBehindOverlay(overlay,currentOverlay)){this._applyOverlayZ(currentOver
lay,minimumZ);insertionIndex--;var previousOverlay=this._overlays[insertionIndex
-1];minimumZ=Math.max(this._getZ(previousOverlay),this._minimumZ)}if(newZ<=minim
umZ){this._applyOverlayZ(overlay,minimumZ)}this._overlays.splice(insertionIndex,
0,overlay);this.trackBackdrop()},removeOverlay:function(overlay){var i=this._ove
rlays.indexOf(overlay);if(i===-1){return}this._overlays.splice(i,1);this.trackBa
ckdrop()},currentOverlay:function(){var i=this._overlays.length-1;return this._o
verlays[i]},currentOverlayZ:function(){return this._getZ(this.currentOverlay())}
,ensureMinimumZ:function(minimumZ){this._minimumZ=Math.max(this._minimumZ,minimu
mZ)},focusOverlay:function(){var current=this.currentOverlay();if(current){curre
nt._applyFocus()}},trackBackdrop:function(){var overlay=this._overlayWithBackdro
p();if(!overlay&&!this._backdropElement){return}this.backdropElement.style.zInde
x=this._getZ(overlay)-1;this.backdropElement.opened=!!overlay},getBackdrops:func
tion(){var backdrops=[];for(var i=0;i<this._overlays.length;i++){if(this._overla
ys[i].withBackdrop){backdrops.push(this._overlays[i])}}return backdrops},backdro
pZ:function(){return this._getZ(this._overlayWithBackdrop())-1},_overlayWithBack
drop:function(){for(var i=0;i<this._overlays.length;i++){if(this._overlays[i].wi
thBackdrop){return this._overlays[i]}}},_getZ:function(overlay){var z=this._mini
mumZ;if(overlay){var z1=Number(overlay.style.zIndex||window.getComputedStyle(ove
rlay).zIndex);if(z1===z1){z=z1}}return z},_setZ:function(element,z){element.styl
e.zIndex=z},_applyOverlayZ:function(overlay,aboveZ){this._setZ(overlay,aboveZ+2)
},_overlayInPath:function(path){path=path||[];for(var i=0;i<path.length;i++){if(
path[i]._manager===this){return path[i]}}},_onCaptureClick:function(event){var o
verlay=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)}}
,_onCaptureKeyDown:function(event){var overlay=this.currentOverlay();if(overlay)
{if(Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(event,"esc")){overlay.
_onCaptureEsc(event)}else if(Polymer.IronA11yKeysBehavior.keyboardEventMatchesKe
ys(event,"tab")){overlay._onCaptureTab(event)}}},_shouldBeBehindOverlay:function
(overlay1,overlay2){return!overlay1.alwaysOnTop&&overlay2.alwaysOnTop}};Polymer.
IronOverlayManager=new Polymer.IronOverlayManagerClass;(function(){"use strict";
Polymer.IronOverlayBehaviorImpl={properties:{opened:{observer:"_openedChanged",t
ype:Boolean,value:false,notify:true},canceled:{observer:"_canceledChanged",readO
nly:true,type:Boolean,value:false},withBackdrop:{observer:"_withBackdropChanged"
,type:Boolean},noAutoFocus:{type:Boolean,value:false},noCancelOnEscKey:{type:Boo
lean,value:false},noCancelOnOutsideClick:{type:Boolean,value:false},closingReaso
n:{ | 2510 cr.define("downloads", function() { |
| 47 type:Object},restoreFocusOnClose:{type:Boolean,value:false},alwaysOnTop:{type:Bo
olean},_manager:{type:Object,value:Polymer.IronOverlayManager},_focusedChild:{ty
pe:Object}},listeners:{"iron-resize":"_onIronResize"},get backdropElement(){retu
rn this._manager.backdropElement},get _focusNode(){return this._focusedChild||Po
lymer.dom(this).querySelector("[autofocus]")||this},get _focusableNodes(){var FO
CUSABLE_WITH_DISABLED=["a[href]","area[href]","iframe","[tabindex]","[contentEdi
table=true]"];var FOCUSABLE_WITHOUT_DISABLED=["input","select","textarea","butto
n"];var selector=FOCUSABLE_WITH_DISABLED.join(':not([tabindex="-1"]),')+':not([t
abindex="-1"]),'+FOCUSABLE_WITHOUT_DISABLED.join(':not([disabled]):not([tabindex
="-1"]),')+':not([disabled]):not([tabindex="-1"])';var focusables=Polymer.dom(th
is).querySelectorAll(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.t
abIndex===0||a.tabIndex>b.tabIndex){return 1}return-1})},ready:function(){this._
_isAnimating=false;this.__shouldRemoveTabIndex=false;this.__firstFocusableNode=t
his.__lastFocusableNode=null;this.__raf=null;this.__restoreFocusNode=null;this._
ensureSetup()},attached:function(){if(this.opened){this._openedChanged(this.open
ed)}this._observer=Polymer.dom(this).observeNodes(this._onNodesChange)},detached
:function(){Polymer.dom(this).unobserveNodes(this._observer);this._observer=null
;if(this.__raf){window.cancelAnimationFrame(this.__raf);this.__raf=null}this._ma
nager.removeOverlay(this)},toggle:function(){this._setCanceled(false);this.opene
d=!this.opened},open:function(){this._setCanceled(false);this.opened=true},close
:function(){this._setCanceled(false);this.opened=false},cancel:function(event){v
ar cancelEvent=this.fire("iron-overlay-canceled",event,{cancelable:true});if(can
celEvent.defaultPrevented){return}this._setCanceled(true);this.opened=false},_en
sureSetup:function(){if(this._overlaySetup){return}this._overlaySetup=true;this.
style.outline="none";this.style.display="none"},_openedChanged:function(opened){
if(opened){this.removeAttribute("aria-hidden")}else{this.setAttribute("aria-hidd
en","true")}if(!this.isAttached){return}this.__isAnimating=true;this.__onNextAni
mationFrame(this.__openedChanged)},_canceledChanged:function(){this.closingReaso
n=this.closingReason||{};this.closingReason.canceled=this.canceled},_withBackdro
pChanged:function(){if(this.withBackdrop&&!this.hasAttribute("tabindex")){this.s
etAttribute("tabindex","-1");this.__shouldRemoveTabIndex=true}else if(this.__sho
uldRemoveTabIndex){this.removeAttribute("tabindex");this.__shouldRemoveTabIndex=
false}if(this.opened&&this.isAttached){this._manager.trackBackdrop()}},_prepareR
enderOpened:function(){this.__restoreFocusNode=this._manager.deepActiveElement;t
his._preparePositioning();this.refit();this._finishPositioning();if(this.noAutoF
ocus&&document.activeElement===this._focusNode){this._focusNode.blur();this.__re
storeFocusNode.focus()}},_renderOpened:function(){this._finishRenderOpened()},_r
enderClosed:function(){this._finishRenderClosed()},_finishRenderOpened:function(
){this.notifyResize();this.__isAnimating=false;var focusableNodes=this._focusabl
eNodes;this.__firstFocusableNode=focusableNodes[0];this.__lastFocusableNode=focu
sableNodes[focusableNodes.length-1];this.fire("iron-overlay-opened")},_finishRen
derClosed:function(){this.style.display="none";this.style.zIndex="";this.notifyR
esize();this.__isAnimating=false;this.fire("iron-overlay-closed",this.closingRea
son)},_preparePositioning:function(){this.style.transition=this.style.webkitTran
sition="none";this.style.transform=this.style.webkitTransform="none";this.style.
display=""},_finishPositioning:function(){this.style.display="none";this.scrollT
op=this.scrollTop;this.style.transition=this.style.webkitTransition="";this.styl
e.transform=this.style.webkitTransform="";this.style.display="";this.scrollTop=t
his.scrollTop},_applyFocus:function(){if(this.opened){if(!this.noAutoFocus){this
._focusNode.focus()}}else{this._focusNode.blur();this._focusedChild=null;if(this
.restoreFocusOnClose&&this.__restoreFocusNode){this.__restoreFocusNode.focus()}t
his.__restoreFocusNode=null;var currentOverlay=this._manager.currentOverlay();if
(currentOverlay&&this!==currentOverlay){currentOverlay._applyFocus()}}},_onCaptu
reClick:function(event){if(!this.noCancelOnOutsideClick){this.cancel(event)}},_o
nCaptureFocus:function(event){if(!this.withBackdrop){return}var path=Polymer.dom
(event).path;if(path.indexOf(this)===-1){event.stopPropagation();this._applyFocu
s()}else{this._focusedChild=path[0]}},_onCaptureEsc:function(event){if(!this.noC
ancelOnEscKey){this.cancel(event)}},_onCaptureTab:function(event){if(!this.withB
ackdrop){return}var shift=event.shiftKey;var nodeToCheck=shift?this.__firstFocus
ableNode:this.__lastFocusableNode;var nodeToSet=shift?this.__lastFocusableNode:t
his.__firstFocusableNode;var shouldWrap=false;if(nodeToCheck===nodeToSet){should
Wrap=true}else{var focusedNode=this._manager.deepActiveElement;shouldWrap=focuse
dNode===nodeToCheck||focusedNode===this}if(shouldWrap){event.preventDefault();th
is._focusedChild=nodeToSet;this._applyFocus()}},_onIronResize:function(){if(this
.opened&&!this.__isAnimating){this.__onNextAnimationFrame(this.refit)}},_onNodes
Change:function(){if(this.opened&&!this.__isAnimating){this.notifyResize()}},__o
penedChanged:function(){if(this.opened){this._prepareRenderOpened();this._manage
r.addOverlay(this);this._applyFocus();this._renderOpened()}else{this._manager.re
moveOverlay(this);this._applyFocus();this._renderClosed()}},__onNextAnimationFra
me:function(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.Ir
onFitBehavior,Polymer.IronResizableBehavior,Polymer.IronOverlayBehaviorImpl]})()
;Polymer.NeonAnimatableBehavior={properties:{animationConfig:{type:Object},entry
Animation:{observer:"_entryAnimationChanged",type:String},exitAnimation:{observe
r:"_exitAnimationChanged",type:String}},_entryAnimationChanged:function(){this.a
nimationConfig=this.animationConfig||{};this.animationConfig["entry"]=[{name:thi
s.entryAnimation,node:this}]},_exitAnimationChanged:function(){this.animationCon
fig=this.animationConfig||{};this.animationConfig["exit"]=[{name:this.exitAnimat
ion,node:this}]},_copyProperties:function(config1,config2){for(var property in c
onfig2){config1[property]=config2[property]}},_cloneConfig:function(config){var
clone={isClone:true};this._copyProperties(clone,config);return clone},_getAnimat
ionConfigRecursive:function(type,map,allConfigs){if(!this.animationConfig){retur
n}if(this.animationConfig.value&&typeof this.animationConfig.value==="function")
{this._warn(this._logf("playAnimation","Please put 'animationConfig' inside of y
our components 'properties' object instead of outside of it."));return}var thisC
onfig;if(type){thisConfig=this.animationConfig[type]}else{thisConfig=this.animat
ionConfig}if(!Array.isArray(thisConfig)){thisConfig=[thisConfig]}if(thisConfig){
for(var config,index=0;config=thisConfig[index];index++){if(config.animatable){c
onfig.animatable._getAnimationConfigRecursive(config.type||type,map,allConfigs)}
else{if(config.id){var cachedConfig=map[config.id];if(cachedConfig){if(!cachedCo
nfig.isClone){map[config.id]=this._cloneConfig(cachedConfig);cachedConfig=map[co
nfig.id]}this._copyProperties(cachedConfig,config)}else{map[config.id]=config}}e
lse{allConfigs.push(config)}}}}},getAnimationConfig:function(type){var map={};va
r allConfigs=[];this._getAnimationConfigRecursive(type,map,allConfigs);for(var k
ey in map){allConfigs.push(map[key])}return allConfigs}};Polymer.NeonAnimationRu
nnerBehaviorImpl={_configureAnimations:function(configs){var results=[];if(confi
gs.length>0){for(var config,index=0;config=configs[index];index++){var neonAnima
tion=document.createElement(config.name);if(neonAnimation.isNeonAnimation){var r
esult=null;try{result=neonAnimation.configure(config);if(typeof result.cancel!="
function"){result=document.timeline.play(result)}}catch(e){result=null;console.w
arn("Couldnt play","(",config.name,").",e)}if(result){results.push({neonAnimatio
n:neonAnimation,config:config,animation:result})}}else{console.warn(this.is+":",
config.name,"not found!")}}}return results},_shouldComplete:function(activeEntri
es){var finished=true;for(var i=0;i<activeEntries.length;i++){if(activeEntries[i
].animation.playState!="finished"){finished=false;break}}return finished},_compl
ete:function(activeEntries){for(var i=0;i<activeEntries.length;i++){activeEntrie
s[i].neonAnimation.complete(activeEntries[i].config)}for(var i=0;i<activeEntries
.length;i++){activeEntries[i].animation.cancel()}},playAnimation:function(type,c
ookie){var configs=this.getAnimationConfig(type);if(!configs){return}this._activ
e=this._active||{};if(this._active[type]){this._complete(this._active[type]);del
ete this._active[type]}var activeEntries=this._configureAnimations(configs);if(a
ctiveEntries.length==0){this.fire("neon-animation-finish",cookie,{bubbles:false}
);return}this._active[type]=activeEntries;for(var i=0;i<activeEntries.length;i++
){activeEntries[i].animation.onfinish=function(){if(this._shouldComplete(activeE
ntries)){this._complete(activeEntries);delete this._active[type];this.fire("neon
-animation-finish",cookie,{bubbles:false})}}.bind(this)}},cancelAnimation:functi
on(){for(var k in this._animations){this._animations[k].cancel()}this._animation
s={}}};Polymer.NeonAnimationRunnerBehavior=[Polymer.NeonAnimatableBehavior,Polym
er.NeonAnimationRunnerBehaviorImpl];Polymer.NeonAnimationBehavior={properties:{a
nimationTiming:{type:Object,value:function(){return{duration:500,easing:"cubic-b
ezier(0.4, 0, 0.2, 1)",fill:"both"}}}},isNeonAnimation:true,timingFromConfig:fun
ction(config){if(config.timing){for(var property in config.timing){this.animatio
nTiming[property]=config.timing[property]}}return this.animationTiming},setPrefi
xedProperty:function(node,property,value){var map={transform:["webkitTransform"]
,transformOrigin:["mozTransformOrigin","webkitTransformOrigin"]};var prefixes=ma
p[property];for(var prefix,index=0;prefix=prefixes[index];index++){node.style[pr
efix]=value}node.style[property]=value},complete:function(){}};Polymer({is:"opaq
ue-animation",behaviors:[Polymer.NeonAnimationBehavior],configure:function(confi
g){var node=config.node;this._effect=new KeyframeEffect(node,[{opacity:"1"},{opa
city:"1"}],this.timingFromConfig(config));node.style.opacity="0";return this._ef
fect},complete:function(config){config.node.style.opacity=""}});(function(){"use
strict";var LAST_TOUCH_POSITION={pageX:0,pageY:0};var ROOT_TARGET=null;var SCRO
LLABLE_NODES=[];Polymer.IronDropdownScrollManager={get currentLockingElement(){r
eturn this._lockingElements[this._lockingElements.length-1]},elementIsScrollLock
ed:function(element){var currentLockingElement=this.currentLockingElement;if(cur
rentLockingElement===undefined)return false;var scrollLocked;if(this._hasCachedL
ockedElement(element)){return true}if(this._hasCachedUnlockedElement(element)){r
eturn false}scrollLocked=!!currentLockingElement&¤tLockingElement!==elemen
t&&!this._composedTreeContains(currentLockingElement,element);if(scrollLocked){t
his._lockedElementCache.push(element)}else{this._unlockedElementCache.push(eleme
nt)}return scrollLocked},pushScrollLock:function(element){if(this._lockingElemen
ts.indexOf(element)>=0){return}if(this._lockingElements.length===0){this._lockSc
rollInteractions()}this._lockingElements.push(element);this._lockedElementCache=
[];this._unlockedElementCache=[]},removeScrollLock:function(element){var index=t
his._lockingElements.indexOf(element);if(index===-1){return}this._lockingElement
s.splice(index,1);this._lockedElementCache=[];this._unlockedElementCache=[];if(t
his._lockingElements.length===0){this._unlockScrollInteractions()}},_lockingElem
ents:[],_lockedElementCache:null,_unlockedElementCache:null,_hasCachedLockedElem
ent:function(element){return this._lockedElementCache.indexOf(element)>-1},_hasC
achedUnlockedElement:function(element){return this._unlockedElementCache.indexOf
(element)>-1},_composedTreeContains:function(element,child){var contentElements;
var distributedNodes;var contentIndex;var nodeIndex;if(element.contains(child)){
return true}contentElements=Polymer.dom(element).querySelectorAll("content");for
(contentIndex=0;contentIndex<contentElements.length;++contentIndex){distributedN
odes=Polymer.dom(contentElements[contentIndex]).getDistributedNodes();for(nodeIn
dex=0;nodeIndex<distributedNodes.length;++nodeIndex){if(this._composedTreeContai
ns(distributedNodes[nodeIndex],child)){return true}}}return false},_scrollIntera
ctionHandler:function(event){if(event.cancelable&&this._shouldPreventScrolling(e
vent)){event.preventDefault()}if(event.targetTouches){var touch=event.targetTouc
hes[0];LAST_TOUCH_POSITION.pageX=touch.pageX;LAST_TOUCH_POSITION.pageY=touch.pag
eY}},_lockScrollInteractions:function(){this._boundScrollHandler=this._boundScro
llHandler||this._scrollInteractionHandler.bind(this);document.addEventListener("
wheel",this._boundScrollHandler,true);document.addEventListener("mousewheel",thi
s._boundScrollHandler,true);document.addEventListener("DOMMouseScroll",this._bou
ndScrollHandler,true);document.addEventListener("touchstart",this._boundScrollHa
ndler,true);document.addEventListener("touchmove",this._boundScrollHandler,true)
},_unlockScrollInteractions:function(){document.removeEventListener("wheel",this
._boundScrollHandler,true);document.removeEventListener("mousewheel",this._bound
ScrollHandler,true);document.removeEventListener("DOMMouseScroll",this._boundScr
ollHandler,true);document.removeEventListener("touchstart",this._boundScrollHand
ler,true);document.removeEventListener("touchmove",this._boundScrollHandler,true
)},_shouldPreventScrolling:function(event){var target=Polymer.dom(event).rootTar
get;if(event.type!=="touchmove"&&ROOT_TARGET!==target){ROOT_TARGET=target;SCROLL
ABLE_NODES=this._getScrollableNodes(Polymer.dom(event).path)}if(!SCROLLABLE_NODE
S.length){return true}if(event.type==="touchstart"){return false}var info=this._
getScrollInfo(event);return!this._getScrollingNode(SCROLLABLE_NODES,info.deltaX,
info.deltaY)},_getScrollableNodes:function(nodes){var scrollables=[];var locking
Index=nodes.indexOf(this.currentLockingElement);for(var i=0;i<=lockingIndex;i++)
{var node=nodes[i];if(node.nodeType===11){continue}var style=node.style;if(style
.overflow!=="scroll"&&style.overflow!=="auto"){style=window.getComputedStyle(nod
e)}if(style.overflow==="scroll"||style.overflow==="auto"){scrollables.push(node)
}}return scrollables},_getScrollingNode:function(nodes,deltaX,deltaY){if(!deltaX
&&!deltaY){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)
{canScroll=deltaY<0?node.scrollTop>0:node.scrollTop<node.scrollHeight-node.clien
tHeight}else{canScroll=deltaX<0?node.scrollLeft>0:node.scrollLeft<node.scrollWid
th-node.clientWidth}if(canScroll){return node}}},_getScrollInfo:function(event){
var info={deltaX:event.deltaX,deltaY:event.deltaY};if("deltaX"in event){}else if
("wheelDeltaX"in event){info.deltaX=-event.wheelDeltaX;info.deltaY=-event.wheelD
eltaY}else if("axis"in event){info.deltaX=event.axis===1?event.detail:0;info.del
taY=event.axis===2?event.detail:0}else if(event.targetTouches){var touch=event.t
argetTouches[0];info.deltaX=LAST_TOUCH_POSITION.pageX-touch.pageX;info.deltaY=LA
ST_TOUCH_POSITION.pageY-touch.pageY}return info}}})();(function(){"use strict";P
olymer({is:"iron-dropdown",behaviors:[Polymer.IronControlState,Polymer.IronA11yK
eysBehavior,Polymer.IronOverlayBehavior,Polymer.NeonAnimationRunnerBehavior],pro
perties:{horizontalAlign:{type:String,value:"left",reflectToAttribute:true},vert
icalAlign:{type:String,value:"top",reflectToAttribute:true},openAnimationConfig:
{type:Object},closeAnimationConfig:{type:Object},focusTarget:{type:Object},noAni
mations:{type:Boolean,value:false},allowOutsideScroll:{type:Boolean,value:false}
,_boundOnCaptureScroll:{type:Function,value:function(){return this._onCaptureScr
oll.bind(this)}}},listeners:{"neon-animation-finish":"_onNeonAnimationFinish"},o
bservers:["_updateOverlayPosition(positionTarget, verticalAlign, horizontalAlign
, verticalOffset, horizontalOffset)"],get containedElement(){return Polymer.dom(
this.$.content).getDistributedNodes()[0]},get _focusTarget(){return this.focusTa
rget||this.containedElement},ready:function(){this._scrollTop=0;this._scrollLeft
=0;this._refitOnScrollRAF=null},attached:function(){if(!this.sizingTarget||this.
sizingTarget===this){this.sizingTarget=this.containedElement}},detached:function
(){this.cancelAnimation();document.removeEventListener("scroll",this._boundOnCap
tureScroll);Polymer.IronDropdownScrollManager.removeScrollLock(this)},_openedCha
nged:function(){if(this.opened&&this.disabled){this.cancel()}else{this.cancelAni
mation();this._updateAnimationConfig();this._saveScrollPosition();if(this.opened
){document.addEventListener("scroll",this._boundOnCaptureScroll);!this.allowOuts
ideScroll&&Polymer.IronDropdownScrollManager.pushScrollLock(this)}else{document.
removeEventListener("scroll",this._boundOnCaptureScroll);Polymer.IronDropdownScr
ollManager.removeScrollLock(this)}Polymer.IronOverlayBehaviorImpl._openedChanged
.apply(this,arguments)}},_renderOpened:function(){if(!this.noAnimations&&this.an
imationConfig.open){this.$.contentWrapper.classList.add("animating");this.playAn
imation("open")}else{Polymer.IronOverlayBehaviorImpl._renderOpened.apply(this,ar
guments)}},_renderClosed:function(){if(!this.noAnimations&&this.animationConfig.
close){this.$.contentWrapper.classList.add("animating");this.playAnimation("clos
e")}else{Polymer.IronOverlayBehaviorImpl._renderClosed.apply(this,arguments)}},_
onNeonAnimationFinish:function(){this.$.contentWrapper.classList.remove("animati
ng");if(this.opened){this._finishRenderOpened()}else{this._finishRenderClosed()}
},_onCaptureScroll:function(){if(!this.allowOutsideScroll){this._restoreScrollPo
sition()}else{this._refitOnScrollRAF&&window.cancelAnimationFrame(this._refitOnS
crollRAF);this._refitOnScrollRAF=window.requestAnimationFrame(this.refit.bind(th
is))}},_saveScrollPosition:function(){if(document.scrollingElement){this._scroll
Top=document.scrollingElement.scrollTop;this._scrollLeft=document.scrollingEleme
nt.scrollLeft}else{this._scrollTop=Math.max(document.documentElement.scrollTop,d
ocument.body.scrollTop);this._scrollLeft=Math.max(document.documentElement.scrol
lLeft,document.body.scrollLeft)}},_restoreScrollPosition:function(){if(document.
scrollingElement){document.scrollingElement.scrollTop=this._scrollTop;document.s
crollingElement.scrollLeft=this._scrollLeft}else{document.documentElement.scroll
Top=this._scrollTop;document.documentElement.scrollLeft=this._scrollLeft;documen
t.body.scrollTop=this._scrollTop;document.body.scrollLeft=this._scrollLeft}},_up
dateAnimationConfig:function(){var animations=(this.openAnimationConfig||[]).con
cat(this.closeAnimationConfig||[]);for(var i=0;i<animations.length;i++){animatio
ns[i].node=this.containedElement}this.animationConfig={open:this.openAnimationCo
nfig,close:this.closeAnimationConfig}},_updateOverlayPosition:function(){if(this
.isAttached){this.notifyResize()}},_applyFocus:function(){var focusTarget=this.f
ocusTarget||this.containedElement;if(focusTarget&&this.opened&&!this.noAutoFocus
){focusTarget.focus()}else{Polymer.IronOverlayBehaviorImpl._applyFocus.apply(thi
s,arguments)}}})})();Polymer({is:"fade-in-animation",behaviors:[Polymer.NeonAnim
ationBehavior],configure:function(config){var node=config.node;this._effect=new
KeyframeEffect(node,[{opacity:"0"},{opacity:"1"}],this.timingFromConfig(config))
;return this._effect}});Polymer({is:"fade-out-animation",behaviors:[Polymer.Neon
AnimationBehavior],configure:function(config){var node=config.node;this._effect=
new KeyframeEffect(node,[{opacity:"1"},{opacity:"0"}],this.timingFromConfig(conf
ig));return this._effect}});Polymer({is:"paper-menu-grow-height-animation",behav
iors:[Polymer.NeonAnimationBehavior],configure:function(config){var node=config.
node;var rect=node.getBoundingClientRect();var height=rect.height;this._effect=n
ew KeyframeEffect(node,[{height:height/2+"px"},{height:height+"px"}],this.timing
FromConfig(config));return this._effect}});Polymer({is:"paper-menu-grow-width-an
imation",behaviors:[Polymer.NeonAnimationBehavior],configure:function(config){va
r node=config.node;var rect=node.getBoundingClientRect();var width=rect.width;th
is._effect=new KeyframeEffect(node,[{width:width/2+"px"},{width:width+"px"}],thi
s.timingFromConfig(config));return this._effect}});Polymer({is:"paper-menu-shrin
k-width-animation",behaviors:[Polymer.NeonAnimationBehavior],configure:function(
config){var node=config.node;var rect=node.getBoundingClientRect();var width=rec
t.width;this._effect=new KeyframeEffect(node,[{width:width+"px"},{width:width-wi
dth/20+"px"}],this.timingFromConfig(config));return this._effect}});Polymer({is:
"paper-menu-shrink-height-animation",behaviors:[Polymer.NeonAnimationBehavior],c
onfigure:function(config){var node=config.node;var rect=node.getBoundingClientRe
ct();var height=rect.height;var top=rect.top;this.setPrefixedProperty(node,"tran
sformOrigin","0 0");this._effect=new KeyframeEffect(node,[{height:height+"px",tr
ansform:"translateY(0)"},{height:height/2+"px",transform:"translateY(-20px)"}],t
his.timingFromConfig(config));return this._effect}});(function(){"use strict";va
r config={ANIMATION_CUBIC_BEZIER:"cubic-bezier(.3,.95,.5,1)",MAX_ANIMATION_TIME_
MS:400};var PaperMenuButton=Polymer({is:"paper-menu-button",behaviors:[Polymer.I
ronA11yKeysBehavior,Polymer.IronControlState],properties:{opened:{type:Boolean,v
alue:false,notify:true,observer:"_openedChanged"},horizontalAlign:{type:String,v
alue:"left",reflectToAttribute:true},verticalAlign:{type:String,value:"top",refl
ectToAttribute:true},dynamicAlign:{type:Boolean},horizontalOffset:{type:Number,v
alue:0,notify:true},verticalOffset:{type:Number,value:0,notify:true},noOverlap:{
type:Boolean},noAnimations:{type:Boolean,value:false},ignoreSelect:{type:Boolean
,value:false},closeOnActivate:{type:Boolean,value:false},openAnimationConfig:{ty
pe:Object,value:function(){return[{name:"fade-in-animation",timing:{delay:100,du
ration:200}},{name:"paper-menu-grow-width-animation",timing:{delay:100,duration:
150,easing:config.ANIMATION_CUBIC_BEZIER}},{name:"paper-menu-grow-height-animati
on",timing:{delay:100,duration:275,easing:config.ANIMATION_CUBIC_BEZIER}}]}},clo
seAnimationConfig:{type:Object,value:function(){return[{name:"fade-out-animation
",timing:{duration:150}},{name:"paper-menu-shrink-width-animation",timing:{delay
:100,duration:50,easing:config.ANIMATION_CUBIC_BEZIER}},{name:"paper-menu-shrink
-height-animation",timing:{duration:200,easing:"ease-in"}}]}},allowOutsideScroll
:{type:Boolean,value:false},restoreFocusOnClose:{type:Boolean,value:true},_dropd
ownContent:{type:Object}},hostAttributes:{role:"group","aria-haspopup":"true"},l
isteners:{"iron-activate":"_onIronActivate","iron-select":"_onIronSelect"},get c
ontentElement(){return Polymer.dom(this.$.content).getDistributedNodes()[0]},tog
gle:function(){if(this.opened){this.close()}else{this.open()}},open:function(){i
f(this.disabled){return}this.$.dropdown.open()},close:function(){this.$.dropdown
.close()},_onIronSelect:function(event){if(!this.ignoreSelect){this.close()}},_o
nIronActivate:function(event){if(this.closeOnActivate){this.close()}},_openedCha
nged:function(opened,oldOpened){if(opened){this._dropdownContent=this.contentEle
ment;this.fire("paper-dropdown-open")}else if(oldOpened!=null){this.fire("paper-
dropdown-close")}},_disabledChanged:function(disabled){Polymer.IronControlState.
_disabledChanged.apply(this,arguments);if(disabled&&this.opened){this.close()}},
__onIronOverlayCanceled:function(event){var uiEvent=event.detail;var target=Poly
mer.dom(uiEvent).rootTarget;var trigger=this.$.trigger;var path=Polymer.dom(uiEv
ent).path;if(path.indexOf(trigger)>-1){event.preventDefault()}}});Object.keys(co
nfig).forEach(function(key){PaperMenuButton[key]=config[key]});Polymer.PaperMenu
Button=PaperMenuButton})();Polymer.PaperInkyFocusBehaviorImpl={observers:["_focu
sedChanged(receivedFocusFromKeyboard)"],_focusedChanged:function(receivedFocusFr
omKeyboard){if(receivedFocusFromKeyboard){this.ensureRipple()}if(this.hasRipple(
)){this._ripple.holdDown=receivedFocusFromKeyboard}},_createRipple:function(){va
r ripple=Polymer.PaperRippleBehavior._createRipple();ripple.id="ink";ripple.setA
ttribute("center","");ripple.classList.add("circle");return ripple}};Polymer.Pap
erInkyFocusBehavior=[Polymer.IronButtonState,Polymer.IronControlState,Polymer.Pa
perRippleBehavior,Polymer.PaperInkyFocusBehaviorImpl];Polymer({is:"paper-icon-bu
tton",hostAttributes:{role:"button",tabindex:"0"},behaviors:[Polymer.PaperInkyFo
cusBehavior],properties:{src:{type:String},icon:{type:String},alt:{type:String,o
bserver:"_altChanged"}},_altChanged:function(newValue,oldValue){var label=this.g
etAttribute("aria-label");if(!label||oldValue==label){this.setAttribute("aria-la
bel",newValue)}}});Polymer({is:"iron-media-query",properties:{queryMatches:{type
:Boolean,value:false,readOnly:true,notify:true},query:{type:String,observer:"que
ryChanged"},full:{type:Boolean,value:false},_boundMQHandler:{value:function(){re
turn this.queryHandler.bind(this)}},_mq:{value:null}},attached:function(){this.s
tyle.display="none";this.queryChanged()},detached:function(){this._remove()},_ad
d:function(){if(this._mq){this._mq.addListener(this._boundMQHandler)}},_remove:f
unction(){if(this._mq){this._mq.removeListener(this._boundMQHandler)}this._mq=nu
ll},queryChanged:function(){this._remove();var query=this.query;if(!query){retur
n}if(!this.full&&query[0]!=="("){query="("+query+")"}this._mq=window.matchMedia(
query);this._add();this.queryHandler(this._mq)},queryHandler:function(mq){this._
setQueryMatches(mq.matches)}});Polymer.PaperSpinnerBehavior={listeners:{animatio
nend:"__reset",webkitAnimationEnd:"__reset"},properties:{active:{type:Boolean,va
lue:false,reflectToAttribute:true,observer:"__activeChanged"},alt:{type:String,v
alue:"loading",observer:"__altChanged"},__coolingDown:{type:Boolean,value:false}
},__computeContainerClasses:function(active,coolingDown){return[active||coolingD
own?"active":"",coolingDown?"cooldown":""].join(" ")},__activeChanged:function(a
ctive,old){this.__setAriaHidden(!active);this.__coolingDown=!active&&old},__altC
hanged:function(alt){if(alt===this.getPropertyInfo("alt").value){this.alt=this.g
etAttribute("aria-label")||alt}else{this.__setAriaHidden(alt==="");this.setAttri
bute("aria-label",alt)}},__setAriaHidden:function(hidden){var attr="aria-hidden"
;if(hidden){this.setAttribute(attr,"true")}else{this.removeAttribute(attr)}},__r
eset:function(){this.active=false;this.__coolingDown=false}};Polymer({is:"paper-
spinner-lite",behaviors:[Polymer.PaperSpinnerBehavior]}); | 2511 var Item = Polymer({ |
| 2512 is: "downloads-item", |
| 2513 properties: { |
| 2514 data: {type: Object}, |
| 2515 completelyOnDisk_: { |
| 2516 computed: "computeCompletelyOnDisk_(" + |
| 2517 "data.state, data.file_externally_removed)", |
| 2518 type: Boolean, |
| 2519 value: true |
| 2520 }, |
| 2521 controlledBy_: { |
| 2522 computed: "computeControlledBy_(data.by_ext_id, data.by_ext_name)", |
| 2523 type: String, |
| 2524 value: "" |
| 2525 }, |
| 2526 isActive_: { |
| 2527 computed: "computeIsActive_(" + |
| 2528 "data.state, data.file_externally_removed)", |
| 2529 type: Boolean, |
| 2530 value: true |
| 2531 }, |
| 2532 isDangerous_: { |
| 2533 computed: "computeIsDangerous_(data.state)", |
| 2534 type: Boolean, |
| 2535 value: false |
| 2536 }, |
| 2537 isMalware_: { |
| 2538 computed: "computeIsMalware_(isDangerous_, data.danger_type)", |
| 2539 type: Boolean, |
| 2540 value: false |
| 2541 }, |
| 2542 isInProgress_: { |
| 2543 computed: "computeIsInProgress_(data.state)", |
| 2544 type: Boolean, |
| 2545 value: false |
| 2546 }, |
| 2547 pauseOrResumeText_: { |
| 2548 computed: "computePauseOrResumeText_(isInProgress_, data.resume)", |
| 2549 type: String |
| 2550 }, |
| 2551 showCancel_: { |
| 2552 computed: "computeShowCancel_(data.state)", |
| 2553 type: Boolean, |
| 2554 value: false |
| 2555 }, |
| 2556 showProgress_: { |
| 2557 computed: "computeShowProgress_(showCancel_, data.percent)", |
| 2558 type: Boolean, |
| 2559 value: false |
| 2560 } |
| 2561 }, |
| 2562 observers: [ |
| 2563 "observeControlledBy_(controlledBy_)", |
| 2564 "observeIsDangerous_(isDangerous_, data)" |
| 2565 ], |
| 2566 ready: function() { |
| 2567 this.content = this.$.content |
| 2568 }, |
| 2569 chopUrl_: function(url) { |
| 2570 return url.slice(0, 300) |
| 2571 }, |
| 2572 computeClass_: function() { |
| 2573 var classes = []; |
| 2574 if (this.isActive_) |
| 2575 classes.push("is-active"); |
| 2576 if (this.isDangerous_) |
| 2577 classes.push("dangerous"); |
| 2578 if (this.showProgress_) |
| 2579 classes.push("show-progress"); |
| 2580 return classes.join(" ") |
| 2581 }, |
| 2582 computeCompletelyOnDisk_: function() { |
| 2583 return this.data.state == downloads.States.COMPLETE && |
| 2584 !this.data.file_externally_removed |
| 2585 }, |
| 2586 computeControlledBy_: function() { |
| 2587 if (!this.data.by_ext_id || !this.data.by_ext_name) |
| 2588 return ""; |
| 2589 var url = "chrome://extensions#" + this.data.by_ext_id; |
| 2590 var name = this.data.by_ext_name; |
| 2591 return loadTimeData.getStringF("controlledByUrl", url, HTMLEscape(name)) |
| 2592 }, |
| 2593 computeDangerIcon_: function() { |
| 2594 return this.isDangerous_ ? "cr:warning" : "" |
| 2595 }, |
| 2596 computeDate_: function() { |
| 2597 assert(typeof this.data.hideDate == "boolean"); |
| 2598 if (this.data.hideDate) |
| 2599 return ""; |
| 2600 return assert(this.data.since_string || this.data.date_string) |
| 2601 }, |
| 2602 computeDescription_: function() { |
| 2603 var data = this.data; |
| 2604 switch (data.state) { |
| 2605 case downloads.States.DANGEROUS: |
| 2606 var fileName = data.file_name; |
| 2607 switch (data.danger_type) { |
| 2608 case downloads.DangerType.DANGEROUS_FILE: |
| 2609 return loadTimeData.getString("dangerFileDesc"); |
| 2610 case downloads.DangerType.DANGEROUS_URL: |
| 2611 case downloads.DangerType.DANGEROUS_CONTENT: |
| 2612 case downloads.DangerType.DANGEROUS_HOST: |
| 2613 return loadTimeData.getString("dangerDownloadDesc"); |
| 2614 case downloads.DangerType.UNCOMMON_CONTENT: |
| 2615 return loadTimeData.getString("dangerUncommonDesc"); |
| 2616 case downloads.DangerType.POTENTIALLY_UNWANTED: |
| 2617 return loadTimeData.getString("dangerSettingsDesc") |
| 2618 } |
| 2619 break; |
| 2620 case downloads.States.IN_PROGRESS: |
| 2621 case downloads.States.PAUSED: |
| 2622 return data.progress_status_text |
| 2623 } |
| 2624 return "" |
| 2625 }, |
| 2626 computeIsActive_: function() { |
| 2627 return this.data.state != downloads.States.CANCELLED && |
| 2628 this.data.state != downloads.States.INTERRUPTED && |
| 2629 !this.data.file_externally_removed |
| 2630 }, |
| 2631 computeIsDangerous_: function() { |
| 2632 return this.data.state == downloads.States.DANGEROUS |
| 2633 }, |
| 2634 computeIsInProgress_: function() { |
| 2635 return this.data.state == downloads.States.IN_PROGRESS |
| 2636 }, |
| 2637 computeIsMalware_: function() { |
| 2638 return this.isDangerous_ && |
| 2639 (this.data.danger_type == downloads.DangerType.DANGEROUS_CONTENT || |
| 2640 this.data.danger_type == downloads.DangerType.DANGEROUS_HOST || |
| 2641 this.data.danger_type == downloads.DangerType.DANGEROUS_URL || |
| 2642 this.data.danger_type == downloads.DangerType.POTENTIALLY_UNWANTED) |
| 2643 }, |
| 2644 computePauseOrResumeText_: function() { |
| 2645 if (this.isInProgress_) |
| 2646 return loadTimeData.getString("controlPause"); |
| 2647 if (this.data.resume) |
| 2648 return loadTimeData.getString("controlResume"); |
| 2649 return "" |
| 2650 }, |
| 2651 computeRemoveStyle_: function() { |
| 2652 var canDelete = loadTimeData.getBoolean("allowDeletingHistory"); |
| 2653 var hideRemove = this.isDangerous_ || this.showCancel_ || !canDelete; |
| 2654 return hideRemove ? "visibility: hidden" : "" |
| 2655 }, |
| 2656 computeShowCancel_: function() { |
| 2657 return this.data.state == downloads.States.IN_PROGRESS || |
| 2658 this.data.state == downloads.States.PAUSED |
| 2659 }, |
| 2660 computeShowProgress_: function() { |
| 2661 return this.showCancel_ && this.data.percent >= -1 |
| 2662 }, |
| 2663 computeTag_: function() { |
| 2664 switch (this.data.state) { |
| 2665 case downloads.States.CANCELLED: |
| 2666 return loadTimeData.getString("statusCancelled"); |
| 2667 case downloads.States.INTERRUPTED: |
| 2668 return this.data.last_reason_text; |
| 2669 case downloads.States.COMPLETE: |
| 2670 return this.data.file_externally_removed ? |
| 2671 loadTimeData.getString("statusRemoved") : |
| 2672 "" |
| 2673 } |
| 2674 return "" |
| 2675 }, |
| 2676 isIndeterminate_: function() { |
| 2677 return this.data.percent == -1 |
| 2678 }, |
| 2679 observeControlledBy_: function() { |
| 2680 this.$["controlled-by"].innerHTML = this.controlledBy_ |
| 2681 }, |
| 2682 observeIsDangerous_: function() { |
| 2683 if (!this.data) |
| 2684 return; |
| 2685 if (this.isDangerous_) { |
| 2686 this.$.url.removeAttribute("href") |
| 2687 } else { |
| 2688 this.$.url.href = assert(this.data.url); |
| 2689 var filePath = encodeURIComponent(this.data.file_path); |
| 2690 var scaleFactor = "?scale=" + window.devicePixelRatio + "x"; |
| 2691 this.$["file-icon"].src = "chrome://fileicon/" + filePath + scaleFactor |
| 2692 } |
| 2693 }, |
| 2694 onCancelTap_: function() { |
| 2695 downloads.ActionService.getInstance().cancel(this.data.id) |
| 2696 }, |
| 2697 onDiscardDangerousTap_: function() { |
| 2698 downloads.ActionService.getInstance().discardDangerous(this.data.id) |
| 2699 }, |
| 2700 onDragStart_: function(e) { |
| 2701 e.preventDefault(); |
| 2702 downloads.ActionService.getInstance().drag(this.data.id) |
| 2703 }, |
| 2704 onFileLinkTap_: function(e) { |
| 2705 e.preventDefault(); |
| 2706 downloads.ActionService.getInstance().openFile(this.data.id) |
| 2707 }, |
| 2708 onPauseOrResumeTap_: function() { |
| 2709 if (this.isInProgress_) |
| 2710 downloads.ActionService.getInstance().pause(this.data.id); |
| 2711 else |
| 2712 downloads.ActionService.getInstance().resume(this.data.id) |
| 2713 }, |
| 2714 onRemoveTap_: function() { |
| 2715 downloads.ActionService.getInstance().remove(this.data.id) |
| 2716 }, |
| 2717 onRetryTap_: function() { |
| 2718 downloads.ActionService.getInstance().download(this.data.url) |
| 2719 }, |
| 2720 onSaveDangerousTap_: function() { |
| 2721 downloads.ActionService.getInstance().saveDangerous(this.data.id) |
| 2722 }, |
| 2723 onShowTap_: function() { |
| 2724 downloads.ActionService.getInstance().show(this.data.id) |
| 2725 } |
| 2726 }); |
| 2727 return { |
| 2728 Item: Item |
| 2729 } |
| 2730 }); |
| 2731 Polymer.PaperItemBehaviorImpl = { |
| 2732 hostAttributes: {role: "option", tabindex: "0"} |
| 2733 }; |
| 2734 Polymer.PaperItemBehavior = [ |
| 2735 Polymer.IronButtonState, Polymer.IronControlState, |
| 2736 Polymer.PaperItemBehaviorImpl |
| 2737 ]; |
| 2738 Polymer({is: "paper-item", behaviors: [Polymer.PaperItemBehavior]}); |
| 2739 Polymer.IronSelection = function(selectCallback) { |
| 2740 this.selection = []; |
| 2741 this.selectCallback = selectCallback |
| 2742 }; |
| 2743 Polymer.IronSelection.prototype = { |
| 2744 get: function() { |
| 2745 return this.multi ? this.selection.slice() : this.selection[0] |
| 2746 }, |
| 2747 clear: function(excludes) { |
| 2748 this.selection.slice().forEach(function(item) { |
| 2749 if (!excludes || excludes.indexOf(item) < 0) { |
| 2750 this.setItemSelected(item, false) |
| 2751 } |
| 2752 }, this) |
| 2753 }, |
| 2754 isSelected: function(item) { |
| 2755 return this.selection.indexOf(item) >= 0 |
| 2756 }, |
| 2757 setItemSelected: function(item, isSelected) { |
| 2758 if (item != null) { |
| 2759 if (isSelected !== this.isSelected(item)) { |
| 2760 if (isSelected) { |
| 2761 this.selection.push(item) |
| 2762 } else { |
| 2763 var i = this.selection.indexOf(item); |
| 2764 if (i >= 0) { |
| 2765 this.selection.splice(i, 1) |
| 2766 } |
| 2767 } |
| 2768 if (this.selectCallback) { |
| 2769 this.selectCallback(item, isSelected) |
| 2770 } |
| 2771 } |
| 2772 } |
| 2773 }, |
| 2774 select: function(item) { |
| 2775 if (this.multi) { |
| 2776 this.toggle(item) |
| 2777 } else if (this.get() !== item) { |
| 2778 this.setItemSelected(this.get(), false); |
| 2779 this.setItemSelected(item, true) |
| 2780 } |
| 2781 }, |
| 2782 toggle: function(item) { |
| 2783 this.setItemSelected(item, !this.isSelected(item)) |
| 2784 } |
| 2785 }; |
| 2786 Polymer.IronSelectableBehavior = { |
| 2787 properties: { |
| 2788 attrForSelected: {type: String, value: null}, |
| 2789 selected: {type: String, notify: true}, |
| 2790 selectedItem: {type: Object, readOnly: true, notify: true}, |
| 2791 activateEvent: |
| 2792 {type: String, value: "tap", observer: "_activateEventChanged"}, |
| 2793 selectable: String, |
| 2794 selectedClass: {type: String, value: "iron-selected"}, |
| 2795 selectedAttribute: {type: String, value: null}, |
| 2796 fallbackSelection: {type: String, value: null}, |
| 2797 items: { |
| 2798 type: Array, |
| 2799 readOnly: true, |
| 2800 notify: true, |
| 2801 value: function() { |
| 2802 return [] |
| 2803 } |
| 2804 }, |
| 2805 _excludedLocalNames: { |
| 2806 type: Object, |
| 2807 value: function() { |
| 2808 return { |
| 2809 template: 1 |
| 2810 } |
| 2811 } |
| 2812 } |
| 2813 }, |
| 2814 observers: [ |
| 2815 "_updateAttrForSelected(attrForSelected)", "_updateSelected(selected)", |
| 2816 "_checkFallback(fallbackSelection)" |
| 2817 ], |
| 2818 created: function() { |
| 2819 this._bindFilterItem = this._filterItem.bind(this); |
| 2820 this._selection = new Polymer.IronSelection(this._applySelection.bind(this)) |
| 2821 }, |
| 2822 attached: function() { |
| 2823 this._observer = this._observeItems(this); |
| 2824 this._updateItems(); |
| 2825 if (!this._shouldUpdateSelection) { |
| 2826 this._updateSelected() |
| 2827 } |
| 2828 this._addListener(this.activateEvent) |
| 2829 }, |
| 2830 detached: function() { |
| 2831 if (this._observer) { |
| 2832 Polymer.dom(this).unobserveNodes(this._observer) |
| 2833 } |
| 2834 this._removeListener(this.activateEvent) |
| 2835 }, |
| 2836 indexOf: function(item) { |
| 2837 return this.items.indexOf(item) |
| 2838 }, |
| 2839 select: function(value) { |
| 2840 this.selected = value |
| 2841 }, |
| 2842 selectPrevious: function() { |
| 2843 var length = this.items.length; |
| 2844 var index = |
| 2845 (Number(this._valueToIndex(this.selected)) - 1 + length) % length; |
| 2846 this.selected = this._indexToValue(index) |
| 2847 }, |
| 2848 selectNext: function() { |
| 2849 var index = |
| 2850 (Number(this._valueToIndex(this.selected)) + 1) % this.items.length; |
| 2851 this.selected = this._indexToValue(index) |
| 2852 }, |
| 2853 selectIndex: function(index) { |
| 2854 this.select(this._indexToValue(index)) |
| 2855 }, |
| 2856 forceSynchronousItemUpdate: function() { |
| 2857 this._updateItems() |
| 2858 }, |
| 2859 get _shouldUpdateSelection() { |
| 2860 return this.selected != null |
| 2861 }, |
| 2862 _checkFallback: function() { |
| 2863 if (this._shouldUpdateSelection) { |
| 2864 this._updateSelected() |
| 2865 } |
| 2866 }, |
| 2867 _addListener: function(eventName) { |
| 2868 this.listen(this, eventName, "_activateHandler") |
| 2869 }, |
| 2870 _removeListener: function(eventName) { |
| 2871 this.unlisten(this, eventName, "_activateHandler") |
| 2872 }, |
| 2873 _activateEventChanged: function(eventName, old) { |
| 2874 this._removeListener(old); |
| 2875 this._addListener(eventName) |
| 2876 }, |
| 2877 _updateItems: function() { |
| 2878 var nodes = |
| 2879 Polymer.dom(this).queryDistributedElements(this.selectable || "*"); |
| 2880 nodes = Array.prototype.filter.call(nodes, this._bindFilterItem); |
| 2881 this._setItems(nodes) |
| 2882 }, |
| 2883 _updateAttrForSelected: function() { |
| 2884 if (this._shouldUpdateSelection) { |
| 2885 this.selected = this._indexToValue(this.indexOf(this.selectedItem)) |
| 2886 } |
| 2887 }, |
| 2888 _updateSelected: function() { |
| 2889 this._selectSelected(this.selected) |
| 2890 }, |
| 2891 _selectSelected: function(selected) { |
| 2892 this._selection.select(this._valueToItem(this.selected)); |
| 2893 if (this.fallbackSelection && this.items.length && |
| 2894 this._selection.get() === undefined) { |
| 2895 this.selected = this.fallbackSelection |
| 2896 } |
| 2897 }, |
| 2898 _filterItem: function(node) { |
| 2899 return !this._excludedLocalNames[node.localName] |
| 2900 }, |
| 2901 _valueToItem: function(value) { |
| 2902 return value == null ? null : this.items[this._valueToIndex(value)] |
| 2903 }, |
| 2904 _valueToIndex: function(value) { |
| 2905 if (this.attrForSelected) { |
| 2906 for (var i = 0, item; item = this.items[i]; i++) { |
| 2907 if (this._valueForItem(item) == value) { |
| 2908 return i |
| 2909 } |
| 2910 } |
| 2911 } else { |
| 2912 return Number(value) |
| 2913 } |
| 2914 }, |
| 2915 _indexToValue: function(index) { |
| 2916 if (this.attrForSelected) { |
| 2917 var item = this.items[index]; |
| 2918 if (item) { |
| 2919 return this._valueForItem(item) |
| 2920 } |
| 2921 } else { |
| 2922 return index |
| 2923 } |
| 2924 }, |
| 2925 _valueForItem: function(item) { |
| 2926 var propValue = item[Polymer.CaseMap.dashToCamelCase(this.attrForSelected)]; |
| 2927 return propValue != undefined ? propValue : |
| 2928 item.getAttribute(this.attrForSelected) |
| 2929 }, |
| 2930 _applySelection: function(item, isSelected) { |
| 2931 if (this.selectedClass) { |
| 2932 this.toggleClass(this.selectedClass, isSelected, item) |
| 2933 } |
| 2934 if (this.selectedAttribute) { |
| 2935 this.toggleAttribute(this.selectedAttribute, isSelected, item) |
| 2936 } |
| 2937 this._selectionChange(); |
| 2938 this.fire("iron-" + (isSelected ? "select" : "deselect"), {item: item}) |
| 2939 }, |
| 2940 _selectionChange: function() { |
| 2941 this._setSelectedItem(this._selection.get()) |
| 2942 }, |
| 2943 _observeItems: function(node) { |
| 2944 return Polymer.dom(node).observeNodes(function(mutation) { |
| 2945 this._updateItems(); |
| 2946 if (this._shouldUpdateSelection) { |
| 2947 this._updateSelected() |
| 2948 } |
| 2949 this.fire( |
| 2950 "iron-items-changed", mutation, {bubbles: false, cancelable: false}) |
| 2951 }) |
| 2952 }, |
| 2953 _activateHandler: function(e) { |
| 2954 var t = e.target; |
| 2955 var items = this.items; |
| 2956 while (t && t != this) { |
| 2957 var i = items.indexOf(t); |
| 2958 if (i >= 0) { |
| 2959 var value = this._indexToValue(i); |
| 2960 this._itemActivate(value, t); |
| 2961 return |
| 2962 } |
| 2963 t = t.parentNode |
| 2964 } |
| 2965 }, |
| 2966 _itemActivate: function(value, item) { |
| 2967 if (!this.fire( |
| 2968 "iron-activate", {selected: value, item: item}, |
| 2969 {cancelable: true}) |
| 2970 .defaultPrevented) { |
| 2971 this.select(value) |
| 2972 } |
| 2973 } |
| 2974 }; |
| 2975 Polymer.IronMultiSelectableBehaviorImpl = { |
| 2976 properties: { |
| 2977 multi: {type: Boolean, value: false, observer: "multiChanged"}, |
| 2978 selectedValues: {type: Array, notify: true}, |
| 2979 selectedItems: {type: Array, readOnly: true, notify: true} |
| 2980 }, |
| 2981 observers: ["_updateSelected(selectedValues.splices)"], |
| 2982 select: function(value) { |
| 2983 if (this.multi) { |
| 2984 if (this.selectedValues) { |
| 2985 this._toggleSelected(value) |
| 2986 } else { |
| 2987 this.selectedValues = [value] |
| 2988 } |
| 2989 } else { |
| 2990 this.selected = value |
| 2991 } |
| 2992 }, |
| 2993 multiChanged: function(multi) { |
| 2994 this._selection.multi = multi |
| 2995 }, |
| 2996 get _shouldUpdateSelection() { |
| 2997 return this.selected != null || |
| 2998 this.selectedValues != null && this.selectedValues.length |
| 2999 }, |
| 3000 _updateAttrForSelected: function() { |
| 3001 if (!this.multi) { |
| 3002 Polymer.IronSelectableBehavior._updateAttrForSelected.apply(this) |
| 3003 } else if (this._shouldUpdateSelection) { |
| 3004 this.selectedValues = |
| 3005 this.selectedItems |
| 3006 .map( |
| 3007 function(selectedItem) { |
| 3008 return this._indexToValue(this.indexOf(selectedItem)) |
| 3009 }, |
| 3010 this) |
| 3011 .filter(function(unfilteredValue) { |
| 3012 return unfilteredValue != null |
| 3013 }, this) |
| 3014 } |
| 3015 }, |
| 3016 _updateSelected: function() { |
| 3017 if (this.multi) { |
| 3018 this._selectMulti(this.selectedValues) |
| 3019 } else { |
| 3020 this._selectSelected(this.selected) |
| 3021 } |
| 3022 }, |
| 3023 _selectMulti: function(values) { |
| 3024 if (values) { |
| 3025 var selectedItems = this._valuesToItems(values); |
| 3026 this._selection.clear(selectedItems); |
| 3027 for (var i = 0; i < selectedItems.length; i++) { |
| 3028 this._selection.setItemSelected(selectedItems[i], true) |
| 3029 } |
| 3030 if (this.fallbackSelection && this.items.length && |
| 3031 !this._selection.get().length) { |
| 3032 var fallback = this._valueToItem(this.fallbackSelection); |
| 3033 if (fallback) { |
| 3034 this.selectedValues = [this.fallbackSelection] |
| 3035 } |
| 3036 } |
| 3037 } else { |
| 3038 this._selection.clear() |
| 3039 } |
| 3040 }, |
| 3041 _selectionChange: function() { |
| 3042 var s = this._selection.get(); |
| 3043 if (this.multi) { |
| 3044 this._setSelectedItems(s) |
| 3045 } else { |
| 3046 this._setSelectedItems([s]); |
| 3047 this._setSelectedItem(s) |
| 3048 } |
| 3049 }, |
| 3050 _toggleSelected: function(value) { |
| 3051 var i = this.selectedValues.indexOf(value); |
| 3052 var unselected = i < 0; |
| 3053 if (unselected) { |
| 3054 this.push("selectedValues", value) |
| 3055 } else { |
| 3056 this.splice("selectedValues", i, 1) |
| 3057 } |
| 3058 }, |
| 3059 _valuesToItems: function(values) { |
| 3060 return values == null ? null : values.map(function(value) { |
| 3061 return this._valueToItem(value) |
| 3062 }, this) |
| 3063 } |
| 3064 }; |
| 3065 Polymer.IronMultiSelectableBehavior = |
| 3066 [Polymer.IronSelectableBehavior, Polymer.IronMultiSelectableBehaviorImpl]; |
| 3067 Polymer.IronMenuBehaviorImpl = { |
| 3068 properties: { |
| 3069 focusedItem: |
| 3070 {observer: "_focusedItemChanged", readOnly: true, type: Object}, |
| 3071 attrForItemTitle: {type: String} |
| 3072 }, |
| 3073 hostAttributes: {role: "menu", tabindex: "0"}, |
| 3074 observers: ["_updateMultiselectable(multi)"], |
| 3075 listeners: { |
| 3076 focus: "_onFocus", |
| 3077 keydown: "_onKeydown", |
| 3078 "iron-items-changed": "_onIronItemsChanged" |
| 3079 }, |
| 3080 keyBindings: { |
| 3081 up: "_onUpKey", |
| 3082 down: "_onDownKey", |
| 3083 esc: "_onEscKey", |
| 3084 "shift+tab:keydown": "_onShiftTabDown" |
| 3085 }, |
| 3086 attached: function() { |
| 3087 this._resetTabindices() |
| 3088 }, |
| 3089 select: function(value) { |
| 3090 if (this._defaultFocusAsync) { |
| 3091 this.cancelAsync(this._defaultFocusAsync); |
| 3092 this._defaultFocusAsync = null |
| 3093 } |
| 3094 var item = this._valueToItem(value); |
| 3095 if (item && item.hasAttribute("disabled")) |
| 3096 return; |
| 3097 this._setFocusedItem(item); |
| 3098 Polymer.IronMultiSelectableBehaviorImpl.select.apply(this, arguments) |
| 3099 }, |
| 3100 _resetTabindices: function() { |
| 3101 var selectedItem = this.multi ? |
| 3102 this.selectedItems && this.selectedItems[0] : |
| 3103 this.selectedItem; |
| 3104 this.items.forEach(function(item) { |
| 3105 item.setAttribute("tabindex", item === selectedItem ? "0" : "-1") |
| 3106 }, this) |
| 3107 }, |
| 3108 _updateMultiselectable: function(multi) { |
| 3109 if (multi) { |
| 3110 this.setAttribute("aria-multiselectable", "true") |
| 3111 } else { |
| 3112 this.removeAttribute("aria-multiselectable") |
| 3113 } |
| 3114 }, |
| 3115 _focusWithKeyboardEvent: function(event) { |
| 3116 for (var i = 0, item; item = this.items[i]; i++) { |
| 3117 var attr = this.attrForItemTitle || "textContent"; |
| 3118 var title = item[attr] || item.getAttribute(attr); |
| 3119 if (!item.hasAttribute("disabled") && title && |
| 3120 title.trim().charAt(0).toLowerCase() === |
| 3121 String.fromCharCode(event.keyCode).toLowerCase()) { |
| 3122 this._setFocusedItem(item); |
| 3123 break |
| 3124 } |
| 3125 } |
| 3126 }, |
| 3127 _focusPrevious: function() { |
| 3128 var length = this.items.length; |
| 3129 var curFocusIndex = Number(this.indexOf(this.focusedItem)); |
| 3130 for (var i = 1; i < length + 1; i++) { |
| 3131 var item = this.items[(curFocusIndex - i + length) % length]; |
| 3132 if (!item.hasAttribute("disabled")) { |
| 3133 var owner = Polymer.dom(item).getOwnerRoot() || document; |
| 3134 this._setFocusedItem(item); |
| 3135 if (Polymer.dom(owner).activeElement == item) { |
| 3136 return |
| 3137 } |
| 3138 } |
| 3139 } |
| 3140 }, |
| 3141 _focusNext: function() { |
| 3142 var length = this.items.length; |
| 3143 var curFocusIndex = Number(this.indexOf(this.focusedItem)); |
| 3144 for (var i = 1; i < length + 1; i++) { |
| 3145 var item = this.items[(curFocusIndex + i) % length]; |
| 3146 if (!item.hasAttribute("disabled")) { |
| 3147 var owner = Polymer.dom(item).getOwnerRoot() || document; |
| 3148 this._setFocusedItem(item); |
| 3149 if (Polymer.dom(owner).activeElement == item) { |
| 3150 return |
| 3151 } |
| 3152 } |
| 3153 } |
| 3154 }, |
| 3155 _applySelection: function(item, isSelected) { |
| 3156 if (isSelected) { |
| 3157 item.setAttribute("aria-selected", "true") |
| 3158 } else { |
| 3159 item.removeAttribute("aria-selected") |
| 3160 } |
| 3161 Polymer.IronSelectableBehavior._applySelection.apply(this, arguments) |
| 3162 }, |
| 3163 _focusedItemChanged: function(focusedItem, old) { |
| 3164 old && old.setAttribute("tabindex", "-1"); |
| 3165 if (focusedItem) { |
| 3166 focusedItem.setAttribute("tabindex", "0"); |
| 3167 focusedItem.focus() |
| 3168 } |
| 3169 }, |
| 3170 _onIronItemsChanged: function(event) { |
| 3171 if (event.detail.addedNodes.length) { |
| 3172 this._resetTabindices() |
| 3173 } |
| 3174 }, |
| 3175 _onShiftTabDown: function(event) { |
| 3176 var oldTabIndex = this.getAttribute("tabindex"); |
| 3177 Polymer.IronMenuBehaviorImpl._shiftTabPressed = true; |
| 3178 this._setFocusedItem(null); |
| 3179 this.setAttribute("tabindex", "-1"); |
| 3180 this.async(function() { |
| 3181 this.setAttribute("tabindex", oldTabIndex); |
| 3182 Polymer.IronMenuBehaviorImpl._shiftTabPressed = false |
| 3183 }, 1) |
| 3184 }, |
| 3185 _onFocus: function(event) { |
| 3186 if (Polymer.IronMenuBehaviorImpl._shiftTabPressed) { |
| 3187 return |
| 3188 } |
| 3189 var rootTarget = Polymer.dom(event).rootTarget; |
| 3190 if (rootTarget !== this && typeof rootTarget.tabIndex !== "undefined" && |
| 3191 !this.isLightDescendant(rootTarget)) { |
| 3192 return |
| 3193 } |
| 3194 this._defaultFocusAsync = this.async(function() { |
| 3195 var selectedItem = this.multi ? |
| 3196 this.selectedItems && this.selectedItems[0] : |
| 3197 this.selectedItem; |
| 3198 this._setFocusedItem(null); |
| 3199 if (selectedItem) { |
| 3200 this._setFocusedItem(selectedItem) |
| 3201 } else if (this.items[0]) { |
| 3202 this._focusNext() |
| 3203 } |
| 3204 }) |
| 3205 }, |
| 3206 _onUpKey: function(event) { |
| 3207 this._focusPrevious(); |
| 3208 event.detail.keyboardEvent.preventDefault() |
| 3209 }, |
| 3210 _onDownKey: function(event) { |
| 3211 this._focusNext(); |
| 3212 event.detail.keyboardEvent.preventDefault() |
| 3213 }, |
| 3214 _onEscKey: function(event) { |
| 3215 this.focusedItem.blur() |
| 3216 }, |
| 3217 _onKeydown: function(event) { |
| 3218 if (!this.keyboardEventMatchesKeys(event, "up down esc")) { |
| 3219 this._focusWithKeyboardEvent(event) |
| 3220 } |
| 3221 event.stopPropagation() |
| 3222 }, |
| 3223 _activateHandler: function(event) { |
| 3224 Polymer.IronSelectableBehavior._activateHandler.call(this, event); |
| 3225 event.stopPropagation() |
| 3226 } |
| 3227 }; |
| 3228 Polymer.IronMenuBehaviorImpl._shiftTabPressed = false; |
| 3229 Polymer.IronMenuBehavior = [ |
| 3230 Polymer.IronMultiSelectableBehavior, Polymer.IronA11yKeysBehavior, |
| 3231 Polymer.IronMenuBehaviorImpl |
| 3232 ]; |
| 3233 (function() { |
| 3234 Polymer({is: "paper-menu", behaviors: [Polymer.IronMenuBehavior]}) |
| 3235 })(); |
| 3236 Polymer.IronFitBehavior = { |
| 3237 properties: { |
| 3238 sizingTarget: { |
| 3239 type: Object, |
| 3240 value: function() { |
| 3241 return this |
| 3242 } |
| 3243 }, |
| 3244 fitInto: {type: Object, value: window}, |
| 3245 noOverlap: {type: Boolean}, |
| 3246 positionTarget: {type: Element}, |
| 3247 horizontalAlign: {type: String}, |
| 3248 verticalAlign: {type: String}, |
| 3249 dynamicAlign: {type: Boolean}, |
| 3250 horizontalOffset: {type: Number, value: 0, notify: true}, |
| 3251 verticalOffset: {type: Number, value: 0, notify: true}, |
| 3252 autoFitOnAttach: {type: Boolean, value: false}, |
| 3253 _fitInfo: {type: Object} |
| 3254 }, |
| 3255 get _fitWidth() { |
| 3256 var fitWidth; |
| 3257 if (this.fitInto === window) { |
| 3258 fitWidth = this.fitInto.innerWidth |
| 3259 } else { |
| 3260 fitWidth = this.fitInto.getBoundingClientRect().width |
| 3261 } |
| 3262 return fitWidth |
| 3263 }, |
| 3264 get _fitHeight() { |
| 3265 var fitHeight; |
| 3266 if (this.fitInto === window) { |
| 3267 fitHeight = this.fitInto.innerHeight |
| 3268 } else { |
| 3269 fitHeight = this.fitInto.getBoundingClientRect().height |
| 3270 } |
| 3271 return fitHeight |
| 3272 }, |
| 3273 get _fitLeft() { |
| 3274 var fitLeft; |
| 3275 if (this.fitInto === window) { |
| 3276 fitLeft = 0 |
| 3277 } else { |
| 3278 fitLeft = this.fitInto.getBoundingClientRect().left |
| 3279 } |
| 3280 return fitLeft |
| 3281 }, |
| 3282 get _fitTop() { |
| 3283 var fitTop; |
| 3284 if (this.fitInto === window) { |
| 3285 fitTop = 0 |
| 3286 } else { |
| 3287 fitTop = this.fitInto.getBoundingClientRect().top |
| 3288 } |
| 3289 return fitTop |
| 3290 }, |
| 3291 get _defaultPositionTarget() { |
| 3292 var parent = Polymer.dom(this).parentNode; |
| 3293 if (parent && parent.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { |
| 3294 parent = parent.host |
| 3295 } |
| 3296 return parent |
| 3297 }, |
| 3298 get _localeHorizontalAlign() { |
| 3299 if (this._isRTL) { |
| 3300 if (this.horizontalAlign === "right") { |
| 3301 return "left" |
| 3302 } |
| 3303 if (this.horizontalAlign === "left") { |
| 3304 return "right" |
| 3305 } |
| 3306 } |
| 3307 return this.horizontalAlign |
| 3308 }, |
| 3309 attached: function() { |
| 3310 this._isRTL = window.getComputedStyle(this).direction == "rtl"; |
| 3311 this.positionTarget = this.positionTarget || this._defaultPositionTarget; |
| 3312 if (this.autoFitOnAttach) { |
| 3313 if (window.getComputedStyle(this).display === "none") { |
| 3314 setTimeout(function() { |
| 3315 this.fit() |
| 3316 }.bind(this)) |
| 3317 } else { |
| 3318 this.fit() |
| 3319 } |
| 3320 } |
| 3321 }, |
| 3322 fit: function() { |
| 3323 this.position(); |
| 3324 this.constrain(); |
| 3325 this.center() |
| 3326 }, |
| 3327 _discoverInfo: function() { |
| 3328 if (this._fitInfo) { |
| 3329 return |
| 3330 } |
| 3331 var target = window.getComputedStyle(this); |
| 3332 var sizer = window.getComputedStyle(this.sizingTarget); |
| 3333 this._fitInfo = { |
| 3334 inlineStyle: { |
| 3335 top: this.style.top || "", |
| 3336 left: this.style.left || "", |
| 3337 position: this.style.position || "" |
| 3338 }, |
| 3339 sizerInlineStyle: { |
| 3340 maxWidth: this.sizingTarget.style.maxWidth || "", |
| 3341 maxHeight: this.sizingTarget.style.maxHeight || "", |
| 3342 boxSizing: this.sizingTarget.style.boxSizing || "" |
| 3343 }, |
| 3344 positionedBy: { |
| 3345 vertically: target.top !== "auto" ? |
| 3346 "top" : |
| 3347 target.bottom !== "auto" ? "bottom" : null, |
| 3348 horizontally: target.left !== "auto" ? |
| 3349 "left" : |
| 3350 target.right !== "auto" ? "right" : null |
| 3351 }, |
| 3352 sizedBy: { |
| 3353 height: sizer.maxHeight !== "none", |
| 3354 width: sizer.maxWidth !== "none", |
| 3355 minWidth: parseInt(sizer.minWidth, 10) || 0, |
| 3356 minHeight: parseInt(sizer.minHeight, 10) || 0 |
| 3357 }, |
| 3358 margin: { |
| 3359 top: parseInt(target.marginTop, 10) || 0, |
| 3360 right: parseInt(target.marginRight, 10) || 0, |
| 3361 bottom: parseInt(target.marginBottom, 10) || 0, |
| 3362 left: parseInt(target.marginLeft, 10) || 0 |
| 3363 } |
| 3364 }; |
| 3365 if (this.verticalOffset) { |
| 3366 this._fitInfo.margin.top = this._fitInfo.margin.bottom = |
| 3367 this.verticalOffset; |
| 3368 this._fitInfo.inlineStyle.marginTop = this.style.marginTop || ""; |
| 3369 this._fitInfo.inlineStyle.marginBottom = this.style.marginBottom || ""; |
| 3370 this.style.marginTop = this.style.marginBottom = |
| 3371 this.verticalOffset + "px" |
| 3372 } |
| 3373 if (this.horizontalOffset) { |
| 3374 this._fitInfo.margin.left = this._fitInfo.margin.right = |
| 3375 this.horizontalOffset; |
| 3376 this._fitInfo.inlineStyle.marginLeft = this.style.marginLeft || ""; |
| 3377 this._fitInfo.inlineStyle.marginRight = this.style.marginRight || ""; |
| 3378 this.style.marginLeft = this.style.marginRight = |
| 3379 this.horizontalOffset + "px" |
| 3380 } |
| 3381 }, |
| 3382 resetFit: function() { |
| 3383 var info = this._fitInfo || {}; |
| 3384 for (var property in info.sizerInlineStyle) { |
| 3385 this.sizingTarget.style[property] = info.sizerInlineStyle[property] |
| 3386 } |
| 3387 for (var property in info.inlineStyle) { |
| 3388 this.style[property] = info.inlineStyle[property] |
| 3389 } |
| 3390 this._fitInfo = null |
| 3391 }, |
| 3392 refit: function() { |
| 3393 var scrollLeft = this.sizingTarget.scrollLeft; |
| 3394 var scrollTop = this.sizingTarget.scrollTop; |
| 3395 this.resetFit(); |
| 3396 this.fit(); |
| 3397 this.sizingTarget.scrollLeft = scrollLeft; |
| 3398 this.sizingTarget.scrollTop = scrollTop |
| 3399 }, |
| 3400 position: function() { |
| 3401 if (!this.horizontalAlign && !this.verticalAlign) { |
| 3402 return |
| 3403 } |
| 3404 this._discoverInfo(); |
| 3405 this.style.position = "fixed"; |
| 3406 this.sizingTarget.style.boxSizing = "border-box"; |
| 3407 this.style.left = "0px"; |
| 3408 this.style.top = "0px"; |
| 3409 var rect = this.getBoundingClientRect(); |
| 3410 var positionRect = this.__getNormalizedRect(this.positionTarget); |
| 3411 var fitRect = this.__getNormalizedRect(this.fitInto); |
| 3412 var margin = this._fitInfo.margin; |
| 3413 var size = { |
| 3414 width: rect.width + margin.left + margin.right, |
| 3415 height: rect.height + margin.top + margin.bottom |
| 3416 }; |
| 3417 var position = this.__getPosition( |
| 3418 this._localeHorizontalAlign, this.verticalAlign, size, positionRect, |
| 3419 fitRect); |
| 3420 var left = position.left + margin.left; |
| 3421 var top = position.top + margin.top; |
| 3422 var right = Math.min(fitRect.right - margin.right, left + rect.width); |
| 3423 var bottom = Math.min(fitRect.bottom - margin.bottom, top + rect.height); |
| 3424 var minWidth = this._fitInfo.sizedBy.minWidth; |
| 3425 var minHeight = this._fitInfo.sizedBy.minHeight; |
| 3426 if (left < margin.left) { |
| 3427 left = margin.left; |
| 3428 if (right - left < minWidth) { |
| 3429 left = right - minWidth |
| 3430 } |
| 3431 } |
| 3432 if (top < margin.top) { |
| 3433 top = margin.top; |
| 3434 if (bottom - top < minHeight) { |
| 3435 top = bottom - minHeight |
| 3436 } |
| 3437 } |
| 3438 this.sizingTarget.style.maxWidth = right - left + "px"; |
| 3439 this.sizingTarget.style.maxHeight = bottom - top + "px"; |
| 3440 this.style.left = left - rect.left + "px"; |
| 3441 this.style.top = top - rect.top + "px" |
| 3442 }, |
| 3443 constrain: function() { |
| 3444 if (this.horizontalAlign || this.verticalAlign) { |
| 3445 return |
| 3446 } |
| 3447 this._discoverInfo(); |
| 3448 var info = this._fitInfo; |
| 3449 if (!info.positionedBy.vertically) { |
| 3450 this.style.position = "fixed"; |
| 3451 this.style.top = "0px" |
| 3452 } |
| 3453 if (!info.positionedBy.horizontally) { |
| 3454 this.style.position = "fixed"; |
| 3455 this.style.left = "0px" |
| 3456 } |
| 3457 this.sizingTarget.style.boxSizing = "border-box"; |
| 3458 var rect = this.getBoundingClientRect(); |
| 3459 if (!info.sizedBy.height) { |
| 3460 this.__sizeDimension( |
| 3461 rect, info.positionedBy.vertically, "top", "bottom", "Height") |
| 3462 } |
| 3463 if (!info.sizedBy.width) { |
| 3464 this.__sizeDimension( |
| 3465 rect, info.positionedBy.horizontally, "left", "right", "Width") |
| 3466 } |
| 3467 }, |
| 3468 _sizeDimension: function(rect, positionedBy, start, end, extent) { |
| 3469 this.__sizeDimension(rect, positionedBy, start, end, extent) |
| 3470 }, |
| 3471 __sizeDimension: function(rect, positionedBy, start, end, extent) { |
| 3472 var info = this._fitInfo; |
| 3473 var fitRect = this.__getNormalizedRect(this.fitInto); |
| 3474 var max = extent === "Width" ? fitRect.width : fitRect.height; |
| 3475 var flip = positionedBy === end; |
| 3476 var offset = flip ? max - rect[end] : rect[start]; |
| 3477 var margin = info.margin[flip ? start : end]; |
| 3478 var offsetExtent = "offset" + extent; |
| 3479 var sizingOffset = this[offsetExtent] - this.sizingTarget[offsetExtent]; |
| 3480 this.sizingTarget.style["max" + extent] = |
| 3481 max - margin - offset - sizingOffset + "px" |
| 3482 }, |
| 3483 center: function() { |
| 3484 if (this.horizontalAlign || this.verticalAlign) { |
| 3485 return |
| 3486 } |
| 3487 this._discoverInfo(); |
| 3488 var positionedBy = this._fitInfo.positionedBy; |
| 3489 if (positionedBy.vertically && positionedBy.horizontally) { |
| 3490 return |
| 3491 } |
| 3492 this.style.position = "fixed"; |
| 3493 if (!positionedBy.vertically) { |
| 3494 this.style.top = "0px" |
| 3495 } |
| 3496 if (!positionedBy.horizontally) { |
| 3497 this.style.left = "0px" |
| 3498 } |
| 3499 var rect = this.getBoundingClientRect(); |
| 3500 var fitRect = this.__getNormalizedRect(this.fitInto); |
| 3501 if (!positionedBy.vertically) { |
| 3502 var top = fitRect.top - rect.top + (fitRect.height - rect.height) / 2; |
| 3503 this.style.top = top + "px" |
| 3504 } |
| 3505 if (!positionedBy.horizontally) { |
| 3506 var left = fitRect.left - rect.left + (fitRect.width - rect.width) / 2; |
| 3507 this.style.left = left + "px" |
| 3508 } |
| 3509 }, |
| 3510 __getNormalizedRect: function(target) { |
| 3511 if (target === document.documentElement || target === window) { |
| 3512 return { |
| 3513 top: 0, left: 0, width: window.innerWidth, height: window.innerHeight, |
| 3514 right: window.innerWidth, bottom: window.innerHeight |
| 3515 } |
| 3516 } |
| 3517 return target.getBoundingClientRect() |
| 3518 }, |
| 3519 __getCroppedArea: function(position, size, fitRect) { |
| 3520 var verticalCrop = Math.min(0, position.top) + |
| 3521 Math.min(0, fitRect.bottom - (position.top + size.height)); |
| 3522 var horizontalCrop = Math.min(0, position.left) + |
| 3523 Math.min(0, fitRect.right - (position.left + size.width)); |
| 3524 return Math.abs(verticalCrop) * size.width + |
| 3525 Math.abs(horizontalCrop) * size.height |
| 3526 }, |
| 3527 __getPosition: function(hAlign, vAlign, size, positionRect, fitRect) { |
| 3528 var positions = [ |
| 3529 { |
| 3530 verticalAlign: "top", |
| 3531 horizontalAlign: "left", |
| 3532 top: positionRect.top, |
| 3533 left: positionRect.left |
| 3534 }, |
| 3535 { |
| 3536 verticalAlign: "top", |
| 3537 horizontalAlign: "right", |
| 3538 top: positionRect.top, |
| 3539 left: positionRect.right - size.width |
| 3540 }, |
| 3541 { |
| 3542 verticalAlign: "bottom", |
| 3543 horizontalAlign: "left", |
| 3544 top: positionRect.bottom - size.height, |
| 3545 left: positionRect.left |
| 3546 }, |
| 3547 { |
| 3548 verticalAlign: "bottom", |
| 3549 horizontalAlign: "right", |
| 3550 top: positionRect.bottom - size.height, |
| 3551 left: positionRect.right - size.width |
| 3552 } |
| 3553 ]; |
| 3554 if (this.noOverlap) { |
| 3555 for (var i = 0, l = positions.length; i < l; i++) { |
| 3556 var copy = {}; |
| 3557 for (var key in positions[i]) { |
| 3558 copy[key] = positions[i][key] |
| 3559 } |
| 3560 positions.push(copy) |
| 3561 } |
| 3562 positions[0].top = positions[1].top += positionRect.height; |
| 3563 positions[2].top = positions[3].top -= positionRect.height; |
| 3564 positions[4].left = positions[6].left += positionRect.width; |
| 3565 positions[5].left = positions[7].left -= positionRect.width |
| 3566 } |
| 3567 vAlign = vAlign === "auto" ? null : vAlign; |
| 3568 hAlign = hAlign === "auto" ? null : hAlign; |
| 3569 var position; |
| 3570 for (var i = 0; i < positions.length; i++) { |
| 3571 var pos = positions[i]; |
| 3572 if (!this.dynamicAlign && !this.noOverlap && |
| 3573 pos.verticalAlign === vAlign && pos.horizontalAlign === hAlign) { |
| 3574 position = pos; |
| 3575 break |
| 3576 } |
| 3577 var alignOk = (!vAlign || pos.verticalAlign === vAlign) && |
| 3578 (!hAlign || pos.horizontalAlign === hAlign); |
| 3579 if (!this.dynamicAlign && !alignOk) { |
| 3580 continue |
| 3581 } |
| 3582 position = position || pos; |
| 3583 pos.croppedArea = this.__getCroppedArea(pos, size, fitRect); |
| 3584 var diff = pos.croppedArea - position.croppedArea; |
| 3585 if (diff < 0 || diff === 0 && alignOk) { |
| 3586 position = pos |
| 3587 } |
| 3588 if (position.croppedArea === 0 && alignOk) { |
| 3589 break |
| 3590 } |
| 3591 } |
| 3592 return position |
| 3593 } |
| 3594 }; |
| 3595 (function() { |
| 3596 "use strict"; |
| 3597 Polymer({ |
| 3598 is: "iron-overlay-backdrop", |
| 3599 properties: { |
| 3600 opened: { |
| 3601 reflectToAttribute: true, |
| 3602 type: Boolean, |
| 3603 value: false, |
| 3604 observer: "_openedChanged" |
| 3605 } |
| 3606 }, |
| 3607 listeners: {transitionend: "_onTransitionend"}, |
| 3608 created: function() { |
| 3609 this.__openedRaf = null |
| 3610 }, |
| 3611 attached: function() { |
| 3612 this.opened && this._openedChanged(this.opened) |
| 3613 }, |
| 3614 prepare: function() { |
| 3615 if (this.opened && !this.parentNode) { |
| 3616 Polymer.dom(document.body).appendChild(this) |
| 3617 } |
| 3618 }, |
| 3619 open: function() { |
| 3620 this.opened = true |
| 3621 }, |
| 3622 close: function() { |
| 3623 this.opened = false |
| 3624 }, |
| 3625 complete: function() { |
| 3626 if (!this.opened && this.parentNode === document.body) { |
| 3627 Polymer.dom(this.parentNode).removeChild(this) |
| 3628 } |
| 3629 }, |
| 3630 _onTransitionend: function(event) { |
| 3631 if (event && event.target === this) { |
| 3632 this.complete() |
| 3633 } |
| 3634 }, |
| 3635 _openedChanged: function(opened) { |
| 3636 if (opened) { |
| 3637 this.prepare() |
| 3638 } else { |
| 3639 var cs = window.getComputedStyle(this); |
| 3640 if (cs.transitionDuration === "0s" || cs.opacity == 0) { |
| 3641 this.complete() |
| 3642 } |
| 3643 } |
| 3644 if (!this.isAttached) { |
| 3645 return |
| 3646 } |
| 3647 if (this.__openedRaf) { |
| 3648 window.cancelAnimationFrame(this.__openedRaf); |
| 3649 this.__openedRaf = null |
| 3650 } |
| 3651 this.scrollTop = this.scrollTop; |
| 3652 this.__openedRaf = window.requestAnimationFrame(function() { |
| 3653 this.__openedRaf = null; |
| 3654 this.toggleClass("opened", this.opened) |
| 3655 }.bind(this)) |
| 3656 } |
| 3657 }) |
| 3658 })(); |
| 3659 Polymer.IronOverlayManagerClass = function() { |
| 3660 this._overlays = []; |
| 3661 this._minimumZ = 101; |
| 3662 this._backdropElement = null; |
| 3663 Polymer.Gestures.add(document, "tap", this._onCaptureClick.bind(this)); |
| 3664 document.addEventListener("focus", this._onCaptureFocus.bind(this), true); |
| 3665 document.addEventListener("keydown", this._onCaptureKeyDown.bind(this), true) |
| 3666 }; |
| 3667 Polymer.IronOverlayManagerClass.prototype = { |
| 3668 constructor: Polymer.IronOverlayManagerClass, |
| 3669 get backdropElement() { |
| 3670 if (!this._backdropElement) { |
| 3671 this._backdropElement = document.createElement("iron-overlay-backdrop") |
| 3672 } |
| 3673 return this._backdropElement |
| 3674 }, |
| 3675 get deepActiveElement() { |
| 3676 var active = document.activeElement || document.body; |
| 3677 while (active.root && Polymer.dom(active.root).activeElement) { |
| 3678 active = Polymer.dom(active.root).activeElement |
| 3679 } |
| 3680 return active |
| 3681 }, |
| 3682 _bringOverlayAtIndexToFront: function(i) { |
| 3683 var overlay = this._overlays[i]; |
| 3684 if (!overlay) { |
| 3685 return |
| 3686 } |
| 3687 var lastI = this._overlays.length - 1; |
| 3688 var currentOverlay = this._overlays[lastI]; |
| 3689 if (currentOverlay && |
| 3690 this._shouldBeBehindOverlay(overlay, currentOverlay)) { |
| 3691 lastI-- |
| 3692 } |
| 3693 if (i >= lastI) { |
| 3694 return |
| 3695 } |
| 3696 var minimumZ = Math.max(this.currentOverlayZ(), this._minimumZ); |
| 3697 if (this._getZ(overlay) <= minimumZ) { |
| 3698 this._applyOverlayZ(overlay, minimumZ) |
| 3699 } |
| 3700 while (i < lastI) { |
| 3701 this._overlays[i] = this._overlays[i + 1]; |
| 3702 i++ |
| 3703 } |
| 3704 this._overlays[lastI] = overlay |
| 3705 }, |
| 3706 addOrRemoveOverlay: function(overlay) { |
| 3707 if (overlay.opened) { |
| 3708 this.addOverlay(overlay) |
| 3709 } else { |
| 3710 this.removeOverlay(overlay) |
| 3711 } |
| 3712 }, |
| 3713 addOverlay: function(overlay) { |
| 3714 var i = this._overlays.indexOf(overlay); |
| 3715 if (i >= 0) { |
| 3716 this._bringOverlayAtIndexToFront(i); |
| 3717 this.trackBackdrop(); |
| 3718 return |
| 3719 } |
| 3720 var insertionIndex = this._overlays.length; |
| 3721 var currentOverlay = this._overlays[insertionIndex - 1]; |
| 3722 var minimumZ = Math.max(this._getZ(currentOverlay), this._minimumZ); |
| 3723 var newZ = this._getZ(overlay); |
| 3724 if (currentOverlay && |
| 3725 this._shouldBeBehindOverlay(overlay, currentOverlay)) { |
| 3726 this._applyOverlayZ(currentOverlay, minimumZ); |
| 3727 insertionIndex--; |
| 3728 var previousOverlay = this._overlays[insertionIndex - 1]; |
| 3729 minimumZ = Math.max(this._getZ(previousOverlay), this._minimumZ) |
| 3730 } |
| 3731 if (newZ <= minimumZ) { |
| 3732 this._applyOverlayZ(overlay, minimumZ) |
| 3733 } |
| 3734 this._overlays.splice(insertionIndex, 0, overlay); |
| 3735 this.trackBackdrop() |
| 3736 }, |
| 3737 removeOverlay: function(overlay) { |
| 3738 var i = this._overlays.indexOf(overlay); |
| 3739 if (i === -1) { |
| 3740 return |
| 3741 } |
| 3742 this._overlays.splice(i, 1); |
| 3743 this.trackBackdrop() |
| 3744 }, |
| 3745 currentOverlay: function() { |
| 3746 var i = this._overlays.length - 1; |
| 3747 return this._overlays[i] |
| 3748 }, |
| 3749 currentOverlayZ: function() { |
| 3750 return this._getZ(this.currentOverlay()) |
| 3751 }, |
| 3752 ensureMinimumZ: function(minimumZ) { |
| 3753 this._minimumZ = Math.max(this._minimumZ, minimumZ) |
| 3754 }, |
| 3755 focusOverlay: function() { |
| 3756 var current = this.currentOverlay(); |
| 3757 if (current) { |
| 3758 current._applyFocus() |
| 3759 } |
| 3760 }, |
| 3761 trackBackdrop: function() { |
| 3762 var overlay = this._overlayWithBackdrop(); |
| 3763 if (!overlay && !this._backdropElement) { |
| 3764 return |
| 3765 } |
| 3766 this.backdropElement.style.zIndex = this._getZ(overlay) - 1; |
| 3767 this.backdropElement.opened = !!overlay |
| 3768 }, |
| 3769 getBackdrops: function() { |
| 3770 var backdrops = []; |
| 3771 for (var i = 0; i < this._overlays.length; i++) { |
| 3772 if (this._overlays[i].withBackdrop) { |
| 3773 backdrops.push(this._overlays[i]) |
| 3774 } |
| 3775 } |
| 3776 return backdrops |
| 3777 }, |
| 3778 backdropZ: function() { |
| 3779 return this._getZ(this._overlayWithBackdrop()) - 1 |
| 3780 }, |
| 3781 _overlayWithBackdrop: function() { |
| 3782 for (var i = 0; i < this._overlays.length; i++) { |
| 3783 if (this._overlays[i].withBackdrop) { |
| 3784 return this._overlays[i] |
| 3785 } |
| 3786 } |
| 3787 }, |
| 3788 _getZ: function(overlay) { |
| 3789 var z = this._minimumZ; |
| 3790 if (overlay) { |
| 3791 var z1 = Number( |
| 3792 overlay.style.zIndex || window.getComputedStyle(overlay).zIndex); |
| 3793 if (z1 === z1) { |
| 3794 z = z1 |
| 3795 } |
| 3796 } |
| 3797 return z |
| 3798 }, |
| 3799 _setZ: function(element, z) { |
| 3800 element.style.zIndex = z |
| 3801 }, |
| 3802 _applyOverlayZ: function(overlay, aboveZ) { |
| 3803 this._setZ(overlay, aboveZ + 2) |
| 3804 }, |
| 3805 _overlayInPath: function(path) { |
| 3806 path = path || []; |
| 3807 for (var i = 0; i < path.length; i++) { |
| 3808 if (path[i]._manager === this) { |
| 3809 return path[i] |
| 3810 } |
| 3811 } |
| 3812 }, |
| 3813 _onCaptureClick: function(event) { |
| 3814 var overlay = this.currentOverlay(); |
| 3815 if (overlay && this._overlayInPath(Polymer.dom(event).path) !== overlay) { |
| 3816 overlay._onCaptureClick(event) |
| 3817 } |
| 3818 }, |
| 3819 _onCaptureFocus: function(event) { |
| 3820 var overlay = this.currentOverlay(); |
| 3821 if (overlay) { |
| 3822 overlay._onCaptureFocus(event) |
| 3823 } |
| 3824 }, |
| 3825 _onCaptureKeyDown: function(event) { |
| 3826 var overlay = this.currentOverlay(); |
| 3827 if (overlay) { |
| 3828 if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(event, "esc")) { |
| 3829 overlay._onCaptureEsc(event) |
| 3830 } else if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys( |
| 3831 event, "tab")) { |
| 3832 overlay._onCaptureTab(event) |
| 3833 } |
| 3834 } |
| 3835 }, |
| 3836 _shouldBeBehindOverlay: function(overlay1, overlay2) { |
| 3837 return !overlay1.alwaysOnTop && overlay2.alwaysOnTop |
| 3838 } |
| 3839 }; |
| 3840 Polymer.IronOverlayManager = new Polymer.IronOverlayManagerClass; |
| 3841 (function() { |
| 3842 "use strict"; |
| 3843 Polymer.IronOverlayBehaviorImpl = { |
| 3844 properties: { |
| 3845 opened: { |
| 3846 observer: "_openedChanged", |
| 3847 type: Boolean, |
| 3848 value: false, |
| 3849 notify: true |
| 3850 }, |
| 3851 canceled: { |
| 3852 observer: "_canceledChanged", |
| 3853 readOnly: true, |
| 3854 type: Boolean, |
| 3855 value: false |
| 3856 }, |
| 3857 withBackdrop: {observer: "_withBackdropChanged", type: Boolean}, |
| 3858 noAutoFocus: {type: Boolean, value: false}, |
| 3859 noCancelOnEscKey: {type: Boolean, value: false}, |
| 3860 noCancelOnOutsideClick: {type: Boolean, value: false}, |
| 3861 closingReason: {type: Object}, |
| 3862 restoreFocusOnClose: {type: Boolean, value: false}, |
| 3863 alwaysOnTop: {type: Boolean}, |
| 3864 _manager: {type: Object, value: Polymer.IronOverlayManager}, |
| 3865 _focusedChild: {type: Object} |
| 3866 }, |
| 3867 listeners: {"iron-resize": "_onIronResize"}, |
| 3868 get backdropElement() { |
| 3869 return this._manager.backdropElement |
| 3870 }, |
| 3871 get _focusNode() { |
| 3872 return this._focusedChild || |
| 3873 Polymer.dom(this).querySelector("[autofocus]") || this |
| 3874 }, |
| 3875 get _focusableNodes() { |
| 3876 var FOCUSABLE_WITH_DISABLED = [ |
| 3877 "a[href]", "area[href]", "iframe", "[tabindex]", |
| 3878 "[contentEditable=true]" |
| 3879 ]; |
| 3880 var FOCUSABLE_WITHOUT_DISABLED = |
| 3881 ["input", "select", "textarea", "button"]; |
| 3882 var selector = FOCUSABLE_WITH_DISABLED.join(':not([tabindex="-1"]),') + |
| 3883 ':not([tabindex="-1"]),' + |
| 3884 FOCUSABLE_WITHOUT_DISABLED.join( |
| 3885 ':not([disabled]):not([tabindex="-1"]),') + |
| 3886 ':not([disabled]):not([tabindex="-1"])'; |
| 3887 var focusables = Polymer.dom(this).querySelectorAll(selector); |
| 3888 if (this.tabIndex >= 0) { |
| 3889 focusables.splice(0, 0, this) |
| 3890 } |
| 3891 return focusables.sort(function(a, b) { |
| 3892 if (a.tabIndex === b.tabIndex) { |
| 3893 return 0 |
| 3894 } |
| 3895 if (a.tabIndex === 0 || a.tabIndex > b.tabIndex) { |
| 3896 return 1 |
| 3897 } |
| 3898 return -1 |
| 3899 }) |
| 3900 }, |
| 3901 ready: function() { |
| 3902 this.__isAnimating = false; |
| 3903 this.__shouldRemoveTabIndex = false; |
| 3904 this.__firstFocusableNode = this.__lastFocusableNode = null; |
| 3905 this.__raf = null; |
| 3906 this.__restoreFocusNode = null; |
| 3907 this._ensureSetup() |
| 3908 }, |
| 3909 attached: function() { |
| 3910 if (this.opened) { |
| 3911 this._openedChanged(this.opened) |
| 3912 } |
| 3913 this._observer = Polymer.dom(this).observeNodes(this._onNodesChange) |
| 3914 }, |
| 3915 detached: function() { |
| 3916 Polymer.dom(this).unobserveNodes(this._observer); |
| 3917 this._observer = null; |
| 3918 if (this.__raf) { |
| 3919 window.cancelAnimationFrame(this.__raf); |
| 3920 this.__raf = null |
| 3921 } |
| 3922 this._manager.removeOverlay(this) |
| 3923 }, |
| 3924 toggle: function() { |
| 3925 this._setCanceled(false); |
| 3926 this.opened = !this.opened |
| 3927 }, |
| 3928 open: function() { |
| 3929 this._setCanceled(false); |
| 3930 this.opened = true |
| 3931 }, |
| 3932 close: function() { |
| 3933 this._setCanceled(false); |
| 3934 this.opened = false |
| 3935 }, |
| 3936 cancel: function(event) { |
| 3937 var cancelEvent = |
| 3938 this.fire("iron-overlay-canceled", event, {cancelable: true}); |
| 3939 if (cancelEvent.defaultPrevented) { |
| 3940 return |
| 3941 } |
| 3942 this._setCanceled(true); |
| 3943 this.opened = false |
| 3944 }, |
| 3945 _ensureSetup: function() { |
| 3946 if (this._overlaySetup) { |
| 3947 return |
| 3948 } |
| 3949 this._overlaySetup = true; |
| 3950 this.style.outline = "none"; |
| 3951 this.style.display = "none" |
| 3952 }, |
| 3953 _openedChanged: function(opened) { |
| 3954 if (opened) { |
| 3955 this.removeAttribute("aria-hidden") |
| 3956 } else { |
| 3957 this.setAttribute("aria-hidden", "true") |
| 3958 } |
| 3959 if (!this.isAttached) { |
| 3960 return |
| 3961 } |
| 3962 this.__isAnimating = true; |
| 3963 this.__onNextAnimationFrame(this.__openedChanged) |
| 3964 }, |
| 3965 _canceledChanged: function() { |
| 3966 this.closingReason = this.closingReason || {}; |
| 3967 this.closingReason.canceled = this.canceled |
| 3968 }, |
| 3969 _withBackdropChanged: function() { |
| 3970 if (this.withBackdrop && !this.hasAttribute("tabindex")) { |
| 3971 this.setAttribute("tabindex", "-1"); |
| 3972 this.__shouldRemoveTabIndex = true |
| 3973 } else if (this.__shouldRemoveTabIndex) { |
| 3974 this.removeAttribute("tabindex"); |
| 3975 this.__shouldRemoveTabIndex = false |
| 3976 } |
| 3977 if (this.opened && this.isAttached) { |
| 3978 this._manager.trackBackdrop() |
| 3979 } |
| 3980 }, |
| 3981 _prepareRenderOpened: function() { |
| 3982 this.__restoreFocusNode = this._manager.deepActiveElement; |
| 3983 this._preparePositioning(); |
| 3984 this.refit(); |
| 3985 this._finishPositioning(); |
| 3986 if (this.noAutoFocus && document.activeElement === this._focusNode) { |
| 3987 this._focusNode.blur(); |
| 3988 this.__restoreFocusNode.focus() |
| 3989 } |
| 3990 }, |
| 3991 _renderOpened: function() { |
| 3992 this._finishRenderOpened() |
| 3993 }, |
| 3994 _renderClosed: function() { |
| 3995 this._finishRenderClosed() |
| 3996 }, |
| 3997 _finishRenderOpened: function() { |
| 3998 this.notifyResize(); |
| 3999 this.__isAnimating = false; |
| 4000 var focusableNodes = this._focusableNodes; |
| 4001 this.__firstFocusableNode = focusableNodes[0]; |
| 4002 this.__lastFocusableNode = focusableNodes[focusableNodes.length - 1]; |
| 4003 this.fire("iron-overlay-opened") |
| 4004 }, |
| 4005 _finishRenderClosed: function() { |
| 4006 this.style.display = "none"; |
| 4007 this.style.zIndex = ""; |
| 4008 this.notifyResize(); |
| 4009 this.__isAnimating = false; |
| 4010 this.fire("iron-overlay-closed", this.closingReason) |
| 4011 }, |
| 4012 _preparePositioning: function() { |
| 4013 this.style.transition = this.style.webkitTransition = "none"; |
| 4014 this.style.transform = this.style.webkitTransform = "none"; |
| 4015 this.style.display = "" |
| 4016 }, |
| 4017 _finishPositioning: function() { |
| 4018 this.style.display = "none"; |
| 4019 this.scrollTop = this.scrollTop; |
| 4020 this.style.transition = this.style.webkitTransition = ""; |
| 4021 this.style.transform = this.style.webkitTransform = ""; |
| 4022 this.style.display = ""; |
| 4023 this.scrollTop = this.scrollTop |
| 4024 }, |
| 4025 _applyFocus: function() { |
| 4026 if (this.opened) { |
| 4027 if (!this.noAutoFocus) { |
| 4028 this._focusNode.focus() |
| 4029 } |
| 4030 } else { |
| 4031 this._focusNode.blur(); |
| 4032 this._focusedChild = null; |
| 4033 if (this.restoreFocusOnClose && this.__restoreFocusNode) { |
| 4034 this.__restoreFocusNode.focus() |
| 4035 } |
| 4036 this.__restoreFocusNode = null; |
| 4037 var currentOverlay = this._manager.currentOverlay(); |
| 4038 if (currentOverlay && this !== currentOverlay) { |
| 4039 currentOverlay._applyFocus() |
| 4040 } |
| 4041 } |
| 4042 }, |
| 4043 _onCaptureClick: function(event) { |
| 4044 if (!this.noCancelOnOutsideClick) { |
| 4045 this.cancel(event) |
| 4046 } |
| 4047 }, |
| 4048 _onCaptureFocus: function(event) { |
| 4049 if (!this.withBackdrop) { |
| 4050 return |
| 4051 } |
| 4052 var path = Polymer.dom(event).path; |
| 4053 if (path.indexOf(this) === -1) { |
| 4054 event.stopPropagation(); |
| 4055 this._applyFocus() |
| 4056 } else { |
| 4057 this._focusedChild = path[0] |
| 4058 } |
| 4059 }, |
| 4060 _onCaptureEsc: function(event) { |
| 4061 if (!this.noCancelOnEscKey) { |
| 4062 this.cancel(event) |
| 4063 } |
| 4064 }, |
| 4065 _onCaptureTab: function(event) { |
| 4066 if (!this.withBackdrop) { |
| 4067 return |
| 4068 } |
| 4069 var shift = event.shiftKey; |
| 4070 var nodeToCheck = |
| 4071 shift ? this.__firstFocusableNode : this.__lastFocusableNode; |
| 4072 var nodeToSet = |
| 4073 shift ? this.__lastFocusableNode : this.__firstFocusableNode; |
| 4074 var shouldWrap = false; |
| 4075 if (nodeToCheck === nodeToSet) { |
| 4076 shouldWrap = true |
| 4077 } else { |
| 4078 var focusedNode = this._manager.deepActiveElement; |
| 4079 shouldWrap = focusedNode === nodeToCheck || focusedNode === this |
| 4080 } |
| 4081 if (shouldWrap) { |
| 4082 event.preventDefault(); |
| 4083 this._focusedChild = nodeToSet; |
| 4084 this._applyFocus() |
| 4085 } |
| 4086 }, |
| 4087 _onIronResize: function() { |
| 4088 if (this.opened && !this.__isAnimating) { |
| 4089 this.__onNextAnimationFrame(this.refit) |
| 4090 } |
| 4091 }, |
| 4092 _onNodesChange: function() { |
| 4093 if (this.opened && !this.__isAnimating) { |
| 4094 this.notifyResize() |
| 4095 } |
| 4096 }, |
| 4097 __openedChanged: function() { |
| 4098 if (this.opened) { |
| 4099 this._prepareRenderOpened(); |
| 4100 this._manager.addOverlay(this); |
| 4101 this._applyFocus(); |
| 4102 this._renderOpened() |
| 4103 } else { |
| 4104 this._manager.removeOverlay(this); |
| 4105 this._applyFocus(); |
| 4106 this._renderClosed() |
| 4107 } |
| 4108 }, |
| 4109 __onNextAnimationFrame: function(callback) { |
| 4110 if (this.__raf) { |
| 4111 window.cancelAnimationFrame(this.__raf) |
| 4112 } |
| 4113 var self = this; |
| 4114 this.__raf = window.requestAnimationFrame(function nextAnimationFrame() { |
| 4115 self.__raf = null; |
| 4116 callback.call(self) |
| 4117 }) |
| 4118 } |
| 4119 }; |
| 4120 Polymer.IronOverlayBehavior = [ |
| 4121 Polymer.IronFitBehavior, Polymer.IronResizableBehavior, |
| 4122 Polymer.IronOverlayBehaviorImpl |
| 4123 ] |
| 4124 })(); |
| 4125 Polymer.NeonAnimatableBehavior = { |
| 4126 properties: { |
| 4127 animationConfig: {type: Object}, |
| 4128 entryAnimation: {observer: "_entryAnimationChanged", type: String}, |
| 4129 exitAnimation: {observer: "_exitAnimationChanged", type: String} |
| 4130 }, |
| 4131 _entryAnimationChanged: function() { |
| 4132 this.animationConfig = this.animationConfig || {}; |
| 4133 this.animationConfig["entry"] = [{name: this.entryAnimation, node: this}] |
| 4134 }, |
| 4135 _exitAnimationChanged: function() { |
| 4136 this.animationConfig = this.animationConfig || {}; |
| 4137 this.animationConfig["exit"] = [{name: this.exitAnimation, node: this}] |
| 4138 }, |
| 4139 _copyProperties: function(config1, config2) { |
| 4140 for (var property in config2) { |
| 4141 config1[property] = config2[property] |
| 4142 } |
| 4143 }, |
| 4144 _cloneConfig: function(config) { |
| 4145 var clone = {isClone: true}; |
| 4146 this._copyProperties(clone, config); |
| 4147 return clone |
| 4148 }, |
| 4149 _getAnimationConfigRecursive: function(type, map, allConfigs) { |
| 4150 if (!this.animationConfig) { |
| 4151 return |
| 4152 } |
| 4153 if (this.animationConfig.value && |
| 4154 typeof this.animationConfig.value === "function") { |
| 4155 this._warn(this._logf( |
| 4156 "playAnimation", |
| 4157 "Please put 'animationConfig' inside of your components 'properties' o
bject instead of outside of it.")); |
| 4158 return |
| 4159 } |
| 4160 var thisConfig; |
| 4161 if (type) { |
| 4162 thisConfig = this.animationConfig[type] |
| 4163 } else { |
| 4164 thisConfig = this.animationConfig |
| 4165 } |
| 4166 if (!Array.isArray(thisConfig)) { |
| 4167 thisConfig = [thisConfig] |
| 4168 } |
| 4169 if (thisConfig) { |
| 4170 for (var config, index = 0; config = thisConfig[index]; index++) { |
| 4171 if (config.animatable) { |
| 4172 config.animatable._getAnimationConfigRecursive( |
| 4173 config.type || type, map, allConfigs) |
| 4174 } else { |
| 4175 if (config.id) { |
| 4176 var cachedConfig = map[config.id]; |
| 4177 if (cachedConfig) { |
| 4178 if (!cachedConfig.isClone) { |
| 4179 map[config.id] = this._cloneConfig(cachedConfig); |
| 4180 cachedConfig = map[config.id] |
| 4181 } |
| 4182 this._copyProperties(cachedConfig, config) |
| 4183 } else { |
| 4184 map[config.id] = config |
| 4185 } |
| 4186 } else { |
| 4187 allConfigs.push(config) |
| 4188 } |
| 4189 } |
| 4190 } |
| 4191 } |
| 4192 }, |
| 4193 getAnimationConfig: function(type) { |
| 4194 var map = {}; |
| 4195 var allConfigs = []; |
| 4196 this._getAnimationConfigRecursive(type, map, allConfigs); |
| 4197 for (var key in map) { |
| 4198 allConfigs.push(map[key]) |
| 4199 } |
| 4200 return allConfigs |
| 4201 } |
| 4202 }; |
| 4203 Polymer.NeonAnimationRunnerBehaviorImpl = { |
| 4204 _configureAnimations: function(configs) { |
| 4205 var results = []; |
| 4206 if (configs.length > 0) { |
| 4207 for (var config, index = 0; config = configs[index]; index++) { |
| 4208 var neonAnimation = document.createElement(config.name); |
| 4209 if (neonAnimation.isNeonAnimation) { |
| 4210 var result = null; |
| 4211 try { |
| 4212 result = neonAnimation.configure(config); |
| 4213 if (typeof result.cancel != "function") { |
| 4214 result = document.timeline.play(result) |
| 4215 } |
| 4216 } catch (e) { |
| 4217 result = null; |
| 4218 console.warn("Couldnt play", "(", config.name, ").", e) |
| 4219 } |
| 4220 if (result) { |
| 4221 results.push({ |
| 4222 neonAnimation: neonAnimation, |
| 4223 config: config, |
| 4224 animation: result |
| 4225 }) |
| 4226 } |
| 4227 } else { |
| 4228 console.warn(this.is + ":", config.name, "not found!") |
| 4229 } |
| 4230 } |
| 4231 } |
| 4232 return results |
| 4233 }, |
| 4234 _shouldComplete: function(activeEntries) { |
| 4235 var finished = true; |
| 4236 for (var i = 0; i < activeEntries.length; i++) { |
| 4237 if (activeEntries[i].animation.playState != "finished") { |
| 4238 finished = false; |
| 4239 break |
| 4240 } |
| 4241 } |
| 4242 return finished |
| 4243 }, |
| 4244 _complete: function(activeEntries) { |
| 4245 for (var i = 0; i < activeEntries.length; i++) { |
| 4246 activeEntries[i].neonAnimation.complete(activeEntries[i].config) |
| 4247 } |
| 4248 for (var i = 0; i < activeEntries.length; i++) { |
| 4249 activeEntries[i].animation.cancel() |
| 4250 } |
| 4251 }, |
| 4252 playAnimation: function(type, cookie) { |
| 4253 var configs = this.getAnimationConfig(type); |
| 4254 if (!configs) { |
| 4255 return |
| 4256 } |
| 4257 this._active = this._active || {}; |
| 4258 if (this._active[type]) { |
| 4259 this._complete(this._active[type]); |
| 4260 delete this._active[type] |
| 4261 } |
| 4262 var activeEntries = this._configureAnimations(configs); |
| 4263 if (activeEntries.length == 0) { |
| 4264 this.fire("neon-animation-finish", cookie, {bubbles: false}); |
| 4265 return |
| 4266 } |
| 4267 this._active[type] = activeEntries; |
| 4268 for (var i = 0; i < activeEntries.length; i++) { |
| 4269 activeEntries[i].animation.onfinish = function() { |
| 4270 if (this._shouldComplete(activeEntries)) { |
| 4271 this._complete(activeEntries); |
| 4272 delete this._active[type]; |
| 4273 this.fire("neon-animation-finish", cookie, {bubbles: false}) |
| 4274 } |
| 4275 }.bind(this) |
| 4276 } |
| 4277 }, |
| 4278 cancelAnimation: function() { |
| 4279 for (var k in this._animations) { |
| 4280 this._animations[k].cancel() |
| 4281 } |
| 4282 this._animations = {} |
| 4283 } |
| 4284 }; |
| 4285 Polymer.NeonAnimationRunnerBehavior = |
| 4286 [Polymer.NeonAnimatableBehavior, Polymer.NeonAnimationRunnerBehaviorImpl]; |
| 4287 Polymer.NeonAnimationBehavior = { |
| 4288 properties: { |
| 4289 animationTiming: { |
| 4290 type: Object, |
| 4291 value: function() { |
| 4292 return { |
| 4293 duration: 500, easing: "cubic-bezier(0.4, 0, 0.2, 1)", fill: "both" |
| 4294 } |
| 4295 } |
| 4296 } |
| 4297 }, |
| 4298 isNeonAnimation: true, |
| 4299 timingFromConfig: function(config) { |
| 4300 if (config.timing) { |
| 4301 for (var property in config.timing) { |
| 4302 this.animationTiming[property] = config.timing[property] |
| 4303 } |
| 4304 } |
| 4305 return this.animationTiming |
| 4306 }, |
| 4307 setPrefixedProperty: function(node, property, value) { |
| 4308 var map = { |
| 4309 transform: ["webkitTransform"], |
| 4310 transformOrigin: ["mozTransformOrigin", "webkitTransformOrigin"] |
| 4311 }; |
| 4312 var prefixes = map[property]; |
| 4313 for (var prefix, index = 0; prefix = prefixes[index]; index++) { |
| 4314 node.style[prefix] = value |
| 4315 } |
| 4316 node.style[property] = value |
| 4317 }, |
| 4318 complete: function() {} |
| 4319 }; |
| 4320 Polymer({ |
| 4321 is: "opaque-animation", |
| 4322 behaviors: [Polymer.NeonAnimationBehavior], |
| 4323 configure: function(config) { |
| 4324 var node = config.node; |
| 4325 this._effect = new KeyframeEffect( |
| 4326 node, [{opacity: "1"}, {opacity: "1"}], this.timingFromConfig(config)); |
| 4327 node.style.opacity = "0"; |
| 4328 return this._effect |
| 4329 }, |
| 4330 complete: function(config) { |
| 4331 config.node.style.opacity = "" |
| 4332 } |
| 4333 }); |
| 4334 (function() { |
| 4335 "use strict"; |
| 4336 var LAST_TOUCH_POSITION = {pageX: 0, pageY: 0}; |
| 4337 var ROOT_TARGET = null; |
| 4338 var SCROLLABLE_NODES = []; |
| 4339 Polymer.IronDropdownScrollManager = { |
| 4340 get currentLockingElement() { |
| 4341 return this._lockingElements[this._lockingElements.length - 1] |
| 4342 }, |
| 4343 elementIsScrollLocked: function(element) { |
| 4344 var currentLockingElement = this.currentLockingElement; |
| 4345 if (currentLockingElement === undefined) |
| 4346 return false; |
| 4347 var scrollLocked; |
| 4348 if (this._hasCachedLockedElement(element)) { |
| 4349 return true |
| 4350 } |
| 4351 if (this._hasCachedUnlockedElement(element)) { |
| 4352 return false |
| 4353 } |
| 4354 scrollLocked = !!currentLockingElement && |
| 4355 currentLockingElement !== element && |
| 4356 !this._composedTreeContains(currentLockingElement, element); |
| 4357 if (scrollLocked) { |
| 4358 this._lockedElementCache.push(element) |
| 4359 } else { |
| 4360 this._unlockedElementCache.push(element) |
| 4361 } |
| 4362 return scrollLocked |
| 4363 }, |
| 4364 pushScrollLock: function(element) { |
| 4365 if (this._lockingElements.indexOf(element) >= 0) { |
| 4366 return |
| 4367 } |
| 4368 if (this._lockingElements.length === 0) { |
| 4369 this._lockScrollInteractions() |
| 4370 } |
| 4371 this._lockingElements.push(element); |
| 4372 this._lockedElementCache = []; |
| 4373 this._unlockedElementCache = [] |
| 4374 }, |
| 4375 removeScrollLock: function(element) { |
| 4376 var index = this._lockingElements.indexOf(element); |
| 4377 if (index === -1) { |
| 4378 return |
| 4379 } |
| 4380 this._lockingElements.splice(index, 1); |
| 4381 this._lockedElementCache = []; |
| 4382 this._unlockedElementCache = []; |
| 4383 if (this._lockingElements.length === 0) { |
| 4384 this._unlockScrollInteractions() |
| 4385 } |
| 4386 }, |
| 4387 _lockingElements: [], |
| 4388 _lockedElementCache: null, |
| 4389 _unlockedElementCache: null, |
| 4390 _hasCachedLockedElement: function(element) { |
| 4391 return this._lockedElementCache.indexOf(element) > -1 |
| 4392 }, |
| 4393 _hasCachedUnlockedElement: function(element) { |
| 4394 return this._unlockedElementCache.indexOf(element) > -1 |
| 4395 }, |
| 4396 _composedTreeContains: function(element, child) { |
| 4397 var contentElements; |
| 4398 var distributedNodes; |
| 4399 var contentIndex; |
| 4400 var nodeIndex; |
| 4401 if (element.contains(child)) { |
| 4402 return true |
| 4403 } |
| 4404 contentElements = Polymer.dom(element).querySelectorAll("content"); |
| 4405 for (contentIndex = 0; contentIndex < contentElements.length; |
| 4406 ++contentIndex) { |
| 4407 distributedNodes = |
| 4408 Polymer.dom(contentElements[contentIndex]).getDistributedNodes(); |
| 4409 for (nodeIndex = 0; nodeIndex < distributedNodes.length; ++nodeIndex) { |
| 4410 if (this._composedTreeContains(distributedNodes[nodeIndex], child)) { |
| 4411 return true |
| 4412 } |
| 4413 } |
| 4414 } |
| 4415 return false |
| 4416 }, |
| 4417 _scrollInteractionHandler: function(event) { |
| 4418 if (event.cancelable && this._shouldPreventScrolling(event)) { |
| 4419 event.preventDefault() |
| 4420 } |
| 4421 if (event.targetTouches) { |
| 4422 var touch = event.targetTouches[0]; |
| 4423 LAST_TOUCH_POSITION.pageX = touch.pageX; |
| 4424 LAST_TOUCH_POSITION.pageY = touch.pageY |
| 4425 } |
| 4426 }, |
| 4427 _lockScrollInteractions: function() { |
| 4428 this._boundScrollHandler = |
| 4429 this._boundScrollHandler || this._scrollInteractionHandler.bind(this); |
| 4430 document.addEventListener("wheel", this._boundScrollHandler, true); |
| 4431 document.addEventListener("mousewheel", this._boundScrollHandler, true); |
| 4432 document.addEventListener( |
| 4433 "DOMMouseScroll", this._boundScrollHandler, true); |
| 4434 document.addEventListener("touchstart", this._boundScrollHandler, true); |
| 4435 document.addEventListener("touchmove", this._boundScrollHandler, true) |
| 4436 }, |
| 4437 _unlockScrollInteractions: function() { |
| 4438 document.removeEventListener("wheel", this._boundScrollHandler, true); |
| 4439 document.removeEventListener( |
| 4440 "mousewheel", this._boundScrollHandler, true); |
| 4441 document.removeEventListener( |
| 4442 "DOMMouseScroll", this._boundScrollHandler, true); |
| 4443 document.removeEventListener( |
| 4444 "touchstart", this._boundScrollHandler, true); |
| 4445 document.removeEventListener("touchmove", this._boundScrollHandler, true) |
| 4446 }, |
| 4447 _shouldPreventScrolling: function(event) { |
| 4448 var target = Polymer.dom(event).rootTarget; |
| 4449 if (event.type !== "touchmove" && ROOT_TARGET !== target) { |
| 4450 ROOT_TARGET = target; |
| 4451 SCROLLABLE_NODES = this._getScrollableNodes(Polymer.dom(event).path) |
| 4452 } |
| 4453 if (!SCROLLABLE_NODES.length) { |
| 4454 return true |
| 4455 } |
| 4456 if (event.type === "touchstart") { |
| 4457 return false |
| 4458 } |
| 4459 var info = this._getScrollInfo(event); |
| 4460 return !this._getScrollingNode(SCROLLABLE_NODES, info.deltaX, info.deltaY) |
| 4461 }, |
| 4462 _getScrollableNodes: function(nodes) { |
| 4463 var scrollables = []; |
| 4464 var lockingIndex = nodes.indexOf(this.currentLockingElement); |
| 4465 for (var i = 0; i <= lockingIndex; i++) { |
| 4466 var node = nodes[i]; |
| 4467 if (node.nodeType === 11) { |
| 4468 continue |
| 4469 } |
| 4470 var style = node.style; |
| 4471 if (style.overflow !== "scroll" && style.overflow !== "auto") { |
| 4472 style = window.getComputedStyle(node) |
| 4473 } |
| 4474 if (style.overflow === "scroll" || style.overflow === "auto") { |
| 4475 scrollables.push(node) |
| 4476 } |
| 4477 } |
| 4478 return scrollables |
| 4479 }, |
| 4480 _getScrollingNode: function(nodes, deltaX, deltaY) { |
| 4481 if (!deltaX && !deltaY) { |
| 4482 return |
| 4483 } |
| 4484 var verticalScroll = Math.abs(deltaY) >= Math.abs(deltaX); |
| 4485 for (var i = 0; i < nodes.length; i++) { |
| 4486 var node = nodes[i]; |
| 4487 var canScroll = false; |
| 4488 if (verticalScroll) { |
| 4489 canScroll = deltaY < 0 ? |
| 4490 node.scrollTop > 0 : |
| 4491 node.scrollTop < node.scrollHeight - node.clientHeight |
| 4492 } else { |
| 4493 canScroll = deltaX < 0 ? |
| 4494 node.scrollLeft > 0 : |
| 4495 node.scrollLeft < node.scrollWidth - node.clientWidth |
| 4496 } |
| 4497 if (canScroll) { |
| 4498 return node |
| 4499 } |
| 4500 } |
| 4501 }, |
| 4502 _getScrollInfo: function(event) { |
| 4503 var info = {deltaX: event.deltaX, deltaY: event.deltaY}; |
| 4504 if ("deltaX" in event) { |
| 4505 } else if ("wheelDeltaX" in event) { |
| 4506 info.deltaX = -event.wheelDeltaX; |
| 4507 info.deltaY = -event.wheelDeltaY |
| 4508 } else if ("axis" in event) { |
| 4509 info.deltaX = event.axis === 1 ? event.detail : 0; |
| 4510 info.deltaY = event.axis === 2 ? event.detail : 0 |
| 4511 } else if (event.targetTouches) { |
| 4512 var touch = event.targetTouches[0]; |
| 4513 info.deltaX = LAST_TOUCH_POSITION.pageX - touch.pageX; |
| 4514 info.deltaY = LAST_TOUCH_POSITION.pageY - touch.pageY |
| 4515 } |
| 4516 return info |
| 4517 } |
| 4518 } |
| 4519 })(); |
| 4520 (function() { |
| 4521 "use strict"; |
| 4522 Polymer({ |
| 4523 is: "iron-dropdown", |
| 4524 behaviors: [ |
| 4525 Polymer.IronControlState, Polymer.IronA11yKeysBehavior, |
| 4526 Polymer.IronOverlayBehavior, Polymer.NeonAnimationRunnerBehavior |
| 4527 ], |
| 4528 properties: { |
| 4529 horizontalAlign: {type: String, value: "left", reflectToAttribute: true}, |
| 4530 verticalAlign: {type: String, value: "top", reflectToAttribute: true}, |
| 4531 openAnimationConfig: {type: Object}, |
| 4532 closeAnimationConfig: {type: Object}, |
| 4533 focusTarget: {type: Object}, |
| 4534 noAnimations: {type: Boolean, value: false}, |
| 4535 allowOutsideScroll: {type: Boolean, value: false}, |
| 4536 _boundOnCaptureScroll: { |
| 4537 type: Function, |
| 4538 value: function() { |
| 4539 return this._onCaptureScroll.bind(this) |
| 4540 } |
| 4541 } |
| 4542 }, |
| 4543 listeners: {"neon-animation-finish": "_onNeonAnimationFinish"}, |
| 4544 observers: [ |
| 4545 "_updateOverlayPosition(positionTarget, verticalAlign, horizontalAlign, ve
rticalOffset, horizontalOffset)" |
| 4546 ], |
| 4547 get containedElement() { |
| 4548 return Polymer.dom(this.$.content).getDistributedNodes()[0] |
| 4549 }, |
| 4550 get _focusTarget() { |
| 4551 return this.focusTarget || this.containedElement |
| 4552 }, |
| 4553 ready: function() { |
| 4554 this._scrollTop = 0; |
| 4555 this._scrollLeft = 0; |
| 4556 this._refitOnScrollRAF = null |
| 4557 }, |
| 4558 attached: function() { |
| 4559 if (!this.sizingTarget || this.sizingTarget === this) { |
| 4560 this.sizingTarget = this.containedElement |
| 4561 } |
| 4562 }, |
| 4563 detached: function() { |
| 4564 this.cancelAnimation(); |
| 4565 document.removeEventListener("scroll", this._boundOnCaptureScroll); |
| 4566 Polymer.IronDropdownScrollManager.removeScrollLock(this) |
| 4567 }, |
| 4568 _openedChanged: function() { |
| 4569 if (this.opened && this.disabled) { |
| 4570 this.cancel() |
| 4571 } else { |
| 4572 this.cancelAnimation(); |
| 4573 this._updateAnimationConfig(); |
| 4574 this._saveScrollPosition(); |
| 4575 if (this.opened) { |
| 4576 document.addEventListener("scroll", this._boundOnCaptureScroll); |
| 4577 !this.allowOutsideScroll && |
| 4578 Polymer.IronDropdownScrollManager.pushScrollLock(this) |
| 4579 } else { |
| 4580 document.removeEventListener("scroll", this._boundOnCaptureScroll); |
| 4581 Polymer.IronDropdownScrollManager.removeScrollLock(this) |
| 4582 } |
| 4583 Polymer.IronOverlayBehaviorImpl._openedChanged.apply(this, arguments) |
| 4584 } |
| 4585 }, |
| 4586 _renderOpened: function() { |
| 4587 if (!this.noAnimations && this.animationConfig.open) { |
| 4588 this.$.contentWrapper.classList.add("animating"); |
| 4589 this.playAnimation("open") |
| 4590 } else { |
| 4591 Polymer.IronOverlayBehaviorImpl._renderOpened.apply(this, arguments) |
| 4592 } |
| 4593 }, |
| 4594 _renderClosed: function() { |
| 4595 if (!this.noAnimations && this.animationConfig.close) { |
| 4596 this.$.contentWrapper.classList.add("animating"); |
| 4597 this.playAnimation("close") |
| 4598 } else { |
| 4599 Polymer.IronOverlayBehaviorImpl._renderClosed.apply(this, arguments) |
| 4600 } |
| 4601 }, |
| 4602 _onNeonAnimationFinish: function() { |
| 4603 this.$.contentWrapper.classList.remove("animating"); |
| 4604 if (this.opened) { |
| 4605 this._finishRenderOpened() |
| 4606 } else { |
| 4607 this._finishRenderClosed() |
| 4608 } |
| 4609 }, |
| 4610 _onCaptureScroll: function() { |
| 4611 if (!this.allowOutsideScroll) { |
| 4612 this._restoreScrollPosition() |
| 4613 } else { |
| 4614 this._refitOnScrollRAF && |
| 4615 window.cancelAnimationFrame(this._refitOnScrollRAF); |
| 4616 this._refitOnScrollRAF = |
| 4617 window.requestAnimationFrame(this.refit.bind(this)) |
| 4618 } |
| 4619 }, |
| 4620 _saveScrollPosition: function() { |
| 4621 if (document.scrollingElement) { |
| 4622 this._scrollTop = document.scrollingElement.scrollTop; |
| 4623 this._scrollLeft = document.scrollingElement.scrollLeft |
| 4624 } else { |
| 4625 this._scrollTop = Math.max( |
| 4626 document.documentElement.scrollTop, document.body.scrollTop); |
| 4627 this._scrollLeft = Math.max( |
| 4628 document.documentElement.scrollLeft, document.body.scrollLeft) |
| 4629 } |
| 4630 }, |
| 4631 _restoreScrollPosition: function() { |
| 4632 if (document.scrollingElement) { |
| 4633 document.scrollingElement.scrollTop = this._scrollTop; |
| 4634 document.scrollingElement.scrollLeft = this._scrollLeft |
| 4635 } else { |
| 4636 document.documentElement.scrollTop = this._scrollTop; |
| 4637 document.documentElement.scrollLeft = this._scrollLeft; |
| 4638 document.body.scrollTop = this._scrollTop; |
| 4639 document.body.scrollLeft = this._scrollLeft |
| 4640 } |
| 4641 }, |
| 4642 _updateAnimationConfig: function() { |
| 4643 var animations = (this.openAnimationConfig || |
| 4644 []).concat(this.closeAnimationConfig || []); |
| 4645 for (var i = 0; i < animations.length; i++) { |
| 4646 animations[i].node = this.containedElement |
| 4647 } |
| 4648 this.animationConfig = { |
| 4649 open: this.openAnimationConfig, |
| 4650 close: this.closeAnimationConfig |
| 4651 } |
| 4652 }, |
| 4653 _updateOverlayPosition: function() { |
| 4654 if (this.isAttached) { |
| 4655 this.notifyResize() |
| 4656 } |
| 4657 }, |
| 4658 _applyFocus: function() { |
| 4659 var focusTarget = this.focusTarget || this.containedElement; |
| 4660 if (focusTarget && this.opened && !this.noAutoFocus) { |
| 4661 focusTarget.focus() |
| 4662 } else { |
| 4663 Polymer.IronOverlayBehaviorImpl._applyFocus.apply(this, arguments) |
| 4664 } |
| 4665 } |
| 4666 }) |
| 4667 })(); |
| 4668 Polymer({ |
| 4669 is: "fade-in-animation", |
| 4670 behaviors: [Polymer.NeonAnimationBehavior], |
| 4671 configure: function(config) { |
| 4672 var node = config.node; |
| 4673 this._effect = new KeyframeEffect( |
| 4674 node, [{opacity: "0"}, {opacity: "1"}], this.timingFromConfig(config)); |
| 4675 return this._effect |
| 4676 } |
| 4677 }); |
| 4678 Polymer({ |
| 4679 is: "fade-out-animation", |
| 4680 behaviors: [Polymer.NeonAnimationBehavior], |
| 4681 configure: function(config) { |
| 4682 var node = config.node; |
| 4683 this._effect = new KeyframeEffect( |
| 4684 node, [{opacity: "1"}, {opacity: "0"}], this.timingFromConfig(config)); |
| 4685 return this._effect |
| 4686 } |
| 4687 }); |
| 4688 Polymer({ |
| 4689 is: "paper-menu-grow-height-animation", |
| 4690 behaviors: [Polymer.NeonAnimationBehavior], |
| 4691 configure: function(config) { |
| 4692 var node = config.node; |
| 4693 var rect = node.getBoundingClientRect(); |
| 4694 var height = rect.height; |
| 4695 this._effect = new KeyframeEffect( |
| 4696 node, [{height: height / 2 + "px"}, {height: height + "px"}], |
| 4697 this.timingFromConfig(config)); |
| 4698 return this._effect |
| 4699 } |
| 4700 }); |
| 4701 Polymer({ |
| 4702 is: "paper-menu-grow-width-animation", |
| 4703 behaviors: [Polymer.NeonAnimationBehavior], |
| 4704 configure: function(config) { |
| 4705 var node = config.node; |
| 4706 var rect = node.getBoundingClientRect(); |
| 4707 var width = rect.width; |
| 4708 this._effect = new KeyframeEffect( |
| 4709 node, [{width: width / 2 + "px"}, {width: width + "px"}], |
| 4710 this.timingFromConfig(config)); |
| 4711 return this._effect |
| 4712 } |
| 4713 }); |
| 4714 Polymer({ |
| 4715 is: "paper-menu-shrink-width-animation", |
| 4716 behaviors: [Polymer.NeonAnimationBehavior], |
| 4717 configure: function(config) { |
| 4718 var node = config.node; |
| 4719 var rect = node.getBoundingClientRect(); |
| 4720 var width = rect.width; |
| 4721 this._effect = new KeyframeEffect( |
| 4722 node, [{width: width + "px"}, {width: width - width / 20 + "px"}], |
| 4723 this.timingFromConfig(config)); |
| 4724 return this._effect |
| 4725 } |
| 4726 }); |
| 4727 Polymer({ |
| 4728 is: "paper-menu-shrink-height-animation", |
| 4729 behaviors: [Polymer.NeonAnimationBehavior], |
| 4730 configure: function(config) { |
| 4731 var node = config.node; |
| 4732 var rect = node.getBoundingClientRect(); |
| 4733 var height = rect.height; |
| 4734 var top = rect.top; |
| 4735 this.setPrefixedProperty(node, "transformOrigin", "0 0"); |
| 4736 this._effect = new KeyframeEffect( |
| 4737 node, |
| 4738 [ |
| 4739 {height: height + "px", transform: "translateY(0)"}, |
| 4740 {height: height / 2 + "px", transform: "translateY(-20px)"} |
| 4741 ], |
| 4742 this.timingFromConfig(config)); |
| 4743 return this._effect |
| 4744 } |
| 4745 }); |
| 4746 (function() { |
| 4747 "use strict"; |
| 4748 var config = { |
| 4749 ANIMATION_CUBIC_BEZIER: "cubic-bezier(.3,.95,.5,1)", |
| 4750 MAX_ANIMATION_TIME_MS: 400 |
| 4751 }; |
| 4752 var PaperMenuButton = Polymer({ |
| 4753 is: "paper-menu-button", |
| 4754 behaviors: [Polymer.IronA11yKeysBehavior, Polymer.IronControlState], |
| 4755 properties: { |
| 4756 opened: { |
| 4757 type: Boolean, |
| 4758 value: false, |
| 4759 notify: true, |
| 4760 observer: "_openedChanged" |
| 4761 }, |
| 4762 horizontalAlign: {type: String, value: "left", reflectToAttribute: true}, |
| 4763 verticalAlign: {type: String, value: "top", reflectToAttribute: true}, |
| 4764 dynamicAlign: {type: Boolean}, |
| 4765 horizontalOffset: {type: Number, value: 0, notify: true}, |
| 4766 verticalOffset: {type: Number, value: 0, notify: true}, |
| 4767 noOverlap: {type: Boolean}, |
| 4768 noAnimations: {type: Boolean, value: false}, |
| 4769 ignoreSelect: {type: Boolean, value: false}, |
| 4770 closeOnActivate: {type: Boolean, value: false}, |
| 4771 openAnimationConfig: { |
| 4772 type: Object, |
| 4773 value: function() { |
| 4774 return [ |
| 4775 {name: "fade-in-animation", timing: {delay: 100, duration: 200}}, { |
| 4776 name: "paper-menu-grow-width-animation", |
| 4777 timing: { |
| 4778 delay: 100, |
| 4779 duration: 150, |
| 4780 easing: config.ANIMATION_CUBIC_BEZIER |
| 4781 } |
| 4782 }, |
| 4783 { |
| 4784 name: "paper-menu-grow-height-animation", |
| 4785 timing: { |
| 4786 delay: 100, |
| 4787 duration: 275, |
| 4788 easing: config.ANIMATION_CUBIC_BEZIER |
| 4789 } |
| 4790 } |
| 4791 ] |
| 4792 } |
| 4793 }, |
| 4794 closeAnimationConfig: { |
| 4795 type: Object, |
| 4796 value: function() { |
| 4797 return [ |
| 4798 {name: "fade-out-animation", timing: {duration: 150}}, { |
| 4799 name: "paper-menu-shrink-width-animation", |
| 4800 timing: { |
| 4801 delay: 100, |
| 4802 duration: 50, |
| 4803 easing: config.ANIMATION_CUBIC_BEZIER |
| 4804 } |
| 4805 }, |
| 4806 { |
| 4807 name: "paper-menu-shrink-height-animation", |
| 4808 timing: {duration: 200, easing: "ease-in"} |
| 4809 } |
| 4810 ] |
| 4811 } |
| 4812 }, |
| 4813 allowOutsideScroll: {type: Boolean, value: false}, |
| 4814 restoreFocusOnClose: {type: Boolean, value: true}, |
| 4815 _dropdownContent: {type: Object} |
| 4816 }, |
| 4817 hostAttributes: {role: "group", "aria-haspopup": "true"}, |
| 4818 listeners: |
| 4819 {"iron-activate": "_onIronActivate", "iron-select": "_onIronSelect"}, |
| 4820 get contentElement() { |
| 4821 return Polymer.dom(this.$.content).getDistributedNodes()[0] |
| 4822 }, |
| 4823 toggle: function() { |
| 4824 if (this.opened) { |
| 4825 this.close() |
| 4826 } else { |
| 4827 this.open() |
| 4828 } |
| 4829 }, |
| 4830 open: function() { |
| 4831 if (this.disabled) { |
| 4832 return |
| 4833 } |
| 4834 this.$.dropdown.open() |
| 4835 }, |
| 4836 close: function() { |
| 4837 this.$.dropdown.close() |
| 4838 }, |
| 4839 _onIronSelect: function(event) { |
| 4840 if (!this.ignoreSelect) { |
| 4841 this.close() |
| 4842 } |
| 4843 }, |
| 4844 _onIronActivate: function(event) { |
| 4845 if (this.closeOnActivate) { |
| 4846 this.close() |
| 4847 } |
| 4848 }, |
| 4849 _openedChanged: function(opened, oldOpened) { |
| 4850 if (opened) { |
| 4851 this._dropdownContent = this.contentElement; |
| 4852 this.fire("paper-dropdown-open") |
| 4853 } else if (oldOpened != null) { |
| 4854 this.fire("paper-dropdown-close") |
| 4855 } |
| 4856 }, |
| 4857 _disabledChanged: function(disabled) { |
| 4858 Polymer.IronControlState._disabledChanged.apply(this, arguments); |
| 4859 if (disabled && this.opened) { |
| 4860 this.close() |
| 4861 } |
| 4862 }, |
| 4863 __onIronOverlayCanceled: function(event) { |
| 4864 var uiEvent = event.detail; |
| 4865 var target = Polymer.dom(uiEvent).rootTarget; |
| 4866 var trigger = this.$.trigger; |
| 4867 var path = Polymer.dom(uiEvent).path; |
| 4868 if (path.indexOf(trigger) > -1) { |
| 4869 event.preventDefault() |
| 4870 } |
| 4871 } |
| 4872 }); |
| 4873 Object.keys(config).forEach(function(key) { |
| 4874 PaperMenuButton[key] = config[key] |
| 4875 }); |
| 4876 Polymer.PaperMenuButton = PaperMenuButton |
| 4877 })(); |
| 4878 Polymer.PaperInkyFocusBehaviorImpl = { |
| 4879 observers: ["_focusedChanged(receivedFocusFromKeyboard)"], |
| 4880 _focusedChanged: function(receivedFocusFromKeyboard) { |
| 4881 if (receivedFocusFromKeyboard) { |
| 4882 this.ensureRipple() |
| 4883 } |
| 4884 if (this.hasRipple()) { |
| 4885 this._ripple.holdDown = receivedFocusFromKeyboard |
| 4886 } |
| 4887 }, |
| 4888 _createRipple: function() { |
| 4889 var ripple = Polymer.PaperRippleBehavior._createRipple(); |
| 4890 ripple.id = "ink"; |
| 4891 ripple.setAttribute("center", ""); |
| 4892 ripple.classList.add("circle"); |
| 4893 return ripple |
| 4894 } |
| 4895 }; |
| 4896 Polymer.PaperInkyFocusBehavior = [ |
| 4897 Polymer.IronButtonState, Polymer.IronControlState, |
| 4898 Polymer.PaperRippleBehavior, Polymer.PaperInkyFocusBehaviorImpl |
| 4899 ]; |
| 4900 Polymer({ |
| 4901 is: "paper-icon-button", |
| 4902 hostAttributes: {role: "button", tabindex: "0"}, |
| 4903 behaviors: [Polymer.PaperInkyFocusBehavior], |
| 4904 properties: { |
| 4905 src: {type: String}, |
| 4906 icon: {type: String}, |
| 4907 alt: {type: String, observer: "_altChanged"} |
| 4908 }, |
| 4909 _altChanged: function(newValue, oldValue) { |
| 4910 var label = this.getAttribute("aria-label"); |
| 4911 if (!label || oldValue == label) { |
| 4912 this.setAttribute("aria-label", newValue) |
| 4913 } |
| 4914 } |
| 4915 }); |
| 4916 Polymer({ |
| 4917 is: "iron-media-query", |
| 4918 properties: { |
| 4919 queryMatches: {type: Boolean, value: false, readOnly: true, notify: true}, |
| 4920 query: {type: String, observer: "queryChanged"}, |
| 4921 full: {type: Boolean, value: false}, |
| 4922 _boundMQHandler: { |
| 4923 value: function() { |
| 4924 return this.queryHandler.bind(this) |
| 4925 } |
| 4926 }, |
| 4927 _mq: {value: null} |
| 4928 }, |
| 4929 attached: function() { |
| 4930 this.style.display = "none"; |
| 4931 this.queryChanged() |
| 4932 }, |
| 4933 detached: function() { |
| 4934 this._remove() |
| 4935 }, |
| 4936 _add: function() { |
| 4937 if (this._mq) { |
| 4938 this._mq.addListener(this._boundMQHandler) |
| 4939 } |
| 4940 }, |
| 4941 _remove: function() { |
| 4942 if (this._mq) { |
| 4943 this._mq.removeListener(this._boundMQHandler) |
| 4944 } |
| 4945 this._mq = null |
| 4946 }, |
| 4947 queryChanged: function() { |
| 4948 this._remove(); |
| 4949 var query = this.query; |
| 4950 if (!query) { |
| 4951 return |
| 4952 } |
| 4953 if (!this.full && query[0] !== "(") { |
| 4954 query = "(" + query + ")" |
| 4955 } |
| 4956 this._mq = window.matchMedia(query); |
| 4957 this._add(); |
| 4958 this.queryHandler(this._mq) |
| 4959 }, |
| 4960 queryHandler: function(mq) { |
| 4961 this._setQueryMatches(mq.matches) |
| 4962 } |
| 4963 }); |
| 4964 Polymer.PaperSpinnerBehavior = { |
| 4965 listeners: {animationend: "__reset", webkitAnimationEnd: "__reset"}, |
| 4966 properties: { |
| 4967 active: { |
| 4968 type: Boolean, |
| 4969 value: false, |
| 4970 reflectToAttribute: true, |
| 4971 observer: "__activeChanged" |
| 4972 }, |
| 4973 alt: {type: String, value: "loading", observer: "__altChanged"}, |
| 4974 __coolingDown: {type: Boolean, value: false} |
| 4975 }, |
| 4976 __computeContainerClasses: function(active, coolingDown) { |
| 4977 return [ |
| 4978 active || coolingDown ? "active" : "", coolingDown ? "cooldown" : "" |
| 4979 ].join(" ") |
| 4980 }, |
| 4981 __activeChanged: function(active, old) { |
| 4982 this.__setAriaHidden(!active); |
| 4983 this.__coolingDown = !active && old |
| 4984 }, |
| 4985 __altChanged: function(alt) { |
| 4986 if (alt === this.getPropertyInfo("alt").value) { |
| 4987 this.alt = this.getAttribute("aria-label") || alt |
| 4988 } else { |
| 4989 this.__setAriaHidden(alt === ""); |
| 4990 this.setAttribute("aria-label", alt) |
| 4991 } |
| 4992 }, |
| 4993 __setAriaHidden: function(hidden) { |
| 4994 var attr = "aria-hidden"; |
| 4995 if (hidden) { |
| 4996 this.setAttribute(attr, "true") |
| 4997 } else { |
| 4998 this.removeAttribute(attr) |
| 4999 } |
| 5000 }, |
| 5001 __reset: function() { |
| 5002 this.active = false; |
| 5003 this.__coolingDown = false |
| 5004 } |
| 5005 }; |
| 5006 Polymer({is: "paper-spinner-lite", behaviors: [Polymer.PaperSpinnerBehavior]}); |
| 48 // Copyright 2016 The Chromium Authors. All rights reserved. | 5007 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 49 // Use of this source code is governed by a BSD-style license that can be | 5008 // Use of this source code is governed by a BSD-style license that can be |
| 50 // found in the LICENSE file. | 5009 // found in the LICENSE file. |
| 51 var CrSearchFieldBehavior={properties:{label:{type:String,value:""},clearLabel:{
type:String,value:""},lastValue_:{type:String,value:""}},getSearchInput:function
(){},getValue:function(){return this.getSearchInput().value},setValue:function(v
alue,opt_noEvent){var searchInput=this.getSearchInput();searchInput.value=value;
this.onValueChanged_(value,!!opt_noEvent)},onSearchTermSearch:function(){this.on
ValueChanged_(this.getValue(),false)},onValueChanged_:function(newValue,noEvent)
{if(newValue==this.lastValue_)return;this.lastValue_=newValue;if(!noEvent)this.f
ire("search-changed",newValue)}}; | 5010 var CrSearchFieldBehavior = { |
| 5011 properties: { |
| 5012 label: {type: String, value: ""}, |
| 5013 clearLabel: {type: String, value: ""}, |
| 5014 lastValue_: {type: String, value: ""} |
| 5015 }, |
| 5016 getSearchInput: function() {}, |
| 5017 getValue: function() { |
| 5018 return this.getSearchInput().value |
| 5019 }, |
| 5020 setValue: function(value, opt_noEvent) { |
| 5021 var searchInput = this.getSearchInput(); |
| 5022 searchInput.value = value; |
| 5023 this.onValueChanged_(value, !!opt_noEvent) |
| 5024 }, |
| 5025 onSearchTermSearch: function() { |
| 5026 this.onValueChanged_(this.getValue(), false) |
| 5027 }, |
| 5028 onValueChanged_: function(newValue, noEvent) { |
| 5029 if (newValue == this.lastValue_) |
| 5030 return; |
| 5031 this.lastValue_ = newValue; |
| 5032 if (!noEvent) |
| 5033 this.fire("search-changed", newValue) |
| 5034 } |
| 5035 }; |
| 52 // Copyright 2016 The Chromium Authors. All rights reserved. | 5036 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 53 // Use of this source code is governed by a BSD-style license that can be | 5037 // Use of this source code is governed by a BSD-style license that can be |
| 54 // found in the LICENSE file. | 5038 // found in the LICENSE file. |
| 55 Polymer({is:"cr-toolbar-search-field",behaviors:[CrSearchFieldBehavior],properti
es:{narrow:{type:Boolean,reflectToAttribute:true},showingSearch:{type:Boolean,va
lue:false,notify:true,observer:"showingSearchChanged_",reflectToAttribute:true},
label:String,clearLabel:String,spinnerActive:{type:Boolean,reflectToAttribute:tr
ue},hasSearchText_:{type:Boolean,reflectToAttribute:true},isSpinnerShown_:{type:
Boolean,computed:"computeIsSpinnerShown_(spinnerActive, showingSearch)"},searchF
ocused_:{type:Boolean,value:false}},listeners:{click:"showSearch_"},getSearchInp
ut:function(){return this.$.searchInput},setValue:function(value,opt_noEvent){Cr
SearchFieldBehavior.setValue.call(this,value,opt_noEvent);this.onSearchInput_()}
,isSearchFocused:function(){return this.searchFocused_},showAndFocus:function(){
this.showingSearch=true;this.focus_()},focus_:function(){this.getSearchInput().f
ocus()},computeIconTabIndex_:function(narrow){return narrow?0:-1},computeIsSpinn
erShown_:function(){return this.spinnerActive&&this.showingSearch},onInputFocus_
:function(){this.searchFocused_=true},onInputBlur_:function(){this.searchFocused
_=false;if(!this.hasSearchText_)this.showingSearch=false},onSearchInput_:functio
n(){var newValue=this.$.searchInput.value;this.hasSearchText_=newValue!="";if(ne
wValue!="")this.showingSearch=true},onSearchTermKeydown_:function(e){if(e.key=="
Escape")this.showingSearch=false},showSearch_:function(e){if(e.target!=this.$.cl
earSearch)this.showingSearch=true},clearSearch_:function(e){this.setValue("");th
is.focus_()},showingSearchChanged_:function(current,previous){if(previous==undef
ined)return;if(this.showingSearch){this.focus_();return}this.setValue("");this.g
etSearchInput().blur()}}); | 5039 Polymer({ |
| 5040 is: "cr-toolbar-search-field", |
| 5041 behaviors: [CrSearchFieldBehavior], |
| 5042 properties: { |
| 5043 narrow: {type: Boolean, reflectToAttribute: true}, |
| 5044 showingSearch: { |
| 5045 type: Boolean, |
| 5046 value: false, |
| 5047 notify: true, |
| 5048 observer: "showingSearchChanged_", |
| 5049 reflectToAttribute: true |
| 5050 }, |
| 5051 label: String, |
| 5052 clearLabel: String, |
| 5053 spinnerActive: {type: Boolean, reflectToAttribute: true}, |
| 5054 hasSearchText_: {type: Boolean, reflectToAttribute: true}, |
| 5055 isSpinnerShown_: { |
| 5056 type: Boolean, |
| 5057 computed: "computeIsSpinnerShown_(spinnerActive, showingSearch)" |
| 5058 }, |
| 5059 searchFocused_: {type: Boolean, value: false} |
| 5060 }, |
| 5061 listeners: {click: "showSearch_"}, |
| 5062 getSearchInput: function() { |
| 5063 return this.$.searchInput |
| 5064 }, |
| 5065 setValue: function(value, opt_noEvent) { |
| 5066 CrSearchFieldBehavior.setValue.call(this, value, opt_noEvent); |
| 5067 this.onSearchInput_() |
| 5068 }, |
| 5069 isSearchFocused: function() { |
| 5070 return this.searchFocused_ |
| 5071 }, |
| 5072 showAndFocus: function() { |
| 5073 this.showingSearch = true; |
| 5074 this.focus_() |
| 5075 }, |
| 5076 focus_: function() { |
| 5077 this.getSearchInput().focus() |
| 5078 }, |
| 5079 computeIconTabIndex_: function(narrow) { |
| 5080 return narrow ? 0 : -1 |
| 5081 }, |
| 5082 computeIsSpinnerShown_: function() { |
| 5083 return this.spinnerActive && this.showingSearch |
| 5084 }, |
| 5085 onInputFocus_: function() { |
| 5086 this.searchFocused_ = true |
| 5087 }, |
| 5088 onInputBlur_: function() { |
| 5089 this.searchFocused_ = false; |
| 5090 if (!this.hasSearchText_) |
| 5091 this.showingSearch = false |
| 5092 }, |
| 5093 onSearchInput_: function() { |
| 5094 var newValue = this.$.searchInput.value; |
| 5095 this.hasSearchText_ = newValue != ""; |
| 5096 if (newValue != "") |
| 5097 this.showingSearch = true |
| 5098 }, |
| 5099 onSearchTermKeydown_: function(e) { |
| 5100 if (e.key == "Escape") |
| 5101 this.showingSearch = false |
| 5102 }, |
| 5103 showSearch_: function(e) { |
| 5104 if (e.target != this.$.clearSearch) |
| 5105 this.showingSearch = true |
| 5106 }, |
| 5107 clearSearch_: function(e) { |
| 5108 this.setValue(""); |
| 5109 this.focus_() |
| 5110 }, |
| 5111 showingSearchChanged_: function(current, previous) { |
| 5112 if (previous == undefined) |
| 5113 return; |
| 5114 if (this.showingSearch) { |
| 5115 this.focus_(); |
| 5116 return |
| 5117 } |
| 5118 this.setValue(""); |
| 5119 this.getSearchInput().blur() |
| 5120 } |
| 5121 }); |
| 56 // Copyright 2016 The Chromium Authors. All rights reserved. | 5122 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 57 // Use of this source code is governed by a BSD-style license that can be | 5123 // Use of this source code is governed by a BSD-style license that can be |
| 58 // found in the LICENSE file. | 5124 // found in the LICENSE file. |
| 59 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.fire("cr-toolbar-menu-promo-close")},onMenuTap_:funct
ion(){this.fire("cr-toolbar-menu-tap")},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-toolbar-menu-promo-shown")}}.bind(this))
},titleIfNotShowMenuPromo_:function(title,showMenuPromo){return showMenuPromo?""
:title}}); | 5125 Polymer({ |
| 5126 is: "cr-toolbar", |
| 5127 properties: { |
| 5128 pageName: String, |
| 5129 searchPrompt: String, |
| 5130 clearLabel: String, |
| 5131 menuLabel: String, |
| 5132 menuPromo: String, |
| 5133 spinnerActive: Boolean, |
| 5134 showMenu: {type: Boolean, value: false}, |
| 5135 showMenuPromo: {type: Boolean, value: false}, |
| 5136 closeMenuPromo: String, |
| 5137 narrow_: {type: Boolean, reflectToAttribute: true}, |
| 5138 showingSearch_: {type: Boolean, reflectToAttribute: true} |
| 5139 }, |
| 5140 observers: |
| 5141 ["possiblyShowMenuPromo_(showMenu, showMenuPromo, showingSearch_)"], |
| 5142 getSearchField: function() { |
| 5143 return this.$.search |
| 5144 }, |
| 5145 onClosePromoTap_: function() { |
| 5146 this.fire("cr-toolbar-menu-promo-close") |
| 5147 }, |
| 5148 onMenuTap_: function() { |
| 5149 this.fire("cr-toolbar-menu-tap") |
| 5150 }, |
| 5151 possiblyShowMenuPromo_: function() { |
| 5152 Polymer.RenderStatus.afterNextRender(this, function() { |
| 5153 if (this.showMenu && this.showMenuPromo && !this.showingSearch_) { |
| 5154 this.$$("#menuPromo") |
| 5155 .animate({opacity: [0, .9]}, {duration: 500, fill: "forwards"}); |
| 5156 this.fire("cr-toolbar-menu-promo-shown") |
| 5157 } |
| 5158 }.bind(this)) |
| 5159 }, |
| 5160 titleIfNotShowMenuPromo_: function(title, showMenuPromo) { |
| 5161 return showMenuPromo ? "" : title |
| 5162 } |
| 5163 }); |
| 60 // Copyright 2015 The Chromium Authors. All rights reserved. | 5164 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 61 // Use of this source code is governed by a BSD-style license that can be | 5165 // Use of this source code is governed by a BSD-style license that can be |
| 62 // found in the LICENSE file. | 5166 // found in the LICENSE file. |
| 63 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}}); | 5167 cr.define("downloads", function() { |
| 5168 var Toolbar = Polymer({ |
| 5169 is: "downloads-toolbar", |
| 5170 properties: { |
| 5171 downloadsShowing: { |
| 5172 reflectToAttribute: true, |
| 5173 type: Boolean, |
| 5174 value: false, |
| 5175 observer: "downloadsShowingChanged_" |
| 5176 }, |
| 5177 spinnerActive: {type: Boolean, notify: true} |
| 5178 }, |
| 5179 listeners: { |
| 5180 "paper-dropdown-close": "onPaperDropdownClose_", |
| 5181 "paper-dropdown-open": "onPaperDropdownOpen_" |
| 5182 }, |
| 5183 canUndo: function() { |
| 5184 return !this.$.toolbar.getSearchField().isSearchFocused() |
| 5185 }, |
| 5186 canClearAll: function() { |
| 5187 return !this.$.toolbar.getSearchField().getValue() && |
| 5188 this.downloadsShowing |
| 5189 }, |
| 5190 onFindCommand: function() { |
| 5191 this.$.toolbar.getSearchField().showAndFocus() |
| 5192 }, |
| 5193 closeMoreActions_: function() { |
| 5194 this.$.more.close() |
| 5195 }, |
| 5196 downloadsShowingChanged_: function() { |
| 5197 this.updateClearAll_() |
| 5198 }, |
| 5199 onClearAllTap_: function() { |
| 5200 assert(this.canClearAll()); |
| 5201 downloads.ActionService.getInstance().clearAll() |
| 5202 }, |
| 5203 onPaperDropdownClose_: function() { |
| 5204 window.removeEventListener("resize", assert(this.boundClose_)) |
| 5205 }, |
| 5206 onItemBlur_: function(e) { |
| 5207 var menu = this.$$("paper-menu"); |
| 5208 if (menu.items.indexOf(e.relatedTarget) >= 0) |
| 5209 return; |
| 5210 this.$.more.restoreFocusOnClose = false; |
| 5211 this.closeMoreActions_(); |
| 5212 this.$.more.restoreFocusOnClose = true |
| 5213 }, |
| 5214 onPaperDropdownOpen_: function() { |
| 5215 this.boundClose_ = this.boundClose_ || this.closeMoreActions_.bind(this); |
| 5216 window.addEventListener("resize", this.boundClose_) |
| 5217 }, |
| 5218 onSearchChanged_: function(event) { |
| 5219 var actionService = downloads.ActionService.getInstance(); |
| 5220 if (actionService.search(event.detail)) |
| 5221 this.spinnerActive = actionService.isSearching(); |
| 5222 this.updateClearAll_() |
| 5223 }, |
| 5224 onOpenDownloadsFolderTap_: function() { |
| 5225 downloads.ActionService.getInstance().openDownloadsFolder() |
| 5226 }, |
| 5227 updateClearAll_: function() { |
| 5228 this.$$("paper-menu .clear-all").hidden = !this.canClearAll() |
| 5229 } |
| 5230 }); |
| 5231 return { |
| 5232 Toolbar: Toolbar |
| 5233 } |
| 5234 }); |
| 64 // Copyright 2015 The Chromium Authors. All rights reserved. | 5235 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 65 // Use of this source code is governed by a BSD-style license that can be | 5236 // Use of this source code is governed by a BSD-style license that can be |
| 66 // found in the LICENSE file. | 5237 // found in the LICENSE file. |
| 67 cr.define("downloads",function(){var Manager=Polymer({is:"downloads-manager",pro
perties:{hasDownloads_:{observer:"hasDownloadsChanged_",type:Boolean},hasShadow_
:{type:Boolean,value:false,reflectToAttribute:true},inSearchMode_:{type:Boolean,
value:false},items_:{type:Array,value:function(){return[]}},spinnerActive_:{type
:Boolean,notify:true}},hostAttributes:{loading:true},listeners:{"downloads-list.
scroll":"onListScroll_","toolbar.search-changed":"onSearchChanged_"},observers:[
"itemsChanged_(items_.*)"],loaded_:new PromiseResolver,clearAll_:function(){this
.set("items_",[])},hasDownloadsChanged_:function(){if(loadTimeData.getBoolean("a
llowDeletingHistory"))this.$.toolbar.downloadsShowing=this.hasDownloads_;if(this
.hasDownloads_)this.$["downloads-list"].fire("iron-resize")},insertItems_:functi
on(index,list){this.splice.apply(this,["items_",index,0].concat(list));this.upda
teHideDates_(index,index+list.length);if(this.hasAttribute("loading")){this.remo
veAttribute("loading");this.loaded_.resolve()}this.spinnerActive_=false},itemsCh
anged_:function(){this.hasDownloads_=this.items_.length>0},noDownloadsText_:func
tion(){return loadTimeData.getString(this.inSearchMode_?"noSearchResults":"noDow
nloads")},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-command":e.canExecute=true;break}}
,onCommand_:function(e){if(e.command.id=="clear-all-command")downloads.ActionSer
vice.getInstance().clearAll();else if(e.command.id=="undo-command")downloads.Act
ionService.getInstance().undo();else if(e.command.id=="find-command")this.$.tool
bar.onFindCommand()},onListScroll_:function(){var list=this.$["downloads-list"];
if(list.scrollHeight-list.scrollTop-list.offsetHeight<=100){downloads.ActionServ
ice.getInstance().loadMore()}this.hasShadow_=list.scrollTop>0},onLoad_:function(
){cr.ui.decorate("command",cr.ui.Command);document.addEventListener("canExecute"
,this.onCanExecute_.bind(this));document.addEventListener("command",this.onComma
nd_.bind(this));downloads.ActionService.getInstance().loadMore();return this.loa
ded_.promise},onSearchChanged_:function(){this.inSearchMode_=downloads.ActionSer
vice.getInstance().isSearching()},removeItem_:function(index){this.splice("items
_",index,1);this.updateHideDates_(index,index);this.onListScroll_()},updateHideD
ates_:function(start,end){for(var i=start;i<=end;++i){var current=this.items_[i]
;if(!current)continue;var prev=this.items_[i-1];var hideDate=!!prev&&prev.date_s
tring==current.date_string;this.set("items_."+i+".hideDate",hideDate)}},updateIt
em_:function(index,data){this.set("items_."+index,data);this.updateHideDates_(in
dex,index);var list=this.$["downloads-list"];list.updateSizeForItem(index)}});Ma
nager.clearAll=function(){Manager.get().clearAll_()};Manager.get=function(){retu
rn queryRequiredElement("downloads-manager")};Manager.insertItems=function(index
,list){Manager.get().insertItems_(index,list)};Manager.onLoad=function(){return
Manager.get().onLoad_()};Manager.removeItem=function(index){Manager.get().remove
Item_(index)};Manager.updateItem=function(index,data){Manager.get().updateItem_(
index,data)};return{Manager:Manager}}); | 5238 cr.define("downloads", function() { |
| 5239 var Manager = Polymer({ |
| 5240 is: "downloads-manager", |
| 5241 properties: { |
| 5242 hasDownloads_: {observer: "hasDownloadsChanged_", type: Boolean}, |
| 5243 hasShadow_: {type: Boolean, value: false, reflectToAttribute: true}, |
| 5244 inSearchMode_: {type: Boolean, value: false}, |
| 5245 items_: { |
| 5246 type: Array, |
| 5247 value: function() { |
| 5248 return [] |
| 5249 } |
| 5250 }, |
| 5251 spinnerActive_: {type: Boolean, notify: true} |
| 5252 }, |
| 5253 hostAttributes: {loading: true}, |
| 5254 listeners: { |
| 5255 "downloads-list.scroll": "onListScroll_", |
| 5256 "toolbar.search-changed": "onSearchChanged_" |
| 5257 }, |
| 5258 observers: ["itemsChanged_(items_.*)"], |
| 5259 loaded_: new PromiseResolver, |
| 5260 clearAll_: function() { |
| 5261 this.set("items_", []) |
| 5262 }, |
| 5263 hasDownloadsChanged_: function() { |
| 5264 if (loadTimeData.getBoolean("allowDeletingHistory")) |
| 5265 this.$.toolbar.downloadsShowing = this.hasDownloads_; |
| 5266 if (this.hasDownloads_) |
| 5267 this.$["downloads-list"].fire("iron-resize") |
| 5268 }, |
| 5269 insertItems_: function(index, list) { |
| 5270 this.splice.apply(this, ["items_", index, 0].concat(list)); |
| 5271 this.updateHideDates_(index, index + list.length); |
| 5272 if (this.hasAttribute("loading")) { |
| 5273 this.removeAttribute("loading"); |
| 5274 this.loaded_.resolve() |
| 5275 } |
| 5276 this.spinnerActive_ = false |
| 5277 }, |
| 5278 itemsChanged_: function() { |
| 5279 this.hasDownloads_ = this.items_.length > 0 |
| 5280 }, |
| 5281 noDownloadsText_: function() { |
| 5282 return loadTimeData.getString( |
| 5283 this.inSearchMode_ ? "noSearchResults" : "noDownloads") |
| 5284 }, |
| 5285 onCanExecute_: function(e) { |
| 5286 e = e; |
| 5287 switch (e.command.id) { |
| 5288 case "undo-command": |
| 5289 e.canExecute = this.$.toolbar.canUndo(); |
| 5290 break; |
| 5291 case "clear-all-command": |
| 5292 e.canExecute = this.$.toolbar.canClearAll(); |
| 5293 break; |
| 5294 case "find-command": |
| 5295 e.canExecute = true; |
| 5296 break |
| 5297 } |
| 5298 }, |
| 5299 onCommand_: function(e) { |
| 5300 if (e.command.id == "clear-all-command") |
| 5301 downloads.ActionService.getInstance().clearAll(); |
| 5302 else if (e.command.id == "undo-command") |
| 5303 downloads.ActionService.getInstance().undo(); |
| 5304 else if (e.command.id == "find-command") |
| 5305 this.$.toolbar.onFindCommand() |
| 5306 }, |
| 5307 onListScroll_: function() { |
| 5308 var list = this.$["downloads-list"]; |
| 5309 if (list.scrollHeight - list.scrollTop - list.offsetHeight <= 100) { |
| 5310 downloads.ActionService.getInstance().loadMore() |
| 5311 } |
| 5312 this.hasShadow_ = list.scrollTop > 0 |
| 5313 }, |
| 5314 onLoad_: function() { |
| 5315 cr.ui.decorate("command", cr.ui.Command); |
| 5316 document.addEventListener("canExecute", this.onCanExecute_.bind(this)); |
| 5317 document.addEventListener("command", this.onCommand_.bind(this)); |
| 5318 downloads.ActionService.getInstance().loadMore(); |
| 5319 return this.loaded_.promise |
| 5320 }, |
| 5321 onSearchChanged_: function() { |
| 5322 this.inSearchMode_ = downloads.ActionService.getInstance().isSearching() |
| 5323 }, |
| 5324 removeItem_: function(index) { |
| 5325 this.splice("items_", index, 1); |
| 5326 this.updateHideDates_(index, index); |
| 5327 this.onListScroll_() |
| 5328 }, |
| 5329 updateHideDates_: function(start, end) { |
| 5330 for (var i = start; i <= end; ++i) { |
| 5331 var current = this.items_[i]; |
| 5332 if (!current) |
| 5333 continue; |
| 5334 var prev = this.items_[i - 1]; |
| 5335 var hideDate = !!prev && prev.date_string == current.date_string; |
| 5336 this.set("items_." + i + ".hideDate", hideDate) |
| 5337 } |
| 5338 }, |
| 5339 updateItem_: function(index, data) { |
| 5340 this.set("items_." + index, data); |
| 5341 this.updateHideDates_(index, index); |
| 5342 var list = this.$["downloads-list"]; |
| 5343 list.updateSizeForItem(index) |
| 5344 } |
| 5345 }); |
| 5346 Manager.clearAll = function() { |
| 5347 Manager.get().clearAll_() |
| 5348 }; |
| 5349 Manager.get = function() { |
| 5350 return queryRequiredElement("downloads-manager") |
| 5351 }; |
| 5352 Manager.insertItems = function(index, list) { |
| 5353 Manager.get().insertItems_(index, list) |
| 5354 }; |
| 5355 Manager.onLoad = function() { |
| 5356 return Manager.get().onLoad_() |
| 5357 }; |
| 5358 Manager.removeItem = function(index) { |
| 5359 Manager.get().removeItem_(index) |
| 5360 }; |
| 5361 Manager.updateItem = function(index, data) { |
| 5362 Manager.get().updateItem_(index, data) |
| 5363 }; |
| 5364 return { |
| 5365 Manager: Manager |
| 5366 } |
| 5367 }); |
| 68 // Copyright 2015 The Chromium Authors. All rights reserved. | 5368 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 69 // Use of this source code is governed by a BSD-style license that can be | 5369 // Use of this source code is governed by a BSD-style license that can be |
| 70 // found in the LICENSE file. | 5370 // found in the LICENSE file. |
| 71 window.addEventListener("load",function(){downloads.Manager.onLoad().then(functi
on(){requestIdleCallback(function(){chrome.send("metricsHandler:recordTime",["Do
wnload.ResultsRenderedTime",window.performance.now()]);document.fonts.load("bold
12px Roboto")})})}); | 5371 window.addEventListener("load", function() { |
| 5372 downloads.Manager.onLoad().then(function() { |
| 5373 requestIdleCallback(function() { |
| 5374 chrome.send( |
| 5375 "metricsHandler:recordTime", |
| 5376 ["Download.ResultsRenderedTime", window.performance.now()]); |
| 5377 document.fonts.load("bold 12px Roboto") |
| 5378 }) |
| 5379 }) |
| 5380 }); |
| OLD | NEW |