Permalink
Browse files

Added examples/alternate-publisher.html.

This example uses the Hackasaurus publishing endpoint for publishing
unsanitized pages (i.e., JS is allowed).
  • Loading branch information...
1 parent b259606 commit 1f4e165a7d94a0bea685b74d3d71c03f7421a13f @toolness toolness committed Oct 9, 2012
Showing with 89 additions and 0 deletions.
  1. +89 −0 examples/alternate-publisher.html
@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<html class="deployment-type-development">
+ <head>
+ <meta charset="utf-8">
+ <base target="_blank">
+
+ <title>Alternate Publisher Friendlycode Editor</title>
+ <link rel="stylesheet" href="../css/friendlycode.css">
+ </head>
+ <body style="margin: 0">
+ <div id="bare-fc-holder" class="friendlycode-loading"></div>
+
+ <script src="../js/require-config.js"></script>
+ <script src="../js/require.min.js"></script>
+ <script>
+ // Alternate publisher implementation that publishes to a hackpub
+ // endpoint. For more information, see:
+ //
+ // https://github.com/hackasaurus/hackpub
+ //
+ // Note also that the Amazon S3 bucket hackpub publishes to must
+ // be configured with a CORS configuration that allows for cross-origin
+ // GET requests, e.g.:
+ //
+ // <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
+ // <CORSRule>
+ // <AllowedOrigin>*</AllowedOrigin>
+ // <AllowedMethod>GET</AllowedMethod>
+ // </CORSRule>
+ // </CORSConfiguration>
+
+ define("hackpub", ["jquery"], function($) {
+ return function Hackpub(options) {
+ return {
+ loadCode: function(path, cb) {
+ var url = options.publishURL + path;
+ $.ajax({
+ type: "GET",
+ url: url,
+ dataType: 'text',
+ error: function(req) {
+ cb(req);
+ },
+ success: function(html) {
+ cb(null, html, url);
+ }
+ });
+ },
+ saveCode: function(data, originalURL, cb) {
+ $.ajax({
+ type: "POST",
+ url: options.hackpubURL + "/publish",
+ data: {
+ 'html': data,
+ 'original-url': originalURL
+ },
+ dataType: 'json',
+ error: function(req) {
+ cb(req);
+ },
+ success: function(result) {
+ var url = result['published-url'];
+ var path = '/' + url.match(/\/([A-Za-z0-9]+)$/)[1];
+ cb(null, {path: path, url: options.publishURL + path});
+ }
+ });
+ }
+ };
+ };
+ });
+ </script>
+ <script>
+ require([
+ "jquery",
+ "friendlycode",
+ "hackpub"
+ ], function($, FriendlycodeEditor, Hackpub) {
+ return FriendlycodeEditor({
+ allowJS: true,
+ publisher: Hackpub({
+ hackpubURL: "http://hackpub.hackasaurus.org",
+ publishURL: "http://poof.hksr.us"
+ }),
+ container: $("#bare-fc-holder")
+ });
+ });
+ </script>
+ </body>
+</html>

0 comments on commit 1f4e165

Please sign in to comment.