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