Fix some stray id="mkws-foo" specifiers to class="mkws-foo".
[mkws-moved-to-github.git] / doc / mkws-manual.markdown
1 % The MKWS manual: embedded metasearching with the MasterKey Widget Set
2 % Mike Taylor
3 % October 2014
4
5
6 Introduction
7 ============
8
9 There are lots of practical problems in building resource discovery
10 solutions. One of the biggest, and most ubiquitous is incorporating
11 metasearching functionality into existing web-sites -- for example,
12 content-management systems, library catalogues or intranets. In
13 general, even when access to core metasearching functionality is
14 provided by simple web-services such as
15 [Pazpar2](http://www.indexdata.com/pazpar2), integration work is seen
16 as a major part of most projects.
17
18 Index Data provides several different toolkits for communicating with
19 its metasearching middleware, trading off varying degrees of
20 flexibility against convenience:
21
22 * [pz2.js](http://www.indexdata.com/pazpar2/doc/ajaxdev.html) --
23   a low-level JavaScript library for interrogating the
24   [Service Proxy](http://www.indexdata.com/service-proxy/)
25   and
26   [Pazpar2](http://www.indexdata.com/pazpar2/).
27   It allows the HTML/JavaScript programmer
28   to create JavaScript applications to display facets, records,
29   etc. that are fetched from the metasearching middleware.
30
31 * masterkey-ui-core -- a higher-level, complex JavaScript library that
32   uses pz2.js to provide the pieces needed for building a
33   full-featured JavaScript application.
34
35 * MasterKey Demo UI -- an example of a searching application built on
36   top of masterkey-ui-core. Available as a public demo at
37   <http://mk2.indexdata.com/>
38
39 * [MKDru](http://www.indexdata.com/masterkey-drupal) --
40   a toolkit for embedding MasterKey-like searching into
41   [Drupal](https://www.drupal.org/)
42   sites.
43
44 All of these approaches require programming to a greater or lesser
45 extent. Against this backdrop, we introduced
46 [MKWS (the MasterKey Widget Set)](http://mkws.indexdata.com/)
47 -- a set of simple, very high-level HTML+CSS+JavaScript
48 components that can be incorporated into any web-site to provide
49 MasterKey searching facilities. By placing `<div>`s with well-known
50 MKWS classes in any HTML page, the various components of an application
51 can be embedded: search-boxes, results areas, target information, etc.
52
53
54 Simple Example
55 ==============
56
57 The following is
58 [a complete MKWS-based searching application](//example.indexdata.com/simple.html):
59
60     <html>
61       <head>
62         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
63         <title>MKWS demo client</title>
64         <script type="text/javascript" src="//mkws.indexdata.com/mkws-complete.js"></script>
65         <link rel="stylesheet" href="//mkws.indexdata.com/mkws.css" />
66       </head>
67       <body>
68         <div class="mkws-search"></div>
69         <div class="mkws-results"></div>
70       </body>
71     </html>
72
73 Go ahead, try it! Simply put the above in a file (e.g index.html),
74 drop it into a folder accessible with an ordinary web-server (e.g
75 Apache) and load it in your web browser. Just like that, you have
76 working metasearching.
77
78 How the example works
79 ---------------------
80
81 If you know any HTML, the structure of the file will be familar to
82 you: the `<html>` element at the top level contains a `<head>` and a
83 `<body>`. In addition to whatever else you might want to put on your
84 page, you can add MKWS elements.
85
86 These fall into two categories. First, the prerequisites in the HTML
87 header, which are loaded from the tool site `mkws.indexdata.com`:
88
89 * `mkws-complete.js`
90   contains all the JavaScript needed by the widget-set, including a
91   copy of the jQuery library.
92
93 * `mkws.css`
94   provides the default CSS styling
95
96 Second, within the HTML body, `<div>` elements with special IDs that
97 begin `mkws-` can be provided. These are filled in by the MKWS code,
98 and provide the components of the searching UI. The very simple
99 application above has only two such widgets: a search box and a
100 results area. But more are supported.
101
102 Defining Widget Elements
103 ========================
104
105 Widget type
106 -----------
107
108 An HTML element is made an MKWS widget by including an MKWS
109 class-name. These names begin `mkws-`: what follows that prefix
110 specifies the type of the widget. The type can be any sequence of
111 alphanumeric characters and hyphens _except_ something beginning
112 `team` -- see below.
113
114 The main widgets are:
115
116 * `mkws-search` -- provides the search box and button.
117
118 * `mkws-results` -- provides the results area, including a list of
119    brief records (which open out into full versions when clicked),
120    paging for large results sets, facets for refining a search,
121    sorting facilities, etc.
122
123 * `mkws-progress` -- shows a progress bar indicating how many of the
124    targets have responded to the search request.
125
126 * `mkws-stat` -- provides a status line summarising the statistics of
127    the various targets.
128
129 * `mkws-switch` -- provides links to switch between a view of the
130    result records and of the targets that provide them. Only
131    meaningful when `mkwsTargets` is also provided.
132
133 * `mkws-targets` -- the area where per-target information will appear
134    when selected by the link in the `mkwsSwitch` area. Of interest
135    mostly for fault diagnosis rather than for end-users.
136
137 * `mkws-lang` -- provides links to switch between one of several
138    different UI languages. By default, English, Danish and German are
139    provided.
140
141 To see all of these working together, just put them all into the HTML
142 `<body>` like so:
143
144         <div class="mkws-switch"></div>
145         <div class="mkws-lang"></div>
146         <div class="mkws-progress"></div>
147         <div class="mkws-search"></div>
148         <div class="mkws-results"></div>
149         <div class="mkws-targets"></div>
150         <div class="mkws-stat"></div>
151
152 The full set of supported widgets is described in the
153 reference guide below.
154
155 Widget team
156 -----------
157
158 In general a set of widgets work together in a team: in the example
159 above, the search-term that the user enters in the `mkws-search`
160 widget is used to generate the set of records that are displayed in
161 the `mkws-results` widget.
162
163 Sometimes, it's desirable to have multiple teams in a single page. A
164 widget can be placed in a named team by giving it (in addition to its
165 main class) a class that begins with `mkws-team-`: what follows that
166 prefix specifies the team that the widget is part of. For example,
167 `<div class="mkws-search mkws-team-aux">` creates a search widget that
168 is part of the `aux` team.
169
170 Widgets that do not have a team specified (as in the examples above)
171 are placed in the team called `AUTO`.
172
173 Old and new-style class-names
174 -----------------------------
175
176 **NOTE.** Versions of MKWS before v1.0 used camel-case class-names:
177 without hyphens and with second and subsequent words capitalised. So
178 instead of `mkws-search`, it used to be `mkwsSearch`. And the classes
179 used to specify team names used an `mkwsTeam_` prefix (with an
180 underscore). So instead of `mkws-team-foo`, it used to be
181 `mkwsTeam_foo`.
182
183 The 1.x series of MKWS releases recognise these old-style class-names
184 as well as the canonical ones, as a facility for backwards
185 compatibility. However, **these old class-names are deprecated, and
186 support will be removed in v2.0**. Existing applications that use them
187 should be upgraded to the new-style class names as soon as convenient.
188
189 Configuration
190 =============
191
192 Many aspects of the behaviour of MKWS can be modified by setting
193 parameters into the `mkws_config` object. So the HTML header looks
194 like this:
195
196         <script type="text/javascript">
197           var mkws_config = {
198             lang: "da",
199             sort_default: "title",
200             query_width: 60
201           };
202         </script>
203         <script type="text/javascript" src="http://mkws.indexdata.com/mkws-complete.js"></script>
204
205 This configuration sets the UI language to Danish (rather than the
206 default of English), initially sorts search results by title rather
207 than relevance (though as always this can be changed in the UI) and
208 makes the search box a bit wider than the default.
209
210 The full set of supported configuration items is described in the
211 reference guide below.
212
213
214 Control over HTML and CSS
215 =========================
216
217 More sophisticated applications will not simply place the `<div>`s
218 together, but position them carefully within an existing page
219 framework -- such as a Drupal template, an OPAC or a SharePoint page.
220
221 While it's convenient for simple applications to use a monolithic
222 `mkwsResults` area which contains record, facets, sorting options,
223 etc., customised layouts may wish to treat each of these components
224 separately. In this case, `mkwsResults` can be omitted, and the
225 following lower-level widgets provided instead:
226
227 * `mkwsTermlists` -- provides the facets
228
229 * `mkwsRanking` -- provides the options for how records are sorted and
230    how many are included on each page of results.
231
232 * `mkwsPager` -- provides the links for navigating back and forth
233    through the pages of records.
234
235 * `mkwsNavi` -- when a search result has been narrowed by one or more
236    facets, this area shows the names of those facets, and allows the
237    selected values to be clicked in order to remove them.
238
239 * `mkwsRecords` -- lists the actual result records.
240
241 Customisation of MKWS searching widgets can also be achieved by
242 overriding the styles set in the toolkit's CSS stylesheet. The default
243 styles can be inspected in [mkws.css](mkws.css)
244 and overridden in any
245 styles that appears later in the HTML than that file. At the simplest
246 level, this might just mean changing fonts, sizes and colours, but
247 more fundamental changes are also possible.
248
249 To properly apply styles, it's necessary to understand how the HTML is
250 structured, e.g. which elements are nested within which
251 containers. The structures used by the widget-set are described in the
252 reference guide below.
253
254
255 Customised display using Handlebars templates
256 =============================================
257
258 A lot can be done by styling widgets in CSS and changing basic MKWS config
259 options. For further customisation, MKWS allows you to change the markup it
260 outputs for any widget. This is done by overriding the
261 [Handlebars](http://handlebarsjs.com/) template used to generate it. In general
262 these consist of `{{things in double braces}}` that are replaced by values from
263 the system. For details of Handlebars template syntax, see [the online
264 documentation](http://handlebarsjs.com/).
265
266 The templates used by the core widgets can be viewed in [our git
267 repository](http://git.indexdata.com/?p=mkws.git;a=tree;f=src/templates;).
268 Parameters are documented in a comment at the top of each template so
269 you can see what's going where. If all you want to do is add a CSS class to
270 something or change a `span` to a `div` it's easy to just copy the existing
271 template and make your edits.
272
273 Overriding templates
274 --------------------
275
276 To override the template for a widget, include it inline in the document
277 as a `<script>` tag marked with a class of `mkws-template-foo` where foo is the
278 name of the template you want to override (typically the name of the widget).
279 Inline Handlebars templates are distinguished from Javascript via a
280 `type="text/x-handlebars-template"` attribute. For example, to override the
281 pager template you would include this in your document:
282
283     <script class="mkws-template-pager" type="text/x-handlebars-template">
284       ...new Pager template
285     </script>
286
287 The Facet template has a special feature where you can override it on a
288 per-facet basis by adding a dash and the facet name as a suffix eg.
289 `facet-subjects` rather than `facet`. (So `class="mkws-template-facet-subjects"`)
290
291 You can also explicitly specify a different template for a particular instance
292 of a widget by providing the name of your alternative (eg. SpecialPager) as the
293 value of the `template` key in the MKWS config object for that widget:
294 for example, `<div class="mkws-pager" template="special-pager"/>`.
295
296 Templates for MKWS can also be
297 [precompiled](http://handlebarsjs.com/precompilation.html). If a precompiled
298 template of the same name is found in the `Handlebars.templates` object, it
299 will be used instead of the default.
300
301 Inspecting metadata for templating
302 ----------------------------------
303
304 MKWS makes requests to Service Proxy or Pazpar2 that perform the actual
305 searching. Depending on how these are configured and what is available from the
306 targets you are searching there may be more data available than what is
307 presented by the default templates.
308
309 Handlebars offers a convenient log helper that will output the contents of a
310 variable for you to inspect. This lets you look at exactly what is being
311 returned by the back end without needing to use a Javascript debugger. For
312 example, you might prepend `{{log hits}}` to the Records template in order to
313 see what is being returned with each search result in the list. In order for
314 this to work you'll need to enable verbose output from Handlebars which is done
315 by including this line or similar:
316
317     <script>Handlebars.logger.level = 1;</script>
318
319 Internationalisation
320 --------------------
321
322 If you would like your template to use the built in translation functionality,
323 output locale specific text via the mkws-translate helper like so:
324 `{{{mkws-translate "a few words"}}}`.
325
326 Example
327 -------
328
329 Rather than use the included AJAX helpers to render record details inline,
330 here's a Records template that will link directly to the source via the address
331 provided in the metadata as the first element of `md-electronic-url`:
332
333     <script class="mkws-template-records" type="text/x-handlebars-template">
334       {{#each hits}}
335         <div class="{{containerClass}}">
336           <a href="{{md-electronic-url.[0]}}">
337             <b>{{md-title}}</b>
338           </a>
339           {{#if md-title-remainder}}
340             <span>{{md-title-remainder}}</span>
341           {{/if}}
342           {{#if md-title-responsibility}}
343             <span><i>{{md-title-responsibility}}</i></span>
344           {{/if}}
345         </div>
346       {{/each}}
347     </script>
348
349 For a more involved example where markup for multiple widgets is decorated with
350 [Bootstrap](http://getbootstrap.com/) classes and a custom Handlebars helper is
351 employed, take a look at the source of
352 [topic.html](http://example.indexdata.com/topic.html?q=water).
353
354
355 Refinements
356 ===========
357
358
359 Message of the day
360 ------------------
361
362 Some applications might like to open with content in the area that
363 will subsequently be filled with result-records -- a message of the
364 day, a welcome message or a help page. This can be done by placing an
365 `mkwsMOTD` division anywhere on the page. It will be moved into the
366 `mkwsResults` area and initially displayed, but will be hidden when a
367 search is made.
368
369
370 Popup results with jQuery UI
371 ----------------------------
372
373 The [jQuery UI library](http://en.wikipedia.org/wiki/JQuery_UI)
374 can be used to construct MKWS applications in which the only widget
375 generally visible on the page is a search box, and the results appear
376 in a popup. The key part of such an application is this invocation of
377 the MKWS jQuery plugin:
378
379         <div class="mkwsSearch"></div>
380         <div class="mkwsPopup" popup_width="1024" popup_height="650" popup_modal="0" popup_autoOpen="0" popup_button="input.mkwsButton">
381           <div class="mkwsSwitch"></div>
382           <div class="mkwsLang"></div>
383           <div class="mkwsResults"></div>
384           <div class="mkwsTargets"></div>
385           <div class="mkwsStat"></div>
386         </div>
387
388 The necessary scaffolding can be seen in an example application,
389 http://example.indexdata.com/index-popup.html
390
391
392 Authentication and target configuration
393 ---------------------------------------
394
395 By default, MKWS configures itself to use a demonstration account on a
396 service hosted by mkws.indexdata.com. This account (username `demo`,
397 password `demo`) provides access to about a dozen free data
398 sources. Authentication onto this service is via an authentication URL
399 on the same MKWS server, so no explicit configuration is needed.
400
401 In order to search in a customised set of targets, including
402 subscription resources, it's necessary to create an account with
403 Index Data's hosted service proxy, and protect that account with
404 authentication tokens (to prevent unauthorised use of subscription
405 resources). For information on how to do this, see the next section.
406
407
408 MKWS Target Selection
409 =====================
410
411 MKWS accesses targets using the Pazpar2 metasearching engine. Although
412 Pazpar2 can be used directly, using a statically configured set of
413 targets, this usage is unusual. More often, Pazpar2 is fronted by the
414 Service Proxy (SP), which manages authentication, sessions, target
415 selection, etc.
416
417 This document assumes the SP is used, and explains how to go about
418 making a set of targets (a "library") available, how to connect your
419 MKWS application to that library, and how to choose which of the
420 available targets to use.
421
422
423 Maintaining the library
424 -----------------------
425
426 The service proxy accesses sets of targets that are known as
427 "libraries". In general, each customer will have their own library,
428 though some standard libraries may be shared between many customers --
429 for example, a library containing all open-access academic journals.
430 A library can also contain other configuration information, including
431 the set of categories by which targets are classified for the library.
432
433 Libraries are maintained using MKAdmin (MasterKey
434 Admin). Specifically, those used by MKWS are generally maintained on
435 the "MKX Admin" installation at
436 <http://mkx-admin.indexdata.com/console/>
437
438 In general, Index Data will create a library for each customer, then
439 give the customer a username/password pair that they can use to enter
440 MKAdmin and administrate that library.
441
442 Once logged in, customers can select which targets to include (from
443 the list of several thousand that MKAdmin knows about), and make
444 customer-specific modifications -- e.g. overriding the titles of the
445 targets.
446
447 Most importantly, customers' administrators can add authentication
448 credentials that the Service Proxy will used on their behalf when
449 accessing subscription resources -- username/password pairs or proxies
450 to use for IP-based authentication. Note that **it is then crucial to
451 secure the library from use by unauthorised clients**, otherwise the
452 customer's paid subscriptions will be exploited.
453
454 Access to libraries is managed by creating one or more "User Access"
455 records in MKAdmin, under the tab of that name. Each of these records
456 provides a combination of credentials and other data that allow an
457 incoming MKWS client to be identified as having legitimate access to
458 the library. The authentication process, described below, works by
459 searching for a matching User Access record.
460
461
462 Authenticating your MWKS application onto the library
463 -----------------------------------------------------
464
465 Some MKWS applications will be content to use the default library with
466 its selection of targets. Most, though, will want to define their own
467 library providing a different range of available targets. An important
468 case is that of applications that authenticate onto subscription
469 resources by means of back-end site credentials stored in MKAdmin:
470 precautions must be taken so that such library accounts do not allow
471 unauthorised access.
472
473 Setting up such a library is a process of several stages.
474
475 ### Create the User Access account
476
477 Log in to MKAdmin to add a User Access account for your library:
478
479 * Go to <http://mkx-admin.indexdata.com/console/>
480 * Enter the adminstrative username/password
481 * Go to the User Access tab
482 * Create an end-user account
483 * Depending on what authentication method it be used, set the
484   User Access account's username and password, or referring URL, or
485   Service Proxy hostname, or IP-address range.
486
487 If your MWKS application runs at a well-known, permanent address --
488 <http://yourname.com/app.html>, say -- you can set the User Access
489 record so that this originating URL is recognised by setting it into
490 the "Referring URL" field.
491
492 If your application accesses the Service Proxy by a unique virtual
493 hostname -- yourname.sp-mkws.indexdata.com, say -- you can tie the use
494 of this hostname to your library by setting the User Access record's
495 "Host Name" field to name of the host where the SP is accessed. **Note
496 that this is not secure, as other applications can use this virtual
497 hostname to gain access to your library.**
498
499 Or if your application's users are coming from a well-known range of
500 IP-address space, you can enter the range in the "IP Ranges"
501 field. The format of this field is as follows: it can contain any
502 number of ranges, separated by commas; each range is either a single
503 IP address or two addresses separated by a hyphen; each IP address is
504 four small integers separated by periods. For example,
505 `80.229.143.255-80.229.143.255, 5.57.0.0-5.57.255.255, 127.0.0.1`.
506
507 Alternatively, your application can authenticate by username and
508 password credentials. This is a useful approach in several situations,
509 including when you need to specify the use of a different library from
510 usual one. To arrange for this, set the username and password as a
511 single string separated by a slash -- e.g. "mike/swordfish" -- into
512 the User Access record's Authentication field.
513
514 You can set multiple fields into a single User Access record; or
515 create multiple User Access records. For example, a single User Access
516 record can specify both a Referring URL a username/password pair that
517 can be used when running an application from a different URL. But if
518 multiple Referring URLs are needed, then each must be specified in its
519 own User Access record.
520
521 ### Tell the application to use the library
522
523 In the HTML of the application, tell MKWS to authenticate on to the
524 Service Proxy. When referer-based or IP-based authentication is used,
525 this is very simple:
526
527         <script type="text/javascript">
528           var mkws_config = { service_proxy_auth:
529           "//sp-mkws.indexdata.com/service-proxy/?command=auth&action=perconfig" };
530         </script>
531
532 > TODO This should be the default setting: see **MKWS-251**.
533
534 And ensure that access to the MWKS application is from the correct
535 Referrer URL or IP-range.
536
537 ### (Optional): access by a different virtual hostname
538
539 When hostname-based authentication is in use, it's necessary to access
540 the Service Proxy as the correctly named virtual host. This can be
541 done by setting the `service_proxy_auth` configuration item to a
542 URL containing that hostname, such as
543 `//yourname.sp-mkws.indexdata.com/service-proxy/?command=auth&action=perconfig`
544
545 > TODO It should be possible to change just the hostname without
546 > needing to repeat the rest of the URL (protocol, path, query): see
547 > **MKWS-252**.
548
549 > TODO When changing the SP authentication URL, the Pazpar2 URL should
550 > in general change along with it: see **MKWS-253**.
551
552 ### (Optional): embed credentials for access to the library
553
554 When credential-based authentication is in use (username and
555 password), it's necessary to pass these credentials into the Service
556 Proxy when establishing the session. This can most simply be done just
557 by setting the `service_proxy_auth` configuration item to a URL such as
558 `//sp-mkws.indexdata.com/service-proxy/?command=auth&action=perconfig&username=mike&password=swordfish`
559
560 > TODO It should be possible to add the username and password to the
561 > configuration without needing to repeat the rest of the URL: see
562 > **MKWS-254**.
563
564 ### (Optional): conceal credentials from HTML source
565
566 Using a credential-based Service-Proxy authentication URL such as the
567 one above reveals the the credentials to public view -- to anyone who
568 does View Source on the MKWS application. This may be acceptable for
569 some libraries, but is intolerable for those which provide
570 authenticated access to subscription resources.
571
572 In these circumstances, a more elaborate approach is necessary. The
573 idea is to make a URL local to the customer that is used for
574 authentication onto the Service Proxy, hiding the credentials in a
575 local rewrite rule. Then local mechanisms can be used to limit access
576 to that local authentication URL. Here is one way to do it when
577 Apache2 is the application's web-server, which we will call
578 yourname.com:
579
580 Step 1: add a rewriting authentication alias to the configuration:
581
582         RewriteEngine on
583         RewriteRule /spauth/ http://sp-mkws.indexdata.com/service-proxy/?command=auth&action=check,login&username=U&password=PW [P]
584
585 Step 2: set the MKWS configuration item `service_proxy_auth` to
586 <http://yourname.com/spauth/>
587
588 Step 3: protect access to the local path <http://yourname.com/spauth/>
589 (e.g. using a `.htaccess` file).
590
591
592 Choosing targets from the library
593 ---------------------------------
594
595 MKWS applications can choose what subset of the library's targets to
596 use, by means of several alternative settings on individual widgets or
597 in the `mkws_config` structure:
598
599 * `targets` -- contains a Pazpar2 targets string, typically of the form
600   "pz:id=" or "pz:id~" followed by a pipe-separated list of low-level
601   target IDs.
602   At present, these IDs can take one of two forms, depending on the
603   configuration of the Service Proxy being used: they may be based on
604   ZURLs (so a typical value would be something like
605   `pz:id=josiah.brown.edu:210/innopac|lui.indexdata.com:8080/solr4/select?fq=database:4902`)
606   or they may be UDBs (so a typical value would be something like
607   `pz:id=brown|artstor`)
608
609 * `targetfilter` -- contains a CQL query which is used to find relevant
610   targets from the relvant library. For example,
611   `udb==Google_Images`
612   or
613   `categories=news`
614
615 * `target` -- contains a single UDB, that of the sole target to be
616   used. For example,
617   `Google_Images`.
618   This is merely syntactic sugar for "targetfilter" with the query
619   `udb==NAME`
620
621 For example, a `Records` widget can be limited to searching only in
622 targets that have been categorised as news sources by providing an
623 attribute as follows:
624
625         <div class="mkwsRecords" targetfilter='categories=news'/>
626
627
628 Reference Guide
629 ===============
630
631 Configuration object
632 --------------------
633
634 The configuration object `mkws_config` may be created before including
635 the MKWS JavaScript code to modify default behaviour. This structure
636 is a key-value lookup table, whose entries are described in the table
637 below. All entries are optional, but if specified must be given values
638 of the specified type. If ommitted, each setting takes the indicated
639 default value; long default values are in footnotes to keep the table
640 reasonably narrow.
641
642 ----
643 Element                   Type    Default   Description
644 --------                  -----   --------- ------------
645 debug_level               int     1         Level of debugging output to emit. 0 = none, 1 = messages, 2 = messages with
646                                             datestamps, 3 = messages with datestamps and stack-traces.
647
648 facets                    array   *Note 1*  Ordered list of names of facets to display. Supported facet names are
649                                             `xtargets`, `subject` and `author`.
650
651 lang                      string  en        Code of the default language to display the UI in. Supported language codes are `en` =
652                                             English, `de` = German, `da` = Danish, and whatever additional languages are configured
653                                             using `language_*` entries (see below).
654
655 lang_options              array   []        A list of the languages to offer as options. If empty (the default), then all
656                                             configured languages are listed.
657
658 language_*                hash              Support for any number of languages can be added by providing entries whose name is
659                                             `language_` followed by the code of the language. See the separate section below for
660                                             details.
661
662 pazpar2_url               string  *Note 2*  The URL used to access the metasearch middleware. This service must be configured to
663                                             provide search results, facets, etc. It may be either unmediated or Pazpar2 the
664                                             MasterKey Service Proxy, which mediates access to an underlying Pazpar2 instance. In
665                                             the latter case, `service_proxy_auth` must be provided.
666
667 perpage_default           string  20        The initial value for the number of records to show on each page.
668
669 perpage_options           array   *Note 3*  A list of candidate page sizes. Users can choose between these to determine how many
670                                             records are displayed on each page of results.
671
672 query_width               int     50        The width of the query box, in characters.
673
674 responsive_design_width   int               If defined, then the facets display moves between two locations as the screen-width
675                                             varies, as described above. The specified number is the threshhold width, in pixels,
676                                             at which the facets move between their two locations.
677
678 service_proxy_auth        url     *Note 4*  A URL which, when `use_service_proxy` is true, is fetched once at the beginning of each
679                                             session to authenticate the user and establish a session that encompasses a defined set
680                                             of targets to search in.
681
682 service_proxy_auth_domain domain            Can be set to the domain for which `service_proxy_auth` proxies authentication, so
683                                             that cookies are rewritten to appear to be from this domain. In general, this is not
684                                             necessary, as this setting defaults to the domain of `pazpar2_url`.
685
686 show_lang                 bool    true      Indicates whether or not to display the language menu.
687
688 show_perpage              bool    true      Indicates whether or not to display the perpage menu.
689
690 show_sort                 bool    true      Indicates whether or not to display the sort menu.
691
692 show_switch               bool    true      Indicates whether or not to display the switch menu, for switching between showing
693                                             retrieved records and target information.
694
695 sort_default              string  relevance The label of the default sort criterion to use. Must be one of those in the `sort`
696                                             array.
697
698 sort_options              array   *Note 6*  List of supported sort criteria. Each element of the list is itself a two-element list:
699                                             the first element of each sublist is a pazpar2 sort-expression such as `data:0` and
700                                             the second is a human-readable label such as `newest`.
701
702 use_service_proxy         bool    true      If true, then a Service Proxy is used to deliver searching services rather than raw
703                                             Pazpar2.
704 ----
705
706 Perhaps we should get rid of the `show_lang`, `show_perpage`,
707 `show_sort` and `show_switch` configuration items, and simply display the relevant menus
708 only when their containers are provided -- e.g. an `mkwsLang` element
709 for the language menu. But for now we retain these, as an easier route
710 to lightly customise the display than my changing providing a full HTML
711 structure.
712
713 ### Notes
714
715 1. ["sources", "subjects", "authors"]
716
717 2. /pazpar2/search.pz2
718
719 3. [10, 20, 30, 50]
720
721 4. http://sp-mkws.indexdata.com/service-proxy-auth
722
723 5. http://sp-mkws.indexdata.com/service-proxy/
724
725 6. [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]]
726
727
728 Language specification
729 ----------------------
730
731 Support for another UI language can be added by providing an entry in
732 the `mkws_config` object whose name is `language_` followed by the
733 name of the language: for example, `language_French` to support
734 French. Then value of this entry must be a key-value lookup table,
735 mapping the English-language strings of the UI into their equivalents
736 in the specified language. For example:
737
738             var mkws_config = {
739               language_French: {
740                 "Authors": "Auteurs",
741                 "Subjects": "Sujets",
742                 // ... and others ...
743               }
744             }
745
746 The following strings occurring in the UI can be translated:
747 `Displaying`,
748 `Next`,
749 `Prev`,
750 `Records`,
751 `Search`,
752 `Sort by`,
753 `Targets`,
754 `Termlists`,
755 `and show`,
756 `found`,
757 `of`,
758 `per page`
759 and
760 `to`.
761
762 In addition, facet names can be translated:
763 `Authors`,
764 `Sources`
765 and
766 `Subjects`.
767
768 Finally, the names of fields in the full-record display can be
769 translated. These include, but may not be limited to:
770 `Author`,
771 `Date`,
772 `Location`,
773 `Subject`
774 and
775 `Title`.
776
777
778
779 jQuery UI popup invocation
780 --------------------------
781
782 The MasterKey Widget Set can be invoked in a popup window on top of the page.
783
784 Note that when using the `popup` layout, facilities from the jQuery UI
785 toolkit are used, so it's necessary to include both CSS and JavaScript
786 from that toolkit. The relevant lines are:
787
788     <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
789     <link rel="stylesheet" type="text/css"
790           href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
791
792     <div class="mkwsSearch"></div>
793     <div class="mkwsPopup" popup_width="1024" popup_height="650" popup_modal="0" popup_autoOpen="0" popup_button="input.mkwsButton">
794       <div class="mkwsSwitch"></div>
795       <div class="mkwsLang"></div>
796       <div class="mkwsResults"></div>
797       <div class="mkwsTargets"></div>
798       <div class="mkwsStat"></div>
799     </div>
800
801 ----
802 Element         Type    Default             Description
803 --------        -----   -------             ------------
804 popup_width     string  880                 Width of the popup window (if used), in
805                                             pixels.
806
807 popup_height    string  760                 Height of the popup window (if used), in
808                                             pixels.
809
810 popup_button    string  `input.mkwsButton`  (Never change this.)
811
812 popup_modal     string  0                   Modal confirmation mode. Valid values are 0 or 1
813
814 popup_autoOpen  string  1                   Open popup window on load. Valid values are 0 or 1
815
816 ----
817
818
819 The structure of the HTML generated by the MKWS widgets
820 -------------------------------------------------------
821
822 In order to override the default CSS styles provided by the MasterKey Widget
823 Set, it's necessary to understand that structure of the HTML elements that are
824 generated within the widgets. This knowledge make it possible, for example,
825 to style each `<div>` with class `term` but only when it occurs inside an
826 element with ID `#mkwsTermlists`, so as to avoid inadvertently styling other
827 elements using the same class in the non-MKWS parts of the page.
828
829 The HTML structure is as follows. As in CSS, #ID indicates a unique identifier
830 and .CLASS indicates an instance of a class.
831
832     #mkwsSwitch
833       a*
834
835     #mkwsLang
836       ( a | span )*
837
838     #mkwsSearch
839       form
840         input#mkwsQuery type=text
841         input#mkwsButton type=submit
842
843     #mkwsBlanket
844       (no contents -- used only for masking)
845
846     #mkwsResults
847       table
848         tbody
849           tr
850             td
851               #mkwsTermlists
852                 div.title
853                 div.facet*
854                   div.termtitle
855                   ( a span br )*
856             td
857               div#mkwsRanking
858                 form#mkwsSelect
859                   select#mkwsSort
860                   select#mkwsPerpage
861               #mkwsPager
862               #mkwsNavi
863               #mkwsRecords
864                 div.record*
865                   span (for sequence number)
866                   a (for title)
867                   span (for other information such as author)
868                   div.details (sometimes)
869                     table
870                       tbody
871                         tr*
872                           th
873                           td
874     #mkwsTargets
875       #mkwsBytarget
876         table
877           thead
878             tr*
879               td*
880           tbody
881             tr*
882               td*
883
884     #mkwsStat
885       span.head
886       span.clients
887       span.records
888
889 - - -
890
891 Copyright (C) 2013-2014 Index Data ApS. <http://indexdata.com>