1/* DOKUWIKI:include_once raphael.min.js */
2/* DOKUWIKI:include_once flowchart.min.js */
3
4jQuery(function(){
5
6function draw (style){
7	var sel = 'pre.flowchartjs';
8	if (style != '') sel = sel + '.' + style;
9	return function (opt){
10		jQuery(sel).each(function (index){
11			var cls = jQuery(this).attr('class').replace(/^\s+|\s+$/, '').replace(/\s+/g, ' ').split(' ');
12			var obj = flowchart.parse( jQuery(this).text() );
13			var classes = cls.length == 1? cls[0]: cls[0] + ' ' + cls[1];
14			var id = classes.replace(/ /g, '_') + '_' + index;
15			jQuery(this).replaceWith(
16				jQuery('<div class="' + classes + '" id="' + id + '"></div>')
17			);
18			obj.drawSVG(id, opt);
19
20			div_size_style = "";
21			if (cls.length >= 3) div_size_style = div_size_style + "width: " + cls[2] + ";";
22			if (cls.length >= 4) div_size_style = div_size_style + "height: " + cls[3] + ";";
23			if (div_size_style != "") jQuery('div#' + id).attr('style', div_size_style);
24
25			jQuery('div#' + id + ' svg').attr(
26				'style',
27				jQuery('div#' + id + ' svg').attr('style') + ' height: 100%; width: 100%;'
28			);
29		});
30	};
31}
32/*
33 * callback should indicate style info
34 */
35function draw1style (style, callback){
36	jQuery.ajax(DOKU_BASE + 'lib/plugins/flowchartjs/styles/' + style + '.json', {dataType: 'json'})
37		.done(function(d){
38			callback(d);
39		})
40		.fail(function(j, s, e){
41			callback(null);
42		});
43}
44
45var classes = [];
46jQuery('pre.flowchartjs').each(function(index){
47	var cls = jQuery(this).attr('class').replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' ').split(' ');
48	if (cls.length == 1) classes[''] = 1;
49	else classes[cls[1]] = 1;
50	return true;
51});
52
53for (var cls in classes){
54	draw1style(cls, callback=draw(cls));
55}
56
57});
58
59