Skip to content

Commit

Permalink
Merge pull request #2 from IamNguele/url-without-protocol
Browse files Browse the repository at this point in the history
http:// appended to urls without protocol
  • Loading branch information
pfrazee committed Sep 20, 2016
2 parents 447f43b + 422b7db commit 57f11a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules/
18 changes: 15 additions & 3 deletions browser-navbar.jsx
@@ -1,3 +1,13 @@
function normalizedUri(input) {
var prefix = 'http://';

if (!/^([^:\/]+)(:\/\/)/g.test(input) && !prefix.includes(input)) {
input = prefix + input;
}

return input;
}

var BrowserNavbarBtn = React.createClass({
render: function() {
return <a href="#" className={this.props.disabled?'disabled':''} title={this.props.title} onClick={this.props.onClick}><i className={'fa fa-'+this.props.icon} /></a>
Expand All @@ -7,16 +17,18 @@ var BrowserNavbarBtn = React.createClass({
var BrowserNavbarLocation = React.createClass({
onKeyDown: function (e) {
if (e.keyCode == 13)
this.props.onEnterLocation(e.target.value)
this.props.onEnterLocation(normalizedUri(e.target.value))
},
onChange: function (e) {
this.props.onChangeLocation(e.target.value)
this.props.onChangeLocation(normalizedUri(e.target.value))
},
render: function() {
return <input type="text" onKeyDown={this.onKeyDown} onChange={this.onChange} onContextMenu={this.props.onContextMenu} value={this.props.page.location} />
}
})



var BrowserNavbar = React.createClass({
render: function() {
return <div id="browser-navbar">
Expand All @@ -29,4 +41,4 @@ var BrowserNavbar = React.createClass({
</div>
</div>
}
})
})

0 comments on commit 57f11a6

Please sign in to comment.