<commit_before>/*
 * jQuery UI menubar
 *
 * backported from <NAME>'s fork: http://www.nexul.com/prototypes/toolbar/demo.html
 */
(function($) {

// TODO take non-menubar buttons into account
$.widget("ui.menubar", {
   options: {
      buttons: false,
      menuIcon: false
   },
	_create: function() {
		var self = this;
		var items = this.items = this.element.children("button, a");
		var o = this.options;
				
		this.element.addClass('ui-menubar ui-widget-header ui-helper-clearfix');
		this._focusable(items);
		this._hoverable(items);
		items.next("ul").each(function(i, elm) {
			$(elm).menu({
				select: function(event, ui) {
					ui.item.parents("ul:last").hide()
					self.options.select.apply(this, arguments);
				}
			}).hide().keydown(function(event) {
				var menu = $(this);
				if (menu.is(":hidden")) 
					return;
				event.stopPropagation();
				switch (event.keyCode) {
				case $.ui.keyCode.LEFT:
					self.left(event);
					event.preventDefault();
					break;
				case $.ui.keyCode.RIGHT:
					self.right(event);
					event.preventDefault();
					break;
				};
			}).blur(function() {
				$(this).hide().prev().removeClass("ui-state-active").removeAttr("tabIndex");
				self.timer = setTimeout(function() {
					self.open = false;
				}, 13);
			});
		});
		items.each(function() {
			var input = $(this),
				   menu = input.next("ul");
			
			input.bind("click focus mouseenter", function(event) {
   				event.preventDefault();
   				event.stopPropagation();
			   	if (menu.is(":visible") && self.active && self.active[0] == menu[0]) {
					self._close();
					return;
				}
   				if (menu.length && (self.open || event.type == "click")) {
   					self._open(event, menu);
   				}
   			})
			.addClass("ui-button ui-widget ui-button-text-only ui-menubar-link")
			.wrapInner("<span class='ui-button-text'></span>");
			
			if (o.menuIcon) {
				input.addClass("ui-state-default").append("<span class='ui-button-icon-secondary ui-icon ui-icon-triangle-1-s'></span>");
				input.removeClass("ui-button-text-only").addClass("ui-button-text-icon-secondary");
			}
   			
			if (!o.buttons) {
				input.addClass('ui-menubar-link').removeClass('ui-state-default');
			};			
			
		});
		$(document).click(function(event) {
			!$(event.target).closest(".ui-menubar").length && self._close();
		});
	},
	
	_close: function() {<commit_msg>Menubar: Handle ESCAPE to close and refactor document-click code to also use _bind<commit_after>/*
 * jQuery UI menubar
 *
 * backported from <NAME>'s fork: http://www.nexul.com/prototypes/toolbar/demo.html
 */
(function($) {

// TODO take non-menubar buttons into account
$.widget("ui.menubar", {
   options: {
      buttons: false,
      menuIcon: false
   },
	_create: function() {
		var self = this;
		var items = this.items = this.element.children("button, a");
		var o = this.options;
				
		this.element.addClass('ui-menubar ui-widget-header ui-helper-clearfix');
		this._focusable(items);
		this._hoverable(items);
		items.next("ul").each(function(i, elm) {
			$(elm).menu({
				select: function(event, ui) {
					ui.item.parents("ul:last").hide()
					self.options.select.apply(this, arguments);
				}
			}).hide().keydown(function(event) {
				var menu = $(this);
				if (menu.is(":hidden")) 
					return;
				event.stopPropagation();
				switch (event.keyCode) {
				case $.ui.keyCode.LEFT:
					self.left(event);
					event.preventDefault();
					break;
				case $.ui.keyCode.RIGHT:
					self.right(event);
					event.preventDefault();
					break;
				};
			}).blur(function() {
				$(this).hide().prev().removeClass("ui-state-active").removeAttr("tabIndex");
				self.timer = setTimeout(function() {
					self.open = false;
				}, 13);
			});
		});
		items.each(function() {
			var input = $(this),
				   menu = input.next("ul");
			
			input.bind("click focus mouseenter", function(event) {
   				event.preventDefault();
   				event.stopPropagation();
			   	if (menu.is(":visible") && self.active && self.active[0] == menu[0]) {
					self._close();
					return;
				}
   				if (menu.length && (self.open || event.type == "click")) {
   					self._open(event, menu);
   				}
   			})
			.addClass("ui-button ui-widget ui-button-text-only ui-menubar-link")
			.wrapInner("<span class='ui-button-text'></span>");
			
			if (o.menuIcon) {
				input.addClass("ui-state-default").append("<span class='ui-button-icon-secondary ui-icon ui-icon-triangle-1-s'></span>");
				input.removeClass("ui-button-text-only").addClass("ui-button-text-icon-secondary");
			}
   			
			if (!o.buttons) {
				input.addClass('ui-menubar-link').removeClass('ui-state-default');
			};			
			
		});
		self._bind(document, {
			click: function(event) {
				!$(event.target).closest(".ui-menubar").length && self._close();
			}
		})
		self._bind({
			keyup: function(event) {
				if (event.keyCode == $.ui.keyCode.ESCAPE) {
					self._close();
				}
			}
		});
	},
	
	_close: function() {
{'fraction_non_alphanumeric': 0.1922687715037442, 'fraction_numerical': 0.0020238818053025702, 'mean_word_length': 2.9191118160190324, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '334203', 'n_tokens_mistral': 2050, 'n_tokens_neox': 1688, 'n_words': 267}