Blame view

bower_components/jquery/src/css/defaultDisplay.js 1.82 KB
c5169e0e   Renato De Donato   a new hope
1
  define([
74249687   Luigi Serra   Cross browser con...
2
  	"../core",
74249687   Luigi Serra   Cross browser con...
3
  	"../manipulation" // appendTo
c5169e0e   Renato De Donato   a new hope
4
  ], function( jQuery ) {
74249687   Luigi Serra   Cross browser con...
5
6
  
  var iframe,
c5169e0e   Renato De Donato   a new hope
7
  	elemdisplay = {};
74249687   Luigi Serra   Cross browser con...
8
9
10
11
12
13
  
  /**
   * Retrieve the actual display of a element
   * @param {String} name nodeName of the element
   * @param {Object} doc Document object
   */
74249687   Luigi Serra   Cross browser con...
14
15
  // Called only from within defaultDisplay
  function actualDisplay( name, doc ) {
c5169e0e   Renato De Donato   a new hope
16
17
  	var style,
  		elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
74249687   Luigi Serra   Cross browser con...
18
  
c5169e0e   Renato De Donato   a new hope
19
20
21
22
23
24
  		// getDefaultComputedStyle might be reliably used only on attached element
  		display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
  
  			// Use of this method is a temporary fix (more like optimization) until something better comes along,
  			// since it was removed from specification and supported only in FF
  			style.display : jQuery.css( elem[ 0 ], "display" );
74249687   Luigi Serra   Cross browser con...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  
  	// We don't have any data stored on the element,
  	// so use "detach" method as fast way to get rid of the element
  	elem.detach();
  
  	return display;
  }
  
  /**
   * Try to determine the default display value of an element
   * @param {String} nodeName
   */
  function defaultDisplay( nodeName ) {
  	var doc = document,
  		display = elemdisplay[ nodeName ];
  
  	if ( !display ) {
  		display = actualDisplay( nodeName, doc );
  
  		// If the simple way fails, read from inside an iframe
  		if ( display === "none" || !display ) {
  
  			// Use the already-created iframe if possible
c5169e0e   Renato De Donato   a new hope
48
  			iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
74249687   Luigi Serra   Cross browser con...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  
  			// Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
  			doc = iframe[ 0 ].contentDocument;
  
  			// Support: IE
  			doc.write();
  			doc.close();
  
  			display = actualDisplay( nodeName, doc );
  			iframe.detach();
  		}
  
  		// Store the correct default display
  		elemdisplay[ nodeName ] = display;
  	}
  
  	return display;
  }
  
  return defaultDisplay;
c5169e0e   Renato De Donato   a new hope
69
70
  
  });