Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

domReady #1587

Closed
charbelrami opened this issue May 21, 2015 · 2 comments
Closed

domReady #1587

charbelrami opened this issue May 21, 2015 · 2 comments

Comments

@charbelrami
Copy link

In version 0.5

domReady: function() {
  this.fs = parseInt(window.getComputedStyle(this).height, 10) + 'px';
}

returns the height value of the element.

Without domReady in version 0.9, it returns NaN (height: auto) because the element has not been rendered yet.

Is there any alternative to domReady?

Thanks

@kevinpschaaf
Copy link
Member

DOM measurement should be performed in attached.

It is incorrect to perform DOM measurement in ready, since there is no guarantee that the element is actually in the DOM (e.g. document.createElement('your-element')). The 0.5 domReady did not have this guarantee either (and this is one of the reasons it was removed).

@charbelrami
Copy link
Author

Thanks. I have tried attached, but it also returns NaN.

In 0.5:

<polymer-element name="math-brack" attributes="l r">
  <template>
    <span class="math-font-x-light" style="font-size: {{fs}}">{{l}}</span>
    <content></content>
    <span class="math-font-x-light" style="font-size: {{fs}}">{{r}}</span>
  </template>
  <script>
    Polymer({
      l: '(',
      r: ')',
      domReady: function () {
        this.fs = parseInt(window.getComputedStyle(this).height, 10) + 'px';
      }
    });
  </script>
</polymer-element>

It works here: http://charbelrami.github.io/math-elements/
The size of the bracket changes according to the container size.

In 0.9:

<dom-module id="math-brack">
  <template>
    <span class="math-font-x-light" style$="{{fs}}">{{l}}</span>
    <content></content>
    <span class="math-font-x-light" style$="{{fs}}">{{r}}</span>
  </template>
</dom-module>
<script>
  Polymer({
    is: 'math-brack',
    properties: {
      l: {
        type: String,
        value: '('
      },
      r: {
        type: String,
        value: ')'
      }
    },
    attached: function() {
      this.fs = 'font-size: ' + parseInt(window.getComputedStyle(this).height, 10) + 'px';
    }
  });
</script>

It does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants