Skip to content

Commit

Permalink
Changes to make local install of jsbin much easier - in particular fo…
Browse files Browse the repository at this point in the history
…r subdirectory hosting.
  • Loading branch information
remy committed Jun 24, 2011
1 parent d2a918e commit d03b966
Show file tree
Hide file tree
Showing 6 changed files with 5,899 additions and 39 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
@@ -1,3 +0,0 @@
[submodule "js/vendor/jshint"]
path = js/vendor/jshint
url = https://github.com/jshint/jshint.git
16 changes: 9 additions & 7 deletions app.php
@@ -1,8 +1,10 @@
<?php
include('config.php'); // contains DB & important versioning

$host = 'http://' . $_SERVER['HTTP_HOST'];

$pos = strpos($_SERVER['REQUEST_URI'], ROOT);
if ($pos !== false) $pos++;
if ($pos !== false) $pos = strlen(ROOT);

$request_uri = substr($_SERVER['REQUEST_URI'], $pos);
$home = isset($_COOKIE['home']) ? $_COOKIE['home'] : '';
Expand Down Expand Up @@ -67,7 +69,7 @@
if ($action == 'js') {
echo $javascript;
} else {
$url = HOST . $code_id . ($revision == 1 ? '' : '/' . $revision);
$url = $host . ROOT . $code_id . ($revision == 1 ? '' : '/' . $revision);
if (!$ajax) {
echo 'var template = ';
}
Expand Down Expand Up @@ -129,7 +131,7 @@
if (@$_REQUEST['callback']) {
echo $_REQUEST['callback'] . '("';
}
$url = HOST . $code_id . ($revision == 1 ? '' : '/' . $revision);
$url = $host . ROOT . $code_id . ($revision == 1 ? '' : '/' . $revision);
if (isset($_REQUEST['format']) && strtolower($_REQUEST['format']) == 'plain') {
echo $url;
} else {
Expand All @@ -150,9 +152,9 @@
// code was saved, so lets do a location redirect to the newly saved code
$edit_mode = false;
if ($revision == 1) {
header('Location: /' . $code_id . '/edit');
header('Location: ' . ROOT . $code_id . '/edit');
} else {
header('Location: /' . $code_id . '/' . $revision . '/edit');
header('Location: ' . ROOT . $code_id . '/' . $revision . '/edit');
}
}

Expand Down Expand Up @@ -195,7 +197,7 @@
}

if (!$html && !$ajax) {
$javascript = "/*\n Created using " . HOST . "\n Source can be edit via " . HOST . "$code_id/edit\n*/\n\n" . $javascript;
$javascript = "/*\n Created using " . $host . ROOT . "\n Source can be edit via " . $host . ROOT . "$code_id/edit\n*/\n\n" . $javascript;
}

