Home | History | Annotate | Download | only in paper-behaviors
      1 <!--
      2 @license
      3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
      4 This code may only be used under the BSD style license found at http://polymer.github.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/CONTRIBUTORS.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/PATENTS.txt
      9 -->
     10 
     11 <link rel="import" href="../polymer/polymer.html">
     12 <link rel="import" href="../iron-checked-element-behavior/iron-checked-element-behavior.html">
     13 <link rel="import" href="paper-inky-focus-behavior.html">
     14 
     15 <script>
     16 
     17   /**
     18    * Use `Polymer.PaperCheckedElementBehavior` to implement a custom element
     19    * that has a `checked` property similar to `Polymer.IronCheckedElementBehavior`
     20    * and is compatible with having a ripple effect.
     21    * @polymerBehavior Polymer.PaperCheckedElementBehavior
     22    */
     23   Polymer.PaperCheckedElementBehaviorImpl = {
     24 
     25     /**
     26      * Synchronizes the element's checked state with its ripple effect.
     27      */
     28     _checkedChanged: function() {
     29       Polymer.IronCheckedElementBehaviorImpl._checkedChanged.call(this);
     30       if (this.hasRipple()) {
     31         if (this.checked) {
     32           this._ripple.setAttribute('checked', '');
     33         } else {
     34           this._ripple.removeAttribute('checked');
     35         }
     36       }
     37     },
     38 
     39     /**
     40      * Synchronizes the element's `active` and `checked` state.
     41      */
     42     _buttonStateChanged: function() {
     43       Polymer.PaperRippleBehavior._buttonStateChanged.call(this);
     44       if (this.disabled) {
     45         return;
     46       }
     47       if (this.isAttached) {
     48         this.checked = this.active;
     49       }
     50     }
     51 
     52   };
     53 
     54   /** @polymerBehavior Polymer.PaperCheckedElementBehavior */
     55   Polymer.PaperCheckedElementBehavior = [
     56     Polymer.PaperInkyFocusBehavior,
     57     Polymer.IronCheckedElementBehavior,
     58     Polymer.PaperCheckedElementBehaviorImpl
     59   ];
     60 
     61 </script>
     62