Koha/koha-tmpl/intranet-tmpl/lib/keyboard/js/jquery.keyboard.extension-typing.min.js
Agustin Moyano 9e91662ac7
Bug 17178: Add virtual keyboard to advanced cataloguing editor
This patch adds Mottie keyboard (https://github.com/Mottie/Keyboard) to advanced editor.

To test:
1) Apply patches
2) perl install/data/mysql/updatedatabase.pl
3) Enable EnableAdvancedCatalogingEditor system preference
4) Go to cataloguing and to Advanced editor
5) Click on Keyboard shortcuts
SUCCESS => the keyboard shortcut "Ctrl-K" should be displayed, with "Toggle keyboard" as description
6) press Ctrl-K
SUCCESS => a virtual keyboard should be displayed, and a new toolbar button labeled "Keyboard layout" should appear.
	=> when you press a letter on both the physical and virtual keyboard, they should be added to the editor.
7) Click on "Keyboard layout"
SUCCESS => a modal should appear, where you can filter and select keyboard layouts.
	=> when you select a layout, it should be reflected on the keyboard.
	=> when you close the modal without selecting a layout, it should keep using the previous layout.
8) Sign off

Sponsored-by: Round Rock Public Library

Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2019-06-28 15:54:33 +01:00

2 lines
No EOL
4.8 KiB
JavaScript

