aboutsummaryrefslogtreecommitdiff
path: root/depictions/js/data-loader-engine.js
blob: 723b728bb0db62341a0525cf5f8b85ee2eb8b63f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function data_loader_engine(contentBlocks,xml) {

	/* Loop through each if the contentBlocks */
	$.each(contentBlocks, function (key,contentInfo){
		
		console.log('Processing '+key);
		console.log('  type= '+contentInfo.type);
		
		// go out if key element does not exits
		if (!($(key).length)) {return}
		
		switch(contentInfo.type) {
			case "text":
				var content = $(xml).find(contentInfo.source).text();
				$(key).html(content)
				break;
			case "link":
				console.log('  url= '+contentInfo.url);
				console.log('  text= '+contentInfo.text);

				var url = contentInfo.url;
				var params = [];
				if (contentInfo.params) {
					$.each(contentInfo.params, function(){
						this[1] = escape(this[1]);
						params[params.length] = this.join('=');
					});
				}
				url = url+'?'+params.join('&');
				$(key).append( $("<a></a>")
					.attr("href",url)
					.text(contentInfo.text)
				 );
				break;				
			case "list":
				var list = $(xml).find(contentInfo.source);
				
				
				if (list.size()==0) {
					if (contentInfo.emptyListCallback) {
						contentInfo.emptyListCallback($(key))
					}
				} else {
					if (!!contentInfo.reverseRender) {
						list = $(list).get().reverse();
					}
					$.each(list, function(index,value){
						var item = $(value).text()
						
						if (!!contentInfo.reverseRender) {
							$(key).prepend( $(contentInfo.paragraphElement).html("<p>"+item+"</p>") )
						} else {
							$(key).append( $(contentInfo.paragraphElement).html("<p>"+item+"</p>") )
						}
					});
				}
				break;
			case "articles":
				var articles = 	$(xml).find(contentInfo.source).children();
				var titleID = 0;
				$.each(articles,function(index,article){
					var articleTitle = $(article).find(contentInfo.titleSource).text()
					$(key).append( $(contentInfo.titleElement).html(articleTitle));
					var container = $(contentInfo.paragraphContainer).attr("id",++titleID);
					$(key).append($(container));
					$.each( $(article).find(contentInfo.paragraphSource), function(index,paragraph){
						$(container).append( $(contentInfo.paragraphElement).html("<p>"+$(paragraph).text()+"</p>") )
					}) //paragraph
				}) //article

				break;
			case "custom":
				if (!key) {return}
				contentInfo.render( $(key), $(xml).find(contentInfo.source) )
				break;
		}//switch
	}); //each
}