|
1 /* |
|
2 YUI 3.10.3 (build 2fb5187) |
|
3 Copyright 2013 Yahoo! Inc. All rights reserved. |
|
4 Licensed under the BSD License. |
|
5 http://yuilibrary.com/license/ |
|
6 */ |
|
7 |
|
8 YUI.add('shim-plugin', function (Y, NAME) { |
|
9 |
|
10 /** |
|
11 * Provides shimming support for Node via a Plugin. |
|
12 * This fixes SELECT bleedthrough for IE6 & Mac scrollbars |
|
13 * @module shim-plugin |
|
14 */ |
|
15 |
|
16 /** |
|
17 * Node plugin which can be used to add shim support. |
|
18 * |
|
19 * @class Plugin.Shim |
|
20 * @param {Object} User configuration object |
|
21 */ |
|
22 function Shim(config) { |
|
23 this.init(config); |
|
24 } |
|
25 |
|
26 /** |
|
27 * Default class used to mark the shim element |
|
28 * |
|
29 * @property CLASS_NAME |
|
30 * @type String |
|
31 * @static |
|
32 * @default "yui-node-shim" |
|
33 */ |
|
34 // TODO: use ClassNameManager |
|
35 Shim.CLASS_NAME = 'yui-node-shim'; |
|
36 |
|
37 /** |
|
38 * Default markup template used to generate the shim element. |
|
39 * |
|
40 * @property TEMPLATE |
|
41 * @type String |
|
42 * @static |
|
43 */ |
|
44 Shim.TEMPLATE = '<iframe class="' + Shim.CLASS_NAME + |
|
45 '" frameborder="0" title="Node Stacking Shim"' + |
|
46 'src="javascript:false" tabindex="-1" role="presentation"' + |
|
47 'style="position:absolute; z-index:-1;"></iframe>'; |
|
48 |
|
49 Shim.prototype = { |
|
50 init: function(config) { |
|
51 this._host = config.host; |
|
52 this.initEvents(); |
|
53 this.insert(); |
|
54 this.sync(); |
|
55 }, |
|
56 |
|
57 initEvents: function() { |
|
58 this._resizeHandle = this._host.on('resize', this.sync, this); |
|
59 }, |
|
60 |
|
61 getShim: function() { |
|
62 return this._shim || ( |
|
63 this._shim = Y.Node.create( |
|
64 Shim.TEMPLATE, |
|
65 this._host.get('ownerDocument') |
|
66 ) |
|
67 ); |
|
68 }, |
|
69 |
|
70 insert: function() { |
|
71 var node = this._host; |
|
72 this._shim = node.insertBefore( this.getShim(), |
|
73 node.get('firstChild')); |
|
74 }, |
|
75 |
|
76 /** |
|
77 * Updates the size of the shim to fill its container |
|
78 * @method sync |
|
79 */ |
|
80 sync: function() { |
|
81 var shim = this._shim, |
|
82 node = this._host; |
|
83 |
|
84 if (shim) { |
|
85 shim.setAttrs({ |
|
86 width: node.getStyle('width'), |
|
87 height: node.getStyle('height') |
|
88 }); |
|
89 } |
|
90 }, |
|
91 |
|
92 /** |
|
93 * Removes the shim and destroys the plugin |
|
94 * @method destroy |
|
95 */ |
|
96 destroy: function() { |
|
97 var shim = this._shim; |
|
98 if (shim) { |
|
99 shim.remove(true); |
|
100 } |
|
101 |
|
102 this._resizeHandle.detach(); |
|
103 } |
|
104 }; |
|
105 |
|
106 Shim.NAME = 'Shim'; |
|
107 Shim.NS = 'shim'; |
|
108 |
|
109 Y.namespace('Plugin'); |
|
110 Y.Plugin.Shim = Shim; |
|
111 |
|
112 |
|
113 }, '3.10.3', {"requires": ["node-style", "node-pluginhost"]}); |