diff options
author | Jason <jason.daurus@gmail.com> | 2016-06-15 00:46:59 +0800 |
---|---|---|
committer | Jason <jason.daurus@gmail.com> | 2016-06-17 04:38:35 +0800 |
commit | f5c597a9e351b8dfb84f0fe3f09046e772482fc6 (patch) | |
tree | 8f44cc55513a04b64b4e79d4d9c18f59f100cfaf /web/src/js/components/prompt.js | |
parent | e5bf1e930a5b6ba0b3300b02daf792d65d795202 (diff) | |
download | mitmproxy-f5c597a9e351b8dfb84f0fe3f09046e772482fc6.tar.gz mitmproxy-f5c597a9e351b8dfb84f0fe3f09046e772482fc6.tar.bz2 mitmproxy-f5c597a9e351b8dfb84f0fe3f09046e772482fc6.zip |
[web] Editor & Prompt
Diffstat (limited to 'web/src/js/components/prompt.js')
-rw-r--r-- | web/src/js/components/prompt.js | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/web/src/js/components/prompt.js b/web/src/js/components/prompt.js deleted file mode 100644 index 5ab26b82..00000000 --- a/web/src/js/components/prompt.js +++ /dev/null @@ -1,102 +0,0 @@ -import React from "react"; -import ReactDOM from 'react-dom'; -import _ from "lodash"; - -import {Key} from "../utils.js"; - -var Prompt = React.createClass({ - contextTypes: { - returnFocus: React.PropTypes.func - }, - propTypes: { - options: React.PropTypes.array.isRequired, - done: React.PropTypes.func.isRequired, - prompt: React.PropTypes.string - }, - componentDidMount: function () { - ReactDOM.findDOMNode(this).focus(); - }, - onKeyDown: function (e) { - e.stopPropagation(); - e.preventDefault(); - var opts = this.getOptions(); - for (var i = 0; i < opts.length; i++) { - var k = opts[i].key; - if (Key[k.toUpperCase()] === e.keyCode) { - this.done(k); - return; - } - } - if (e.keyCode === Key.ESC || e.keyCode === Key.ENTER) { - this.done(false); - } - }, - onClick: function (e) { - this.done(false); - }, - done: function (ret) { - this.props.done(ret); - this.context.returnFocus(); - }, - getOptions: function () { - var opts = []; - - var keyTaken = function (k) { - return _.includes(_.map(opts, "key"), k); - }; - - for (var i = 0; i < this.props.options.length; i++) { - var opt = this.props.options[i]; - if (_.isString(opt)) { - var str = opt; - while (str.length > 0 && keyTaken(str[0])) { - str = str.substr(1); - } - opt = { - text: opt, - key: str[0] - }; - } - if (!opt.text || !opt.key || keyTaken(opt.key)) { - throw "invalid options"; - } else { - opts.push(opt); - } - } - return opts; - }, - render: function () { - var opts = this.getOptions(); - opts = _.map(opts, function (o) { - var prefix, suffix; - var idx = o.text.indexOf(o.key); - if (idx !== -1) { - prefix = o.text.substring(0, idx); - suffix = o.text.substring(idx + 1); - - } else { - prefix = o.text + " ("; - suffix = ")"; - } - var onClick = function (e) { - this.done(o.key); - e.stopPropagation(); - }.bind(this); - return <span - key={o.key} - className="option" - onClick={onClick}> - {prefix} - <strong className="text-primary">{o.key}</strong>{suffix} - </span>; - }.bind(this)); - return <div tabIndex="0" onKeyDown={this.onKeyDown} onClick={this.onClick} className="prompt-dialog"> - <div className="prompt-content"> - {this.props.prompt || <strong>Select: </strong> } - {opts} - </div> - </div>; - } -}); - -export default Prompt; |