Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
index.html and bare.html are now separate pages that embed friendlycode.
Browse files Browse the repository at this point in the history
Specifically, index.html assumes embedding within the Thimble website
and features Thimble-specific branding, while bare.html is a trivial
embedding of friendlycode.

The many stylesheets used by both pages are now consolidated into
friendlycode.css, which (for now) just @imports all the stylesheets.
A production build system can compile these into a single file for
better performance.
  • Loading branch information
toolness committed Aug 14, 2012
1 parent 647246b commit a84ed3b
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 208 deletions.
24 changes: 24 additions & 0 deletions bare.html
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html class="deployment-type-development">
<head>
<meta charset="utf-8">
<base target="_blank">

<title>Barebones Friendlycode Editor</title>
<link rel="stylesheet" href="css/friendlycode.css">
</head>
<body>
<div id="bare-fc-holder" class="friendlycode-loading"></div>

<script src="js/require-config.js"></script>
<script src="js/require.min.js"></script>
<script>
require(["jquery", "friendlycode"], function($, FriendlycodeEditor) {
return FriendlycodeEditor({
publishURL: "https://webpagemaker-dev.allizom.org",
container: $("#bare-fc-holder")
});
});
</script>
</body>
</html>
41 changes: 0 additions & 41 deletions css/editor.css
Expand Up @@ -30,14 +30,6 @@ img {
border: 0 none;
}

#friendlycode-holder {
position: absolute;
top: 79px;
bottom: 0;
left: 0;
right: 0;
}

.friendlycode-loading > * {
visibility: hidden;
}
Expand Down Expand Up @@ -112,36 +104,6 @@ img {
background: white;
}

#header {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 79px;

background: #f5f5f5;
background-image: url("../img/header-gradient.png");
background-position: 0 0;
-webkit-box-shadow: 0 5px 5px 0 rgba(233,233,233,0.5);
box-shadow: 0 5px 5px 0 rgba(233,233,233,0.5);
border-top: 2px solid white;

z-index: 2;
}

#header .logo {
display: inline-block;
font-family: OpenSansLight, sans-serif;
margin-left: 15px;
width: 200px;
margin-top: 10px;
}

#header .logo a {
color: #27AAE1;
text-decoration: none;
}

.nav-options {
font-family: "myriad-pro", Helvetica, Arial, sans-serif;
font-size: 12px;
Expand Down Expand Up @@ -259,9 +221,6 @@ img {
.hints-nav-item {
left: 180px !important;
}
#tabzilla {
right: 16% !important;
}
}

@media screen and (max-width: 420px) {
Expand Down
19 changes: 19 additions & 0 deletions css/friendlycode.css
@@ -0,0 +1,19 @@
/*
* This stylesheet is only intended for development purposes,
* due to the inefficiency of @import [1]. For production use, this
* file should be a raw concatenation of all the @import rules below.
*
* [1] http://www.stevesouders.com/blog/2009/04/09/dont-use-import/
*/

@import url(../codemirror2/lib/codemirror.css);

@import url(jsbin-codemirror-theme.css);
@import url(tipsy.css);
@import url(ubuntumono/stylesheet.css);
@import url(opensans/stylesheet.css);
@import url(opensymbolcropped/stylesheet.css);
@import url(editor.css);
@import url(errorhelp.css);
@import url(modals.css);

6 changes: 6 additions & 0 deletions css/tabzilla-overrides.css
Expand Up @@ -9,3 +9,9 @@
z-index: 9001;
right: 6em;
}

@media screen and (max-width: 620px) {
#tabzilla {
right: 16% !important;
}
}
37 changes: 37 additions & 0 deletions css/thimble.css
@@ -0,0 +1,37 @@
#thimble-friendlycode-holder {
position: absolute;
top: 79px;
bottom: 0;
left: 0;
right: 0;
}

#thimble-header {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 79px;

background: #f5f5f5;
background-image: url("../img/header-gradient.png");
background-position: 0 0;
-webkit-box-shadow: 0 5px 5px 0 rgba(233,233,233,0.5);
box-shadow: 0 5px 5px 0 rgba(233,233,233,0.5);
border-top: 2px solid white;

z-index: 2;
}

#thimble-header .logo {
display: inline-block;
font-family: OpenSansLight, sans-serif;
margin-left: 15px;
width: 200px;
margin-top: 10px;
}

#thimble-header .logo a {
color: #27AAE1;
text-decoration: none;
}
19 changes: 6 additions & 13 deletions index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="remix-url" content="">
<meta name="publish-url" content="https://webpagemaker-dev.allizom.org">
<meta name="publish-url" content="">
<meta name="deployment-type" content="development">
<base target="_blank">

Expand All @@ -13,36 +13,29 @@
<base href=".">

<title>Mozilla Thimble</title>
<link rel="stylesheet" href="codemirror2/lib/codemirror.css">
<link rel="stylesheet" href="css/jsbin-codemirror-theme.css">
<link rel="stylesheet" href="css/tipsy.css">
<link rel="stylesheet" href="css/ubuntumono/stylesheet.css">
<link rel="stylesheet" href="css/opensans/stylesheet.css">
<link rel="stylesheet" href="css/opensymbolcropped/stylesheet.css">
<link rel="stylesheet" href="css/editor.css">
<link rel="stylesheet" href="css/errorhelp.css">
<link rel="stylesheet" href="css/modals.css">
<link rel="stylesheet" href="css/friendlycode.css">
<link rel="stylesheet" href="css/thimble.css">
</head>
<body>
<a href="http://www.mozilla.org/" id="tabzilla">mozilla</a>

