function serverMessage(msg){ displayData = JSON.parse(msg.data); displayScreen(displayData); } var ws; function openedConnection(){ $('.not-connected').hide(); $('.connected').show(); ws.send('{}'); } function closedConnection(){ $('.not-connected').show(); $('.connected').hide(); setTimeout(connect, 3 * 1000); } function setupConnection(){ connect(); } function connect(){ if(ws){ ws.onopen = null; ws.onclose = null; } var emacsURL = window.location.host + '/socket'; console.log("Trying to connect to " + emacsURL); ws = new WebSocket('ws://' + emacsURL); ws.onopen = openedConnection; ws.onmessage = serverMessage; ws.onclose = closedConnection; } function execute(code){ JSON.stringify(ws.send(JSON.stringify({code: code}))); } //----------------------------------------------------------------------------- //Code for the dynamic part of the page below //Typical messy intertwined jquery code. Would be nice o user angular/ember /* Called when there has potentially been a change in the list of buttons */ function buttonsMayHaveChanged(){ if($('.buttons *').length) $('button[name=openRemoveButtonDialog]').removeClass('disabled'); else $('button[name=openRemoveButtonDialog]').addClass('disabled'); } function closeAddButtonDialog(){ enableInputOverride(); $('#buttonCode').val(''); $('#buttonName').val(''); $('#newButtonDialog').hide(); } function addButton(name, code){ if(code.trim()){ var newButton = $(''); newButton[0].code = code; if(!name || !name.trim()){ var match = code.match(/^[\s()]*([^\t\r\n\f()]+)/); if(match) name = match[1]; else name = code.replace(/[\(\)\s]+/g, ''); } if(name.length > 20){ name = name.slice(0, 17) + '…'; } newButton.text(name); newButton.on('click', function(){ execute(this.code); }); $('.buttons').append(newButton); } } function addButtons(buttons){ $.each(buttons, function(){ addButton(this.name, this.code); }); } function addNavigationButtonSet(){ var navigationButtons = [ {name: "Recenter", code: "(recenter-top-bottom)"}, //scroll-down = scroll text down = cursor up {name: "Page up", code: "(scroll-down-command)"}, {name: "Page down", code: "(scroll-up-command)"}, {name: "First line", code: "(beginning-of-buffer)"}, {name: "Last line", code: "(end-of-buffer)"}, {name: "Previous buffer", code: "(previous-buffer)"}, {name: "Next buffer", code: "(next-buffer)"}, ]; addButtons(navigationButtons); } function addMultipleWindowsButtonSet(){ var navigationButtons = [ {name: "Previous window", code: "(other-window -1)"}, {name: "Next window", code: "(other-window 1)"}, {name: "Split Horizontally", code: "(split-window)"}, {name: "Split Vertically", code: "(split-window nil nil t)"}, {name: "Close window", code: "(delete-window)"}, ]; addButtons(navigationButtons); } function openRemoveButtonDialog(){ disableInputOverride(); var buttonList = $('#removeButtonDialog div.buttonList'); $('#removeButtonDialog .modal-body').append(buttonList); buttonList.append( $('.buttons button').map(function(){ var checkDiv = $('