Koha/koha-tmpl/intranet-tmpl/lib/keyboard/js/jquery.keyboard.extension-scramble.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
3.5 KiB
JavaScript

/*! jQuery UI Virtual Keyboard Scramble Extension v1.8.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(f){"use strict";f.keyboard=f.keyboard||{},f.fn.addScramble=function(e){var a={targetKeys:/[a-z\d]/i,byRow:!0,byKeySet:!1,randomizeOnce:!0,randomizeInput:!1,init:null,sameForAll:!1};return this.each(function(){var b,c=f(this).data("keyboard"),t=c.namespace+"Scramble",o=c.options;c&&!c.scramble_options&&(b=c.scramble_options=f.extend({},a,e),c.extensionNamespace.push(t),b.orig_create=o.create,c.scramble_setup=function(e){var t,o,a,n,r,i,u,y,d,s,l;if(t=e.find("."+f.keyboard.css.keySet),e.length){for(b.byKeySet&&(t=t.eq(0)),o=0;o<t.length;o++)if(a=t.eq(o),u=0,l=[],d=[],y=[],s=[],a.children("button, span, br").each(function(){"BR"===this.tagName?(b.byRow?(l.push(this),d.push(!1),s[u]=l,y[u]=d,l=[],d=[]):(s[u]=this,y[u]=!1),u++):(i=!(1!==(i=f(this).attr("data-value")||"").length||!b.targetKeys.test(i))&&i,b.byRow?(l.push(this),d.push(i)):(s[u]=this,y[u]=i,u++))}),a.find("."+f.keyboard.css.endRow).remove(),b.byRow)for(r=0;r<s.length;r++)for(l=c.shuffle(s[r],y[r]),n=0;n<l.length;n++)a.append(l[n]);else for(l=c.shuffle(s,y),n=0;n<l.length;n++)a.append(l[n]);return b.byKeySet&&(e=c.realign(e)),e}},c.getRandomUInt=function(e){var t=window.crypto||window.msCrypto;if(void 0===t)return Math.floor(Math.random()*e);var o=new Uint32Array(1);return t.getRandomValues(o),o[0]%e},c.shuffle=function(e,t){for(var o,a,n=e.length;0<n;)a=c.getRandomUInt(n),!1===t[n-1]&&n--,!1!==t[n-1]&&!1!==t[a]&&(o=e[--n],e[n]=e[a],e[a]=o);return e},c.realign=function(e){var o,a,n,r=e.find("."+f.keyboard.css.keySet),t=r.eq(0);return r=r.filter(":gt(0)"),t.children().each(function(e,t){a="BR"===t.tagName,n=f(t).attr("data-pos"),r.each(function(e,t){o=a?"br:first":'button[data-pos="'+n+'"]',f(t).find(o).appendTo(t)})}),e},c.setScrambleLayout=function(){if(!/^scrambled/.test(o.layout)){c.orig_layout=o.layout;var e=e||"scrambled"+Math.round(1e4*Math.random());o.layout=b.sameForAll?e:"scrambled"+Math.round(1e4*Math.random())}},o.create=function(){var e=o.layout;f.keyboard.builtLayouts[e]={mappedKeys:{},acceptedKeys:[],$keyboard:null},c.layout=o.layout=c.orig_layout,c.buildKeyboard(c.layout,!0),c.layout=o.layout=e,f.keyboard.builtLayouts[e]=f.extend(!0,{},f.keyboard.builtLayouts[c.orig_layout]),b.randomizeOnce&&(f.keyboard.builtLayouts[e].$keyboard=c.scramble_setup(f.keyboard.builtLayouts[c.orig_layout].$keyboard.clone())),c.$keyboard=f.keyboard.builtLayouts[e].$keyboard,b.randomizeInput?c.$el.unbind(f.keyboard.events.kbChange+t).bind(f.keyboard.events.kbChange+t,function(e,t){b.targetKeys.test(t.last.key)&&(t.$keyboard.find("."+o.css.buttonHover).removeClass(o.css.buttonHover),t.$keyboard=t.scramble_setup(t.$keyboard),f(document.elementFromPoint(e.clientX,e.clientY)).trigger("mouseenter"))}):b.randomizeOnce||c.$el.unbind(f.keyboard.events.kbBeforeVisible+t).bind(f.keyboard.events.kbBeforeVisible+t,function(e,t){t.$keyboard=t.scramble_setup(t.$keyboard)}),"function"==typeof b.orig_create&&b.orig_create(c)},c.setScrambleLayout(),o.alwaysOpen&&c.$keyboard.length?setTimeout(function(){var e=f.keyboard.builtLayouts;c.$keyboard=c.scramble_setup(c.$keyboard),c.setScrambleLayout(),void 0===e[o.layout]&&(e[o.layout]={mappedKeys:f.extend({},e[c.layout].mappedKeys),acceptedKeys:f.extend([],e[c.layout].acceptedKeys),$keyboard:c.$keyboard.clone()}),"function"==typeof b.init&&b.init(c)},0):"function"==typeof b.init&&b.init(c))})}});