it yourself. Looks like you need node and npm, make install puts them
into /usr/local/bin.
+To compile the default templates you'll need to install the stable version
+of Handlebars. Currently it's at 1.3.0 and available by npm:
+
+ npm install handlebars@1.3.0 -g
+
For apache setup, see tools/apache2/README
NEWS
<script type="text/javascript" src="src/mkws-widget-categories.js"></script>
<script type="text/javascript" src="src/mkws-widget-log.js"></script>
<script type="text/javascript" src="src/mkws-widget-record.js"></script>
+ <script type="text/javascript" src="src/mkws-templates.js"></script>
<script type="text/javascript" src="src/mkws-widget-reference.js"></script>
<script type="text/javascript" src="src/mkws-widget-builder.js"></script>
+++ /dev/null
-// The Google Images database returns links like:
-// http://images.google.com/url?q=http://eofdreams.com/fish.html&sa=U&ei=RAB-U9XNDo2Dqga1o4L4Bw&ved=0CC4Q9QEwAA&usg=AFQjCNFhRtn6GMevHbpITZ6kfx6rsHV2ow
-// This Handlebars helper avoids a pointless redirect by transforming
-// this to the URL of the underling page, in this case
-// http://eofdreams.com/fish.html
-//
-Handlebars.registerHelper('mkws-googleurl', function(obj) {
- if (!obj) {
- return "obj undefined";
- } else if (!obj[0]) {
- return "obj[0] undefined, JSON=" + $.toJSON(obj);
- } else {
- return mkws.getParameterByName('q', obj[0]);
- }
-});
-
-
-// ### This works inefficiently by having multiple teams all run the
-// same search against different sets of targets. A much better
-// approach would be run a single search, with all these panels
-// members of the same team, but picking out only the results relevant
-// to them. That will be more work.
-
-mkws.registerWidgetType('Credo', function() {
- var that = this;
-
- this.team.registerTemplate('CredoImage', '\
- <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">\
- <a href="{{mkws-googleurl md-electronic-url}}" target="_blank">\
- {{#mkws-first md-thumburl}}\
- <img src="{{this}}" alt="{{../md-title}}"/>\
- {{/mkws-first}}\
- <br/>\
- </a>\
- <p>{{{md-title}}}</p>\
- </div>\
-');
-
- var s = []
- // Main panel: encylopaedia and images on the left, topics on the right
- s.push('<div class="row">');
-
- s.push('<div class="jumbotron panel col-md-8"><div class="panel-body">');
- //s.push(section('encyclopaedia', 'Topic Page: <span class="x-mkws-title"/>',
- s.push(this.subwidget('Reference', { _team: 'ref', paragraphs: 1 }));
- // The Images widget needs to be in our team so we can set its template
- s.push('</div></div>');
-
- s.push('<div class="col-md-4">');
- s.push(section('topics', 'Related Topics',
- this.subwidget('Facet', { _team: 'main', facet: 'subject' })));
- s.push('</div>');
-
- s.push('</div>');
-
- s.push('<div class="row">');
- s.push(section('image col-md-12', 'Images', this.subwidget('GoogleImage', { maxrecs: 4, template: 'CredoImage', target: 'google_images_js' })));
- s.push('</div>');
-
-
- s.push('<div class="row clearfix">');
- s.push(section('entries clearfix col-md-4 col-sm-6', 'News',
- this.subwidget('Records', { _team: 'news', targetfilter: 'categories=news', perpage: 10 })));
- s.push(section('articles clearfix col-md-4 col-sm-6', 'Articles',
- this.subwidget('Records', { _team: 'articles', targetfilter: 'categories=articles', perpage: 10 })));
- s.push(section('books clearfix col-md-4 col-sm-6', 'Books',
- this.subwidget('Records', { _team: 'books', targetfilter: 'categories=books', perpage: 10 })));
- s.push(section('news col-md-4 col-sm-6', 'Results from all targets',
- this.subwidget('Records', { _team: 'main' })));
- s.push('</div>');
- this.node.html(s.join(''));
-
- // Fill in the titles from the query once widgets have all been prepared
- var that = this;
- this.team.queue("ready").subscribe(function() {
- var query = toTitleCase(that.config.query);
- that.log("got query '" + query + "' from team config");
- mkws.$('.x-mkws-title').html(query);
- mkws.$('title').html("MKWS: " + query);
-
- mkws.$(".mkwsSummary img").addClass("media-object");
- console.log(mkws.$("body").html());
-
- // Derived from http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript
- function toTitleCase(str) {
- return str.replace(/\w\S*/g, function(txt) {
- return txt.charAt(0).toUpperCase() + txt.substr(1);
- });
- }
- });
-
-
- function section(xclass, title, content) {
- var s = [];
- s.push('<div class="' + xclass + '"><div class="panel panel-default">');
- s.push('<div class="panel-heading title"><h3 class="panel-title">' + title + '</h3></div>');
- s.push('<div class="panel-body">' + content + '</div>');
- s.push('</div></div>');
- return s.join('');
- }
-
- function sectionRow(xclass, title, content) {
- var s = [];
- s.push('<div class="row">');
- s.push(section(xclass, title, content));
- s.push('</div>');
- return s.join('');
- }
-});
+++ /dev/null
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>MKWS demo: Compound reference widget</title>
- <!-- <link rel="stylesheet" type="text/css" href="mkws-widget-credo.css" /> -->
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
- <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
- <script type="text/javascript">
- var mkws_config = { service_proxy_auth: "//mkws.indexdata.com/service-proxy-credoauth" };
- </script>
- <script class="mkwsTemplate_FacetBootstrap" type="text/x-handlebars-template">
- <h3>Results from Reference Universe</h3>
- {{#each hits}}
- <div class="refinement">
- {{#mkws-first md-electronic-url}}
- <a href="{{this}}">
- {{/mkws-first}}
- {{md-title}}
- </a>
- {{#if md-title-remainder}}
- <span>{{md-title-remainder}}</span>
- {{/if}}
- {{#if md-title-responsibility}}
- <span><i>{{md-title-responsibility}}</i></span>
- {{/if}}
- </div>
- {{/each}}
- </script>
- <script type="text/javascript" src="//mkws.indexdata.com/mkws-complete.js"></script>
- <script type="text/javascript" src="mkws-widget-credo-bs.js"></script>
- <style>
- .mkwsCredo {
- max-width: 1440px;
- }
- .mkwsGoogleImage img {
- max-width: 95%;
- }
- </style>
- </head>
- <body>
- <div class='mkwsCredo page-header container-fluid' autosearch='!param!q'></div>
- </body>
-</html>
--- /dev/null
+body {
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+ background: radial-gradient(ellipse at center, #ffffff 0%,#f8f8f8 100%);
+ font-weight: 300;
+}
+b, strong {
+ font-weight: 400;
+}
+.panel {
+ border: none;
+ background: white;
+ padding: 1em .75em;
+ border-radius: 3px;
+ -moz-border-radius: 3px;
+ -webkit-border-radius: 3px;
+ color: #76868A;
+ box-shadow: 0 0 2px rgba(0, 0, 0, 0.09);
+ margin-bottom: 2em;
+}
+
+.panel-default > .panel-heading {
+ background-image: none;
+ border: none;
+ background-color: white;
+}
+
+.panel-heading {
+ padding: 0.5em 15px 0;
+}
+
+.panel-title {
+ font-size: 130%;
+ color: #4A5456;
+}
+
+.panel-body {
+ padding: 10px 15px;
+}
+
+.mkwsFacetTitle {
+ font-style: italic;
+ font-weight: 400;
+}
+ .mkwsTerm {
+ padding: .1em 0;
+ }
+ .mkwsTerm a {
+ padding-right: .5em;
+ font-weight: 400;
+ }
+
+.mkwsSummary {
+ padding: .5em 0;
+ line-height: 1.35;
+}
+.mkwsSummary:last-child {
+ padding-bottom: 0;
+}
+
+.container .jumbotron {
+ background: none;
+ padding: 0 2em 0 0;
+ box-shadow: none;
+ color: black;
+}
+ .jumbotron .mkwsSummary {
+ line-height: 1.5;
+ }
+ .jumbotron p{
+ font-size: 150%;
+ }
+ .mkwsCredit {
+ font-size: 125% !important;
+ font-style: italic;
+ }
+
+.mkwsGoogleImage .mkwsSummary {
+ padding: 0;
+ font-weight: 400;
+}
+ .mkwsGoogleImage img {
+ max-width: 100%;
+ max-height: 200px;
+ padding: 1em 0 .5em;
+ }
+.list-group-item {
+ padding: 10px 15px !important;
+}
+.list-group {
+ box-shadow: none;
+ -webkit-box-shadow: none;
+}
+@media screen and (min-width:700px) {
+ .multicol {
+ column-count: 2;
+ column-gap: 20px;
+ -moz-column-count: 2;
+ -moz-column-gap: 20px;
+ -webkit-column-count: 2;
+ -webkit-column-gap: 20px;
+ }
+}
--- /dev/null
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>MKWS demo: Compound reference widget, Bootstrap edition</title>
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
+ <!-- http://www.bootstrapcdn.com/#bootswatch_tab has some themes that look mediumly okay -->
+ <!-- <link href="//maxcdn.bootstrapcdn.com/bootswatch/3.1.1/cyborg/bootstrap.min.css" rel="stylesheet"> -->
+ <!-- <link href="//maxcdn.bootstrapcdn.com/bootswatch/3.1.1/amelia/bootstrap.min.css" rel="stylesheet"> -->
+ <!-- <link href="//maxcdn.bootstrapcdn.com/bootswatch/3.1.1/united/bootstrap.min.css" rel="stylesheet"> -->
+ <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
+ <script type="text/javascript">
+ var mkws_config = { service_proxy_auth: "//mkws.indexdata.com/service-proxy-credoauth" }
+ </script>
+ <script type="text/javascript" src="//mkws.indexdata.com/mkws-complete.js"></script>
+ <!-- <script type="text/javascript" src="//mkws.local/mkws-complete.js"></script> -->
+ <link rel="stylesheet" type="text/css" href="topic-bootstrap.css">
+ <script>
+ // The Google Images database returns links like:
+ // http://images.google.com/url?q=http://eofdreams.com/fish.html&sa=U&ei=RAB-U9XNDo2Dqga1o4L4Bw&ved=0CC4Q9QEwAA&usg=AFQjCNFhRtn6GMevHbpITZ6kfx6rsHV2ow
+ // This Handlebars helper avoids a pointless redirect by transforming
+ // this to the URL of the underling page, in this case
+ // http://eofdreams.com/fish.html
+ Handlebars.registerHelper('mkws-googleurl', function(obj) {
+ if (!obj) {
+ return "obj undefined";
+ } else if (!obj[0]) {
+ return "obj[0] undefined, JSON=" + $.toJSON(obj);
+ } else {
+ return mkws.getParameterByName('q', obj[0]);
+ }
+ });
+ </script>
+ <script class="mkwsTemplate_TopicImage" type="text/x-handlebars-template">
+ {{#each hits}}
+ <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
+ <a href="{{mkws-googleurl md-electronic-url}}" target="_blank">
+ {{#mkws-first md-thumburl}}
+ <img src="{{this}}" alt="{{../md-title}}"/>
+ {{/mkws-first}}
+ <br/>
+ </a>
+ <p>{{{md-title}}}</p>
+ </div>
+ {{/each}}
+ </script>
+ <script class="mkwsTemplate_TopicFacet" type="text/x-handlebars-template">
+ {{#each terms}}
+ <li class="list-group-item mkwsTerm">
+ <span class="badge">{{count}}</span>
+ <a href="#" {{linkdata}}>{{term}}</a>
+ </li>
+ {{/each}}
+ </script>
+</head>
+<body>
+ <div class='page-header container' autosearch='!param!q'>
+ <div class="row">
+ <!-- reference entry -->
+ <div class="jumbotron panel col-md-8">
+ <div class="panel-body mkwsReference mkwsTeam_ref" autosearch="!param!q"
+ data-mkws-config='{"paragraphs":1}'></div>
+ </div>
+ <!-- related topics -->
+ <div class="col-md-offset-1 col-md-3"><div class="panel panel-default">
+ <div class="panel-heading title">
+ <h3 class="panel-title">Related Topics</h3>
+ </div>
+ <ul class="panel-body list-group mkwsFacet mkwsTeam_main"
+ autosearch="!param!q"
+ data-mkws-facet="subject"
+ data-mkws-config='{ "template": "TopicFacet" }'></ul>
+ </div></div>
+ </div>
+ <!-- images -->
+ <div class="row">
+ <div class="col-md-12"><div class="panel panel-default">
+ <div class="panel-heading title">
+ <h3 class="panel-title">Images</h3>
+ </div>
+ <div class="panel-body mkwsGoogleImage" autosearch="!param!q"
+ data-mkws-config='{ "maxrecs": 4, "template": "TopicImage", "target": "google_images_js" }'></div>
+ </div></div>
+ </div>
+
+ <!-- sources -->
+ <div class="row">
+ <div class="col-md-4 col-sm-6"><div class="panel panel-default">
+ <div class="panel-heading title">
+ <h3 class="panel-title">News</h3>
+ </div>
+ <div class="panel-body mkwsRecords mkwsTeam_news" autosearch="!param!q"
+ data-mkws-config='{"targetfilter":"categories=news",
+ "perpage":7}'></div>
+ </div></div>
+ <div class="col-md-4 col-sm-6"><div class="panel panel-default">
+ <div class="panel-heading title">
+ <h3 class="panel-title">Articles</h3>
+ </div>
+ <div class="panel-body mkwsRecords mkwsTeam_articles" autosearch="!param!q"
+ data-mkws-config='{"targetfilter":"categories=articles",
+ "perpage":7}'></div>
+ </div></div>
+ <div class="col-md-4 col-sm-6"><div class="panel panel-default">
+ <div class="panel-heading title">
+ <h3 class="panel-title">Books</h3>
+ </div>
+ <div class="panel-body mkwsRecords mkwsTeam_books" autosearch="!param!q"
+ data-mkws-config='{"targetfilter":"categories=books",
+ "perpage":7}'></div>
+ </div></div>
+ </div>
+ <div class="row">
+ <div class="col-md-12"><div class="panel panel-default">
+ <div class="panel-heading title">
+ <h3 class="panel-title">Results from all targets</h3>
+ </div>
+ <div class="panel-body multicol mkwsRecords mkwsTeam_main"></div>
+ </div></div>
+ </div>
+ </div>
+</body>
+</html>
<script type="text/javascript" src="http://mkws.indexdata.com/jquery.json-2.4.js"></script>
<script type="text/javascript" src="http://mkws.indexdata.com/handlebars-v1.1.2.js"></script>
<script type="text/javascript" src="http://mkws.indexdata.com/pazpar2/js/pz2.js"></script>
- <script type="text/javascript" src="http://mkws.indexdata.com/mkws.js"></script>
+ <script type="text/javascript" src="http://mkws.local/src/mkws.js"></script>
</head>
<body>
<table width="100%" border="1">
// initial value allows jQuery popup to use logging.
teams: {},
widgetType2function: {},
+ defaultTemplates: {},
locale_lang: {
"de": {
facets: ["xtargets", "subject", "author"], /* display facets, in this order, [] for none */
responsive_design_width: undefined, /* a page with less pixel width considered as narrow */
log_level: 1, /* log level for development: 0..2 */
+ template_vars: {}, /* values that may be exposed to templates */
dummy: "dummy"
};
}
-mkws.defaultTemplate = function(name) {
- if (name === 'Record') {
- return '\
-<table>\
- <tr>\
- <th>{{mkws-translate "Title"}}</th>\
- <td>\
- {{md-title}}\
- {{#if md-title-remainder}}\
- ({{md-title-remainder}})\
- {{/if}}\
- {{#if md-title-responsibility}}\
- <i>{{md-title-responsibility}}</i>\
- {{/if}}\
- </td>\
- </tr>\
- {{#if md-date}}\
- <tr>\
- <th>{{mkws-translate "Date"}}</th>\
- <td>{{md-date}}</td>\
- </tr>\
- {{/if}}\
- {{#if md-author}}\
- <tr>\
- <th>{{mkws-translate "Author"}}</th>\
- <td>{{md-author}}</td>\
- </tr>\
- {{/if}}\
- {{#if md-electronic-url}}\
- <tr>\
- <th>{{mkws-translate "Links"}}</th>\
- <td>\
- {{#each md-electronic-url}}\
- <a href="{{this}}">Link{{mkws-index1}}</a>\
- {{/each}}\
- </td>\
- </tr>\
- {{/if}}\
- {{#mkws-if-any location having="md-subject"}}\
- <tr>\
- <th>{{mkws-translate "Subject"}}</th>\
- <td>\
- {{#mkws-first location having="md-subject"}}\
- {{#if md-subject}}\
- {{#mkws-commaList md-subject}}\
- {{this}}{{/mkws-commaList}}\
- {{/if}}\
- {{/mkws-first}}\
- </td>\
- </tr>\
- {{/mkws-if-any}}\
- <tr>\
- <th>{{mkws-translate "Locations"}}</th>\
- <td>\
- {{#mkws-commaList location}}\
- {{mkws-attr "@name"}}{{/mkws-commaList}}\
- </td>\
- </tr>\
-</table>\
-';
- } else if (name === "Summary") {
- return '\
-<a href="#" id="{{_id}}" onclick="{{_onclick}}">\
- <b>{{md-title}}</b>\
-</a>\
-{{#if md-title-remainder}}\
- <span>{{md-title-remainder}}</span>\
-{{/if}}\
-{{#if md-title-responsibility}}\
- <span><i>{{md-title-responsibility}}</i></span>\
-{{/if}}\
-{{#if md-date}}, {{md-date}}\
-{{#if location}}\
-, {{#mkws-first location}}{{mkws-attr "@name"}}{{/mkws-first}}\
-{{/if}}\
-{{#if md-medium}}\
-<span>, {{md-medium}}</span>\
-{{/if}}\
-{{/if}}\
-';
- } else if (name === "Image") {
- return '\
- <a href="#" id="{{_id}}" onclick="{{_onclick}}">\
- {{#mkws-first md-thumburl}}\
- <img src="{{this}}" alt="{{../md-title}}"/>\
- {{/mkws-first}}\
- <br/>\
- </a>\
-';
- } else if (name === 'Facet') {
- return '\
-<a href="#"\
-{{#if fn}}\
-onclick="mkws.{{fn}}(\'{{team}}\', \'{{field}}\', \'{{term}}\');return false;"\
-{{/if}}\
->{{term}}</a>\
-<span>{{count}}</span>\
-';
- }
-
- return null;
-};
-
-
// The following functions are dispatchers for team methods that
// are called from the UI using a team-name rather than implicit
// context.
function loadTemplate(name, fallbackString) {
var template = m_template[name];
-
- if (template === undefined) {
- // Fall back to generic template if there is no team-specific one
+ if (template === undefined && Handlebars.compile) {
var source;
var node = $(".mkwsTemplate_" + name + " .mkwsTeam_" + that.name());
if (node && node.length < 1) {
node = $(".mkwsTemplate_" + name);
}
- if (node) {
- source = node.html();
- }
-
- // If the template is not defined in HTML, check the following
- // in order: template registered in the team by a widget;
- // fallback string provided on this invocation; global default.
- if (!source) {
- source = m_templateText[name];
- }
- if (!source) {
- source = fallbackString;
- }
- if (!source) {
- source = mkws.defaultTemplate(name);
+ if (node) source = node.html();
+ if (!source) source = m_templateText[name];
+ if (source) {
+ template = Handlebars.compile(source);
+ log("compiled template '" + name + "'");
}
-
- if (!source) return null;
- template = Handlebars.compile(source);
- log("compiled template '" + name + "'");
+ }
+ //if (template === undefined) template = mkws_templatesbyteam[m_teamName][name];
+ if (template === undefined && Handlebars.templates) {
+ template = Handlebars.templates[name];
+ }
+ if (template === undefined && mkws.defaultTemplates) {
+ template = mkws.defaultTemplates[name];
+ }
+ if (template) {
m_template[name] = template;
+ return template;
}
-
- return template;
+ else {
+ mkws.log("No MKWS template for " + name);
+ return null;
+ }
}
that.loadTemplate = loadTemplate;
var team = this.team;
this.team.queue("records").subscribe(function(data) {
- var html = [];
for (var i = 0; i < data.hits.length; i++) {
var hit = data.hits[i];
that.team.queue("record").publish(hit);
- var divId = team.recordElementId(hit.recid[0]);
- html.push('<div class="mkwsSummary mkwsTeam_' + team.name() + ' ' + divId + '">', renderSummary(hit), '</div>');
+ hit.detailLinkId = team.recordElementId(hit.recid[0]);
+ hit.detailClick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"
+ hit.containerClass = "mkwsSummary mkwsTeam_" + team.name();
+ hit.containerClass += " " + hit.detailLinkId;
// ### At some point, we may be able to move the
// m_currentRecordId and m_currentRecordData members
// from the team object into this widget.
if (hit.recid == team.currentRecordId()) {
- if (team.currentRecordData())
- html.push(team.renderDetails(team.currentRecordData()));
+ if (team.currentRecordData()) {
+ hit.renderedDetails = team.renderDetails(team.currentRecordData());
+ console.log(hit.renderedDetails);
+ }
}
}
- that.node.html(html.join(''));
-
- function renderSummary(hit) {
- var template = team.loadTemplate(that.config.template || "Summary");
- hit._id = team.recordElementId(hit.recid[0]);
- hit._onclick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"
- return template(hit);
- }
+ var template = team.loadTemplate(that.config.template || "Records");
+ var targs = $.extend({}, {"hits": data.hits}, that.config.template_vars);
+ that.node.html(template(targs));
});
that.autosearch();
--- /dev/null
+{{!
+Records presented as images.
+
+hits:
+ containerClass - class attribute for same
+ detailLinkId - id for the element triggering detail display
+ detailClick - a click event handler for details
+ renderedDetails - active record details rendered from the Record template
+ md-* - metadata fields passed through from backend
+}}
+{{#each hits}}
+ <a href="#" id="{{detailLinkId}}" onclick="{{detailClick}}">
+ {{#mkws-first md-thumburl}}
+ <img src="{{this}}" alt="{{../md-title}}"/>
+ {{/mkws-first}}
+ <br/>
+ </a>
+{{/each}}
--- /dev/null
+{{!
+Full record display.
+}}
+<table>
+ <tr>
+ <th>{{mkws-translate "Title"}}</th>
+ <td>
+ {{md-title}}
+ {{#if md-title-remainder}}
+ ({{md-title-remainder}})
+ {{/if}}
+ {{#if md-title-responsibility}}
+ <i>{{md-title-responsibility}}</i>
+ {{/if}}
+ </td>
+ </tr>
+ {{#if md-date}}
+ <tr>
+ <th>{{mkws-translate "Date"}}</th>
+ <td>{{md-date}}</td>
+ </tr>
+ {{/if}}
+ {{#if md-author}}
+ <tr>
+ <th>{{mkws-translate "Author"}}</th>
+ <td>{{md-author}}</td>
+ </tr>
+ {{/if}}
+ {{#if md-electronic-url}}
+ <tr>
+ <th>{{mkws-translate "Links"}}</th>
+ <td>
+ {{#each md-electronic-url}}
+ <a href="{{this}}">Link{{mkws-index1}}</a>
+ {{/each}}
+ </td>
+ </tr>
+ {{/if}}
+ {{#mkws-if-any location having="md-subject"}}
+ <tr>
+ <th>{{mkws-translate "Subject"}}</th>
+ <td>
+ {{#mkws-first location having="md-subject"}}
+ {{#if md-subject}}
+ {{#mkws-commaList md-subject}}
+ {{this}}{{/mkws-commaList}}
+ {{/if}}
+ {{/mkws-first}}
+ </td>
+ </tr>
+ {{/mkws-if-any}}
+ <tr>
+ <th>{{mkws-translate "Locations"}}</th>
+ <td>
+ {{#mkws-commaList location}}
+ {{mkws-attr "@name"}}{{/mkws-commaList}}
+ </td>
+ </tr>
+</table>
--- /dev/null
+{{!
+Records from a search.
+
+hits:
+ containerClass - class attribute for same
+ detailLinkId - id for the element triggering detail display
+ detailClick - a click event handler for details
+ renderedDetails - active record details rendered from the Record template
+ md-* - metadata fields passed through from backend
+}}
+{{#each hits}}
+ <div class="{{containerClass}}">
+ <a href="#" id="{{detailLinkId}}" onclick="{{detailClick}}">
+ <b>{{md-title}}</b>
+ </a>
+ {{#if md-title-remainder}}
+ <span>{{md-title-remainder}}</span>
+ {{/if}}
+ {{#if md-title-responsibility}}
+ <span><i>{{md-title-responsibility}}</i></span>
+ {{/if}}
+ {{#if renderedDetails}}
+ {{{renderedDetails}}}
+ {{/if}}
+ </div>
+{{/each}}
+// A widget for one record
mkws.registerWidgetType('Record', function() {
- mkws.promotionFunction('Records').call(this);
if (!this.config.maxrecs) this.config.maxrecs = 1;
+ var that = this;
+ var team = this.team;
+ team.queue("records").subscribe(function(data) {
+ var template = team.loadTemplate(that.config.template || "Record");
+ var targs = $.extend({}, data.hits[0], that.config.template_vars);
+ that.node.html(template(targs));
+ });
+ that.autosearch();
});
mkws.registerWidgetType('Image', function() {
- mkws.promotionFunction('Record').call(this);
+ mkws.promotionFunction('Records').call(this);
if (!this.config.template) this.config.template = 'Image';
});
mkws.promotionFunction('Record').call(this);
if (!this.config.target) this.config.target = 'wikimedia_wikipedia_single_result';
if (!this.config.template) this.config.template = 'Reference';
- var nPara = this.config.paragraphs || 0;
- var nSent = this.config.sentences || 0;
-
- this.team.registerTemplate('Reference', '\
- <img src="{{md-thumburl}}" alt="{{md-title}}">\
- <h1><a href="{{md-electronic-url}}">{{md-title}}</a></h1>\
-{{#if md-title-remainder}}\
- <b>{{md-title-remainder}}</b>\
-{{/if}}\
-{{#if md-title-responsibility}}\
- <i>{{md-title-responsibility}}</i>\
-{{/if}}\
- {{{mkws-paragraphs md-description ' + nPara + ' ' + nSent + '}}}\
- <p class="mkwsCredit">Wikipedia</p>\
-');
+ this.config.template_vars.paragraphs = this.config.paragraphs || 0;
+ this.config.template_vars.sentences = this.config.sentences || 0;
});
--- /dev/null
+{{!
+Paragraphs and images from a reference source.
+
+sentences - number of sentences to include
+paragraphs - number of paragraphs to include
+md-* - metadata fields passed through from backend
+}}
+<img src="{{md-thumburl}}" alt="{{md-title}}">
+<h1><a href="{{md-electronic-url}}">{{md-title}}</a></h1>
+{{#if md-title-remainder}}
+<b>{{md-title-remainder}}</b>
+{{/if}}
+{{#if md-title-responsibility}}
+<i>{{md-title-responsibility}}</i>
+{{/if}}
+{{{mkws-paragraphs md-description paragraphs sentences}}}
+<p class="mkwsCredit">Wikipedia</p>
mkws.registerWidgetType('Termlists', function() {
- var that = this;
-
// Initially hide the termlists; display when we get results
+ var that = this;
+ var team = this.team;
mkws.$(document).ready(function() {
that.node.hide();
});
- this.team.queue("termlists").subscribe(function(data) {
+ team.queue("termlists").subscribe(function(data) {
that.node.show();
});
- var acc = [];
- var facets = this.config.facets;
- acc.push('<div class="mkwsTermlistsTitle">' + mkws.M('Termlists') + '</div>');
- for (var i = 0; i < facets.length; i++) {
- acc.push('<div class="mkwsFacet mkwsTeam_', this.team.name(), '" data-mkws-facet="', facets[i], '">', '</div>');
- }
- this.node.html(acc.join(''));
-
+ var template = team.loadTemplate(this.config.template || "Termlists");
+ this.node.html(template({
+ team: team.name(),
+ facets: this.config.facets
+ }));
this.autosearch();
});
subject: [ "Subjects", 10, true ],
author: [ "Authors", 10, true ]
}
-
var that = this;
+ var team = this.team;
var name = that.config.facet;
var ref = facetConfig[name] || [ "Unknown", 10, true ];
var caption = this.config['facet_caption_' + name] || ref[0];
var pzIndex = ref[2] ? name : null;
that.toString = function() {
- return '[Widget ' + that.team.name() + ':' + that.type + '(' + name + ')]';
+ return '[Widget ' + team.name() + ':' + that.type + '(' + name + ')]';
};
- var t2 = that.team.loadTemplate('Facet-' + caption);
- that.log("template for Facet-" + caption + " is " + !!t2);
- if (!t2) {
- that.log("no " + caption + "-specific template, falling back");
- t2 = that.team.loadTemplate('Facet');
- }
- that.log("template for Facet is " + !!t2);
-
- that.team.queue("termlists").subscribe(function(data) {
+ team.queue("termlists").subscribe(function(data) {
data = data[name];
- var t1 = that.team.loadTemplate('facetTitle-' + caption, mkws.M(caption))
- var title = t1({ query: that.config.query });
- var acc = [];
- acc.push('<div class="mkwsFacetTitle">', title, '</div>');
-
- var teamName = that.team.name();
+ var terms = [];
+ var teamName = team.name();
for (var i = 0; i < data.length && i < max; i++) {
- var fn, field;
- // General case modifies the query; special case selects a target
- if (pzIndex) {
- fn = 'limitQuery'; field = pzIndex;
- } else if (!that.team.targetFiltered(data[i].id)) {
- fn = 'limitTarget'; field = data[i].id;
+ var linkdata = "";
+ var action = "";
+ if (!pzIndex) {
+ // Special case: target selection
+ linkdata += ('target_id='+data[i].id+' ');
+ if (!team.targetFiltered(data[i].id)) {
+ action = 'mkws.limitTarget(\'' + teamName + '\', this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
+ }
+ } else {
+ action = 'mkws.limitQuery(\'' + teamName + '\', \'' + pzIndex + '\', this.firstChild.nodeValue)';
}
-
- var s = t2({
- team: teamName,
- fn: fn,
- field: field,
+ linkdata += 'onclick="' + action + ';return false;"';
+ terms.push({
term: data[i].name,
count: data[i].freq,
- query: that.config.query
- });
- acc.push('<div class="mkwsTerm">', s, '</div>');
+ linkdata: linkdata
+ });
}
-
- that.node.html(acc.join(''));
+ // configured template > facet specific template > default facet template
+ var template;
+ if (that.config.template) {
+ template = team.loadTemplate(that.config.template);
+ } else {
+ template = team.loadTemplate("Facet-" + caption);
+ if (template) {
+ that.log("Using Facet-" + caption + " template.")
+ } else {
+ that.log("No " + caption + " specific template, using default.")
+ template = team.loadTemplate("Facet");
+ }
+ }
+ that.node.html(template({
+ name: name,
+ caption: caption,
+ terms: terms
+ }));
});
-
this.autosearch();
});
--- /dev/null
+{{!
+A facet in the search.
+
+name - facet identifier, typically English and lowercase
+caption - caption for this facet
+terms:
+ term - term name
+ count - count of items matching in the current search for this team
+ linkdata - attributes to add to the term element including an onclick handler
+}}
+
+<div class="mkwsFacetTitle">{{caption}}</div>
+{{#each terms}}
+ <div class="mkwsTerm">
+ <a href="#" {{{linkdata}}}>{{term}}</a> <span>{{count}}</span>
+ </div>
+{{/each}}
--- /dev/null
+{{!
+Termlists, a container of all configured facets.
+
+team - the current team
+facets - array of facet names
+}}
+
+<div class="mkwsTermlistsTitle">Termlists</div>
+{{#each facets}}
+ <div class="mkwsFacet mkwsTeam_{{../team}}" data-mkws-facet="{{this}}"></div>
+{{/each}}
${SRC}/mkws-core.js \
${SRC}/mkws-team.js \
${SRC}/mkws-filter.js \
+ ${SRC}/mkws-templates.js \
${SRC}/mkws-popup.js \
${SRC}/mkws-widget.js \
${SRC}/mkws-widget-main.js \
${SRC}/mkws-widget-builder.js
GENERATED = ${HANDLEBARS_FILE} ${JQUERY_FILE} ${JQUERY_JSON_FILE} ${PP2_FILE} \
- mkws.js mkws.min.js mkws-complete.js mkws-complete.min.js
+ mkws.js mkws.min.js mkws-complete.js mkws-complete.min.js mkws-templates.js
**make-default**: all
echo "Made release $(VERSION)"; \
fi
-mkws.js: $(COMPONENTS) Makefile
+mkws.js: mkws-templates.js $(COMPONENTS) Makefile
rm -f $@
cat ${COMPONENTS} > $@.tmp
mv -f $@.tmp $@
chmod 444 $@
+mkws-templates.js:
+ handlebars -n mkws.defaultTemplates ${SRC}/*.templates/*.handlebars -f ${SRC}/mkws-templates.js
+
mkws-html-includes:
echo $(COMPONENTS) | perl -npe "s,${SRC},,g; s/\s+/\0/g" | \
perl -n0e 'chomp(); print qq{ <script type="text/javascript" src="src$$_"></script>\n}'