Topic on Project:Support desk

Looking for a wiki about a wiki with Javascript

2
81.148.149.3 (talkcontribs)

Been trying to figure out where to even find information on this.

Got a wiki up and running, and added semantic to be able to do some more stuff. Now I want the data that I added using semantic to generate some fancy graphics using javascript. My problem is as follows.

I can't find much in the way of information how to embed javascript in mediawiki. Got as far as that it needs to be added to MediaWiki:Common.js.

But are there examples. In my case, how to call a function deffined in Common.js Secondly (and this probably does not belong here, but thought I might be lucky) How would I go about running a SMW ask and get the data to the javascipt rather than generate the page. I have managed to get it into an array, but just don't know if that array can be accessed or if I need to do some JSON magic or similar.

Ciencia Al Poder (talkcontribs)

With SMW ask you should generate an HTML table, or list, and with JavaScript look at that structure to gather the data. It can't generate JavaScript code directly.

For example, assume it generates a table inside a div with class "graphicdata":

$(function() {
	$('.graphicdata').each(function() {
		var data = $.map($.makeArray($(this).find('table').eq(0).find('tr')), function(val, i) {
			if (i == 0) {
				// Skip the first row (we assume it's the header)
				return;
			}
			return {
				col1: $(val.cells[0]).text(),
				col2: $(val.cells[1]).text()
			};
		});
		generateGraphic(data);
	});
});
Reply to "Looking for a wiki about a wiki with Javascript"