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"
};
}
}
var template = team.loadTemplate(that.config.template || "Records");
- that.node.html(template({"hits": data.hits}));
+ var targs = $.extend({}, {"hits": data.hits}, that.config.template_vars);
+ that.node.html(template(targs));
});
that.autosearch();
- <a href="#" id="{{_id}}" onclick="{{_onclick}}">
- {{#mkws-first md-thumburl}}
- <img src="{{this}}" alt="{{../md-title}}"/>
- {{/mkws-first}}
- <br/>
- </a>
+{{!
+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}}
+// 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;
});