parent
a808b28940
commit
dc42864607
6 changed files with 140 additions and 26 deletions
@ -0,0 +1,19 @@ |
||||
import './command-line-frame.scss'; |
||||
|
||||
export default class CommandLineFrame { |
||||
constructor(win, initial = '') { |
||||
let url = browser.runtime.getURL('build/command-line.html') + |
||||
'#' + encodeURIComponent(initial); |
||||
|
||||
let element = window.document.createElement('iframe'); |
||||
element.src = url; |
||||
element.className = 'vimvixen-command-line-frame'; |
||||
win.document.body.append(element); |
||||
|
||||
this.element = element; |
||||
} |
||||
|
||||
remove() { |
||||
this.element.remove(); |
||||
} |
||||
} |
@ -0,0 +1,11 @@ |
||||
.vimvixen-command-line-frame { |
||||
margin: 0; |
||||
padding: 0; |
||||
bottom: 0; |
||||
left: 0; |
||||
width: 100%; |
||||
height: 20px; |
||||
position: fixed; |
||||
z-index: 10000; |
||||
border: none; |
||||
} |
@ -1 +1,64 @@ |
||||
import './index.scss'; |
||||
|
||||
const parent = window.parent; |
||||
|
||||
// TODO consider object-oriented
|
||||
var prevValue = ""; |
||||
|
||||
const blurData = () => { |
||||
return JSON.stringify({ |
||||
type: 'vimvixen.commandline.blur' |
||||
}); |
||||
}; |
||||
|
||||
const keydownData = (input) => { |
||||
return JSON.stringify({ |
||||
type: 'vimvixen.commandline.enter', |
||||
value: input.value |
||||
}); |
||||
}; |
||||
|
||||
const keyupData = (input) => { |
||||
return JSON.stringify({ |
||||
type: 'vimvixen.commandline.change', |
||||
value: input.value |
||||
}); |
||||
}; |
||||
|
||||
const handleBlur = () => { |
||||
parent.postMessage(blurData(), '*'); |
||||
}; |
||||
|
||||
const handleKeydown = (e) => { |
||||
switch(e.keyCode) { |
||||
case KeyboardEvent.DOM_VK_ESCAPE: |
||||
parent.postMessage(blurData(), '*'); |
||||
break; |
||||
case KeyboardEvent.DOM_VK_RETURN: |
||||
parent.postMessage(keydownData(e.target), '*'); |
||||
break; |
||||
} |
||||
}; |
||||
|
||||
const handleKeyup = (e) => { |
||||
if (e.target.value === prevValue) { |
||||
return; |
||||
} |
||||
parent.postMessage(keyupData(e.target), '*'); |
||||
prevValue = e.target.value; |
||||
}; |
||||
|
||||
window.addEventListener('load', () => { |
||||
let hash = window.location.hash; |
||||
let initial = ''; |
||||
if (hash.length > 0) { |
||||
initial = decodeURIComponent(hash.substring(1)); |
||||
} |
||||
|
||||
let input = window.document.querySelector('#vimvixen-command-line-line-input'); |
||||
input.addEventListener('blur', handleBlur); |
||||
input.addEventListener('keydown', handleKeydown); |
||||
input.addEventListener('keyup', handleKeyup); |
||||
input.value = initial; |
||||
input.focus(); |
||||
}); |
||||
|
Reference in new issue