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