Document more configuration settings.
[mkws-moved-to-github.git] / doc / mkws-manual.markdown
1 % The MKWS manual: embedded metasearching with the MasterKey Widget Set
2 % Mike Taylor
3 % October 2014
4
5
6 Introduction
7 ============
8
9 There are lots of practical problems in building resource discovery
10 solutions. One of the biggest, and most ubiquitous is incorporating
11 metasearching functionality into existing web-sites -- for example,
12 content-management systems, library catalogues or intranets. In
13 general, even when access to core metasearching functionality is
14 provided by simple web-services such as
15 [Pazpar2](http://www.indexdata.com/pazpar2), integration work is seen
16 as a major part of most projects.
17
18 Index Data provides several different toolkits for communicating with
19 its metasearching middleware, trading off varying degrees of
20 flexibility against convenience:
21
22 * [pz2.js](http://www.indexdata.com/pazpar2/doc/ajaxdev.html) --
23   a low-level JavaScript library for interrogating the
24   [Service Proxy](http://www.indexdata.com/service-proxy/)
25   and
26   [Pazpar2](http://www.indexdata.com/pazpar2/).
27   It allows the HTML/JavaScript programmer
28   to create JavaScript applications to display facets, records,
29   etc. that are fetched from the metasearching middleware.
30
31 * masterkey-ui-core -- a higher-level, complex JavaScript library that
32   uses pz2.js to provide the pieces needed for building a
33   full-featured JavaScript application.
34
35 * MasterKey Demo UI -- an example of a searching application built on
36   top of masterkey-ui-core. Available as a public demo at
37   <http://mk2.indexdata.com/>
38
39 * [MKDru](http://www.indexdata.com/masterkey-drupal) --
40   a toolkit for embedding MasterKey-like searching into
41   [Drupal](https://www.drupal.org/)
42   sites.
43
44 All of these approaches require programming to a greater or lesser
45 extent. Against this backdrop, we introduced
46 [MKWS (the MasterKey Widget Set)](http://mkws.indexdata.com/)
47 -- a set of simple, very high-level HTML+CSS+JavaScript
48 components that can be incorporated into any web-site to provide
49 MasterKey searching facilities. By placing `<div>`s with well-known
50 MKWS classes in any HTML page, the various components of an application
51 can be embedded: search-boxes, results areas, target information, etc.
52
53
54 Simple example
55 ==============
56
57 The following is
58 [a complete MKWS-based searching application](//example.indexdata.com/simple.html):
59
60         <html>
61           <head>
62             <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
63             <title>MKWS demo client</title>
64             <script type="text/javascript" src="//mkws.indexdata.com/mkws-complete.js"></script>
65             <link rel="stylesheet" href="//mkws.indexdata.com/mkws.css" />
66           </head>
67           <body>
68             <div class="mkws-search"></div>
69             <div class="mkws-results"></div>
70           </body>
71         </html>
72
73 Go ahead, try it! Simply put the above in a file (e.g index.html),
74 drop it into a folder accessible with an ordinary web-server (e.g
75 Apache) and load it in your web browser. Just like that, you have
76 working metasearching.
77
78 How the example works
79 ---------------------
80
81 If you know any HTML, the structure of the file will be familar to
82 you: the `<html>` element at the top level contains a `<head>` and a
83 `<body>`. In addition to whatever else you might want to put on your
84 page, you can add MKWS elements.
85
86 These fall into two categories. First, the prerequisites in the HTML
87 header, which are loaded from the tool site `mkws.indexdata.com`:
88
89 * `mkws-complete.js`
90   contains all the JavaScript needed by the widget-set, including a
91   copy of the jQuery library.
92
93 * `mkws.css`
94   provides the default CSS styling
95
96 Second, within the HTML body, `<div>` elements with special IDs that
97 begin `mkws-` can be provided. These are filled in by the MKWS code,
98 and provide the components of the searching UI. The very simple
99 application above has only two such widgets: a search box and a
100 results area. But more are supported.
101
102 Defining widget elements
103 ========================
104
105 Widget type
106 -----------
107
108 An HTML element is made an MKWS widget by including an MKWS
109 class-name. These names begin `mkws-`: what follows that prefix
110 specifies the type of the widget. The type can be any sequence of
111 alphanumeric characters and hyphens _except_ something beginning
112 `team` -- see below.
113
114 The main widgets are:
115
116 * `mkws-search` -- provides the search box and button.
117
118 * `mkws-results` -- provides the results area, including a list of
119    brief records (which open out into full versions when clicked),
120    paging for large results sets, facets for refining a search,
121    sorting facilities, etc.
122
123 * `mkws-progress` -- shows a progress bar indicating how many of the
124    targets have responded to the search request.
125
126 * `mkws-stat` -- provides a status line summarising the statistics of
127    the various targets.
128
129 * `mkws-switch` -- provides links to switch between a view of the
130    result records and of the targets that provide them. Only
131    meaningful when `mkws-targets` is also provided.
132
133 * `mkws-targets` -- the area where per-target information will appear
134    when selected by the link in the `mkws-switch` area. Of interest
135    mostly for fault diagnosis rather than for end-users.
136
137 * `mkws-lang` -- provides links to switch between one of several
138    different UI languages. By default, English, Danish and German are
139    provided.
140
141 To see all of these working together, just put them all into the HTML
142 `<body>` like so:
143
144         <div class="mkws-switch"></div>
145         <div class="mkws-lang"></div>
146         <div class="mkws-progress"></div>
147         <div class="mkws-search"></div>
148         <div class="mkws-results"></div>
149         <div class="mkws-targets"></div>
150         <div class="mkws-stat"></div>
151
152 The full set of supported widgets is described in the
153 reference guide
154 [below](#widgets).
155
156 Widget team
157 -----------
158
159 In general a set of widgets work together in a team: in the example
160 above, the search-term that the user enters in the `mkws-search`
161 widget is used to generate the set of records that are displayed in
162 the `mkws-results` widget.
163
164 Sometimes, it's desirable to have multiple teams in a single page. A
165 widget can be placed in a named team by giving it (in addition to its
166 main class) a class that begins with `mkws-team-`: what follows that
167 prefix specifies the team that the widget is part of. For example,
168 `<div class="mkws-search mkws-team-aux">` creates a search widget that
169 is part of the `aux` team.
170
171 Widgets that do not have a team specified (as in the examples above)
172 are placed in the team called `AUTO`.
173
174 Old and new-style class-names
175 -----------------------------
176
177 **NOTE.** Versions of MKWS before v1.0 used camel-case class-names:
178 without hyphens and with second and subsequent words capitalised. So
179 instead of `mkws-search`, it used to be `mkwsSearch`. And the classes
180 used to specify team names used an `mkwsTeam_` prefix (with an
181 underscore). So instead of `mkws-team-foo`, it used to be
182 `mkwsTeam_foo`.
183
184 The 1.x series of MKWS releases recognise these old-style class-names
185 as well as the canonical ones, as a facility for backwards
186 compatibility. However, **these old class-names are deprecated, and
187 support will be removed in v2.0**. Existing applications that use them
188 should be upgraded to the new-style class names as soon as convenient.
189
190 Configuring widgets
191 ===================
192
193 Global configuration
194 --------------------
195
196 Many aspects of the behaviour of MKWS can be modified by setting
197 parameters into the `mkws_config` object. So the HTML header looks
198 like this:
199
200         <script type="text/javascript">
201           var mkws_config = {
202             lang_options: [ "en", "da" ]
203             lang: "da",
204             sort_default: "title",
205             query_width: 60
206           };
207         </script>
208         <script type="text/javascript" src="http://mkws.indexdata.com/mkws-complete.js"></script>
209
210 This configuration restricts the set of available UI languages English
211 and Danish (omitting German), sets the default to Danish (rather than
212 the English), initially sorts search results by title rather than
213 relevance (though as always this can be changed in the UI) and makes
214 the search box a bit wider than the default.
215
216 The full set of supported configuration settings is described in the
217 reference guide below.
218
219 Per-widget configuration
220 ------------------------
221
222 In addition to the global configuration provided by the `mkws_config`
223 object, individual widgets' behaviour can be configured by providing
224 configuration settings as attributes on their HTML elements. For example,
225 a `records` widget might be restricted to displaying no more than
226 three records by setting the `numrecs` parameter as follows:
227
228         <div class="mkws-records" maxrecs="3">
229
230 Although this works well, HTML validators will consider this element
231 acceptable, since the `maxrecs` attribute is not part of the HTML
232 schema. However, attributes beginning `data-` are always accepted as
233 HTML extensions, much like email headers beginning with
234 `X-`. Therefore, the widget set also recognises configuration
235 attributes prefixed with `data-mkws-`, so:
236
237         <div class="mkws-records" data-mkws-maxrecs="3">
238
239 For first form is more convenient; the second is more correct.
240
241 Because some configuration settings take structured values rather than
242 simple strings, they cannot be directly provided by inline
243 attributes. To allow for this, the special attribute
244 `data-mkws-config`, if provided, is parsed as JSON and its key-value
245 pairs used as configuration settings for the widget in question. For
246 example, the value of `lang_options` is an array of strings specifying
247 which of the supported UI languages should be made available. The
248 following invocation will limit this list to only English and Danish
249 (omitting German):
250
251         <div class="mkws-lang" data-mkws-config='{ "lang_options": [ "en", "da" ] }'></div>
252
253 (Note that, as JSON requires double quotes around all strings, single
254 quotes must be used to contain the entire attribute value.)
255
256
257 Control over HTML and CSS
258 =========================
259
260 More sophisticated applications will not simply place the widgets
261 together, but position them carefully within an existing page
262 framework -- such as a Drupal template, an OPAC or a SharePoint page.
263
264 While it's convenient for simple applications to use a monolithic
265 `mkws-results` area which contains record, facets, sorting options,
266 etc., customised layouts may wish to treat each of these components
267 separately. In this case, `mkws-results` can be omitted, and the
268 following lower-level widgets provided instead:
269
270 * `mkws-facets` -- provides the facets
271
272 * `mkws-ranking` -- provides the options for how records are sorted and
273    how many are included on each page of results.
274
275 * `mkws-pager` -- provides the links for navigating back and forth
276    through the pages of records.
277
278 * `mkws-navi` -- when a search result has been narrowed by one or more
279    facets, this area shows the names of those facets, and allows the
280    selected values to be clicked in order to remove them.
281
282 * `mkws-records` -- lists the actual result records.
283
284 Customisation of MKWS searching widgets can also be achieved by
285 overriding the styles set in the toolkit's CSS stylesheet. The default
286 styles can be inspected in [mkws.css](mkws.css)
287 and overridden in any
288 styles that appears later in the HTML than that file. At the simplest
289 level, this might just mean changing fonts, sizes and colours, but
290 more fundamental changes are also possible.
291
292 To properly apply styles, it's necessary to understand how the HTML is
293 structured, e.g. which elements are nested within which
294 containers. The structures used by the widget-set are described in the
295 reference guide below.
296
297
298 Customised display using Handlebars templates
299 =============================================
300
301 A lot can be done by styling widgets in CSS and changing basic MKWS config
302 options. For further customisation, MKWS allows you to change the markup it
303 outputs for any widget. This is done by overriding the
304 [Handlebars](http://handlebarsjs.com/) template used to generate it. In general
305 these consist of `{{things in double braces}}` that are replaced by values from
306 the system. For details of Handlebars template syntax, see [the online
307 documentation](http://handlebarsjs.com/).
308
309 The templates used by the core widgets can be viewed in [our git
310 repository](http://git.indexdata.com/?p=mkws.git;a=tree;f=src/templates;).
311 Parameters are documented in a comment at the top of each template so
312 you can see what's going where. If all you want to do is add a CSS class to
313 something or change a `span` to a `div` it's easy to just copy the existing
314 template and make your edits.
315
316 Overriding templates
317 --------------------
318
319 To override the template for a widget, include it inline in the document
320 as a `<script>` tag marked with a class of `mkws-template-foo` where foo is the
321 name of the template you want to override (typically the name of the widget).
322 Inline Handlebars templates are distinguished from Javascript via a
323 `type="text/x-handlebars-template"` attribute. For example, to override the
324 pager template you would include this in your document:
325
326         <script class="mkws-template-pager" type="text/x-handlebars-template">
327           ...new Pager template
328         </script>
329
330 The Facet template has a special feature where you can override it on
331 a per-facet basis by adding a dash and the facet name as a suffix eg.
332 `facet-subjects`. (So `class="mkws-template-facet-subjects"`.) When
333 rendering a facet for which no specific template is defined, the code
334 falls back to using the generic facet template, just called `facet`.
335
336 You can also explicitly specify a different template for a particular
337 instance of a widget by providing the name of your alternative
338 (eg. `special-pager`) as the value of the `template` key in the MKWS
339 config object for that widget: for example, `<div class="mkws-pager"
340 template="special-pager"/>`.
341
342 Templates for MKWS can also be
343 [precompiled](http://handlebarsjs.com/precompilation.html). If a precompiled
344 template of the same name is found in the `Handlebars.templates` object, it
345 will be used instead of the default.
346
347 Inspecting metadata for templating
348 ----------------------------------
349
350 MKWS makes requests to the Service Proxy or Pazpar2 that perform the
351 actual searching. Depending on how these are configured and what is
352 available from the targets you are searching there may be more data
353 available than what is presented by the default templates.
354
355 Handlebars offers a convenient log helper that will output the contents of a
356 variable for you to inspect. This lets you look at exactly what is being
357 returned by the back end without needing to use a Javascript debugger. For
358 example, you might prepend `{{log hits}}` to the Records template in order to
359 see what is being returned with each search result in the list. In order for
360 this to work you'll need to enable verbose output from Handlebars which is done
361 by including this line or similar:
362
363         <script>Handlebars.logger.level = 1;</script>
364
365 Internationalisation
366 --------------------
367
368 If you would like your template to use the built in translation functionality,
369 output locale specific text via the mkws-translate helper like so:
370 `{{{mkws-translate "a few words"}}}`.
371
372 Example
373 -------
374
375 Rather than use the toolkit's included AJAX helpers to render record
376 details inline, here's a summary template that will link directly to
377 the source via the address provided in the metadata as the first
378 element of `md-electronic-url`:
379
380         <script class="mkws-template-summary" type="text/x-handlebars-template">
381           <a href="{{md-electronic-url.[0]}}">
382             <b>{{md-title}}</b>
383           </a>
384           {{#if md-title-remainder}}
385             <span>{{md-title-remainder}}</span>
386           {{/if}}
387           {{#if md-title-responsibility}}
388             <span><i>{{md-title-responsibility}}</i></span>
389           {{/if}}
390         </script>
391
392 For a more involved example where markup for multiple widgets is decorated with
393 [Bootstrap](http://getbootstrap.com/) classes and a custom Handlebars helper is
394 employed, take a look at the source of
395 [topic.html](http://example.indexdata.com/topic.html?q=water).
396
397
398 Some Refinements
399 ================
400
401
402 Message of the day
403 ------------------
404
405 Some applications might like to open with content in the area that
406 will subsequently be filled with result-records -- a message of the
407 day, a welcome message or a help page. This can be done by placing an
408 `mkws-motd` division anywhere on the page. It will initially be moved
409 into the `mkws-results` area and displayed, but will be hidden as soon
410 as the first search is made.
411
412
413 Popup results with jQuery UI
414 ----------------------------
415
416 The [jQuery UI library](http://en.wikipedia.org/wiki/JQuery_UI)
417 can be used to construct MKWS applications in which the only widget
418 generally visible on the page is a search box, and the results appear
419 in a popup. The key part of such an application is this invocation of
420 the MKWS jQuery plugin:
421
422         <div class="mkws-search"></div>
423         <div class="mkws-popup" popup_width="1024" popup_height="650">
424           <div class="mkws-results"></div>
425         </div>
426
427 The necessary scaffolding can be seen in an example application,
428 [popup.html](http://example.indexdata.com/popup.html).
429
430 The relevant properties (`popup_width`, etc.) are documented
431 [below](#jquery-ui-popup-invocation)
432 in the reference section.
433
434
435 MKWS target selection
436 =====================
437
438 Introduction
439 ------------
440
441 MKWS accesses targets using the Pazpar2 metasearching engine. Although
442 Pazpar2 can be used directly, using a statically configured set of
443 targets, this usage is unusual. More often, Pazpar2 is fronted by the
444 Service Proxy (SP), which manages authentication, sessions, target
445 selection, etc. This document assumes the SP is used, and explains how
446 to go about making a set of targets (a "library") available, how to
447 connect your MKWS application to that library, and how to choose which
448 of the available targets to use.
449
450 By default MKWS configures itself to use an account on a service
451 hosted by `sp-mkws.indexdata.com`. By default, it sends no
452 authentication credentials, allowing the appropriate account to be
453 selected on the basis of referring URL or IP address.
454
455 If no account has been set up to recognise the referring URL of the
456 application or the IP address of the client, then a default "MKWS
457 Demo" account is used. This account (which can also be explicitly
458 chosen by using the username `mkws`, password `mkws`) provides access
459 to about a dozen free data sources.
460
461 In order to search in a customised set of targets, including
462 subscription resources, it's necessary to create an account with
463 Index Data's hosted Service Proxy, and protect that account with
464 authentication tokens (to prevent unauthorised use of subscription
465 resources).
466
467 Maintaining the library
468 -----------------------
469
470 The Service Proxy accesses sets of targets that are known as
471 "libraries". In general, each customer will have their own library,
472 though some standard libraries may be shared between many customers --
473 for example, a library containing all open-access academic journals.
474 A library can also contain other configuration information, including
475 the set of categories by which targets are classified for the library.
476
477 Libraries are maintained using MKAdmin (MasterKey
478 Admin). Specifically, those used by MKWS are generally maintained on
479 the "MKX Admin" installation at
480 <http://mkx-admin.indexdata.com/console/>
481 In general, Index Data will create a library for each customer, then
482 give the customer a username/password pair that they can use to enter
483 MKAdmin and administrate that library.
484
485 Once logged in, customers can select which targets to include (from
486 the list of several thousand that MKAdmin knows about), and make
487 customer-specific modifications to the target profiles --
488 e.g. overriding the titles of the targets.
489
490 Most importantly, customers' administrators can add authentication
491 credentials that the Service Proxy will use on their behalf when
492 accessing subscription resources -- username/password pairs or proxies
493 to use for IP-based authentication. Note that **it is then crucial to
494 secure the library from use by unauthorised clients**, otherwise the
495 customer's paid subscriptions will be exploited.
496
497 Access to libraries is managed by creating one or more "User Access"
498 records in MKAdmin, under the tab of that name. Each of these records
499 provides a combination of credentials and other data that allow an
500 incoming MKWS client to be identified as having legitimate access to
501 the library. The authentication process, described below, works by
502 searching for a matching User Access record.
503
504
505 Authenticating your MWKS application onto the library
506 -----------------------------------------------------
507
508 Some MKWS applications will be content to use the default library with
509 its selection of targets. Most, though, will want to define their own
510 library providing a different range of available targets. An important
511 case is that of applications that authenticate onto subscription
512 resources by means of back-end site credentials stored in MKAdmin:
513 precautions must be taken so that such library accounts do not allow
514 unauthorised access.
515
516 Setting up such a library is a process of several stages.
517
518 ### Create the User Access account
519
520 Log in to MKAdmin to add a User Access account for your library:
521
522 * Go to <http://mkx-admin.indexdata.com/console/>
523 * Enter the adminstrative username/password
524 * Go to the User Access tab
525 * Create an end-user account
526 * Depending on what authentication method it be used, set the
527   User Access account's username and password, or referring URL, or
528   IP-address range.
529
530 If your MWKS application runs at a well-known, permanent address --
531 <http://yourname.com/app.html>, say -- you can set the User Access
532 record so that this originating URL is recognised by setting it into
533 the "Referring URL" field. Then the application will always use that
534 library that this User Access record is associated with (unless it
535 sends a username/password pair to override this default).
536
537 Or if your application's users are coming from a well-known range of
538 IP-address space, you can enter the range in the "IP Ranges"
539 field. The format of this field is as follows: it can contain any
540 number of ranges, separated by commas; each range is either a single
541 IP address or two addresses separated by a hyphen; each IP address is
542 four small integers separated by periods. For example,
543 `80.229.143.255-80.229.143.255, 5.57.0.0-5.57.255.255, 127.0.0.1`.
544
545 Alternatively, your application can authenticate by username and
546 password credentials. This is a useful approach in several situations,
547 including when you need to specify the use of a different library from
548 usual one. To arrange for this, set the username and password as a
549 single string separated by a slash -- e.g. `mike/swordfish` -- into
550 the User Access record's Authentication field.
551
552 You can set multiple fields into a single User Access record; or
553 create multiple User Access records. For example, a single User Access
554 record can specify both a Referring URL and a username/password pair
555 that can be used when running an application from a different URL. But
556 if multiple Referring URLs are needed, then each must be specified in
557 its own User Access record.
558
559 ### (Optional): embed credentials for access to the library
560
561 When credential-based authentication is in use (username and
562 password), it's necessary to pass these credentials into the Service
563 Proxy when establishing the session. This is done 
564 by providing the `sp_auth_credentials` configuration setting as a string
565 containing the username and password separated by a slash:
566
567         mkws_config = { sp_auth_credentials: "mike/swordfish" };
568
569 ### (Optional): conceal credentials from HTML source
570
571 Using credential-based authentication settings such as those above
572 reveals the the credentials to public view -- to anyone who does View
573 Source on the MKWS application. This may be acceptable for some
574 libraries, but is intolerable for those which provide authenticated
575 access to subscription resources.
576
577 In these circumstances, a different approach is
578 necessary. Referer-based or IP-based authentication may be
579 appropriate. But if these are not possible, then a more elaborate
580 approach can be used to hide the credentials in a web-server
581 configuration that is not visible to users.
582
583 The idea is to make a Service Proxy authentication URL local to the
584 customer, hiding the credentials in a rewrite rule in the local
585 web-server's configuration. Then local mechanisms can be used to limit
586 access to that local authentication URL. Here is one way to do it when
587 Apache2 is the application's web-server, which we will call
588 yourname.com`:
589
590 Step 1: add a rewriting authentication alias to the configuration:
591
592         RewriteEngine on
593         RewriteRule /spauth/ http://sp-mkws.indexdata.com/service-proxy/\
594                 ?command=auth&action=check,login&username=U&password=PW [P]
595
596 Step 2: set the MKWS configuration setting `service_proxy_auth` to
597 `http://yourname.com/spauth/`.
598
599 Step 3: protect access to the local path `http://yourname.com/spauth/`
600 (e.g. using a `.htaccess` file).
601
602
603 Choosing targets from the library
604 ---------------------------------
605
606 MKWS applications can choose what subset of the library's targets to
607 use, by means of several alternative settings on individual widgets or
608 in the `mkws_config` structure:
609
610 * `targets` -- contains a Pazpar2 targets string, typically of the form
611   "pz:id=" or "pz:id~" followed by a pipe-separated list of low-level
612   target IDs.
613   At present, these IDs can take one of two forms, depending on the
614   configuration of the Service Proxy being used: they may be based on
615   ZURLs (so a typical value would be something like
616   `pz:id=josiah.brown.edu:210/innopac|lui.indexdata.com:8080/solr4/select?fq=database:4902`)
617   or they may be UDBs (so a typical value would be something like
618   `pz:id=brown|artstor`)
619
620 * `targetfilter` -- contains a CQL query which is used to find relevant
621   targets from the relvant library. For example,
622   `udb==Google_Images`
623   or
624   `categories=news`
625
626 * `target` -- contains a single UDB, that of the sole target to be
627   used. For example,
628   `Google_Images`.
629   This is merely syntactic sugar for "targetfilter" with the query
630   `udb==NAME`
631
632 For example, a `Records` widget can be limited to searching only in
633 targets that have been categorised as news sources by providing an
634 attribute as follows:
635
636         <div class="mkws-records" targetfilter='categories=news'/>
637
638
639 Reference guide
640 ===============
641
642 Widgets
643 -------
644
645 The following widgets are provided in the core set. (Others can be
646 added: see the [MKWS developers' guide](mkws-developer.html).)
647
648 ----
649 Name              Description
650 ----              -----------
651 `auth-name`       Initially empty, it updates itself to shows the name
652                   of the library that the application is logged in as
653                   when authentication is complete.
654
655 `builder`         A button which, when pressed, analyses the current
656                   settings of the team that it is a part of, and
657                   generates the HTML for an auto-searching element
658                   that will replicate the present search. This HTML is
659                   displayed in an alert box: it is intended that this
660                   widget be subclassed to store the generated widget
661                   definitions in more useful places.
662
663 `button`          The search button. Usually generated a `search`
664                   widget.
665
666 `categories`      Obtains from the Service Proxy a list of the target
667                   categories associated with the library in use, and
668                   displays them in a drop-down list. When a category
669                   is selected, searches are limited to the targets
670                   that are part of that category.
671
672 `config`          This widget has no functionality of its own, but its
673                   configuration is copied up into its team, allowing
674                   it to affect other widgets in the team. This is the
675                   only way to set configuration settings at the team
676                   level.
677
678 `console-builder` Like the `builder` widget, but emits the generated
679                   HTML on the JavaScript console. This exists to
680                   provide an example of how to subclass the `builder`
681                   widget.
682
683 `cover-art`       Displays cover art for a book by searching in
684                   Amazon. Often used with an `autosearch` attribute to
685                   indicate what book to display. For example,
686                   `<div class="mkws-cover-art" autosearch="isbn=1291177124"></div>`
687                   displays cover art for _All Yesterdays: Unique and
688                   Speculative Views of Dinosaurs and Other Prehistoric
689                   Animals_.
690                   For this widget to work, a library that includes the
691                   AmazonBooks target must be used. For example, the
692                   "DEMO AmazonBooks for MKWS" account, which can be
693                   selected with `sp_auth_credentials="mkws-amazon/mkws"`.
694
695 `details`         This widget is generated by the toolkit itself to
696                   hold the full details of records that are initially
697                   listed in summary form.
698
699 `done`            Initially empty, this widget is set to display
700                   "Search complete: found _n_ records" when all
701                   targets have completed their work, either returning
702                   a hit-count or an error. The message displayed can
703                   be changed by overriding the `done` template using
704                   `<script class="mkws-template-done" type="text/x-handlebars-template">`.
705
706 `facet`           A facet that displays the frequency with which a set
707                   of terms occur within a specific field. The specific
708                   field whose contents are analysed must be specified
709                   by the widget's `facet` configuration setting, which
710                   may conveniently be done by means of the
711                   `data-mkws-facet` attribute on the HTML
712                   element. The supported facets are "subject",
713                   "author" and "xtargets" -- the latter a special case
714                   which treats the target providing a record as a
715                   facet. Most often, `facet` widgets are generated
716                   by a `facets` widget, which knows which facets are
717                   required, but they can also be placed individually.
718
719 `facets`          An area that contains a "Facets" heading and several
720                   `facet` widgets. The set of facet widgets generated
721                   is specified by the `facets` configuration setting,
722                   which may be set globally or at the level of the
723                   widget or the team. The value of this configuration
724                   setting is an array of zero or more strings, each
725                   naming a facet.
726
727 `google-image`    A specialisation of the `images` widget which
728                   defaults to the `Google_Images` target.
729
730 `images`          A specialisation of the `records` widget which
731                   defaults to the `images` template. Unlike the default
732                   summary template, this displays an image from the
733                   URL specified by the `md-thumburl` field of each
734                   record.
735
736 `lang`            Provides a selection between the supported set of
737                   languages (which defaults to English, German and
738                   Danish, but can be configured by the `lang`
739                   configuration setting, whose value is an array of
740                   two-letter language codes).
741
742 `log`             Initially empty, this widget accumulates a log of
743                   messages generated by the widget set, similar to
744                   those emitted on the JavaScript console.
745
746 `lolcat`          A specialisation of the `google-image` widget which
747                   defaults to the search-term "kitteh" and
748                   auto-executes.
749
750 `motd-container`  An empty container which the `motd` widget, if any,
751                   is moved into for initial display. Usually generated
752                   as part of the `results` widget.
753
754 `motd`            May be provided, containing content to appear in the
755                   area where records will later appear. It is moved
756                   into this area (the `motd-container` widget) and
757                   initially displayed; then hidden when the first
758                   search is run. It can be used to provide a "message
759                   of the day".
760
761 `navi`            Shows a list of the facets that have been selected,
762                   and allows them to be deselected.
763
764 `pager`           Shows a list of the available pages of results, and
765                   allows the user to navigate to a selected page.
766
767 `per-page`        Provides a dropdown allowing the user to choose how
768                   many records should appear on each page. The
769                   available set of page-sizes can be specified as the
770                   `perpage_options` configuration setting, whose value is
771                   an array of integers. The initial selected value can
772                   be specified by the `perpage_default` configuration setting.
773
774 `progress`        Shows a progress bar which indicates how many of the
775                   targets have responded to the search.
776
777 `query`           The input area for a query. Usually generated a `search`
778                   widget.
779
780 `ranking`         The result-ranking area, consisting of a `sort`
781                   widget and a `per-page` widget. These may instead
782                   be specified separately if preferred.
783
784 `record`          A detailed display of a single record, usually
785                   appearing when the user clicks on a summary
786                   record. This is generated by the `records` widget.
787
788 `records`         The area in which summary records appear. (Clicking
789                   on a summary record make it pop up as a detailed
790                   record.)
791
792 `reference`       A short summary about a subject specified by the
793                   `autosearch` configuration setting. This is created by
794                   drawing a picture and a paragraph of text from
795                   Wikipedia. To work correctly, this widget must be
796                   used in a library that provides the
797                   `wikimedia_wikipedia_single_result` target.
798
799 `results`         A large compound widget used to provide the most
800                   important results-oriented widgets in a pre-packaged
801                   framework: `facets`, `ranking`, `pager`, `navi` and
802                   `records`.
803
804 `search-form`     The search form, containing the query area and the
805                   button. Usually generated a `search` widget.
806
807 `search`          The search box, consisting of a form containing a
808                   query area and a button.
809
810 `sort`            Provides a dropdown allowing the user to choose how
811                   the displayed records should be sorted. The
812                   available set of sort criteria can be specified as the
813                   `sort_options` configuration setting, whose value is
814                   an array of two-element arrays. The first item of
815                   each sub-array is a pazpar2 sort-expression such as
816                   `data:0` and the second is a human-readable label
817                   such as `newest`. The initial selected
818                   value can be specified by the `sort_default` configuration
819                   setting.
820
821 `stat`            A summary line stating how many targets remain
822                   active, how many records have been found, and how
823                   many of them have been retrieved for display. For
824                   most purposes, the `progress` widget may be
825                   preferable.
826
827 `summary`         A short record, included in the list shown when a
828                   search is run. When clicked, this generally pops up
829                   a detailed `record` widget. This widget is generated
830                   by the toolkit in response to search results.
831
832 `switch`          A pair of buttons allowing the user to switch
833                   between viewing the search results (the usual case)
834                   or the target list.
835
836 `targets`         A list of all targets in the present library,
837                   showing their ID, the number of records they have
838                   found for the current search, any diagnostics they
839                   have returned, the number of records that have been
840                   returned for display, and the connection state.
841 ----
842
843
844 Configuration settings
845 ----------------------
846
847 Configuration settings may be provided at the level of a indiviual widget, or a team, or globally. Per-widget configuration is
848 described above; per-team settings can be placed in a `config` widget belonging to the relevant team, and will be applied to that
849 team as a whole; and global settings are provided in the global variable `mkws_config`. This structure is a key-value lookup
850 table, and may specify the values of many settings.
851
852 Some settings apply only to specific widgets; others to the behaviour of the tookit as a whole. When a widget does not itself have
853 a value specified for a particular configuration setting, its team is consulted; and if that also does not have a value, the global
854 settings are consulted. Only if this, too, is unspecified, is the default value used.
855
856 The supported configuration settings are described in the table below. For those settings that apply only to particular widgets,
857 the relevant widgets are listed. All entries are optional, but if specified must be given values of the specified type. Long
858 default values are in footnotes to keep the table reasonably narrow.
859
860 ----
861 Element                   Widget    Type    Default   Description
862 --------                  ------    -----   --------- ------------
863 auth_hostname             _global_  string            If provided, overrides the `pp2_hostname` setting when constructing the
864                                                       Service Proxy authentication URL. This need only be used when authentication
865                                                       is performed on a different host from the remaining operations (search,
866                                                       retrieve, etc.)
867
868 autosearch                facet,    string            If provided, this setting contains a query which is immediately run on behalf
869                           facets,                     of the team. Often used with an [indirect setting](#indirect-settings).
870                           record,
871                           records,
872                           results
873
874 facet                     facet     string            For a `facet` widget, this setting is mandatory, and indicates which field to
875                                                       list terms for. Three fields are supported: `subject`, `author` and
876                                                       `xtargets` -- the latter a special case which treats the target providing a
877                                                       record as a facet. Any other field may also be used, but the default caption
878                                                       and maximum term-count may not be appropriate, needing to be overridden by
879                                                       `facet_caption_*` and `facet_max_*` settings.
880
881 facet_caption_*           facet     string            Specifies what on-screen caption is to be used for the named facet: for
882                                                       example, if a `date` facet is generated, then `facet_caption_date` can be
883                                                       used to set the caption to "Year".
884
885 facet_max_*               facet     int               Specifies how many terms are to be displayed for the named facet: for
886                                                       example, if a `publisher` facet is generated, then `facet_max_publisher` can
887                                                       be used to limit the list to the top six.
888
889 facets                    _team_    array   *Note 1*  Ordered list of names of facets to display.
890
891 lang                      _team_    string  en        Two-letter ISO code of the default language to display the UI in. Supported
892                                                       language codes are `en` = English, `de` = German, `da` = Danish, and whatever
893                                                       additional languages are configured using `language_*` entries (see below).
894
895 lang_options              lang      array   []        A list of the languages to offer as options. If empty (the default), then all
896                                                       configured languages are listed.
897
898 language_*                _global_  hash              Support for any number of languages can be added by providing entries whose
899                                                       name is `language_` followed by the code of the language. See the separate
900                                                       section below for details.
901
902 limit                     facet,    string            ### See the Search section in
903                           facets,                     [the Protocol chapter of the Pazpar2 manual
904                           record,                     ](http://www.indexdata.com/pazpar2/doc/pazpar2_protocol.html)
905                           records,
906                           results
907
908 log_level                 _global_  int     1         Level of debugging output to emit. 0 = none, 1 = messages, 2 = messages with
909                                                       datestamps, 3 = messages with datestamps and stack-traces.
910
911 maxrecs                   facet,    int
912                           facets,
913                           record,
914                           records,
915                           results
916
917 paragraphs                reference int
918
919 pazpar2_url               _global_  string  *Note 2*  The URL used to access the metasearch middleware. This service must be
920                                                       configured to provide search results, facets, etc. It may be either
921                                                       unmediated or Pazpar2 the MasterKey Service Proxy, which mediates access to
922                                                       an underlying Pazpar2 instance. In the latter case, `service_proxy_auth` must
923                                                       be provided.
924
925 perpage                   facet,    int
926                           facets,
927                           record,
928                           records,
929                           results
930
931 perpage_default           _team_    string  20        The initial value for the number of records to show on each page.
932
933 perpage_options           ranking   array   *Note 3*  A list of candidate page sizes. Users can choose between these to determine
934                                                       how many records are displayed on each page of results.
935
936 pp2_hostname              _global_  string
937
938 pp2_path                  _global_  string
939
940 query_width               _search_  int     50        The width of the query box, in characters.
941
942 responsive_design_width   _global_  int               If defined, then the facets display moves between two locations as the
943                                                       screen-width varies, as described above. The specified number is the
944                                                       threshhold width, in pixels, at which the facets move between their two
945                                                       locations.
946
947 scan_all_nodes            _global_  bool
948
949 sentences                 reference int
950
951 service_proxy_auth        _global_  url     *Note 4*  A URL which, when `use_service_proxy` is true, is fetched once at the
952                                                       beginning of each session to authenticate the user and establish a session
953                                                       that encompasses a defined set of targets to search in.
954
955 service_proxy_auth_domain _global_  domain            Can be set to the domain for which `service_proxy_auth` proxies
956                                                       authentication, so that cookies are rewritten to appear to be from this
957                                                       domain. In general, this is not necessary, as this setting defaults to the
958                                                       domain of `pazpar2_url`.
959
960 show_lang                lang       bool    true      Indicates whether or not to display the language menu.
961
962 show_perpage             ranking    bool    true      Indicates whether or not to display the perpage menu.
963
964 show_sort                ranking    bool    true      Indicates whether or not to display the sort menu.
965
966 show_switch              switch     bool    true      Indicates whether or not to display the switch menu, for switching between
967                                                       showing retrieved records and target information.
968
969 sort                      facet,    string
970                           facets,
971                           record,
972                           records,
973                           results
974
975 sort_default              _team_    string  relevance The label of the default sort criterion to use. Must be one of those in the
976                                                       `sort` array.
977
978 sort_options              ranking   array   *Note 6*  List of supported sort criteria. Each element of the list is itself a
979                                                       two-element list: the first element of each sublist is a pazpar2
980                                                       sort-expression such as `data:0` and the second is a human-readable label
981                                                       such as `newest`.
982
983 sp_auth_credentials       _global_  string
984
985 sp_auth_path              _global_  string
986
987 sp_auth_query             _global_  string
988
989 target                    facet,    string
990                           facets,
991                           record,
992                           records,
993                           results
994
995 targetfilter              facet,    string
996                           facets,
997                           record,
998                           records,
999                           results
1000
1001 targets                   facet,    string
1002                           facets,
1003                           record,
1004                           records,
1005                           results
1006
1007 template                  details,  string
1008                           done,
1009                           facet,
1010                           facets,
1011                           images,
1012                           lang,
1013                           navi,
1014                           pager,
1015                           progress,
1016                           ranking,
1017                           record,
1018                           records,
1019                           reference,
1020                           results,
1021                           search,
1022                           stat,
1023                           switch,
1024                           targets
1025
1026 text                      builder   string
1027
1028 use_service_proxy         _global_  bool    true      If true, then a Service Proxy is used to deliver searching services rather
1029                                                       than raw Pazpar2.
1030 ----
1031
1032 (Perhaps we should get rid of the `show_lang`, `show_perpage`,
1033 `show_sort` and `show_switch` configuration settings, as we display the relevant menus
1034 only when their containers are provided -- e.g. an `mkws-lang` element
1035 for the language menu. But for now we retain these, as an easier route
1036 to lightly customise the display than by providing a full HTML
1037 structure.)
1038
1039 ### Notes
1040
1041 1. ["sources", "subjects", "authors"]
1042
1043 2. /pazpar2/search.pz2
1044
1045 3. [10, 20, 30, 50]
1046
1047 4. http://sp-mkws.indexdata.com/service-proxy-auth
1048
1049 5. http://sp-mkws.indexdata.com/service-proxy/
1050
1051 6. [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]]
1052
1053 ### Indirect settings
1054
1055 FIXME !query!q, !path!2, etc.
1056
1057 Language specification
1058 ----------------------
1059
1060 Support for another UI language can be added by providing an entry in
1061 the `mkws_config` object whose name is `language_` followed by the
1062 name of the language: for example, `language_French` to support
1063 French. Then value of this entry must be a key-value lookup table,
1064 mapping the English-language strings of the UI into their equivalents
1065 in the specified language. For example:
1066
1067         var mkws_config = {
1068           language_French: {
1069             "Authors": "Auteurs",
1070             "Subjects": "Sujets",
1071             // ... and others ...
1072           }
1073         }
1074
1075 The following strings occurring in the UI can be translated:
1076 `Displaying`,
1077 `Next`,
1078 `Prev`,
1079 `Records`,
1080 `Search`,
1081 `Sort by`,
1082 `Targets`,
1083 `Facets`,
1084 `and show`,
1085 `found`,
1086 `of`,
1087 `per page`
1088 and
1089 `to`.
1090
1091 In addition, facet names can be translated:
1092 `Authors`,
1093 `Sources`
1094 and
1095 `Subjects`.
1096
1097 Finally, the names of fields in the full-record display can be
1098 translated. These include, but may not be limited to:
1099 `Author`,
1100 `Date`,
1101 `Location`,
1102 `Subject`
1103 and
1104 `Title`.
1105
1106
1107
1108 jQuery UI popup invocation
1109 --------------------------
1110
1111 The MasterKey Widget Set can be invoked in a popup window on top of the page.
1112
1113 Note that when using the `popup` layout, facilities from the jQuery UI
1114 toolkit are used, so it's necessary to include both CSS and JavaScript
1115 from that toolkit. The relevant lines are:
1116
1117         <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
1118         <link rel="stylesheet" type="text/css"
1119               href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
1120
1121         <div class="mkws-search"></div>
1122         <div class="mkws-popup" popup_width="1024" popup_height="650" popup_autoOpen="0">
1123           <div class="mkws-switch"></div>
1124           <div class="mkws-lang"></div>
1125           <div class="mkws-results"></div>
1126           <div class="mkws-targets"></div>
1127           <div class="mkws-stat"></div>
1128         </div>
1129
1130 ----
1131 Element         Type    Default             Description
1132 --------        -----   -------             ------------
1133 popup_width     string  880                 Width of the popup window (if used), in
1134                                             pixels.
1135
1136 popup_height    string  760                 Height of the popup window (if used), in
1137                                             pixels.
1138
1139 popup_button    string  `input.mkwsButton`  A click on this selector will trigger the
1140                                             popup to open
1141
1142 popup_modal     string  0                   Modal confirmation mode. Valid values are 0 or 1
1143
1144 popup_autoOpen  string  1                   Open popup window on load. Valid values are 0 or 1
1145
1146 ----
1147
1148 You can have more than one mkws-popup widgets on a page. Please use a different 
1149 popup_button value to address the right ones.
1150
1151 The structure of the HTML generated by the MKWS widgets
1152 -------------------------------------------------------
1153
1154 In order to override the default CSS styles provided by the MasterKey Widget
1155 Set, it's necessary to understand that structure of the HTML elements that are
1156 generated within the widgets. This knowledge make it possible, for example,
1157 to style each `<div>` with class `term` but only when it occurs inside an
1158 element with class `mkws-facets`, so as to avoid inadvertently styling other
1159 elements using the same class in the non-MKWS parts of the page.
1160
1161 The HTML structure is as follows. As in CSS, #ID indicates a unique identifier
1162 and .CLASS indicates an instance of a class.
1163
1164         #mkwsSwitch
1165           a*
1166         
1167         #mkwsLang
1168           ( a | span )*
1169         
1170         #mkwsSearch
1171           form
1172             input#mkwsQuery type=text
1173             input#mkwsButton type=submit
1174         
1175         #mkwsBlanket
1176           (no contents -- used only for masking)
1177         
1178         #mkwsResults
1179           table
1180             tbody
1181               tr
1182                 td
1183                   #mkwsTermlists
1184                     div.title
1185                     div.facet*
1186                       div.termtitle
1187                       ( a span br )*
1188                 td
1189                   div#mkwsRanking
1190                     form#mkwsSelect
1191                       select#mkwsSort
1192                       select#mkwsPerpage
1193                   #mkwsPager
1194                   #mkwsNavi
1195                   #mkwsRecords
1196                     div.record*
1197                       span (for sequence number)
1198                       a (for title)
1199                       span (for other information such as author)
1200                       div.details (sometimes)
1201                         table
1202                           tbody
1203                             tr*
1204                               th
1205                               td
1206         #mkwsTargets
1207           #mkwsBytarget
1208             table
1209               thead
1210                 tr*
1211                   td*
1212               tbody
1213                 tr*
1214                   td*
1215         
1216         #mkwsStat
1217           span.head
1218           span.clients
1219           span.records
1220
1221 - - -
1222
1223 Copyright (C) 2013-2014 Index Data ApS. <http://indexdata.com>