<commit_before>(function($) {
$.fn.bkviewer_rounded_box = function(options) {
return this.each(function() {
	var t = $(this);
	var hiddens = new Object();

	function remove_item(hiddens, i) {
		var items = hiddens.items, head, tail;

		head = items.slice(0, i);
		tail = items.slice(i+1, items.length);
		hiddens.items = head.concat(tail);
	}

	function toggle_and_save(box, title, hiddens) {
		var prefs = nsPreferences;
		var key = "extensions.bkviewer.hiddens";

		box.slideToggle(function() {
			var box = $(this);
			var i = hiddens.items.indexOf(title);

			if (box.css('display') == 'none') {
				if (i == -1)
					hiddens.items.push(title);
			} else {
				if (i != -1)
					remove_item(hiddens, i);
			}

			prefs.setUnicharPref(key,
					     JSON.stringify(hiddens.items));
		});
	}

	t.show_bookmarks({
		add_category_view: function(json, target, context) {
			var result, box = target;

			box = $('<ul />').addClass('bk-category')
					 .appendTo(box);

			$('<li />').text(json['title'])
				   .addClass('bk-category')
				   .appendTo(box)
				   .click(function() {
					toggle_and_save($(this).next(),
							json['title'],
							hiddens);
				   });

			box = $('<ul />').addClass('bk-item')
					 .appendTo(box);

			context.cur_box = box;
		},

		add_item_view: function(json, target, context) {
			var box = context.cur_box, atag;
			var default_height;

			box = $('<li />').addClass('bk-item')
					 .appendTo(box);

			atag = $('<a />').text(json['title'])
				  .attr({'href': json['uri']})
				  .addClass('bk-item')
				  .appendTo(box);

			$('<img />').addClass('favicon')
				    .attr({'src': json['favicon']})
				    .prependTo(atag);
		},
	});

	$('ul.bk-item').addClass('bv-clearfix')
		       .each(function() {
		var t = $(this);
		var item = t.find('li.bk-item');

		$(window).resize(function() {
					equal_spacing(t, item);
				 });

		equal_spacing(t, item);
	});

	get_hiddens(hiddens);

	function get_hiddens(hiddens) {
		var prefs = nsPreferences;
		var key = "extensions.bkviewer.hiddens";

		hiddens.items = JSON.parse(prefs.copyUnicharPref(key, "[]"));
	}

	function equal_spacing(box, contents) {
		var box_width, item_width, items_num, margin;

		contents.width("");
		contents.css("margin-right", 0);

		item_width = 0;
		contents.each(function() {
			if (item_width < $(this).width()) {
				item_width = $(this).width();
			}
		});

		contents.width(item_width + 1);
<commit_msg>Hides categories according to the preference when opening bkviewer page<commit_after>(function($) {
$.fn.bkviewer_rounded_box = function(options) {
return this.each(function() {
	var t = $(this);
	var hiddens = new Object();

	function remove_item(hiddens, i) {
		var items = hiddens.items, head, tail;

		head = items.slice(0, i);
		tail = items.slice(i+1, items.length);
		hiddens.items = head.concat(tail);
	}

	function toggle_and_save(box, title, hiddens) {
		var prefs = nsPreferences;
		var key = "extensions.bkviewer.hiddens";

		box.slideToggle(function() {
			var box = $(this);
			var i = hiddens.items.indexOf(title);

			if (box.css('display') == 'none') {
				if (i == -1)
					hiddens.items.push(title);
			} else {
				if (i != -1)
					remove_item(hiddens, i);
			}

			prefs.setUnicharPref(key,
					     JSON.stringify(hiddens.items));
		});
	}

	t.show_bookmarks({
		add_category_view: function(json, target, context) {
			var result, box = target;

			box = $('<ul />').addClass('bk-category')
					 .appendTo(box);

			$('<li />').text(json['title'])
				   .addClass('bk-category')
				   .appendTo(box)
				   .click(function() {
					toggle_and_save($(this).next(),
							json['title'],
							hiddens);
				   });

			box = $('<ul />').addClass('bk-item')
					 .appendTo(box);

			context.cur_box = box;
		},

		add_item_view: function(json, target, context) {
			var box = context.cur_box, atag;
			var default_height;

			box = $('<li />').addClass('bk-item')
					 .appendTo(box);

			atag = $('<a />').text(json['title'])
				  .attr({'href': json['uri']})
				  .addClass('bk-item')
				  .appendTo(box);

			$('<img />').addClass('favicon')
				    .attr({'src': json['favicon']})
				    .prependTo(atag);
		},
	});

	$('ul.bk-item').addClass('bv-clearfix')
		       .each(function() {
		var t = $(this);
		var item = t.find('li.bk-item');

		$(window).resize(function() {
					equal_spacing(t, item);
				 });

		equal_spacing(t, item);
	});

	hide_categories(t, hiddens);

	function hide_categories(target, hiddens) {
		/* Users may change titles, so this synchronize
		 * the preferences with the actual titles.
		 */
		var prefs = nsPreferences;
		var key = "extensions.bkviewer.hiddens";
		var new_hiddens = [];
		var i, box, title;

		hiddens.items = JSON.parse(prefs.copyUnicharPref(key, "[]"));
		target.find('ul.bk-category').each(function() {
			box = $(this);
			title = box.children('li').text();
			i = hiddens.items.indexOf(title);
			if (i != -1) {
				box.children('ul').hide();
				new_hiddens.push(title);
			}
		});

		hiddens.items = new_hiddens;
		prefs.setUnicharPref(key, JSON.stringify(hiddens.items));
	}

	function equal_spacing(box, contents) {
		var box_width, item_width, items_num, margin;

		contents.width("");
		contents.css("margin-right", 0);

		item_width = 0;
		contents.each(function() {
			if (item_width < $(this).width()) {
				item_width = $(this).width();
			}
		});

		contents.width(item_width + 1);

{'fraction_non_alphanumeric': 0.1921300572695363, 'fraction_numerical': 0.0027711065952336967, 'mean_word_length': 3.151840490797546, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '221637', 'n_tokens_mistral': 2380, 'n_tokens_neox': 1940, 'n_words': 362}