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 (bugfix)
m (update from local version)
Line 56: Line 56:
 
$(document).delegate('[href=#le-lethosor]','click',user_lethosor);
 
$(document).delegate('[href=#le-lethosor]','click',user_lethosor);
 
 
mscr = (function(){
+
MS=(function(){
MS={active:false,};
+
var MS={active:false,};
 
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', 'border-radius':'.8em'}).hide().appendTo('body');
 
'background-color':'white', padding:'1.5em', margin:'-1.5em', 'border-radius':'.8em'}).hide().appendTo('body');
Line 64: Line 64:
 
'background-color':'rgba(100,100,100,0.5)'}).hide().appendTo('body')
 
'background-color':'rgba(100,100,100,0.5)'}).hide().appendTo('body')
 
.attr({href:'#le-menu-hide'});  
 
.attr({href:'#le-menu-hide'});  
 +
MS.content=$("<div>").addClass("le-cf").css({padding:'1em'}).appendTo(MS.$);
 
MS.header=$("<h3>").css({'text-align':'center'}).html('<a href="#le-lethosor" target="_blank"><span style="color:#093">L</span><span style="color:#084">e</span>'+
 
MS.header=$("<h3>").css({'text-align':'center'}).html('<a href="#le-lethosor" target="_blank"><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:#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></a><span style="color:#c40">Menu</span>')
 
'<span style="color:#048">s</span><span style="color:#039">o</span><span style="color:#02a">r</span></a><span style="color:#c40">Menu</span>')
.appendTo(MS.$);
+
.appendTo(MS.content);
MS.content=$("<div>").css({padding:'1em'}).appendTo(MS.$);
+
MS.cfs={main:MS.content};//content frames
 +
MS.ccf='content';//current
 
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.$);
Line 86: Line 88:
 
MS.active=false
 
MS.active=false
 
};
 
};
$(document).delegate('[href=#le-menu-show]','click',MS.show);
+
$(document).on('click','[href=#le-menu-show]',MS.show);
$(document).delegate('[href=#le-menu-hide]','click',MS.hide);
+
$(document).on('click','[href=#le-menu-hide]',MS.hide);
 +
 +
MS.csize=function(w,h){
 +
if(w+''=='')return;
 +
var w,h,l,t;
 +
w=parseInt(w);h=parseInt(h);
 +
l=50-w/2;t=50-h/2;
 +
MS.$.css({width:w+'%',height:h+'%',top:t+'%',left:l+'%'});
 +
};
 +
MS.cf=function(n){ //Content frame - switch to specified
 +
if(!n)return MS.ccf;
 +
MS.ccf=n;$('.le-cf').hide();
 +
if(!MS.cfs[n])MS.cfs[n]=$('<div class="le-cf">').appendTo(MS.$);
 +
return MS.cfs[n].show();
 +
};
 +
MS.reset=function(){
 +
MS.show();MS.cf('main');MS.csize(80,80);
 +
};
 
 
 
_links={};
 
_links={};
Line 99: Line 118:
 
};
 
};
 
 
return function(){return MS;};
+
var _=MS;return function(){return _;};
 
})();
 
})();
A('menuScreen',mscr);
+
A('menuScreen',MS);
 
 
 
