Widget:A2Event: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
Zeile 35: Zeile 35:
  
 
  var lineText = document.createTextNode(prefix + ": " + lines[i]);
 
  var lineText = document.createTextNode(prefix + ": " + lines[i]);
  if (error && i == error.line){
+
  if (error.line && i == error.line){
 
  var $node = $('<span style="color: red;" />').append(lineText+"\n");
 
  var $node = $('<span style="color: red;" />').append(lineText+"\n");
 
  $node.append(document.createTextNode(error));
 
  $node.append(document.createTextNode(error));

Version vom 10. Juli 2012, 20:08 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 = "";
		var list = [];
		try {
			list = window.a2.parser.parse(text);
		} catch (e) {
			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 (error.line && i == error.line){
					var $node = $('').append(lineText+"\n");
					$node.append(document.createTextNode(error));
				} else {
					var $node = $(lineText+"\n")
				}
				$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>