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 (jq 1.9 import test)
m (Found $.delegate to be a good workaround)
Line 1: Line 1:
importScript("http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js");
+
;jQuery(function($){
  
;jQuery(function($){
 
 
LE=(function(){
 
LE=(function(){
 
_le = {};
 
_le = {};
Line 27: Line 26:
 
function init(){
 
function init(){
 
if(window.console&&window.console.log) console.log("Loaded LethosorMenu");
 
if(window.console&&window.console.log) console.log("Loaded LethosorMenu");
link = $("<a>").attr({href:'#'}).text("LethosorMenu");
+
link = $("<a>").attr({href:'#le-menu-show'}).text("LethosorMenu").attr({title:'Shift-Alt-L'});
 
menuitem = $("<li>").append(link);
 
menuitem = $("<li>").append(link);
 
$("div#p-personal ul").append(menuitem);
 
$("div#p-personal ul").append(menuitem);
link.bind('click', function(e){
+
//link.bind('click', function(e){
e.preventDefault();
+
// e.preventDefault();
mscr().show();
+
// mscr().show();
});
+
//});
 
}
 
}
 
 
Line 43: Line 42:
 
'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'); //upper 'o' not #0
 
MS.header=$("<h3>").css({'text-align':'center'}).text("LethosorMenu").appendTo(MS.$);
 
MS.header=$("<h3>").css({'text-align':'center'}).text("LethosorMenu").appendTo(MS.$);
MS.close=$("<a>").attr({href:'#'}).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'})
.prependTo(MS.$);
+
.attr({title:'Esc'}).prependTo(MS.$);
 
 
 
MS.show=function(evt){
 
MS.show=function(evt){
Line 58: Line 57:
 
MS.active=false
 
MS.active=false
 
};
 
};
MS.close.bind('click',MS.hide);
+
$(document).delegate('[href=#le-menu-show]','click',MS.show);
 +
$(document).delegate('[href=#le-menu-hide]','click',MS.hide);
 
 
 
return function(){return MS;};
 
return function(){return MS;};

Revision as of 22:26, 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');
		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
		MS.header=$("<h3>").css({'text-align':'center'}).text("LethosorMenu").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;
})();
});