Widget:A2Event: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
(ne, is klar, J* …)
Zeile 2: Zeile 2:
 
   
 
   
 
  function wait4a2 (f){
 
  function wait4a2 (f){
if (window.a2 && window.a2.parser) {
+
if (window.a2 && window.a2.parser) {
f();
+
f();
} else {
+
} else {
if (window.importJS) {
+
if (window.importJS) {
importJS("MediaWiki:Skin/Projekt:Adventure2/lib.js");
+
importJS("MediaWiki:Skin/Projekt:Adventure2/lib.js");
importJS("MediaWiki:Skin/Projekt:Adventure2/parser.js");
+
importJS("MediaWiki:Skin/Projekt:Adventure2/parser.js");
}
+
}
window.setTimeout(function() { wait4a2(f); }, 100);
+
window.setTimeout(function() { wait4a2(f); }, 100);
}
+
}
 
  }
 
  }
 
   
 
   
 
  $(function () {
 
  $(function () {
wait4a2(function () {
+
wait4a2(function () {
+
var text = "<!--{$event|escape:'javascript'}-->";
+
var text = "<!--{$event|escape:'javascript'}-->";
var list = window.a2.parser.parse(text);
+
var error = "";
var error = "";
 
  
try {
+
try {
var event = window.a2.parser.parse("<!--{$event|escape:'javascript'}-->");
+
var list = window.a2.parser.parse(text);
} catch (e) {
+
} catch (e) {
var error = "Line " + e.line + ", Column " + e.column + ": " + e.message;
+
var error = "Line " + e.line + ", Column " + e.column + ": " + e.message;
}
+
}
  
if ("<!--{$action|escape:'javascript'}-->" != "render"){   
+
if ("<!--{$action|escape:'javascript'}-->" != "render"){   
$pre = $("<pr"+"e/>");
+
$pre = $("<pr"+"e/>");
var lines = text.split("\n");
+
var lines = text.split("\n");
for (var i=0; i<lines.length; i++) {
+
for (var i=0; i<lines.length; i++) {
prefix = String(i);
+
prefix = String(i);
while (prefix.length < 3)
+
while (prefix.length < 3)
prefix = " "+prefix;
+
prefix = " "+prefix;
  
var lineText = document.createTextNode(prefix + ": " + lines[i]);
+
var lineText = document.createTextNode(prefix + ": " + lines[i]);
if (i==e.line){
+
if (i==e.line){
var $node = $('<span style="color: red;" />').append(lineText);
+
var $node = $('<span style="color: red;" />').append(lineText);
$node.append("<br/>").append(document.createTextNode(error));
+
$node.append("<br/>").append(document.createTextNode(error));
} else {
+
} else {
var $node = $(lineText)
+
var $node = $(lineText)
}
+
}
$pre.append($node);
+
$pre.append($node);
}
+
}
  
if ($("#wikiPreview").length)
+
if ($("#wikiPreview").length)
$cont = $("#wikiPreview");
+
$cont = $("#wikiPreview");
else
+
else
$cont = $("#bodyContent");
+
$cont = $("#bodyContent");
  
$cont.append($pre);
+
$cont.append($pre);
  
return;
+
return;
}
+
}
  
if (error)
+
if (error)
return;
+
return;
  
for (var i=0; i<list.length; i++) {
+
for (var i=0; i<list.length; i++) {
+
var type = list[i][0];
+
var type = list[i][0];
var data = list[i][1];
+
var data = list[i][1];
  
if (type == "event"){
+
if (type == "event"){
a2.registerEventHandler(data);
+
a2.registerEventHandler(data);
} else {
+
} else {
//FIXME: not yet implemented: declarations for item, page
+
//FIXME: not yet implemented: declarations for item, page
}
+
}
}
+
}
});
+
});
 
  });
 
  });
 
    
 
    
 
  </script>
 
  </script>

Version vom 10. Juli 2012, 20:04 Uhr

<script type="text/javascript">

function wait4a2 (f){
	if (window.a2 && window.a2.parser) {
		f();
	} else {
		if (window.importJS) {
			importJS("MediaWiki:Skin/Projekt:Adventure2/lib.js");
			importJS("MediaWiki:Skin/Projekt:Adventure2/parser.js");
		}
		window.setTimeout(function() { wait4a2(f); }, 100);
	}
}

$(function () {
	 wait4a2(function () {
	 
		var text = "";
		var error = "";
		try {
			var list = window.a2.parser.parse(text);
		} catch (e) {
			var error = "Line " + e.line + ", Column " + e.column + ": " + e.message;
		}
		if ("" != "render"){  
			$pre = $("<pr"+"e/>");
			var lines = text.split("\n");
			for (var i=0; i<lines.length; i++) {
				prefix = String(i);
				while (prefix.length < 3)
					prefix = " "+prefix;
				var lineText = document.createTextNode(prefix + ": " + lines[i]);
				if (i==e.line){
					var $node = $('').append(lineText);
					$node.append("
").append(document.createTextNode(error)); } else { var $node = $(lineText) } $pre.append($node); }
			if ($("#wikiPreview").length)
				$cont = $("#wikiPreview");
			else
				$cont = $("#bodyContent");
			$cont.append($pre);
			return;
		}
		if (error)
			return;
		for (var i=0; i<list.length; i++) {
		
			var type = list[i][0];
			var data = list[i][1];
			if (type == "event"){
				a2.registerEventHandler(data);
			} else {
				//FIXME: not yet implemented: declarations for item, page
			}
		}
	 });
});
 
</script>