| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 @license | |
| 3 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | |
| 7 Code distributed by Google as part of the polymer project is also | |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | |
| 9 --><link rel="import" href="polymer-micro.html"> | |
| 10 | |
| 11 <script>Polymer.Base._addFeature({ | |
| 12 _prepTemplate: function () { | |
| 13 this._template = this._template || Polymer.DomModule.import(this.is, 'template')
; | |
| 14 if (this._template && this._template.hasAttribute('is')) { | |
| 15 this._warn(this._logf('_prepTemplate', 'top-level Polymer template ' + 'must not
be a type-extension, found', this._template, 'Move inside simple <template>.'))
; | |
| 16 } | |
| 17 }, | |
| 18 _stampTemplate: function () { | |
| 19 if (this._template) { | |
| 20 this.root = this.instanceTemplate(this._template); | |
| 21 } | |
| 22 }, | |
| 23 instanceTemplate: function (template) { | |
| 24 var dom = document.importNode(template._content || template.content, true); | |
| 25 return dom; | |
| 26 } | |
| 27 }); | |
| 28 (function () { | |
| 29 var baseAttachedCallback = Polymer.Base.attachedCallback; | |
| 30 Polymer.Base._addFeature({ | |
| 31 _hostStack: [], | |
| 32 ready: function () { | |
| 33 }, | |
| 34 _pushHost: function (host) { | |
| 35 this.dataHost = host = host || Polymer.Base._hostStack[Polymer.Base._hostStack.l
ength - 1]; | |
| 36 if (host && host._clients) { | |
| 37 host._clients.push(this); | |
| 38 } | |
| 39 this._beginHost(); | |
| 40 }, | |
| 41 _beginHost: function () { | |
| 42 Polymer.Base._hostStack.push(this); | |
| 43 if (!this._clients) { | |
| 44 this._clients = []; | |
| 45 } | |
| 46 }, | |
| 47 _popHost: function () { | |
| 48 Polymer.Base._hostStack.pop(); | |
| 49 }, | |
| 50 _tryReady: function () { | |
| 51 if (this._canReady()) { | |
| 52 this._ready(); | |
| 53 } | |
| 54 }, | |
| 55 _canReady: function () { | |
| 56 return !this.dataHost || this.dataHost._clientsReadied; | |
| 57 }, | |
| 58 _ready: function () { | |
| 59 this._beforeClientsReady(); | |
| 60 this._setupRoot(); | |
| 61 this._readyClients(); | |
| 62 this._afterClientsReady(); | |
| 63 this._readySelf(); | |
| 64 }, | |
| 65 _readyClients: function () { | |
| 66 this._beginDistribute(); | |
| 67 var c$ = this._clients; | |
| 68 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { | |
| 69 c._ready(); | |
| 70 } | |
| 71 this._finishDistribute(); | |
| 72 this._clientsReadied = true; | |
| 73 this._clients = null; | |
| 74 }, | |
| 75 _readySelf: function () { | |
| 76 this._doBehavior('ready'); | |
| 77 this._readied = true; | |
| 78 if (this._attachedPending) { | |
| 79 this._attachedPending = false; | |
| 80 this.attachedCallback(); | |
| 81 } | |
| 82 }, | |
| 83 _beforeClientsReady: function () { | |
| 84 }, | |
| 85 _afterClientsReady: function () { | |
| 86 }, | |
| 87 _beforeAttached: function () { | |
| 88 }, | |
| 89 attachedCallback: function () { | |
| 90 if (this._readied) { | |
| 91 this._beforeAttached(); | |
| 92 baseAttachedCallback.call(this); | |
| 93 } else { | |
| 94 this._attachedPending = true; | |
| 95 } | |
| 96 } | |
| 97 }); | |
| 98 }()); | |
| 99 Polymer.ArraySplice = function () { | |
| 100 function newSplice(index, removed, addedCount) { | |
| 101 return { | |
| 102 index: index, | |
| 103 removed: removed, | |
| 104 addedCount: addedCount | |
| 105 }; | |
| 106 } | |
| 107 var EDIT_LEAVE = 0; | |
| 108 var EDIT_UPDATE = 1; | |
| 109 var EDIT_ADD = 2; | |
| 110 var EDIT_DELETE = 3; | |
| 111 function ArraySplice() { | |
| 112 } | |
| 113 ArraySplice.prototype = { | |
| 114 calcEditDistances: function (current, currentStart, currentEnd, old, oldStart, o
ldEnd) { | |
| 115 var rowCount = oldEnd - oldStart + 1; | |
| 116 var columnCount = currentEnd - currentStart + 1; | |
| 117 var distances = new Array(rowCount); | |
| 118 for (var i = 0; i < rowCount; i++) { | |
| 119 distances[i] = new Array(columnCount); | |
| 120 distances[i][0] = i; | |
| 121 } | |
| 122 for (var j = 0; j < columnCount; j++) | |
| 123 distances[0][j] = j; | |
| 124 for (var i = 1; i < rowCount; i++) { | |
| 125 for (var j = 1; j < columnCount; j++) { | |
| 126 if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1])) | |
| 127 distances[i][j] = distances[i - 1][j - 1]; | |
| 128 else { | |
| 129 var north = distances[i - 1][j] + 1; | |
| 130 var west = distances[i][j - 1] + 1; | |
| 131 distances[i][j] = north < west ? north : west; | |
| 132 } | |
| 133 } | |
| 134 } | |
| 135 return distances; | |
| 136 }, | |
| 137 spliceOperationsFromEditDistances: function (distances) { | |
| 138 var i = distances.length - 1; | |
| 139 var j = distances[0].length - 1; | |
| 140 var current = distances[i][j]; | |
| 141 var edits = []; | |
| 142 while (i > 0 || j > 0) { | |
| 143 if (i == 0) { | |
| 144 edits.push(EDIT_ADD); | |
| 145 j--; | |
| 146 continue; | |
| 147 } | |
| 148 if (j == 0) { | |
| 149 edits.push(EDIT_DELETE); | |
| 150 i--; | |
| 151 continue; | |
| 152 } | |
| 153 var northWest = distances[i - 1][j - 1]; | |
| 154 var west = distances[i - 1][j]; | |
| 155 var north = distances[i][j - 1]; | |
| 156 var min; | |
| 157 if (west < north) | |
| 158 min = west < northWest ? west : northWest; | |
| 159 else | |
| 160 min = north < northWest ? north : northWest; | |
| 161 if (min == northWest) { | |
| 162 if (northWest == current) { | |
| 163 edits.push(EDIT_LEAVE); | |
| 164 } else { | |
| 165 edits.push(EDIT_UPDATE); | |
| 166 current = northWest; | |
| 167 } | |
| 168 i--; | |
| 169 j--; | |
| 170 } else if (min == west) { | |
| 171 edits.push(EDIT_DELETE); | |
| 172 i--; | |
| 173 current = west; | |
| 174 } else { | |
| 175 edits.push(EDIT_ADD); | |
| 176 j--; | |
| 177 current = north; | |
| 178 } | |
| 179 } | |
| 180 edits.reverse(); | |
| 181 return edits; | |
| 182 }, | |
| 183 calcSplices: function (current, currentStart, currentEnd, old, oldStart, oldEnd)
{ | |
| 184 var prefixCount = 0; | |
| 185 var suffixCount = 0; | |
| 186 var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart); | |
| 187 if (currentStart == 0 && oldStart == 0) | |
| 188 prefixCount = this.sharedPrefix(current, old, minLength); | |
| 189 if (currentEnd == current.length && oldEnd == old.length) | |
| 190 suffixCount = this.sharedSuffix(current, old, minLength - prefixCount); | |
| 191 currentStart += prefixCount; | |
| 192 oldStart += prefixCount; | |
| 193 currentEnd -= suffixCount; | |
| 194 oldEnd -= suffixCount; | |
| 195 if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0) | |
| 196 return []; | |
| 197 if (currentStart == currentEnd) { | |
| 198 var splice = newSplice(currentStart, [], 0); | |
| 199 while (oldStart < oldEnd) | |
| 200 splice.removed.push(old[oldStart++]); | |
| 201 return [splice]; | |
| 202 } else if (oldStart == oldEnd) | |
| 203 return [newSplice(currentStart, [], currentEnd - currentStart)]; | |
| 204 var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current,
currentStart, currentEnd, old, oldStart, oldEnd)); | |
| 205 var splice = undefined; | |
| 206 var splices = []; | |
| 207 var index = currentStart; | |
| 208 var oldIndex = oldStart; | |
| 209 for (var i = 0; i < ops.length; i++) { | |
| 210 switch (ops[i]) { | |
| 211 case EDIT_LEAVE: | |
| 212 if (splice) { | |
| 213 splices.push(splice); | |
| 214 splice = undefined; | |
| 215 } | |
| 216 index++; | |
| 217 oldIndex++; | |
| 218 break; | |
| 219 case EDIT_UPDATE: | |
| 220 if (!splice) | |
| 221 splice = newSplice(index, [], 0); | |
| 222 splice.addedCount++; | |
| 223 index++; | |
| 224 splice.removed.push(old[oldIndex]); | |
| 225 oldIndex++; | |
| 226 break; | |
| 227 case EDIT_ADD: | |
| 228 if (!splice) | |
| 229 splice = newSplice(index, [], 0); | |
| 230 splice.addedCount++; | |
| 231 index++; | |
| 232 break; | |
| 233 case EDIT_DELETE: | |
| 234 if (!splice) | |
| 235 splice = newSplice(index, [], 0); | |
| 236 splice.removed.push(old[oldIndex]); | |
| 237 oldIndex++; | |
| 238 break; | |
| 239 } | |
| 240 } | |
| 241 if (splice) { | |
| 242 splices.push(splice); | |
| 243 } | |
| 244 return splices; | |
| 245 }, | |
| 246 sharedPrefix: function (current, old, searchLength) { | |
| 247 for (var i = 0; i < searchLength; i++) | |
| 248 if (!this.equals(current[i], old[i])) | |
| 249 return i; | |
| 250 return searchLength; | |
| 251 }, | |
| 252 sharedSuffix: function (current, old, searchLength) { | |
| 253 var index1 = current.length; | |
| 254 var index2 = old.length; | |
| 255 var count = 0; | |
| 256 while (count < searchLength && this.equals(current[--index1], old[--index2])) | |
| 257 count++; | |
| 258 return count; | |
| 259 }, | |
| 260 calculateSplices: function (current, previous) { | |
| 261 return this.calcSplices(current, 0, current.length, previous, 0, previous.length
); | |
| 262 }, | |
| 263 equals: function (currentValue, previousValue) { | |
| 264 return currentValue === previousValue; | |
| 265 } | |
| 266 }; | |
| 267 return new ArraySplice(); | |
| 268 }(); | |
| 269 Polymer.EventApi = function () { | |
| 270 var Settings = Polymer.Settings; | |
| 271 var EventApi = function (event) { | |
| 272 this.event = event; | |
| 273 }; | |
| 274 if (Settings.useShadow) { | |
| 275 EventApi.prototype = { | |
| 276 get rootTarget() { | |
| 277 return this.event.path[0]; | |
| 278 }, | |
| 279 get localTarget() { | |
| 280 return this.event.target; | |
| 281 }, | |
| 282 get path() { | |
| 283 return this.event.path; | |
| 284 } | |
| 285 }; | |
| 286 } else { | |
| 287 EventApi.prototype = { | |
| 288 get rootTarget() { | |
| 289 return this.event.target; | |
| 290 }, | |
| 291 get localTarget() { | |
| 292 var current = this.event.currentTarget; | |
| 293 var currentRoot = current && Polymer.dom(current).getOwnerRoot(); | |
| 294 var p$ = this.path; | |
| 295 for (var i = 0; i < p$.length; i++) { | |
| 296 if (Polymer.dom(p$[i]).getOwnerRoot() === currentRoot) { | |
| 297 return p$[i]; | |
| 298 } | |
| 299 } | |
| 300 }, | |
| 301 get path() { | |
| 302 if (!this.event._path) { | |
| 303 var path = []; | |
| 304 var o = this.rootTarget; | |
| 305 while (o) { | |
| 306 path.push(o); | |
| 307 o = Polymer.dom(o).parentNode || o.host; | |
| 308 } | |
| 309 path.push(window); | |
| 310 this.event._path = path; | |
| 311 } | |
| 312 return this.event._path; | |
| 313 } | |
| 314 }; | |
| 315 } | |
| 316 var factory = function (event) { | |
| 317 if (!event.__eventApi) { | |
| 318 event.__eventApi = new EventApi(event); | |
| 319 } | |
| 320 return event.__eventApi; | |
| 321 }; | |
| 322 return { factory: factory }; | |
| 323 }(); | |
| 324 Polymer.domInnerHTML = function () { | |
| 325 var escapeAttrRegExp = /[&\u00A0"]/g; | |
| 326 var escapeDataRegExp = /[&\u00A0<>]/g; | |
| 327 function escapeReplace(c) { | |
| 328 switch (c) { | |
| 329 case '&': | |
| 330 return '&'; | |
| 331 case '<': | |
| 332 return '<'; | |
| 333 case '>': | |
| 334 return '>'; | |
| 335 case '"': | |
| 336 return '"'; | |
| 337 case '\xA0': | |
| 338 return ' '; | |
| 339 } | |
| 340 } | |
| 341 function escapeAttr(s) { | |
| 342 return s.replace(escapeAttrRegExp, escapeReplace); | |
| 343 } | |
| 344 function escapeData(s) { | |
| 345 return s.replace(escapeDataRegExp, escapeReplace); | |
| 346 } | |
| 347 function makeSet(arr) { | |
| 348 var set = {}; | |
| 349 for (var i = 0; i < arr.length; i++) { | |
| 350 set[arr[i]] = true; | |
| 351 } | |
| 352 return set; | |
| 353 } | |
| 354 var voidElements = makeSet([ | |
| 355 'area', | |
| 356 'base', | |
| 357 'br', | |
| 358 'col', | |
| 359 'command', | |
| 360 'embed', | |
| 361 'hr', | |
| 362 'img', | |
| 363 'input', | |
| 364 'keygen', | |
| 365 'link', | |
| 366 'meta', | |
| 367 'param', | |
| 368 'source', | |
| 369 'track', | |
| 370 'wbr' | |
| 371 ]); | |
| 372 var plaintextParents = makeSet([ | |
| 373 'style', | |
| 374 'script', | |
| 375 'xmp', | |
| 376 'iframe', | |
| 377 'noembed', | |
| 378 'noframes', | |
| 379 'plaintext', | |
| 380 'noscript' | |
| 381 ]); | |
| 382 function getOuterHTML(node, parentNode, composed) { | |
| 383 switch (node.nodeType) { | |
| 384 case Node.ELEMENT_NODE: | |
| 385 var tagName = node.localName; | |
| 386 var s = '<' + tagName; | |
| 387 var attrs = node.attributes; | |
| 388 for (var i = 0, attr; attr = attrs[i]; i++) { | |
| 389 s += ' ' + attr.name + '="' + escapeAttr(attr.value) + '"'; | |
| 390 } | |
| 391 s += '>'; | |
| 392 if (voidElements[tagName]) { | |
| 393 return s; | |
| 394 } | |
| 395 return s + getInnerHTML(node, composed) + '</' + tagName + '>'; | |
| 396 case Node.TEXT_NODE: | |
| 397 var data = node.data; | |
| 398 if (parentNode && plaintextParents[parentNode.localName]) { | |
| 399 return data; | |
| 400 } | |
| 401 return escapeData(data); | |
| 402 case Node.COMMENT_NODE: | |
| 403 return '<!--' + node.data + '-->'; | |
| 404 default: | |
| 405 console.error(node); | |
| 406 throw new Error('not implemented'); | |
| 407 } | |
| 408 } | |
| 409 function getInnerHTML(node, composed) { | |
| 410 if (node instanceof HTMLTemplateElement) | |
| 411 node = node.content; | |
| 412 var s = ''; | |
| 413 var c$ = Polymer.dom(node).childNodes; | |
| 414 c$ = composed ? node._composedChildren : c$; | |
| 415 for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) { | |
| 416 s += getOuterHTML(child, node, composed); | |
| 417 } | |
| 418 return s; | |
| 419 } | |
| 420 return { getInnerHTML: getInnerHTML }; | |
| 421 }(); | |
| 422 Polymer.DomApi = function () { | |
| 423 'use strict'; | |
| 424 var Settings = Polymer.Settings; | |
| 425 var getInnerHTML = Polymer.domInnerHTML.getInnerHTML; | |
| 426 var nativeInsertBefore = Element.prototype.insertBefore; | |
| 427 var nativeRemoveChild = Element.prototype.removeChild; | |
| 428 var nativeAppendChild = Element.prototype.appendChild; | |
| 429 var nativeCloneNode = Element.prototype.cloneNode; | |
| 430 var nativeImportNode = Document.prototype.importNode; | |
| 431 var dirtyRoots = []; | |
| 432 var DomApi = function (node) { | |
| 433 this.node = node; | |
| 434 if (this.patch) { | |
| 435 this.patch(); | |
| 436 } | |
| 437 }; | |
| 438 DomApi.prototype = { | |
| 439 flush: function () { | |
| 440 for (var i = 0, host; i < dirtyRoots.length; i++) { | |
| 441 host = dirtyRoots[i]; | |
| 442 host.flushDebouncer('_distribute'); | |
| 443 } | |
| 444 dirtyRoots = []; | |
| 445 }, | |
| 446 _lazyDistribute: function (host) { | |
| 447 if (host.shadyRoot && host.shadyRoot._distributionClean) { | |
| 448 host.shadyRoot._distributionClean = false; | |
| 449 host.debounce('_distribute', host._distributeContent); | |
| 450 dirtyRoots.push(host); | |
| 451 } | |
| 452 }, | |
| 453 appendChild: function (node) { | |
| 454 var handled; | |
| 455 this._removeNodeFromHost(node, true); | |
| 456 if (this._nodeIsInLogicalTree(this.node)) { | |
| 457 this._addLogicalInfo(node, this.node); | |
| 458 this._addNodeToHost(node); | |
| 459 handled = this._maybeDistribute(node, this.node); | |
| 460 } | |
| 461 if (!handled && !this._tryRemoveUndistributedNode(node)) { | |
| 462 var container = this.node._isShadyRoot ? this.node.host : this.node; | |
| 463 addToComposedParent(container, node); | |
| 464 nativeAppendChild.call(container, node); | |
| 465 } | |
| 466 return node; | |
| 467 }, | |
| 468 insertBefore: function (node, ref_node) { | |
| 469 if (!ref_node) { | |
| 470 return this.appendChild(node); | |
| 471 } | |
| 472 var handled; | |
| 473 this._removeNodeFromHost(node, true); | |
| 474 if (this._nodeIsInLogicalTree(this.node)) { | |
| 475 saveLightChildrenIfNeeded(this.node); | |
| 476 var children = this.childNodes; | |
| 477 var index = children.indexOf(ref_node); | |
| 478 if (index < 0) { | |
| 479 throw Error('The ref_node to be inserted before is not a child ' + 'of this node
'); | |
| 480 } | |
| 481 this._addLogicalInfo(node, this.node, index); | |
| 482 this._addNodeToHost(node); | |
| 483 handled = this._maybeDistribute(node, this.node); | |
| 484 } | |
| 485 if (!handled && !this._tryRemoveUndistributedNode(node)) { | |
| 486 ref_node = ref_node.localName === CONTENT ? this._firstComposedNode(ref_node) :
ref_node; | |
| 487 var container = this.node._isShadyRoot ? this.node.host : this.node; | |
| 488 addToComposedParent(container, node, ref_node); | |
| 489 nativeInsertBefore.call(container, node, ref_node); | |
| 490 } | |
| 491 return node; | |
| 492 }, | |
| 493 removeChild: function (node) { | |
| 494 if (factory(node).parentNode !== this.node) { | |
| 495 console.warn('The node to be removed is not a child of this node', node); | |
| 496 } | |
| 497 var handled; | |
| 498 if (this._nodeIsInLogicalTree(this.node)) { | |
| 499 this._removeNodeFromHost(node); | |
| 500 handled = this._maybeDistribute(node, this.node); | |
| 501 } | |
| 502 if (!handled) { | |
| 503 var container = this.node._isShadyRoot ? this.node.host : this.node; | |
| 504 if (container === node.parentNode) { | |
| 505 removeFromComposedParent(container, node); | |
| 506 nativeRemoveChild.call(container, node); | |
| 507 } | |
| 508 } | |
| 509 return node; | |
| 510 }, | |
| 511 replaceChild: function (node, ref_node) { | |
| 512 this.insertBefore(node, ref_node); | |
| 513 this.removeChild(ref_node); | |
| 514 return node; | |
| 515 }, | |
| 516 getOwnerRoot: function () { | |
| 517 return this._ownerShadyRootForNode(this.node); | |
| 518 }, | |
| 519 _ownerShadyRootForNode: function (node) { | |
| 520 if (!node) { | |
| 521 return; | |
| 522 } | |
| 523 if (node._ownerShadyRoot === undefined) { | |
| 524 var root; | |
| 525 if (node._isShadyRoot) { | |
| 526 root = node; | |
| 527 } else { | |
| 528 var parent = Polymer.dom(node).parentNode; | |
| 529 if (parent) { | |
| 530 root = parent._isShadyRoot ? parent : this._ownerShadyRootForNode(parent); | |
| 531 } else { | |
| 532 root = null; | |
| 533 } | |
| 534 } | |
| 535 node._ownerShadyRoot = root; | |
| 536 } | |
| 537 return node._ownerShadyRoot; | |
| 538 }, | |
| 539 _maybeDistribute: function (node, parent) { | |
| 540 var fragContent = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && !node.__noCon
tent && Polymer.dom(node).querySelector(CONTENT); | |
| 541 var wrappedContent = fragContent && Polymer.dom(fragContent).parentNode.nodeType
!== Node.DOCUMENT_FRAGMENT_NODE; | |
| 542 var hasContent = fragContent || node.localName === CONTENT; | |
| 543 if (hasContent) { | |
| 544 var root = this._ownerShadyRootForNode(parent); | |
| 545 if (root) { | |
| 546 var host = root.host; | |
| 547 this._updateInsertionPoints(host); | |
| 548 this._lazyDistribute(host); | |
| 549 } | |
| 550 } | |
| 551 var parentNeedsDist = this._parentNeedsDistribution(parent); | |
| 552 if (parentNeedsDist) { | |
| 553 this._lazyDistribute(parent); | |
| 554 } | |
| 555 return parentNeedsDist || hasContent && !wrappedContent; | |
| 556 }, | |
| 557 _tryRemoveUndistributedNode: function (node) { | |
| 558 if (this.node.shadyRoot) { | |
| 559 if (node._composedParent) { | |
| 560 nativeRemoveChild.call(node._composedParent, node); | |
| 561 } | |
| 562 return true; | |
| 563 } | |
| 564 }, | |
| 565 _updateInsertionPoints: function (host) { | |
| 566 host.shadyRoot._insertionPoints = factory(host.shadyRoot).querySelectorAll(CONTE
NT); | |
| 567 }, | |
| 568 _nodeIsInLogicalTree: function (node) { | |
| 569 return Boolean(node._lightParent !== undefined || node._isShadyRoot || this._own
erShadyRootForNode(node) || node.shadyRoot); | |
| 570 }, | |
| 571 _parentNeedsDistribution: function (parent) { | |
| 572 return parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot); | |
| 573 }, | |
| 574 _removeNodeFromHost: function (node, ensureComposedRemoval) { | |
| 575 var hostNeedsDist; | |
| 576 var root; | |
| 577 var parent = node._lightParent; | |
| 578 if (parent) { | |
| 579 root = this._ownerShadyRootForNode(node); | |
| 580 if (root) { | |
| 581 root.host._elementRemove(node); | |
| 582 hostNeedsDist = this._removeDistributedChildren(root, node); | |
| 583 } | |
| 584 this._removeLogicalInfo(node, node._lightParent); | |
| 585 } | |
| 586 this._removeOwnerShadyRoot(node); | |
| 587 if (root && hostNeedsDist) { | |
| 588 this._updateInsertionPoints(root.host); | |
| 589 this._lazyDistribute(root.host); | |
| 590 } else if (ensureComposedRemoval) { | |
| 591 removeFromComposedParent(parent || node.parentNode, node); | |
| 592 } | |
| 593 }, | |
| 594 _removeDistributedChildren: function (root, container) { | |
| 595 var hostNeedsDist; | |
| 596 var ip$ = root._insertionPoints; | |
| 597 for (var i = 0; i < ip$.length; i++) { | |
| 598 var content = ip$[i]; | |
| 599 if (this._contains(container, content)) { | |
| 600 var dc$ = factory(content).getDistributedNodes(); | |
| 601 for (var j = 0; j < dc$.length; j++) { | |
| 602 hostNeedsDist = true; | |
| 603 var node = dc$[j]; | |
| 604 var parent = node.parentNode; | |
| 605 if (parent) { | |
| 606 removeFromComposedParent(parent, node); | |
| 607 nativeRemoveChild.call(parent, node); | |
| 608 } | |
| 609 } | |
| 610 } | |
| 611 } | |
| 612 return hostNeedsDist; | |
| 613 }, | |
| 614 _contains: function (container, node) { | |
| 615 while (node) { | |
| 616 if (node == container) { | |
| 617 return true; | |
| 618 } | |
| 619 node = factory(node).parentNode; | |
| 620 } | |
| 621 }, | |
| 622 _addNodeToHost: function (node) { | |
| 623 var checkNode = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE ? node.firstChild
: node; | |
| 624 var root = this._ownerShadyRootForNode(checkNode); | |
| 625 if (root) { | |
| 626 root.host._elementAdd(node); | |
| 627 } | |
| 628 }, | |
| 629 _addLogicalInfo: function (node, container, index) { | |
| 630 saveLightChildrenIfNeeded(container); | |
| 631 var children = factory(container).childNodes; | |
| 632 index = index === undefined ? children.length : index; | |
| 633 if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | |
| 634 var c$ = Array.prototype.slice.call(node.childNodes); | |
| 635 for (var i = 0, n; i < c$.length && (n = c$[i]); i++) { | |
| 636 children.splice(index++, 0, n); | |
| 637 n._lightParent = container; | |
| 638 } | |
| 639 } else { | |
| 640 children.splice(index, 0, node); | |
| 641 node._lightParent = container; | |
| 642 } | |
| 643 }, | |
| 644 _removeLogicalInfo: function (node, container) { | |
| 645 var children = factory(container).childNodes; | |
| 646 var index = children.indexOf(node); | |
| 647 if (index < 0 || container !== node._lightParent) { | |
| 648 throw Error('The node to be removed is not a child of this node'); | |
| 649 } | |
| 650 children.splice(index, 1); | |
| 651 node._lightParent = null; | |
| 652 }, | |
| 653 _removeOwnerShadyRoot: function (node) { | |
| 654 var hasCachedRoot = factory(node).getOwnerRoot() !== undefined; | |
| 655 if (hasCachedRoot) { | |
| 656 var c$ = factory(node).childNodes; | |
| 657 for (var i = 0, l = c$.length, n; i < l && (n = c$[i]); i++) { | |
| 658 this._removeOwnerShadyRoot(n); | |
| 659 } | |
| 660 } | |
| 661 node._ownerShadyRoot = undefined; | |
| 662 }, | |
| 663 _firstComposedNode: function (content) { | |
| 664 var n$ = factory(content).getDistributedNodes(); | |
| 665 for (var i = 0, l = n$.length, n, p$; i < l && (n = n$[i]); i++) { | |
| 666 p$ = factory(n).getDestinationInsertionPoints(); | |
| 667 if (p$[p$.length - 1] === content) { | |
| 668 return n; | |
| 669 } | |
| 670 } | |
| 671 }, | |
| 672 querySelector: function (selector) { | |
| 673 return this.querySelectorAll(selector)[0]; | |
| 674 }, | |
| 675 querySelectorAll: function (selector) { | |
| 676 return this._query(function (n) { | |
| 677 return matchesSelector.call(n, selector); | |
| 678 }, this.node); | |
| 679 }, | |
| 680 _query: function (matcher, node) { | |
| 681 node = node || this.node; | |
| 682 var list = []; | |
| 683 this._queryElements(factory(node).childNodes, matcher, list); | |
| 684 return list; | |
| 685 }, | |
| 686 _queryElements: function (elements, matcher, list) { | |
| 687 for (var i = 0, l = elements.length, c; i < l && (c = elements[i]); i++) { | |
| 688 if (c.nodeType === Node.ELEMENT_NODE) { | |
| 689 this._queryElement(c, matcher, list); | |
| 690 } | |
| 691 } | |
| 692 }, | |
| 693 _queryElement: function (node, matcher, list) { | |
| 694 if (matcher(node)) { | |
| 695 list.push(node); | |
| 696 } | |
| 697 this._queryElements(factory(node).childNodes, matcher, list); | |
| 698 }, | |
| 699 getDestinationInsertionPoints: function () { | |
| 700 return this.node._destinationInsertionPoints || []; | |
| 701 }, | |
| 702 getDistributedNodes: function () { | |
| 703 return this.node._distributedNodes || []; | |
| 704 }, | |
| 705 queryDistributedElements: function (selector) { | |
| 706 var c$ = this.childNodes; | |
| 707 var list = []; | |
| 708 this._distributedFilter(selector, c$, list); | |
| 709 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { | |
| 710 if (c.localName === CONTENT) { | |
| 711 this._distributedFilter(selector, factory(c).getDistributedNodes(), list); | |
| 712 } | |
| 713 } | |
| 714 return list; | |
| 715 }, | |
| 716 _distributedFilter: function (selector, list, results) { | |
| 717 results = results || []; | |
| 718 for (var i = 0, l = list.length, d; i < l && (d = list[i]); i++) { | |
| 719 if (d.nodeType === Node.ELEMENT_NODE && d.localName !== CONTENT && matchesSelect
or.call(d, selector)) { | |
| 720 results.push(d); | |
| 721 } | |
| 722 } | |
| 723 return results; | |
| 724 }, | |
| 725 _clear: function () { | |
| 726 while (this.childNodes.length) { | |
| 727 this.removeChild(this.childNodes[0]); | |
| 728 } | |
| 729 }, | |
| 730 setAttribute: function (name, value) { | |
| 731 this.node.setAttribute(name, value); | |
| 732 this._distributeParent(); | |
| 733 }, | |
| 734 removeAttribute: function (name) { | |
| 735 this.node.removeAttribute(name); | |
| 736 this._distributeParent(); | |
| 737 }, | |
| 738 _distributeParent: function () { | |
| 739 if (this._parentNeedsDistribution(this.parentNode)) { | |
| 740 this._lazyDistribute(this.parentNode); | |
| 741 } | |
| 742 }, | |
| 743 cloneNode: function (deep) { | |
| 744 var n = nativeCloneNode.call(this.node, false); | |
| 745 if (deep) { | |
| 746 var c$ = this.childNodes; | |
| 747 var d = factory(n); | |
| 748 for (var i = 0, nc; i < c$.length; i++) { | |
| 749 nc = factory(c$[i]).cloneNode(true); | |
| 750 d.appendChild(nc); | |
| 751 } | |
| 752 } | |
| 753 return n; | |
| 754 }, | |
| 755 importNode: function (externalNode, deep) { | |
| 756 var doc = this.node instanceof Document ? this.node : this.node.ownerDocument; | |
| 757 var n = nativeImportNode.call(doc, externalNode, false); | |
| 758 if (deep) { | |
| 759 var c$ = factory(externalNode).childNodes; | |
| 760 var d = factory(n); | |
| 761 for (var i = 0, nc; i < c$.length; i++) { | |
| 762 nc = factory(doc).importNode(c$[i], true); | |
| 763 d.appendChild(nc); | |
| 764 } | |
| 765 } | |
| 766 return n; | |
| 767 } | |
| 768 }; | |
| 769 Object.defineProperty(DomApi.prototype, 'classList', { | |
| 770 get: function () { | |
| 771 if (!this._classList) { | |
| 772 this._classList = new DomApi.ClassList(this); | |
| 773 } | |
| 774 return this._classList; | |
| 775 }, | |
| 776 configurable: true | |
| 777 }); | |
| 778 DomApi.ClassList = function (host) { | |
| 779 this.domApi = host; | |
| 780 this.node = host.node; | |
| 781 }; | |
| 782 DomApi.ClassList.prototype = { | |
| 783 add: function () { | |
| 784 this.node.classList.add.apply(this.node.classList, arguments); | |
| 785 this.domApi._distributeParent(); | |
| 786 }, | |
| 787 remove: function () { | |
| 788 this.node.classList.remove.apply(this.node.classList, arguments); | |
| 789 this.domApi._distributeParent(); | |
| 790 }, | |
| 791 toggle: function () { | |
| 792 this.node.classList.toggle.apply(this.node.classList, arguments); | |
| 793 this.domApi._distributeParent(); | |
| 794 }, | |
| 795 contains: function () { | |
| 796 return this.node.classList.contains.apply(this.node.classList, arguments); | |
| 797 } | |
| 798 }; | |
| 799 if (!Settings.useShadow) { | |
| 800 Object.defineProperties(DomApi.prototype, { | |
| 801 childNodes: { | |
| 802 get: function () { | |
| 803 var c$ = getLightChildren(this.node); | |
| 804 return Array.isArray(c$) ? c$ : Array.prototype.slice.call(c$); | |
| 805 }, | |
| 806 configurable: true | |
| 807 }, | |
| 808 children: { | |
| 809 get: function () { | |
| 810 return Array.prototype.filter.call(this.childNodes, function (n) { | |
| 811 return n.nodeType === Node.ELEMENT_NODE; | |
| 812 }); | |
| 813 }, | |
| 814 configurable: true | |
| 815 }, | |
| 816 parentNode: { | |
| 817 get: function () { | |
| 818 return this.node._lightParent || (this.node.__patched ? this.node._composedParen
t : this.node.parentNode); | |
| 819 }, | |
| 820 configurable: true | |
| 821 }, | |
| 822 firstChild: { | |
| 823 get: function () { | |
| 824 return this.childNodes[0]; | |
| 825 }, | |
| 826 configurable: true | |
| 827 }, | |
| 828 lastChild: { | |
| 829 get: function () { | |
| 830 var c$ = this.childNodes; | |
| 831 return c$[c$.length - 1]; | |
| 832 }, | |
| 833 configurable: true | |
| 834 }, | |
| 835 nextSibling: { | |
| 836 get: function () { | |
| 837 var c$ = this.parentNode && factory(this.parentNode).childNodes; | |
| 838 if (c$) { | |
| 839 return c$[Array.prototype.indexOf.call(c$, this.node) + 1]; | |
| 840 } | |
| 841 }, | |
| 842 configurable: true | |
| 843 }, | |
| 844 previousSibling: { | |
| 845 get: function () { | |
| 846 var c$ = this.parentNode && factory(this.parentNode).childNodes; | |
| 847 if (c$) { | |
| 848 return c$[Array.prototype.indexOf.call(c$, this.node) - 1]; | |
| 849 } | |
| 850 }, | |
| 851 configurable: true | |
| 852 }, | |
| 853 firstElementChild: { | |
| 854 get: function () { | |
| 855 return this.children[0]; | |
| 856 }, | |
| 857 configurable: true | |
| 858 }, | |
| 859 lastElementChild: { | |
| 860 get: function () { | |
| 861 var c$ = this.children; | |
| 862 return c$[c$.length - 1]; | |
| 863 }, | |
| 864 configurable: true | |
| 865 }, | |
| 866 nextElementSibling: { | |
| 867 get: function () { | |
| 868 var c$ = this.parentNode && factory(this.parentNode).children; | |
| 869 if (c$) { | |
| 870 return c$[Array.prototype.indexOf.call(c$, this.node) + 1]; | |
| 871 } | |
| 872 }, | |
| 873 configurable: true | |
| 874 }, | |
| 875 previousElementSibling: { | |
| 876 get: function () { | |
| 877 var c$ = this.parentNode && factory(this.parentNode).children; | |
| 878 if (c$) { | |
| 879 return c$[Array.prototype.indexOf.call(c$, this.node) - 1]; | |
| 880 } | |
| 881 }, | |
| 882 configurable: true | |
| 883 }, | |
| 884 textContent: { | |
| 885 get: function () { | |
| 886 if (this.node.nodeType === Node.TEXT_NODE) { | |
| 887 return this.node.textContent; | |
| 888 } else { | |
| 889 return Array.prototype.map.call(this.childNodes, function (c) { | |
| 890 return c.textContent; | |
| 891 }).join(''); | |
| 892 } | |
| 893 }, | |
| 894 set: function (text) { | |
| 895 this._clear(); | |
| 896 if (text) { | |
| 897 this.appendChild(document.createTextNode(text)); | |
| 898 } | |
| 899 }, | |
| 900 configurable: true | |
| 901 }, | |
| 902 innerHTML: { | |
| 903 get: function () { | |
| 904 if (this.node.nodeType === Node.TEXT_NODE) { | |
| 905 return null; | |
| 906 } else { | |
| 907 return getInnerHTML(this.node); | |
| 908 } | |
| 909 }, | |
| 910 set: function (text) { | |
| 911 if (this.node.nodeType !== Node.TEXT_NODE) { | |
| 912 this._clear(); | |
| 913 var d = document.createElement('div'); | |
| 914 d.innerHTML = text; | |
| 915 var c$ = Array.prototype.slice.call(d.childNodes); | |
| 916 for (var i = 0; i < c$.length; i++) { | |
| 917 this.appendChild(c$[i]); | |
| 918 } | |
| 919 } | |
| 920 }, | |
| 921 configurable: true | |
| 922 } | |
| 923 }); | |
| 924 DomApi.prototype._getComposedInnerHTML = function () { | |
| 925 return getInnerHTML(this.node, true); | |
| 926 }; | |
| 927 } else { | |
| 928 DomApi.prototype.querySelectorAll = function (selector) { | |
| 929 return Array.prototype.slice.call(this.node.querySelectorAll(selector)); | |
| 930 }; | |
| 931 DomApi.prototype.getOwnerRoot = function () { | |
| 932 var n = this.node; | |
| 933 while (n) { | |
| 934 if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE && n.host) { | |
| 935 return n; | |
| 936 } | |
| 937 n = n.parentNode; | |
| 938 } | |
| 939 }; | |
| 940 DomApi.prototype.cloneNode = function (deep) { | |
| 941 return this.node.cloneNode(deep); | |
| 942 }; | |
| 943 DomApi.prototype.importNode = function (externalNode, deep) { | |
| 944 var doc = this.node instanceof Document ? this.node : this.node.ownerDocument; | |
| 945 return doc.importNode(externalNode, deep); | |
| 946 }; | |
| 947 DomApi.prototype.getDestinationInsertionPoints = function () { | |
| 948 var n$ = this.node.getDestinationInsertionPoints && this.node.getDestinationInse
rtionPoints(); | |
| 949 return n$ ? Array.prototype.slice.call(n$) : []; | |
| 950 }; | |
| 951 DomApi.prototype.getDistributedNodes = function () { | |
| 952 var n$ = this.node.getDistributedNodes && this.node.getDistributedNodes(); | |
| 953 return n$ ? Array.prototype.slice.call(n$) : []; | |
| 954 }; | |
| 955 DomApi.prototype._distributeParent = function () { | |
| 956 }; | |
| 957 Object.defineProperties(DomApi.prototype, { | |
| 958 childNodes: { | |
| 959 get: function () { | |
| 960 return Array.prototype.slice.call(this.node.childNodes); | |
| 961 }, | |
| 962 configurable: true | |
| 963 }, | |
| 964 children: { | |
| 965 get: function () { | |
| 966 return Array.prototype.slice.call(this.node.children); | |
| 967 }, | |
| 968 configurable: true | |
| 969 }, | |
| 970 textContent: { | |
| 971 get: function () { | |
| 972 return this.node.textContent; | |
| 973 }, | |
| 974 set: function (value) { | |
| 975 return this.node.textContent = value; | |
| 976 }, | |
| 977 configurable: true | |
| 978 }, | |
| 979 innerHTML: { | |
| 980 get: function () { | |
| 981 return this.node.innerHTML; | |
| 982 }, | |
| 983 set: function (value) { | |
| 984 return this.node.innerHTML = value; | |
| 985 }, | |
| 986 configurable: true | |
| 987 } | |
| 988 }); | |
| 989 var forwards = [ | |
| 990 'parentNode', | |
| 991 'firstChild', | |
| 992 'lastChild', | |
| 993 'nextSibling', | |
| 994 'previousSibling', | |
| 995 'firstElementChild', | |
| 996 'lastElementChild', | |
| 997 'nextElementSibling', | |
| 998 'previousElementSibling' | |
| 999 ]; | |
| 1000 forwards.forEach(function (name) { | |
| 1001 Object.defineProperty(DomApi.prototype, name, { | |
| 1002 get: function () { | |
| 1003 return this.node[name]; | |
| 1004 }, | |
| 1005 configurable: true | |
| 1006 }); | |
| 1007 }); | |
| 1008 } | |
| 1009 var CONTENT = 'content'; | |
| 1010 var factory = function (node, patch) { | |
| 1011 node = node || document; | |
| 1012 if (!node.__domApi) { | |
| 1013 node.__domApi = new DomApi(node, patch); | |
| 1014 } | |
| 1015 return node.__domApi; | |
| 1016 }; | |
| 1017 Polymer.dom = function (obj, patch) { | |
| 1018 if (obj instanceof Event) { | |
| 1019 return Polymer.EventApi.factory(obj); | |
| 1020 } else { | |
| 1021 return factory(obj, patch); | |
| 1022 } | |
| 1023 }; | |
| 1024 Polymer.dom.flush = DomApi.prototype.flush; | |
| 1025 function getLightChildren(node) { | |
| 1026 var children = node._lightChildren; | |
| 1027 return children ? children : node.childNodes; | |
| 1028 } | |
| 1029 function getComposedChildren(node) { | |
| 1030 if (!node._composedChildren) { | |
| 1031 node._composedChildren = Array.prototype.slice.call(node.childNodes); | |
| 1032 } | |
| 1033 return node._composedChildren; | |
| 1034 } | |
| 1035 function addToComposedParent(parent, node, ref_node) { | |
| 1036 var children = getComposedChildren(parent); | |
| 1037 var i = ref_node ? children.indexOf(ref_node) : -1; | |
| 1038 if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | |
| 1039 var fragChildren = getComposedChildren(node); | |
| 1040 for (var j = 0; j < fragChildren.length; j++) { | |
| 1041 addNodeToComposedChildren(fragChildren[j], parent, children, i + j); | |
| 1042 } | |
| 1043 node._composedChildren = null; | |
| 1044 } else { | |
| 1045 addNodeToComposedChildren(node, parent, children, i); | |
| 1046 } | |
| 1047 } | |
| 1048 function addNodeToComposedChildren(node, parent, children, i) { | |
| 1049 node._composedParent = parent; | |
| 1050 children.splice(i >= 0 ? i : children.length, 0, node); | |
| 1051 } | |
| 1052 function removeFromComposedParent(parent, node) { | |
| 1053 node._composedParent = null; | |
| 1054 if (parent) { | |
| 1055 var children = getComposedChildren(parent); | |
| 1056 var i = children.indexOf(node); | |
| 1057 if (i >= 0) { | |
| 1058 children.splice(i, 1); | |
| 1059 } | |
| 1060 } | |
| 1061 } | |
| 1062 function saveLightChildrenIfNeeded(node) { | |
| 1063 if (!node._lightChildren) { | |
| 1064 var c$ = Array.prototype.slice.call(node.childNodes); | |
| 1065 for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) { | |
| 1066 child._lightParent = child._lightParent || node; | |
| 1067 } | |
| 1068 node._lightChildren = c$; | |
| 1069 } | |
| 1070 } | |
| 1071 function hasInsertionPoint(root) { | |
| 1072 return Boolean(root._insertionPoints.length); | |
| 1073 } | |
| 1074 var p = Element.prototype; | |
| 1075 var matchesSelector = p.matches || p.matchesSelector || p.mozMatchesSelector ||
p.msMatchesSelector || p.oMatchesSelector || p.webkitMatchesSelector; | |
| 1076 return { | |
| 1077 getLightChildren: getLightChildren, | |
| 1078 getComposedChildren: getComposedChildren, | |
| 1079 removeFromComposedParent: removeFromComposedParent, | |
| 1080 saveLightChildrenIfNeeded: saveLightChildrenIfNeeded, | |
| 1081 matchesSelector: matchesSelector, | |
| 1082 hasInsertionPoint: hasInsertionPoint, | |
| 1083 ctor: DomApi, | |
| 1084 factory: factory | |
| 1085 }; | |
| 1086 }(); | |
| 1087 (function () { | |
| 1088 Polymer.Base._addFeature({ | |
| 1089 _prepShady: function () { | |
| 1090 this._useContent = this._useContent || Boolean(this._template); | |
| 1091 }, | |
| 1092 _poolContent: function () { | |
| 1093 if (this._useContent) { | |
| 1094 saveLightChildrenIfNeeded(this); | |
| 1095 } | |
| 1096 }, | |
| 1097 _setupRoot: function () { | |
| 1098 if (this._useContent) { | |
| 1099 this._createLocalRoot(); | |
| 1100 if (!this.dataHost) { | |
| 1101 upgradeLightChildren(this._lightChildren); | |
| 1102 } | |
| 1103 } | |
| 1104 }, | |
| 1105 _createLocalRoot: function () { | |
| 1106 this.shadyRoot = this.root; | |
| 1107 this.shadyRoot._distributionClean = false; | |
| 1108 this.shadyRoot._isShadyRoot = true; | |
| 1109 this.shadyRoot._dirtyRoots = []; | |
| 1110 this.shadyRoot._insertionPoints = !this._notes || this._notes._hasContent ? this
.shadyRoot.querySelectorAll('content') : []; | |
| 1111 saveLightChildrenIfNeeded(this.shadyRoot); | |
| 1112 this.shadyRoot.host = this; | |
| 1113 }, | |
| 1114 get domHost() { | |
| 1115 var root = Polymer.dom(this).getOwnerRoot(); | |
| 1116 return root && root.host; | |
| 1117 }, | |
| 1118 distributeContent: function (updateInsertionPoints) { | |
| 1119 if (this.shadyRoot) { | |
| 1120 var dom = Polymer.dom(this); | |
| 1121 if (updateInsertionPoints) { | |
| 1122 dom._updateInsertionPoints(this); | |
| 1123 } | |
| 1124 var host = getTopDistributingHost(this); | |
| 1125 dom._lazyDistribute(host); | |
| 1126 } | |
| 1127 }, | |
| 1128 _distributeContent: function () { | |
| 1129 if (this._useContent && !this.shadyRoot._distributionClean) { | |
| 1130 this._beginDistribute(); | |
| 1131 this._distributeDirtyRoots(); | |
| 1132 this._finishDistribute(); | |
| 1133 } | |
| 1134 }, | |
| 1135 _beginDistribute: function () { | |
| 1136 if (this._useContent && hasInsertionPoint(this.shadyRoot)) { | |
| 1137 this._resetDistribution(); | |
| 1138 this._distributePool(this.shadyRoot, this._collectPool()); | |
| 1139 } | |
| 1140 }, | |
| 1141 _distributeDirtyRoots: function () { | |
| 1142 var c$ = this.shadyRoot._dirtyRoots; | |
| 1143 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { | |
| 1144 c._distributeContent(); | |
| 1145 } | |
| 1146 this.shadyRoot._dirtyRoots = []; | |
| 1147 }, | |
| 1148 _finishDistribute: function () { | |
| 1149 if (this._useContent) { | |
| 1150 if (hasInsertionPoint(this.shadyRoot)) { | |
| 1151 this._composeTree(); | |
| 1152 } else { | |
| 1153 if (!this.shadyRoot._hasDistributed) { | |
| 1154 this.textContent = ''; | |
| 1155 this._composedChildren = null; | |
| 1156 this.appendChild(this.shadyRoot); | |
| 1157 } else { | |
| 1158 var children = this._composeNode(this); | |
| 1159 this._updateChildNodes(this, children); | |
| 1160 } | |
| 1161 } | |
| 1162 this.shadyRoot._hasDistributed = true; | |
| 1163 this.shadyRoot._distributionClean = true; | |
| 1164 } | |
| 1165 }, | |
| 1166 elementMatches: function (selector, node) { | |
| 1167 node = node || this; | |
| 1168 return matchesSelector.call(node, selector); | |
| 1169 }, | |
| 1170 _resetDistribution: function () { | |
| 1171 var children = getLightChildren(this); | |
| 1172 for (var i = 0; i < children.length; i++) { | |
| 1173 var child = children[i]; | |
| 1174 if (child._destinationInsertionPoints) { | |
| 1175 child._destinationInsertionPoints = undefined; | |
| 1176 } | |
| 1177 if (isInsertionPoint(child)) { | |
| 1178 clearDistributedDestinationInsertionPoints(child); | |
| 1179 } | |
| 1180 } | |
| 1181 var root = this.shadyRoot; | |
| 1182 var p$ = root._insertionPoints; | |
| 1183 for (var j = 0; j < p$.length; j++) { | |
| 1184 p$[j]._distributedNodes = []; | |
| 1185 } | |
| 1186 }, | |
| 1187 _collectPool: function () { | |
| 1188 var pool = []; | |
| 1189 var children = getLightChildren(this); | |
| 1190 for (var i = 0; i < children.length; i++) { | |
| 1191 var child = children[i]; | |
| 1192 if (isInsertionPoint(child)) { | |
| 1193 pool.push.apply(pool, child._distributedNodes); | |
| 1194 } else { | |
| 1195 pool.push(child); | |
| 1196 } | |
| 1197 } | |
| 1198 return pool; | |
| 1199 }, | |
| 1200 _distributePool: function (node, pool) { | |
| 1201 var p$ = node._insertionPoints; | |
| 1202 for (var i = 0, l = p$.length, p; i < l && (p = p$[i]); i++) { | |
| 1203 this._distributeInsertionPoint(p, pool); | |
| 1204 maybeRedistributeParent(p, this); | |
| 1205 } | |
| 1206 }, | |
| 1207 _distributeInsertionPoint: function (content, pool) { | |
| 1208 var anyDistributed = false; | |
| 1209 for (var i = 0, l = pool.length, node; i < l; i++) { | |
| 1210 node = pool[i]; | |
| 1211 if (!node) { | |
| 1212 continue; | |
| 1213 } | |
| 1214 if (this._matchesContentSelect(node, content)) { | |
| 1215 distributeNodeInto(node, content); | |
| 1216 pool[i] = undefined; | |
| 1217 anyDistributed = true; | |
| 1218 } | |
| 1219 } | |
| 1220 if (!anyDistributed) { | |
| 1221 var children = getLightChildren(content); | |
| 1222 for (var j = 0; j < children.length; j++) { | |
| 1223 distributeNodeInto(children[j], content); | |
| 1224 } | |
| 1225 } | |
| 1226 }, | |
| 1227 _composeTree: function () { | |
| 1228 this._updateChildNodes(this, this._composeNode(this)); | |
| 1229 var p$ = this.shadyRoot._insertionPoints; | |
| 1230 for (var i = 0, l = p$.length, p, parent; i < l && (p = p$[i]); i++) { | |
| 1231 parent = p._lightParent || p.parentNode; | |
| 1232 if (!parent._useContent && parent !== this && parent !== this.shadyRoot) { | |
| 1233 this._updateChildNodes(parent, this._composeNode(parent)); | |
| 1234 } | |
| 1235 } | |
| 1236 }, | |
| 1237 _composeNode: function (node) { | |
| 1238 var children = []; | |
| 1239 var c$ = getLightChildren(node.shadyRoot || node); | |
| 1240 for (var i = 0; i < c$.length; i++) { | |
| 1241 var child = c$[i]; | |
| 1242 if (isInsertionPoint(child)) { | |
| 1243 var distributedNodes = child._distributedNodes; | |
| 1244 for (var j = 0; j < distributedNodes.length; j++) { | |
| 1245 var distributedNode = distributedNodes[j]; | |
| 1246 if (isFinalDestination(child, distributedNode)) { | |
| 1247 children.push(distributedNode); | |
| 1248 } | |
| 1249 } | |
| 1250 } else { | |
| 1251 children.push(child); | |
| 1252 } | |
| 1253 } | |
| 1254 return children; | |
| 1255 }, | |
| 1256 _updateChildNodes: function (container, children) { | |
| 1257 var composed = getComposedChildren(container); | |
| 1258 var splices = Polymer.ArraySplice.calculateSplices(children, composed); | |
| 1259 for (var i = 0, d = 0, s; i < splices.length && (s = splices[i]); i++) { | |
| 1260 for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) { | |
| 1261 remove(n); | |
| 1262 composed.splice(s.index + d, 1); | |
| 1263 } | |
| 1264 d -= s.addedCount; | |
| 1265 } | |
| 1266 for (var i = 0, s, next; i < splices.length && (s = splices[i]); i++) { | |
| 1267 next = composed[s.index]; | |
| 1268 for (var j = s.index, n; j < s.index + s.addedCount; j++) { | |
| 1269 n = children[j]; | |
| 1270 insertBefore(container, n, next); | |
| 1271 composed.splice(j, 0, n); | |
| 1272 } | |
| 1273 } | |
| 1274 }, | |
| 1275 _matchesContentSelect: function (node, contentElement) { | |
| 1276 var select = contentElement.getAttribute('select'); | |
| 1277 if (!select) { | |
| 1278 return true; | |
| 1279 } | |
| 1280 select = select.trim(); | |
| 1281 if (!select) { | |
| 1282 return true; | |
| 1283 } | |
| 1284 if (!(node instanceof Element)) { | |
| 1285 return false; | |
| 1286 } | |
| 1287 var validSelectors = /^(:not\()?[*.#[a-zA-Z_|]/; | |
| 1288 if (!validSelectors.test(select)) { | |
| 1289 return false; | |
| 1290 } | |
| 1291 return this.elementMatches(select, node); | |
| 1292 }, | |
| 1293 _elementAdd: function () { | |
| 1294 }, | |
| 1295 _elementRemove: function () { | |
| 1296 } | |
| 1297 }); | |
| 1298 var saveLightChildrenIfNeeded = Polymer.DomApi.saveLightChildrenIfNeeded; | |
| 1299 var getLightChildren = Polymer.DomApi.getLightChildren; | |
| 1300 var matchesSelector = Polymer.DomApi.matchesSelector; | |
| 1301 var hasInsertionPoint = Polymer.DomApi.hasInsertionPoint; | |
| 1302 var getComposedChildren = Polymer.DomApi.getComposedChildren; | |
| 1303 var removeFromComposedParent = Polymer.DomApi.removeFromComposedParent; | |
| 1304 function distributeNodeInto(child, insertionPoint) { | |
| 1305 insertionPoint._distributedNodes.push(child); | |
| 1306 var points = child._destinationInsertionPoints; | |
| 1307 if (!points) { | |
| 1308 child._destinationInsertionPoints = [insertionPoint]; | |
| 1309 } else { | |
| 1310 points.push(insertionPoint); | |
| 1311 } | |
| 1312 } | |
| 1313 function clearDistributedDestinationInsertionPoints(content) { | |
| 1314 var e$ = content._distributedNodes; | |
| 1315 if (e$) { | |
| 1316 for (var i = 0; i < e$.length; i++) { | |
| 1317 var d = e$[i]._destinationInsertionPoints; | |
| 1318 if (d) { | |
| 1319 d.splice(d.indexOf(content) + 1, d.length); | |
| 1320 } | |
| 1321 } | |
| 1322 } | |
| 1323 } | |
| 1324 function maybeRedistributeParent(content, host) { | |
| 1325 var parent = content._lightParent; | |
| 1326 if (parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot) && parent.
shadyRoot._distributionClean) { | |
| 1327 parent.shadyRoot._distributionClean = false; | |
| 1328 host.shadyRoot._dirtyRoots.push(parent); | |
| 1329 } | |
| 1330 } | |
| 1331 function isFinalDestination(insertionPoint, node) { | |
| 1332 var points = node._destinationInsertionPoints; | |
| 1333 return points && points[points.length - 1] === insertionPoint; | |
| 1334 } | |
| 1335 function isInsertionPoint(node) { | |
| 1336 return node.localName == 'content'; | |
| 1337 } | |
| 1338 var nativeInsertBefore = Element.prototype.insertBefore; | |
| 1339 var nativeRemoveChild = Element.prototype.removeChild; | |
| 1340 function insertBefore(parentNode, newChild, refChild) { | |
| 1341 var newChildParent = getComposedParent(newChild); | |
| 1342 if (newChildParent !== parentNode) { | |
| 1343 removeFromComposedParent(newChildParent, newChild); | |
| 1344 } | |
| 1345 remove(newChild); | |
| 1346 saveLightChildrenIfNeeded(parentNode); | |
| 1347 nativeInsertBefore.call(parentNode, newChild, refChild || null); | |
| 1348 newChild._composedParent = parentNode; | |
| 1349 } | |
| 1350 function remove(node) { | |
| 1351 var parentNode = getComposedParent(node); | |
| 1352 if (parentNode) { | |
| 1353 saveLightChildrenIfNeeded(parentNode); | |
| 1354 node._composedParent = null; | |
| 1355 nativeRemoveChild.call(parentNode, node); | |
| 1356 } | |
| 1357 } | |
| 1358 function getComposedParent(node) { | |
| 1359 return node.__patched ? node._composedParent : node.parentNode; | |
| 1360 } | |
| 1361 function getTopDistributingHost(host) { | |
| 1362 while (host && hostNeedsRedistribution(host)) { | |
| 1363 host = host.domHost; | |
| 1364 } | |
| 1365 return host; | |
| 1366 } | |
| 1367 function hostNeedsRedistribution(host) { | |
| 1368 var c$ = Polymer.dom(host).children; | |
| 1369 for (var i = 0, c; i < c$.length; i++) { | |
| 1370 c = c$[i]; | |
| 1371 if (c.localName === 'content') { | |
| 1372 return host.domHost; | |
| 1373 } | |
| 1374 } | |
| 1375 } | |
| 1376 var needsUpgrade = window.CustomElements && !CustomElements.useNative; | |
| 1377 function upgradeLightChildren(children) { | |
| 1378 if (needsUpgrade && children) { | |
| 1379 for (var i = 0; i < children.length; i++) { | |
| 1380 CustomElements.upgrade(children[i]); | |
| 1381 } | |
| 1382 } | |
| 1383 } | |
| 1384 }()); | |
| 1385 if (Polymer.Settings.useShadow) { | |
| 1386 Polymer.Base._addFeature({ | |
| 1387 _poolContent: function () { | |
| 1388 }, | |
| 1389 _beginDistribute: function () { | |
| 1390 }, | |
| 1391 distributeContent: function () { | |
| 1392 }, | |
| 1393 _distributeContent: function () { | |
| 1394 }, | |
| 1395 _finishDistribute: function () { | |
| 1396 }, | |
| 1397 _createLocalRoot: function () { | |
| 1398 this.createShadowRoot(); | |
| 1399 this.shadowRoot.appendChild(this.root); | |
| 1400 this.root = this.shadowRoot; | |
| 1401 } | |
| 1402 }); | |
| 1403 } | |
| 1404 Polymer.DomModule = document.createElement('dom-module'); | |
| 1405 Polymer.Base._addFeature({ | |
| 1406 _registerFeatures: function () { | |
| 1407 this._prepIs(); | |
| 1408 this._prepAttributes(); | |
| 1409 this._prepBehaviors(); | |
| 1410 this._prepConstructor(); | |
| 1411 this._prepTemplate(); | |
| 1412 this._prepShady(); | |
| 1413 }, | |
| 1414 _prepBehavior: function (b) { | |
| 1415 this._addHostAttributes(b.hostAttributes); | |
| 1416 }, | |
| 1417 _initFeatures: function () { | |
| 1418 this._poolContent(); | |
| 1419 this._pushHost(); | |
| 1420 this._stampTemplate(); | |
| 1421 this._popHost(); | |
| 1422 this._marshalHostAttributes(); | |
| 1423 this._setupDebouncers(); | |
| 1424 this._marshalBehaviors(); | |
| 1425 this._tryReady(); | |
| 1426 }, | |
| 1427 _marshalBehavior: function (b) { | |
| 1428 } | |
| 1429 });</script> | |
| 1430 | |
| OLD | NEW |