| OLD | NEW |
| 1 | 1 (function() { |
| 2 (function() { | |
| 3 var Utility = { | 2 var Utility = { |
| 4 distance: function(x1, y1, x2, y2) { | 3 distance: function(x1, y1, x2, y2) { |
| 5 var xDelta = (x1 - x2); | 4 var xDelta = (x1 - x2); |
| 6 var yDelta = (y1 - y2); | 5 var yDelta = (y1 - y2); |
| 7 | 6 |
| 8 return Math.sqrt(xDelta * xDelta + yDelta * yDelta); | 7 return Math.sqrt(xDelta * xDelta + yDelta * yDelta); |
| 9 }, | 8 }, |
| 10 | 9 |
| 11 now: window.performance && window.performance.now ? | 10 now: window.performance && window.performance.now ? |
| 12 window.performance.now.bind(window.performance) : Date.now | 11 window.performance.now.bind(window.performance) : Date.now |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 /** | 369 /** |
| 371 * If true, the ripple will remain in the "down" state until `holdDown` | 370 * If true, the ripple will remain in the "down" state until `holdDown` |
| 372 * is set to false again. | 371 * is set to false again. |
| 373 */ | 372 */ |
| 374 holdDown: { | 373 holdDown: { |
| 375 type: Boolean, | 374 type: Boolean, |
| 376 value: false, | 375 value: false, |
| 377 observer: '_holdDownChanged' | 376 observer: '_holdDownChanged' |
| 378 }, | 377 }, |
| 379 | 378 |
| 379 /** |
| 380 * If true, the ripple will not generate a ripple effect |
| 381 * via pointer interaction. |
| 382 * Calling ripple's imperative api like `simulatedRipple` will |
| 383 * still generate the ripple effect. |
| 384 */ |
| 385 noink: { |
| 386 type: Boolean, |
| 387 value: false |
| 388 }, |
| 389 |
| 380 _animating: { | 390 _animating: { |
| 381 type: Boolean | 391 type: Boolean |
| 382 }, | 392 }, |
| 383 | 393 |
| 384 _boundAnimate: { | 394 _boundAnimate: { |
| 385 type: Function, | 395 type: Function, |
| 386 value: function() { | 396 value: function() { |
| 387 return this.animate.bind(this); | 397 return this.animate.bind(this); |
| 388 } | 398 } |
| 389 } | 399 } |
| 390 }, | 400 }, |
| 391 | 401 |
| 402 observers: [ |
| 403 '_noinkChanged(noink, isAttached)' |
| 404 ], |
| 405 |
| 392 get target () { | 406 get target () { |
| 393 var ownerRoot = Polymer.dom(this).getOwnerRoot(); | 407 var ownerRoot = Polymer.dom(this).getOwnerRoot(); |
| 394 var target; | 408 var target; |
| 395 | 409 |
| 396 if (this.parentNode.nodeType == 11) { // DOCUMENT_FRAGMENT_NODE | 410 if (this.parentNode.nodeType == 11) { // DOCUMENT_FRAGMENT_NODE |
| 397 target = ownerRoot.host; | 411 target = ownerRoot.host; |
| 398 } else { | 412 } else { |
| 399 target = this.parentNode; | 413 target = this.parentNode; |
| 400 } | 414 } |
| 401 | 415 |
| 402 return target; | 416 return target; |
| 403 }, | 417 }, |
| 404 | 418 |
| 405 keyBindings: { | 419 keyBindings: { |
| 406 'enter:keydown': '_onEnterKeydown', | 420 'enter:keydown': '_onEnterKeydown', |
| 407 'space:keydown': '_onSpaceKeydown', | 421 'space:keydown': '_onSpaceKeydown', |
| 408 'space:keyup': '_onSpaceKeyup' | 422 'space:keyup': '_onSpaceKeyup' |
| 409 }, | 423 }, |
| 410 | 424 |
| 411 attached: function() { | 425 attached: function() { |
| 412 this.listen(this.target, 'up', 'upAction'); | 426 this.listen(this.target, 'up', 'uiUpAction'); |
| 413 this.listen(this.target, 'down', 'downAction'); | 427 this.listen(this.target, 'down', 'uiDownAction'); |
| 428 }, |
| 414 | 429 |
| 415 if (!this.target.hasAttribute('noink')) { | 430 detached: function() { |
| 416 this.keyEventTarget = this.target; | 431 this.unlisten(this.target, 'up', 'uiUpAction'); |
| 417 } | 432 this.unlisten(this.target, 'down', 'uiDownAction'); |
| 418 }, | 433 }, |
| 419 | 434 |
| 420 get shouldKeepAnimating () { | 435 get shouldKeepAnimating () { |
| 421 for (var index = 0; index < this.ripples.length; ++index) { | 436 for (var index = 0; index < this.ripples.length; ++index) { |
| 422 if (!this.ripples[index].isAnimationComplete) { | 437 if (!this.ripples[index].isAnimationComplete) { |
| 423 return true; | 438 return true; |
| 424 } | 439 } |
| 425 } | 440 } |
| 426 | 441 |
| 427 return false; | 442 return false; |
| 428 }, | 443 }, |
| 429 | 444 |
| 430 simulatedRipple: function() { | 445 simulatedRipple: function() { |
| 431 this.downAction(null); | 446 this.downAction(null); |
| 432 | 447 |
| 433 // Please see polymer/polymer#1305 | 448 // Please see polymer/polymer#1305 |
| 434 this.async(function() { | 449 this.async(function() { |
| 435 this.upAction(); | 450 this.upAction(); |
| 436 }, 1); | 451 }, 1); |
| 437 }, | 452 }, |
| 438 | 453 |
| 439 /** @param {Event=} event */ | 454 /** |
| 455 * Provokes a ripple down effect via a UI event, |
| 456 * respecting the `noink` property. |
| 457 * @param {Event=} event |
| 458 */ |
| 459 uiDownAction: function(event) { |
| 460 if (!this.noink) { |
| 461 this.downAction(event); |
| 462 } |
| 463 }, |
| 464 |
| 465 /** |
| 466 * Provokes a ripple down effect via a UI event, |
| 467 * *not* respecting the `noink` property. |
| 468 * @param {Event=} event |
| 469 */ |
| 440 downAction: function(event) { | 470 downAction: function(event) { |
| 441 if (this.holdDown && this.ripples.length > 0) { | 471 if (this.holdDown && this.ripples.length > 0) { |
| 442 return; | 472 return; |
| 443 } | 473 } |
| 444 | 474 |
| 445 var ripple = this.addRipple(); | 475 var ripple = this.addRipple(); |
| 446 | 476 |
| 447 ripple.downAction(event); | 477 ripple.downAction(event); |
| 448 | 478 |
| 449 if (!this._animating) { | 479 if (!this._animating) { |
| 450 this.animate(); | 480 this.animate(); |
| 451 } | 481 } |
| 452 }, | 482 }, |
| 453 | 483 |
| 454 /** @param {Event=} event */ | 484 /** |
| 485 * Provokes a ripple up effect via a UI event, |
| 486 * respecting the `noink` property. |
| 487 * @param {Event=} event |
| 488 */ |
| 489 uiUpAction: function(event) { |
| 490 if (!this.noink) { |
| 491 this.upAction(event); |
| 492 } |
| 493 }, |
| 494 |
| 495 /** |
| 496 * Provokes a ripple up effect via a UI event, |
| 497 * *not* respecting the `noink` property. |
| 498 * @param {Event=} event |
| 499 */ |
| 455 upAction: function(event) { | 500 upAction: function(event) { |
| 456 if (this.holdDown) { | 501 if (this.holdDown) { |
| 457 return; | 502 return; |
| 458 } | 503 } |
| 459 | 504 |
| 460 this.ripples.forEach(function(ripple) { | 505 this.ripples.forEach(function(ripple) { |
| 461 ripple.upAction(event); | 506 ripple.upAction(event); |
| 462 }); | 507 }); |
| 463 | 508 |
| 464 this.animate(); | 509 this.animate(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 } | 562 } |
| 518 | 563 |
| 519 if (!this.shouldKeepAnimating && this.ripples.length === 0) { | 564 if (!this.shouldKeepAnimating && this.ripples.length === 0) { |
| 520 this.onAnimationComplete(); | 565 this.onAnimationComplete(); |
| 521 } else { | 566 } else { |
| 522 window.requestAnimationFrame(this._boundAnimate); | 567 window.requestAnimationFrame(this._boundAnimate); |
| 523 } | 568 } |
| 524 }, | 569 }, |
| 525 | 570 |
| 526 _onEnterKeydown: function() { | 571 _onEnterKeydown: function() { |
| 527 this.downAction(); | 572 this.uiDownAction(); |
| 528 this.async(this.upAction, 1); | 573 this.async(this.uiUpAction, 1); |
| 529 }, | 574 }, |
| 530 | 575 |
| 531 _onSpaceKeydown: function() { | 576 _onSpaceKeydown: function() { |
| 532 this.downAction(); | 577 this.uiDownAction(); |
| 533 }, | 578 }, |
| 534 | 579 |
| 535 _onSpaceKeyup: function() { | 580 _onSpaceKeyup: function() { |
| 536 this.upAction(); | 581 this.uiUpAction(); |
| 537 }, | 582 }, |
| 538 | 583 |
| 539 _holdDownChanged: function(holdDown) { | 584 // note: holdDown does not respect noink since it can be a focus based |
| 540 if (holdDown) { | 585 // effect. |
| 586 _holdDownChanged: function(newVal, oldVal) { |
| 587 if (oldVal === undefined) { |
| 588 return; |
| 589 } |
| 590 if (newVal) { |
| 541 this.downAction(); | 591 this.downAction(); |
| 542 } else { | 592 } else { |
| 543 this.upAction(); | 593 this.upAction(); |
| 544 } | 594 } |
| 595 }, |
| 596 |
| 597 _noinkChanged: function(noink, attached) { |
| 598 if (attached) { |
| 599 this.keyEventTarget = noink ? this : this.target; |
| 600 } |
| 545 } | 601 } |
| 546 }); | 602 }); |
| 547 })(); | 603 })(); |
| OLD | NEW |