forked from Kenshin/simpread
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl.jsx
More file actions
54 lines (44 loc) · 1.47 KB
/
url.jsx
File metadata and controls
54 lines (44 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
console.log( "===== simpread option common: URL =====" )
import * as puplugin from 'puplugin';
import TextField from 'textfield';
export default class URL extends React.Component {
static defaultProps = {
flag: {},
}
static propType = {
flag : React.PropTypes.object,
}
state = {
error : ""
};
changeURL( event ) {
let code = 0;
const url = event.target.value.trim(),
minimatch = puplugin.Plugin( "minimatch" );
if ( url == "" ) {
code = -2;
this.setState({ error : "当前输入不能为空。" });
} else if ( !/^http(s)?:\/\//.test( url ) ) {
code = -1;
this.setState({ error : "请输入有效的 url " });
} else if ( location.protocol.startsWith( "http" ) && !minimatch( window.location.href, url ) && url != this.props.url ) {
code = -1;
this.setState({ error : "请输入与当前网址匹配的域名,支持 minimatch " });
} else {
this.setState({ error : "" });
}
this.props.changeURL( url, code );
}
render() {
return (
<TextField
multi={ false }
placeholder={ "必填,支持 minimatch " }
floatingtext="域名"
value={ this.props.url }
errortext={ this.state.error }
onChange={ evt=>this.changeURL(evt) }
/>
)
}
}