<commit_before>/*
---
name: ART.Menu
description: Menu PseudoClass
requires: [ART.Sheet, ART.Widget, ART/ART.Rectangle, ART.Keyboard]
provides: ART.Menu
...
*/

ART.Sheet.define('menu.art', {
	'width': 150,
	'border-color': 'hsb(0, 0, 0, 0.3)',
	'background-color': 'hsb(0, 0, 100, 0.98)',
	'selection-color': 'red',
	
	'border-radius': [5, 5, 5, 5],
	
	'font-family': 'Arial',
	'font-variant': 'normal',
	'font-size': 12,
	'font-color': 'hsb(0, 0, 5)',
	
	'padding': [5, 0, 5, 0],
	'item-padding': [2, 10, 2, 10]
});

(function(){
	
var Menu = ART.Menu = new Class({
	
	Extends: ART.Widget,
	
	name: 'menu',
	
	options: {
		left: null,
		top: null
	},
	
	initialize: function(options, menu, handlers){
		this.parent(options);
		
		this.borderLayer = new ART.Rectangle;
		this.backgroundLayer = new ART.Rectangle;
		this.canvas.grab(this.borderLayer, this.backgroundLayer);
		
		this.menu = menu.setStyles({
			position: 'absolute',
			top: 0,
			left: 0
		});
		
		this.element.grab(this.menu);
		
		this.element.setStyles({'position': 'absolute', top: 0, left: 0});
		
		var self = this;
		
		this.element.addEvent('blur', function(){
			self.hide();
		});
		
		this.handlers = $$(handlers);
		
		var selectedIndex = -1, link;
		
		if (this.handlers.length) this.handlers.addEvents({
				
			'mousedown': function(e){
				e.stopPropagation().preventDefault();
				var left = $lambda(self.options.left)(), top = $lambda(self.options.top)();
				self.show((left != null) ? left : e.client.x, (top != null) ? top : e.client.y);
				selectedIndex = -1;
			}

		});

		var selectLink = function(link){
			if (!link) return;
			self.links.removeClass('selected');
			link.addClass('selected');
			selectedIndex = self.links.indexOf(link);
		};

		this.links = this.menu.getElements('a').addEvents({

			'mouseup': function(e){
				self.hide();
				e.stopPropagation().preventDefault();
			},

			'mousedown': function(e){
				e.stopPropagation().preventDefault();
			},
			
			mouseenter: function(){
				selectLink(this);
			},<commit_msg> - the Menu class now fires a press event passing the menu item clicked / keyboarded.<commit_after>/*
---
name: ART.Menu
description: Menu PseudoClass
requires: [ART.Sheet, ART.Widget, ART/ART.Rectangle, ART.Keyboard]
provides: ART.Menu
...
*/

ART.Sheet.define('menu.art', {
	'width': 150,
	'border-color': 'hsb(0, 0, 0, 0.3)',
	'background-color': 'hsb(0, 0, 100, 0.98)',
	'selection-color': 'red',
	
	'border-radius': [5, 5, 5, 5],
	
	'font-family': 'Arial',
	'font-variant': 'normal',
	'font-size': 12,
	'font-color': 'hsb(0, 0, 5)',
	
	'padding': [5, 0, 5, 0],
	'item-padding': [2, 10, 2, 10]
});

(function(){
	
var Menu = ART.Menu = new Class({
	
	Extends: ART.Widget,
	
	name: 'menu',
	
	options: {
		left: null,
		top: null
	},
	
	initialize: function(options, menu, handlers){
		this.parent(options);
		
		this.borderLayer = new ART.Rectangle;
		this.backgroundLayer = new ART.Rectangle;
		this.canvas.grab(this.borderLayer, this.backgroundLayer);
		
		this.menu = menu.setStyles({
			position: 'absolute',
			top: 0,
			left: 0
		});
		
		this.element.grab(this.menu);
		
		this.element.setStyles({'position': 'absolute', top: 0, left: 0});
		
		var self = this;
		
		this.element.addEvent('blur', function(){
			self.hide();
		});
		
		this.handlers = $$(handlers);
		
		var selectedIndex = -1, link;
		
		if (this.handlers.length) this.handlers.addEvents({
				
			'mousedown': function(e){
				e.stopPropagation().preventDefault();
				var left = $lambda(self.options.left)(), top = $lambda(self.options.top)();
				self.show((left != null) ? left : e.client.x, (top != null) ? top : e.client.y);
				selectedIndex = -1;
			}

		});

		var selectLink = function(link){
			if (!link) return;
			self.links.removeClass('selected');
			link.addClass('selected');
			selectedIndex = self.links.indexOf(link);
		};

		this.links = this.menu.getElements('a').addEvents({

			mouseup: function(e){
				self.fireEvent('click', this);
				self.hide();
				e.stopPropagation().preventDefault();
			},

			mousedown: function(e){
				e.stopPropagation().preventDefault();
			},
			
			mouseenter: function(){
				selectLink(this);
			},
{'fraction_non_alphanumeric': 0.19305389221556887, 'fraction_numerical': 0.019640718562874252, 'mean_word_length': 3.391167192429022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '209466', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1476, 'n_words': 318}