Skip to content

Commit d3bcb60

Browse files
Dont use submodules
1 parent 177306c commit d3bcb60

File tree

8 files changed

+836
-1
lines changed

8 files changed

+836
-1
lines changed

examples/jankybrowser

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/jankybrowser/_README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
JankyBrowser
2+
============
3+
4+
The only cross-platform browser that fits in a Gist!
5+
6+
One line install. Works on Linux, MacOSX and Windows.
7+
8+
#### Local Install
9+
```
10+
$> npm install http://gist.github.com/morganrallen/f07f59802884bcdcad4a/download
11+
$> node node_modules/jankybrowser
12+
```
13+
14+
#### Global Install
15+
```
16+
$> npm install -g http://gist.github.com/morganrallen/f07f59802884bcdcad4a/download
17+
$> jankybrowser
18+
```
19+
20+
JankyBrowser is based on [Thrust](https://github.com/breach/thrust)

examples/jankybrowser/browser.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"html/template"
7+
"log"
8+
"net/http"
9+
10+
"github.com/miketheprogrammer/go-thrust/dispatcher"
11+
"github.com/miketheprogrammer/go-thrust/spawn"
12+
"github.com/miketheprogrammer/go-thrust/window"
13+
)
14+
15+
var (
16+
port = flag.Int("port", 8000, "TCP port to listen on")
17+
)
18+
var html *template.Template = template.New("main")
19+
20+
func init() {
21+
template.Must(html.New("browser.html").Parse(string(browser_html)))
22+
23+
}
24+
25+
func index(w http.ResponseWriter, req *http.Request) {
26+
w.Header().Set("Content-Type", "text/html")
27+
w.WriteHeader(http.StatusOK)
28+
err := html.ExecuteTemplate(w, "browser.html", nil)
29+
if err != nil {
30+
log.Printf("Template error: %v", err)
31+
}
32+
}
33+
34+
func main() {
35+
flag.Parse()
36+
spawn.SetBaseDirectory("./")
37+
spawn.Run(true)
38+
thrustWindow := window.NewWindow(fmt.Sprintf("http://127.0.0.1:%d", *port), nil)
39+
thrustWindow.Show()
40+
thrustWindow.Focus()
41+
// BLOCKING - Dont run before youve excuted all commands you want first.
42+
go dispatcher.RunLoop()
43+
addr := fmt.Sprintf("127.0.0.1:%d", *port)
44+
http.Handle("/", http.HandlerFunc(index))
45+
err := http.ListenAndServe(addr, nil)
46+
47+
if err != nil {
48+
panic(err)
49+
}
50+
}