PM=(function(){ //Plugins manager
 
PM=(function(){ //Plugins manager
Line 115: Line 134:
 
PM.addMenuLink=function(name){
 
PM.addMenuLink=function(name){
 
ml=(T.func(PM.plugs[name].menuLinkData))?PM.plugs[name].menuLinkData():{name:name,func:PM.plugs[name].main}; //call menuLinkData if func, else use defaults
 
ml=(T.func(PM.plugs[name].menuLinkData))?PM.plugs[name].menuLinkData():{name:name,func:PM.plugs[name].main}; //call menuLinkData if func, else use defaults
mscr().addLink(ml.name,ml.func);
+
MS().addLink(ml.name,ml.func);
 
}
 
}
 
return function(){return PM};
 
return function(){return PM};
Line 122: Line 141:
 
keyf=function(e){
 
keyf=function(e){
 
if(e.metaKey||e.ctrlKey)return;
 
if(e.metaKey||e.ctrlKey)return;
M=mscr();
+
var M=MS();
 
if(e.altKey&&e.shiftKey&&e.keyCode==76){//S-A-l
 
if(e.altKey&&e.shiftKey&&e.keyCode==76){//S-A-l
 
if(!M.active)M.show();return;
 
if(!M.active)M.show();return;
Line 145: Line 164:
 
 
 
function link_opts(PM){
 
function link_opts(PM){
t={};
+
var t={};
 
t.a={e:'?title=$1&action=edit',h:'?title=$1&action=history'}
 
t.a={e:'?title=$1&action=edit',h:'?title=$1&action=history'}
 
t.p='';
 
t.p='';
t.help=$("<div>").css({position:'fixed',top:0,left:0,width:'100%','background-color':'#ff9'}).hide().appendTo('body').text('[E]dit [H]istory');
+
t.help=$("<span>").css({position:'fixed',bottom:0,right:0,width:'100%','background-color':'#ff9','text-align':'right'}).hide().appendTo('body').text('[E]dit [H]istory');
 +
t.ad=500;t.hs=function(){t.help.stop().fadeIn(t.ad)};
 +
t.hh=function(){t.help.stop().fadeOut(t.ad)};
 
t.over=function(e){
 
t.over=function(e){
 
console.log('over',e,this);
 
console.log('over',e,this);
 
a=$(this);if(!a||!a.attr||!T.func(a.attr))return;
 
a=$(this);if(!a||!a.attr||!T.func(a.attr))return;
t.help.show();
+
t.hs();
 
t.p=a.attr('href').replace(wgScript+'/','');
 
t.p=a.attr('href').replace(wgScript+'/','');
 
$('body').on('keypress',t.key);
 
$('body').on('keypress',t.key);
 
};
 
};
t.out=function(e){console.log('out',e,this);$('body').off('keypress',t.key);t.help.hide();};
+
t.out=function(e){console.log('out',e,this);$('body').off('keypress',t.key);t.hh();};
 
t.key=function(e){
 
t.key=function(e){
 
T.PD(e);k=String.fromCharCode(e.which).toLowerCase();
 
T.PD(e);k=String.fromCharCode(e.which).toLowerCase();
Line 168: Line 189:
 
}
 
}
 
PM().register("Links",link_opts);
 
PM().register("Links",link_opts);
 +
 +
function about(PM){
 +
var t={};
 +
t.main=function(){
 +
MS().csize(60,80);
 +
MS().cf('about');
 +
t.f=MS().cfs[MS().cf()];
 +
t.f.html('').append($("<p>").text("LethosorMenu: JavaScript plugin manager"));
 +
t.ql=$("<a>").attr('href','#').text("Back").on('click',function(e){T.PD(e);t.quit();}).appendTo(t.f);
 +
};
 +
t.quit=function(){
 +
MS().reset();
 +
};
 +
t.init=function(PM){
 +
PM.addMenuLink("About");
 +
};
 +
t.title="About LethosorMenu";
 +
return t;
 +
}
 +
PM().register("About",about);
 
 
 
return _le;
 
return _le;

Revision as of 21:13, 10 March 2013

;jQuery(function(){
MW=mediaWiki;LEInit=(function($){
	console.log($.fn.jquery);
	var _le = {OPTS:{}};
	_le.DEFAULT_OPTS={
		menu:{
			show_overlay:true
		}
	};
	_le.OPTS_MD={
		menu:{
			desc:'Menu settings',
			data:{
				show_overlay:{
					desc:'Show overlay',
					type:'b'
				}
			}
		}
	};
	function update_opts(){
		if(!'LE_USER_OPTS' in window)window.LE_USER_OPTS={}
		_le.OPTS=$.extend(_le.DEFAULT_OPTS,window.LE_USER_OPTS);
	}
	update_opts();
	O=function(){return _le.OPTS};
	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;
	}
	A('update_opts',update_opts);
	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);
	}
	function user_lethosor(e){T.PD(e);window.location.href="http://dwarffortresswiki.org/index.php/User:Lethosor";}
	$(document).delegate('[href=#le-lethosor]','click',user_lethosor);
	
	MS=(function(){
		var 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', 'border-radius':'.8em'}).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.content=$("<div>").addClass("le-cf").css({padding:'1em'}).appendTo(MS.$);
		MS.header=$("<h3>").css({'text-align':'center'}).html('<a href="#le-lethosor" target="_blank"><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></a><span style="color:#c40">Menu</span>')
			.appendTo(MS.content);
		MS.cfs={main:MS.content};//content frames
		MS.ccf='content';//current
		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);
			if(O().menu.show_overlay) MS.$O.stop().fadeIn(500);
			MS.$.stop().fadeIn(350);
			$('body').css({overflow:'hidden'});
			MS.active=true;
		};
		MS.hide=function(evt){
			T.PD(evt);
			MS.$O.stop().fadeOut(400);
			MS.$.stop().fadeOut(250);
			$('body').css({overflow:'auto'});
			MS.active=false
		};
		$(document).on('click','[href=#le-menu-show]',MS.show);
		$(document).on('click','[href=#le-menu-hide]',MS.hide);
		
		MS.csize=function(w,h){
			if(w+''=='')return;
			var w,h,l,t;
			w=parseInt(w);h=parseInt(h);
			l=50-w/2;t=50-h/2;
			MS.$.css({width:w+'%',height:h+'%',top:t+'%',left:l+'%'});
		};
		MS.cf=function(n){ //Content frame - switch to specified
			if(!n)return MS.ccf;
			MS.ccf=n;$('.le-cf').hide();
			if(!MS.cfs[n])MS.cfs[n]=$('<div class="le-cf">').appendTo(MS.$);
			return MS.cfs[n].show();
		};
		MS.reset=function(){
			MS.show();MS.cf('main');MS.csize(80,80);
		};
		
		_links={};
		MS.linklist=$("<ul>").appendTo(MS.content);
		MS.addLink=function(name,func){
			el=$("<li>").append($("<a>").attr('href','#')).appendTo(MS.linklist);
			a=PM().plugs[name].title;
			el.find('a').text((a)?a:name);
			el.on('click','a',function(e){T.PD(e);func(PM);});
			_links[name]={func:func,link:el};
		};
		
		var _=MS;return function(){return _;};
	})();
	A('menuScreen',MS);
	
	PM=(function(){ //Plugins manager
		var PM={plugs:{}};
		PM.register=function(name,func,opts){
			opts=$.extend({},opts);
			if(PM.plugs[name]&&!opts.override) return
			if(T.func(func)){
				PM.plugs[name]=func(PM);
			}
			if(T.func(PM.plugs[name].init))PM.plugs[name].init(PM);
		}
		PM.addMenuLink=function(name){
			ml=(T.func(PM.plugs[name].menuLinkData))?PM.plugs[name].menuLinkData():{name:name,func:PM.plugs[name].main}; //call menuLinkData if func, else use defaults
			MS().addLink(ml.name,ml.func);
		}
		return function(){return PM};
	})();A('PM',PM);
	
	keyf=function(e){
		if(e.metaKey||e.ctrlKey)return;
		var M=MS();
		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);
	
	local=(function(){
		__t=this;return function(k){return k?__t[k]:__t;}
	})();A('local',local);
		
	init();
	
	function test(PM){return {main:function(){alert("This is a test plugin:\n"+PM)},title:"Test plugin v0.0.1", init:function(){PM.addMenuLink("Test")}}}
	PM().register("Test", test);
	//PM().addMenuLink("Test");
	
	function link_opts(PM){
		var t={};
		t.a={e:'?title=$1&action=edit',h:'?title=$1&action=history'}
		t.p='';
		t.help=$("<span>").css({position:'fixed',bottom:0,right:0,width:'100%','background-color':'#ff9','text-align':'right'}).hide().appendTo('body').text('[E]dit [H]istory');
		t.ad=500;t.hs=function(){t.help.stop().fadeIn(t.ad)};
		t.hh=function(){t.help.stop().fadeOut(t.ad)};
		t.over=function(e){
			console.log('over',e,this);
			a=$(this);if(!a||!a.attr||!T.func(a.attr))return;
			t.hs();
			t.p=a.attr('href').replace(wgScript+'/','');
			$('body').on('keypress',t.key);
		};
		t.out=function(e){console.log('out',e,this);$('body').off('keypress',t.key);t.hh();};
		t.key=function(e){
			T.PD(e);k=String.fromCharCode(e.which).toLowerCase();
			if(t.a[k])window.location=wgScript+t.a[k].replace('$1',t.p);
		};
		t.init=function(){
			$('body').on('mouseover','a',t.over);
			$('body').on('mouseout','a',t.out);
		};
		return t;
	}
	PM().register("Links",link_opts);
	
	function about(PM){
		var t={};
		t.main=function(){
			MS().csize(60,80);
			MS().cf('about');
			t.f=MS().cfs[MS().cf()];
			t.f.html('').append($("<p>").text("LethosorMenu: JavaScript plugin manager"));
			t.ql=$("<a>").attr('href','#').text("Back").on('click',function(e){T.PD(e);t.quit();}).appendTo(t.f);
		};
		t.quit=function(){
			MS().reset();
		};
		t.init=function(PM){
			PM.addMenuLink("About");
		};
		t.title="About LethosorMenu";
		return t;
	}
	PM().register("About",about);
	
	return _le;
});
LEInitCheck=function(){
	if($.fn.jquery!='1.9.1') return setTimeout(LEInitCheck, 500);
	else window.LE=LEInit(jQuery); return LE;
};LEInitCheck()
});importScriptURI("http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js");