76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassYUI.add('shim-plugin', function(Y) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Provides shimming support for Node via a Plugin.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * This fixes SELECT bleedthrough for IE6 & Mac scrollbars
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @module shim-plugin
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Node plugin which can be used to add shim support.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @class Plugin.Shim
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Object} User configuration object
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass function Shim(config) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this.init(config);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Default class used to mark the shim element
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith * @property CLASS_NAME
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type String
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @static
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default "yui-node-shim"
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // TODO: use ClassNameManager
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Shim.CLASS_NAME = 'yui-node-shim';
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Default markup template used to generate the shim element.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass *
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith * @property TEMPLATE
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type String
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @static
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Shim.TEMPLATE = '<iframe class="' + Shim.CLASS_NAME +
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass '" frameborder="0" title="Node Stacking Shim"' +
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass 'src="javascript:false" tabindex="-1" role="presentation"' +
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass 'style="position:absolute; z-index:-1;"></iframe>';
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Shim.prototype = {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass init: function(config) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._host = config.host;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this.initEvents();
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this.insert();
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this.sync();
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass initEvents: function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._resizeHandle = this._host.on('resize', this.sync, this);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass getShim: function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this._shim || (
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._shim = Y.Node.create(
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Shim.TEMPLATE,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._host.get('ownerDocument')
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass )
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass );
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass insert: function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var node = this._host;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._shim = node.insertBefore( this.getShim(),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass node.get('firstChild'));
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Updates the size of the shim to fill its container
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method sync
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass sync: function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var shim = this._shim,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass node = this._host;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (shim) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass shim.setAttrs({
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass width: node.getStyle('width'),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass height: node.getStyle('height')
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass });
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Removes the shim and destroys the plugin
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method destroy
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass destroy: function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var shim = this._shim;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (shim) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass shim.remove(true);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._resizeHandle.detach();
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Shim.NAME = 'Shim';
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Shim.NS = 'shim';
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.namespace('Plugin');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.Plugin.Shim = Shim;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass}, '@VERSION@' ,{requires:['node-style', 'node-pluginhost']});