From 686be824b520e4f04e634846b415e82ed9fb1c4d Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Fri, 12 Aug 2011 22:18:38 +0200
Subject: [PATCH] hide settings menu when clicking outside it

---
 core/js/js.js       | 11 ++++++-
 core/js/listview.js | 71 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100644 core/js/listview.js

diff --git a/core/js/js.js b/core/js/js.js
index 8ac999a104..677cd5fbb7 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -283,12 +283,21 @@ $(document).ready(function(){
 	});
 
 	if($('body').attr("id")=="body-user") { $('#settings #expanddiv').hide(); }
-	$('#settings #expand').click(function() {
+	$('#settings #expand').click(function(event) {
 		$('#settings #expanddiv').slideToggle();
+		event.stopPropagation();
 	});
+	$('#settings #expanddiv').click(function(event){
+		event.stopPropagation();
+	})
 	$('#settings #expand').hover(function(){
 		$('#settings #expand+span').fadeToggle();
 	});
+	$(window).click(function(){//hide the settings menu when clicking oustide it
+		if($('body').attr("id")=="body-user"){
+			$('#settings #expanddiv').slideUp();
+		}
+	});
 	
 	$('.file_action').tipsy({gravity:'s', live:true});
 	$('.selectedActions a').tipsy({gravity:'n', live:true});
diff --git a/core/js/listview.js b/core/js/listview.js
new file mode 100644
index 0000000000..e3e5ebdab8
--- /dev/null
+++ b/core/js/listview.js
@@ -0,0 +1,71 @@
+function ListView(element){
+	this.element=element;
+}
+
+ListView.generateTable=function(collumns){
+	var html='<table>';
+	html+='<thead>';
+	$.each(collumns,function(index,collumn){
+		html+='<th>'+collumn+'</th>';
+	});
+	html+='<thead>';
+	html+='</head>';
+	html+='<tbody>';
+	html+'<tr class="template">'
+	$.each(collumns,function(index,collumn){
+		html+='<th class="'+collumn.toLower()+'"</th>';
+	});
+	html+'</tr>'
+	html+='</tbody>';
+	html='</table>';
+	return $(html);
+}
+
+ListView.prototype={
+	rows:{},
+	hoverElements:{},
+	addRow:function(id,data,extraData){
+		var tr=this.element.find('tr.template').clone();
+		tr.removeClass('template');
+		$.each(data,function(name,value){
+			tr.children('td.'+name).text(value);
+			tr.attr('data-'+name,value);
+		});
+		$.each(extraData,function(name,value){
+			tr.attr('data-'+name,value);
+		});
+		this.rows[id]=data;
+		tr.data('id',id);
+		this.element.children('tbody').append(tr);
+	},
+	removeRow:function(id){
+		this.rows[id].remove();
+		delete this.rows[id];
+	},
+	hoverHandeler:function(tr){
+		$.each(this.hoverElement,function(index,collumn){
+			$.each(collumn,function(index,element){
+				var html='<a href="#" title="'+element.title+'" class="hoverElement"/>';
+				var element=$(html);
+				element.append($('<img src="'+element.icon+'"/>'));
+				element.click(element.callback);
+				tr.children('td.'+collumn).append(element)
+			});
+		});
+		if(this.deleteCallback){
+			
+		}
+	},
+	hoverHandelerOut:function(tr){
+		tr.find('*.hoverElement').remove();
+	},
+	addHoverElement:function(collumn,icon,title,callback){
+		if(!this.hoverElements[collumn]){
+			this.hoverElements[collumn]=[];
+		}
+		this.hoverElements[row].push({icon:icon,callback:callback,title:title});
+	},
+	empty:function(){
+		this.element.children('tr:not(.template)').remove();
+	}
+}
\ No newline at end of file
-- 
GitLab