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