Skip to main content

Bug Tracker

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)
  • show.diff (0.7 KB) - added by brandon March 22, 2007 07:59PM UTC.

    Patch

Change History (10)

Changed February 14, 2007 08:48PM UTC by Dave comment:1

Just creating a similar tag breaks for elements that change display type based on the cascade or a style, for example:

code {
  display: inline;
}
code.chunk {
  display: block;
}

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.

Changed February 14, 2007 09:45PM UTC by BenjaminWieg 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 john comment:3

type: bugenhancement

Changed March 22, 2007 08:00PM UTC by brandon comment:4

summary: Make .show() element-aware[PATCH] Make .show() element-aware

Changed March 24, 2007 05:19PM UTC by john comment:5

need: → Commit

Changed March 24, 2007 05:23PM UTC by john comment:6

milestone: → 1.1.3
summary: [PATCH] Make .show() element-awareMake .show() element-aware
type: enhancementbug
version: → 1.1.2

Changed June 30, 2007 12:43AM UTC by genezys 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 john 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 WiegandFrom 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.31.1.4
version: 1.1.21.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 brandon 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 brandon comment:10

resolution: → fixed
status: newclosed

Fixed in Rev [4074]