Skip to content

Instantly share code, notes, and snippets.

@cduruk
Created May 28, 2009 20:26
Show Gist options
  • Save cduruk/119548 to your computer and use it in GitHub Desktop.
Save cduruk/119548 to your computer and use it in GitHub Desktop.
YUI().use('node', 'plugin',
function(Y) {
var PieMenu = function(config) {
this.init(config);
};
//Plugin Settings
PieMenu.NAME = 'piemenu';
PieMenu.NS = 'pm';
//Defaults
//TODO Support to change these somehow (like JQuery's $.extend)
PieMenu.STARTER_CLASSNAME = 'piemenu_starter';
PieMenu.LIST_CLASSNAME = 'piemenu_list';
PieMenu.STARTER_SELECTOR = '.' + PieMenu.STARTER_CLASSNAME;
PieMenu.LIST_SELECTOR = '.' + PieMenu.LIST_CLASSNAME + ' li';
PieMenu.DEFAULT_WIDTH = 50;
PieMenu.prototype = {
init: function(config) {
this.owner = config.owner;
this.owner.on('click', this.onClick, this);
this.hideList();
},
createMenu: function(information) {
var _size = list.size();
var information = {
size: _size,
step: (2.0 * Math.PI) / (1.0 * (_size)),
rotation: (0.5) * Math.PI,
radius: Math.sqrt(PieMenu.DEFAULT_WIDTH) * Math.sqrt(_size) * 2.5,
xPos: information.xPos,
yPos: information.yPos
};
this.createLeafs(information);
},
createLeafs: function(information) {
for (var i = 0; i < information.size; i++) {
var angle = i * information.step - information.rotation;
var xCor = information.xPos + Math.cos(angle) * information.radius - (PieMenu.DEFAULT_WIDTH / 2);
var yCor = information.yPos + Math.sin(angle) * information.radius - (PieMenu.DEFAULT_WIDTH / 2);
var leaf = list.item(i);
leaf.setXY([xCor, yCor]);
leaf.setStyle('position', 'absolute');
leaf.setStyle('display', 'block');
}
},
//hide the list that will be used for the pie menu
hideList: function() {
Y.all(PieMenu.LIST_SELECTOR).setStyle('display', 'none');
},
//Hide borders on links for FF
//See https://bugzilla.mozilla.org/show_bug.cgi?id=452915
//TODO Use UA and run this only on FF (worth it?)
hideBorders: function() {
},
onClick: function(e) {
var information = {
xPos: e.pageX,
yPos: e.pageY
};
this.createMenu(information);
}
};
//var list = Y.all(PieMenu.LIST_SELECTOR);
var starter = Y.get(PieMenu.STARTER_SELECTOR);
var list = Y.all(PieMenu.LIST_SELECTOR);
starter.plug(PieMenu);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment