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