if (!$html) {
Expand Down Expand Up @@ -258,7 +260,7 @@ function formatCompletedCode($html, $javascript, $code_id, $revision) {

if (!$ajax && $code_id != 'jsbin') {
$code_id .= $revision == 1 ? '' : '/' . $revision;
$html = preg_replace('/<html(.*)/', "<html$1\n<!--\n\n Created using " . HOST . "\n Source can be edited via " . HOST . "$code_id/edit\n\n-->", $html);
$html = preg_replace('/<html(.*)/', "<html$1\n<!--\n\n Created using " . $host . ROOT . "\n Source can be edited via " . $host . ROOT . "$code_id/edit\n\n-->", $html);
}

return array($html, $javascript);
Expand Down
30 changes: 15 additions & 15 deletions css/style.css
@@ -1,11 +1,11 @@
/* Font via http://robey.lag.net/2010/06/21/mensch-font.html */
@font-face {
font-family: 'MenschRegular';
src: url('/font/mensch-webfont.eot');
src: url('/font/mensch-webfont.eot?#iefix') format('eot'),
url('/font/mensch-webfont.woff') format('woff'),
url('/font/mensch-webfont.ttf') format('truetype'),
url('/font/mensch-webfont.svg#webfont0UwCC656') format('svg');
src: url('../font/mensch-webfont.eot');
src: url('../font/mensch-webfont.eot?#iefix') format('eot'),
url('../font/mensch-webfont.woff') format('woff'),
url('../font/mensch-webfont.ttf') format('truetype'),
url('../font/mensch-webfont.svg#webfont0UwCC656') format('svg');
font-weight: normal;
font-style: normal;
}
Expand All @@ -17,7 +17,7 @@ body {
font-size: 13px;
min-width: 976px;
overflow: hidden;
background: url(/images/jsbin-bg.gif) repeat-x 0 -10px;
background: url(../images/jsbin-bg.gif) repeat-x 0 -10px;
}

p {
Expand Down Expand Up @@ -364,7 +364,7 @@ div.tall:hover {
text-align: center;
height: 18px;
line-height: 14px;
background: url(/images/down.png) no-repeat 90% center;
background: url(../images/down.png) no-repeat 90% center;
padding-right: 26px;
font-weight: normal;
text-decoration: none;
Expand All @@ -373,7 +373,7 @@ div.tall:hover {
}

#control div.group:hover .title {
background: #eee url(/images/down-hover.png) no-repeat 90% center;
background: #eee url(../images/down-hover.png) no-repeat 90% center;
}

#control div.group .button {
Expand Down Expand Up @@ -525,12 +525,12 @@ body.preview #source select {

.video {
padding-left: 20px;
background: url(/images/play.gif) no-repeat left center;
background: url(../images/play.gif) no-repeat left center;
}

#info {
display: inline-block;
background: url(/images/info.gif) no-repeat bottom left;
background: url(../images/info.gif) no-repeat bottom left;
color: #fff;
font-weight: bold;
font-style: italic;
Expand All @@ -544,7 +544,7 @@ body.preview #source select {
}

#info:hover {
background: url(/images/info.gif) no-repeat top left;
background: url(../images/info.gif) no-repeat top left;
}

#startingpoint {
Expand Down Expand Up @@ -642,7 +642,7 @@ div.javascript {
width: 100%;
height: 100%;
z-index: 99;
background: url(/images/op7.png) repeat;
background: url(../images/op7.png) repeat;
}

.hud .outercontainer {
Expand Down Expand Up @@ -884,13 +884,13 @@ ie6, li {
.button.download {
padding-left: 24px;
/* background-image: url(/images/arrow_down_12x12.png);*/
background-image: url(/images/download.png);
background-image: url(../images/download.png);
background-repeat: no-repeat;
background-position: 8px -33px;
}

.button.download:hover {
background-image: url(/images/download.png);
background-image: url(../images/download.png);
background-repeat: no-repeat;
background-position: 8px 7px;
}
Expand All @@ -917,7 +917,7 @@ ie6, li {
}

#live {
background: white url(/images/jsbin-bg.gif) repeat-x 0 -62px;
background: white url(../images/jsbin-bg.gif) repeat-x 0 -62px;
top: 0;
left: 67%;
border-top: 0;
Expand Down
27 changes: 14 additions & 13 deletions index.php
Expand Up @@ -20,17 +20,18 @@
if ($revision != 1 && $revision) {
$code_id .= '/' . $revision;
}
$code_id_path = '';
$code_id_path = ROOT;
if ($code_id) {
$code_id_path = '/' . $code_id;
$code_id_path = ROOT . $code_id . '/';
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8 />
<title>JS Bin - Collaborative JavaScript Debugging</title>
<link rel="stylesheet" href="/css/style.css?<?=VERSION?>" type="text/css" />
<link rel="stylesheet" href="<?=ROOT?>css/style.css?<?=VERSION?>" type="text/css" />
</head>
<!--[if lt IE 7 ]><body class="source ie ie6"><![endif]-->
<!--[if lt IE 8 ]><body class="source ie ie7"><![endif]-->
Expand All @@ -41,20 +42,20 @@
<div class="buttons">
<a class="tab button source group left" accesskey="1" href="#source">Code</a>
<a class="tab button preview group right gap" accesskey="2" href="#preview" title="Run with alerts, prompts, etc">Render</a>
<a title="Revert" class="button light group left" id="revert" href="#"><img class="enabled" src="/images/revert.png" /><img class="disabled" src="/images/revert-disabled.png" /></a>
<a title="Revert" class="button light group left" id="revert" href="#"><img class="enabled" src="<?=ROOT?>images/revert.png" /><img class="disabled" src="<?=ROOT?>images/revert-disabled.png" /></a>
<?php if ($code_id) : ?>
<a id="jsbinurl" class="button group light left" href="http://<?=$_SERVER['HTTP_HOST'] . '/' . $code_id?>">http://<?=$_SERVER['HTTP_HOST'] . '/' . $code_id?></a>
<a id="jsbinurl" class="button group light left" href="http://<?=$_SERVER['HTTP_HOST'] . ROOT . $code_id?>">http://<?=$_SERVER['HTTP_HOST'] . ROOT . $code_id?></a>

<div class="button group gap right tall">
<a href="/save" class="save title">Save</a>
<a id="clone" title="Create a new copy" class="button clone group light" href="/clone">Clone</a>
<a id="save" title="Save new a new revision" class="button light save group" href="<?=$code_id_path?>/save">Save</a>
<a href="<?=ROOT?>save" class="save title">Save</a>
<a id="clone" title="Create a new copy" class="button clone group light" href="<?=ROOT?>clone">Clone</a>
<a id="save" title="Save new a new revision" class="button light save group" href="<?=$code_id_path?>save">Save</a>
<?php else : ?>
<div class="button group gap left right">
<a href="/save" class="save title">Save</a>
<a id="save" title="Save new bin" class="button save group" href="/save">Save</a>
<a href="<?=ROOT?>save" class="save title">Save</a>
<a id="save" title="Save new bin" class="button save group" href="<?=ROOT?>save">Save</a>
<?php endif ?>
<a id="download" title="Save to drive" class="button download group light" href="/download">Download</a>
<a id="download" title="Save to drive" class="button download group light" href="<?=ROOT?>download">Download</a>
</div>

<span id="panelsvisible" class="gap">View:
Expand Down Expand Up @@ -101,7 +102,7 @@
</div>
<div id="live" class="stretch livepreview"><!-- <span class="close"></span> --></div>
<div id="preview" class="binview stretch"></div>
<form method="post" action="<?=$code_id_path?>/save">
<form method="post" action="<?=$code_id_path?>save">
<input type="hidden" name="method" />
</form>
</div>
Expand Down Expand Up @@ -175,7 +176,7 @@
?>
</script>
<script>jsbin = { version: "<?=VERSION?>" }; tips = <?=file_get_contents('tips.json')?>;</script>
<script src="/js/<?=VERSION?>/jsbin.js"></script>
<script src="<?=ROOT?>js/<?=VERSION?>/jsbin.js"></script>
<?php if (!OFFLINE) : ?>
<script>
var _gaq = _gaq || [];
Expand Down

4 comments on commit d03b966

@evilwalrus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think twice about using shortcut tags for echoing data in PHP (i.e., )

Alot of people have this disabled in their configs, as well as it's disabled by default in recent PHP releases.

@remy
Copy link
Member Author

@remy remy commented on d03b966 Jun 24, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, really? Darn, it's all over the index file. You think I should change it then to the full <?php nonsense?

@evilwalrus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could fork and submit a pull request if you'd like

@remy
Copy link
Member Author

@remy remy commented on d03b966 Jun 24, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in the code right now, so it's not a problem.

Please sign in to comment.