1 // The Google Images database returns links like:
2 // http://images.google.com/url?q=http://eofdreams.com/fish.html&sa=U&ei=RAB-U9XNDo2Dqga1o4L4Bw&ved=0CC4Q9QEwAA&usg=AFQjCNFhRtn6GMevHbpITZ6kfx6rsHV2ow
3 // This Handlebars helper avoids a pointless redirect by transforming
4 // this to the URL of the underling page, in this case
5 // http://eofdreams.com/fish.html
7 Handlebars.registerHelper('mkws-googleurl', function(obj) {
9 return "obj undefined";
11 return "obj[0] undefined, JSON=" + $.toJSON(obj);
13 return mkws.getParameterByName('q', obj[0]);
18 // ### This works inefficiently by having multiple teams all run the
19 // same search against different sets of targets. A much better
20 // approach would be run a single search, with all these panels
21 // members of the same team, but picking out only the results relevant
22 // to them. That will be more work.
24 mkws.registerWidgetType('Credo', function() {
27 this.team.registerTemplate('CredoImage', '\
28 <div class="col-md-3 col-sm-4 col-xs-6">\
29 <a href="{{mkws-googleurl md-electronic-url}}" target="_blank">\
30 {{#mkws-first md-thumburl}}\
31 <img src="{{this}}" alt="{{../md-title}}"/>\
40 // Main panel: encylopaedia and images on the left, topics on the right
41 s.push('<div class="row">');
43 s.push('<div class="jumbotron panel col-md-8"><div class="panel-body">');
44 //s.push(section('encyclopaedia', 'Topic Page: <span class="x-mkws-title"/>',
45 s.push(this.subwidget('Reference', { _team: 'ref', paragraphs: 1 }));
46 // The Images widget needs to be in our team so we can set its template
47 s.push('</div></div>');
49 s.push('<div class="col-md-4">');
50 s.push(section('mindmap', 'Create a Mind Map for <span class="x-mkws-title"/>',
51 this.subwidget('Mindmap', { _team: 'main', facet: 'subject' })));
52 s.push(section('topics', 'Related Topics',
53 this.subwidget('Facet', { _team: 'main', facet: 'subject' })));
58 s.push('<div class="row">');
59 s.push(section('image col-md-12', 'Images', this.subwidget('GoogleImage', { maxrecs: 4, template: 'CredoImage' })));
63 s.push('<div class="row clearfix">');
64 s.push(section('entries clearfix col-md-4 col-sm-6', 'Credo Entries',
65 this.subwidget('Records', { _team: 'main' })));
66 s.push(section('articles clearfix col-md-4 col-sm-6', 'Articles',
67 this.subwidget('Records', { _team: 'articles', targetfilter: 'categories=articles' })));
68 s.push(section('books clearfix col-md-4 col-sm-6', 'Books',
69 this.subwidget('Records', { _team: 'books', targetfilter: 'categories=books' })));
70 s.push(section('news col-md-4 col-sm-6', 'News',
71 this.subwidget('Records', { _team: 'news', targetfilter: 'categories=news' })));
72 s.push(section('resources col-md-4 col-sm-6', 'Suggested Resources',
73 "### Not yet implemented"));
75 this.node.html(s.join(''));
77 // Fill in the titles from the query once widgets have all been prepared
79 this.team.queue("ready").subscribe(function() {
80 var query = toTitleCase(that.config.query);
81 that.log("got query '" + query + "' from team config");
82 mkws.$('.x-mkws-title').html(query);
83 mkws.$('title').html("MKWS: " + query);
85 mkws.$(".mkwsSummary img").addClass("media-object");
86 console.log(mkws.$("body").html());
88 // Derived from http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript
89 function toTitleCase(str) {
90 return str.replace(/\w\S*/g, function(txt) {
91 return txt.charAt(0).toUpperCase() + txt.substr(1);
97 function section(xclass, title, content) {
99 s.push('<div class="' + xclass + '"><div class="panel panel-default">');
100 s.push('<div class="panel-heading title"><h3 class="panel-title">' + title + '</h3></div>');
101 s.push('<div class="panel-body">' + content + '</div>');
102 s.push('</div></div>');
106 function sectionRow(xclass, title, content) {
108 s.push('<div class="row">');
109 s.push(section(xclass, title, content));
116 mkws.registerWidgetType('Mindmap', function() {
117 this.node.html("### We do not yet have a Mindmap widget");