| OLD | NEW |
| 1 Polymer({is:"iron-collapse",behaviors:[Polymer.IronResizableBehavior],properties
:{horizontal:{type:Boolean,value:false,observer:"_horizontalChanged"},opened:{ty
pe:Boolean,value:false,notify:true,observer:"_openedChanged"},noAnimation:{type:
Boolean},_desiredSize:{type:String,value:""}},get dimension(){return this.horizo
ntal?"width":"height"},get _dimensionMax(){return this.horizontal?"maxWidth":"ma
xHeight"},get _dimensionMaxCss(){return this.horizontal?"max-width":"max-height"
},hostAttributes:{role:"group","aria-hidden":"true","aria-expanded":"false"},lis
teners:{transitionend:"_transitionEnd"},attached:function(){this._transitionEnd(
)},toggle:function(){this.opened=!this.opened},show:function(){this.opened=true}
,hide:function(){this.opened=false},updateSize:function(size,animated){size=size
==="auto"?"":size;if(this._desiredSize===size){return}this._desiredSize=size;thi
s._updateTransition(false);var willAnimate=animated&&!this.noAnimation&&this._is
Displayed;if(willAnimate){var startSize=this._calcSize();if(size===""){this.styl
e[this._dimensionMax]="";size=this._calcSize()}this.style[this._dimensionMax]=st
artSize;this.scrollTop=this.scrollTop;this._updateTransition(true);willAnimate=s
ize!==startSize}this.style[this._dimensionMax]=size;if(!willAnimate){this._trans
itionEnd()}},enableTransition:function(enabled){Polymer.Base._warn("`enableTrans
ition()` is deprecated, use `noAnimation` instead.");this.noAnimation=!enabled},
_updateTransition:function(enabled){this.style.transitionDuration=enabled&&!this
.noAnimation?"":"0s"},_horizontalChanged:function(){this.style.transitionPropert
y=this._dimensionMaxCss;var otherDimension=this._dimensionMax==="maxWidth"?"maxH
eight":"maxWidth";this.style[otherDimension]="";this.updateSize(this.opened?"aut
o":"0px",false)},_openedChanged:function(){this.setAttribute("aria-expanded",thi
s.opened);this.setAttribute("aria-hidden",!this.opened);this.toggleClass("iron-c
ollapse-closed",false);this.toggleClass("iron-collapse-opened",false);this.updat
eSize(this.opened?"auto":"0px",true);if(this.opened){this.focus()}},_transitionE
nd:function(){this.style[this._dimensionMax]=this._desiredSize;this.toggleClass(
"iron-collapse-closed",!this.opened);this.toggleClass("iron-collapse-opened",thi
s.opened);this._updateTransition(false);this.notifyResize()},get _isDisplayed(){
var rect=this.getBoundingClientRect();for(var prop in rect){if(rect[prop]!==0)re
turn true}return false},_calcSize:function(){return this.getBoundingClientRect()
[this.dimension]+"px"}}); | 1 Polymer({ |
| 2 is: "iron-collapse", |
| 3 behaviors: [Polymer.IronResizableBehavior], |
| 4 properties: { |
| 5 horizontal: {type: Boolean, value: false, observer: "_horizontalChanged"}, |
| 6 opened: |
| 7 {type: Boolean, value: false, notify: true, observer: "_openedChanged"}, |
| 8 noAnimation: {type: Boolean}, |
| 9 _desiredSize: {type: String, value: ""} |
| 10 }, |
| 11 get dimension() { |
| 12 return this.horizontal ? "width" : "height" |
| 13 }, |
| 14 get _dimensionMax() { |
| 15 return this.horizontal ? "maxWidth" : "maxHeight" |
| 16 }, |
| 17 get _dimensionMaxCss() { |
| 18 return this.horizontal ? "max-width" : "max-height" |
| 19 }, |
| 20 hostAttributes: |
| 21 {role: "group", "aria-hidden": "true", "aria-expanded": "false"}, |
| 22 listeners: {transitionend: "_transitionEnd"}, |
| 23 attached: function() { |
| 24 this._transitionEnd() |
| 25 }, |
| 26 toggle: function() { |
| 27 this.opened = !this.opened |
| 28 }, |
| 29 show: function() { |
| 30 this.opened = true |
| 31 }, |
| 32 hide: function() { |
| 33 this.opened = false |
| 34 }, |
| 35 updateSize: function(size, animated) { |
| 36 size = size === "auto" ? "" : size; |
| 37 if (this._desiredSize === size) { |
| 38 return |
| 39 } |
| 40 this._desiredSize = size; |
| 41 this._updateTransition(false); |
| 42 var willAnimate = animated && !this.noAnimation && this._isDisplayed; |
| 43 if (willAnimate) { |
| 44 var startSize = this._calcSize(); |
| 45 if (size === "") { |
| 46 this.style[this._dimensionMax] = ""; |
| 47 size = this._calcSize() |
| 48 } |
| 49 this.style[this._dimensionMax] = startSize; |
| 50 this.scrollTop = this.scrollTop; |
| 51 this._updateTransition(true); |
| 52 willAnimate = size !== startSize |
| 53 } |
| 54 this.style[this._dimensionMax] = size; |
| 55 if (!willAnimate) { |
| 56 this._transitionEnd() |
| 57 } |
| 58 }, |
| 59 enableTransition: function(enabled) { |
| 60 Polymer.Base._warn( |
| 61 "`enableTransition()` is deprecated, use `noAnimation` instead."); |
| 62 this.noAnimation = !enabled |
| 63 }, |
| 64 _updateTransition: function(enabled) { |
| 65 this.style.transitionDuration = enabled && !this.noAnimation ? "" : "0s" |
| 66 }, |
| 67 _horizontalChanged: function() { |
| 68 this.style.transitionProperty = this._dimensionMaxCss; |
| 69 var otherDimension = |
| 70 this._dimensionMax === "maxWidth" ? "maxHeight" : "maxWidth"; |
| 71 this.style[otherDimension] = ""; |
| 72 this.updateSize(this.opened ? "auto" : "0px", false) |
| 73 }, |
| 74 _openedChanged: function() { |
| 75 this.setAttribute("aria-expanded", this.opened); |
| 76 this.setAttribute("aria-hidden", !this.opened); |
| 77 this.toggleClass("iron-collapse-closed", false); |
| 78 this.toggleClass("iron-collapse-opened", false); |
| 79 this.updateSize(this.opened ? "auto" : "0px", true); |
| 80 if (this.opened) { |
| 81 this.focus() |
| 82 } |
| 83 }, |
| 84 _transitionEnd: function() { |
| 85 this.style[this._dimensionMax] = this._desiredSize; |
| 86 this.toggleClass("iron-collapse-closed", !this.opened); |
| 87 this.toggleClass("iron-collapse-opened", this.opened); |
| 88 this._updateTransition(false); |
| 89 this.notifyResize() |
| 90 }, |
| 91 get _isDisplayed() { |
| 92 var rect = this.getBoundingClientRect(); |
| 93 for (var prop in rect) { |
| 94 if (rect[prop] !== 0) |
| 95 return true |
| 96 } |
| 97 return false |
| 98 }, |
| 99 _calcSize: function() { |
| 100 return this.getBoundingClientRect()[this.dimension] + "px" |
| 101 } |
| 102 }); |
| 2 // Copyright 2016 The Chromium Authors. All rights reserved. | 103 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 // Use of this source code is governed by a BSD-style license that can be | 104 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 105 // found in the LICENSE file. |
| 5 var HistoryDomain;var HistoryGroup;Polymer({is:"history-grouped-list",behaviors:
[HistoryListBehavior],properties:{searchedTerm:{type:String,value:""},groupedHis
toryData_:Array,historyData:Array,queryStartTime:String,queryEndTime:String,rang
e:Number},observers:["updateGroupedHistoryData_(range, historyData)"],addNewResu
lts:function(results,incremental,finished){this.historyData=results},createHisto
ryDomains_:function(visits){var domainIndexes={};var domains=[];for(var i=0,visi
t;visit=visits[i];i++){var domain=visit.domain;if(domainIndexes[domain]==undefin
ed){domainIndexes[domain]=domains.length;domains.push({domain:domain,visits:[],e
xpanded:false,rendered:false})}domains[domainIndexes[domain]].visits.push(visit)
}var sortByVisits=function(a,b){return b.visits.length-a.visits.length};domains.
sort(sortByVisits);return domains},updateGroupedHistoryData_:function(){if(this.
historyData.length==0){this.groupedHistoryData_=[];return}if(this.range==History
Range.WEEK){var days=[];var currentDayVisits=[this.historyData[0]];var pushCurre
ntDay=function(){days.push({title:this.searchedTerm?currentDayVisits[0].dateShor
t:currentDayVisits[0].dateRelativeDay,domains:this.createHistoryDomains_(current
DayVisits)})}.bind(this);var visitsSameDay=function(a,b){if(this.searchedTerm)re
turn a.dateShort==b.dateShort;return a.dateRelativeDay==b.dateRelativeDay}.bind(
this);for(var i=1;i<this.historyData.length;i++){var visit=this.historyData[i];i
f(!visitsSameDay(visit,currentDayVisits[0])){pushCurrentDay();currentDayVisits=[
]}currentDayVisits.push(visit)}pushCurrentDay();this.groupedHistoryData_=days}el
se if(this.range==HistoryRange.MONTH){this.groupedHistoryData_=[{title:this.quer
yStartTime+" – "+this.queryEndTime,domains:this.createHistoryDomains_(this.histo
ryData)}]}},toggleDomainExpanded_:function(e){var collapse=e.currentTarget.paren
tNode.querySelector("iron-collapse");e.model.set("domain.rendered",true);setTime
out(function(){collapse.toggle()},0)},needsTimeGap_:function(groupIndex,domainIn
dex,itemIndex){var visits=this.groupedHistoryData_[groupIndex].domains[domainInd
ex].visits;return md_history.HistoryItem.needsTimeGap(visits,itemIndex,this.sear
chedTerm)},pathForItem_:function(groupIndex,domainIndex,itemIndex){return["group
edHistoryData_",groupIndex,"domains",domainIndex,"visits",itemIndex].join(".")},
getWebsiteIconStyle_:function(domain){return"background-image: "+cr.icon.getFavi
con(domain.visits[0].url)},getDropdownIcon_:function(expanded){return expanded?"
cr:expand-less":"cr:expand-more"}}); | 106 var HistoryDomain; |
| 107 var HistoryGroup; |
| 108 Polymer({ |
| 109 is: "history-grouped-list", |
| 110 behaviors: [HistoryListBehavior], |
| 111 properties: { |
| 112 searchedTerm: {type: String, value: ""}, |
| 113 groupedHistoryData_: Array, |
| 114 historyData: Array, |
| 115 queryStartTime: String, |
| 116 queryEndTime: String, |
| 117 range: Number |
| 118 }, |
| 119 observers: ["updateGroupedHistoryData_(range, historyData)"], |
| 120 addNewResults: function(results, incremental, finished) { |
| 121 this.historyData = results |
| 122 }, |
| 123 createHistoryDomains_: function(visits) { |
| 124 var domainIndexes = {}; |
| 125 var domains = []; |
| 126 for (var i = 0, visit; visit = visits[i]; i++) { |
| 127 var domain = visit.domain; |
| 128 if (domainIndexes[domain] == undefined) { |
| 129 domainIndexes[domain] = domains.length; |
| 130 domains.push( |
| 131 {domain: domain, visits: [], expanded: false, rendered: false}) |
| 132 } |
| 133 domains[domainIndexes[domain]].visits.push(visit) |
| 134 } |
| 135 var sortByVisits = function(a, b) { |
| 136 return b.visits.length - a.visits.length |
| 137 }; |
| 138 domains.sort(sortByVisits); |
| 139 return domains |
| 140 }, |
| 141 updateGroupedHistoryData_: function() { |
| 142 if (this.historyData.length == 0) { |
| 143 this.groupedHistoryData_ = []; |
| 144 return |
| 145 } |
| 146 if (this.range == HistoryRange.WEEK) { |
| 147 var days = []; |
| 148 var currentDayVisits = [this.historyData[0]]; |
| 149 var pushCurrentDay = function() { |
| 150 days.push({ |
| 151 title: this.searchedTerm ? currentDayVisits[0].dateShort : |
| 152 currentDayVisits[0].dateRelativeDay, |
| 153 domains: this.createHistoryDomains_(currentDayVisits) |
| 154 }) |
| 155 }.bind(this); |
| 156 var visitsSameDay = function(a, b) { |
| 157 if (this.searchedTerm) |
| 158 return a.dateShort == b.dateShort; |
| 159 return a.dateRelativeDay == b.dateRelativeDay |
| 160 }.bind(this); |
| 161 for (var i = 1; i < this.historyData.length; i++) { |
| 162 var visit = this.historyData[i]; |
| 163 if (!visitsSameDay(visit, currentDayVisits[0])) { |
| 164 pushCurrentDay(); |
| 165 currentDayVisits = [] |
| 166 } |
| 167 currentDayVisits.push(visit) |
| 168 } |
| 169 pushCurrentDay(); |
| 170 this.groupedHistoryData_ = days |
| 171 } else if (this.range == HistoryRange.MONTH) { |
| 172 this.groupedHistoryData_ = [{ |
| 173 title: this.queryStartTime + " – " + this.queryEndTime, |
| 174 domains: this.createHistoryDomains_(this.historyData) |
| 175 }] |
| 176 } |
| 177 }, |
| 178 toggleDomainExpanded_: function(e) { |
| 179 var collapse = e.currentTarget.parentNode.querySelector("iron-collapse"); |
| 180 e.model.set("domain.rendered", true); |
| 181 setTimeout(function() { |
| 182 collapse.toggle() |
| 183 }, 0) |
| 184 }, |
| 185 needsTimeGap_: function(groupIndex, domainIndex, itemIndex) { |
| 186 var visits = |
| 187 this.groupedHistoryData_[groupIndex].domains[domainIndex].visits; |
| 188 return md_history.HistoryItem.needsTimeGap( |
| 189 visits, itemIndex, this.searchedTerm) |
| 190 }, |
| 191 pathForItem_: function(groupIndex, domainIndex, itemIndex) { |
| 192 return [ |
| 193 "groupedHistoryData_", groupIndex, "domains", domainIndex, "visits", |
| 194 itemIndex |
| 195 ].join(".") |
| 196 }, |
| 197 getWebsiteIconStyle_: function(domain) { |
| 198 return "background-image: " + cr.icon.getFavicon(domain.visits[0].url) |
| 199 }, |
| 200 getDropdownIcon_: function(expanded) { |
| 201 return expanded ? "cr:expand-less" : "cr:expand-more" |
| 202 } |
| 203 }); |
| 6 // Copyright 2014 The Chromium Authors. All rights reserved. | 204 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 7 // Use of this source code is governed by a BSD-style license that can be | 205 // Use of this source code is governed by a BSD-style license that can be |
| 8 // found in the LICENSE file. | 206 // found in the LICENSE file. |
| 9 cr.define("cr.ui",function(){function FocusGrid(){this.rows=[]}FocusGrid.prototy
pe={ignoreFocusChange_:false,onFocus:function(row,e){if(this.ignoreFocusChange_)
this.ignoreFocusChange_=false;else this.lastFocused_=e.currentTarget;this.rows.f
orEach(function(r){r.makeActive(r==row)})},onKeydown:function(row,e){var rowInde
x=this.rows.indexOf(row);assert(rowIndex>=0);var newRow=-1;if(e.key=="ArrowUp")n
ewRow=rowIndex-1;else if(e.key=="ArrowDown")newRow=rowIndex+1;else if(e.key=="Pa
geUp")newRow=0;else if(e.key=="PageDown")newRow=this.rows.length-1;var rowToFocu
s=this.rows[newRow];if(rowToFocus){this.ignoreFocusChange_=true;rowToFocus.getEq
uivalentElement(this.lastFocused_).focus();e.preventDefault();return true}return
false},destroy:function(){this.rows.forEach(function(row){row.destroy()});this.
rows.length=0},getRowIndexForTarget:function(target){for(var i=0;i<this.rows.len
gth;++i){if(this.rows[i].getElements().indexOf(target)>=0)return i}return-1},get
RowForRoot:function(root){for(var i=0;i<this.rows.length;++i){if(this.rows[i].ro
ot==root)return this.rows[i]}return null},addRow:function(row){this.addRowBefore
(row,null)},addRowBefore:function(row,nextRow){row.delegate=row.delegate||this;v
ar nextRowIndex=nextRow?this.rows.indexOf(nextRow):-1;if(nextRowIndex==-1)this.r
ows.push(row);else this.rows.splice(nextRowIndex,0,row)},removeRow:function(row)
{var nextRowIndex=row?this.rows.indexOf(row):-1;if(nextRowIndex>-1)this.rows.spl
ice(nextRowIndex,1)},ensureRowActive:function(){if(this.rows.length==0)return;fo
r(var i=0;i<this.rows.length;++i){if(this.rows[i].isActive())return}this.rows[0]
.makeActive(true)}};return{FocusGrid:FocusGrid}});Polymer.PaperButtonBehaviorImp
l={properties:{elevation:{type:Number,reflectToAttribute:true,readOnly:true}},ob
servers:["_calculateElevation(focused, disabled, active, pressed, receivedFocusF
romKeyboard)","_computeKeyboardClass(receivedFocusFromKeyboard)"],hostAttributes
:{role:"button",tabindex:"0",animated:true},_calculateElevation:function(){var e
=1;if(this.disabled){e=0}else if(this.active||this.pressed){e=4}else if(this.rec
eivedFocusFromKeyboard){e=3}this._setElevation(e)},_computeKeyboardClass:functio
n(receivedFocusFromKeyboard){this.toggleClass("keyboard-focus",receivedFocusFrom
Keyboard)},_spaceKeyDownHandler:function(event){Polymer.IronButtonStateImpl._spa
ceKeyDownHandler.call(this,event);if(this.hasRipple()&&this.getRipple().ripples.
length<1){this._ripple.uiDownAction()}},_spaceKeyUpHandler:function(event){Polym
er.IronButtonStateImpl._spaceKeyUpHandler.call(this,event);if(this.hasRipple()){
this._ripple.uiUpAction()}}};Polymer.PaperButtonBehavior=[Polymer.IronButtonStat
e,Polymer.IronControlState,Polymer.PaperRippleBehavior,Polymer.PaperButtonBehavi
orImpl];Polymer({is:"paper-button",behaviors:[Polymer.PaperButtonBehavior],prope
rties:{raised:{type:Boolean,reflectToAttribute:true,value:false,observer:"_calcu
lateElevation"}},_calculateElevation:function(){if(!this.raised){this._setElevat
ion(0)}else{Polymer.PaperButtonBehaviorImpl._calculateElevation.apply(this)}}});
Polymer.PaperItemBehaviorImpl={hostAttributes:{role:"option",tabindex:"0"}};Poly
mer.PaperItemBehavior=[Polymer.IronButtonState,Polymer.IronControlState,Polymer.
PaperItemBehaviorImpl];Polymer({is:"paper-item",behaviors:[Polymer.PaperItemBeha
vior]}); | 207 cr.define("cr.ui", function() { |
| 208 function FocusGrid() { |
| 209 this.rows = [] |
| 210 } |
| 211 FocusGrid.prototype = { |
| 212 ignoreFocusChange_: false, |
| 213 onFocus: function(row, e) { |
| 214 if (this.ignoreFocusChange_) |
| 215 this.ignoreFocusChange_ = false; |
| 216 else |
| 217 this.lastFocused_ = e.currentTarget; |
| 218 this.rows.forEach(function(r) { |
| 219 r.makeActive(r == row) |
| 220 }) |
| 221 }, |
| 222 onKeydown: function(row, e) { |
| 223 var rowIndex = this.rows.indexOf(row); |
| 224 assert(rowIndex >= 0); |
| 225 var newRow = -1; |
| 226 if (e.key == "ArrowUp") |
| 227 newRow = rowIndex - 1; |
| 228 else if (e.key == "ArrowDown") |
| 229 newRow = rowIndex + 1; |
| 230 else if (e.key == "PageUp") |
| 231 newRow = 0; |
| 232 else if (e.key == "PageDown") |
| 233 newRow = this.rows.length - 1; |
| 234 var rowToFocus = this.rows[newRow]; |
| 235 if (rowToFocus) { |
| 236 this.ignoreFocusChange_ = true; |
| 237 rowToFocus.getEquivalentElement(this.lastFocused_).focus(); |
| 238 e.preventDefault(); |
| 239 return true |
| 240 } |
| 241 return false |
| 242 }, |
| 243 destroy: function() { |
| 244 this.rows.forEach(function(row) { |
| 245 row.destroy() |
| 246 }); |
| 247 this.rows.length = 0 |
| 248 }, |
| 249 getRowIndexForTarget: function(target) { |
| 250 for (var i = 0; i < this.rows.length; ++i) { |
| 251 if (this.rows[i].getElements().indexOf(target) >= 0) |
| 252 return i |
| 253 } |
| 254 return -1 |
| 255 }, |
| 256 getRowForRoot: function(root) { |
| 257 for (var i = 0; i < this.rows.length; ++i) { |
| 258 if (this.rows[i].root == root) |
| 259 return this.rows[i] |
| 260 } |
| 261 return null |
| 262 }, |
| 263 addRow: function(row) { |
| 264 this.addRowBefore(row, null) |
| 265 }, |
| 266 addRowBefore: function(row, nextRow) { |
| 267 row.delegate = row.delegate || this; |
| 268 var nextRowIndex = nextRow ? this.rows.indexOf(nextRow) : -1; |
| 269 if (nextRowIndex == -1) |
| 270 this.rows.push(row); |
| 271 else |
| 272 this.rows.splice(nextRowIndex, 0, row) |
| 273 }, |
| 274 removeRow: function(row) { |
| 275 var nextRowIndex = row ? this.rows.indexOf(row) : -1; |
| 276 if (nextRowIndex > -1) |
| 277 this.rows.splice(nextRowIndex, 1) |
| 278 }, |
| 279 ensureRowActive: function() { |
| 280 if (this.rows.length == 0) |
| 281 return; |
| 282 for (var i = 0; i < this.rows.length; ++i) { |
| 283 if (this.rows[i].isActive()) |
| 284 return |
| 285 } |
| 286 this.rows[0].makeActive(true) |
| 287 } |
| 288 }; |
| 289 return { |
| 290 FocusGrid: FocusGrid |
| 291 } |
| 292 }); |
| 293 Polymer.PaperButtonBehaviorImpl = { |
| 294 properties: |
| 295 {elevation: {type: Number, reflectToAttribute: true, readOnly: true}}, |
| 296 observers: [ |
| 297 "_calculateElevation(focused, disabled, active, pressed, receivedFocusFromKe
yboard)", |
| 298 "_computeKeyboardClass(receivedFocusFromKeyboard)" |
| 299 ], |
| 300 hostAttributes: {role: "button", tabindex: "0", animated: true}, |
| 301 _calculateElevation: function() { |
| 302 var e = 1; |
| 303 if (this.disabled) { |
| 304 e = 0 |
| 305 } else if (this.active || this.pressed) { |
| 306 e = 4 |
| 307 } else if (this.receivedFocusFromKeyboard) { |
| 308 e = 3 |
| 309 } |
| 310 this._setElevation(e) |
| 311 }, |
| 312 _computeKeyboardClass: function(receivedFocusFromKeyboard) { |
| 313 this.toggleClass("keyboard-focus", receivedFocusFromKeyboard) |
| 314 }, |
| 315 _spaceKeyDownHandler: function(event) { |
| 316 Polymer.IronButtonStateImpl._spaceKeyDownHandler.call(this, event); |
| 317 if (this.hasRipple() && this.getRipple().ripples.length < 1) { |
| 318 this._ripple.uiDownAction() |
| 319 } |
| 320 }, |
| 321 _spaceKeyUpHandler: function(event) { |
| 322 Polymer.IronButtonStateImpl._spaceKeyUpHandler.call(this, event); |
| 323 if (this.hasRipple()) { |
| 324 this._ripple.uiUpAction() |
| 325 } |
| 326 } |
| 327 }; |
| 328 Polymer.PaperButtonBehavior = [ |
| 329 Polymer.IronButtonState, Polymer.IronControlState, |
| 330 Polymer.PaperRippleBehavior, Polymer.PaperButtonBehaviorImpl |
| 331 ]; |
| 332 Polymer({ |
| 333 is: "paper-button", |
| 334 behaviors: [Polymer.PaperButtonBehavior], |
| 335 properties: { |
| 336 raised: { |
| 337 type: Boolean, |
| 338 reflectToAttribute: true, |
| 339 value: false, |
| 340 observer: "_calculateElevation" |
| 341 } |
| 342 }, |
| 343 _calculateElevation: function() { |
| 344 if (!this.raised) { |
| 345 this._setElevation(0) |
| 346 } else { |
| 347 Polymer.PaperButtonBehaviorImpl._calculateElevation.apply(this) |
| 348 } |
| 349 } |
| 350 }); |
| 351 Polymer.PaperItemBehaviorImpl = { |
| 352 hostAttributes: {role: "option", tabindex: "0"} |
| 353 }; |
| 354 Polymer.PaperItemBehavior = [ |
| 355 Polymer.IronButtonState, Polymer.IronControlState, |
| 356 Polymer.PaperItemBehaviorImpl |
| 357 ]; |
| 358 Polymer({is: "paper-item", behaviors: [Polymer.PaperItemBehavior]}); |
| 10 // Copyright 2016 The Chromium Authors. All rights reserved. | 359 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 11 // Use of this source code is governed by a BSD-style license that can be | 360 // Use of this source code is governed by a BSD-style license that can be |
| 12 // found in the LICENSE file. | 361 // found in the LICENSE file. |
| 13 Polymer({is:"cr-action-menu","extends":"dialog",options_:null,anchorElement_:nul
l,onWindowResize_:null,hostAttributes:{tabindex:0},listeners:{keydown:"onKeyDown
_",tap:"onTap_"},attached:function(){this.options_=this.querySelectorAll(".dropd
own-item")},detached:function(){this.removeResizeListener_()},removeResizeListen
er_:function(){window.removeEventListener("resize",this.onWindowResize_)},onTap_
:function(e){if(e.target==this){this.close();e.stopPropagation()}},onKeyDown_:fu
nction(e){if(e.key=="Tab"||e.key=="Escape"){this.close();e.preventDefault();retu
rn}if(e.key!=="ArrowDown"&&e.key!=="ArrowUp")return;var nextOption=this.getNextO
ption_(e.key=="ArrowDown"?1:-1);if(nextOption)nextOption.focus();e.preventDefaul
t()},getNextOption_:function(step){var counter=0;var nextOption=null;var numOpti
ons=this.options_.length;var focusedIndex=Array.prototype.indexOf.call(this.opti
ons_,this.root.activeElement);do{focusedIndex=(numOptions+focusedIndex+step)%num
Options;nextOption=this.options_[focusedIndex];if(nextOption.disabled||nextOptio
n.hidden)nextOption=null;counter++}while(!nextOption&&counter<numOptions);return
nextOption},close:function(){this.removeResizeListener_();HTMLDialogElement.pro
totype.close.call(this);this.anchorElement_.focus();this.anchorElement_=null},sh
owAt:function(anchorElement){this.anchorElement_=anchorElement;this.onWindowResi
ze_=this.onWindowResize_||function(){if(this.open)this.close()}.bind(this);windo
w.addEventListener("resize",this.onWindowResize_);this.showModal();var rect=this
.anchorElement_.getBoundingClientRect();if(getComputedStyle(this.anchorElement_)
.direction=="rtl"){var right=window.innerWidth-rect.left-this.offsetWidth;this.s
tyle.right=right+"px"}else{var left=rect.right-this.offsetWidth;this.style.left=
left+"px"}var top=rect.top+this.offsetHeight<=window.innerHeight?rect.top:rect.b
ottom-this.offsetHeight-Math.max(rect.bottom-window.innerHeight,0);this.style.to
p=top+"px"}});Polymer({is:"paper-icon-button-light","extends":"button",behaviors
:[Polymer.PaperRippleBehavior],listeners:{down:"_rippleDown",up:"_rippleUp",focu
s:"_rippleDown",blur:"_rippleUp"},_rippleDown:function(){this.getRipple().downAc
tion()},_rippleUp:function(){this.getRipple().upAction()},ensureRipple:function(
var_args){var lastRipple=this._ripple;Polymer.PaperRippleBehavior.ensureRipple.a
pply(this,arguments);if(this._ripple&&this._ripple!==lastRipple){this._ripple.ce
nter=true;this._ripple.classList.add("circle")}}}); | 362 Polymer({ |
| 363 is: "cr-action-menu", |
| 364 "extends": "dialog", |
| 365 options_: null, |
| 366 anchorElement_: null, |
| 367 onWindowResize_: null, |
| 368 hostAttributes: {tabindex: 0}, |
| 369 listeners: {keydown: "onKeyDown_", tap: "onTap_"}, |
| 370 attached: function() { |
| 371 this.options_ = this.querySelectorAll(".dropdown-item") |
| 372 }, |
| 373 detached: function() { |
| 374 this.removeResizeListener_() |
| 375 }, |
| 376 removeResizeListener_: function() { |
| 377 window.removeEventListener("resize", this.onWindowResize_) |
| 378 }, |
| 379 onTap_: function(e) { |
| 380 if (e.target == this) { |
| 381 this.close(); |
| 382 e.stopPropagation() |
| 383 } |
| 384 }, |
| 385 onKeyDown_: function(e) { |
| 386 if (e.key == "Tab" || e.key == "Escape") { |
| 387 this.close(); |
| 388 e.preventDefault(); |
| 389 return |
| 390 } |
| 391 if (e.key !== "ArrowDown" && e.key !== "ArrowUp") |
| 392 return; |
| 393 var nextOption = this.getNextOption_(e.key == "ArrowDown" ? 1 : -1); |
| 394 if (nextOption) |
| 395 nextOption.focus(); |
| 396 e.preventDefault() |
| 397 }, |
| 398 getNextOption_: function(step) { |
| 399 var counter = 0; |
| 400 var nextOption = null; |
| 401 var numOptions = this.options_.length; |
| 402 var focusedIndex = |
| 403 Array.prototype.indexOf.call(this.options_, this.root.activeElement); |
| 404 do { |
| 405 focusedIndex = (numOptions + focusedIndex + step) % numOptions; |
| 406 nextOption = this.options_[focusedIndex]; |
| 407 if (nextOption.disabled || nextOption.hidden) |
| 408 nextOption = null; |
| 409 counter++ |
| 410 } while (!nextOption && counter < numOptions); |
| 411 return nextOption |
| 412 }, |
| 413 close: function() { |
| 414 this.removeResizeListener_(); |
| 415 HTMLDialogElement.prototype.close.call(this); |
| 416 this.anchorElement_.focus(); |
| 417 this.anchorElement_ = null |
| 418 }, |
| 419 showAt: function(anchorElement) { |
| 420 this.anchorElement_ = anchorElement; |
| 421 this.onWindowResize_ = this.onWindowResize_ || function() { |
| 422 if (this.open) |
| 423 this.close() |
| 424 }.bind(this); |
| 425 window.addEventListener("resize", this.onWindowResize_); |
| 426 this.showModal(); |
| 427 var rect = this.anchorElement_.getBoundingClientRect(); |
| 428 if (getComputedStyle(this.anchorElement_).direction == "rtl") { |
| 429 var right = window.innerWidth - rect.left - this.offsetWidth; |
| 430 this.style.right = right + "px" |
| 431 } else { |
| 432 var left = rect.right - this.offsetWidth; |
| 433 this.style.left = left + "px" |
| 434 } |
| 435 var top = rect.top + this.offsetHeight <= window.innerHeight ? rect.top : |
| 436 rect.bottom - |
| 437 this.offsetHeight - Math.max(rect.bottom - window.innerHeight, 0); |
| 438 this.style.top = top + "px" |
| 439 } |
| 440 }); |
| 441 Polymer({ |
| 442 is: "paper-icon-button-light", |
| 443 "extends": "button", |
| 444 behaviors: [Polymer.PaperRippleBehavior], |
| 445 listeners: { |
| 446 down: "_rippleDown", |
| 447 up: "_rippleUp", |
| 448 focus: "_rippleDown", |
| 449 blur: "_rippleUp" |
| 450 }, |
| 451 _rippleDown: function() { |
| 452 this.getRipple().downAction() |
| 453 }, |
| 454 _rippleUp: function() { |
| 455 this.getRipple().upAction() |
| 456 }, |
| 457 ensureRipple: function(var_args) { |
| 458 var lastRipple = this._ripple; |
| 459 Polymer.PaperRippleBehavior.ensureRipple.apply(this, arguments); |
| 460 if (this._ripple && this._ripple !== lastRipple) { |
| 461 this._ripple.center = true; |
| 462 this._ripple.classList.add("circle") |
| 463 } |
| 464 } |
| 465 }); |
| 14 // Copyright 2016 The Chromium Authors. All rights reserved. | 466 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 15 // Use of this source code is governed by a BSD-style license that can be | 467 // Use of this source code is governed by a BSD-style license that can be |
| 16 // found in the LICENSE file. | 468 // found in the LICENSE file. |
| 17 Polymer({is:"history-synced-device-card",properties:{tabs:{type:Array,value:func
tion(){return[]},observer:"updateIcons_"},device:String,lastUpdateTime:String,op
ened:Boolean,searchTerm:String,separatorIndexes:Array,sessionTag:String},listene
rs:{"dom-change":"notifyFocusUpdate_"},createFocusRows:function(){var titleRow=n
ew cr.ui.FocusRow(this.$["card-heading"],null);titleRow.addItem("menu","#menu-bu
tton");titleRow.addItem("collapse","#collapse-button");var rows=[titleRow];if(th
is.opened){Polymer.dom(this.root).querySelectorAll(".item-container").forEach(fu
nction(el){var row=new cr.ui.FocusRow(el,null);row.addItem("title",".website-tit
le");rows.push(row)})}return rows},openTab_:function(e){var tab=e.model.tab;var
browserService=md_history.BrowserService.getInstance();browserService.recordHist
ogram(SYNCED_TABS_HISTOGRAM_NAME,SyncedTabsHistogram.LINK_CLICKED,SyncedTabsHist
ogram.LIMIT);browserService.openForeignSessionTab(this.sessionTag,tab.windowId,t
ab.sessionId,e);e.preventDefault()},toggleTabCard:function(){var histogramValue=
this.$.collapse.opened?SyncedTabsHistogram.COLLAPSE_SESSION:SyncedTabsHistogram.
EXPAND_SESSION;md_history.BrowserService.getInstance().recordHistogram(SYNCED_TA
BS_HISTOGRAM_NAME,histogramValue,SyncedTabsHistogram.LIMIT);this.$.collapse.togg
le();this.$["dropdown-indicator"].icon=this.$.collapse.opened?"cr:expand-less":"
cr:expand-more";this.fire("update-focus-grid")},notifyFocusUpdate_:function(){th
is.fire("update-focus-grid")},updateIcons_:function(){this.async(function(){var
icons=Polymer.dom(this.root).querySelectorAll(".website-icon");for(var i=0;i<thi
s.tabs.length;i++){icons[i].style.backgroundImage=cr.icon.getFavicon(this.tabs[i
].url)}})},isWindowSeparatorIndex_:function(index,separatorIndexes){return this.
separatorIndexes.indexOf(index)!=-1},getCollapseIcon_:function(opened){return op
ened?"cr:expand-less":"cr:expand-more"},getCollapseTitle_:function(opened){retur
n opened?loadTimeData.getString("collapseSessionButton"):loadTimeData.getString(
"expandSessionButton")},onMenuButtonTap_:function(e){this.fire("open-menu",{targ
et:Polymer.dom(e).localTarget,tag:this.sessionTag});e.stopPropagation()},onLinkR
ightClick_:function(){md_history.BrowserService.getInstance().recordHistogram(SY
NCED_TABS_HISTOGRAM_NAME,SyncedTabsHistogram.LINK_RIGHT_CLICKED,SyncedTabsHistog
ram.LIMIT)}}); | 469 Polymer({ |
| 470 is: "history-synced-device-card", |
| 471 properties: { |
| 472 tabs: { |
| 473 type: Array, |
| 474 value: function() { |
| 475 return [] |
| 476 }, |
| 477 observer: "updateIcons_" |
| 478 }, |
| 479 device: String, |
| 480 lastUpdateTime: String, |
| 481 opened: Boolean, |
| 482 searchTerm: String, |
| 483 separatorIndexes: Array, |
| 484 sessionTag: String |
| 485 }, |
| 486 listeners: {"dom-change": "notifyFocusUpdate_"}, |
| 487 createFocusRows: function() { |
| 488 var titleRow = new cr.ui.FocusRow(this.$["card-heading"], null); |
| 489 titleRow.addItem("menu", "#menu-button"); |
| 490 titleRow.addItem("collapse", "#collapse-button"); |
| 491 var rows = [titleRow]; |
| 492 if (this.opened) { |
| 493 Polymer.dom(this.root) |
| 494 .querySelectorAll(".item-container") |
| 495 .forEach(function(el) { |
| 496 var row = new cr.ui.FocusRow(el, null); |
| 497 row.addItem("title", ".website-title"); |
| 498 rows.push(row) |
| 499 }) |
| 500 } |
| 501 return rows |
| 502 }, |
| 503 openTab_: function(e) { |
| 504 var tab = e.model.tab; |
| 505 var browserService = md_history.BrowserService.getInstance(); |
| 506 browserService.recordHistogram( |
| 507 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.LINK_CLICKED, |
| 508 SyncedTabsHistogram.LIMIT); |
| 509 browserService.openForeignSessionTab( |
| 510 this.sessionTag, tab.windowId, tab.sessionId, e); |
| 511 e.preventDefault() |
| 512 }, |
| 513 toggleTabCard: function() { |
| 514 var histogramValue = this.$.collapse.opened ? |
| 515 SyncedTabsHistogram.COLLAPSE_SESSION : |
| 516 SyncedTabsHistogram.EXPAND_SESSION; |
| 517 md_history.BrowserService.getInstance().recordHistogram( |
| 518 SYNCED_TABS_HISTOGRAM_NAME, histogramValue, SyncedTabsHistogram.LIMIT); |
| 519 this.$.collapse.toggle(); |
| 520 this.$["dropdown-indicator"].icon = |
| 521 this.$.collapse.opened ? "cr:expand-less" : "cr:expand-more"; |
| 522 this.fire("update-focus-grid") |
| 523 }, |
| 524 notifyFocusUpdate_: function() { |
| 525 this.fire("update-focus-grid") |
| 526 }, |
| 527 updateIcons_: function() { |
| 528 this.async(function() { |
| 529 var icons = Polymer.dom(this.root).querySelectorAll(".website-icon"); |
| 530 for (var i = 0; i < this.tabs.length; i++) { |
| 531 icons[i].style.backgroundImage = cr.icon.getFavicon(this.tabs[i].url) |
| 532 } |
| 533 }) |
| 534 }, |
| 535 isWindowSeparatorIndex_: function(index, separatorIndexes) { |
| 536 return this.separatorIndexes.indexOf(index) != -1 |
| 537 }, |
| 538 getCollapseIcon_: function(opened) { |
| 539 return opened ? "cr:expand-less" : "cr:expand-more" |
| 540 }, |
| 541 getCollapseTitle_: function(opened) { |
| 542 return opened ? loadTimeData.getString("collapseSessionButton") : |
| 543 loadTimeData.getString("expandSessionButton") |
| 544 }, |
| 545 onMenuButtonTap_: function(e) { |
| 546 this.fire( |
| 547 "open-menu", |
| 548 {target: Polymer.dom(e).localTarget, tag: this.sessionTag}); |
| 549 e.stopPropagation() |
| 550 }, |
| 551 onLinkRightClick_: function() { |
| 552 md_history.BrowserService.getInstance().recordHistogram( |
| 553 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.LINK_RIGHT_CLICKED, |
| 554 SyncedTabsHistogram.LIMIT) |
| 555 } |
| 556 }); |
| 18 // Copyright 2016 The Chromium Authors. All rights reserved. | 557 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 19 // Use of this source code is governed by a BSD-style license that can be | 558 // Use of this source code is governed by a BSD-style license that can be |
| 20 // found in the LICENSE file. | 559 // found in the LICENSE file. |
| 21 var ForeignDeviceInternal;Polymer({is:"history-synced-device-manager",properties
:{sessionList:{type:Array,observer:"updateSyncedDevices"},searchTerm:{type:Strin
g,observer:"searchTermChanged"},syncedDevices_:{type:Array,value:function(){retu
rn[]}},signInState:{type:Boolean,observer:"signInStateChanged_"},guestSession_:{
type:Boolean,value:loadTimeData.getBoolean("isGuestSession")},fetchingSyncedTabs
_:{type:Boolean,value:false},hasSeenForeignData_:Boolean,actionMenuModel_:String
},listeners:{"open-menu":"onOpenMenu_","update-focus-grid":"updateFocusGrid_"},f
ocusGrid_:null,attached:function(){this.focusGrid_=new cr.ui.FocusGrid;chrome.se
nd("otherDevicesInitialized");md_history.BrowserService.getInstance().recordHist
ogram(SYNCED_TABS_HISTOGRAM_NAME,SyncedTabsHistogram.INITIALIZED,SyncedTabsHisto
gram.LIMIT)},detached:function(){this.focusGrid_.destroy()},getContentScrollTarg
et:function(){return this},createInternalDevice_:function(session){var tabs=[];v
ar separatorIndexes=[];for(var i=0;i<session.windows.length;i++){var windowId=se
ssion.windows[i].sessionId;var newTabs=session.windows[i].tabs;if(newTabs.length
==0)continue;newTabs.forEach(function(tab){tab.windowId=windowId});var windowAdd
ed=false;if(!this.searchTerm){tabs=tabs.concat(newTabs);windowAdded=true}else{va
r searchText=this.searchTerm.toLowerCase();for(var j=0;j<newTabs.length;j++){var
tab=newTabs[j];if(tab.title.toLowerCase().indexOf(searchText)!=-1){tabs.push(ta
b);windowAdded=true}}}if(windowAdded&&i!=session.windows.length-1)separatorIndex
es.push(tabs.length-1)}return{device:session.name,lastUpdateTime:"– "+session.mo
difiedTime,opened:true,separatorIndexes:separatorIndexes,timestamp:session.times
tamp,tabs:tabs,tag:session.tag}},onSignInTap_:function(){chrome.send("startSignI
nFlow")},onOpenMenu_:function(e){var menu=this.$.menu.get();this.actionMenuModel
_=e.detail.tag;menu.showAt(e.detail.target);md_history.BrowserService.getInstanc
e().recordHistogram(SYNCED_TABS_HISTOGRAM_NAME,SyncedTabsHistogram.SHOW_SESSION_
MENU,SyncedTabsHistogram.LIMIT)},onOpenAllTap_:function(){var menu=assert(this.$
.menu.getIfExists());var browserService=md_history.BrowserService.getInstance();
browserService.recordHistogram(SYNCED_TABS_HISTOGRAM_NAME,SyncedTabsHistogram.OP
EN_ALL,SyncedTabsHistogram.LIMIT);browserService.openForeignSessionAllTabs(asser
t(this.actionMenuModel_));this.actionMenuModel_=null;menu.close()},updateFocusGr
id_:function(){if(!this.focusGrid_)return;this.focusGrid_.destroy();this.debounc
e("updateFocusGrid",function(){Polymer.dom(this.root).querySelectorAll("history-
synced-device-card").reduce(function(prev,cur){return prev.concat(cur.createFocu
sRows())},[]).forEach(function(row){this.focusGrid_.addRow(row)}.bind(this));thi
s.focusGrid_.ensureRowActive()})},onDeleteSessionTap_:function(){var menu=assert
(this.$.menu.getIfExists());var browserService=md_history.BrowserService.getInst
ance();browserService.recordHistogram(SYNCED_TABS_HISTOGRAM_NAME,SyncedTabsHisto
gram.HIDE_FOR_NOW,SyncedTabsHistogram.LIMIT);browserService.deleteForeignSession
(assert(this.actionMenuModel_));this.actionMenuModel_=null;menu.close()},clearDi
splayedSyncedDevices_:function(){this.syncedDevices_=[]},showNoSyncedMessage:fun
ction(signInState,syncedDevicesLength,guestSession){if(guestSession)return true;
return signInState&&syncedDevicesLength==0},showSignInGuide:function(signInState
,guestSession){var show=!signInState&&!guestSession;if(show){md_history.BrowserS
ervice.getInstance().recordAction("Signin_Impression_FromRecentTabs")}return sho
w},noSyncedTabsMessage:function(){var stringName=this.fetchingSyncedTabs_?"loadi
ng":"noSyncedResults";if(this.searchTerm!=="")stringName="noSearchResults";retur
n loadTimeData.getString(stringName)},updateSyncedDevices:function(sessionList){
this.fetchingSyncedTabs_=false;if(!sessionList)return;if(sessionList.length>0&&!
this.hasSeenForeignData_){this.hasSeenForeignData_=true;md_history.BrowserServic
e.getInstance().recordHistogram(SYNCED_TABS_HISTOGRAM_NAME,SyncedTabsHistogram.H
AS_FOREIGN_DATA,SyncedTabsHistogram.LIMIT)}var devices=[];sessionList.forEach(fu
nction(session){var device=this.createInternalDevice_(session);if(device.tabs.le
ngth!=0)devices.push(device)}.bind(this));this.syncedDevices_=devices},signInSta
teChanged_:function(){this.fire("history-view-changed");if(!this.signInState){th
is.clearDisplayedSyncedDevices_();return}this.fetchingSyncedTabs_=true},searchTe
rmChanged:function(searchTerm){this.clearDisplayedSyncedDevices_();this.updateSy
ncedDevices(this.sessionList)}}); | 560 var ForeignDeviceInternal; |
| 561 Polymer({ |
| 562 is: "history-synced-device-manager", |
| 563 properties: { |
| 564 sessionList: {type: Array, observer: "updateSyncedDevices"}, |
| 565 searchTerm: {type: String, observer: "searchTermChanged"}, |
| 566 syncedDevices_: { |
| 567 type: Array, |
| 568 value: function() { |
| 569 return [] |
| 570 } |
| 571 }, |
| 572 signInState: {type: Boolean, observer: "signInStateChanged_"}, |
| 573 guestSession_: |
| 574 {type: Boolean, value: loadTimeData.getBoolean("isGuestSession")}, |
| 575 fetchingSyncedTabs_: {type: Boolean, value: false}, |
| 576 hasSeenForeignData_: Boolean, |
| 577 actionMenuModel_: String |
| 578 }, |
| 579 listeners: |
| 580 {"open-menu": "onOpenMenu_", "update-focus-grid": "updateFocusGrid_"}, |
| 581 focusGrid_: null, |
| 582 attached: function() { |
| 583 this.focusGrid_ = new cr.ui.FocusGrid; |
| 584 chrome.send("otherDevicesInitialized"); |
| 585 md_history.BrowserService.getInstance().recordHistogram( |
| 586 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.INITIALIZED, |
| 587 SyncedTabsHistogram.LIMIT) |
| 588 }, |
| 589 detached: function() { |
| 590 this.focusGrid_.destroy() |
| 591 }, |
| 592 getContentScrollTarget: function() { |
| 593 return this |
| 594 }, |
| 595 createInternalDevice_: function(session) { |
| 596 var tabs = []; |
| 597 var separatorIndexes = []; |
| 598 for (var i = 0; i < session.windows.length; i++) { |
| 599 var windowId = session.windows[i].sessionId; |
| 600 var newTabs = session.windows[i].tabs; |
| 601 if (newTabs.length == 0) |
| 602 continue; |
| 603 newTabs.forEach(function(tab) { |
| 604 tab.windowId = windowId |
| 605 }); |
| 606 var windowAdded = false; |
| 607 if (!this.searchTerm) { |
| 608 tabs = tabs.concat(newTabs); |
| 609 windowAdded = true |
| 610 } else { |
| 611 var searchText = this.searchTerm.toLowerCase(); |
| 612 for (var j = 0; j < newTabs.length; j++) { |
| 613 var tab = newTabs[j]; |
| 614 if (tab.title.toLowerCase().indexOf(searchText) != -1) { |
| 615 tabs.push(tab); |
| 616 windowAdded = true |
| 617 } |
| 618 } |
| 619 } |
| 620 if (windowAdded && i != session.windows.length - 1) |
| 621 separatorIndexes.push(tabs.length - 1) |
| 622 } |
| 623 return { |
| 624 device: session.name, lastUpdateTime: "– " + session.modifiedTime, |
| 625 opened: true, separatorIndexes: separatorIndexes, |
| 626 timestamp: session.timestamp, tabs: tabs, tag: session.tag |
| 627 } |
| 628 }, |
| 629 onSignInTap_: function() { |
| 630 chrome.send("startSignInFlow") |
| 631 }, |
| 632 onOpenMenu_: function(e) { |
| 633 var menu = this.$.menu.get(); |
| 634 this.actionMenuModel_ = e.detail.tag; |
| 635 menu.showAt(e.detail.target); |
| 636 md_history.BrowserService.getInstance().recordHistogram( |
| 637 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.SHOW_SESSION_MENU, |
| 638 SyncedTabsHistogram.LIMIT) |
| 639 }, |
| 640 onOpenAllTap_: function() { |
| 641 var menu = assert(this.$.menu.getIfExists()); |
| 642 var browserService = md_history.BrowserService.getInstance(); |
| 643 browserService.recordHistogram( |
| 644 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.OPEN_ALL, |
| 645 SyncedTabsHistogram.LIMIT); |
| 646 browserService.openForeignSessionAllTabs(assert(this.actionMenuModel_)); |
| 647 this.actionMenuModel_ = null; |
| 648 menu.close() |
| 649 }, |
| 650 updateFocusGrid_: function() { |
| 651 if (!this.focusGrid_) |
| 652 return; |
| 653 this.focusGrid_.destroy(); |
| 654 this.debounce("updateFocusGrid", function() { |
| 655 Polymer.dom(this.root) |
| 656 .querySelectorAll("history-synced-device-card") |
| 657 .reduce( |
| 658 function(prev, cur) { |
| 659 return prev.concat(cur.createFocusRows()) |
| 660 }, |
| 661 []) |
| 662 .forEach(function(row) { |
| 663 this.focusGrid_.addRow(row) |
| 664 }.bind(this)); |
| 665 this.focusGrid_.ensureRowActive() |
| 666 }) |
| 667 }, |
| 668 onDeleteSessionTap_: function() { |
| 669 var menu = assert(this.$.menu.getIfExists()); |
| 670 var browserService = md_history.BrowserService.getInstance(); |
| 671 browserService.recordHistogram( |
| 672 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.HIDE_FOR_NOW, |
| 673 SyncedTabsHistogram.LIMIT); |
| 674 browserService.deleteForeignSession(assert(this.actionMenuModel_)); |
| 675 this.actionMenuModel_ = null; |
| 676 menu.close() |
| 677 }, |
| 678 clearDisplayedSyncedDevices_: function() { |
| 679 this.syncedDevices_ = [] |
| 680 }, |
| 681 showNoSyncedMessage: function( |
| 682 signInState, syncedDevicesLength, guestSession) { |
| 683 if (guestSession) |
| 684 return true; |
| 685 return signInState && syncedDevicesLength == 0 |
| 686 }, |
| 687 showSignInGuide: function(signInState, guestSession) { |
| 688 var show = !signInState && !guestSession; |
| 689 if (show) { |
| 690 md_history.BrowserService.getInstance().recordAction( |
| 691 "Signin_Impression_FromRecentTabs") |
| 692 } |
| 693 return show |
| 694 }, |
| 695 noSyncedTabsMessage: function() { |
| 696 var stringName = this.fetchingSyncedTabs_ ? "loading" : "noSyncedResults"; |
| 697 if (this.searchTerm !== "") |
| 698 stringName = "noSearchResults"; |
| 699 return loadTimeData.getString(stringName) |
| 700 }, |
| 701 updateSyncedDevices: function(sessionList) { |
| 702 this.fetchingSyncedTabs_ = false; |
| 703 if (!sessionList) |
| 704 return; |
| 705 if (sessionList.length > 0 && !this.hasSeenForeignData_) { |
| 706 this.hasSeenForeignData_ = true; |
| 707 md_history.BrowserService.getInstance().recordHistogram( |
| 708 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.HAS_FOREIGN_DATA, |
| 709 SyncedTabsHistogram.LIMIT) |
| 710 } |
| 711 var devices = []; |
| 712 sessionList.forEach(function(session) { |
| 713 var device = this.createInternalDevice_(session); |
| 714 if (device.tabs.length != 0) |
| 715 devices.push(device) |
| 716 }.bind(this)); |
| 717 this.syncedDevices_ = devices |
| 718 }, |
| 719 signInStateChanged_: function() { |
| 720 this.fire("history-view-changed"); |
| 721 if (!this.signInState) { |
| 722 this.clearDisplayedSyncedDevices_(); |
| 723 return |
| 724 } |
| 725 this.fetchingSyncedTabs_ = true |
| 726 }, |
| 727 searchTermChanged: function(searchTerm) { |
| 728 this.clearDisplayedSyncedDevices_(); |
| 729 this.updateSyncedDevices(this.sessionList) |
| 730 } |
| 731 }); |
| 22 // Copyright 2016 The Chromium Authors. All rights reserved. | 732 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 23 // Use of this source code is governed by a BSD-style license that can be | 733 // Use of this source code is governed by a BSD-style license that can be |
| 24 // found in the LICENSE file. | 734 // found in the LICENSE file. |
| 25 Polymer({is:"cr-dialog","extends":"dialog",properties:{closeText:String,ignorePo
pstate:{type:Boolean,value:false}},ready:function(){window.addEventListener("pop
state",function(){if(!this.ignorePopstate&&this.open)this.cancel()}.bind(this))}
,cancel:function(){this.fire("cancel");HTMLDialogElement.prototype.close.call(th
is,"")},close:function(opt_returnValue){HTMLDialogElement.prototype.close.call(t
his,"success")},getCloseButton:function(){return this.$.close}});Polymer({is:"ap
p-drawer",properties:{opened:{type:Boolean,value:false,notify:true,reflectToAttr
ibute:true},persistent:{type:Boolean,value:false,reflectToAttribute:true},align:
{type:String,value:"left"},position:{type:String,readOnly:true,value:"left",refl
ectToAttribute:true},swipeOpen:{type:Boolean,value:false,reflectToAttribute:true
},noFocusTrap:{type:Boolean,value:false}},observers:["resetLayout(position)","_r
esetPosition(align, isAttached)"],_translateOffset:0,_trackDetails:null,_drawerS
tate:0,_boundEscKeydownHandler:null,_firstTabStop:null,_lastTabStop:null,ready:f
unction(){this.setScrollDirection("y");this._setTransitionDuration("0s")},attach
ed:function(){Polymer.RenderStatus.afterNextRender(this,function(){this._setTran
sitionDuration("");this._boundEscKeydownHandler=this._escKeydownHandler.bind(thi
s);this._resetDrawerState();this.listen(this,"track","_track");this.addEventList
ener("transitionend",this._transitionend.bind(this));this.addEventListener("keyd
own",this._tabKeydownHandler.bind(this))})},detached:function(){document.removeE
ventListener("keydown",this._boundEscKeydownHandler)},open:function(){this.opene
d=true},close:function(){this.opened=false},toggle:function(){this.opened=!this.
opened},getWidth:function(){return this.$.contentContainer.offsetWidth},resetLay
out:function(){this.debounce("_resetLayout",function(){this.fire("app-drawer-res
et-layout")},1)},_isRTL:function(){return window.getComputedStyle(this).directio
n==="rtl"},_resetPosition:function(){switch(this.align){case"start":this._setPos
ition(this._isRTL()?"right":"left");return;case"end":this._setPosition(this._isR
TL()?"left":"right");return}this._setPosition(this.align)},_escKeydownHandler:fu
nction(event){var ESC_KEYCODE=27;if(event.keyCode===ESC_KEYCODE){event.preventDe
fault();this.close()}},_track:function(event){if(this.persistent){return}event.p
reventDefault();switch(event.detail.state){case"start":this._trackStart(event);b
reak;case"track":this._trackMove(event);break;case"end":this._trackEnd(event);br
eak}},_trackStart:function(event){this._drawerState=this._DRAWER_STATE.TRACKING;
this._setTransitionDuration("0s");this.style.visibility="visible";var rect=this.
$.contentContainer.getBoundingClientRect();if(this.position==="left"){this._tran
slateOffset=rect.left}else{this._translateOffset=rect.right-window.innerWidth}th
is._trackDetails=[]},_trackMove:function(event){this._translateDrawer(event.deta
il.dx+this._translateOffset);this._trackDetails.push({dx:event.detail.dx,timeSta
mp:Date.now()})},_trackEnd:function(event){var x=event.detail.dx+this._translate
Offset;var drawerWidth=this.getWidth();var isPositionLeft=this.position==="left"
;var isInEndState=isPositionLeft?x>=0||x<=-drawerWidth:x<=0||x>=drawerWidth;if(!
isInEndState){var trackDetails=this._trackDetails;this._trackDetails=null;this._
flingDrawer(event,trackDetails);if(this._drawerState===this._DRAWER_STATE.FLINGI
NG){return}}var halfWidth=drawerWidth/2;if(event.detail.dx<-halfWidth){this.open
ed=this.position==="right"}else if(event.detail.dx>halfWidth){this.opened=this.p
osition==="left"}if(isInEndState){this._resetDrawerState()}this._setTransitionDu
ration("");this._resetDrawerTranslate();this.style.visibility=""},_calculateVelo
city:function(event,trackDetails){var now=Date.now();var timeLowerBound=now-100;
var trackDetail;var min=0;var max=trackDetails.length-1;while(min<=max){var mid=
min+max>>1;var d=trackDetails[mid];if(d.timeStamp>=timeLowerBound){trackDetail=d
;max=mid-1}else{min=mid+1}}if(trackDetail){var dx=event.detail.dx-trackDetail.dx
;var dt=now-trackDetail.timeStamp||1;return dx/dt}return 0},_flingDrawer:functio
n(event,trackDetails){var velocity=this._calculateVelocity(event,trackDetails);i
f(Math.abs(velocity)<this._MIN_FLING_THRESHOLD){return}this._drawerState=this._D
RAWER_STATE.FLINGING;var x=event.detail.dx+this._translateOffset;var drawerWidth
=this.getWidth();var isPositionLeft=this.position==="left";var isVelocityPositiv
e=velocity>0;var isClosingLeft=!isVelocityPositive&&isPositionLeft;var isClosing
Right=isVelocityPositive&&!isPositionLeft;var dx;if(isClosingLeft){dx=-(x+drawer
Width)}else if(isClosingRight){dx=drawerWidth-x}else{dx=-x}if(isVelocityPositive
){velocity=Math.max(velocity,this._MIN_TRANSITION_VELOCITY);this.opened=this.pos
ition==="left"}else{velocity=Math.min(velocity,-this._MIN_TRANSITION_VELOCITY);t
his.opened=this.position==="right"}this._setTransitionDuration(this._FLING_INITI
AL_SLOPE*dx/velocity+"ms");this._setTransitionTimingFunction(this._FLING_TIMING_
FUNCTION);this._resetDrawerTranslate()},_transitionend:function(event){var targe
t=Polymer.dom(event).rootTarget;if(target===this.$.contentContainer||target===th
is.$.scrim){if(this._drawerState===this._DRAWER_STATE.FLINGING){this._setTransit
ionDuration("");this._setTransitionTimingFunction("");this.style.visibility=""}t
his._resetDrawerState()}},_setTransitionDuration:function(duration){this.$.conte
ntContainer.style.transitionDuration=duration;this.$.scrim.style.transitionDurat
ion=duration},_setTransitionTimingFunction:function(timingFunction){this.$.conte
ntContainer.style.transitionTimingFunction=timingFunction;this.$.scrim.style.tra
nsitionTimingFunction=timingFunction},_translateDrawer:function(x){var drawerWid
th=this.getWidth();if(this.position==="left"){x=Math.max(-drawerWidth,Math.min(x
,0));this.$.scrim.style.opacity=1+x/drawerWidth}else{x=Math.max(0,Math.min(x,dra
werWidth));this.$.scrim.style.opacity=1-x/drawerWidth}this.translate3d(x+"px","0
","0",this.$.contentContainer)},_resetDrawerTranslate:function(){this.$.scrim.st
yle.opacity="";this.transform("",this.$.contentContainer)},_resetDrawerState:fun
ction(){var oldState=this._drawerState;if(this.opened){this._drawerState=this.pe
rsistent?this._DRAWER_STATE.OPENED_PERSISTENT:this._DRAWER_STATE.OPENED}else{thi
s._drawerState=this._DRAWER_STATE.CLOSED}if(oldState!==this._drawerState){if(thi
s._drawerState===this._DRAWER_STATE.OPENED){this._setKeyboardFocusTrap();documen
t.addEventListener("keydown",this._boundEscKeydownHandler);document.body.style.o
verflow="hidden"}else{document.removeEventListener("keydown",this._boundEscKeydo
wnHandler);document.body.style.overflow=""}if(oldState!==this._DRAWER_STATE.INIT
){this.fire("app-drawer-transitioned")}}},_setKeyboardFocusTrap:function(){if(th
is.noFocusTrap){return}var focusableElementsSelector=['a[href]:not([tabindex="-1
"])','area[href]:not([tabindex="-1"])','input:not([disabled]):not([tabindex="-1"
])','select:not([disabled]):not([tabindex="-1"])','textarea:not([disabled]):not(
[tabindex="-1"])','button:not([disabled]):not([tabindex="-1"])','iframe:not([tab
index="-1"])','[tabindex]:not([tabindex="-1"])','[contentEditable=true]:not([tab
index="-1"])'].join(",");var focusableElements=Polymer.dom(this).querySelectorAl
l(focusableElementsSelector);if(focusableElements.length>0){this._firstTabStop=f
ocusableElements[0];this._lastTabStop=focusableElements[focusableElements.length
-1]}else{this._firstTabStop=null;this._lastTabStop=null}var tabindex=this.getAtt
ribute("tabindex");if(tabindex&&parseInt(tabindex,10)>-1){this.focus()}else if(t
his._firstTabStop){this._firstTabStop.focus()}},_tabKeydownHandler:function(even
t){if(this.noFocusTrap){return}var TAB_KEYCODE=9;if(this._drawerState===this._DR
AWER_STATE.OPENED&&event.keyCode===TAB_KEYCODE){if(event.shiftKey){if(this._firs
tTabStop&&Polymer.dom(event).localTarget===this._firstTabStop){event.preventDefa
ult();this._lastTabStop.focus()}}else{if(this._lastTabStop&&Polymer.dom(event).l
ocalTarget===this._lastTabStop){event.preventDefault();this._firstTabStop.focus(
)}}}},_MIN_FLING_THRESHOLD:.2,_MIN_TRANSITION_VELOCITY:1.2,_FLING_TIMING_FUNCTIO
N:"cubic-bezier(0.667, 1, 0.667, 1)",_FLING_INITIAL_SLOPE:1.5,_DRAWER_STATE:{INI
T:0,OPENED:1,OPENED_PERSISTENT:2,CLOSED:3,TRACKING:4,FLINGING:5}});Polymer.IronF
itBehavior={properties:{sizingTarget:{type:Object,value:function(){return this}}
,fitInto:{type:Object,value:window},noOverlap:{type:Boolean},positionTarget:{typ
e:Element},horizontalAlign:{type:String},verticalAlign:{type:String},dynamicAlig
n:{type:Boolean},horizontalOffset:{type:Number,value:0,notify:true},verticalOffs
et:{type:Number,value:0,notify:true},autoFitOnAttach:{type:Boolean,value:false},
_fitInfo:{type:Object}},get _fitWidth(){var fitWidth;if(this.fitInto===window){f
itWidth=this.fitInto.innerWidth}else{fitWidth=this.fitInto.getBoundingClientRect
().width}return fitWidth},get _fitHeight(){var fitHeight;if(this.fitInto===windo
w){fitHeight=this.fitInto.innerHeight}else{fitHeight=this.fitInto.getBoundingCli
entRect().height}return fitHeight},get _fitLeft(){var fitLeft;if(this.fitInto===
window){fitLeft=0}else{fitLeft=this.fitInto.getBoundingClientRect().left}return
fitLeft},get _fitTop(){var fitTop;if(this.fitInto===window){fitTop=0}else{fitTop
=this.fitInto.getBoundingClientRect().top}return fitTop},get _defaultPositionTar
get(){var parent=Polymer.dom(this).parentNode;if(parent&&parent.nodeType===Node.
DOCUMENT_FRAGMENT_NODE){parent=parent.host}return parent},get _localeHorizontalA
lign(){if(this._isRTL){if(this.horizontalAlign==="right"){return"left"}if(this.h
orizontalAlign==="left"){return"right"}}return this.horizontalAlign},attached:fu
nction(){this._isRTL=window.getComputedStyle(this).direction=="rtl";this.positio
nTarget=this.positionTarget||this._defaultPositionTarget;if(this.autoFitOnAttach
){if(window.getComputedStyle(this).display==="none"){setTimeout(function(){this.
fit()}.bind(this))}else{this.fit()}}},fit:function(){this.position();this.constr
ain();this.center()},_discoverInfo:function(){if(this._fitInfo){return}var targe
t=window.getComputedStyle(this);var sizer=window.getComputedStyle(this.sizingTar
get);this._fitInfo={inlineStyle:{top:this.style.top||"",left:this.style.left||""
,position:this.style.position||""},sizerInlineStyle:{maxWidth:this.sizingTarget.
style.maxWidth||"",maxHeight:this.sizingTarget.style.maxHeight||"",boxSizing:thi
s.sizingTarget.style.boxSizing||""},positionedBy:{vertically:target.top!=="auto"
?"top":target.bottom!=="auto"?"bottom":null,horizontally:target.left!=="auto"?"l
eft":target.right!=="auto"?"right":null},sizedBy:{height:sizer.maxHeight!=="none
",width:sizer.maxWidth!=="none",minWidth:parseInt(sizer.minWidth,10)||0,minHeigh
t:parseInt(sizer.minHeight,10)||0},margin:{top:parseInt(target.marginTop,10)||0,
right:parseInt(target.marginRight,10)||0,bottom:parseInt(target.marginBottom,10)
||0,left:parseInt(target.marginLeft,10)||0}};if(this.verticalOffset){this._fitIn
fo.margin.top=this._fitInfo.margin.bottom=this.verticalOffset;this._fitInfo.inli
neStyle.marginTop=this.style.marginTop||"";this._fitInfo.inlineStyle.marginBotto
m=this.style.marginBottom||"";this.style.marginTop=this.style.marginBottom=this.
verticalOffset+"px"}if(this.horizontalOffset){this._fitInfo.margin.left=this._fi
tInfo.margin.right=this.horizontalOffset;this._fitInfo.inlineStyle.marginLeft=th
is.style.marginLeft||"";this._fitInfo.inlineStyle.marginRight=this.style.marginR
ight||"";this.style.marginLeft=this.style.marginRight=this.horizontalOffset+"px"
}},resetFit:function(){var info=this._fitInfo||{};for(var property in info.sizer
InlineStyle){this.sizingTarget.style[property]=info.sizerInlineStyle[property]}f
or(var property in info.inlineStyle){this.style[property]=info.inlineStyle[prope
rty]}this._fitInfo=null},refit:function(){var scrollLeft=this.sizingTarget.scrol
lLeft;var scrollTop=this.sizingTarget.scrollTop;this.resetFit();this.fit();this.
sizingTarget.scrollLeft=scrollLeft;this.sizingTarget.scrollTop=scrollTop},positi
on:function(){if(!this.horizontalAlign&&!this.verticalAlign){return}this._discov
erInfo();this.style.position="fixed";this.sizingTarget.style.boxSizing="border-b
ox";this.style.left="0px";this.style.top="0px";var rect=this.getBoundingClientRe
ct();var positionRect=this.__getNormalizedRect(this.positionTarget);var fitRect=
this.__getNormalizedRect(this.fitInto);var margin=this._fitInfo.margin;var size=
{width:rect.width+margin.left+margin.right,height:rect.height+margin.top+margin.
bottom};var position=this.__getPosition(this._localeHorizontalAlign,this.vertica
lAlign,size,positionRect,fitRect);var left=position.left+margin.left;var top=pos
ition.top+margin.top;var right=Math.min(fitRect.right-margin.right,left+rect.wid
th);var bottom=Math.min(fitRect.bottom-margin.bottom,top+rect.height);var minWid
th=this._fitInfo.sizedBy.minWidth;var minHeight=this._fitInfo.sizedBy.minHeight;
if(left<margin.left){left=margin.left;if(right-left<minWidth){left=right-minWidt
h}}if(top<margin.top){top=margin.top;if(bottom-top<minHeight){top=bottom-minHeig
ht}}this.sizingTarget.style.maxWidth=right-left+"px";this.sizingTarget.style.max
Height=bottom-top+"px";this.style.left=left-rect.left+"px";this.style.top=top-re
ct.top+"px"},constrain:function(){if(this.horizontalAlign||this.verticalAlign){r
eturn}this._discoverInfo();var info=this._fitInfo;if(!info.positionedBy.vertical
ly){this.style.position="fixed";this.style.top="0px"}if(!info.positionedBy.horiz
ontally){this.style.position="fixed";this.style.left="0px"}this.sizingTarget.sty
le.boxSizing="border-box";var rect=this.getBoundingClientRect();if(!info.sizedBy
.height){this.__sizeDimension(rect,info.positionedBy.vertically,"top","bottom","
Height")}if(!info.sizedBy.width){this.__sizeDimension(rect,info.positionedBy.hor
izontally,"left","right","Width")}},_sizeDimension:function(rect,positionedBy,st
art,end,extent){this.__sizeDimension(rect,positionedBy,start,end,extent)},__size
Dimension:function(rect,positionedBy,start,end,extent){var info=this._fitInfo;va
r fitRect=this.__getNormalizedRect(this.fitInto);var max=extent==="Width"?fitRec
t.width:fitRect.height;var flip=positionedBy===end;var offset=flip?max-rect[end]
:rect[start];var margin=info.margin[flip?start:end];var offsetExtent="offset"+ex
tent;var sizingOffset=this[offsetExtent]-this.sizingTarget[offsetExtent];this.si
zingTarget.style["max"+extent]=max-margin-offset-sizingOffset+"px"},center:funct
ion(){if(this.horizontalAlign||this.verticalAlign){return}this._discoverInfo();v
ar positionedBy=this._fitInfo.positionedBy;if(positionedBy.vertically&&positione
dBy.horizontally){return}this.style.position="fixed";if(!positionedBy.vertically
){this.style.top="0px"}if(!positionedBy.horizontally){this.style.left="0px"}var
rect=this.getBoundingClientRect();var fitRect=this.__getNormalizedRect(this.fitI
nto);if(!positionedBy.vertically){var top=fitRect.top-rect.top+(fitRect.height-r
ect.height)/2;this.style.top=top+"px"}if(!positionedBy.horizontally){var left=fi
tRect.left-rect.left+(fitRect.width-rect.width)/2;this.style.left=left+"px"}},__
getNormalizedRect:function(target){if(target===document.documentElement||target=
==window){return{top:0,left:0,width:window.innerWidth,height:window.innerHeight,
right:window.innerWidth,bottom:window.innerHeight}}return target.getBoundingClie
ntRect()},__getCroppedArea:function(position,size,fitRect){var verticalCrop=Math
.min(0,position.top)+Math.min(0,fitRect.bottom-(position.top+size.height));var h
orizontalCrop=Math.min(0,position.left)+Math.min(0,fitRect.right-(position.left+
size.width));return Math.abs(verticalCrop)*size.width+Math.abs(horizontalCrop)*s
ize.height},__getPosition:function(hAlign,vAlign,size,positionRect,fitRect){var
positions=[{verticalAlign:"top",horizontalAlign:"left",top:positionRect.top,left
:positionRect.left},{verticalAlign:"top",horizontalAlign:"right",top:positionRec
t.top,left:positionRect.right-size.width},{verticalAlign:"bottom",horizontalAlig
n:"left",top:positionRect.bottom-size.height,left:positionRect.left},{verticalAl
ign:"bottom",horizontalAlign:"right",top:positionRect.bottom-size.height,left:po
sitionRect.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]}po
sitions.push(copy)}positions[0].top=positions[1].top+=positionRect.height;positi
ons[2].top=positions[3].top-=positionRect.height;positions[4].left=positions[6].
left+=positionRect.width;positions[5].left=positions[7].left-=positionRect.width
}vAlign=vAlign==="auto"?null:vAlign;hAlign=hAlign==="auto"?null:hAlign;var posit
ion;for(var i=0;i<positions.length;i++){var pos=positions[i];if(!this.dynamicAli
gn&&!this.noOverlap&&pos.verticalAlign===vAlign&&pos.horizontalAlign===hAlign){p
osition=pos;break}var alignOk=(!vAlign||pos.verticalAlign===vAlign)&&(!hAlign||p
os.horizontalAlign===hAlign);if(!this.dynamicAlign&&!alignOk){continue}position=
position||pos;pos.croppedArea=this.__getCroppedArea(pos,size,fitRect);var diff=p
os.croppedArea-position.croppedArea;if(diff<0||diff===0&&alignOk){position=pos}i
f(position.croppedArea===0&&alignOk){break}}return position}};(function(){"use s
trict";Polymer({is:"iron-overlay-backdrop",properties:{opened:{reflectToAttribut
e:true,type:Boolean,value:false,observer:"_openedChanged"}},listeners:{transitio
nend:"_onTransitionend"},created:function(){this.__openedRaf=null},attached:func
tion(){this.opened&&this._openedChanged(this.opened)},prepare:function(){if(this
.opened&&!this.parentNode){Polymer.dom(document.body).appendChild(this)}},open:f
unction(){this.opened=true},close:function(){this.opened=false},complete:functio
n(){if(!this.opened&&this.parentNode===document.body){Polymer.dom(this.parentNod
e).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.complete()}}if(!this.isAttached){return}if(this.__openedRaf){w
indow.cancelAnimationFrame(this.__openedRaf);this.__openedRaf=null}this.scrollTo
p=this.scrollTop;this.__openedRaf=window.requestAnimationFrame(function(){this._
_openedRaf=null;this.toggleClass("opened",this.opened)}.bind(this))}})})();Polym
er.IronOverlayManagerClass=function(){this._overlays=[];this._minimumZ=101;this.
_backdropElement=null;Polymer.Gestures.add(document,"tap",this._onCaptureClick.b
ind(this));document.addEventListener("focus",this._onCaptureFocus.bind(this),tru
e);document.addEventListener("keydown",this._onCaptureKeyDown.bind(this),true)};
Polymer.IronOverlayManagerClass.prototype={constructor:Polymer.IronOverlayManage
rClass,get backdropElement(){if(!this._backdropElement){this._backdropElement=do
cument.createElement("iron-overlay-backdrop")}return this._backdropElement},get
deepActiveElement(){var active=document.activeElement||document.body;while(activ
e.root&&Polymer.dom(active.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 cur
rentOverlay=this._overlays[lastI];if(currentOverlay&&this._shouldBeBehindOverlay
(overlay,currentOverlay)){lastI--}if(i>=lastI){return}var minimumZ=Math.max(this
.currentOverlayZ(),this._minimumZ);if(this._getZ(overlay)<=minimumZ){this._apply
OverlayZ(overlay,minimumZ)}while(i<lastI){this._overlays[i]=this._overlays[i+1];
i++}this._overlays[lastI]=overlay},addOrRemoveOverlay:function(overlay){if(overl
ay.opened){this.addOverlay(overlay)}else{this.removeOverlay(overlay)}},addOverla
y:function(overlay){var i=this._overlays.indexOf(overlay);if(i>=0){this._bringOv
erlayAtIndexToFront(i);this.trackBackdrop();return}var insertionIndex=this._over
lays.length;var currentOverlay=this._overlays[insertionIndex-1];var minimumZ=Mat
h.max(this._getZ(currentOverlay),this._minimumZ);var newZ=this._getZ(overlay);if
(currentOverlay&&this._shouldBeBehindOverlay(overlay,currentOverlay)){this._appl
yOverlayZ(currentOverlay,minimumZ);insertionIndex--;var previousOverlay=this._ov
erlays[insertionIndex-1];minimumZ=Math.max(this._getZ(previousOverlay),this._min
imumZ)}if(newZ<=minimumZ){this._applyOverlayZ(overlay,minimumZ)}this._overlays.s
plice(insertionIndex,0,overlay);this.trackBackdrop()},removeOverlay:function(ove
rlay){var i=this._overlays.indexOf(overlay);if(i===-1){return}this._overlays.spl
ice(i,1);this.trackBackdrop()},currentOverlay:function(){var i=this._overlays.le
ngth-1;return this._overlays[i]},currentOverlayZ:function(){return this._getZ(th
is.currentOverlay())},ensureMinimumZ:function(minimumZ){this._minimumZ=Math.max(
this._minimumZ,minimumZ)},focusOverlay:function(){var current=this.currentOverla
y();if(current){current._applyFocus()}},trackBackdrop:function(){var overlay=thi
s._overlayWithBackdrop();if(!overlay&&!this._backdropElement){return}this.backdr
opElement.style.zIndex=this._getZ(overlay)-1;this.backdropElement.opened=!!overl
ay},getBackdrops:function(){var backdrops=[];for(var i=0;i<this._overlays.length
;i++){if(this._overlays[i].withBackdrop){backdrops.push(this._overlays[i])}}retu
rn backdrops},backdropZ:function(){return this._getZ(this._overlayWithBackdrop()
)-1},_overlayWithBackdrop:function(){for(var i=0;i<this._overlays.length;i++){if
(this._overlays[i].withBackdrop){return this._overlays[i]}}},_getZ:function(over
lay){var z=this._minimumZ;if(overlay){var z1=Number(overlay.style.zIndex||window
.getComputedStyle(overlay).zIndex);if(z1===z1){z=z1}}return z},_setZ:function(el
ement,z){element.style.zIndex=z},_applyOverlayZ:function(overlay,aboveZ){this._s
etZ(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 overlay=this.currentOverlay();if(overlay&&this._overlayInPat
h(Polymer.dom(event).path)!==overlay){overlay._onCaptureClick(event)}},_onCaptur
eFocus:function(event){var overlay=this.currentOverlay();if(overlay){overlay._on
CaptureFocus(event)}},_onCaptureKeyDown:function(event){var overlay=this.current
Overlay();if(overlay){if(Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(e
vent,"esc")){overlay._onCaptureEsc(event)}else if(Polymer.IronA11yKeysBehavior.k
eyboardEventMatchesKeys(event,"tab")){overlay._onCaptureTab(event)}}},_shouldBeB
ehindOverlay:function(overlay1,overlay2){return!overlay1.alwaysOnTop&&overlay2.a
lwaysOnTop}};Polymer.IronOverlayManager=new Polymer.IronOverlayManagerClass;(fun
ction(){"use strict";Polymer.IronOverlayBehaviorImpl={properties:{opened:{observ
er:"_openedChanged",type:Boolean,value:false,notify:true},canceled:{observer:"_c
anceledChanged",readOnly:true,type:Boolean,value:false},withBackdrop:{observer:"
_withBackdropChanged",type:Boolean},noAutoFocus:{type:Boolean,value:false},noCan
celOnEscKey:{type:Boolean,value:false},noCancelOnOutsideClick:{type:Boolean,valu
e:false},closingReason:{type:Object},restoreFocusOnClose:{type:Boolean,value:fal
se},alwaysOnTop:{type:Boolean},_manager:{type:Object,value:Polymer.IronOverlayMa
nager},_focusedChild:{type:Object}},listeners:{"iron-resize":"_onIronResize"},ge
t backdropElement(){return this._manager.backdropElement},get _focusNode(){retur
n this._focusedChild||Polymer.dom(this).querySelector("[autofocus]")||this},get
_focusableNodes(){var FOCUSABLE_WITH_DISABLED=["a[href]","area[href]","iframe","
[tabindex]","[contentEditable=true]"];var FOCUSABLE_WITHOUT_DISABLED=["input","s
elect","textarea","button"];var selector=FOCUSABLE_WITH_DISABLED.join(':not([tab
index="-1"]),')+':not([tabindex="-1"]),'+FOCUSABLE_WITHOUT_DISABLED.join(':not([
disabled]):not([tabindex="-1"]),')+':not([disabled]):not([tabindex="-1"])';var f
ocusables=Polymer.dom(this).querySelectorAll(selector);if(this.tabIndex>=0){focu
sables.splice(0,0,this)}return focusables.sort(function(a,b){if(a.tabIndex===b.t
abIndex){return 0}if(a.tabIndex===0||a.tabIndex>b.tabIndex){return 1}return-1})}
,ready:function(){this.__isAnimating=false;this.__shouldRemoveTabIndex=false;thi
s.__firstFocusableNode=this.__lastFocusableNode=null;this.__raf=null;this.__rest
oreFocusNode=null;this._ensureSetup()},attached:function(){if(this.opened){this.
_openedChanged(this.opened)}this._observer=Polymer.dom(this).observeNodes(this._
onNodesChange)},detached:function(){Polymer.dom(this).unobserveNodes(this._obser
ver);this._observer=null;if(this.__raf){window.cancelAnimationFrame(this.__raf);
this.__raf=null}this._manager.removeOverlay(this)},toggle:function(){this._setCa
nceled(false);this.opened=!this.opened},open:function(){this._setCanceled(false)
;this.opened=true},close:function(){this._setCanceled(false);this.opened=false},
cancel:function(event){var cancelEvent=this.fire("iron-overlay-canceled",event,{
cancelable:true});if(cancelEvent.defaultPrevented){return}this._setCanceled(true
);this.opened=false},_ensureSetup:function(){if(this._overlaySetup){return}this.
_overlaySetup=true;this.style.outline="none";this.style.display="none"},_openedC
hanged:function(opened){if(opened){this.removeAttribute("aria-hidden")}else{this
.setAttribute("aria-hidden","true")}if(!this.isAttached){return}this.__isAnimati
ng=true;this.__onNextAnimationFrame(this.__openedChanged)},_canceledChanged:func
tion(){this.closingReason=this.closingReason||{};this.closingReason.canceled=thi
s.canceled},_withBackdropChanged:function(){if(this.withBackdrop&&!this.hasAttri
bute("tabindex")){this.setAttribute("tabindex","-1");this.__shouldRemoveTabIndex
=true}else if(this.__shouldRemoveTabIndex){this.removeAttribute("tabindex");this
.__shouldRemoveTabIndex=false}if(this.opened&&this.isAttached){this._manager.tra
ckBackdrop()}},_prepareRenderOpened:function(){this.__restoreFocusNode=this._man
ager.deepActiveElement;this._preparePositioning();this.refit();this._finishPosit
ioning();if(this.noAutoFocus&&document.activeElement===this._focusNode){this._fo
cusNode.blur();this.__restoreFocusNode.focus()}},_renderOpened:function(){this._
finishRenderOpened()},_renderClosed:function(){this._finishRenderClosed()},_fini
shRenderOpened:function(){this.notifyResize();this.__isAnimating=false;var focus
ableNodes=this._focusableNodes;this.__firstFocusableNode=focusableNodes[0];this.
__lastFocusableNode=focusableNodes[focusableNodes.length-1];this.fire("iron-over
lay-opened")},_finishRenderClosed:function(){this.style.display="none";this.styl
e.zIndex="";this.notifyResize();this.__isAnimating=false;this.fire("iron-overlay
-closed",this.closingReason)},_preparePositioning:function(){this.style.transiti
on=this.style.webkitTransition="none";this.style.transform=this.style.webkitTran
sform="none";this.style.display=""},_finishPositioning:function(){this.style.dis
play="none";this.scrollTop=this.scrollTop;this.style.transition=this.style.webki
tTransition="";this.style.transform=this.style.webkitTransform="";this.style.dis
play="";this.scrollTop=this.scrollTop},_applyFocus:function(){if(this.opened){if
(!this.noAutoFocus){this._focusNode.focus()}}else{this._focusNode.blur();this._f
ocusedChild=null;if(this.restoreFocusOnClose&&this.__restoreFocusNode){this.__re
storeFocusNode.focus()}this.__restoreFocusNode=null;var currentOverlay=this._man
ager.currentOverlay();if(currentOverlay&&this!==currentOverlay){currentOverlay._
applyFocus()}}},_onCaptureClick:function(event){if(!this.noCancelOnOutsideClick)
{this.cancel(event)}},_onCaptureFocus:function(event){if(!this.withBackdrop){ret
urn}var path=Polymer.dom(event).path;if(path.indexOf(this)===-1){event.stopPropa
gation();this._applyFocus()}else{this._focusedChild=path[0]}},_onCaptureEsc:func
tion(event){if(!this.noCancelOnEscKey){this.cancel(event)}},_onCaptureTab:functi
on(event){if(!this.withBackdrop){return}var shift=event.shiftKey;var nodeToCheck
=shift?this.__firstFocusableNode:this.__lastFocusableNode;var nodeToSet=shift?th
is.__lastFocusableNode:this.__firstFocusableNode;var shouldWrap=false;if(nodeToC
heck===nodeToSet){shouldWrap=true}else{var focusedNode=this._manager.deepActiveE
lement;shouldWrap=focusedNode===nodeToCheck||focusedNode===this}if(shouldWrap){e
vent.preventDefault();this._focusedChild=nodeToSet;this._applyFocus()}},_onIronR
esize:function(){if(this.opened&&!this.__isAnimating){this.__onNextAnimationFram
e(this.refit)}},_onNodesChange:function(){if(this.opened&&!this.__isAnimating){t
his.notifyResize()}},__openedChanged:function(){if(this.opened){this._prepareRen
derOpened();this._manager.addOverlay(this);this._applyFocus();this._renderOpened
()}else{this._manager.removeOverlay(this);this._applyFocus();this._renderClosed(
)}},__onNextAnimationFrame:function(callback){if(this.__raf){window.cancelAnimat
ionFrame(this.__raf)}var self=this;this.__raf=window.requestAnimationFrame(funct
ion nextAnimationFrame(){self.__raf=null;callback.call(self)})}};Polymer.IronOve
rlayBehavior=[Polymer.IronFitBehavior,Polymer.IronResizableBehavior,Polymer.Iron
OverlayBehaviorImpl]})();Polymer.NeonAnimatableBehavior={properties:{animationCo
nfig:{type:Object},entryAnimation:{observer:"_entryAnimationChanged",type:String
},exitAnimation:{observer:"_exitAnimationChanged",type:String}},_entryAnimationC
hanged:function(){this.animationConfig=this.animationConfig||{};this.animationCo
nfig["entry"]=[{name:this.entryAnimation,node:this}]},_exitAnimationChanged:func
tion(){this.animationConfig=this.animationConfig||{};this.animationConfig["exit"
]=[{name:this.exitAnimation,node:this}]},_copyProperties:function(config1,config
2){for(var property in config2){config1[property]=config2[property]}},_cloneConf
ig:function(config){var clone={isClone:true};this._copyProperties(clone,config);
return clone},_getAnimationConfigRecursive:function(type,map,allConfigs){if(!thi
s.animationConfig){return}if(this.animationConfig.value&&typeof this.animationCo
nfig.value==="function"){this._warn(this._logf("playAnimation","Please put 'anim
ationConfig' inside of your components 'properties' object instead of outside of
it."));return}var thisConfig;if(type){thisConfig=this.animationConfig[type]}els
e{thisConfig=this.animationConfig}if(!Array.isArray(thisConfig)){thisConfig=[thi
sConfig]}if(thisConfig){for(var config,index=0;config=thisConfig[index];index++)
{if(config.animatable){config.animatable._getAnimationConfigRecursive(config.typ
e||type,map,allConfigs)}else{if(config.id){var cachedConfig=map[config.id];if(ca
chedConfig){if(!cachedConfig.isClone){map[config.id]=this._cloneConfig(cachedCon
fig);cachedConfig=map[config.id]}this._copyProperties(cachedConfig,config)}else{
map[config.id]=config}}else{allConfigs.push(config)}}}}},getAnimationConfig:func
tion(type){var map={};var allConfigs=[];this._getAnimationConfigRecursive(type,m
ap,allConfigs);for(var key in map){allConfigs.push(map[key])}return allConfigs}}
;Polymer.NeonAnimationRunnerBehaviorImpl={_configureAnimations:function(configs)
{var results=[];if(configs.length>0){for(var config,index=0;config=configs[index
];index++){var neonAnimation=document.createElement(config.name);if(neonAnimatio
n.isNeonAnimation){var result=null;try{result=neonAnimation.configure(config);if
(typeof result.cancel!="function"){result=document.timeline.play(result)}}catch(
e){result=null;console.warn("Couldnt play","(",config.name,").",e)}if(result){re
sults.push({neonAnimation:neonAnimation,config:config,animation:result})}}else{c
onsole.warn(this.is+":",config.name,"not found!")}}}return results},_shouldCompl
ete:function(activeEntries){var finished=true;for(var i=0;i<activeEntries.length
;i++){if(activeEntries[i].animation.playState!="finished"){finished=false;break}
}return finished},_complete:function(activeEntries){for(var i=0;i<activeEntries.
length;i++){activeEntries[i].neonAnimation.complete(activeEntries[i].config)}for
(var i=0;i<activeEntries.length;i++){activeEntries[i].animation.cancel()}},playA
nimation:function(type,cookie){var configs=this.getAnimationConfig(type);if(!con
figs){return}this._active=this._active||{};if(this._active[type]){this._complete
(this._active[type]);delete this._active[type]}var activeEntries=this._configure
Animations(configs);if(activeEntries.length==0){this.fire("neon-animation-finish
",cookie,{bubbles:false});return}this._active[type]=activeEntries;for(var i=0;i<
activeEntries.length;i++){ | 735 Polymer({ |
| 26 activeEntries[i].animation.onfinish=function(){if(this._shouldComplete(activeEnt
ries)){this._complete(activeEntries);delete this._active[type];this.fire("neon-a
nimation-finish",cookie,{bubbles:false})}}.bind(this)}},cancelAnimation:function
(){for(var k in this._animations){this._animations[k].cancel()}this._animations=
{}}};Polymer.NeonAnimationRunnerBehavior=[Polymer.NeonAnimatableBehavior,Polymer
.NeonAnimationRunnerBehaviorImpl];Polymer.NeonAnimationBehavior={properties:{ani
mationTiming:{type:Object,value:function(){return{duration:500,easing:"cubic-bez
ier(0.4, 0, 0.2, 1)",fill:"both"}}}},isNeonAnimation:true,timingFromConfig:funct
ion(config){if(config.timing){for(var property in config.timing){this.animationT
iming[property]=config.timing[property]}}return this.animationTiming},setPrefixe
dProperty:function(node,property,value){var map={transform:["webkitTransform"],t
ransformOrigin:["mozTransformOrigin","webkitTransformOrigin"]};var prefixes=map[
property];for(var prefix,index=0;prefix=prefixes[index];index++){node.style[pref
ix]=value}node.style[property]=value},complete:function(){}};Polymer({is:"opaque
-animation",behaviors:[Polymer.NeonAnimationBehavior],configure:function(config)
{var node=config.node;this._effect=new KeyframeEffect(node,[{opacity:"1"},{opaci
ty:"1"}],this.timingFromConfig(config));node.style.opacity="0";return this._effe
ct},complete:function(config){config.node.style.opacity=""}});(function(){"use s
trict";var LAST_TOUCH_POSITION={pageX:0,pageY:0};var ROOT_TARGET=null;var SCROLL
ABLE_NODES=[];Polymer.IronDropdownScrollManager={get currentLockingElement(){ret
urn this._lockingElements[this._lockingElements.length-1]},elementIsScrollLocked
:function(element){var currentLockingElement=this.currentLockingElement;if(curre
ntLockingElement===undefined)return false;var scrollLocked;if(this._hasCachedLoc
kedElement(element)){return true}if(this._hasCachedUnlockedElement(element)){ret
urn false}scrollLocked=!!currentLockingElement&¤tLockingElement!==element&
&!this._composedTreeContains(currentLockingElement,element);if(scrollLocked){thi
s._lockedElementCache.push(element)}else{this._unlockedElementCache.push(element
)}return scrollLocked},pushScrollLock:function(element){if(this._lockingElements
.indexOf(element)>=0){return}if(this._lockingElements.length===0){this._lockScro
llInteractions()}this._lockingElements.push(element);this._lockedElementCache=[]
;this._unlockedElementCache=[]},removeScrollLock:function(element){var index=thi
s._lockingElements.indexOf(element);if(index===-1){return}this._lockingElements.
splice(index,1);this._lockedElementCache=[];this._unlockedElementCache=[];if(thi
s._lockingElements.length===0){this._unlockScrollInteractions()}},_lockingElemen
ts:[],_lockedElementCache:null,_unlockedElementCache:null,_hasCachedLockedElemen
t:function(element){return this._lockedElementCache.indexOf(element)>-1},_hasCac
hedUnlockedElement:function(element){return this._unlockedElementCache.indexOf(e
lement)>-1},_composedTreeContains:function(element,child){var contentElements;va
r distributedNodes;var contentIndex;var nodeIndex;if(element.contains(child)){re
turn true}contentElements=Polymer.dom(element).querySelectorAll("content");for(c
ontentIndex=0;contentIndex<contentElements.length;++contentIndex){distributedNod
es=Polymer.dom(contentElements[contentIndex]).getDistributedNodes();for(nodeInde
x=0;nodeIndex<distributedNodes.length;++nodeIndex){if(this._composedTreeContains
(distributedNodes[nodeIndex],child)){return true}}}return false},_scrollInteract
ionHandler:function(event){if(event.cancelable&&this._shouldPreventScrolling(eve
nt)){event.preventDefault()}if(event.targetTouches){var touch=event.targetTouche
s[0];LAST_TOUCH_POSITION.pageX=touch.pageX;LAST_TOUCH_POSITION.pageY=touch.pageY
}},_lockScrollInteractions:function(){this._boundScrollHandler=this._boundScroll
Handler||this._scrollInteractionHandler.bind(this);document.addEventListener("wh
eel",this._boundScrollHandler,true);document.addEventListener("mousewheel",this.
_boundScrollHandler,true);document.addEventListener("DOMMouseScroll",this._bound
ScrollHandler,true);document.addEventListener("touchstart",this._boundScrollHand
ler,true);document.addEventListener("touchmove",this._boundScrollHandler,true)},
_unlockScrollInteractions:function(){document.removeEventListener("wheel",this._
boundScrollHandler,true);document.removeEventListener("mousewheel",this._boundSc
rollHandler,true);document.removeEventListener("DOMMouseScroll",this._boundScrol
lHandler,true);document.removeEventListener("touchstart",this._boundScrollHandle
r,true);document.removeEventListener("touchmove",this._boundScrollHandler,true)}
,_shouldPreventScrolling:function(event){var target=Polymer.dom(event).rootTarge
t;if(event.type!=="touchmove"&&ROOT_TARGET!==target){ROOT_TARGET=target;SCROLLAB
LE_NODES=this._getScrollableNodes(Polymer.dom(event).path)}if(!SCROLLABLE_NODES.
length){return true}if(event.type==="touchstart"){return false}var info=this._ge
tScrollInfo(event);return!this._getScrollingNode(SCROLLABLE_NODES,info.deltaX,in
fo.deltaY)},_getScrollableNodes:function(nodes){var scrollables=[];var lockingIn
dex=nodes.indexOf(this.currentLockingElement);for(var i=0;i<=lockingIndex;i++){v
ar node=nodes[i];if(node.nodeType===11){continue}var style=node.style;if(style.o
verflow!=="scroll"&&style.overflow!=="auto"){style=window.getComputedStyle(node)
}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){c
anScroll=deltaY<0?node.scrollTop>0:node.scrollTop<node.scrollHeight-node.clientH
eight}else{canScroll=deltaX<0?node.scrollLeft>0:node.scrollLeft<node.scrollWidth
-node.clientWidth}if(canScroll){return node}}},_getScrollInfo:function(event){va
r info={deltaX:event.deltaX,deltaY:event.deltaY};if("deltaX"in event){}else if("
wheelDeltaX"in event){info.deltaX=-event.wheelDeltaX;info.deltaY=-event.wheelDel
taY}else if("axis"in event){info.deltaX=event.axis===1?event.detail:0;info.delta
Y=event.axis===2?event.detail:0}else if(event.targetTouches){var touch=event.tar
getTouches[0];info.deltaX=LAST_TOUCH_POSITION.pageX-touch.pageX;info.deltaY=LAST
_TOUCH_POSITION.pageY-touch.pageY}return info}}})();(function(){"use strict";Pol
ymer({is:"iron-dropdown",behaviors:[Polymer.IronControlState,Polymer.IronA11yKey
sBehavior,Polymer.IronOverlayBehavior,Polymer.NeonAnimationRunnerBehavior],prope
rties:{horizontalAlign:{type:String,value:"left",reflectToAttribute:true},vertic
alAlign:{type:String,value:"top",reflectToAttribute:true},openAnimationConfig:{t
ype:Object},closeAnimationConfig:{type:Object},focusTarget:{type:Object},noAnima
tions:{type:Boolean,value:false},allowOutsideScroll:{type:Boolean,value:false},_
boundOnCaptureScroll:{type:Function,value:function(){return this._onCaptureScrol
l.bind(this)}}},listeners:{"neon-animation-finish":"_onNeonAnimationFinish"},obs
ervers:["_updateOverlayPosition(positionTarget, verticalAlign, horizontalAlign,
verticalOffset, horizontalOffset)"],get containedElement(){return Polymer.dom(th
is.$.content).getDistributedNodes()[0]},get _focusTarget(){return this.focusTarg
et||this.containedElement},ready:function(){this._scrollTop=0;this._scrollLeft=0
;this._refitOnScrollRAF=null},attached:function(){if(!this.sizingTarget||this.si
zingTarget===this){this.sizingTarget=this.containedElement}},detached:function()
{this.cancelAnimation();document.removeEventListener("scroll",this._boundOnCaptu
reScroll);Polymer.IronDropdownScrollManager.removeScrollLock(this)},_openedChang
ed:function(){if(this.opened&&this.disabled){this.cancel()}else{this.cancelAnima
tion();this._updateAnimationConfig();this._saveScrollPosition();if(this.opened){
document.addEventListener("scroll",this._boundOnCaptureScroll);!this.allowOutsid
eScroll&&Polymer.IronDropdownScrollManager.pushScrollLock(this)}else{document.re
moveEventListener("scroll",this._boundOnCaptureScroll);Polymer.IronDropdownScrol
lManager.removeScrollLock(this)}Polymer.IronOverlayBehaviorImpl._openedChanged.a
pply(this,arguments)}},_renderOpened:function(){if(!this.noAnimations&&this.anim
ationConfig.open){this.$.contentWrapper.classList.add("animating");this.playAnim
ation("open")}else{Polymer.IronOverlayBehaviorImpl._renderOpened.apply(this,argu
ments)}},_renderClosed:function(){if(!this.noAnimations&&this.animationConfig.cl
ose){this.$.contentWrapper.classList.add("animating");this.playAnimation("close"
)}else{Polymer.IronOverlayBehaviorImpl._renderClosed.apply(this,arguments)}},_on
NeonAnimationFinish:function(){this.$.contentWrapper.classList.remove("animating
");if(this.opened){this._finishRenderOpened()}else{this._finishRenderClosed()}},
_onCaptureScroll:function(){if(!this.allowOutsideScroll){this._restoreScrollPosi
tion()}else{this._refitOnScrollRAF&&window.cancelAnimationFrame(this._refitOnScr
ollRAF);this._refitOnScrollRAF=window.requestAnimationFrame(this.refit.bind(this
))}},_saveScrollPosition:function(){if(document.scrollingElement){this._scrollTo
p=document.scrollingElement.scrollTop;this._scrollLeft=document.scrollingElement
.scrollLeft}else{this._scrollTop=Math.max(document.documentElement.scrollTop,doc
ument.body.scrollTop);this._scrollLeft=Math.max(document.documentElement.scrollL
eft,document.body.scrollLeft)}},_restoreScrollPosition:function(){if(document.sc
rollingElement){document.scrollingElement.scrollTop=this._scrollTop;document.scr
ollingElement.scrollLeft=this._scrollLeft}else{document.documentElement.scrollTo
p=this._scrollTop;document.documentElement.scrollLeft=this._scrollLeft;document.
body.scrollTop=this._scrollTop;document.body.scrollLeft=this._scrollLeft}},_upda
teAnimationConfig:function(){var animations=(this.openAnimationConfig||[]).conca
t(this.closeAnimationConfig||[]);for(var i=0;i<animations.length;i++){animations
[i].node=this.containedElement}this.animationConfig={open:this.openAnimationConf
ig,close:this.closeAnimationConfig}},_updateOverlayPosition:function(){if(this.i
sAttached){this.notifyResize()}},_applyFocus:function(){var focusTarget=this.foc
usTarget||this.containedElement;if(focusTarget&&this.opened&&!this.noAutoFocus){
focusTarget.focus()}else{Polymer.IronOverlayBehaviorImpl._applyFocus.apply(this,
arguments)}}})})();Polymer({is:"paper-tab",behaviors:[Polymer.IronControlState,P
olymer.IronButtonState,Polymer.PaperRippleBehavior],properties:{link:{type:Boole
an,value:false,reflectToAttribute:true}},hostAttributes:{role:"tab"},listeners:{
down:"_updateNoink",tap:"_onTap"},attached:function(){this._updateNoink()},get _
parentNoink(){var parent=Polymer.dom(this).parentNode;return!!parent&&!!parent.n
oink},_updateNoink:function(){this.noink=!!this.noink||!!this._parentNoink},_onT
ap:function(event){if(this.link){var anchor=this.queryEffectiveChildren("a");if(
!anchor){return}if(event.target===anchor){return}anchor.click()}}});Polymer.Iron
MenuBehaviorImpl={properties:{focusedItem:{observer:"_focusedItemChanged",readOn
ly:true,type:Object},attrForItemTitle:{type:String}},hostAttributes:{role:"menu"
,tabindex:"0"},observers:["_updateMultiselectable(multi)"],listeners:{focus:"_on
Focus",keydown:"_onKeydown","iron-items-changed":"_onIronItemsChanged"},keyBindi
ngs:{up:"_onUpKey",down:"_onDownKey",esc:"_onEscKey","shift+tab:keydown":"_onShi
ftTabDown"},attached:function(){this._resetTabindices()},select:function(value){
if(this._defaultFocusAsync){this.cancelAsync(this._defaultFocusAsync);this._defa
ultFocusAsync=null}var item=this._valueToItem(value);if(item&&item.hasAttribute(
"disabled"))return;this._setFocusedItem(item);Polymer.IronMultiSelectableBehavio
rImpl.select.apply(this,arguments)},_resetTabindices:function(){var selectedItem
=this.multi?this.selectedItems&&this.selectedItems[0]:this.selectedItem;this.ite
ms.forEach(function(item){item.setAttribute("tabindex",item===selectedItem?"0":"
-1")},this)},_updateMultiselectable:function(multi){if(multi){this.setAttribute(
"aria-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.get
Attribute(attr);if(!item.hasAttribute("disabled")&&title&&title.trim().charAt(0)
.toLowerCase()===String.fromCharCode(event.keyCode).toLowerCase()){this._setFocu
sedItem(item);break}}},_focusPrevious:function(){var length=this.items.length;va
r 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("d
isabled")){var owner=Polymer.dom(item).getOwnerRoot()||document;this._setFocused
Item(item);if(Polymer.dom(owner).activeElement==item){return}}}},_focusNext:func
tion(){var length=this.items.length;var curFocusIndex=Number(this.indexOf(this.f
ocusedItem));for(var i=1;i<length+1;i++){var item=this.items[(curFocusIndex+i)%l
ength];if(!item.hasAttribute("disabled")){var owner=Polymer.dom(item).getOwnerRo
ot()||document;this._setFocusedItem(item);if(Polymer.dom(owner).activeElement==i
tem){return}}}},_applySelection:function(item,isSelected){if(isSelected){item.se
tAttribute("aria-selected","true")}else{item.removeAttribute("aria-selected")}Po
lymer.IronSelectableBehavior._applySelection.apply(this,arguments)},_focusedItem
Changed:function(focusedItem,old){old&&old.setAttribute("tabindex","-1");if(focu
sedItem){focusedItem.setAttribute("tabindex","0");focusedItem.focus()}},_onIronI
temsChanged:function(event){if(event.detail.addedNodes.length){this._resetTabind
ices()}},_onShiftTabDown:function(event){var oldTabIndex=this.getAttribute("tabi
ndex");Polymer.IronMenuBehaviorImpl._shiftTabPressed=true;this._setFocusedItem(n
ull);this.setAttribute("tabindex","-1");this.async(function(){this.setAttribute(
"tabindex",oldTabIndex);Polymer.IronMenuBehaviorImpl._shiftTabPressed=false},1)}
,_onFocus:function(event){if(Polymer.IronMenuBehaviorImpl._shiftTabPressed){retu
rn}var rootTarget=Polymer.dom(event).rootTarget;if(rootTarget!==this&&typeof roo
tTarget.tabIndex!=="undefined"&&!this.isLightDescendant(rootTarget)){return}this
._defaultFocusAsync=this.async(function(){var selectedItem=this.multi?this.selec
tedItems&&this.selectedItems[0]:this.selectedItem;this._setFocusedItem(null);if(
selectedItem){this._setFocusedItem(selectedItem)}else if(this.items[0]){this._fo
cusNext()}})},_onUpKey:function(event){this._focusPrevious();event.detail.keyboa
rdEvent.preventDefault()},_onDownKey:function(event){this._focusNext();event.det
ail.keyboardEvent.preventDefault()},_onEscKey:function(event){this.focusedItem.b
lur()},_onKeydown:function(event){if(!this.keyboardEventMatchesKeys(event,"up do
wn esc")){this._focusWithKeyboardEvent(event)}event.stopPropagation()},_activate
Handler:function(event){Polymer.IronSelectableBehavior._activateHandler.call(thi
s,event);event.stopPropagation()}};Polymer.IronMenuBehaviorImpl._shiftTabPressed
=false;Polymer.IronMenuBehavior=[Polymer.IronMultiSelectableBehavior,Polymer.Iro
nA11yKeysBehavior,Polymer.IronMenuBehaviorImpl];Polymer.IronMenubarBehaviorImpl=
{hostAttributes:{role:"menubar"},keyBindings:{left:"_onLeftKey",right:"_onRightK
ey"},_onUpKey:function(event){this.focusedItem.click();event.detail.keyboardEven
t.preventDefault()},_onDownKey:function(event){this.focusedItem.click();event.de
tail.keyboardEvent.preventDefault()},get _isRTL(){return window.getComputedStyle
(this)["direction"]==="rtl"},_onLeftKey:function(event){if(this._isRTL){this._fo
cusNext()}else{this._focusPrevious()}event.detail.keyboardEvent.preventDefault()
},_onRightKey:function(event){if(this._isRTL){this._focusPrevious()}else{this._f
ocusNext()}event.detail.keyboardEvent.preventDefault()},_onKeydown:function(even
t){if(this.keyboardEventMatchesKeys(event,"up down left right esc")){return}this
._focusWithKeyboardEvent(event)}};Polymer.IronMenubarBehavior=[Polymer.IronMenuB
ehavior,Polymer.IronMenubarBehaviorImpl];Polymer({is:"paper-tabs",behaviors:[Pol
ymer.IronResizableBehavior,Polymer.IronMenubarBehavior],properties:{noink:{type:
Boolean,value:false,observer:"_noinkChanged"},noBar:{type:Boolean,value:false},n
oSlide:{type:Boolean,value:false},scrollable:{type:Boolean,value:false},fitConta
iner:{type:Boolean,value:false},disableDrag:{type:Boolean,value:false},hideScrol
lButtons:{type:Boolean,value:false},alignBottom:{type:Boolean,value:false},selec
table:{type:String,value:"paper-tab"},autoselect:{type:Boolean,value:false},auto
selectDelay:{type:Number,value:0},_step:{type:Number,value:10},_holdDelay:{type:
Number,value:1},_leftHidden:{type:Boolean,value:false},_rightHidden:{type:Boolea
n,value:false},_previousTab:{type:Object}},hostAttributes:{role:"tablist"},liste
ners:{"iron-resize":"_onTabSizingChanged","iron-items-changed":"_onTabSizingChan
ged","iron-select":"_onIronSelect","iron-deselect":"_onIronDeselect"},keyBinding
s:{"left:keyup right:keyup":"_onArrowKeyup"},created:function(){this._holdJob=nu
ll;this._pendingActivationItem=undefined;this._pendingActivationTimeout=undefine
d;this._bindDelayedActivationHandler=this._delayedActivationHandler.bind(this);t
his.addEventListener("blur",this._onBlurCapture.bind(this),true)},ready:function
(){this.setScrollDirection("y",this.$.tabsContainer)},detached:function(){this._
cancelPendingActivation()},_noinkChanged:function(noink){var childTabs=Polymer.d
om(this).querySelectorAll("paper-tab");childTabs.forEach(noink?this._setNoinkAtt
ribute:this._removeNoinkAttribute)},_setNoinkAttribute:function(element){element
.setAttribute("noink","")},_removeNoinkAttribute:function(element){element.remov
eAttribute("noink")},_computeScrollButtonClass:function(hideThisButton,scrollabl
e,hideScrollButtons){if(!scrollable||hideScrollButtons){return"hidden"}if(hideTh
isButton){return"not-visible"}return""},_computeTabsContentClass:function(scroll
able,fitContainer){return scrollable?"scrollable"+(fitContainer?" fit-container"
:""):" fit-container"},_computeSelectionBarClass:function(noBar,alignBottom){if(
noBar){return"hidden"}else if(alignBottom){return"align-bottom"}return""},_onTab
SizingChanged:function(){this.debounce("_onTabSizingChanged",function(){this._sc
roll();this._tabChanged(this.selectedItem)},10)},_onIronSelect:function(event){t
his._tabChanged(event.detail.item,this._previousTab);this._previousTab=event.det
ail.item;this.cancelDebouncer("tab-changed")},_onIronDeselect:function(event){th
is.debounce("tab-changed",function(){this._tabChanged(null,this._previousTab);th
is._previousTab=null},1)},_activateHandler:function(){this._cancelPendingActivat
ion();Polymer.IronMenuBehaviorImpl._activateHandler.apply(this,arguments)},_sche
duleActivation:function(item,delay){this._pendingActivationItem=item;this._pendi
ngActivationTimeout=this.async(this._bindDelayedActivationHandler,delay)},_delay
edActivationHandler:function(){var item=this._pendingActivationItem;this._pendin
gActivationItem=undefined;this._pendingActivationTimeout=undefined;item.fire(thi
s.activateEvent,null,{bubbles:true,cancelable:true})},_cancelPendingActivation:f
unction(){if(this._pendingActivationTimeout!==undefined){this.cancelAsync(this._
pendingActivationTimeout);this._pendingActivationItem=undefined;this._pendingAct
ivationTimeout=undefined}},_onArrowKeyup:function(event){if(this.autoselect){thi
s._scheduleActivation(this.focusedItem,this.autoselectDelay)}},_onBlurCapture:fu
nction(event){if(event.target===this._pendingActivationItem){this._cancelPending
Activation()}},get _tabContainerScrollSize(){return Math.max(0,this.$.tabsContai
ner.scrollWidth-this.$.tabsContainer.offsetWidth)},_scroll:function(e,detail){if
(!this.scrollable){return}var ddx=detail&&-detail.ddx||0;this._affectScroll(ddx)
},_down:function(e){this.async(function(){if(this._defaultFocusAsync){this.cance
lAsync(this._defaultFocusAsync);this._defaultFocusAsync=null}},1)},_affectScroll
:function(dx){this.$.tabsContainer.scrollLeft+=dx;var scrollLeft=this.$.tabsCont
ainer.scrollLeft;this._leftHidden=scrollLeft===0;this._rightHidden=scrollLeft===
this._tabContainerScrollSize},_onLeftScrollButtonDown:function(){this._scrollToL
eft();this._holdJob=setInterval(this._scrollToLeft.bind(this),this._holdDelay)},
_onRightScrollButtonDown:function(){this._scrollToRight();this._holdJob=setInter
val(this._scrollToRight.bind(this),this._holdDelay)},_onScrollButtonUp:function(
){clearInterval(this._holdJob);this._holdJob=null},_scrollToLeft:function(){this
._affectScroll(-this._step)},_scrollToRight:function(){this._affectScroll(this._
step)},_tabChanged:function(tab,old){if(!tab){this.$.selectionBar.classList.remo
ve("expand");this.$.selectionBar.classList.remove("contract");this._positionBar(
0,0);return}var r=this.$.tabsContent.getBoundingClientRect();var w=r.width;var t
abRect=tab.getBoundingClientRect();var tabOffsetLeft=tabRect.left-r.left;this._p
os={width:this._calcPercent(tabRect.width,w),left:this._calcPercent(tabOffsetLef
t,w)};if(this.noSlide||old==null){this.$.selectionBar.classList.remove("expand")
;this.$.selectionBar.classList.remove("contract");this._positionBar(this._pos.wi
dth,this._pos.left);return}var oldRect=old.getBoundingClientRect();var oldIndex=
this.items.indexOf(old);var index=this.items.indexOf(tab);var m=5;this.$.selecti
onBar.classList.add("expand");var moveRight=oldIndex<index;var isRTL=this._isRTL
;if(isRTL){moveRight=!moveRight}if(moveRight){this._positionBar(this._calcPercen
t(tabRect.left+tabRect.width-oldRect.left,w)-m,this._left)}else{this._positionBa
r(this._calcPercent(oldRect.left+oldRect.width-tabRect.left,w)-m,this._calcPerce
nt(tabOffsetLeft,w)+m)}if(this.scrollable){this._scrollToSelectedIfNeeded(tabRec
t.width,tabOffsetLeft)}},_scrollToSelectedIfNeeded:function(tabWidth,tabOffsetLe
ft){var l=tabOffsetLeft-this.$.tabsContainer.scrollLeft;if(l<0){this.$.tabsConta
iner.scrollLeft+=l}else{l+=tabWidth-this.$.tabsContainer.offsetWidth;if(l>0){thi
s.$.tabsContainer.scrollLeft+=l}}},_calcPercent:function(w,w0){return 100*w/w0},
_positionBar:function(width,left){width=width||0;left=left||0;this._width=width;
this._left=left;this.transform("translateX("+left+"%) scaleX("+width/100+")",thi
s.$.selectionBar)},_onBarTransitionEnd:function(e){var cl=this.$.selectionBar.cl
assList;if(cl.contains("expand")){cl.remove("expand");cl.add("contract");this._p
ositionBar(this._pos.width,this._pos.left)}else if(cl.contains("contract")){cl.r
emove("contract")}}}); | 736 is: "cr-dialog", |
| 737 "extends": "dialog", |
| 738 properties: |
| 739 {closeText: String, ignorePopstate: {type: Boolean, value: false}}, |
| 740 ready: function() { |
| 741 window.addEventListener("popstate", function() { |
| 742 if (!this.ignorePopstate && this.open) |
| 743 this.cancel() |
| 744 }.bind(this)) |
| 745 }, |
| 746 cancel: function() { |
| 747 this.fire("cancel"); |
| 748 HTMLDialogElement.prototype.close.call(this, "") |
| 749 }, |
| 750 close: function(opt_returnValue) { |
| 751 HTMLDialogElement.prototype.close.call(this, "success") |
| 752 }, |
| 753 getCloseButton: function() { |
| 754 return this.$.close |
| 755 } |
| 756 }); |
| 757 Polymer({ |
| 758 is: "app-drawer", |
| 759 properties: { |
| 760 opened: |
| 761 {type: Boolean, value: false, notify: true, reflectToAttribute: true}, |
| 762 persistent: {type: Boolean, value: false, reflectToAttribute: true}, |
| 763 align: {type: String, value: "left"}, |
| 764 position: |
| 765 {type: String, readOnly: true, value: "left", reflectToAttribute: true}, |
| 766 swipeOpen: {type: Boolean, value: false, reflectToAttribute: true}, |
| 767 noFocusTrap: {type: Boolean, value: false} |
| 768 }, |
| 769 observers: ["resetLayout(position)", "_resetPosition(align, isAttached)"], |
| 770 _translateOffset: 0, |
| 771 _trackDetails: null, |
| 772 _drawerState: 0, |
| 773 _boundEscKeydownHandler: null, |
| 774 _firstTabStop: null, |
| 775 _lastTabStop: null, |
| 776 ready: function() { |
| 777 this.setScrollDirection("y"); |
| 778 this._setTransitionDuration("0s") |
| 779 }, |
| 780 attached: function() { |
| 781 Polymer.RenderStatus.afterNextRender(this, function() { |
| 782 this._setTransitionDuration(""); |
| 783 this._boundEscKeydownHandler = this._escKeydownHandler.bind(this); |
| 784 this._resetDrawerState(); |
| 785 this.listen(this, "track", "_track"); |
| 786 this.addEventListener("transitionend", this._transitionend.bind(this)); |
| 787 this.addEventListener("keydown", this._tabKeydownHandler.bind(this)) |
| 788 }) |
| 789 }, |
| 790 detached: function() { |
| 791 document.removeEventListener("keydown", this._boundEscKeydownHandler) |
| 792 }, |
| 793 open: function() { |
| 794 this.opened = true |
| 795 }, |
| 796 close: function() { |
| 797 this.opened = false |
| 798 }, |
| 799 toggle: function() { |
| 800 this.opened = !this.opened |
| 801 }, |
| 802 getWidth: function() { |
| 803 return this.$.contentContainer.offsetWidth |
| 804 }, |
| 805 resetLayout: function() { |
| 806 this.debounce("_resetLayout", function() { |
| 807 this.fire("app-drawer-reset-layout") |
| 808 }, 1) |
| 809 }, |
| 810 _isRTL: function() { |
| 811 return window.getComputedStyle(this).direction === "rtl" |
| 812 }, |
| 813 _resetPosition: function() { |
| 814 switch (this.align) { |
| 815 case "start": |
| 816 this._setPosition(this._isRTL() ? "right" : "left"); |
| 817 return; |
| 818 case "end": |
| 819 this._setPosition(this._isRTL() ? "left" : "right"); |
| 820 return |
| 821 } |
| 822 this._setPosition(this.align) |
| 823 }, |
| 824 _escKeydownHandler: function(event) { |
| 825 var ESC_KEYCODE = 27; |
| 826 if (event.keyCode === ESC_KEYCODE) { |
| 827 event.preventDefault(); |
| 828 this.close() |
| 829 } |
| 830 }, |
| 831 _track: function(event) { |
| 832 if (this.persistent) { |
| 833 return |
| 834 } |
| 835 event.preventDefault(); |
| 836 switch (event.detail.state) { |
| 837 case "start": |
| 838 this._trackStart(event); |
| 839 break; |
| 840 case "track": |
| 841 this._trackMove(event); |
| 842 break; |
| 843 case "end": |
| 844 this._trackEnd(event); |
| 845 break |
| 846 } |
| 847 }, |
| 848 _trackStart: function(event) { |
| 849 this._drawerState = this._DRAWER_STATE.TRACKING; |
| 850 this._setTransitionDuration("0s"); |
| 851 this.style.visibility = "visible"; |
| 852 var rect = this.$.contentContainer.getBoundingClientRect(); |
| 853 if (this.position === "left") { |
| 854 this._translateOffset = rect.left |
| 855 } else { |
| 856 this._translateOffset = rect.right - window.innerWidth |
| 857 } |
| 858 this._trackDetails = [] |
| 859 }, |
| 860 _trackMove: function(event) { |
| 861 this._translateDrawer(event.detail.dx + this._translateOffset); |
| 862 this._trackDetails.push({dx: event.detail.dx, timeStamp: Date.now()}) |
| 863 }, |
| 864 _trackEnd: function(event) { |
| 865 var x = event.detail.dx + this._translateOffset; |
| 866 var drawerWidth = this.getWidth(); |
| 867 var isPositionLeft = this.position === "left"; |
| 868 var isInEndState = isPositionLeft ? x >= 0 || x <= -drawerWidth : |
| 869 x <= 0 || x >= drawerWidth; |
| 870 if (!isInEndState) { |
| 871 var trackDetails = this._trackDetails; |
| 872 this._trackDetails = null; |
| 873 this._flingDrawer(event, trackDetails); |
| 874 if (this._drawerState === this._DRAWER_STATE.FLINGING) { |
| 875 return |
| 876 } |
| 877 } |
| 878 var halfWidth = drawerWidth / 2; |
| 879 if (event.detail.dx < -halfWidth) { |
| 880 this.opened = this.position === "right" |
| 881 } else if (event.detail.dx > halfWidth) { |
| 882 this.opened = this.position === "left" |
| 883 } |
| 884 if (isInEndState) { |
| 885 this._resetDrawerState() |
| 886 } |
| 887 this._setTransitionDuration(""); |
| 888 this._resetDrawerTranslate(); |
| 889 this.style.visibility = "" |
| 890 }, |
| 891 _calculateVelocity: function(event, trackDetails) { |
| 892 var now = Date.now(); |
| 893 var timeLowerBound = now - 100; |
| 894 var trackDetail; |
| 895 var min = 0; |
| 896 var max = trackDetails.length - 1; |
| 897 while (min <= max) { |
| 898 var mid = min + max >> 1; |
| 899 var d = trackDetails[mid]; |
| 900 if (d.timeStamp >= timeLowerBound) { |
| 901 trackDetail = d; |
| 902 max = mid - 1 |
| 903 } else { |
| 904 min = mid + 1 |
| 905 } |
| 906 } |
| 907 if (trackDetail) { |
| 908 var dx = event.detail.dx - trackDetail.dx; |
| 909 var dt = now - trackDetail.timeStamp || 1; |
| 910 return dx / dt |
| 911 } |
| 912 return 0 |
| 913 }, |
| 914 _flingDrawer: function(event, trackDetails) { |
| 915 var velocity = this._calculateVelocity(event, trackDetails); |
| 916 if (Math.abs(velocity) < this._MIN_FLING_THRESHOLD) { |
| 917 return |
| 918 } |
| 919 this._drawerState = this._DRAWER_STATE.FLINGING; |
| 920 var x = event.detail.dx + this._translateOffset; |
| 921 var drawerWidth = this.getWidth(); |
| 922 var isPositionLeft = this.position === "left"; |
| 923 var isVelocityPositive = velocity > 0; |
| 924 var isClosingLeft = !isVelocityPositive && isPositionLeft; |
| 925 var isClosingRight = isVelocityPositive && !isPositionLeft; |
| 926 var dx; |
| 927 if (isClosingLeft) { |
| 928 dx = -(x + drawerWidth) |
| 929 } else if (isClosingRight) { |
| 930 dx = drawerWidth - x |
| 931 } else { |
| 932 dx = -x |
| 933 } |
| 934 if (isVelocityPositive) { |
| 935 velocity = Math.max(velocity, this._MIN_TRANSITION_VELOCITY); |
| 936 this.opened = this.position === "left" |
| 937 } else { |
| 938 velocity = Math.min(velocity, -this._MIN_TRANSITION_VELOCITY); |
| 939 this.opened = this.position === "right" |
| 940 } |
| 941 this._setTransitionDuration( |
| 942 this._FLING_INITIAL_SLOPE * dx / velocity + "ms"); |
| 943 this._setTransitionTimingFunction(this._FLING_TIMING_FUNCTION); |
| 944 this._resetDrawerTranslate() |
| 945 }, |
| 946 _transitionend: function(event) { |
| 947 var target = Polymer.dom(event).rootTarget; |
| 948 if (target === this.$.contentContainer || target === this.$.scrim) { |
| 949 if (this._drawerState === this._DRAWER_STATE.FLINGING) { |
| 950 this._setTransitionDuration(""); |
| 951 this._setTransitionTimingFunction(""); |
| 952 this.style.visibility = "" |
| 953 } |
| 954 this._resetDrawerState() |
| 955 } |
| 956 }, |
| 957 _setTransitionDuration: function(duration) { |
| 958 this.$.contentContainer.style.transitionDuration = duration; |
| 959 this.$.scrim.style.transitionDuration = duration |
| 960 }, |
| 961 _setTransitionTimingFunction: function(timingFunction) { |
| 962 this.$.contentContainer.style.transitionTimingFunction = timingFunction; |
| 963 this.$.scrim.style.transitionTimingFunction = timingFunction |
| 964 }, |
| 965 _translateDrawer: function(x) { |
| 966 var drawerWidth = this.getWidth(); |
| 967 if (this.position === "left") { |
| 968 x = Math.max(-drawerWidth, Math.min(x, 0)); |
| 969 this.$.scrim.style.opacity = 1 + x / drawerWidth |
| 970 } else { |
| 971 x = Math.max(0, Math.min(x, drawerWidth)); |
| 972 this.$.scrim.style.opacity = 1 - x / drawerWidth |
| 973 } |
| 974 this.translate3d(x + "px", "0", "0", this.$.contentContainer) |
| 975 }, |
| 976 _resetDrawerTranslate: function() { |
| 977 this.$.scrim.style.opacity = ""; |
| 978 this.transform("", this.$.contentContainer) |
| 979 }, |
| 980 _resetDrawerState: function() { |
| 981 var oldState = this._drawerState; |
| 982 if (this.opened) { |
| 983 this._drawerState = this.persistent ? |
| 984 this._DRAWER_STATE.OPENED_PERSISTENT : |
| 985 this._DRAWER_STATE.OPENED |
| 986 } else { |
| 987 this._drawerState = this._DRAWER_STATE.CLOSED |
| 988 } |
| 989 if (oldState !== this._drawerState) { |
| 990 if (this._drawerState === this._DRAWER_STATE.OPENED) { |
| 991 this._setKeyboardFocusTrap(); |
| 992 document.addEventListener("keydown", this._boundEscKeydownHandler); |
| 993 document.body.style.overflow = "hidden" |
| 994 } else { |
| 995 document.removeEventListener("keydown", this._boundEscKeydownHandler); |
| 996 document.body.style.overflow = "" |
| 997 } |
| 998 if (oldState !== this._DRAWER_STATE.INIT) { |
| 999 this.fire("app-drawer-transitioned") |
| 1000 } |
| 1001 } |
| 1002 }, |
| 1003 _setKeyboardFocusTrap: function() { |
| 1004 if (this.noFocusTrap) { |
| 1005 return |
| 1006 } |
| 1007 var focusableElementsSelector = [ |
| 1008 'a[href]:not([tabindex="-1"])', 'area[href]:not([tabindex="-1"])', |
| 1009 'input:not([disabled]):not([tabindex="-1"])', |
| 1010 'select:not([disabled]):not([tabindex="-1"])', |
| 1011 'textarea:not([disabled]):not([tabindex="-1"])', |
| 1012 'button:not([disabled]):not([tabindex="-1"])', |
| 1013 'iframe:not([tabindex="-1"])', '[tabindex]:not([tabindex="-1"])', |
| 1014 '[contentEditable=true]:not([tabindex="-1"])' |
| 1015 ].join(","); |
| 1016 var focusableElements = |
| 1017 Polymer.dom(this).querySelectorAll(focusableElementsSelector); |
| 1018 if (focusableElements.length > 0) { |
| 1019 this._firstTabStop = focusableElements[0]; |
| 1020 this._lastTabStop = focusableElements[focusableElements.length - 1] |
| 1021 } else { |
| 1022 this._firstTabStop = null; |
| 1023 this._lastTabStop = null |
| 1024 } |
| 1025 var tabindex = this.getAttribute("tabindex"); |
| 1026 if (tabindex && parseInt(tabindex, 10) > -1) { |
| 1027 this.focus() |
| 1028 } else if (this._firstTabStop) { |
| 1029 this._firstTabStop.focus() |
| 1030 } |
| 1031 }, |
| 1032 _tabKeydownHandler: function(event) { |
| 1033 if (this.noFocusTrap) { |
| 1034 return |
| 1035 } |
| 1036 var TAB_KEYCODE = 9; |
| 1037 if (this._drawerState === this._DRAWER_STATE.OPENED && |
| 1038 event.keyCode === TAB_KEYCODE) { |
| 1039 if (event.shiftKey) { |
| 1040 if (this._firstTabStop && |
| 1041 Polymer.dom(event).localTarget === this._firstTabStop) { |
| 1042 event.preventDefault(); |
| 1043 this._lastTabStop.focus() |
| 1044 } |
| 1045 } else { |
| 1046 if (this._lastTabStop && |
| 1047 Polymer.dom(event).localTarget === this._lastTabStop) { |
| 1048 event.preventDefault(); |
| 1049 this._firstTabStop.focus() |
| 1050 } |
| 1051 } |
| 1052 } |
| 1053 }, |
| 1054 _MIN_FLING_THRESHOLD: .2, |
| 1055 _MIN_TRANSITION_VELOCITY: 1.2, |
| 1056 _FLING_TIMING_FUNCTION: "cubic-bezier(0.667, 1, 0.667, 1)", |
| 1057 _FLING_INITIAL_SLOPE: 1.5, |
| 1058 _DRAWER_STATE: { |
| 1059 INIT: 0, |
| 1060 OPENED: 1, |
| 1061 OPENED_PERSISTENT: 2, |
| 1062 CLOSED: 3, |
| 1063 TRACKING: 4, |
| 1064 FLINGING: 5 |
| 1065 } |
| 1066 }); |
| 1067 Polymer.IronFitBehavior = { |
| 1068 properties: { |
| 1069 sizingTarget: { |
| 1070 type: Object, |
| 1071 value: function() { |
| 1072 return this |
| 1073 } |
| 1074 }, |
| 1075 fitInto: {type: Object, value: window}, |
| 1076 noOverlap: {type: Boolean}, |
| 1077 positionTarget: {type: Element}, |
| 1078 horizontalAlign: {type: String}, |
| 1079 verticalAlign: {type: String}, |
| 1080 dynamicAlign: {type: Boolean}, |
| 1081 horizontalOffset: {type: Number, value: 0, notify: true}, |
| 1082 verticalOffset: {type: Number, value: 0, notify: true}, |
| 1083 autoFitOnAttach: {type: Boolean, value: false}, |
| 1084 _fitInfo: {type: Object} |
| 1085 }, |
| 1086 get _fitWidth() { |
| 1087 var fitWidth; |
| 1088 if (this.fitInto === window) { |
| 1089 fitWidth = this.fitInto.innerWidth |
| 1090 } else { |
| 1091 fitWidth = this.fitInto.getBoundingClientRect().width |
| 1092 } |
| 1093 return fitWidth |
| 1094 }, |
| 1095 get _fitHeight() { |
| 1096 var fitHeight; |
| 1097 if (this.fitInto === window) { |
| 1098 fitHeight = this.fitInto.innerHeight |
| 1099 } else { |
| 1100 fitHeight = this.fitInto.getBoundingClientRect().height |
| 1101 } |
| 1102 return fitHeight |
| 1103 }, |
| 1104 get _fitLeft() { |
| 1105 var fitLeft; |
| 1106 if (this.fitInto === window) { |
| 1107 fitLeft = 0 |
| 1108 } else { |
| 1109 fitLeft = this.fitInto.getBoundingClientRect().left |
| 1110 } |
| 1111 return fitLeft |
| 1112 }, |
| 1113 get _fitTop() { |
| 1114 var fitTop; |
| 1115 if (this.fitInto === window) { |
| 1116 fitTop = 0 |
| 1117 } else { |
| 1118 fitTop = this.fitInto.getBoundingClientRect().top |
| 1119 } |
| 1120 return fitTop |
| 1121 }, |
| 1122 get _defaultPositionTarget() { |
| 1123 var parent = Polymer.dom(this).parentNode; |
| 1124 if (parent && parent.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { |
| 1125 parent = parent.host |
| 1126 } |
| 1127 return parent |
| 1128 }, |
| 1129 get _localeHorizontalAlign() { |
| 1130 if (this._isRTL) { |
| 1131 if (this.horizontalAlign === "right") { |
| 1132 return "left" |
| 1133 } |
| 1134 if (this.horizontalAlign === "left") { |
| 1135 return "right" |
| 1136 } |
| 1137 } |
| 1138 return this.horizontalAlign |
| 1139 }, |
| 1140 attached: function() { |
| 1141 this._isRTL = window.getComputedStyle(this).direction == "rtl"; |
| 1142 this.positionTarget = this.positionTarget || this._defaultPositionTarget; |
| 1143 if (this.autoFitOnAttach) { |
| 1144 if (window.getComputedStyle(this).display === "none") { |
| 1145 setTimeout(function() { |
| 1146 this.fit() |
| 1147 }.bind(this)) |
| 1148 } else { |
| 1149 this.fit() |
| 1150 } |
| 1151 } |
| 1152 }, |
| 1153 fit: function() { |
| 1154 this.position(); |
| 1155 this.constrain(); |
| 1156 this.center() |
| 1157 }, |
| 1158 _discoverInfo: function() { |
| 1159 if (this._fitInfo) { |
| 1160 return |
| 1161 } |
| 1162 var target = window.getComputedStyle(this); |
| 1163 var sizer = window.getComputedStyle(this.sizingTarget); |
| 1164 this._fitInfo = { |
| 1165 inlineStyle: { |
| 1166 top: this.style.top || "", |
| 1167 left: this.style.left || "", |
| 1168 position: this.style.position || "" |
| 1169 }, |
| 1170 sizerInlineStyle: { |
| 1171 maxWidth: this.sizingTarget.style.maxWidth || "", |
| 1172 maxHeight: this.sizingTarget.style.maxHeight || "", |
| 1173 boxSizing: this.sizingTarget.style.boxSizing || "" |
| 1174 }, |
| 1175 positionedBy: { |
| 1176 vertically: target.top !== "auto" ? |
| 1177 "top" : |
| 1178 target.bottom !== "auto" ? "bottom" : null, |
| 1179 horizontally: target.left !== "auto" ? |
| 1180 "left" : |
| 1181 target.right !== "auto" ? "right" : null |
| 1182 }, |
| 1183 sizedBy: { |
| 1184 height: sizer.maxHeight !== "none", |
| 1185 width: sizer.maxWidth !== "none", |
| 1186 minWidth: parseInt(sizer.minWidth, 10) || 0, |
| 1187 minHeight: parseInt(sizer.minHeight, 10) || 0 |
| 1188 }, |
| 1189 margin: { |
| 1190 top: parseInt(target.marginTop, 10) || 0, |
| 1191 right: parseInt(target.marginRight, 10) || 0, |
| 1192 bottom: parseInt(target.marginBottom, 10) || 0, |
| 1193 left: parseInt(target.marginLeft, 10) || 0 |
| 1194 } |
| 1195 }; |
| 1196 if (this.verticalOffset) { |
| 1197 this._fitInfo.margin.top = this._fitInfo.margin.bottom = |
| 1198 this.verticalOffset; |
| 1199 this._fitInfo.inlineStyle.marginTop = this.style.marginTop || ""; |
| 1200 this._fitInfo.inlineStyle.marginBottom = this.style.marginBottom || ""; |
| 1201 this.style.marginTop = this.style.marginBottom = |
| 1202 this.verticalOffset + "px" |
| 1203 } |
| 1204 if (this.horizontalOffset) { |
| 1205 this._fitInfo.margin.left = this._fitInfo.margin.right = |
| 1206 this.horizontalOffset; |
| 1207 this._fitInfo.inlineStyle.marginLeft = this.style.marginLeft || ""; |
| 1208 this._fitInfo.inlineStyle.marginRight = this.style.marginRight || ""; |
| 1209 this.style.marginLeft = this.style.marginRight = |
| 1210 this.horizontalOffset + "px" |
| 1211 } |
| 1212 }, |
| 1213 resetFit: function() { |
| 1214 var info = this._fitInfo || {}; |
| 1215 for (var property in info.sizerInlineStyle) { |
| 1216 this.sizingTarget.style[property] = info.sizerInlineStyle[property] |
| 1217 } |
| 1218 for (var property in info.inlineStyle) { |
| 1219 this.style[property] = info.inlineStyle[property] |
| 1220 } |
| 1221 this._fitInfo = null |
| 1222 }, |
| 1223 refit: function() { |
| 1224 var scrollLeft = this.sizingTarget.scrollLeft; |
| 1225 var scrollTop = this.sizingTarget.scrollTop; |
| 1226 this.resetFit(); |
| 1227 this.fit(); |
| 1228 this.sizingTarget.scrollLeft = scrollLeft; |
| 1229 this.sizingTarget.scrollTop = scrollTop |
| 1230 }, |
| 1231 position: function() { |
| 1232 if (!this.horizontalAlign && !this.verticalAlign) { |
| 1233 return |
| 1234 } |
| 1235 this._discoverInfo(); |
| 1236 this.style.position = "fixed"; |
| 1237 this.sizingTarget.style.boxSizing = "border-box"; |
| 1238 this.style.left = "0px"; |
| 1239 this.style.top = "0px"; |
| 1240 var rect = this.getBoundingClientRect(); |
| 1241 var positionRect = this.__getNormalizedRect(this.positionTarget); |
| 1242 var fitRect = this.__getNormalizedRect(this.fitInto); |
| 1243 var margin = this._fitInfo.margin; |
| 1244 var size = { |
| 1245 width: rect.width + margin.left + margin.right, |
| 1246 height: rect.height + margin.top + margin.bottom |
| 1247 }; |
| 1248 var position = this.__getPosition( |
| 1249 this._localeHorizontalAlign, this.verticalAlign, size, positionRect, |
| 1250 fitRect); |
| 1251 var left = position.left + margin.left; |
| 1252 var top = position.top + margin.top; |
| 1253 var right = Math.min(fitRect.right - margin.right, left + rect.width); |
| 1254 var bottom = Math.min(fitRect.bottom - margin.bottom, top + rect.height); |
| 1255 var minWidth = this._fitInfo.sizedBy.minWidth; |
| 1256 var minHeight = this._fitInfo.sizedBy.minHeight; |
| 1257 if (left < margin.left) { |
| 1258 left = margin.left; |
| 1259 if (right - left < minWidth) { |
| 1260 left = right - minWidth |
| 1261 } |
| 1262 } |
| 1263 if (top < margin.top) { |
| 1264 top = margin.top; |
| 1265 if (bottom - top < minHeight) { |
| 1266 top = bottom - minHeight |
| 1267 } |
| 1268 } |
| 1269 this.sizingTarget.style.maxWidth = right - left + "px"; |
| 1270 this.sizingTarget.style.maxHeight = bottom - top + "px"; |
| 1271 this.style.left = left - rect.left + "px"; |
| 1272 this.style.top = top - rect.top + "px" |
| 1273 }, |
| 1274 constrain: function() { |
| 1275 if (this.horizontalAlign || this.verticalAlign) { |
| 1276 return |
| 1277 } |
| 1278 this._discoverInfo(); |
| 1279 var info = this._fitInfo; |
| 1280 if (!info.positionedBy.vertically) { |
| 1281 this.style.position = "fixed"; |
| 1282 this.style.top = "0px" |
| 1283 } |
| 1284 if (!info.positionedBy.horizontally) { |
| 1285 this.style.position = "fixed"; |
| 1286 this.style.left = "0px" |
| 1287 } |
| 1288 this.sizingTarget.style.boxSizing = "border-box"; |
| 1289 var rect = this.getBoundingClientRect(); |
| 1290 if (!info.sizedBy.height) { |
| 1291 this.__sizeDimension( |
| 1292 rect, info.positionedBy.vertically, "top", "bottom", "Height") |
| 1293 } |
| 1294 if (!info.sizedBy.width) { |
| 1295 this.__sizeDimension( |
| 1296 rect, info.positionedBy.horizontally, "left", "right", "Width") |
| 1297 } |
| 1298 }, |
| 1299 _sizeDimension: function(rect, positionedBy, start, end, extent) { |
| 1300 this.__sizeDimension(rect, positionedBy, start, end, extent) |
| 1301 }, |
| 1302 __sizeDimension: function(rect, positionedBy, start, end, extent) { |
| 1303 var info = this._fitInfo; |
| 1304 var fitRect = this.__getNormalizedRect(this.fitInto); |
| 1305 var max = extent === "Width" ? fitRect.width : fitRect.height; |
| 1306 var flip = positionedBy === end; |
| 1307 var offset = flip ? max - rect[end] : rect[start]; |
| 1308 var margin = info.margin[flip ? start : end]; |
| 1309 var offsetExtent = "offset" + extent; |
| 1310 var sizingOffset = this[offsetExtent] - this.sizingTarget[offsetExtent]; |
| 1311 this.sizingTarget.style["max" + extent] = |
| 1312 max - margin - offset - sizingOffset + "px" |
| 1313 }, |
| 1314 center: function() { |
| 1315 if (this.horizontalAlign || this.verticalAlign) { |
| 1316 return |
| 1317 } |
| 1318 this._discoverInfo(); |
| 1319 var positionedBy = this._fitInfo.positionedBy; |
| 1320 if (positionedBy.vertically && positionedBy.horizontally) { |
| 1321 return |
| 1322 } |
| 1323 this.style.position = "fixed"; |
| 1324 if (!positionedBy.vertically) { |
| 1325 this.style.top = "0px" |
| 1326 } |
| 1327 if (!positionedBy.horizontally) { |
| 1328 this.style.left = "0px" |
| 1329 } |
| 1330 var rect = this.getBoundingClientRect(); |
| 1331 var fitRect = this.__getNormalizedRect(this.fitInto); |
| 1332 if (!positionedBy.vertically) { |
| 1333 var top = fitRect.top - rect.top + (fitRect.height - rect.height) / 2; |
| 1334 this.style.top = top + "px" |
| 1335 } |
| 1336 if (!positionedBy.horizontally) { |
| 1337 var left = fitRect.left - rect.left + (fitRect.width - rect.width) / 2; |
| 1338 this.style.left = left + "px" |
| 1339 } |
| 1340 }, |
| 1341 __getNormalizedRect: function(target) { |
| 1342 if (target === document.documentElement || target === window) { |
| 1343 return { |
| 1344 top: 0, left: 0, width: window.innerWidth, height: window.innerHeight, |
| 1345 right: window.innerWidth, bottom: window.innerHeight |
| 1346 } |
| 1347 } |
| 1348 return target.getBoundingClientRect() |
| 1349 }, |
| 1350 __getCroppedArea: function(position, size, fitRect) { |
| 1351 var verticalCrop = Math.min(0, position.top) + |
| 1352 Math.min(0, fitRect.bottom - (position.top + size.height)); |
| 1353 var horizontalCrop = Math.min(0, position.left) + |
| 1354 Math.min(0, fitRect.right - (position.left + size.width)); |
| 1355 return Math.abs(verticalCrop) * size.width + |
| 1356 Math.abs(horizontalCrop) * size.height |
| 1357 }, |
| 1358 __getPosition: function(hAlign, vAlign, size, positionRect, fitRect) { |
| 1359 var positions = [ |
| 1360 { |
| 1361 verticalAlign: "top", |
| 1362 horizontalAlign: "left", |
| 1363 top: positionRect.top, |
| 1364 left: positionRect.left |
| 1365 }, |
| 1366 { |
| 1367 verticalAlign: "top", |
| 1368 horizontalAlign: "right", |
| 1369 top: positionRect.top, |
| 1370 left: positionRect.right - size.width |
| 1371 }, |
| 1372 { |
| 1373 verticalAlign: "bottom", |
| 1374 horizontalAlign: "left", |
| 1375 top: positionRect.bottom - size.height, |
| 1376 left: positionRect.left |
| 1377 }, |
| 1378 { |
| 1379 verticalAlign: "bottom", |
| 1380 horizontalAlign: "right", |
| 1381 top: positionRect.bottom - size.height, |
| 1382 left: positionRect.right - size.width |
| 1383 } |
| 1384 ]; |
| 1385 if (this.noOverlap) { |
| 1386 for (var i = 0, l = positions.length; i < l; i++) { |
| 1387 var copy = {}; |
| 1388 for (var key in positions[i]) { |
| 1389 copy[key] = positions[i][key] |
| 1390 } |
| 1391 positions.push(copy) |
| 1392 } |
| 1393 positions[0].top = positions[1].top += positionRect.height; |
| 1394 positions[2].top = positions[3].top -= positionRect.height; |
| 1395 positions[4].left = positions[6].left += positionRect.width; |
| 1396 positions[5].left = positions[7].left -= positionRect.width |
| 1397 } |
| 1398 vAlign = vAlign === "auto" ? null : vAlign; |
| 1399 hAlign = hAlign === "auto" ? null : hAlign; |
| 1400 var position; |
| 1401 for (var i = 0; i < positions.length; i++) { |
| 1402 var pos = positions[i]; |
| 1403 if (!this.dynamicAlign && !this.noOverlap && |
| 1404 pos.verticalAlign === vAlign && pos.horizontalAlign === hAlign) { |
| 1405 position = pos; |
| 1406 break |
| 1407 } |
| 1408 var alignOk = (!vAlign || pos.verticalAlign === vAlign) && |
| 1409 (!hAlign || pos.horizontalAlign === hAlign); |
| 1410 if (!this.dynamicAlign && !alignOk) { |
| 1411 continue |
| 1412 } |
| 1413 position = position || pos; |
| 1414 pos.croppedArea = this.__getCroppedArea(pos, size, fitRect); |
| 1415 var diff = pos.croppedArea - position.croppedArea; |
| 1416 if (diff < 0 || diff === 0 && alignOk) { |
| 1417 position = pos |
| 1418 } |
| 1419 if (position.croppedArea === 0 && alignOk) { |
| 1420 break |
| 1421 } |
| 1422 } |
| 1423 return position |
| 1424 } |
| 1425 }; |
| 1426 (function() { |
| 1427 "use strict"; |
| 1428 Polymer({ |
| 1429 is: "iron-overlay-backdrop", |
| 1430 properties: { |
| 1431 opened: { |
| 1432 reflectToAttribute: true, |
| 1433 type: Boolean, |
| 1434 value: false, |
| 1435 observer: "_openedChanged" |
| 1436 } |
| 1437 }, |
| 1438 listeners: {transitionend: "_onTransitionend"}, |
| 1439 created: function() { |
| 1440 this.__openedRaf = null |
| 1441 }, |
| 1442 attached: function() { |
| 1443 this.opened && this._openedChanged(this.opened) |
| 1444 }, |
| 1445 prepare: function() { |
| 1446 if (this.opened && !this.parentNode) { |
| 1447 Polymer.dom(document.body).appendChild(this) |
| 1448 } |
| 1449 }, |
| 1450 open: function() { |
| 1451 this.opened = true |
| 1452 }, |
| 1453 close: function() { |
| 1454 this.opened = false |
| 1455 }, |
| 1456 complete: function() { |
| 1457 if (!this.opened && this.parentNode === document.body) { |
| 1458 Polymer.dom(this.parentNode).removeChild(this) |
| 1459 } |
| 1460 }, |
| 1461 _onTransitionend: function(event) { |
| 1462 if (event && event.target === this) { |
| 1463 this.complete() |
| 1464 } |
| 1465 }, |
| 1466 _openedChanged: function(opened) { |
| 1467 if (opened) { |
| 1468 this.prepare() |
| 1469 } else { |
| 1470 var cs = window.getComputedStyle(this); |
| 1471 if (cs.transitionDuration === "0s" || cs.opacity == 0) { |
| 1472 this.complete() |
| 1473 } |
| 1474 } |
| 1475 if (!this.isAttached) { |
| 1476 return |
| 1477 } |
| 1478 if (this.__openedRaf) { |
| 1479 window.cancelAnimationFrame(this.__openedRaf); |
| 1480 this.__openedRaf = null |
| 1481 } |
| 1482 this.scrollTop = this.scrollTop; |
| 1483 this.__openedRaf = window.requestAnimationFrame(function() { |
| 1484 this.__openedRaf = null; |
| 1485 this.toggleClass("opened", this.opened) |
| 1486 }.bind(this)) |
| 1487 } |
| 1488 }) |
| 1489 })(); |
| 1490 Polymer.IronOverlayManagerClass = function() { |
| 1491 this._overlays = []; |
| 1492 this._minimumZ = 101; |
| 1493 this._backdropElement = null; |
| 1494 Polymer.Gestures.add(document, "tap", this._onCaptureClick.bind(this)); |
| 1495 document.addEventListener("focus", this._onCaptureFocus.bind(this), true); |
| 1496 document.addEventListener("keydown", this._onCaptureKeyDown.bind(this), true) |
| 1497 }; |
| 1498 Polymer.IronOverlayManagerClass.prototype = { |
| 1499 constructor: Polymer.IronOverlayManagerClass, |
| 1500 get backdropElement() { |
| 1501 if (!this._backdropElement) { |
| 1502 this._backdropElement = document.createElement("iron-overlay-backdrop") |
| 1503 } |
| 1504 return this._backdropElement |
| 1505 }, |
| 1506 get deepActiveElement() { |
| 1507 var active = document.activeElement || document.body; |
| 1508 while (active.root && Polymer.dom(active.root).activeElement) { |
| 1509 active = Polymer.dom(active.root).activeElement |
| 1510 } |
| 1511 return active |
| 1512 }, |
| 1513 _bringOverlayAtIndexToFront: function(i) { |
| 1514 var overlay = this._overlays[i]; |
| 1515 if (!overlay) { |
| 1516 return |
| 1517 } |
| 1518 var lastI = this._overlays.length - 1; |
| 1519 var currentOverlay = this._overlays[lastI]; |
| 1520 if (currentOverlay && |
| 1521 this._shouldBeBehindOverlay(overlay, currentOverlay)) { |
| 1522 lastI-- |
| 1523 } |
| 1524 if (i >= lastI) { |
| 1525 return |
| 1526 } |
| 1527 var minimumZ = Math.max(this.currentOverlayZ(), this._minimumZ); |
| 1528 if (this._getZ(overlay) <= minimumZ) { |
| 1529 this._applyOverlayZ(overlay, minimumZ) |
| 1530 } |
| 1531 while (i < lastI) { |
| 1532 this._overlays[i] = this._overlays[i + 1]; |
| 1533 i++ |
| 1534 } |
| 1535 this._overlays[lastI] = overlay |
| 1536 }, |
| 1537 addOrRemoveOverlay: function(overlay) { |
| 1538 if (overlay.opened) { |
| 1539 this.addOverlay(overlay) |
| 1540 } else { |
| 1541 this.removeOverlay(overlay) |
| 1542 } |
| 1543 }, |
| 1544 addOverlay: function(overlay) { |
| 1545 var i = this._overlays.indexOf(overlay); |
| 1546 if (i >= 0) { |
| 1547 this._bringOverlayAtIndexToFront(i); |
| 1548 this.trackBackdrop(); |
| 1549 return |
| 1550 } |
| 1551 var insertionIndex = this._overlays.length; |
| 1552 var currentOverlay = this._overlays[insertionIndex - 1]; |
| 1553 var minimumZ = Math.max(this._getZ(currentOverlay), this._minimumZ); |
| 1554 var newZ = this._getZ(overlay); |
| 1555 if (currentOverlay && |
| 1556 this._shouldBeBehindOverlay(overlay, currentOverlay)) { |
| 1557 this._applyOverlayZ(currentOverlay, minimumZ); |
| 1558 insertionIndex--; |
| 1559 var previousOverlay = this._overlays[insertionIndex - 1]; |
| 1560 minimumZ = Math.max(this._getZ(previousOverlay), this._minimumZ) |
| 1561 } |
| 1562 if (newZ <= minimumZ) { |
| 1563 this._applyOverlayZ(overlay, minimumZ) |
| 1564 } |
| 1565 this._overlays.splice(insertionIndex, 0, overlay); |
| 1566 this.trackBackdrop() |
| 1567 }, |
| 1568 removeOverlay: function(overlay) { |
| 1569 var i = this._overlays.indexOf(overlay); |
| 1570 if (i === -1) { |
| 1571 return |
| 1572 } |
| 1573 this._overlays.splice(i, 1); |
| 1574 this.trackBackdrop() |
| 1575 }, |
| 1576 currentOverlay: function() { |
| 1577 var i = this._overlays.length - 1; |
| 1578 return this._overlays[i] |
| 1579 }, |
| 1580 currentOverlayZ: function() { |
| 1581 return this._getZ(this.currentOverlay()) |
| 1582 }, |
| 1583 ensureMinimumZ: function(minimumZ) { |
| 1584 this._minimumZ = Math.max(this._minimumZ, minimumZ) |
| 1585 }, |
| 1586 focusOverlay: function() { |
| 1587 var current = this.currentOverlay(); |
| 1588 if (current) { |
| 1589 current._applyFocus() |
| 1590 } |
| 1591 }, |
| 1592 trackBackdrop: function() { |
| 1593 var overlay = this._overlayWithBackdrop(); |
| 1594 if (!overlay && !this._backdropElement) { |
| 1595 return |
| 1596 } |
| 1597 this.backdropElement.style.zIndex = this._getZ(overlay) - 1; |
| 1598 this.backdropElement.opened = !!overlay |
| 1599 }, |
| 1600 getBackdrops: function() { |
| 1601 var backdrops = []; |
| 1602 for (var i = 0; i < this._overlays.length; i++) { |
| 1603 if (this._overlays[i].withBackdrop) { |
| 1604 backdrops.push(this._overlays[i]) |
| 1605 } |
| 1606 } |
| 1607 return backdrops |
| 1608 }, |
| 1609 backdropZ: function() { |
| 1610 return this._getZ(this._overlayWithBackdrop()) - 1 |
| 1611 }, |
| 1612 _overlayWithBackdrop: function() { |
| 1613 for (var i = 0; i < this._overlays.length; i++) { |
| 1614 if (this._overlays[i].withBackdrop) { |
| 1615 return this._overlays[i] |
| 1616 } |
| 1617 } |
| 1618 }, |
| 1619 _getZ: function(overlay) { |
| 1620 var z = this._minimumZ; |
| 1621 if (overlay) { |
| 1622 var z1 = Number( |
| 1623 overlay.style.zIndex || window.getComputedStyle(overlay).zIndex); |
| 1624 if (z1 === z1) { |
| 1625 z = z1 |
| 1626 } |
| 1627 } |
| 1628 return z |
| 1629 }, |
| 1630 _setZ: function(element, z) { |
| 1631 element.style.zIndex = z |
| 1632 }, |
| 1633 _applyOverlayZ: function(overlay, aboveZ) { |
| 1634 this._setZ(overlay, aboveZ + 2) |
| 1635 }, |
| 1636 _overlayInPath: function(path) { |
| 1637 path = path || []; |
| 1638 for (var i = 0; i < path.length; i++) { |
| 1639 if (path[i]._manager === this) { |
| 1640 return path[i] |
| 1641 } |
| 1642 } |
| 1643 }, |
| 1644 _onCaptureClick: function(event) { |
| 1645 var overlay = this.currentOverlay(); |
| 1646 if (overlay && this._overlayInPath(Polymer.dom(event).path) !== overlay) { |
| 1647 overlay._onCaptureClick(event) |
| 1648 } |
| 1649 }, |
| 1650 _onCaptureFocus: function(event) { |
| 1651 var overlay = this.currentOverlay(); |
| 1652 if (overlay) { |
| 1653 overlay._onCaptureFocus(event) |
| 1654 } |
| 1655 }, |
| 1656 _onCaptureKeyDown: function(event) { |
| 1657 var overlay = this.currentOverlay(); |
| 1658 if (overlay) { |
| 1659 if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(event, "esc")) { |
| 1660 overlay._onCaptureEsc(event) |
| 1661 } else if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys( |
| 1662 event, "tab")) { |
| 1663 overlay._onCaptureTab(event) |
| 1664 } |
| 1665 } |
| 1666 }, |
| 1667 _shouldBeBehindOverlay: function(overlay1, overlay2) { |
| 1668 return !overlay1.alwaysOnTop && overlay2.alwaysOnTop |
| 1669 } |
| 1670 }; |
| 1671 Polymer.IronOverlayManager = new Polymer.IronOverlayManagerClass; |
| 1672 (function() { |
| 1673 "use strict"; |
| 1674 Polymer.IronOverlayBehaviorImpl = { |
| 1675 properties: { |
| 1676 opened: { |
| 1677 observer: "_openedChanged", |
| 1678 type: Boolean, |
| 1679 value: false, |
| 1680 notify: true |
| 1681 }, |
| 1682 canceled: { |
| 1683 observer: "_canceledChanged", |
| 1684 readOnly: true, |
| 1685 type: Boolean, |
| 1686 value: false |
| 1687 }, |
| 1688 withBackdrop: {observer: "_withBackdropChanged", type: Boolean}, |
| 1689 noAutoFocus: {type: Boolean, value: false}, |
| 1690 noCancelOnEscKey: {type: Boolean, value: false}, |
| 1691 noCancelOnOutsideClick: {type: Boolean, value: false}, |
| 1692 closingReason: {type: Object}, |
| 1693 restoreFocusOnClose: {type: Boolean, value: false}, |
| 1694 alwaysOnTop: {type: Boolean}, |
| 1695 _manager: {type: Object, value: Polymer.IronOverlayManager}, |
| 1696 _focusedChild: {type: Object} |
| 1697 }, |
| 1698 listeners: {"iron-resize": "_onIronResize"}, |
| 1699 get backdropElement() { |
| 1700 return this._manager.backdropElement |
| 1701 }, |
| 1702 get _focusNode() { |
| 1703 return this._focusedChild || |
| 1704 Polymer.dom(this).querySelector("[autofocus]") || this |
| 1705 }, |
| 1706 get _focusableNodes() { |
| 1707 var FOCUSABLE_WITH_DISABLED = [ |
| 1708 "a[href]", "area[href]", "iframe", "[tabindex]", |
| 1709 "[contentEditable=true]" |
| 1710 ]; |
| 1711 var FOCUSABLE_WITHOUT_DISABLED = |
| 1712 ["input", "select", "textarea", "button"]; |
| 1713 var selector = FOCUSABLE_WITH_DISABLED.join(':not([tabindex="-1"]),') + |
| 1714 ':not([tabindex="-1"]),' + |
| 1715 FOCUSABLE_WITHOUT_DISABLED.join( |
| 1716 ':not([disabled]):not([tabindex="-1"]),') + |
| 1717 ':not([disabled]):not([tabindex="-1"])'; |
| 1718 var focusables = Polymer.dom(this).querySelectorAll(selector); |
| 1719 if (this.tabIndex >= 0) { |
| 1720 focusables.splice(0, 0, this) |
| 1721 } |
| 1722 return focusables.sort(function(a, b) { |
| 1723 if (a.tabIndex === b.tabIndex) { |
| 1724 return 0 |
| 1725 } |
| 1726 if (a.tabIndex === 0 || a.tabIndex > b.tabIndex) { |
| 1727 return 1 |
| 1728 } |
| 1729 return -1 |
| 1730 }) |
| 1731 }, |
| 1732 ready: function() { |
| 1733 this.__isAnimating = false; |
| 1734 this.__shouldRemoveTabIndex = false; |
| 1735 this.__firstFocusableNode = this.__lastFocusableNode = null; |
| 1736 this.__raf = null; |
| 1737 this.__restoreFocusNode = null; |
| 1738 this._ensureSetup() |
| 1739 }, |
| 1740 attached: function() { |
| 1741 if (this.opened) { |
| 1742 this._openedChanged(this.opened) |
| 1743 } |
| 1744 this._observer = Polymer.dom(this).observeNodes(this._onNodesChange) |
| 1745 }, |
| 1746 detached: function() { |
| 1747 Polymer.dom(this).unobserveNodes(this._observer); |
| 1748 this._observer = null; |
| 1749 if (this.__raf) { |
| 1750 window.cancelAnimationFrame(this.__raf); |
| 1751 this.__raf = null |
| 1752 } |
| 1753 this._manager.removeOverlay(this) |
| 1754 }, |
| 1755 toggle: function() { |
| 1756 this._setCanceled(false); |
| 1757 this.opened = !this.opened |
| 1758 }, |
| 1759 open: function() { |
| 1760 this._setCanceled(false); |
| 1761 this.opened = true |
| 1762 }, |
| 1763 close: function() { |
| 1764 this._setCanceled(false); |
| 1765 this.opened = false |
| 1766 }, |
| 1767 cancel: function(event) { |
| 1768 var cancelEvent = |
| 1769 this.fire("iron-overlay-canceled", event, {cancelable: true}); |
| 1770 if (cancelEvent.defaultPrevented) { |
| 1771 return |
| 1772 } |
| 1773 this._setCanceled(true); |
| 1774 this.opened = false |
| 1775 }, |
| 1776 _ensureSetup: function() { |
| 1777 if (this._overlaySetup) { |
| 1778 return |
| 1779 } |
| 1780 this._overlaySetup = true; |
| 1781 this.style.outline = "none"; |
| 1782 this.style.display = "none" |
| 1783 }, |
| 1784 _openedChanged: function(opened) { |
| 1785 if (opened) { |
| 1786 this.removeAttribute("aria-hidden") |
| 1787 } else { |
| 1788 this.setAttribute("aria-hidden", "true") |
| 1789 } |
| 1790 if (!this.isAttached) { |
| 1791 return |
| 1792 } |
| 1793 this.__isAnimating = true; |
| 1794 this.__onNextAnimationFrame(this.__openedChanged) |
| 1795 }, |
| 1796 _canceledChanged: function() { |
| 1797 this.closingReason = this.closingReason || {}; |
| 1798 this.closingReason.canceled = this.canceled |
| 1799 }, |
| 1800 _withBackdropChanged: function() { |
| 1801 if (this.withBackdrop && !this.hasAttribute("tabindex")) { |
| 1802 this.setAttribute("tabindex", "-1"); |
| 1803 this.__shouldRemoveTabIndex = true |
| 1804 } else if (this.__shouldRemoveTabIndex) { |
| 1805 this.removeAttribute("tabindex"); |
| 1806 this.__shouldRemoveTabIndex = false |
| 1807 } |
| 1808 if (this.opened && this.isAttached) { |
| 1809 this._manager.trackBackdrop() |
| 1810 } |
| 1811 }, |
| 1812 _prepareRenderOpened: function() { |
| 1813 this.__restoreFocusNode = this._manager.deepActiveElement; |
| 1814 this._preparePositioning(); |
| 1815 this.refit(); |
| 1816 this._finishPositioning(); |
| 1817 if (this.noAutoFocus && document.activeElement === this._focusNode) { |
| 1818 this._focusNode.blur(); |
| 1819 this.__restoreFocusNode.focus() |
| 1820 } |
| 1821 }, |
| 1822 _renderOpened: function() { |
| 1823 this._finishRenderOpened() |
| 1824 }, |
| 1825 _renderClosed: function() { |
| 1826 this._finishRenderClosed() |
| 1827 }, |
| 1828 _finishRenderOpened: function() { |
| 1829 this.notifyResize(); |
| 1830 this.__isAnimating = false; |
| 1831 var focusableNodes = this._focusableNodes; |
| 1832 this.__firstFocusableNode = focusableNodes[0]; |
| 1833 this.__lastFocusableNode = focusableNodes[focusableNodes.length - 1]; |
| 1834 this.fire("iron-overlay-opened") |
| 1835 }, |
| 1836 _finishRenderClosed: function() { |
| 1837 this.style.display = "none"; |
| 1838 this.style.zIndex = ""; |
| 1839 this.notifyResize(); |
| 1840 this.__isAnimating = false; |
| 1841 this.fire("iron-overlay-closed", this.closingReason) |
| 1842 }, |
| 1843 _preparePositioning: function() { |
| 1844 this.style.transition = this.style.webkitTransition = "none"; |
| 1845 this.style.transform = this.style.webkitTransform = "none"; |
| 1846 this.style.display = "" |
| 1847 }, |
| 1848 _finishPositioning: function() { |
| 1849 this.style.display = "none"; |
| 1850 this.scrollTop = this.scrollTop; |
| 1851 this.style.transition = this.style.webkitTransition = ""; |
| 1852 this.style.transform = this.style.webkitTransform = ""; |
| 1853 this.style.display = ""; |
| 1854 this.scrollTop = this.scrollTop |
| 1855 }, |
| 1856 _applyFocus: function() { |
| 1857 if (this.opened) { |
| 1858 if (!this.noAutoFocus) { |
| 1859 this._focusNode.focus() |
| 1860 } |
| 1861 } else { |
| 1862 this._focusNode.blur(); |
| 1863 this._focusedChild = null; |
| 1864 if (this.restoreFocusOnClose && this.__restoreFocusNode) { |
| 1865 this.__restoreFocusNode.focus() |
| 1866 } |
| 1867 this.__restoreFocusNode = null; |
| 1868 var currentOverlay = this._manager.currentOverlay(); |
| 1869 if (currentOverlay && this !== currentOverlay) { |
| 1870 currentOverlay._applyFocus() |
| 1871 } |
| 1872 } |
| 1873 }, |
| 1874 _onCaptureClick: function(event) { |
| 1875 if (!this.noCancelOnOutsideClick) { |
| 1876 this.cancel(event) |
| 1877 } |
| 1878 }, |
| 1879 _onCaptureFocus: function(event) { |
| 1880 if (!this.withBackdrop) { |
| 1881 return |
| 1882 } |
| 1883 var path = Polymer.dom(event).path; |
| 1884 if (path.indexOf(this) === -1) { |
| 1885 event.stopPropagation(); |
| 1886 this._applyFocus() |
| 1887 } else { |
| 1888 this._focusedChild = path[0] |
| 1889 } |
| 1890 }, |
| 1891 _onCaptureEsc: function(event) { |
| 1892 if (!this.noCancelOnEscKey) { |
| 1893 this.cancel(event) |
| 1894 } |
| 1895 }, |
| 1896 _onCaptureTab: function(event) { |
| 1897 if (!this.withBackdrop) { |
| 1898 return |
| 1899 } |
| 1900 var shift = event.shiftKey; |
| 1901 var nodeToCheck = |
| 1902 shift ? this.__firstFocusableNode : this.__lastFocusableNode; |
| 1903 var nodeToSet = |
| 1904 shift ? this.__lastFocusableNode : this.__firstFocusableNode; |
| 1905 var shouldWrap = false; |
| 1906 if (nodeToCheck === nodeToSet) { |
| 1907 shouldWrap = true |
| 1908 } else { |
| 1909 var focusedNode = this._manager.deepActiveElement; |
| 1910 shouldWrap = focusedNode === nodeToCheck || focusedNode === this |
| 1911 } |
| 1912 if (shouldWrap) { |
| 1913 event.preventDefault(); |
| 1914 this._focusedChild = nodeToSet; |
| 1915 this._applyFocus() |
| 1916 } |
| 1917 }, |
| 1918 _onIronResize: function() { |
| 1919 if (this.opened && !this.__isAnimating) { |
| 1920 this.__onNextAnimationFrame(this.refit) |
| 1921 } |
| 1922 }, |
| 1923 _onNodesChange: function() { |
| 1924 if (this.opened && !this.__isAnimating) { |
| 1925 this.notifyResize() |
| 1926 } |
| 1927 }, |
| 1928 __openedChanged: function() { |
| 1929 if (this.opened) { |
| 1930 this._prepareRenderOpened(); |
| 1931 this._manager.addOverlay(this); |
| 1932 this._applyFocus(); |
| 1933 this._renderOpened() |
| 1934 } else { |
| 1935 this._manager.removeOverlay(this); |
| 1936 this._applyFocus(); |
| 1937 this._renderClosed() |
| 1938 } |
| 1939 }, |
| 1940 __onNextAnimationFrame: function(callback) { |
| 1941 if (this.__raf) { |
| 1942 window.cancelAnimationFrame(this.__raf) |
| 1943 } |
| 1944 var self = this; |
| 1945 this.__raf = window.requestAnimationFrame(function nextAnimationFrame() { |
| 1946 self.__raf = null; |
| 1947 callback.call(self) |
| 1948 }) |
| 1949 } |
| 1950 }; |
| 1951 Polymer.IronOverlayBehavior = [ |
| 1952 Polymer.IronFitBehavior, Polymer.IronResizableBehavior, |
| 1953 Polymer.IronOverlayBehaviorImpl |
| 1954 ] |
| 1955 })(); |
| 1956 Polymer.NeonAnimatableBehavior = { |
| 1957 properties: { |
| 1958 animationConfig: {type: Object}, |
| 1959 entryAnimation: {observer: "_entryAnimationChanged", type: String}, |
| 1960 exitAnimation: {observer: "_exitAnimationChanged", type: String} |
| 1961 }, |
| 1962 _entryAnimationChanged: function() { |
| 1963 this.animationConfig = this.animationConfig || {}; |
| 1964 this.animationConfig["entry"] = [{name: this.entryAnimation, node: this}] |
| 1965 }, |
| 1966 _exitAnimationChanged: function() { |
| 1967 this.animationConfig = this.animationConfig || {}; |
| 1968 this.animationConfig["exit"] = [{name: this.exitAnimation, node: this}] |
| 1969 }, |
| 1970 _copyProperties: function(config1, config2) { |
| 1971 for (var property in config2) { |
| 1972 config1[property] = config2[property] |
| 1973 } |
| 1974 }, |
| 1975 _cloneConfig: function(config) { |
| 1976 var clone = {isClone: true}; |
| 1977 this._copyProperties(clone, config); |
| 1978 return clone |
| 1979 }, |
| 1980 _getAnimationConfigRecursive: function(type, map, allConfigs) { |
| 1981 if (!this.animationConfig) { |
| 1982 return |
| 1983 } |
| 1984 if (this.animationConfig.value && |
| 1985 typeof this.animationConfig.value === "function") { |
| 1986 this._warn(this._logf( |
| 1987 "playAnimation", |
| 1988 "Please put 'animationConfig' inside of your components 'properties' o
bject instead of outside of it.")); |
| 1989 return |
| 1990 } |
| 1991 var thisConfig; |
| 1992 if (type) { |
| 1993 thisConfig = this.animationConfig[type] |
| 1994 } else { |
| 1995 thisConfig = this.animationConfig |
| 1996 } |
| 1997 if (!Array.isArray(thisConfig)) { |
| 1998 thisConfig = [thisConfig] |
| 1999 } |
| 2000 if (thisConfig) { |
| 2001 for (var config, index = 0; config = thisConfig[index]; index++) { |
| 2002 if (config.animatable) { |
| 2003 config.animatable._getAnimationConfigRecursive( |
| 2004 config.type || type, map, allConfigs) |
| 2005 } else { |
| 2006 if (config.id) { |
| 2007 var cachedConfig = map[config.id]; |
| 2008 if (cachedConfig) { |
| 2009 if (!cachedConfig.isClone) { |
| 2010 map[config.id] = this._cloneConfig(cachedConfig); |
| 2011 cachedConfig = map[config.id] |
| 2012 } |
| 2013 this._copyProperties(cachedConfig, config) |
| 2014 } else { |
| 2015 map[config.id] = config |
| 2016 } |
| 2017 } else { |
| 2018 allConfigs.push(config) |
| 2019 } |
| 2020 } |
| 2021 } |
| 2022 } |
| 2023 }, |
| 2024 getAnimationConfig: function(type) { |
| 2025 var map = {}; |
| 2026 var allConfigs = []; |
| 2027 this._getAnimationConfigRecursive(type, map, allConfigs); |
| 2028 for (var key in map) { |
| 2029 allConfigs.push(map[key]) |
| 2030 } |
| 2031 return allConfigs |
| 2032 } |
| 2033 }; |
| 2034 Polymer.NeonAnimationRunnerBehaviorImpl = { |
| 2035 _configureAnimations: function(configs) { |
| 2036 var results = []; |
| 2037 if (configs.length > 0) { |
| 2038 for (var config, index = 0; config = configs[index]; index++) { |
| 2039 var neonAnimation = document.createElement(config.name); |
| 2040 if (neonAnimation.isNeonAnimation) { |
| 2041 var result = null; |
| 2042 try { |
| 2043 result = neonAnimation.configure(config); |
| 2044 if (typeof result.cancel != "function") { |
| 2045 result = document.timeline.play(result) |
| 2046 } |
| 2047 } catch (e) { |
| 2048 result = null; |
| 2049 console.warn("Couldnt play", "(", config.name, ").", e) |
| 2050 } |
| 2051 if (result) { |
| 2052 results.push({ |
| 2053 neonAnimation: neonAnimation, |
| 2054 config: config, |
| 2055 animation: result |
| 2056 }) |
| 2057 } |
| 2058 } else { |
| 2059 console.warn(this.is + ":", config.name, "not found!") |
| 2060 } |
| 2061 } |
| 2062 } |
| 2063 return results |
| 2064 }, |
| 2065 _shouldComplete: function(activeEntries) { |
| 2066 var finished = true; |
| 2067 for (var i = 0; i < activeEntries.length; i++) { |
| 2068 if (activeEntries[i].animation.playState != "finished") { |
| 2069 finished = false; |
| 2070 break |
| 2071 } |
| 2072 } |
| 2073 return finished |
| 2074 }, |
| 2075 _complete: function(activeEntries) { |
| 2076 for (var i = 0; i < activeEntries.length; i++) { |
| 2077 activeEntries[i].neonAnimation.complete(activeEntries[i].config) |
| 2078 } |
| 2079 for (var i = 0; i < activeEntries.length; i++) { |
| 2080 activeEntries[i].animation.cancel() |
| 2081 } |
| 2082 }, |
| 2083 playAnimation: function(type, cookie) { |
| 2084 var configs = this.getAnimationConfig(type); |
| 2085 if (!configs) { |
| 2086 return |
| 2087 } |
| 2088 this._active = this._active || {}; |
| 2089 if (this._active[type]) { |
| 2090 this._complete(this._active[type]); |
| 2091 delete this._active[type] |
| 2092 } |
| 2093 var activeEntries = this._configureAnimations(configs); |
| 2094 if (activeEntries.length == 0) { |
| 2095 this.fire("neon-animation-finish", cookie, {bubbles: false}); |
| 2096 return |
| 2097 } |
| 2098 this._active[type] = activeEntries; |
| 2099 for (var i = 0; i < activeEntries.length; i++) { |
| 2100 activeEntries[i].animation.onfinish = function() { |
| 2101 if (this._shouldComplete(activeEntries)) { |
| 2102 this._complete(activeEntries); |
| 2103 delete this._active[type]; |
| 2104 this.fire("neon-animation-finish", cookie, {bubbles: false}) |
| 2105 } |
| 2106 }.bind(this) |
| 2107 } |
| 2108 }, |
| 2109 cancelAnimation: function() { |
| 2110 for (var k in this._animations) { |
| 2111 this._animations[k].cancel() |
| 2112 } |
| 2113 this._animations = {} |
| 2114 } |
| 2115 }; |
| 2116 Polymer.NeonAnimationRunnerBehavior = |
| 2117 [Polymer.NeonAnimatableBehavior, Polymer.NeonAnimationRunnerBehaviorImpl]; |
| 2118 Polymer.NeonAnimationBehavior = { |
| 2119 properties: { |
| 2120 animationTiming: { |
| 2121 type: Object, |
| 2122 value: function() { |
| 2123 return { |
| 2124 duration: 500, easing: "cubic-bezier(0.4, 0, 0.2, 1)", fill: "both" |
| 2125 } |
| 2126 } |
| 2127 } |
| 2128 }, |
| 2129 isNeonAnimation: true, |
| 2130 timingFromConfig: function(config) { |
| 2131 if (config.timing) { |
| 2132 for (var property in config.timing) { |
| 2133 this.animationTiming[property] = config.timing[property] |
| 2134 } |
| 2135 } |
| 2136 return this.animationTiming |
| 2137 }, |
| 2138 setPrefixedProperty: function(node, property, value) { |
| 2139 var map = { |
| 2140 transform: ["webkitTransform"], |
| 2141 transformOrigin: ["mozTransformOrigin", "webkitTransformOrigin"] |
| 2142 }; |
| 2143 var prefixes = map[property]; |
| 2144 for (var prefix, index = 0; prefix = prefixes[index]; index++) { |
| 2145 node.style[prefix] = value |
| 2146 } |
| 2147 node.style[property] = value |
| 2148 }, |
| 2149 complete: function() {} |
| 2150 }; |
| 2151 Polymer({ |
| 2152 is: "opaque-animation", |
| 2153 behaviors: [Polymer.NeonAnimationBehavior], |
| 2154 configure: function(config) { |
| 2155 var node = config.node; |
| 2156 this._effect = new KeyframeEffect( |
| 2157 node, [{opacity: "1"}, {opacity: "1"}], this.timingFromConfig(config)); |
| 2158 node.style.opacity = "0"; |
| 2159 return this._effect |
| 2160 }, |
| 2161 complete: function(config) { |
| 2162 config.node.style.opacity = "" |
| 2163 } |
| 2164 }); |
| 2165 (function() { |
| 2166 "use strict"; |
| 2167 var LAST_TOUCH_POSITION = {pageX: 0, pageY: 0}; |
| 2168 var ROOT_TARGET = null; |
| 2169 var SCROLLABLE_NODES = []; |
| 2170 Polymer.IronDropdownScrollManager = { |
| 2171 get currentLockingElement() { |
| 2172 return this._lockingElements[this._lockingElements.length - 1] |
| 2173 }, |
| 2174 elementIsScrollLocked: function(element) { |
| 2175 var currentLockingElement = this.currentLockingElement; |
| 2176 if (currentLockingElement === undefined) |
| 2177 return false; |
| 2178 var scrollLocked; |
| 2179 if (this._hasCachedLockedElement(element)) { |
| 2180 return true |
| 2181 } |
| 2182 if (this._hasCachedUnlockedElement(element)) { |
| 2183 return false |
| 2184 } |
| 2185 scrollLocked = !!currentLockingElement && |
| 2186 currentLockingElement !== element && |
| 2187 !this._composedTreeContains(currentLockingElement, element); |
| 2188 if (scrollLocked) { |
| 2189 this._lockedElementCache.push(element) |
| 2190 } else { |
| 2191 this._unlockedElementCache.push(element) |
| 2192 } |
| 2193 return scrollLocked |
| 2194 }, |
| 2195 pushScrollLock: function(element) { |
| 2196 if (this._lockingElements.indexOf(element) >= 0) { |
| 2197 return |
| 2198 } |
| 2199 if (this._lockingElements.length === 0) { |
| 2200 this._lockScrollInteractions() |
| 2201 } |
| 2202 this._lockingElements.push(element); |
| 2203 this._lockedElementCache = []; |
| 2204 this._unlockedElementCache = [] |
| 2205 }, |
| 2206 removeScrollLock: function(element) { |
| 2207 var index = this._lockingElements.indexOf(element); |
| 2208 if (index === -1) { |
| 2209 return |
| 2210 } |
| 2211 this._lockingElements.splice(index, 1); |
| 2212 this._lockedElementCache = []; |
| 2213 this._unlockedElementCache = []; |
| 2214 if (this._lockingElements.length === 0) { |
| 2215 this._unlockScrollInteractions() |
| 2216 } |
| 2217 }, |
| 2218 _lockingElements: [], |
| 2219 _lockedElementCache: null, |
| 2220 _unlockedElementCache: null, |
| 2221 _hasCachedLockedElement: function(element) { |
| 2222 return this._lockedElementCache.indexOf(element) > -1 |
| 2223 }, |
| 2224 _hasCachedUnlockedElement: function(element) { |
| 2225 return this._unlockedElementCache.indexOf(element) > -1 |
| 2226 }, |
| 2227 _composedTreeContains: function(element, child) { |
| 2228 var contentElements; |
| 2229 var distributedNodes; |
| 2230 var contentIndex; |
| 2231 var nodeIndex; |
| 2232 if (element.contains(child)) { |
| 2233 return true |
| 2234 } |
| 2235 contentElements = Polymer.dom(element).querySelectorAll("content"); |
| 2236 for (contentIndex = 0; contentIndex < contentElements.length; |
| 2237 ++contentIndex) { |
| 2238 distributedNodes = |
| 2239 Polymer.dom(contentElements[contentIndex]).getDistributedNodes(); |
| 2240 for (nodeIndex = 0; nodeIndex < distributedNodes.length; ++nodeIndex) { |
| 2241 if (this._composedTreeContains(distributedNodes[nodeIndex], child)) { |
| 2242 return true |
| 2243 } |
| 2244 } |
| 2245 } |
| 2246 return false |
| 2247 }, |
| 2248 _scrollInteractionHandler: function(event) { |
| 2249 if (event.cancelable && this._shouldPreventScrolling(event)) { |
| 2250 event.preventDefault() |
| 2251 } |
| 2252 if (event.targetTouches) { |
| 2253 var touch = event.targetTouches[0]; |
| 2254 LAST_TOUCH_POSITION.pageX = touch.pageX; |
| 2255 LAST_TOUCH_POSITION.pageY = touch.pageY |
| 2256 } |
| 2257 }, |
| 2258 _lockScrollInteractions: function() { |
| 2259 this._boundScrollHandler = |
| 2260 this._boundScrollHandler || this._scrollInteractionHandler.bind(this); |
| 2261 document.addEventListener("wheel", this._boundScrollHandler, true); |
| 2262 document.addEventListener("mousewheel", this._boundScrollHandler, true); |
| 2263 document.addEventListener( |
| 2264 "DOMMouseScroll", this._boundScrollHandler, true); |
| 2265 document.addEventListener("touchstart", this._boundScrollHandler, true); |
| 2266 document.addEventListener("touchmove", this._boundScrollHandler, true) |
| 2267 }, |
| 2268 _unlockScrollInteractions: function() { |
| 2269 document.removeEventListener("wheel", this._boundScrollHandler, true); |
| 2270 document.removeEventListener( |
| 2271 "mousewheel", this._boundScrollHandler, true); |
| 2272 document.removeEventListener( |
| 2273 "DOMMouseScroll", this._boundScrollHandler, true); |
| 2274 document.removeEventListener( |
| 2275 "touchstart", this._boundScrollHandler, true); |
| 2276 document.removeEventListener("touchmove", this._boundScrollHandler, true) |
| 2277 }, |
| 2278 _shouldPreventScrolling: function(event) { |
| 2279 var target = Polymer.dom(event).rootTarget; |
| 2280 if (event.type !== "touchmove" && ROOT_TARGET !== target) { |
| 2281 ROOT_TARGET = target; |
| 2282 SCROLLABLE_NODES = this._getScrollableNodes(Polymer.dom(event).path) |
| 2283 } |
| 2284 if (!SCROLLABLE_NODES.length) { |
| 2285 return true |
| 2286 } |
| 2287 if (event.type === "touchstart") { |
| 2288 return false |
| 2289 } |
| 2290 var info = this._getScrollInfo(event); |
| 2291 return !this._getScrollingNode(SCROLLABLE_NODES, info.deltaX, info.deltaY) |
| 2292 }, |
| 2293 _getScrollableNodes: function(nodes) { |
| 2294 var scrollables = []; |
| 2295 var lockingIndex = nodes.indexOf(this.currentLockingElement); |
| 2296 for (var i = 0; i <= lockingIndex; i++) { |
| 2297 var node = nodes[i]; |
| 2298 if (node.nodeType === 11) { |
| 2299 continue |
| 2300 } |
| 2301 var style = node.style; |
| 2302 if (style.overflow !== "scroll" && style.overflow !== "auto") { |
| 2303 style = window.getComputedStyle(node) |
| 2304 } |
| 2305 if (style.overflow === "scroll" || style.overflow === "auto") { |
| 2306 scrollables.push(node) |
| 2307 } |
| 2308 } |
| 2309 return scrollables |
| 2310 }, |
| 2311 _getScrollingNode: function(nodes, deltaX, deltaY) { |
| 2312 if (!deltaX && !deltaY) { |
| 2313 return |
| 2314 } |
| 2315 var verticalScroll = Math.abs(deltaY) >= Math.abs(deltaX); |
| 2316 for (var i = 0; i < nodes.length; i++) { |
| 2317 var node = nodes[i]; |
| 2318 var canScroll = false; |
| 2319 if (verticalScroll) { |
| 2320 canScroll = deltaY < 0 ? |
| 2321 node.scrollTop > 0 : |
| 2322 node.scrollTop < node.scrollHeight - node.clientHeight |
| 2323 } else { |
| 2324 canScroll = deltaX < 0 ? |
| 2325 node.scrollLeft > 0 : |
| 2326 node.scrollLeft < node.scrollWidth - node.clientWidth |
| 2327 } |
| 2328 if (canScroll) { |
| 2329 return node |
| 2330 } |
| 2331 } |
| 2332 }, |
| 2333 _getScrollInfo: function(event) { |
| 2334 var info = {deltaX: event.deltaX, deltaY: event.deltaY}; |
| 2335 if ("deltaX" in event) { |
| 2336 } else if ("wheelDeltaX" in event) { |
| 2337 info.deltaX = -event.wheelDeltaX; |
| 2338 info.deltaY = -event.wheelDeltaY |
| 2339 } else if ("axis" in event) { |
| 2340 info.deltaX = event.axis === 1 ? event.detail : 0; |
| 2341 info.deltaY = event.axis === 2 ? event.detail : 0 |
| 2342 } else if (event.targetTouches) { |
| 2343 var touch = event.targetTouches[0]; |
| 2344 info.deltaX = LAST_TOUCH_POSITION.pageX - touch.pageX; |
| 2345 info.deltaY = LAST_TOUCH_POSITION.pageY - touch.pageY |
| 2346 } |
| 2347 return info |
| 2348 } |
| 2349 } |
| 2350 })(); |
| 2351 (function() { |
| 2352 "use strict"; |
| 2353 Polymer({ |
| 2354 is: "iron-dropdown", |
| 2355 behaviors: [ |
| 2356 Polymer.IronControlState, Polymer.IronA11yKeysBehavior, |
| 2357 Polymer.IronOverlayBehavior, Polymer.NeonAnimationRunnerBehavior |
| 2358 ], |
| 2359 properties: { |
| 2360 horizontalAlign: {type: String, value: "left", reflectToAttribute: true}, |
| 2361 verticalAlign: {type: String, value: "top", reflectToAttribute: true}, |
| 2362 openAnimationConfig: {type: Object}, |
| 2363 closeAnimationConfig: {type: Object}, |
| 2364 focusTarget: {type: Object}, |
| 2365 noAnimations: {type: Boolean, value: false}, |
| 2366 allowOutsideScroll: {type: Boolean, value: false}, |
| 2367 _boundOnCaptureScroll: { |
| 2368 type: Function, |
| 2369 value: function() { |
| 2370 return this._onCaptureScroll.bind(this) |
| 2371 } |
| 2372 } |
| 2373 }, |
| 2374 listeners: {"neon-animation-finish": "_onNeonAnimationFinish"}, |
| 2375 observers: [ |
| 2376 "_updateOverlayPosition(positionTarget, verticalAlign, horizontalAlign, ve
rticalOffset, horizontalOffset)" |
| 2377 ], |
| 2378 get containedElement() { |
| 2379 return Polymer.dom(this.$.content).getDistributedNodes()[0] |
| 2380 }, |
| 2381 get _focusTarget() { |
| 2382 return this.focusTarget || this.containedElement |
| 2383 }, |
| 2384 ready: function() { |
| 2385 this._scrollTop = 0; |
| 2386 this._scrollLeft = 0; |
| 2387 this._refitOnScrollRAF = null |
| 2388 }, |
| 2389 attached: function() { |
| 2390 if (!this.sizingTarget || this.sizingTarget === this) { |
| 2391 this.sizingTarget = this.containedElement |
| 2392 } |
| 2393 }, |
| 2394 detached: function() { |
| 2395 this.cancelAnimation(); |
| 2396 document.removeEventListener("scroll", this._boundOnCaptureScroll); |
| 2397 Polymer.IronDropdownScrollManager.removeScrollLock(this) |
| 2398 }, |
| 2399 _openedChanged: function() { |
| 2400 if (this.opened && this.disabled) { |
| 2401 this.cancel() |
| 2402 } else { |
| 2403 this.cancelAnimation(); |
| 2404 this._updateAnimationConfig(); |
| 2405 this._saveScrollPosition(); |
| 2406 if (this.opened) { |
| 2407 document.addEventListener("scroll", this._boundOnCaptureScroll); |
| 2408 !this.allowOutsideScroll && |
| 2409 Polymer.IronDropdownScrollManager.pushScrollLock(this) |
| 2410 } else { |
| 2411 document.removeEventListener("scroll", this._boundOnCaptureScroll); |
| 2412 Polymer.IronDropdownScrollManager.removeScrollLock(this) |
| 2413 } |
| 2414 Polymer.IronOverlayBehaviorImpl._openedChanged.apply(this, arguments) |
| 2415 } |
| 2416 }, |
| 2417 _renderOpened: function() { |
| 2418 if (!this.noAnimations && this.animationConfig.open) { |
| 2419 this.$.contentWrapper.classList.add("animating"); |
| 2420 this.playAnimation("open") |
| 2421 } else { |
| 2422 Polymer.IronOverlayBehaviorImpl._renderOpened.apply(this, arguments) |
| 2423 } |
| 2424 }, |
| 2425 _renderClosed: function() { |
| 2426 if (!this.noAnimations && this.animationConfig.close) { |
| 2427 this.$.contentWrapper.classList.add("animating"); |
| 2428 this.playAnimation("close") |
| 2429 } else { |
| 2430 Polymer.IronOverlayBehaviorImpl._renderClosed.apply(this, arguments) |
| 2431 } |
| 2432 }, |
| 2433 _onNeonAnimationFinish: function() { |
| 2434 this.$.contentWrapper.classList.remove("animating"); |
| 2435 if (this.opened) { |
| 2436 this._finishRenderOpened() |
| 2437 } else { |
| 2438 this._finishRenderClosed() |
| 2439 } |
| 2440 }, |
| 2441 _onCaptureScroll: function() { |
| 2442 if (!this.allowOutsideScroll) { |
| 2443 this._restoreScrollPosition() |
| 2444 } else { |
| 2445 this._refitOnScrollRAF && |
| 2446 window.cancelAnimationFrame(this._refitOnScrollRAF); |
| 2447 this._refitOnScrollRAF = |
| 2448 window.requestAnimationFrame(this.refit.bind(this)) |
| 2449 } |
| 2450 }, |
| 2451 _saveScrollPosition: function() { |
| 2452 if (document.scrollingElement) { |
| 2453 this._scrollTop = document.scrollingElement.scrollTop; |
| 2454 this._scrollLeft = document.scrollingElement.scrollLeft |
| 2455 } else { |
| 2456 this._scrollTop = Math.max( |
| 2457 document.documentElement.scrollTop, document.body.scrollTop); |
| 2458 this._scrollLeft = Math.max( |
| 2459 document.documentElement.scrollLeft, document.body.scrollLeft) |
| 2460 } |
| 2461 }, |
| 2462 _restoreScrollPosition: function() { |
| 2463 if (document.scrollingElement) { |
| 2464 document.scrollingElement.scrollTop = this._scrollTop; |
| 2465 document.scrollingElement.scrollLeft = this._scrollLeft |
| 2466 } else { |
| 2467 document.documentElement.scrollTop = this._scrollTop; |
| 2468 document.documentElement.scrollLeft = this._scrollLeft; |
| 2469 document.body.scrollTop = this._scrollTop; |
| 2470 document.body.scrollLeft = this._scrollLeft |
| 2471 } |
| 2472 }, |
| 2473 _updateAnimationConfig: function() { |
| 2474 var animations = (this.openAnimationConfig || |
| 2475 []).concat(this.closeAnimationConfig || []); |
| 2476 for (var i = 0; i < animations.length; i++) { |
| 2477 animations[i].node = this.containedElement |
| 2478 } |
| 2479 this.animationConfig = { |
| 2480 open: this.openAnimationConfig, |
| 2481 close: this.closeAnimationConfig |
| 2482 } |
| 2483 }, |
| 2484 _updateOverlayPosition: function() { |
| 2485 if (this.isAttached) { |
| 2486 this.notifyResize() |
| 2487 } |
| 2488 }, |
| 2489 _applyFocus: function() { |
| 2490 var focusTarget = this.focusTarget || this.containedElement; |
| 2491 if (focusTarget && this.opened && !this.noAutoFocus) { |
| 2492 focusTarget.focus() |
| 2493 } else { |
| 2494 Polymer.IronOverlayBehaviorImpl._applyFocus.apply(this, arguments) |
| 2495 } |
| 2496 } |
| 2497 }) |
| 2498 })(); |
| 2499 Polymer({ |
| 2500 is: "paper-tab", |
| 2501 behaviors: [ |
| 2502 Polymer.IronControlState, Polymer.IronButtonState, |
| 2503 Polymer.PaperRippleBehavior |
| 2504 ], |
| 2505 properties: {link: {type: Boolean, value: false, reflectToAttribute: true}}, |
| 2506 hostAttributes: {role: "tab"}, |
| 2507 listeners: {down: "_updateNoink", tap: "_onTap"}, |
| 2508 attached: function() { |
| 2509 this._updateNoink() |
| 2510 }, |
| 2511 get _parentNoink() { |
| 2512 var parent = Polymer.dom(this).parentNode; |
| 2513 return !!parent && !!parent.noink |
| 2514 }, |
| 2515 _updateNoink: function() { |
| 2516 this.noink = !!this.noink || !!this._parentNoink |
| 2517 }, |
| 2518 _onTap: function(event) { |
| 2519 if (this.link) { |
| 2520 var anchor = this.queryEffectiveChildren("a"); |
| 2521 if (!anchor) { |
| 2522 return |
| 2523 } |
| 2524 if (event.target === anchor) { |
| 2525 return |
| 2526 } |
| 2527 anchor.click() |
| 2528 } |
| 2529 } |
| 2530 }); |
| 2531 Polymer.IronMenuBehaviorImpl = { |
| 2532 properties: { |
| 2533 focusedItem: |
| 2534 {observer: "_focusedItemChanged", readOnly: true, type: Object}, |
| 2535 attrForItemTitle: {type: String} |
| 2536 }, |
| 2537 hostAttributes: {role: "menu", tabindex: "0"}, |
| 2538 observers: ["_updateMultiselectable(multi)"], |
| 2539 listeners: { |
| 2540 focus: "_onFocus", |
| 2541 keydown: "_onKeydown", |
| 2542 "iron-items-changed": "_onIronItemsChanged" |
| 2543 }, |
| 2544 keyBindings: { |
| 2545 up: "_onUpKey", |
| 2546 down: "_onDownKey", |
| 2547 esc: "_onEscKey", |
| 2548 "shift+tab:keydown": "_onShiftTabDown" |
| 2549 }, |
| 2550 attached: function() { |
| 2551 this._resetTabindices() |
| 2552 }, |
| 2553 select: function(value) { |
| 2554 if (this._defaultFocusAsync) { |
| 2555 this.cancelAsync(this._defaultFocusAsync); |
| 2556 this._defaultFocusAsync = null |
| 2557 } |
| 2558 var item = this._valueToItem(value); |
| 2559 if (item && item.hasAttribute("disabled")) |
| 2560 return; |
| 2561 this._setFocusedItem(item); |
| 2562 Polymer.IronMultiSelectableBehaviorImpl.select.apply(this, arguments) |
| 2563 }, |
| 2564 _resetTabindices: function() { |
| 2565 var selectedItem = this.multi ? |
| 2566 this.selectedItems && this.selectedItems[0] : |
| 2567 this.selectedItem; |
| 2568 this.items.forEach(function(item) { |
| 2569 item.setAttribute("tabindex", item === selectedItem ? "0" : "-1") |
| 2570 }, this) |
| 2571 }, |
| 2572 _updateMultiselectable: function(multi) { |
| 2573 if (multi) { |
| 2574 this.setAttribute("aria-multiselectable", "true") |
| 2575 } else { |
| 2576 this.removeAttribute("aria-multiselectable") |
| 2577 } |
| 2578 }, |
| 2579 _focusWithKeyboardEvent: function(event) { |
| 2580 for (var i = 0, item; item = this.items[i]; i++) { |
| 2581 var attr = this.attrForItemTitle || "textContent"; |
| 2582 var title = item[attr] || item.getAttribute(attr); |
| 2583 if (!item.hasAttribute("disabled") && title && |
| 2584 title.trim().charAt(0).toLowerCase() === |
| 2585 String.fromCharCode(event.keyCode).toLowerCase()) { |
| 2586 this._setFocusedItem(item); |
| 2587 break |
| 2588 } |
| 2589 } |
| 2590 }, |
| 2591 _focusPrevious: function() { |
| 2592 var length = this.items.length; |
| 2593 var curFocusIndex = Number(this.indexOf(this.focusedItem)); |
| 2594 for (var i = 1; i < length + 1; i++) { |
| 2595 var item = this.items[(curFocusIndex - i + length) % length]; |
| 2596 if (!item.hasAttribute("disabled")) { |
| 2597 var owner = Polymer.dom(item).getOwnerRoot() || document; |
| 2598 this._setFocusedItem(item); |
| 2599 if (Polymer.dom(owner).activeElement == item) { |
| 2600 return |
| 2601 } |
| 2602 } |
| 2603 } |
| 2604 }, |
| 2605 _focusNext: function() { |
| 2606 var length = this.items.length; |
| 2607 var curFocusIndex = Number(this.indexOf(this.focusedItem)); |
| 2608 for (var i = 1; i < length + 1; i++) { |
| 2609 var item = this.items[(curFocusIndex + i) % length]; |
| 2610 if (!item.hasAttribute("disabled")) { |
| 2611 var owner = Polymer.dom(item).getOwnerRoot() || document; |
| 2612 this._setFocusedItem(item); |
| 2613 if (Polymer.dom(owner).activeElement == item) { |
| 2614 return |
| 2615 } |
| 2616 } |
| 2617 } |
| 2618 }, |
| 2619 _applySelection: function(item, isSelected) { |
| 2620 if (isSelected) { |
| 2621 item.setAttribute("aria-selected", "true") |
| 2622 } else { |
| 2623 item.removeAttribute("aria-selected") |
| 2624 } |
| 2625 Polymer.IronSelectableBehavior._applySelection.apply(this, arguments) |
| 2626 }, |
| 2627 _focusedItemChanged: function(focusedItem, old) { |
| 2628 old && old.setAttribute("tabindex", "-1"); |
| 2629 if (focusedItem) { |
| 2630 focusedItem.setAttribute("tabindex", "0"); |
| 2631 focusedItem.focus() |
| 2632 } |
| 2633 }, |
| 2634 _onIronItemsChanged: function(event) { |
| 2635 if (event.detail.addedNodes.length) { |
| 2636 this._resetTabindices() |
| 2637 } |
| 2638 }, |
| 2639 _onShiftTabDown: function(event) { |
| 2640 var oldTabIndex = this.getAttribute("tabindex"); |
| 2641 Polymer.IronMenuBehaviorImpl._shiftTabPressed = true; |
| 2642 this._setFocusedItem(null); |
| 2643 this.setAttribute("tabindex", "-1"); |
| 2644 this.async(function() { |
| 2645 this.setAttribute("tabindex", oldTabIndex); |
| 2646 Polymer.IronMenuBehaviorImpl._shiftTabPressed = false |
| 2647 }, 1) |
| 2648 }, |
| 2649 _onFocus: function(event) { |
| 2650 if (Polymer.IronMenuBehaviorImpl._shiftTabPressed) { |
| 2651 return |
| 2652 } |
| 2653 var rootTarget = Polymer.dom(event).rootTarget; |
| 2654 if (rootTarget !== this && typeof rootTarget.tabIndex !== "undefined" && |
| 2655 !this.isLightDescendant(rootTarget)) { |
| 2656 return |
| 2657 } |
| 2658 this._defaultFocusAsync = this.async(function() { |
| 2659 var selectedItem = this.multi ? |
| 2660 this.selectedItems && this.selectedItems[0] : |
| 2661 this.selectedItem; |
| 2662 this._setFocusedItem(null); |
| 2663 if (selectedItem) { |
| 2664 this._setFocusedItem(selectedItem) |
| 2665 } else if (this.items[0]) { |
| 2666 this._focusNext() |
| 2667 } |
| 2668 }) |
| 2669 }, |
| 2670 _onUpKey: function(event) { |
| 2671 this._focusPrevious(); |
| 2672 event.detail.keyboardEvent.preventDefault() |
| 2673 }, |
| 2674 _onDownKey: function(event) { |
| 2675 this._focusNext(); |
| 2676 event.detail.keyboardEvent.preventDefault() |
| 2677 }, |
| 2678 _onEscKey: function(event) { |
| 2679 this.focusedItem.blur() |
| 2680 }, |
| 2681 _onKeydown: function(event) { |
| 2682 if (!this.keyboardEventMatchesKeys(event, "up down esc")) { |
| 2683 this._focusWithKeyboardEvent(event) |
| 2684 } |
| 2685 event.stopPropagation() |
| 2686 }, |
| 2687 _activateHandler: function(event) { |
| 2688 Polymer.IronSelectableBehavior._activateHandler.call(this, event); |
| 2689 event.stopPropagation() |
| 2690 } |
| 2691 }; |
| 2692 Polymer.IronMenuBehaviorImpl._shiftTabPressed = false; |
| 2693 Polymer.IronMenuBehavior = [ |
| 2694 Polymer.IronMultiSelectableBehavior, Polymer.IronA11yKeysBehavior, |
| 2695 Polymer.IronMenuBehaviorImpl |
| 2696 ]; |
| 2697 Polymer.IronMenubarBehaviorImpl = { |
| 2698 hostAttributes: {role: "menubar"}, |
| 2699 keyBindings: {left: "_onLeftKey", right: "_onRightKey"}, |
| 2700 _onUpKey: function(event) { |
| 2701 this.focusedItem.click(); |
| 2702 event.detail.keyboardEvent.preventDefault() |
| 2703 }, |
| 2704 _onDownKey: function(event) { |
| 2705 this.focusedItem.click(); |
| 2706 event.detail.keyboardEvent.preventDefault() |
| 2707 }, |
| 2708 get _isRTL() { |
| 2709 return window.getComputedStyle(this)["direction"] === "rtl" |
| 2710 }, |
| 2711 _onLeftKey: function(event) { |
| 2712 if (this._isRTL) { |
| 2713 this._focusNext() |
| 2714 } else { |
| 2715 this._focusPrevious() |
| 2716 } |
| 2717 event.detail.keyboardEvent.preventDefault() |
| 2718 }, |
| 2719 _onRightKey: function(event) { |
| 2720 if (this._isRTL) { |
| 2721 this._focusPrevious() |
| 2722 } else { |
| 2723 this._focusNext() |
| 2724 } |
| 2725 event.detail.keyboardEvent.preventDefault() |
| 2726 }, |
| 2727 _onKeydown: function(event) { |
| 2728 if (this.keyboardEventMatchesKeys(event, "up down left right esc")) { |
| 2729 return |
| 2730 } |
| 2731 this._focusWithKeyboardEvent(event) |
| 2732 } |
| 2733 }; |
| 2734 Polymer.IronMenubarBehavior = |
| 2735 [Polymer.IronMenuBehavior, Polymer.IronMenubarBehaviorImpl]; |
| 2736 Polymer({ |
| 2737 is: "paper-tabs", |
| 2738 behaviors: [Polymer.IronResizableBehavior, Polymer.IronMenubarBehavior], |
| 2739 properties: { |
| 2740 noink: {type: Boolean, value: false, observer: "_noinkChanged"}, |
| 2741 noBar: {type: Boolean, value: false}, |
| 2742 noSlide: {type: Boolean, value: false}, |
| 2743 scrollable: {type: Boolean, value: false}, |
| 2744 fitContainer: {type: Boolean, value: false}, |
| 2745 disableDrag: {type: Boolean, value: false}, |
| 2746 hideScrollButtons: {type: Boolean, value: false}, |
| 2747 alignBottom: {type: Boolean, value: false}, |
| 2748 selectable: {type: String, value: "paper-tab"}, |
| 2749 autoselect: {type: Boolean, value: false}, |
| 2750 autoselectDelay: {type: Number, value: 0}, |
| 2751 _step: {type: Number, value: 10}, |
| 2752 _holdDelay: {type: Number, value: 1}, |
| 2753 _leftHidden: {type: Boolean, value: false}, |
| 2754 _rightHidden: {type: Boolean, value: false}, |
| 2755 _previousTab: {type: Object} |
| 2756 }, |
| 2757 hostAttributes: {role: "tablist"}, |
| 2758 listeners: { |
| 2759 "iron-resize": "_onTabSizingChanged", |
| 2760 "iron-items-changed": "_onTabSizingChanged", |
| 2761 "iron-select": "_onIronSelect", |
| 2762 "iron-deselect": "_onIronDeselect" |
| 2763 }, |
| 2764 keyBindings: {"left:keyup right:keyup": "_onArrowKeyup"}, |
| 2765 created: function() { |
| 2766 this._holdJob = null; |
| 2767 this._pendingActivationItem = undefined; |
| 2768 this._pendingActivationTimeout = undefined; |
| 2769 this._bindDelayedActivationHandler = |
| 2770 this._delayedActivationHandler.bind(this); |
| 2771 this.addEventListener("blur", this._onBlurCapture.bind(this), true) |
| 2772 }, |
| 2773 ready: function() { |
| 2774 this.setScrollDirection("y", this.$.tabsContainer) |
| 2775 }, |
| 2776 detached: function() { |
| 2777 this._cancelPendingActivation() |
| 2778 }, |
| 2779 _noinkChanged: function(noink) { |
| 2780 var childTabs = Polymer.dom(this).querySelectorAll("paper-tab"); |
| 2781 childTabs.forEach( |
| 2782 noink ? this._setNoinkAttribute : this._removeNoinkAttribute) |
| 2783 }, |
| 2784 _setNoinkAttribute: function(element) { |
| 2785 element.setAttribute("noink", "") |
| 2786 }, |
| 2787 _removeNoinkAttribute: function(element) { |
| 2788 element.removeAttribute("noink") |
| 2789 }, |
| 2790 _computeScrollButtonClass: function( |
| 2791 hideThisButton, scrollable, hideScrollButtons) { |
| 2792 if (!scrollable || hideScrollButtons) { |
| 2793 return "hidden" |
| 2794 } |
| 2795 if (hideThisButton) { |
| 2796 return "not-visible" |
| 2797 } |
| 2798 return "" |
| 2799 }, |
| 2800 _computeTabsContentClass: function(scrollable, fitContainer) { |
| 2801 return scrollable ? "scrollable" + (fitContainer ? " fit-container" : "") : |
| 2802 " fit-container" |
| 2803 }, |
| 2804 _computeSelectionBarClass: function(noBar, alignBottom) { |
| 2805 if (noBar) { |
| 2806 return "hidden" |
| 2807 } else if (alignBottom) { |
| 2808 return "align-bottom" |
| 2809 } |
| 2810 return "" |
| 2811 }, |
| 2812 _onTabSizingChanged: function() { |
| 2813 this.debounce("_onTabSizingChanged", function() { |
| 2814 this._scroll(); |
| 2815 this._tabChanged(this.selectedItem) |
| 2816 }, 10) |
| 2817 }, |
| 2818 _onIronSelect: function(event) { |
| 2819 this._tabChanged(event.detail.item, this._previousTab); |
| 2820 this._previousTab = event.detail.item; |
| 2821 this.cancelDebouncer("tab-changed") |
| 2822 }, |
| 2823 _onIronDeselect: function(event) { |
| 2824 this.debounce("tab-changed", function() { |
| 2825 this._tabChanged(null, this._previousTab); |
| 2826 this._previousTab = null |
| 2827 }, 1) |
| 2828 }, |
| 2829 _activateHandler: function() { |
| 2830 this._cancelPendingActivation(); |
| 2831 Polymer.IronMenuBehaviorImpl._activateHandler.apply(this, arguments) |
| 2832 }, |
| 2833 _scheduleActivation: function(item, delay) { |
| 2834 this._pendingActivationItem = item; |
| 2835 this._pendingActivationTimeout = |
| 2836 this.async(this._bindDelayedActivationHandler, delay) |
| 2837 }, |
| 2838 _delayedActivationHandler: function() { |
| 2839 var item = this._pendingActivationItem; |
| 2840 this._pendingActivationItem = undefined; |
| 2841 this._pendingActivationTimeout = undefined; |
| 2842 item.fire(this.activateEvent, null, {bubbles: true, cancelable: true}) |
| 2843 }, |
| 2844 _cancelPendingActivation: function() { |
| 2845 if (this._pendingActivationTimeout !== undefined) { |
| 2846 this.cancelAsync(this._pendingActivationTimeout); |
| 2847 this._pendingActivationItem = undefined; |
| 2848 this._pendingActivationTimeout = undefined |
| 2849 } |
| 2850 }, |
| 2851 _onArrowKeyup: function(event) { |
| 2852 if (this.autoselect) { |
| 2853 this._scheduleActivation(this.focusedItem, this.autoselectDelay) |
| 2854 } |
| 2855 }, |
| 2856 _onBlurCapture: function(event) { |
| 2857 if (event.target === this._pendingActivationItem) { |
| 2858 this._cancelPendingActivation() |
| 2859 } |
| 2860 }, |
| 2861 get _tabContainerScrollSize() { |
| 2862 return Math.max( |
| 2863 0, this.$.tabsContainer.scrollWidth - this.$.tabsContainer.offsetWidth) |
| 2864 }, |
| 2865 _scroll: function(e, detail) { |
| 2866 if (!this.scrollable) { |
| 2867 return |
| 2868 } |
| 2869 var ddx = detail && -detail.ddx || 0; |
| 2870 this._affectScroll(ddx) |
| 2871 }, |
| 2872 _down: function(e) { |
| 2873 this.async(function() { |
| 2874 if (this._defaultFocusAsync) { |
| 2875 this.cancelAsync(this._defaultFocusAsync); |
| 2876 this._defaultFocusAsync = null |
| 2877 } |
| 2878 }, 1) |
| 2879 }, |
| 2880 _affectScroll: function(dx) { |
| 2881 this.$.tabsContainer.scrollLeft += dx; |
| 2882 var scrollLeft = this.$.tabsContainer.scrollLeft; |
| 2883 this._leftHidden = scrollLeft === 0; |
| 2884 this._rightHidden = scrollLeft === this._tabContainerScrollSize |
| 2885 }, |
| 2886 _onLeftScrollButtonDown: function() { |
| 2887 this._scrollToLeft(); |
| 2888 this._holdJob = setInterval(this._scrollToLeft.bind(this), this._holdDelay) |
| 2889 }, |
| 2890 _onRightScrollButtonDown: function() { |
| 2891 this._scrollToRight(); |
| 2892 this._holdJob = setInterval(this._scrollToRight.bind(this), this._holdDelay) |
| 2893 }, |
| 2894 _onScrollButtonUp: function() { |
| 2895 clearInterval(this._holdJob); |
| 2896 this._holdJob = null |
| 2897 }, |
| 2898 _scrollToLeft: function() { |
| 2899 this._affectScroll(-this._step) |
| 2900 }, |
| 2901 _scrollToRight: function() { |
| 2902 this._affectScroll(this._step) |
| 2903 }, |
| 2904 _tabChanged: function(tab, old) { |
| 2905 if (!tab) { |
| 2906 this.$.selectionBar.classList.remove("expand"); |
| 2907 this.$.selectionBar.classList.remove("contract"); |
| 2908 this._positionBar(0, 0); |
| 2909 return |
| 2910 } |
| 2911 var r = this.$.tabsContent.getBoundingClientRect(); |
| 2912 var w = r.width; |
| 2913 var tabRect = tab.getBoundingClientRect(); |
| 2914 var tabOffsetLeft = tabRect.left - r.left; |
| 2915 this._pos = { |
| 2916 width: this._calcPercent(tabRect.width, w), |
| 2917 left: this._calcPercent(tabOffsetLeft, w) |
| 2918 }; |
| 2919 if (this.noSlide || old == null) { |
| 2920 this.$.selectionBar.classList.remove("expand"); |
| 2921 this.$.selectionBar.classList.remove("contract"); |
| 2922 this._positionBar(this._pos.width, this._pos.left); |
| 2923 return |
| 2924 } |
| 2925 var oldRect = old.getBoundingClientRect(); |
| 2926 var oldIndex = this.items.indexOf(old); |
| 2927 var index = this.items.indexOf(tab); |
| 2928 var m = 5; |
| 2929 this.$.selectionBar.classList.add("expand"); |
| 2930 var moveRight = oldIndex < index; |
| 2931 var isRTL = this._isRTL; |
| 2932 if (isRTL) { |
| 2933 moveRight = !moveRight |
| 2934 } |
| 2935 if (moveRight) { |
| 2936 this._positionBar( |
| 2937 this._calcPercent(tabRect.left + tabRect.width - oldRect.left, w) - m, |
| 2938 this._left) |
| 2939 } else { |
| 2940 this._positionBar( |
| 2941 this._calcPercent(oldRect.left + oldRect.width - tabRect.left, w) - m, |
| 2942 this._calcPercent(tabOffsetLeft, w) + m) |
| 2943 } |
| 2944 if (this.scrollable) { |
| 2945 this._scrollToSelectedIfNeeded(tabRect.width, tabOffsetLeft) |
| 2946 } |
| 2947 }, |
| 2948 _scrollToSelectedIfNeeded: function(tabWidth, tabOffsetLeft) { |
| 2949 var l = tabOffsetLeft - this.$.tabsContainer.scrollLeft; |
| 2950 if (l < 0) { |
| 2951 this.$.tabsContainer.scrollLeft += l |
| 2952 } else { |
| 2953 l += tabWidth - this.$.tabsContainer.offsetWidth; |
| 2954 if (l > 0) { |
| 2955 this.$.tabsContainer.scrollLeft += l |
| 2956 } |
| 2957 } |
| 2958 }, |
| 2959 _calcPercent: function(w, w0) { |
| 2960 return 100 * w / w0 |
| 2961 }, |
| 2962 _positionBar: function(width, left) { |
| 2963 width = width || 0; |
| 2964 left = left || 0; |
| 2965 this._width = width; |
| 2966 this._left = left; |
| 2967 this.transform( |
| 2968 "translateX(" + left + "%) scaleX(" + width / 100 + ")", |
| 2969 this.$.selectionBar) |
| 2970 }, |
| 2971 _onBarTransitionEnd: function(e) { |
| 2972 var cl = this.$.selectionBar.classList; |
| 2973 if (cl.contains("expand")) { |
| 2974 cl.remove("expand"); |
| 2975 cl.add("contract"); |
| 2976 this._positionBar(this._pos.width, this._pos.left) |
| 2977 } else if (cl.contains("contract")) { |
| 2978 cl.remove("contract") |
| 2979 } |
| 2980 } |
| 2981 }); |
| OLD | NEW |