view map/WindowWidget.js @ 3:f196939ccc03

error handle and alert feedback to user. If error occurs, user'll not be halted by the loading page and sections_revisions will recovery to previous version.
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 26 Jan 2015 12:19:39 +0100
parents b12c99b7c3f0
children
line wrap: on
line source

var windowWidgetObjArray=[];
var windowZ=10001;
function initWindowWidget(){
	var i=0;
	$(".windowWidget").each(function(){
		windowWidgetObjArray[i]=new WindowWidget($(this));
	});
}

function WindowWidget(obj,x,y,width,height){
	x = typeof x !== 'undefined' ? x:0;
	y = typeof y !== 'undefined' ? y:0;
	width = typeof width !== 'undefined' ? width:"auto";
	height = typeof height !== 'undefined' ? height:"auto";
	var that=this;
	this.obj=obj;
	this.setX(x);
	this.setY(y);
	this.setWidth(width);
	this.setHeight(height);
	//this.isDragging=false;
	//this.obj.attr("draggable","true");
	/*this.obj.mousedown(function(e){
		var h=that.obj.outerHeight();
		var w=that.obj.outerWidth();
		var x=that.obj.offset().top+h-e.pageX;
		var y=that.obj.offset().left+w-e.pageY;
		$(window).mousemove(function(e){
			that.isDragging=true;
			that.setX(e.pageX+x-w);
			that.setY(e.pageY+y-h);
			console.log(e.pageX+" "+e.pageY);
		}).mouseup(function(){
			$(window).unbind("mousemove");

		});
	}).mouseup(function(){
		var wasDragging=that.isDragging;
		that.isDragging=false;
		$(window).unbind("mousemove");
		if(!wasDragging){
			
		}
	});*/
	this.obj.css("z-index",(windowZ++));
	this.title=this.obj.attr("title");
	this.obj.wrapInner("<div class='content'></div>");
	this.obj.draggable({cancel:".content",stack:".windowWidget"});
	this.obj.children(".content").hide();
	this.initTitleBar();
	this.obj.click(function(){
		that.bringToFront();
	});
}
WindowWidget.prototype.constructor=WindowWidget;

WindowWidget.prototype.initTitleBar=function(){
	var titleBarObj=$("<div>").addClass("windowWidgetBar");
        this.obj.prepend(titleBarObj);
	var visibilityButtonObj=$("<div>").addClass("visibilityButton");
	titleBarObj.append(visibilityButtonObj);
	visibilityButtonObj.html("+");
	var titleObj=$("<div>").addClass("title");
	titleBarObj.append(titleObj);
	titleObj.html(this.title);
	var that=this;
	visibilityButtonObj.click(function(){
		//if(that.obj.children(".content").is(":visible")){
		if(visibilityButtonObj.html()=="-"){
			visibilityButtonObj.html("+");
			that.obj.children(".content").hide();
		}else{
			visibilityButtonObj.html("-");
			that.obj.children(".content").show();
		}
	});
};
WindowWidget.prototype.bringToFront=function(){
	var frontWindowObj;
	var maxZ=0;
	$(".windowWidget").each(function(){
		var z=$(this).css("z-index");
		if(z>maxZ){
			maxZ=z;
			frontWindowObj=$(this);
		}
	});
	var z=this.obj.css("z-index");
	this.obj.css("z-index",maxZ);
	frontWindowObj.css("z-index",z);
	/*$(".windowWidget").sort(function(a,b){
		return $(a).css("z-index")-$(b).css("z-index");
	});*/
	
};
WindowWidget.prototype.hideWindow=function(){};
WindowWidget.prototype.showWindow=function(){};
WindowWidget.prototype.resizeWindow=function(){};
WindowWidget.prototype.setX=function(val){
	this.x=val;
	this.obj.css("left",this.x);
};
WindowWidget.prototype.setY=function(val){
	this.y=val;
	this.obj.css("top",this.y);
};
WindowWidget.prototype.setWidth=function(val){
	this.width=val;
	this.obj.css("width",this.width);
};
WindowWidget.prototype.setHeight=function(val){
	this.height=val;
	this.obj.css("height",this.height);
};