<header id="header">
<header id="thimble-header">
<div class="logo">
<a href="/">
<img src="img/thimble-logo.png" alt="Mozilla Thimble">
</a>
</div>
</header>

<div id="friendlycode-holder" class="friendlycode-loading"></div>
<div id="thimble-friendlycode-holder" class="friendlycode-loading"></div>

<script>
if (!location.search.match(/notypekit=1/))
document.write('<script src="//use.typekit.com/qjh6hdg.js"></' +
'script>');
</script>
<script src="js/require-config.js"></script>
<script data-main="js/main" src="js/require.min.js"></script>
<script data-main="js/thimble-main" src="js/require.min.js"></script>
<!-- use main-built for production -->
<!-- <script data-main="js/main-built" src="js/require.min.js"></script> -->

Expand Down
140 changes: 140 additions & 0 deletions js/friendlycode.js
@@ -0,0 +1,140 @@
define(function(require) {
var $ = require("jquery"),
TwoPanedEditor = require("fc/ui/two-paned-editor"),
EditorToolbar = require("fc/ui/editor-toolbar"),
Modals = require("fc/ui/modals"),
Parachute = require("fc/parachute"),
Publisher = require("fc/publisher"),
PublishUI = require("fc/ui/publish");

return function FriendlycodeEditor(options) {
var publishURL = options.publishURL,
pageToLoad = options.pageToLoad,
defaultContent = options.defaultContent || "default-content.html",
remixURLTemplate = options.remixURLTemplate ||
location.protocol + "//" + location.host +
location.pathname + "#{{VIEW_URL}}",
container = options.container.empty()
.addClass("friendlycode-loading"),
toolbarDiv = $('<div class="friendlycode-toolbar"></div>')
.appendTo(container),
editorDiv = $('<div class="friendlycode-editor"></div>')
.appendTo(container),
supportsPushState = window.history.pushState ? true : false,
ready = $.Deferred();

if (supportsPushState)
window.history.replaceState({pageToLoad: pageToLoad}, "",
location.href);

var editor = TwoPanedEditor({
container: editorDiv
});
var modals = Modals({
container: $('<div></div>').appendTo(document.body)
});
var publisher = Publisher(publishURL);
var publishUI = PublishUI({
modals: modals,
codeMirror: editor.codeMirror,
publisher: publisher,
remixURLTemplate: remixURLTemplate
});
var toolbar = EditorToolbar({
container: toolbarDiv,
editor: editor,
startPublish: publishUI.start
});
var parachute = Parachute(window, editor.codeMirror, pageToLoad);

// If a URL hash is specified, it should override anything provided by
// a server.
if (window.location.hash.slice(1))
pageToLoad = window.location.hash.slice(1);

window.addEventListener("hashchange", function(event) {
// We don't currently support dynamically changing the URL
// without a full page reload, unfortunately, so just trigger a
// reload if the user clicked the 'back' button after we pushed
// a new URL to it.
var newPageToLoad = window.location.hash.slice(1);
if (newPageToLoad != pageToLoad)
window.location.reload();
}, false);

if (supportsPushState)
window.addEventListener("popstate", function(event) {
// We don't currently support dynamically changing the URL
// without a full page reload, unfortunately, so just trigger a
// reload if the user clicked the 'back' button after we pushed
// a new URL to it.
//
// Also, for some reason Webkit is sending a spurious popstate with
// state == null on page load, so we want to check that it's
// non-null first (see #39).
if (event.state && event.state.pageToLoad != pageToLoad)
window.location.reload();
}, false);

publishUI.on("publish", function(info) {
// If the browser supports history.pushState, set the URL to
// be the new URL to remix the page they just published, so they
// can share/bookmark the URL and it'll be what they expect it
// to be.
pageToLoad = info.path;
// If the user clicks their back button, we don't want to show
// them the page they just published--we want to show them the
// page the current page is based on.
parachute.clearCurrentPage();
parachute.changePage(pageToLoad);
// It's possible that the server sanitized some stuff that the
// user will be confused by, so save the new state of the page
// to be what they expect it to be, just in case.
parachute.save();
if (supportsPushState)
window.history.pushState({pageToLoad: pageToLoad}, "", info.remixURL);
else
window.location.hash = "#" + pageToLoad;
});

function doneLoading() {
container.removeClass("friendlycode-loading");
editor.codeMirror.clearHistory();
toolbar.refresh();
if (parachute.restore()) {
toolbar.showDataRestoreHelp();
} else {
// Only save data on page unload if it's different from
// the URL we just (hopefully) loaded.
parachute.refresh();
}
editor.codeMirror.reparse();
editor.codeMirror.focus();
ready.resolve();
}

if (!pageToLoad) {
$.get(defaultContent, function(html) {
editor.codeMirror.setValue(html.trim());
doneLoading();
}, "text");
} else
publisher.loadCode(pageToLoad, function(err, data, url) {
if (err) {
modals.showErrorDialog({
text: 'Sorry, an error occurred while trying to get the page.'
});
} else {
editor.codeMirror.setValue(data);
publishUI.setCurrentURL(url);
doneLoading();
}
});

return {
codeMirror: editor.codeMirror,
parachute: parachute,
ready: ready
};
};
});

0 comments on commit a84ed3b

Please sign in to comment.