v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Difference between revisions of "User:Lethosor/main.js"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
m (Found $.delegate to be a good workaround)
m (update - color, modal click to exit)
Line 39: Line 39:
 
MS.$=$("<div>").css({position:'absolute', 'z-index':100, top:'10%', left:'10%', width:'80%', height:'80%',
 
MS.$=$("<div>").css({position:'absolute', 'z-index':100, top:'10%', left:'10%', width:'80%', height:'80%',
 
'background-color':'white', padding:'1.5em', margin:'-1.5em'}).hide().appendTo('body');
 
'background-color':'white', padding:'1.5em', margin:'-1.5em'}).hide().appendTo('body');
 +
//upper 'o' not #0
 
MS.$O=$("<div>").css({position:'absolute', 'z-index':99, top:0, left:0, width:'100%', height:'100%',
 
MS.$O=$("<div>").css({position:'absolute', 'z-index':99, top:0, left:0, width:'100%', height:'100%',
'background-color':'rgba(100,100,100,0.5)'}).hide().appendTo('body'); //upper 'o' not #0
+
'background-color':'rgba(100,100,100,0.5)'}).hide().appendTo('body')
MS.header=$("<h3>").css({'text-align':'center'}).text("LethosorMenu").appendTo(MS.$);
+
.attr({href:'#le-menu-hide'});
 +
MS.header=$("<h3>").css({'text-align':'center'}).html('<span style="color:#093">L</span><span style="color:#084">e</span>'+
 +
'<span style="color:#075">t</span><span style="color:#066">h</span><span style="color:#057">o</span>'+
 +
'<span style="color:#048">s</span><span style="color:#039">o</span><span style="color:#02a">r</span><span style="color:#c40">Menu</span>')
 +
.appendTo(MS.$);
 
MS.close=$("<a>").attr({href:'#le-menu-hide'}).text('Close').css({'text-align':'right','float':'right','color':'red'})
 
MS.close=$("<a>").attr({href:'#le-menu-hide'}).text('Close').css({'text-align':'right','float':'right','color':'red'})
 
.attr({title:'Esc'}).prependTo(MS.$);
 
.attr({title:'Esc'}).prependTo(MS.$);

Revision as of 22:31, 28 February 2013

;jQuery(function($){

LE=(function(){
	_le = {};
	T={
		func:function(o){return !!(o&&o.call);},
		PD:function(e){//preventDefault
			if(!e||!e.preventDefault)return;
			o=e.preventDefault;if(e&&!!(o&&o.call)) e.preventDefault();
		},
		log:function(s){
			if(console&&console.log&&console.log.call)console.log(s);
		},
	}
	function A(a,b){
		if(!b){
			if (typeof a != 'object') return;
			for(i in a){
				if(i in {}) continue;
				_le[i] = a[i]
			}
		}
		else _le[a]=b;
		return A;
	}
	function init(){
		if(window.console&&window.console.log) console.log("Loaded LethosorMenu");
		link = $("<a>").attr({href:'#le-menu-show'}).text("LethosorMenu").attr({title:'Shift-Alt-L'});
		menuitem = $("<li>").append(link);
		$("div#p-personal ul").append(menuitem);
		//link.bind('click', function(e){
		//	e.preventDefault();
		//	mscr().show();
		//});
	}
	
	mscr = (function(){
		MS={active:false,};
		MS.$=$("<div>").css({position:'absolute', 'z-index':100, top:'10%', left:'10%', width:'80%', height:'80%',
			'background-color':'white', padding:'1.5em', margin:'-1.5em'}).hide().appendTo('body');
		//upper 'o' not #0
		MS.$O=$("<div>").css({position:'absolute', 'z-index':99, top:0, left:0, width:'100%', height:'100%',
			'background-color':'rgba(100,100,100,0.5)'}).hide().appendTo('body')
			.attr({href:'#le-menu-hide'}); 
		MS.header=$("<h3>").css({'text-align':'center'}).html('<span style="color:#093">L</span><span style="color:#084">e</span>'+
			'<span style="color:#075">t</span><span style="color:#066">h</span><span style="color:#057">o</span>'+
			'<span style="color:#048">s</span><span style="color:#039">o</span><span style="color:#02a">r</span><span style="color:#c40">Menu</span>')
			.appendTo(MS.$);
		MS.close=$("<a>").attr({href:'#le-menu-hide'}).text('Close').css({'text-align':'right','float':'right','color':'red'})
			.attr({title:'Esc'}).prependTo(MS.$);
		
		MS.show=function(evt){
			T.PD(evt);
			MS.$O.fadeIn(500);
			MS.$.fadeIn(350);
			MS.active=true
		};
		MS.hide=function(evt){
			T.PD(evt);
			MS.$O.fadeOut(400);
			MS.$.fadeOut(250);
			MS.active=false
		};
		$(document).delegate('[href=#le-menu-show]','click',MS.show);
		$(document).delegate('[href=#le-menu-hide]','click',MS.hide);
		
		return function(){return MS;};
	})();
	A('menuScreen',mscr);
	
	keyf=function(e){
		if(e.metaKey||e.ctrlKey)return;
		M=mscr();
		if(e.altKey&&e.shiftKey&&e.keyCode==76){//S-A-l
			if(!M.active)M.show();return;
		}
		if(!M.active)return;
		T.PD(e);
		if(e.keyCode==27){//esc
			M.hide();
		}
	};
	$(document).bind('keydown', keyf);
	
	init();return _le;
})();
});