/*! jQuery UI Virtual Keyboard Typing Simulator v1.12.0 */
!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&"object"==typeof module.exports?module.exports=e(require("jquery")):e(jQuery)}(function(p){p.fn.addTyping=function(e){var t={showTyping:!0,lockTypeIn:!1,delay:250,hoverDelay:250},f=p.keyboard;return this.each(function(){var g,l=p(this).data("keyboard");l&&(g=l.typing_options=p.extend({},t,e),l.typing_keymap={" ":"space",'"':"34","'":"39","&nbsp;":"space","\b":"bksp","{b}":"bksp","{d}":"del","{l}":"left","{r}":"right","\n":"enter","\r":"enter","{e}":"enter","\t":"tab","{t}":"tab"},l.typing_xref={8:"bksp",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"del"},l.typing_event=!1,l.typing_namespace=l.namespace+"typing",l.extensionNamespace.push(l.typing_namespace),g.savedLockInput=l.options.lockInput,l.typing_setup_reset=function(){var e=f.events,t=l.typing_namespace,n=[e.kbHidden,e.kbInactive,""].join(t+" ");l.$el.unbind(t).bind(n,function(){l.typing_reset()}),l.unbindButton(t).bindButton("mousedown"+t,function(){l.typing_reset()})},l.typing_setup=function(){var e=l.typing_namespace;l.typing_setup_reset(),l.$el.bind(f.events.kbBeforeVisible+e,function(){l.typing_setup()}),l.$preview.unbind(e).bind("keyup"+e,function(e){return!(g.init&&g.lockTypeIn||!g.showTyping)&&(37<=e.which&&e.which<=40?void 0:(16===e.which&&(l.shiftActive=!1),18===e.which&&(l.altActive=!1),16===e.which||18===e.which?(l.showSet(),void setTimeout(function(){l.$preview&&l.$preview.focus()},200)):void 0))}).bind("keydown"+e,function(e){if(g.init&&g.lockTypeIn||!g.showTyping)return!1;e.temp=!1,16===e.which&&(e.temp=!l.shiftActive,l.shiftActive=!0),18===e.which&&(e.temp=!l.altActive,l.altActive=!0),e.temp&&(l.showSet(),l.$preview.focus()),l.typing_event=!0,l.typing_xref[e.which]&&l.typing_findKey("",e)}).bind("keypress"+e,function(e){if(g.init&&g.lockTypeIn)return!1;l.typing_event&&!l.options.lockInput&&(l.typing_reset(),l.typing_event=!0,l.typing_findKey("",e))})},l.typing_reset=function(){l.typing_event=g.init=!1,g.text="",g.len=g.current=0,l.options.lockInput=g.savedLockInput},l.typeIn=function(e,t,n,i){if(!l.isVisible())return clearTimeout(l.typing_timer),void l.typing_reset();if(l.typing_event){if(void 0===e)return l.typing_event=!1,void(l.options.lockInput=g.savedLockInput)}else!0!==g.init&&(g.init=!0,l.options.lockInput=g.lockTypeIn,g.text=e||g.text||"",g.len=g.text.length,g.delay=t||g.delay,g.current=0,n&&(g.callback=n)),"{"===(e=g.text.substring(g.current,++g.current))&&"}"===g.text.substring(g.current+1,g.current+2)&&(e+=g.text.substring(g.current,g.current+=2)),l.typing_findKey(e,i)},l.typing_findKey=function(e,t){var n,i,p,y,s,o,r,a,c=f.css,u=f.builtLayouts[l.layout].mappedKeys;if(l.isOpen&&l.$keyboard.length)if(o=l.$keyboard.find("."+c.keySet),y=e in l.typing_keymap?l.typing_keymap[e]:e,n="."+c.keyButton+'[data-action="'+y+'"]',l.typing_event&&t&&(n="keypress"!==t.type&&l.typing_xref.hasOwnProperty(t.keyCode||t.which)?"."+c.keyPrefix+l.processName(l.typing_xref[t.keyCode||t.which]):(i=String.fromCharCode(t.charCode||t.which),u.hasOwnProperty(i)?"."+c.keyButton+'[data-value="'+u[i].replace(/"/g,'\\"')+'"]':"."+c.keyPrefix+l.processName(i))),(s=o.filter(":visible").find(n)).length?l.typing_simulateKey(s,e,t):(a=(s=l.typing_event?o.find(n):(p=e in l.typing_keymap?l.typing_keymap[e]:l.processName(e),o.find("."+c.keyPrefix+p))).closest("."+c.keySet)).attr("name")?(g.showTyping&&(r=a.attr("name"),l.shiftActive=/shift/.test(r),l.altActive=/alt/.test(r),l.metaActive=l.last.keyset[2]=!!/\bmeta/.test(r)&&r.match(/meta[\w-]+/)[0],l.showSet(l.metaActive)),l.typing_simulateKey(s,e,t)):l.typing_event||(e in l.typing_keymap&&l.typing_keymap[e]in f.keyaction?f.keyaction[l.typing_keymap[e]](l,s,t):l.insertText(e),l.checkCombos(),l.$el.trigger(f.events.kbChange,[l,l.el])),g.current<=g.len&&0!==g.len){if(!l.isVisible())return;l.typing_timer=setTimeout(function(){l.typeIn()},g.delay)}else{if(0!==g.len)return l.typing_reset(),void("function"==typeof g.callback&&(l.typing_timer=setTimeout(function(){"function"==typeof g.callback&&g.callback(l)},g.delay)));l.typing_reset()}},l.typing_simulateKey=function(e,t,n){var i=e.length;l.isVisible()&&(g.showTyping&&i&&(e.filter(":visible").trigger("mouseenter"+l.namespace),g.showTyping&&i&&setTimeout(function(){e.trigger("mouseleave"+l.namespace)},Math.min(g.hoverDelay,g.delay))),l.typing_event||setTimeout(function(){t in l.typing_keymap&&l.typing_keymap[t]in f.keyaction?((n=n||p.Event("keypress")).target=e,f.keyaction[l.typing_keymap[t]](l,e,n)):l.insertText(t),l.checkCombos(),l.$el.trigger(f.events.kbChange,[l,l.el])},g.delay/3))},g.showTyping&&l.options.alwaysOpen&&l.isVisible()?l.typing_setup():l.$el.unbind(f.events.kbBeforeVisible+l.typing_namespace).bind(f.events.kbBeforeVisible+l.typing_namespace,function(){g.showTyping?l.typing_setup():l.typing_setup_reset()}))})}});