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