hotkey loader

by cowdd

HTML

<textarea>
    Some entry text.
</textarea>
<div>
    <button class="loader" title="Author(s)">-></button><input id='ikg_authors' type='text'>
</div>
<div>
    <button class="loader" title="date">-></button><input id='date' type='text'>
</div>
<div>
    <button class="loader" title="title">-></button><input id='title' type='text'>
</div>
<div>
    <button class="loader" title="journal">-></button><input id='journal' type='text'>
</div>
<div>
    <button class="loader" title="volNum">-></button><input id='volNum' type='text'>
</div>
<div>
    <button class="loader" title="issue">-></button><input id='issue' type='text'>
</div>
<div id="log"></div>

CSS

input{
    transition: all .5s ease;
}
input.loaded{
    background: #D6EBFF;    
}

JavaScript

function getSelectionText() {
			var text = "";
			if (window.getSelection) {
				text = window.getSelection().toString();
			} else if (document.selection && document.selection.type != "Control") {
				text = document.selection.createRange().text;
			}
			return text;
		}

		var alt	= 18;
        var shift = 16;
        var ctrl = 17;
        var Keycodes = [];
            Keycodes[65] = 'a';
            Keycodes[66] = 'b';
            Keycodes[67] = 'c';
            Keycodes[68] = 'd';
            Keycodes[69] = 'e';
            Keycodes[71] = 'g';
            Keycodes[72] = 'h';
            Keycodes[73] = 'i';
            Keycodes[74] = 'j';
            Keycodes[80] = 'p';
            Keycodes[83] = 's';
            Keycodes[84] = 't';
            Keycodes[86] = 'v';
            Keycodes[89] = 'y';
            
        
		var Hotkeys = {
            a:'authors',
            d:'date',
            t:'title',
            j:'journal',
            v:'volNum',
			i:'issue',
			e:'editors',
			b:'book',
			g:'pages',
			c:'city',
			h:'publisher',
			s:'seriesNum',
			p:'pp',
			y:'docType'
		};
var invert = function (obj) {

  var new_obj = {};

  for (var prop in obj) {
    if(obj.hasOwnProperty(prop)) {
      new_obj[obj[prop]] = prop;
    }
  }

  return new_obj;
};
String.prototype.toProperCase = function () {
    return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
};

		$(document).ready(function (){
			var loaders = $('button.loader');
            loaders.each(function(index) {
                var input = $(this).next('input');
                var rel = "load_" + input.attr('id').split("_").pop();
                var shortcut = invert(Hotkeys)[rel.split("_").pop()];
                var title = $(this).attr('title');
                title = title + "  (alt + " + shortcut +")";
                $(this).attr('rel', rel);
                $(this).attr('title', title.toProperCase());
                
      ...