Side navigation
#960 closed bug (fixed)
Opened February 14, 2007 07:57PM UTC
Closed December 08, 2007 04:56AM UTC
Make .show() element-aware
Reported by: | john | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.1.4 |
Component: | effects | Version: | 1.1.3 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
From here:
http://www.nabble.com/%24.show%28%29-improvement-tf3228045.html
the jquery function show() is at the moment making objects visible by
running
elm.style.display = 'block';
This works just fine for all block elements (div, etc.) but causes some
problems when running on inline elements like links or other elements like
table-cells.
I think it'd be better to do this:
elm.style.display = get_type(elm);
function get_type(elm) {
obj = document.createElement(elm.tagName);
$('body').append(obj);
type = $.curCSS(obj, 'display');
$(obj).remove();
return type;
}
This works for divs as well as for cells.
Benjamin Wiegand
Attachments (1)
Change History (10)
Changed February 14, 2007 08:48PM UTC by comment:1
Changed February 14, 2007 09:45PM UTC by comment:2
>> Doesn't setting el.style.display="" revert to the default display type?
el.style.display = "" doesn't set display to the standard display but to the display defined in the CSS (which may be also "none")
Changed February 26, 2007 11:44PM UTC by comment:3
type: | bug → enhancement |
---|
Changed March 22, 2007 08:00PM UTC by comment:4
summary: | Make .show() element-aware → [PATCH] Make .show() element-aware |
---|
Changed March 24, 2007 05:19PM UTC by comment:5
need: | → Commit |
---|
Changed March 24, 2007 05:23PM UTC by comment:6
milestone: | → 1.1.3 |
---|---|
summary: | [PATCH] Make .show() element-aware → Make .show() element-aware |
type: | enhancement → bug |
version: | → 1.1.2 |
Changed June 30, 2007 12:43AM UTC by comment:7
Sorry to spam but I do really think that this patch is overkill.
Just calling removeAttribute("display") on the element will just revert the display back to its default value (set in CSS by the designer). I really think that there is no issue with that and that this behaviour is better than the one in the patch.
If a <div> element is defined "inline" in the CSS, a hide()/show() should keep this setting and not revert the div to "block" just because this is the default display for a div.
Changed July 21, 2007 02:45AM UTC by comment:8
description: | From here:\ http://www.nabble.com/%24.show%28%29-improvement-tf3228045.html\ \ the jquery function show() is at the moment making objects visible by\ running\ elm.style.display = 'block';\ \ This works just fine for all block elements (div, etc.) but causes some\ problems when running on inline elements like links or other elements like\ table-cells.\ \ I think it'd be better to do this:\ \ elm.style.display = get_type(elm);\ \ function get_type(elm) {\ obj = document.createElement(elm.tagName);\ $('body').append(obj);\ type = $.curCSS(obj, 'display');\ $(obj).remove();\ return type;\ }\ \ This works for divs as well as for cells.\ \ Benjamin Wiegand → From here: \ http://www.nabble.com/%24.show%28%29-improvement-tf3228045.html \ \ the jquery function show() is at the moment making objects visible by \ running \ elm.style.display = 'block'; \ \ This works just fine for all block elements (div, etc.) but causes some \ problems when running on inline elements like links or other elements like \ table-cells. \ \ I think it'd be better to do this: \ \ elm.style.display = get_type(elm); \ \ function get_type(elm) { \ obj = document.createElement(elm.tagName); \ $('body').append(obj); \ type = $.curCSS(obj, 'display'); \ $(obj).remove(); \ return type; \ } \ \ This works for divs as well as for cells. \ \ Benjamin Wiegand |
---|---|
milestone: | 1.1.3 → 1.1.4 |
version: | 1.1.2 → 1.1.3 |
Marked #1208 as a duplicate of this bug (some good test cases were provided with it).
Changed December 07, 2007 03:08AM UTC by comment:9
Replying to [comment:7 genezys]:
First we remove the display style property and then and only then if the element is still hidden do we try and figure out its default display style vs just using block.
Changed December 08, 2007 04:56AM UTC by comment:10
resolution: | → fixed |
---|---|
status: | new → closed |
Fixed in Rev [4074]
Just creating a similar tag breaks for elements that change display type based on the cascade or a style, for example:
That particular example could be fixed by using clone but the general case can't.
Doesn't setting el.style.display="" revert to the default display type? I think currentStyle/getComputedStyle return the actual display type when you do that, but I haven't tested it for a while and don't know what Safari would do with it.