From 80603494574a93527505c0d03efddbf98f28dfad Mon Sep 17 00:00:00 2001 From: StrugglingDoge Date: Tue, 30 Apr 2019 21:12:37 -0400 Subject: Initial Commit --- sileodepictions/js/data-loader-engine.js | 78 ++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 sileodepictions/js/data-loader-engine.js (limited to 'sileodepictions/js/data-loader-engine.js') diff --git a/sileodepictions/js/data-loader-engine.js b/sileodepictions/js/data-loader-engine.js new file mode 100644 index 0000000..723b728 --- /dev/null +++ b/sileodepictions/js/data-loader-engine.js @@ -0,0 +1,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( $("") + .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("

"+item+"

") ) + } else { + $(key).append( $(contentInfo.paragraphElement).html("

"+item+"

") ) + } + }); + } + 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("

"+$(paragraph).text()+"

") ) + }) //paragraph + }) //article + + break; + case "custom": + if (!key) {return} + contentInfo.render( $(key), $(xml).find(contentInfo.source) ) + break; + }//switch + }); //each +} -- cgit v1.2.3