align-plugin.js revision 752e31b910dbf30e2b803437da522585eca28528
/**
* Provides advanced positioning support for Node via a Plugin
* for centering and alignment.
* @module shim-plugin
*/
var OFFSET_WIDTH = 'offsetWidth',
OFFSET_HEIGHT = 'offsetHeight',
_resolveRegion = function(region) {
}
return region;
};
/**
* Node plugin which can be used to align a node with another node,
* region, or the viewport.
*
* @class Plugin.Align
* @param {Object} User configuration object
*/
// TODO: allow for boundingBox
};
/**
* Aligns node with a point on another node or region.
* Possible alignment points are:
* <dl>
* <dt>tl</dt>
* <dd>top left</dd>
* <dt>tr</dt>
* <dd>top right</dd>
* <dt>bl</dt>
* <dd>bottom left</dd>
* <dt>br</dt>
* <dd>bottom right</dd>
* <dt>tc</dt>
* <dd>top center</dd>
* <dt>bc</dt>
* <dd>bottom center</dd>
* <dt>rc</dt>
* <dd>right center</dd>
* <dt>lc</dt>
* <dd>left center</dd>
* </dl>
* @method to
* @parm region {Node || HTMLElement || Object} optional The node or
* region to align with. Defaults to the viewport region.
* @parm regionPoint {String} The point of the region to align with.
* @parm point {String} The point of the node aligned to the region.
* @parm fixed {Boolean} Whether or not the node should re-align when
* the window is resized. Defaults to false.
*/
point = regionPoint;
region = null;
}
x = left,
y = top,
xy;
switch(regionPoint) {
case 'tl':
break;
case 'tr':
x = right;
break;
case 'bl':
y = bottom;
break;
case 'br':
x = right;
y = bottom;
break;
case 'tc':
break;
case 'bc':
y = bottom;
break;
case 'lc':
break;
case 'rc':
x = right;
break;
case 'cc':
break;
}
switch (point) {
case 'tl':
xy = [x, y];
break;
case 'tr':
break;
case 'bl':
break;
case 'br':
break;
case 'tc':
break;
case 'bc':
break;
case 'lc':
break;
case 'rc':
break;
case 'cc':
break;
default:
}
if (fixed) {
this._attachResize(args);
} else {
this._detachResize();
}
}
},
_attachResize: function(args) {
var align = this;
this._resizeHandle = this._resizeHandle ||
Y.on('resize', function() {
setTimeout(function() {
});
}, window);
},
_detachResize: function(args) {
if (this._resizeHandle) {
this._resizeHandle.detach();
this._resizeHandle = null;
}
},
/**
* Aligns the center of a node to the center of another node or region.
* @method center
* @parm region {Node || HTMLElement || Object} optional The node or
* region to align with. Defaults to the viewport region.
* @parm fixed {Boolean} Whether or not the node should re-align when
* the window is resized. If centering to viewport, this defaults
* to true, otherwise default is false.
*/
fixed = true; // default to true when centering to viewport
}
},
/**
* Removes the resize handler, if any. This is called automatically
* when unplugged from the host node.
* @method destroy
*/
destroy: function() {
if (this._resizeHandle) {
this._resizeHandle.detach();
}
}
};
Y.namespace('Plugin');