<commit_before>define(
	[ "knockout", "jquery", "jquery-ui"],
	function(ko, $) {
		self.activeTab = ko.observable(topicexplorerModel.view.activeTab).publishOn("TabView.activeTab");
		self.activeModule = ko.observable(topicexplorerModel.view.tab[self.activeTab()].module);
//		self.activeTab.subscribe(function(newValue) {
//			console.log(topicexplorerModel.view.tab[newValue].module);
//			self.activeModule(topicexplorerModel.view.tab[newValue].module);
//			ko.postbox.publish("TabView.activeTab", newValue);			
//		});
		
		self.tabs = ko.observableArray(topicexplorerModel.view.tabs);
		self.invisibleTabs = ko.observableArray(topicexplorerModel.view.invisbleTabs);
		
		self.windowWidth = ko.observable(topicexplorerModel.view.windowWidth).subscribeTo("windowWidth");

		self.windowWidth.subscribe(function(newValue) {
			topicexplorerModel.view.windowWidth = newValue;
			var allTabs = topicexplorerModel.view.invisibleTabs.concat(topicexplorerModel.view.tabs);
			if($("#desktop").width() / allTabs.length >= 200) {
				topicexplorerModel.view.tabs = allTabs;
				topicexplorerModel.view.invisibleTabs = new Array();
			} else {
				var numVisibleTabs = Math.floor(($("#desktop").width() - 76) / 200);
				topicexplorerModel.view.invisibleTabs = allTabs.slice(0, allTabs.length - numVisibleTabs);
				topicexplorerModel.view.tabs = allTabs.slice(allTabs.length - numVisibleTabs);			
			}
			self.invisibleTabs(topicexplorerModel.view.invisibleTabs);
			self.tabs(topicexplorerModel.view.tabs);
		});
		
		self.setActive = function(allowLoading) {
//			
			if(!allowLoading) topicexplorerModel.data.documentsLoading(true);
			$("#desktop").scrollTop(0);
			$(".tab").removeClass('active');
			$("#tab" + topicexplorerModel.view.activeTab).addClass('active');
			
			self.activeTab(topicexplorerModel.view.activeTab);	
						
			if(self.activeModule() != topicexplorerModel.view.tab[topicexplorerModel.view.activeTab].module) {
				self.activeModule(topicexplorerModel.view.tab[topicexplorerModel.view.activeTab].module);
			}
			
			ko.postbox.publish("TabView.activeTab", topicexplorerModel.view.activeTab);	
			
//			ko.postbox.publish("TabView.activeTab", topicexplorerModel.view.activeTab);
//			console.log("newTab");
			
			$("#desktop").scrollTop(topicexplorerModel.view.tab[topicexplorerModel.view.activeTab].scrollPosition);
			if(!allowLoading) topicexplorerModel.data.documentsLoading(false);
		};
		self.toggleActive = function(active) {
			$('#tabMenu').hide();
			topicexplorerModel.view.tab[topicexplorerModel.view.activeTab].scrollPosition = $("#desktop").scrollTop();
			topicexplorerModel.view.activeTab = active;
			var index = $.inArray(active, self.invisibleTabs());
			if(index > -1) {
				topicexplorerModel.view.invisibleTabs.splice(index, 1);
				var newInvisibleTab = topicexplorerModel.view.tabs.shift();
				topicexplorerModel.view.invisibleTabs.push(newInvisibleTab);
				topicexplorerModel.view.tabs.unshift(active);
				self.invisibleTabs(topicexplorerModel.view.invisibleTabs);
				self.tabs(topicexplorerModel.view.tabs);
			}			
			self.setActive(false);	
		};
		self.deleteTab = function(tab) {
			if(topicexplorerModel.view.tabs.length < 2) {
				alert("Ein Tab muss bleiben!");
				return;
			}
	
			var tabIndex = $.inArray(tab, topicexplorerModel.view.tabs);
			
			topicexplorerModel.view.tabs.splice(tabIndex, 1);
			delete topicexplorerModel.view.tab[tab];
			
			if(self.invisibleTabs().length > 0) {
				var newTabIndex = topicexplorerModel.view.invisibleTabs.shift();
				topicexplorerModel.view.tabs.unshift(newTabIndex);
				self.invisibleTabs(topicexplorerModel.view.invisibleTabs);
			}
				 
			self.tabs(topicexplorerModel.view.tabs);
			
			if(topicexplorerModel.view.activeTab == tab) {
				if(tabIndex > topicexplorerModel.view.tabs.length - 1) {
					tabIndex = topicexplorerModel.view.tabs.length - 1;			
				}
				topicexplorerModel.view.activeTab = topicexplorerModel.view.tabs[tabIndex];
				self.setActive(false);
			}			
		};
		
		self.deleteAllHidden = function() {
			if(confirm("Alle " + self.invisibleTabs().length + " unsichtbaren Tabs loeschen?")) {
				for(key in topicexplorerModel.view.invisibleTabs) {
					delete(topicexplorerModel.view.tab[topicexplorerModel.view.invisibleTabs[key]]);
				}
				
				topicexplorerModel.view.invisibleTabs = new Array();<commit_msg>#48 sometimes it's better not deleting objects when they are still needed<commit_after>define(
	[ "knockout", "jquery", "jquery-ui"],
	function(ko, $) {
		self.activeTab = ko.observable(topicexplorerModel.view.activeTab).publishOn("TabView.activeTab");
		self.activeModule = ko.observable(topicexplorerModel.view.tab[self.activeTab()].module);
//		self.activeTab.subscribe(function(newValue) {
//			console.log(topicexplorerModel.view.tab[newValue].module);
//			self.activeModule(topicexplorerModel.view.tab[newValue].module);
//			ko.postbox.publish("TabView.activeTab", newValue);			
//		});
		
		self.tabs = ko.observableArray(topicexplorerModel.view.tabs);
		self.invisibleTabs = ko.observableArray(topicexplorerModel.view.invisbleTabs);
		
		self.windowWidth = ko.observable(topicexplorerModel.view.windowWidth).subscribeTo("windowWidth");

		self.windowWidth.subscribe(function(newValue) {
			topicexplorerModel.view.windowWidth = newValue;
			var allTabs = topicexplorerModel.view.invisibleTabs.concat(topicexplorerModel.view.tabs);
			if($("#desktop").width() / allTabs.length >= 200) {
				topicexplorerModel.view.tabs = allTabs;
				topicexplorerModel.view.invisibleTabs = new Array();
			} else {
				var numVisibleTabs = Math.floor(($("#desktop").width() - 76) / 200);
				topicexplorerModel.view.invisibleTabs = allTabs.slice(0, allTabs.length - numVisibleTabs);
				topicexplorerModel.view.tabs = allTabs.slice(allTabs.length - numVisibleTabs);			
			}
			self.invisibleTabs(topicexplorerModel.view.invisibleTabs);
			self.tabs(topicexplorerModel.view.tabs);
		});
		
		self.setActive = function(allowLoading) {
//			
			if(!allowLoading) topicexplorerModel.data.documentsLoading(true);
			$("#desktop").scrollTop(0);
			$(".tab").removeClass('active');
			$("#tab" + topicexplorerModel.view.activeTab).addClass('active');
			
			self.activeTab(topicexplorerModel.view.activeTab);	
						
			if(self.activeModule() != topicexplorerModel.view.tab[topicexplorerModel.view.activeTab].module) {
				self.activeModule(topicexplorerModel.view.tab[topicexplorerModel.view.activeTab].module);
			}
			
			ko.postbox.publish("TabView.activeTab", topicexplorerModel.view.activeTab);	
			
//			ko.postbox.publish("TabView.activeTab", topicexplorerModel.view.activeTab);
//			console.log("newTab");
			
			$("#desktop").scrollTop(topicexplorerModel.view.tab[topicexplorerModel.view.activeTab].scrollPosition);
			if(!allowLoading) topicexplorerModel.data.documentsLoading(false);
		};
		self.toggleActive = function(active) {
			$('#tabMenu').hide();
			topicexplorerModel.view.tab[topicexplorerModel.view.activeTab].scrollPosition = $("#desktop").scrollTop();
			topicexplorerModel.view.activeTab = active;
			var index = $.inArray(active, self.invisibleTabs());
			if(index > -1) {
				topicexplorerModel.view.invisibleTabs.splice(index, 1);
				var newInvisibleTab = topicexplorerModel.view.tabs.shift();
				topicexplorerModel.view.invisibleTabs.push(newInvisibleTab);
				topicexplorerModel.view.tabs.unshift(active);
				self.invisibleTabs(topicexplorerModel.view.invisibleTabs);
				self.tabs(topicexplorerModel.view.tabs);
			}			
			self.setActive(false);	
		};
		self.deleteTab = function(tab) {
			if(topicexplorerModel.view.tabs.length < 2) {
				alert("Ein Tab muss bleiben!");
				return;
			}
	
			var tabIndex = $.inArray(tab, topicexplorerModel.view.tabs);
			
			topicexplorerModel.view.tabs.splice(tabIndex, 1);
			
			
			if(self.invisibleTabs().length > 0) {
				var newTabIndex = topicexplorerModel.view.invisibleTabs.shift();
				topicexplorerModel.view.tabs.unshift(newTabIndex);
				self.invisibleTabs(topicexplorerModel.view.invisibleTabs);
			}
				 
			self.tabs(topicexplorerModel.view.tabs);
			
			if(topicexplorerModel.view.activeTab == tab) {
				if(tabIndex > topicexplorerModel.view.tabs.length - 1) {
					tabIndex = topicexplorerModel.view.tabs.length - 1;			
				}
				topicexplorerModel.view.activeTab = topicexplorerModel.view.tabs[tabIndex];
				self.setActive(false);
			}		
			
			delete topicexplorerModel.view.tab[tab];
		};
		
		self.deleteAllHidden = function() {
			if(confirm("Alle " + self.invisibleTabs().length + " unsichtbaren Tabs loeschen?")) {
				for(key in topicexplorerModel.view.invisibleTabs) {
					delete(topicexplorerModel.view.tab[topicexplorerModel.view.invisibleTabs[key]]);
				}
				
				topicexplorerModel.view.invisibleTabs = new Array();
{'fraction_non_alphanumeric': 0.14205778234555214, 'fraction_numerical': 0.0041109969167523125, 'mean_word_length': 4.553582752060875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '4258185', 'n_tokens_mistral': 3574, 'n_tokens_neox': 3071, 'n_words': 294}