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', '\
29 <a href="{{mkws-googleurl md-electronic-url}}" target="_blank">\
30 {{#mkws-first md-thumburl}}\
31 <img src="{{this}}" alt="{{../md-title}}"/>\
35 <p>{{{md-title}}}</p>\
39 // Inhibit the display of the sole facet's title.
40 this.team.registerTemplate('facetTitle-Subject', 'doo');
45 // Main panel: encylopaedia and images on the left, topics on the right
46 s.push('<tr class="front">');
48 s.push('<td class="main">');
49 s.push(section('encyclopaedia', 'Topic Page: <span class="x-mkws-title"/>',
50 this.subwidget('Reference', { _team: 'ref', paragraphs: 1 })));
51 // The Images widget needs to be in our team so we can set its template
52 s.push(section('image', 'Images',
53 this.subwidget('GoogleImage', { maxrecs: 3, template: 'CredoImage', target: 'google_images_js' })));
56 s.push('<td class="side">');
57 s.push(section('topics', 'Related Topics',
58 this.subwidget('Facet', { _team: 'main', facet: 'subject', template: 'CredoFacet' })));
63 s.push('<tr><td colspan="2"><hr class="divider"/></td></tr>');
65 s.push(sectionRow('entries', 'News',
66 this.subwidget('Records', { _team: 'news', targetfilter: 'categories=news', perpage: 10 })));
67 s.push(sectionRow('articles', 'Articles',
68 this.subwidget('Records', { _team: 'articles', targetfilter: 'categories=articles', perpage: 10 })));
69 s.push(sectionRow('books', 'Books',
70 this.subwidget('Records', { _team: 'books', targetfilter: 'categories=books', perpage: 10 })));
71 s.push(sectionRow('news', 'Results from all targets',
72 this.subwidget('Records', { _team: 'main' })));
76 this.node.html(s.join(''));
78 // Fill in the titles from the query once widgets have all been prepared
80 this.team.queue("ready").subscribe(function() {
81 var query = toTitleCase(that.config.query);
82 that.log("got query '" + query + "' from team config");
83 mkws.$('.x-mkws-title').html(query);
84 mkws.$('title').html("MKWS: " + query);
86 // Derived from http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript
87 function toTitleCase(str) {
88 return str.replace(/\w\S*/g, function(txt) {
89 return txt.charAt(0).toUpperCase() + txt.substr(1);
95 function section(xclass, title, content) {
97 s.push('<div class="' + xclass + ' section">');
98 s.push('<div class="title">' + title + '</div>');
99 s.push('<div class="content">' + content + '</div>');
104 function sectionRow(xclass, title, content) {
107 s.push('<td colspan="2">');
108 s.push(section(xclass, title, content));