From 6c46a50ba2658fb08aeb3cf12fa1b6558ca28057 Mon Sep 17 00:00:00 2001 From: Jason Skomorowski Date: Tue, 10 Jun 2014 18:47:52 -0400 Subject: [PATCH] Disambiguate singleton and multiple record templates. --- src/mkws-core.js | 1 + src/mkws-widget-main.js | 3 ++- src/mkws-widget-main.templates/Image.handlebars | 24 +++++++++++++++++------ src/mkws-widget-record.js | 12 ++++++++++-- src/mkws-widget-reference.js | 17 ++-------------- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/mkws-core.js b/src/mkws-core.js index 7b776ab..b3f25cf 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -156,6 +156,7 @@ mkws.setMkwsConfig = function(overrides) { 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" }; diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js index 03eba2e..5106839 100644 --- a/src/mkws-widget-main.js +++ b/src/mkws-widget-main.js @@ -134,7 +134,8 @@ mkws.registerWidgetType('Records', function() { } } 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(); diff --git a/src/mkws-widget-main.templates/Image.handlebars b/src/mkws-widget-main.templates/Image.handlebars index 02bf01d..abee587 100644 --- a/src/mkws-widget-main.templates/Image.handlebars +++ b/src/mkws-widget-main.templates/Image.handlebars @@ -1,6 +1,18 @@ - - {{#mkws-first md-thumburl}} - {{../md-title}} - {{/mkws-first}} -
-
+{{! +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}} + + {{#mkws-first md-thumburl}} + {{../md-title}} + {{/mkws-first}} +
+
+{{/each}} diff --git a/src/mkws-widget-record.js b/src/mkws-widget-record.js index 106c8a3..13d67c3 100644 --- a/src/mkws-widget-record.js +++ b/src/mkws-widget-record.js @@ -1,10 +1,18 @@ +// 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'; }); diff --git a/src/mkws-widget-reference.js b/src/mkws-widget-reference.js index b1044d2..c8d41be 100644 --- a/src/mkws-widget-reference.js +++ b/src/mkws-widget-reference.js @@ -2,19 +2,6 @@ mkws.registerWidgetType('Reference', function() { 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', '\ - {{md-title}}\ -

{{md-title}}

\ -{{#if md-title-remainder}}\ - {{md-title-remainder}}\ -{{/if}}\ -{{#if md-title-responsibility}}\ - {{md-title-responsibility}}\ -{{/if}}\ - {{{mkws-paragraphs md-description ' + nPara + ' ' + nSent + '}}}\ -

Wikipedia

\ -'); + this.config.template_vars.paragraphs = this.config.paragraphs || 0; + this.config.template_vars.sentences = this.config.sentences || 0; }); -- 1.7.10.4