Loading ...
Sorry, an error occurred while loading the content.

Safari and getStyle

Expand Messages
  • Rhett Garber
    Much to my dismay I discovered that the YAHOO.util.Dom.getStyle method does not work in Safari 2.0.3 when you want the style from an element specified in a
    Message 1 of 3 , Apr 2, 2006
    • 0 Attachment
      Much to my dismay I discovered that the YAHOO.util.Dom.getStyle method does not work
      in Safari 2.0.3 when you want the style from an element specified in a stylesheet included
      from a file.

      For example, I have a div 'post_comment' that is styled to be 'display: none'.

      I call the getStyle method, which falls through the various attempts to cover browser
      inconsitencies into the final case:

      else if ( dv && dv.getComputedStyle )
      { // convert camelCase to hyphen-case

      var converted = '';
      for(i = 0, len = property.length;i < len; ++i) {
      if (property.charAt(i) == property.charAt(i).toUpperCase()) {
      converted = converted + '-' + property.charAt(i).toLowerCase();
      } else {
      converted = converted + property.charAt(i);
      }
      }

      if (dv.getComputedStyle(el, null).getPropertyValue(converted)) {
      value = dv.getComputedStyle(el, null).getPropertyValue(converted);
      }
      }

      Now, dv.getComputedStyle exists in Safari 2, however when you actually try to use it
      (dv.getComputedStyle(el, "")), it returns null because the element has been modified by a
      stylesheet. Note that this does work if you are using styles defined in the same HTML file.

      Clearly a Safari defect, but how can I modify these wonderful Yahoo libraries to work
      around it?
    • Rhett Garber
      Here is an update, already. The problem appears to only show up if the display style is set to none . I guess the computedStyle for a non-visable element
      Message 2 of 3 , Apr 2, 2006
      • 0 Attachment
        Here is an update, already.

        The problem appears to only show up if the display style is set to 'none'.

        I guess the computedStyle for a non-visable element doesn't exist.

        Tricky.

        Rhett
      • Matt Sweeney
        Hi Rhett, To get around the Safari error for this case, modify the following line: if (dv.getComputedStyle(el, null).getPropertyValue(converted)) { value =
        Message 3 of 3 , Apr 3, 2006
        • 0 Attachment
          Hi Rhett,

          To get around the Safari error for this case, modify the following line:

          if (dv.getComputedStyle(el, null).getPropertyValue(converted)) {
          value = dv.getComputedStyle(el, null).getPropertyValue(converted);
          }

          to be:

          if (dv.getComputedStyle(el, null) && dv.getComputedStyle(el, null).getPropertyValue(converted)) {
          value = dv.getComputedStyle(el, null).getPropertyValue(converted);
          }

          This will be rolled into the next release.

          Thanks,

          Matt


          Rhett Garber wrote:

          >Here is an update, already.
          >
          >The problem appears to only show up if the display style is set to 'none'.
          >
          >I guess the computedStyle for a non-visable element doesn't exist.
          >
          >Tricky.
          >
          >Rhett
          >
          >
          >
          >
          >
          >
          >Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.