Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | (function() { |
| 2 | 'use strict'; |
| 3 | |
| 4 | /** |
| 5 | * https://github.com/google/material-design-lite/issues/4205 |
| 6 | * @constructor |
| 7 | * @param {Element} element The element that will be upgraded. |
| 8 | */ |
| 9 | const MaterialBasic = function MaterialBasic(element) { |
| 10 | // Stores the element. |
| 11 | this.element_ = element; |
| 12 | |
| 13 | console.log('***** ctor', this.element_.classList, 'data-upgraded', this.element_.getAttribute('data-upgraded')); |
| 14 | |
| 15 | // Initialize instance. |
| 16 | this.init(); |
| 17 | }; |
| 18 | window['MaterialBasic'] = MaterialBasic; |
| 19 | |
| 20 | /** |
| 21 | * Store constants in one place so they can be updated easily. |
| 22 | * |
| 23 | * @enum {string} |
| 24 | * @private |
| 25 | */ |
| 26 | MaterialBasic.prototype.Constant_ = { |
| 27 | RIPPLE_COMPONENT: 'MaterialRipple' |
| 28 | }; |
| 29 | |
| 30 | /** |
| 31 | * Store strings for class names defined by this component that are used in |
| 32 | * JavaScript. This allows us to simply change it in one place should we |
| 33 | * decide to modify at a later date. |
| 34 | * |
| 35 | * @enum {string} |
| 36 | * @private |
| 37 | */ |
| 38 | MaterialBasic.prototype.CssClasses_ = { |
| 39 | IS_UPGRADED: 'is-upgraded', |
| 40 | JS_RIPPLE_EFFECT: 'mdl-js-ripple-effect', |
| 41 | JS_RIPPLE_EFFECT_IGNORE_EVENTS: 'mdl-js-ripple-effect--ignore-events' |
| 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * Initialize component |
| 46 | */ |
| 47 | MaterialBasic.prototype.init = function() { |
| 48 | console.log('***** init', this.element_.classList, 'data-upgraded', this.element_.getAttribute('data-upgraded')); |
| 49 | |
| 50 | if (this.element_) { |
| 51 | if (this.element_.classList.contains(this.CssClasses_.JS_RIPPLE_EFFECT)) { |
| 52 | this.element_.classList.add(this.CssClasses_.JS_RIPPLE_EFFECT_IGNORE_EVENTS); |
| 53 | } |
| 54 | |
| 55 | // Do the init required for this component to work |
| 56 | |
| 57 | // Set upgraded flag |
| 58 | this.element_.classList.add(this.CssClasses_.IS_UPGRADED); |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | /** |
| 63 | * Downgrade component |
| 64 | * E.g remove listeners and clean up resources |
| 65 | */ |
| 66 | MaterialBasic.prototype.mdlDowngrade_ = function() { |
| 67 | 'use strict'; |
| 68 | }; |
| 69 | |
| 70 | // The component registers itself. It can assume componentHandler is available |
| 71 | // in the global scope. |
| 72 | /* eslint no-undef: 0 */ |
| 73 | /* jshint undef:false */ |
| 74 | componentHandler.register({ |
| 75 | constructor: MaterialBasic, |
| 76 | classAsString: 'MaterialBasic', |
| 77 | cssClass: 'mdl-js-basic' |
| 78 | }); |
| 79 | })(); |