examples/jankybrowser/browser.html

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
<html>
2+
<head>
3+
<style>
4+
html, body,
5+
header {
6+
clear: both;
7+
margin: 0;
8+
padding: 0;
9+
width: 100%;
10+
}
11+
12+
header {
13+
border-bottom: 1px solid gray;
14+
}
15+
16+
header input {
17+
margin: 8px;
18+
}
19+
20+
#nav {
21+
float: left;
22+
}
23+
24+
#nav .forward,
25+
#nav .backward {
26+
font-weight: bold;
27+
float: left;
28+
padding: 8px;
29+
padding-top: 10px;
30+
}
31+
32+
#tabs-wrapper, #tabs {
33+
margin: 0;
34+
padding: 0;
35+
}
36+
37+
#tabs-wrapper {
38+
height: 40px;
39+
overflow: hidden;
40+
}
41+
42+
.tabs {
43+
height: 100%;
44+
list-style: none;
45+
margin: 0;
46+
padding: 0;
47+
overflow: hidden;
48+
width: 100%;
49+
}
50+
51+
.tabs li {
52+
float: left;
53+
line-height: 0.5em;
54+
padding: 15px;
55+
}
56+
57+
.tabs li.active {
58+
background-color: gray;
59+
}
60+
61+
li.tab {
62+
border: 1px solid black;
63+
}
64+
65+
.tab .tab-close {
66+
cursor: pointer;
67+
float: right;
68+
font-size: 0.5em;
69+
left: 5px;
70+
padding-left: 3px;
71+
position: relative;
72+
top: -8px;
73+
}
74+
75+
#new {
76+
border: solid 1px gray;
77+
cursor: pointer;
78+
float: right;
79+
position: absolute;
80+
right: 10px;
81+
text-align: center;
82+
top: 10px;
83+
width: 20px;
84+
-webkit-user-select: none;
85+
z-index: 1000;
86+
}
87+
88+
#page-content {
89+
height: 100%;
90+
width: 100%;
91+
}
92+
93+
#page-content .page {
94+
height: 100%;
95+
transition: left 0.7s ease-in-out;
96+
position: absolute;
97+
left: -100%;
98+
width: 100%;
99+
}
100+
101+
#page-content .page.active {
102+
left: 0;
103+
}
104+
</style>
105+
<script type="text/javascript">
106+
107+
function urlToTtile(url) {
108+
var a = document.createElement("a");
109+
a.href = url;
110+
111+
var hostname = a.hostname;
112+
hostname = hostname.split(".").slice(-2).join(".");
113+
114+
return hostname;
115+
}
116+
117+
var loc;
118+
var tabs;
119+
var newTab;
120+
var pageContent;
121+
var navForward;
122+
var navBackward;
123+
124+
var activePage;
125+
var activeTab;
126+
var activeWV;
127+
128+
function activate(page, tab) {
129+
if(activePage && activePage !== page) {
130+
activePage.classList.remove("active");
131+
}
132+
133+
if(activeTab && activeTab !== tab) {
134+
activeTab.classList.remove("active");
135+
}
136+
137+
activePage = page;
138+
activeTab = tab;
139+
activeWV = page.firstElementChild;
140+
141+
activePage.classList.add("active");
142+
activeTab.classList.add("active");
143+
144+
loc.value = activeWV.src;
145+
}
146+
147+
window.onload = function() {
148+
var $ = document.querySelector.bind(document);
149+
150+
loc = $("header input");
151+
tabs = $("ul.tabs");
152+
newTab = $("#new");
153+
pageContent = $("#page-content");
154+
navForward = $("#nav .forward");
155+
navBackward = $("#nav .backward");
156+
157+
function openNewTab(url) {
158+
var page = document.createElement("div");
159+
page.className = "page";
160+
161+
var webview = document.createElement("webview");
162+
page.appendChild(webview);
163+
164+
pageContent.appendChild(page);
165+
166+
if(url) {
167+
webview.src = url;
168+
}
169+
170+
var tab = document.createElement("li");
171+
tab.className = "tab";
172+
173+
var label = document.createTextNode(urlToTtile(url));
174+
tab.appendChild(label);
175+
176+
var close = document.createElement("div");
177+
close.className = "tab-close";
178+
close.textContent = "X";
179+
tab.appendChild(close);
180+
181+
tabs.appendChild(tab);
182+
183+
function handleTabClick() {
184+
console.log("clicking tab");
185+
activate(page, tab);
186+
}
187+
188+
function handleCloseClick(evt) {
189+
console.log("closing tab");
190+
tab.removeEventListener(handleTabClick);
191+
webview.removeEventListener(handleTabClick);
192+
close.removeEventListener(handleCloseClick);
193+
194+
tab.parentNode.removeChild(tab);
195+
webview.parentNode.removeChild(webview);
196+
197+
evt.stopPropagation();
198+
}
199+
200+
tab.addEventListener("click", handleTabClick, false);
201+
close.addEventListener("click", handleCloseClick, true);
202+
203+
webview.addEventListener("title-set", function(evt) {
204+
label.textContent = evt.title;
205+
}, false);
206+
207+
activate(page, tab);
208+
}
209+
210+
loc.addEventListener("keypress", function(evt) {
211+
if(evt.keyCode === 13) {
212+
console.log("changing location " + loc.value);
213+
214+
activeWV.src = loc.value;
215+
}
216+
}, false);
217+
218+
newTab.addEventListener("click", function() {
219+
openNewTab("http://www.google.com");
220+
}, false);
221+
222+
navBackward.addEventListener("click", function() {
223+
activeWV.back();
224+
});
225+
226+
navForward.addEventListener("click", function() {
227+
activeWV.forward();
228+
});
229+
230+
openNewTab("http://www.google.com");
231+
};
232+
233+
</script>
234+
</head>
235+
<body>
236+
<header>
237+
<div id="nav">
238+
<div class="backward">&lt;</div>
239+
<div class="forward">&gt;</div>
240+
<input id="location" />
241+
</div>
242+
<div id="tabs-wrapper">
243+
<ul class="tabs"></ul>
244+
<div id="new">+</div>
245+
</div>
246+
</header>
247+
<div id="page-content"></div>
248+
</body>
249+
</html>

0 commit comments

Comments
 (0)