Merge remote-tracking branch 'upstream/master' into toc
This commit is contained in:
@@ -15,6 +15,7 @@ require File.expand_path('../gollum/blob_entry', __FILE__)
|
||||
require File.expand_path('../gollum/wiki', __FILE__)
|
||||
require File.expand_path('../gollum/page', __FILE__)
|
||||
require File.expand_path('../gollum/file', __FILE__)
|
||||
require File.expand_path('../gollum/file_view', __FILE__)
|
||||
require File.expand_path('../gollum/markup', __FILE__)
|
||||
require File.expand_path('../gollum/sanitization', __FILE__)
|
||||
require File.expand_path('../gollum/tex', __FILE__)
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
module Gollum
|
||||
=begin
|
||||
FileView requires that:
|
||||
- All files in root dir are processed first
|
||||
- Then all the folders are sorted and processed
|
||||
=end
|
||||
class FileView
|
||||
def initialize pages
|
||||
@pages = pages
|
||||
end
|
||||
|
||||
def enclose_tree string
|
||||
%Q(<ol class="tree">\n) + string + %Q(\n</ol>)
|
||||
end
|
||||
|
||||
def new_page page
|
||||
name = page.name
|
||||
%Q( <li class="file"><a href="#{name}">#{name}</a></li>\n)
|
||||
end
|
||||
|
||||
def new_folder page
|
||||
new_sub_folder ::File.dirname(page.path), page.name
|
||||
end
|
||||
|
||||
def new_sub_folder path, name
|
||||
<<-HTML
|
||||
<li>
|
||||
<label>#{path}</label> <input type="checkbox" checked />
|
||||
<ol>
|
||||
<li class="file"><a href="#{name}">#{name}</a></li>
|
||||
HTML
|
||||
end
|
||||
|
||||
def end_folder
|
||||
<<-HTML
|
||||
</ol>
|
||||
</li>
|
||||
HTML
|
||||
end
|
||||
|
||||
def render_files
|
||||
html = ''
|
||||
count = @pages.size
|
||||
folder_start = -1
|
||||
|
||||
# Process all pages until folders start
|
||||
count.times do | index |
|
||||
page = @pages[ index ]
|
||||
path = page.path
|
||||
|
||||
unless path.include? '/'
|
||||
# Page processed (not contained in a folder)
|
||||
html += new_page page
|
||||
else
|
||||
# Folders start at the next index
|
||||
folder_start = index
|
||||
break # Pages finished, move on to folders
|
||||
end
|
||||
end
|
||||
|
||||
# If there are no folders, then we're done.
|
||||
return enclose_tree(html) if folder_start <= -1
|
||||
|
||||
# Handle special case of only one folder.
|
||||
if (count - folder_start == 1)
|
||||
path = @pages[ folder_start ]
|
||||
name = page.name
|
||||
html += <<-HTML
|
||||
<li>
|
||||
<label>#{::File.dirname(path)}</label> <input type="checkbox" checked />
|
||||
<ol>
|
||||
<li class="file"><a href="#{name}">#{name}</a></li>
|
||||
</ol>
|
||||
</li>
|
||||
HTML
|
||||
|
||||
return enclose_tree html
|
||||
end
|
||||
|
||||
sorted_folders = []
|
||||
(folder_start).upto count - 1 do | index |
|
||||
sorted_folders += [[ @pages[ index ].path, index ]]
|
||||
end
|
||||
|
||||
# http://stackoverflow.com/questions/3482814/sorting-list-of-string-paths-in-vb-net
|
||||
sorted_folders.sort! do |first,second|
|
||||
a = first[0]
|
||||
b = second[0]
|
||||
|
||||
# use :: operator because gollum defines its own conflicting File class
|
||||
dir_compare = ::File.dirname(a) <=> ::File.dirname(b)
|
||||
|
||||
# Sort based on directory name unless they're equal (0) in
|
||||
# which case sort based on file name.
|
||||
if dir_compare == 0
|
||||
::File.basename(a) <=> ::File.basename(b)
|
||||
else
|
||||
dir_compare
|
||||
end
|
||||
end
|
||||
|
||||
# Process first folder
|
||||
page = @pages[ sorted_folders[ 0 ][1] ]
|
||||
html += new_folder page
|
||||
|
||||
last_folder = ::File.dirname page.path # define last_folder
|
||||
|
||||
# keep track of folder depth, 0 = at root.
|
||||
depth = 0
|
||||
|
||||
# process rest of folders
|
||||
1.upto(sorted_folders.size - 1) do | index |
|
||||
page = @pages[ sorted_folders[ index ][1] ]
|
||||
path = page.path
|
||||
folder = ::File.dirname path
|
||||
|
||||
if last_folder == folder
|
||||
# same folder
|
||||
html += new_page page
|
||||
elsif folder.include?('/')
|
||||
# check if we're going up or down a depth level
|
||||
if last_folder.scan('/').size > folder.scan('/').size
|
||||
# end tag for 1 subfolder & 1 parent folder
|
||||
# so emit 2 end tags
|
||||
2.times { html += end_folder; }
|
||||
depth -= 1
|
||||
else
|
||||
depth += 1
|
||||
end
|
||||
|
||||
# subfolder
|
||||
html += new_sub_folder ::File.dirname(page.path).split('/').last, page.name
|
||||
else
|
||||
# depth+1 because we need an additional end_folder
|
||||
(depth+1).times { html += end_folder; }
|
||||
depth = 0
|
||||
# New root folder
|
||||
html += new_folder page
|
||||
end
|
||||
|
||||
last_folder = folder
|
||||
end
|
||||
|
||||
# Process last folder's ending tags.
|
||||
(depth+1).times {
|
||||
depth.times { html += end_folder; }
|
||||
depth = 0
|
||||
}
|
||||
|
||||
# return the completed html
|
||||
enclose_tree html
|
||||
end # end render_files
|
||||
end # end FileView class
|
||||
end # end Gollum module
|
||||
@@ -212,6 +212,17 @@ module Precious
|
||||
mustache :pages
|
||||
end
|
||||
|
||||
get '/fileview' do
|
||||
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
||||
@results = Gollum::FileView.new(wiki.pages).render_files
|
||||
File.open('/tmp/log.txt', 'w') {|f|
|
||||
f.puts "log!"
|
||||
f.puts @results
|
||||
}
|
||||
@ref = wiki.ref
|
||||
mustache :file_view
|
||||
end
|
||||
|
||||
get '/*' do
|
||||
show_page_or_file(params[:splat].first)
|
||||
end
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/* Just some base styles not needed for example to function */
|
||||
*, html { font-family: Verdana, Arial, Helvetica, sans-serif; }
|
||||
|
||||
|
||||
#results a:hover {
|
||||
background-color: #4c4c4c;
|
||||
}
|
||||
|
||||
#home_button {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 50%;
|
||||
}
|
||||
|
||||
#home_button .minibutton {
|
||||
/* controls size of home btn */
|
||||
font-size: 1em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#results {
|
||||
position: absolute;
|
||||
top: 60px;
|
||||
left: 10px;
|
||||
}
|
||||
|
||||
|
||||
body, form, ul, li, p, h1, h2, h3, h4, h5
|
||||
{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
body { background-color: #606061; color: #ffffff; margin: 0; }
|
||||
img { border: none; }
|
||||
p
|
||||
{
|
||||
font-size: 1em;
|
||||
margin: 0 0 1em 0;
|
||||
}
|
||||
|
||||
html { font-size: 100%; /* IE hack */ }
|
||||
body { font-size: 1em; /* Sets base font size to 16px */ }
|
||||
table { font-size: 100%; /* IE hack */ }
|
||||
input, select, textarea, th, td { font-size: 1em; }
|
||||
|
||||
/* CSS Tree menu styles */
|
||||
ol.tree
|
||||
{
|
||||
padding: 0 0 0 30px;
|
||||
width: 300px;
|
||||
}
|
||||
li
|
||||
{
|
||||
position: relative;
|
||||
margin-left: -15px;
|
||||
list-style: none;
|
||||
}
|
||||
li.file
|
||||
{
|
||||
margin-left: -1px !important;
|
||||
height: 1.5em;
|
||||
}
|
||||
li.file a
|
||||
{
|
||||
background: url(/images/fileview/document.png) 0 0 no-repeat;
|
||||
color: #fff;
|
||||
padding-left: 21px;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
li.file a[href *= '.pdf'] { background: url(/images/fileview/document.png) 0 0 no-repeat; }
|
||||
li.file a[href *= '.html'] { background: url(/images/fileview/document.png) 0 0 no-repeat; }
|
||||
li.file a[href $= '.css'] { background: url(/images/fileview/document.png) 0 0 no-repeat; }
|
||||
li.file a[href $= '.js'] { background: url(/images/fileview/document.png) 0 0 no-repeat; }
|
||||
li input
|
||||
{
|
||||
position: absolute;
|
||||
left: 0;
|
||||
margin-left: 0;
|
||||
opacity: 0;
|
||||
z-index: 2;
|
||||
cursor: pointer;
|
||||
height: 1em;
|
||||
width: 1em;
|
||||
top: 0;
|
||||
}
|
||||
li input + ol
|
||||
{
|
||||
background: url(/images/fileview/toggle-small-expand.png) 40px 0 no-repeat;
|
||||
margin: -1.188em 0 0 -44px; /* 15px */
|
||||
height: 1.5em;
|
||||
}
|
||||
li input + ol > li { display: none; margin-left: -14px !important; padding-left: 1px; }
|
||||
li label
|
||||
{
|
||||
background: url(/images/fileview/folder-horizontal.png) 15px 1px no-repeat;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
padding-left: 37px;
|
||||
}
|
||||
|
||||
li input:checked + ol
|
||||
{
|
||||
background: url(/images/fileview/toggle-small.png) 40px 5px no-repeat;
|
||||
margin: -1.5em 0 0 -44px; /* 20px */
|
||||
padding: 1.563em 0 0 80px;
|
||||
height: auto;
|
||||
}
|
||||
li input:checked + ol > li { display: block; margin: 0 0 0.125em; /* 2px */}
|
||||
li input:checked + ol > li:last-child { margin: 0 0 0.063em; /* 1px */ }
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 177 B |
Binary file not shown.
|
After Width: | Height: | Size: 271 B |
Binary file not shown.
|
After Width: | Height: | Size: 433 B |
Binary file not shown.
|
After Width: | Height: | Size: 462 B |
@@ -168,6 +168,11 @@
|
||||
},
|
||||
|
||||
setActiveLanguage: function( name ) {
|
||||
// On first load _ACTIVE_LANG.length is 0 and evtChangeFormat isn't called.
|
||||
if ( LanguageDefinition._ACTIVE_LANG.length <= 0 ) {
|
||||
FormatSelector.updateCommitMessage( name );
|
||||
}
|
||||
|
||||
if(LanguageDefinition.getHookFunctionFor("deactivate")) {
|
||||
LanguageDefinition.getHookFunctionFor("deactivate")();
|
||||
}
|
||||
@@ -747,9 +752,18 @@
|
||||
*/
|
||||
evtChangeFormat: function( e ) {
|
||||
var newMarkup = $(this).val();
|
||||
FormatSelector.updateCommitMessage( newMarkup );
|
||||
LanguageDefinition.setActiveLanguage( newMarkup );
|
||||
},
|
||||
|
||||
updateCommitMessage: function( newMarkup ) {
|
||||
var msg = document.getElementById( "gollum-editor-message-field" );
|
||||
var val = msg.value;
|
||||
// Must start with created or updated.
|
||||
if (/^(?:created|updated)/i.test(val)) {
|
||||
msg.value = val.replace( /\([^\)]*\)$/, "(" + newMarkup + ")" );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* FormatSelector.init
|
||||
|
||||
@@ -2,7 +2,22 @@ body {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#editor {
|
||||
#darkness {
|
||||
visibility: hidden;
|
||||
position: absolute;
|
||||
left: 0px;
|
||||
top: 0px;
|
||||
background-color: black;
|
||||
opacity: 0.8;
|
||||
z-index: 1001; /* must be > 1000 to overlay ace gutter */
|
||||
}
|
||||
|
||||
#commenttoolpanel {
|
||||
visibility: hidden;
|
||||
z-index: 1002; /* > 1001 to not be hidden by darkness */
|
||||
}
|
||||
|
||||
#comment, #editor {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
position: absolute;
|
||||
@@ -10,6 +25,16 @@ body {
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
/* Set font size of both ace editors. */
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
/* Set comment to have a higher z-index
|
||||
so editor doesn't display in the background. */
|
||||
|
||||
#comment {
|
||||
visibility: hidden;
|
||||
z-index: 1003; /* > 1002 to not be hidden by toolpanel */
|
||||
}
|
||||
|
||||
#contentframe {
|
||||
@@ -30,7 +55,7 @@ body {
|
||||
}
|
||||
|
||||
/* -- Start from notepag.es -- */
|
||||
#toolpanel {
|
||||
.toolpanel {
|
||||
position: fixed;
|
||||
background: #666;
|
||||
top: 0;
|
||||
@@ -43,7 +68,7 @@ body {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#toolpanel.edit a.edit {
|
||||
.toolpanel.edit a.edit {
|
||||
opacity: 0.4;
|
||||
/* Make it appear as a link even though save
|
||||
doesn't have a href attribute. */
|
||||
@@ -51,7 +76,7 @@ body {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#toolpanel a {
|
||||
.toolpanel a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
margin: 0 5px;
|
||||
@@ -60,7 +85,7 @@ body {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
#toolpanel a img {
|
||||
.toolpanel a img {
|
||||
vertical-align: middle;
|
||||
margin-left: 5px;
|
||||
margin: 0;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 525 B |
Binary file not shown.
|
After Width: | Height: | Size: 278 B |
@@ -1,10 +1,28 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>JavaScript Markdown Editor</title>
|
||||
|
||||
<title>Live Preview</title>
|
||||
<link rel="stylesheet" type="text/css" href="../css/template.css" />
|
||||
<link rel="stylesheet" type="text/css" href="css/highlightjs/github.css" />
|
||||
<link rel="stylesheet" type="text/css" href="css/custom.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="editor"></div>
|
||||
|
||||
<div id="previewframe"><div id="contentframe" class="markdown-body"></div></div>
|
||||
<!-- tool panel from notepage.es. save & savecomment icons from Retina Display Icon Set. -->
|
||||
<div id="toolpanel" class="toolpanel edit" style="width: 500px; right: 0px; ">
|
||||
<a id="save" class="edit"><img src="images/save_24.png" alt="Save" title="Save"></a>
|
||||
<a id="savecomment" class="edit"><img src="images/savecomment_24.png" alt="Save with comment" title="Save with comment"></a>
|
||||
<a id="toggle" class="edit" href="javascript:void(0)" onclick="jsm.toggleLeftRight();"><img src="images/lr_24.png" alt="Toggle left to right" title="Toggle left to right"></a>
|
||||
</div>
|
||||
|
||||
<div id="commenttoolpanel" class="toolpanel edit" style="width: 500px; right: 0px; ">
|
||||
<a id="savecommentconfirm" class="edit"><img src="images/savecomment_24.png" alt="Confirm save with comment" title="Confirm save with comment"></a>
|
||||
<a id="commentcancel" class="edit"><img src="images/cancel_24.png" alt="Cancel save with comment" title="Cancel save with comment"></a>
|
||||
</div>
|
||||
<div id="comment"></div>
|
||||
<div id="darkness"></div>
|
||||
|
||||
<script src="js/ace/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="js/ace/theme-twilight.js" type="text/javascript" charset="utf-8"></script>
|
||||
@@ -13,249 +31,7 @@
|
||||
<script src="js/pagedown/Markdown.Sanitizer.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="js/jquery/jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="js/highlightjs/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="editor"></div>
|
||||
|
||||
<div id="previewframe"><div id="contentframe" class="markdown-body"></div></div>
|
||||
<!-- tool panel and save from notepage.es -->
|
||||
<div id="toolpanel" class="edit" style="width: 500px; right: 0px; ">
|
||||
<a id="save" class="edit"><img src="images/save_24.png" alt="save" title="save"></a>
|
||||
<a id="toggle" class="edit" href="javascript:void(0)" onclick="jsm.toggleLeftRight();"><img src="images/lr_24.png" alt="Toggle left to right" title="Toggle left to right"></a>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function () {
|
||||
var converter = Markdown.getSanitizingConverter();
|
||||
var editor = ace.edit("editor");
|
||||
var editorSession = editor.getSession();
|
||||
var preview = document.getElementById("previewframe");
|
||||
var content = document.getElementById("contentframe");
|
||||
var toolPanel = document.getElementById("toolpanel");
|
||||
|
||||
var leftRight = true;
|
||||
var jsm = {}; // JavaScript Markdown
|
||||
window.jsm = jsm;
|
||||
window.jsm.toggleLeftRight = function() {
|
||||
leftRight = leftRight === false ? true : false;
|
||||
jsm.resize();
|
||||
}
|
||||
|
||||
editor.setTheme("ace/theme/twilight");
|
||||
var MarkdownMode = require("ace/mode/markdown").Mode;
|
||||
|
||||
editorSession.setMode(new MarkdownMode());
|
||||
// Gutter shows line numbers
|
||||
editor.renderer.setShowGutter(true);
|
||||
editor.renderer.setHScrollBarAlwaysVisible(false);
|
||||
editorSession.setUseSoftTabs(true);
|
||||
editorSession.setTabSize(2);
|
||||
editorSession.setUseWrapMode(true);
|
||||
editor.setShowPrintMargin(false);
|
||||
editor.setBehavioursEnabled(true);
|
||||
|
||||
window.onload = function() {
|
||||
// RegExp from http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
|
||||
$.key = function(key){
|
||||
var value = new RegExp('[\\?&]' + key + '=([^&#]*)').exec(window.location.href);
|
||||
return (!value) ? 0 : value[1] || 0;
|
||||
}
|
||||
|
||||
/* Load markdown from /data/page into the ace editor. */
|
||||
jQuery.ajax({
|
||||
type: "GET",
|
||||
url: "/data/" + $.key("page"),
|
||||
success: function(data) {
|
||||
editorSession.setValue(data);
|
||||
}
|
||||
});
|
||||
|
||||
$.save = function() {
|
||||
// if &create=true then handle create instead of edit.
|
||||
var create = $.key("create");
|
||||
|
||||
if (create) {
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: "/create",
|
||||
data: { page: $.key("page"), format: "markdown", content: editorSession.getValue() },
|
||||
success: function() {
|
||||
window.location = window.location.origin + "/" + $.key("page");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: "/edit/" + $.key("page"),
|
||||
data: { format: "markdown", content: editorSession.getValue() },
|
||||
success: function() {
|
||||
window.location = window.location.origin + "/" + $.key("page");
|
||||
}
|
||||
});
|
||||
} // end else
|
||||
}
|
||||
|
||||
$('#save').click(function() {
|
||||
$.save();
|
||||
});
|
||||
|
||||
// onChange calls applyTimeout which rate limits the calling of makePreviewHtml based on render time.
|
||||
editor.on('change', applyTimeout);
|
||||
makePreviewHtml(); // preview default text on load
|
||||
|
||||
function resize() {
|
||||
var ace = editor.container;//document.getElementById("editor");
|
||||
var widthHalf = $(window).width() / 2;
|
||||
var height = $(window).height();
|
||||
ace.style.width = widthHalf + "px";
|
||||
// Minus 50 so the end of document text doesn't flow off the page.
|
||||
ace.style.height = height - 50 + "px";
|
||||
ace.style.left = leftRight === false ? widthHalf + "px" : "0px";
|
||||
ace.style.top = "40px"; // use 40px for tool menu
|
||||
ace.style.fontSize = 16 + "px";
|
||||
editor.resize();
|
||||
|
||||
var previewFrame = document.getElementById("previewframe");
|
||||
previewFrame.style.width = widthHalf - 2 - 10 + "px"; // -2 for scroll bar & -10 for left offset
|
||||
previewFrame.style.height = height + "px";
|
||||
previewFrame.style.left = leftRight === false ? "10px" : widthHalf + "px";
|
||||
previewFrame.style.top = "0px";
|
||||
|
||||
// Resize tool panel
|
||||
toolPanel.style.width = widthHalf + "px";
|
||||
toolPanel.style.left = leftRight === false ? widthHalf + "px" : "0px";
|
||||
}
|
||||
|
||||
window.jsm.resize = resize;
|
||||
|
||||
$(window).resize(function() {
|
||||
resize();
|
||||
});
|
||||
|
||||
// resize for the intial page load
|
||||
resize();
|
||||
};
|
||||
|
||||
var elapsedTime;
|
||||
var oldInputText = "";
|
||||
|
||||
// ---- from Markdown.Editor
|
||||
var previewSetter;
|
||||
var timeout;
|
||||
|
||||
var nonSuckyBrowserPreviewSet = function (text) {
|
||||
content.innerHTML = text;
|
||||
}
|
||||
|
||||
// IE doesn't let you use innerHTML if the element is contained somewhere in a table
|
||||
// (which is the case for inline editing) -- in that case, detach the element, set the
|
||||
// value, and reattach. Yes, that *is* ridiculous.
|
||||
var ieSafePreviewSet = function (text) {
|
||||
var parent = content.parentNode;
|
||||
var sibling = content.nextSibling;
|
||||
parent.removeChild(content);
|
||||
content.innerHTML = text;
|
||||
if (!sibling)
|
||||
parent.appendChild(content);
|
||||
else
|
||||
parent.insertBefore(content, sibling);
|
||||
}
|
||||
|
||||
var previewSet = function (text) {
|
||||
if (previewSetter)
|
||||
return previewSetter(text);
|
||||
|
||||
try {
|
||||
nonSuckyBrowserPreviewSet(text);
|
||||
previewSetter = nonSuckyBrowserPreviewSet;
|
||||
} catch (e) {
|
||||
previewSetter = ieSafePreviewSet;
|
||||
previewSetter(text);
|
||||
}
|
||||
};
|
||||
|
||||
var languages = [ "1c", "actionscript", "apache", "avrasm", "axapta",
|
||||
"bash", "cmake", "coffeescript", "cpp", "cs", "css", "delphi", "diff",
|
||||
"django", "d", "dos", "erlang", "erlang-repl", "go", "haskell", "ini",
|
||||
"java", "javascript", "languages", "lisp", "lua", "markdown", "matlab",
|
||||
"mel", "nginx", "objectivec", "parser3", "perl", "php", "profile",
|
||||
"python", "renderman", "ruby", "rust", "scala", "smalltalk", "sql",
|
||||
"tex", "vala", "vbscript", "vhdl", "xml" ];
|
||||
|
||||
var makePreviewHtml = function () {
|
||||
var text = editorSession.getValue();
|
||||
|
||||
if (text && text == oldInputText) {
|
||||
return; // Input text hasn't changed.
|
||||
}
|
||||
else {
|
||||
oldInputText = text;
|
||||
}
|
||||
|
||||
var prevTime = new Date().getTime();
|
||||
|
||||
text = converter.makeHtml(text);
|
||||
|
||||
// Calculate the processing time of the HTML creation.
|
||||
// It's used as the delay time in the event listener.
|
||||
var currTime = new Date().getTime();
|
||||
elapsedTime = currTime - prevTime;
|
||||
|
||||
// Update the text using feature detection to support IE.
|
||||
// preview.innerHTML = text; // this doesn't work on IE.
|
||||
previewSet(text);
|
||||
|
||||
// highlight code blocks.
|
||||
var codeElements = preview.getElementsByTagName("pre");
|
||||
var codeElementsLength = codeElements.length;
|
||||
|
||||
if (codeElementsLength > 0) {
|
||||
for (var idx = 0; idx < codeElementsLength; idx++) {
|
||||
var element = codeElements[idx];
|
||||
var codeHTML = element.innerHTML;
|
||||
|
||||
// Only use pre tags marked containing code.
|
||||
if (codeHTML[0] !== "`")
|
||||
continue;
|
||||
|
||||
var txt = codeHTML.split(/\b/);
|
||||
// the syntax for code highlighting means all code, even one line, contains newlines.
|
||||
if (txt.length > 1 && codeHTML.match(/\n/)) {
|
||||
// txt[0] = "`"; txt[1] = "ruby"
|
||||
if ($.inArray(txt[1], languages) === -1) {
|
||||
element.innerHTML = codeHTML.substring(1).trim();
|
||||
element.className = "nohighlight";
|
||||
continue;
|
||||
}
|
||||
|
||||
element.className = txt[1] + " highlight";
|
||||
// length + 1 for the marker character.
|
||||
element.innerHTML = codeHTML.substring(txt[1].length+1).trim();
|
||||
hljs.highlightBlock(element, " ");
|
||||
} else {
|
||||
element.innerHTML = codeHTML.substring(1).trim();
|
||||
element.className = "nohighlight";
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// setTimeout is already used. Used as an event listener.
|
||||
var applyTimeout = function () {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = undefined;
|
||||
}
|
||||
|
||||
// 3 second max delay
|
||||
if (elapsedTime > 3000) {
|
||||
elapsedTime = 3000;
|
||||
}
|
||||
|
||||
timeout = setTimeout(makePreviewHtml, elapsedTime);
|
||||
};
|
||||
})();
|
||||
</script>
|
||||
<script src="js/debounce/jquery.ba-throttle-debounce.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="js/livepreview/livepreview.js" type="text/javascript" charset="utf-8"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
/*!
|
||||
* jQuery throttle / debounce - v1.1 - 3/7/2010
|
||||
* http://benalman.com/projects/jquery-throttle-debounce-plugin/
|
||||
*
|
||||
* Copyright (c) 2010 "Cowboy" Ben Alman
|
||||
* Dual licensed under the MIT and GPL licenses.
|
||||
* http://benalman.com/about/license/
|
||||
*/
|
||||
|
||||
// Script: jQuery throttle / debounce: Sometimes, less is more!
|
||||
//
|
||||
// *Version: 1.1, Last updated: 3/7/2010*
|
||||
//
|
||||
// Project Home - http://benalman.com/projects/jquery-throttle-debounce-plugin/
|
||||
// GitHub - http://github.com/cowboy/jquery-throttle-debounce/
|
||||
// Source - http://github.com/cowboy/jquery-throttle-debounce/raw/master/jquery.ba-throttle-debounce.js
|
||||
// (Minified) - http://github.com/cowboy/jquery-throttle-debounce/raw/master/jquery.ba-throttle-debounce.min.js (0.7kb)
|
||||
//
|
||||
// About: License
|
||||
//
|
||||
// Copyright (c) 2010 "Cowboy" Ben Alman,
|
||||
// Dual licensed under the MIT and GPL licenses.
|
||||
// http://benalman.com/about/license/
|
||||
//
|
||||
// About: Examples
|
||||
//
|
||||
// These working examples, complete with fully commented code, illustrate a few
|
||||
// ways in which this plugin can be used.
|
||||
//
|
||||
// Throttle - http://benalman.com/code/projects/jquery-throttle-debounce/examples/throttle/
|
||||
// Debounce - http://benalman.com/code/projects/jquery-throttle-debounce/examples/debounce/
|
||||
//
|
||||
// About: Support and Testing
|
||||
//
|
||||
// Information about what version or versions of jQuery this plugin has been
|
||||
// tested with, what browsers it has been tested in, and where the unit tests
|
||||
// reside (so you can test it yourself).
|
||||
//
|
||||
// jQuery Versions - none, 1.3.2, 1.4.2
|
||||
// Browsers Tested - Internet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome 4-5, Opera 9.6-10.1.
|
||||
// Unit Tests - http://benalman.com/code/projects/jquery-throttle-debounce/unit/
|
||||
//
|
||||
// About: Release History
|
||||
//
|
||||
// 1.1 - (3/7/2010) Fixed a bug in <jQuery.throttle> where trailing callbacks
|
||||
// executed later than they should. Reworked a fair amount of internal
|
||||
// logic as well.
|
||||
// 1.0 - (3/6/2010) Initial release as a stand-alone project. Migrated over
|
||||
// from jquery-misc repo v0.4 to jquery-throttle repo v1.0, added the
|
||||
// no_trailing throttle parameter and debounce functionality.
|
||||
//
|
||||
// Topic: Note for non-jQuery users
|
||||
//
|
||||
// jQuery isn't actually required for this plugin, because nothing internal
|
||||
// uses any jQuery methods or properties. jQuery is just used as a namespace
|
||||
// under which these methods can exist.
|
||||
//
|
||||
// Since jQuery isn't actually required for this plugin, if jQuery doesn't exist
|
||||
// when this plugin is loaded, the method described below will be created in
|
||||
// the `Cowboy` namespace. Usage will be exactly the same, but instead of
|
||||
// $.method() or jQuery.method(), you'll need to use Cowboy.method().
|
||||
|
||||
(function(window,undefined){
|
||||
'$:nomunge'; // Used by YUI compressor.
|
||||
|
||||
// Since jQuery really isn't required for this plugin, use `jQuery` as the
|
||||
// namespace only if it already exists, otherwise use the `Cowboy` namespace,
|
||||
// creating it if necessary.
|
||||
var $ = window.jQuery || window.Cowboy || ( window.Cowboy = {} ),
|
||||
|
||||
// Internal method reference.
|
||||
jq_throttle;
|
||||
|
||||
// Method: jQuery.throttle
|
||||
//
|
||||
// Throttle execution of a function. Especially useful for rate limiting
|
||||
// execution of handlers on events like resize and scroll. If you want to
|
||||
// rate-limit execution of a function to a single time, see the
|
||||
// <jQuery.debounce> method.
|
||||
//
|
||||
// In this visualization, | is a throttled-function call and X is the actual
|
||||
// callback execution:
|
||||
//
|
||||
// > Throttled with `no_trailing` specified as false or unspecified:
|
||||
// > ||||||||||||||||||||||||| (pause) |||||||||||||||||||||||||
|
||||
// > X X X X X X X X X X X X
|
||||
// >
|
||||
// > Throttled with `no_trailing` specified as true:
|
||||
// > ||||||||||||||||||||||||| (pause) |||||||||||||||||||||||||
|
||||
// > X X X X X X X X X X
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// > var throttled = jQuery.throttle( delay, [ no_trailing, ] callback );
|
||||
// >
|
||||
// > jQuery('selector').bind( 'someevent', throttled );
|
||||
// > jQuery('selector').unbind( 'someevent', throttled );
|
||||
//
|
||||
// This also works in jQuery 1.4+:
|
||||
//
|
||||
// > jQuery('selector').bind( 'someevent', jQuery.throttle( delay, [ no_trailing, ] callback ) );
|
||||
// > jQuery('selector').unbind( 'someevent', callback );
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// delay - (Number) A zero-or-greater delay in milliseconds. For event
|
||||
// callbacks, values around 100 or 250 (or even higher) are most useful.
|
||||
// no_trailing - (Boolean) Optional, defaults to false. If no_trailing is
|
||||
// true, callback will only execute every `delay` milliseconds while the
|
||||
// throttled-function is being called. If no_trailing is false or
|
||||
// unspecified, callback will be executed one final time after the last
|
||||
// throttled-function call. (After the throttled-function has not been
|
||||
// called for `delay` milliseconds, the internal counter is reset)
|
||||
// callback - (Function) A function to be executed after delay milliseconds.
|
||||
// The `this` context and all arguments are passed through, as-is, to
|
||||
// `callback` when the throttled-function is executed.
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// (Function) A new, throttled, function.
|
||||
|
||||
$.throttle = jq_throttle = function( delay, no_trailing, callback, debounce_mode ) {
|
||||
// After wrapper has stopped being called, this timeout ensures that
|
||||
// `callback` is executed at the proper times in `throttle` and `end`
|
||||
// debounce modes.
|
||||
var timeout_id,
|
||||
|
||||
// Keep track of the last time `callback` was executed.
|
||||
last_exec = 0;
|
||||
|
||||
// `no_trailing` defaults to falsy.
|
||||
if ( typeof no_trailing !== 'boolean' ) {
|
||||
debounce_mode = callback;
|
||||
callback = no_trailing;
|
||||
no_trailing = undefined;
|
||||
}
|
||||
|
||||
// The `wrapper` function encapsulates all of the throttling / debouncing
|
||||
// functionality and when executed will limit the rate at which `callback`
|
||||
// is executed.
|
||||
function wrapper() {
|
||||
var that = this,
|
||||
elapsed = +new Date() - last_exec,
|
||||
args = arguments;
|
||||
|
||||
// Execute `callback` and update the `last_exec` timestamp.
|
||||
function exec() {
|
||||
last_exec = +new Date();
|
||||
callback.apply( that, args );
|
||||
};
|
||||
|
||||
// If `debounce_mode` is true (at_begin) this is used to clear the flag
|
||||
// to allow future `callback` executions.
|
||||
function clear() {
|
||||
timeout_id = undefined;
|
||||
};
|
||||
|
||||
if ( debounce_mode && !timeout_id ) {
|
||||
// Since `wrapper` is being called for the first time and
|
||||
// `debounce_mode` is true (at_begin), execute `callback`.
|
||||
exec();
|
||||
}
|
||||
|
||||
// Clear any existing timeout.
|
||||
timeout_id && clearTimeout( timeout_id );
|
||||
|
||||
if ( debounce_mode === undefined && elapsed > delay ) {
|
||||
// In throttle mode, if `delay` time has been exceeded, execute
|
||||
// `callback`.
|
||||
exec();
|
||||
|
||||
} else if ( no_trailing !== true ) {
|
||||
// In trailing throttle mode, since `delay` time has not been
|
||||
// exceeded, schedule `callback` to execute `delay` ms after most
|
||||
// recent execution.
|
||||
//
|
||||
// If `debounce_mode` is true (at_begin), schedule `clear` to execute
|
||||
// after `delay` ms.
|
||||
//
|
||||
// If `debounce_mode` is false (at end), schedule `callback` to
|
||||
// execute after `delay` ms.
|
||||
timeout_id = setTimeout( debounce_mode ? clear : exec, debounce_mode === undefined ? delay - elapsed : delay );
|
||||
}
|
||||
};
|
||||
|
||||
// Set the guid of `wrapper` function to the same of original callback, so
|
||||
// it can be removed in jQuery 1.4+ .unbind or .die by using the original
|
||||
// callback as a reference.
|
||||
if ( $.guid ) {
|
||||
wrapper.guid = callback.guid = callback.guid || $.guid++;
|
||||
}
|
||||
|
||||
// Return the wrapper function.
|
||||
return wrapper;
|
||||
};
|
||||
|
||||
// Method: jQuery.debounce
|
||||
//
|
||||
// Debounce execution of a function. Debouncing, unlike throttling,
|
||||
// guarantees that a function is only executed a single time, either at the
|
||||
// very beginning of a series of calls, or at the very end. If you want to
|
||||
// simply rate-limit execution of a function, see the <jQuery.throttle>
|
||||
// method.
|
||||
//
|
||||
// In this visualization, | is a debounced-function call and X is the actual
|
||||
// callback execution:
|
||||
//
|
||||
// > Debounced with `at_begin` specified as false or unspecified:
|
||||
// > ||||||||||||||||||||||||| (pause) |||||||||||||||||||||||||
|
||||
// > X X
|
||||
// >
|
||||
// > Debounced with `at_begin` specified as true:
|
||||
// > ||||||||||||||||||||||||| (pause) |||||||||||||||||||||||||
|
||||
// > X X
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// > var debounced = jQuery.debounce( delay, [ at_begin, ] callback );
|
||||
// >
|
||||
// > jQuery('selector').bind( 'someevent', debounced );
|
||||
// > jQuery('selector').unbind( 'someevent', debounced );
|
||||
//
|
||||
// This also works in jQuery 1.4+:
|
||||
//
|
||||
// > jQuery('selector').bind( 'someevent', jQuery.debounce( delay, [ at_begin, ] callback ) );
|
||||
// > jQuery('selector').unbind( 'someevent', callback );
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// delay - (Number) A zero-or-greater delay in milliseconds. For event
|
||||
// callbacks, values around 100 or 250 (or even higher) are most useful.
|
||||
// at_begin - (Boolean) Optional, defaults to false. If at_begin is false or
|
||||
// unspecified, callback will only be executed `delay` milliseconds after
|
||||
// the last debounced-function call. If at_begin is true, callback will be
|
||||
// executed only at the first debounced-function call. (After the
|
||||
// throttled-function has not been called for `delay` milliseconds, the
|
||||
// internal counter is reset)
|
||||
// callback - (Function) A function to be executed after delay milliseconds.
|
||||
// The `this` context and all arguments are passed through, as-is, to
|
||||
// `callback` when the debounced-function is executed.
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// (Function) A new, debounced, function.
|
||||
|
||||
$.debounce = function( delay, at_begin, callback ) {
|
||||
return callback === undefined
|
||||
? jq_throttle( delay, at_begin, false )
|
||||
: jq_throttle( delay, callback, at_begin !== false );
|
||||
};
|
||||
|
||||
})(this);
|
||||
@@ -0,0 +1,361 @@
|
||||
(function () {
|
||||
window.onbeforeunload = function(){ return "Leaving Live Preview will discard all edits!" };
|
||||
|
||||
var converter = Markdown.getSanitizingConverter();
|
||||
var editor = ace.edit("editor");
|
||||
var editorSession = editor.getSession();
|
||||
var editorContainer = editor.container;
|
||||
var preview = document.getElementById("previewframe");
|
||||
var content = document.getElementById("contentframe");
|
||||
var toolPanel = document.getElementById("toolpanel");
|
||||
var comment = document.getElementById("comment");
|
||||
var commentToolPanel = document.getElementById("commenttoolpanel");
|
||||
// dim the page
|
||||
var darkness = document.getElementById("darkness");
|
||||
|
||||
var leftRight = true;
|
||||
var jsm = {}; // JavaScript Markdown
|
||||
window.jsm = jsm;
|
||||
window.jsm.toggleLeftRight = function() {
|
||||
leftRight = leftRight === false ? true : false;
|
||||
jsm.resize();
|
||||
}
|
||||
|
||||
var MarkdownMode = require("ace/mode/markdown").Mode;
|
||||
|
||||
function initAce(editor, editorSession) {
|
||||
editor.setTheme("ace/theme/twilight");
|
||||
editorSession.setMode(new MarkdownMode());
|
||||
// Gutter shows line numbers
|
||||
editor.renderer.setShowGutter(true);
|
||||
editor.renderer.setHScrollBarAlwaysVisible(false);
|
||||
editorSession.setUseSoftTabs(true);
|
||||
editorSession.setTabSize(2);
|
||||
editorSession.setUseWrapMode(true);
|
||||
editor.setShowPrintMargin(false);
|
||||
editor.setBehavioursEnabled(true);
|
||||
}
|
||||
|
||||
initAce(editor, editorSession);
|
||||
|
||||
// Setup comment ace.
|
||||
var commentEditor = ace.edit("comment");
|
||||
var commentEditorSession = commentEditor.getSession();
|
||||
var commentEditorContainer = commentEditor.container;
|
||||
|
||||
initAce(commentEditor, commentEditorSession);
|
||||
|
||||
// RegExp from http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
|
||||
$.key = function(key){
|
||||
var value = new RegExp('[\\?&]' + key + '=([^&#]*)').exec(window.location.href);
|
||||
return (!value) ? 0 : value[1] || 0;
|
||||
}
|
||||
|
||||
// True if &create=true
|
||||
var create = $.key("create");
|
||||
// The name of the page being edited.
|
||||
var pageName = $.key("page");
|
||||
|
||||
defaultCommitMessage = function() {
|
||||
var msg = pageName + " (markdown)";
|
||||
|
||||
if (create) {
|
||||
return "Created " + msg;
|
||||
} else {
|
||||
return "Updated " + msg;
|
||||
}
|
||||
}
|
||||
|
||||
// Set comment using the default commit message.
|
||||
commentEditorSession.setValue( defaultCommitMessage() );
|
||||
|
||||
$.save = function( commitMessage ) {
|
||||
window.onbeforeunload = null;
|
||||
|
||||
var POST = "POST";
|
||||
var markdown = "markdown";
|
||||
var txt = editorSession.getValue();
|
||||
var msg = defaultCommitMessage();
|
||||
var newLocation = window.location.protocol + "//" + window.location.host + "/" + pageName;
|
||||
|
||||
// if &create=true then handle create instead of edit.
|
||||
if (create) {
|
||||
jQuery.ajax({
|
||||
type: POST,
|
||||
url: "/create",
|
||||
data: { page: pageName, format: markdown, content: txt, message: commitMessage || msg },
|
||||
success: function() {
|
||||
window.location = newLocation;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
jQuery.ajax({
|
||||
type: POST,
|
||||
url: "/edit/" + pageName,
|
||||
data: { format: markdown, content: txt, message: commitMessage || msg },
|
||||
success: function() {
|
||||
window.location = newLocation;
|
||||
}
|
||||
});
|
||||
} // end else
|
||||
}
|
||||
|
||||
var elapsedTime;
|
||||
var oldInputText = "";
|
||||
|
||||
// ---- from Markdown.Editor
|
||||
var timeout;
|
||||
|
||||
var nonSuckyBrowserPreviewSet = function (text) {
|
||||
content.innerHTML = text;
|
||||
}
|
||||
|
||||
// IE doesn't let you use innerHTML if the element is contained somewhere in a table
|
||||
// (which is the case for inline editing) -- in that case, detach the element, set the
|
||||
// value, and reattach. Yes, that *is* ridiculous.
|
||||
var ieSafePreviewSet = function (text) {
|
||||
var parent = content.parentNode;
|
||||
var sibling = content.nextSibling;
|
||||
parent.removeChild(content);
|
||||
content.innerHTML = text;
|
||||
if (!sibling)
|
||||
parent.appendChild(content);
|
||||
else
|
||||
parent.insertBefore(content, sibling);
|
||||
}
|
||||
|
||||
var cssTextSet = function( element, css ){
|
||||
element.style.cssText = css;
|
||||
}
|
||||
|
||||
var cssAttrSet = function( element, css ){
|
||||
element.setAttribute( 'style', css );
|
||||
}
|
||||
|
||||
/*
|
||||
Redefine the function based on browser support.
|
||||
element - the element to set the css on
|
||||
css - a fully formed css string. ex: "top: 0; left: 0;"
|
||||
|
||||
Avoid reflow by batching CSS changes.
|
||||
http://dev.opera.com/articles/view/efficient-javascript/?page=3#stylechanges
|
||||
*/
|
||||
var cssSet = function( element, css ) {
|
||||
if( typeof( element.style.cssText ) != 'undefined' ) {
|
||||
cssTextSet( element, css );
|
||||
cssSet = cssTextSet;
|
||||
} else {
|
||||
cssAttrSet( element, css );
|
||||
cssSet = cssAttrSet;
|
||||
}
|
||||
}
|
||||
|
||||
var previewSet = function( text ) {
|
||||
try {
|
||||
nonSuckyBrowserPreviewSet( text );
|
||||
previewSet = nonSuckyBrowserPreviewSet;
|
||||
} catch (e) {
|
||||
ieSafePreviewSet( text );
|
||||
previewSet = ieSafePreviewSet;
|
||||
}
|
||||
};
|
||||
|
||||
var languages = [ "1c", "actionscript", "apache", "avrasm", "axapta",
|
||||
"bash", "cmake", "coffeescript", "cpp", "cs", "css", "delphi", "diff",
|
||||
"django", "d", "dos", "erlang", "erlang-repl", "go", "haskell", "ini",
|
||||
"java", "javascript", "languages", "lisp", "lua", "markdown", "matlab",
|
||||
"mel", "nginx", "objectivec", "parser3", "perl", "php", "profile",
|
||||
"python", "renderman", "ruby", "rust", "scala", "smalltalk", "sql",
|
||||
"tex", "vala", "vbscript", "vhdl", "xml" ];
|
||||
|
||||
var makePreviewHtml = function () {
|
||||
var text = editorSession.getValue();
|
||||
|
||||
if (text && text == oldInputText) {
|
||||
return; // Input text hasn't changed.
|
||||
}
|
||||
else {
|
||||
oldInputText = text;
|
||||
}
|
||||
|
||||
var prevTime = new Date().getTime();
|
||||
|
||||
text = converter.makeHtml(text);
|
||||
|
||||
// Calculate the processing time of the HTML creation.
|
||||
// It's used as the delay time in the event listener.
|
||||
var currTime = new Date().getTime();
|
||||
elapsedTime = currTime - prevTime;
|
||||
|
||||
// Update the text using feature detection to support IE.
|
||||
// preview.innerHTML = text; // this doesn't work on IE.
|
||||
previewSet(text);
|
||||
|
||||
// highlight code blocks.
|
||||
var codeElements = preview.getElementsByTagName("pre");
|
||||
var codeElementsLength = codeElements.length;
|
||||
var hlSpace = " ";
|
||||
if (codeElementsLength > 0) {
|
||||
for (var idx = 0; idx < codeElementsLength; idx++) {
|
||||
var element = codeElements[idx];
|
||||
var codeHTML = element.innerHTML;
|
||||
|
||||
// Only use pre tags marked containing code.
|
||||
if (codeHTML[0] !== "`")
|
||||
continue;
|
||||
|
||||
var txt = codeHTML.split(/\b/);
|
||||
// the syntax for code highlighting means all code, even one line, contains newlines.
|
||||
if (txt.length > 1 && codeHTML.match(/\n/)) {
|
||||
// txt[0] must be "`"
|
||||
// txt[0] = "`"; txt[1] = "ruby"
|
||||
if (txt[0] !== "`" || $.inArray(txt[1], languages) === -1) {
|
||||
element.innerHTML = codeHTML.substring(1).trim();
|
||||
hljs.highlightBlock(element, hlSpace);
|
||||
continue;
|
||||
}
|
||||
|
||||
element.className = txt[1] + " highlight";
|
||||
// length + 1 for the marker character.
|
||||
element.innerHTML = codeHTML.substring(txt[1].length+1).trim();
|
||||
hljs.highlightBlock(element, hlSpace);
|
||||
} else {
|
||||
element.innerHTML = codeHTML.substring(1).trim();
|
||||
hljs.highlightBlock(element, hlSpace);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// setTimeout is already used. Used as an event listener.
|
||||
var applyTimeout = function () {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = undefined;
|
||||
}
|
||||
|
||||
// 3 second max delay
|
||||
if (elapsedTime > 3000) {
|
||||
elapsedTime = 3000;
|
||||
}
|
||||
|
||||
timeout = setTimeout(makePreviewHtml, elapsedTime);
|
||||
};
|
||||
|
||||
/* Load markdown from /data/page into the ace editor. */
|
||||
jQuery.ajax({
|
||||
type: "GET",
|
||||
url: "/data/" + $.key("page"),
|
||||
success: function(data) {
|
||||
editorSession.setValue(data);
|
||||
}
|
||||
});
|
||||
|
||||
$("#save").click(function() {
|
||||
$.save();
|
||||
});
|
||||
|
||||
// Hide dimmer, comment tool panel, and comment.
|
||||
$("#commentcancel").click(function() {
|
||||
// Restore focus on commentcancel but not on
|
||||
// savecommentconfirm because the latter loads
|
||||
// a new page.
|
||||
hideCommentWindow();
|
||||
editor.focus();
|
||||
});
|
||||
|
||||
var isCommentHidden = true;
|
||||
|
||||
function hideCommentWindow() {
|
||||
isCommentHidden = true;
|
||||
darkness.style.visibility = "hidden";
|
||||
commentToolPanel.style.visibility = "hidden";
|
||||
comment.style.visibility = "hidden";
|
||||
}
|
||||
|
||||
// Show dimmer, comment tool panel, and comment.
|
||||
$("#savecomment").click(function() {
|
||||
isCommentHidden = false;
|
||||
darkness.style.visibility = "visible";
|
||||
commentToolPanel.style.visibility = "visible";
|
||||
comment.style.visibility = "visible";
|
||||
// Set focus so typing can begin immediately.
|
||||
commentEditor.focus();
|
||||
});
|
||||
|
||||
$("#savecommentconfirm").click(function() {
|
||||
$.save(commentEditorSession.getValue());
|
||||
hideCommentWindow();
|
||||
});
|
||||
|
||||
// onChange calls applyTimeout which rate limits the calling of makePreviewHtml based on render time.
|
||||
editor.on('change', applyTimeout);
|
||||
makePreviewHtml(); // preview default text on load
|
||||
|
||||
function resize() {
|
||||
var width = $(window).width();
|
||||
var widthHalf = width / 2;
|
||||
var widthFourth = widthHalf / 2;
|
||||
var height = $(window).height();
|
||||
var heightHalf = height / 2;
|
||||
|
||||
// height minus 50 so the end of document text doesn't flow off the page.
|
||||
var editorContainerStyle = "width:" + widthHalf + "px;" +
|
||||
"height:" + (height - 50) + "px;" +
|
||||
"left:" + (leftRight === false ? widthHalf + "px;" : "0px;") +
|
||||
"top:" + "40px;"; // use 40px for tool menu
|
||||
cssSet( editorContainer, editorContainerStyle );
|
||||
editor.resize();
|
||||
|
||||
// width -2 for scroll bar & -10 for left offset
|
||||
var previewStyle = "width:" + (widthHalf - 2 - 10) + "px;" +
|
||||
"height:" + height + "px;" +
|
||||
"left:" + (leftRight === false ? "10px;" : widthHalf + "px;") +
|
||||
"top:" + "0px;";
|
||||
cssSet( preview, previewStyle );
|
||||
|
||||
// Resize tool panel
|
||||
var toolPanelStyle = "width:" + widthHalf + "px;" +
|
||||
"left:" + (leftRight === false ? widthHalf + "px;" : "0px;");
|
||||
cssSet( toolPanel, toolPanelStyle );
|
||||
|
||||
// Resize comment related elements.
|
||||
var commentHidden = "visibility:" + ( isCommentHidden === true ? "hidden;" : "visible;" );
|
||||
|
||||
// Adjust comment editor
|
||||
var commentEditorContainerStyle = "height:" + heightHalf + "px;" +
|
||||
"width:" + widthHalf + "px;" +
|
||||
"left:" + widthFourth + "px;" +
|
||||
"top:" + (heightHalf / 2) + "px;" +
|
||||
commentHidden;
|
||||
cssSet( commentEditorContainer, commentEditorContainerStyle );
|
||||
commentEditor.resize();
|
||||
|
||||
// In top subtract height (40px) of comment tool panel.
|
||||
var commentToolPanelStyle = "width:" + widthHalf + "px;" +
|
||||
"left:" + widthFourth + "px;" +
|
||||
"top:" + (height / 4 - 40) + "px;" +
|
||||
commentHidden;
|
||||
cssSet( commentToolPanel, commentToolPanelStyle );
|
||||
|
||||
// Resize dimmer.
|
||||
var darknessStyle = "width:" + width + "px;" +
|
||||
"height:" + height + "px;" +
|
||||
commentHidden;
|
||||
cssSet(darkness, darknessStyle);
|
||||
}
|
||||
|
||||
window.jsm.resize = resize;
|
||||
|
||||
/*
|
||||
Resize can be called an absurd amount of times
|
||||
and will crash the page without debouncing.
|
||||
http://benalman.com/projects/jquery-throttle-debounce-plugin/
|
||||
https://github.com/cowboy/jquery-throttle-debounce
|
||||
http://unscriptable.com/2009/03/20/debouncing-javascript-methods/
|
||||
*/
|
||||
$(window).resize( $.debounce( 100, resize ) );
|
||||
|
||||
// resize for the intial page load
|
||||
resize();
|
||||
})();
|
||||
@@ -175,6 +175,9 @@ else
|
||||
// Strip link definitions, store in hashes.
|
||||
text = _StripLinkDefinitions(text);
|
||||
|
||||
// Process gollum style code highlighting.
|
||||
text = _DoCodeSpansGollum(text);
|
||||
|
||||
text = _RunBlockGamut(text);
|
||||
|
||||
text = _UnescapeSpecialChars(text);
|
||||
@@ -1021,16 +1024,17 @@ else
|
||||
function _DoCodeSpansGollum(text) {
|
||||
//
|
||||
// Gollum wraps code in one pre. Use ` to mark code pre.
|
||||
// All regex set to use 'm' multiline option.
|
||||
// Gollum requires exactly three starting and ending `.
|
||||
//
|
||||
text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
|
||||
text = text.replace(/(^|[^\\])(`{3})([^\r]*?[^`])\2(?!`)/gm,
|
||||
function (wholeMatch, m1, m2, m3, m4) {
|
||||
var c = m3;
|
||||
c = c.replace(/^([ \t]*)/gm, ""); // leading whitespace
|
||||
c = c.replace(/[ \t]*$/gm, ""); // trailing whitespace
|
||||
c = c.replace(/^([ \t]*)/g, ""); // leading whitespace
|
||||
c = c.replace(/[ \t]*$/g, ""); // trailing whitespace
|
||||
c = _EncodeCode(c);
|
||||
// Set to use 'm' multiline option.
|
||||
c = c.replace(/:\/\//gm, "~P"); // to prevent auto-linking. Not necessary in code *blocks*, but in code spans. Will be converted back after the auto-linker runs.
|
||||
return m1 + "<pre>`" + c + "</pre>";
|
||||
return m1 + hashBlock("<pre>`" + c + "</pre>");
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1146,8 +1150,6 @@ else
|
||||
// Wrap <p> tags.
|
||||
//
|
||||
var end = grafs.length;
|
||||
var extendedString = "";
|
||||
var isExtended = false;
|
||||
for (var i = 0; i < end; i++) {
|
||||
var str = grafs[i];
|
||||
|
||||
@@ -1156,28 +1158,6 @@ else
|
||||
grafsOut.push(str);
|
||||
}
|
||||
else if (/\S/.test(str)) {
|
||||
// Detect start of gollum code.
|
||||
if (str.substring(0,3) === "```") {
|
||||
isExtended = true;
|
||||
}
|
||||
|
||||
if (isExtended === true) {
|
||||
// Detect end of gollum code.
|
||||
var strLength = str.length;
|
||||
if (str.substring(strLength-3, strLength) === "```") {
|
||||
str = extendedString + str;
|
||||
str = _DoCodeSpansGollum(str);
|
||||
grafsOut.push(str);
|
||||
|
||||
isExtended = false;
|
||||
extendedString = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
extendedString += str + "\n\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
str = _RunSpanGamut(str);
|
||||
str = str.replace(/^([ \t]*)/g, "<p>");
|
||||
str += "</p>"
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
}
|
||||
|
||||
// (tags that can be opened/closed) | (tags that stand alone)
|
||||
var basic_tag_whitelist = /^(<\/?(b|blockquote|code|del|dd|dl|dt|em|h1|h2|h3|i|kbd|li|ol|p|pre|s|sup|sub|strong|strike|ul)>|<(br|hr)\s?\/?>)$/i;
|
||||
var basic_tag_whitelist = /^(<\/?(b|blockquote|code|del|dd|dl|dt|em|h1|h2|h3|h4|h5|h6|i|kbd|li|ol|p|pre|s|sup|sub|strong|strike|ul)>|<(br|hr)\s?\/?>)$/i;
|
||||
// <a href="url..." optional title>|</a>
|
||||
// Make https:// ftp:// prefix optional so relative links work. <a href="page1">page one</a>
|
||||
var a_white = /^(<a\shref="(((https?|ftp):\/\/|\/))?[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+"(\stitle="[^"<>]+")?\s?>|<\/a>)$/i;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2010 "Cowboy" Ben Alman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -12,6 +12,7 @@ Uses code/assets from:
|
||||
0. [notepages](https://github.com/fivesixty/notepages)
|
||||
0. [pagedown](https://code.google.com/p/pagedown/)
|
||||
0. [retina_display_icon_set](http://blog.twg.ca/2010/11/retina-display-icon-set/)
|
||||
0. [debounce](https://github.com/cowboy/jquery-throttle-debounce)
|
||||
|
||||
See licenses folder for details.
|
||||
|
||||
@@ -41,6 +42,6 @@ Using jQuery v1.7.2.
|
||||
- Download latest production version from [jquery.com](http://www.jquery.com).
|
||||
|
||||
## Pagedown
|
||||
The Pagedown code used is from revision `44a4db795617`, Mar 2, 2012 (currently the newest version at the time of writing this document). Markdown.Converter.js has been enhanced to support Gollum style code highlighting.
|
||||
The Pagedown code used is from revision `44a4db795617`, Mar 2, 2012 (currently the newest version at the time of writing this document). Markdown.Converter.js has been enhanced to support Gollum style code highlighting. Markdown.Sanitizer.js has been fixed to not remove h4-6.
|
||||
|
||||
`https://code.google.com/p/pagedown/source/detail?r=44a4db795617288ae9817c90735fb497891ede23`
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
window.onbeforeunload = function(){ return "Leaving will not create a new page!" };
|
||||
$("#gollum-editor-submit").click( function() { window.onbeforeunload = null; } );
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
$.GollumEditor({ NewFile: true, MarkupType: '{{default_markup}}' });
|
||||
});
|
||||
</script>
|
||||
|
||||
{{something}}
|
||||
{{something}}
|
||||
|
||||
@@ -11,7 +11,10 @@
|
||||
<div id="wiki-content">{{>editor}}</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
window.onbeforeunload = function(){ return "Leaving will discard all edits!" };
|
||||
$("#gollum-editor-submit").click( function() { window.onbeforeunload = null; } );
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
$.GollumEditor();
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -112,10 +112,14 @@
|
||||
|
||||
<div id="gollum-editor-edit-summary" class="singleline">
|
||||
<label for="message" class="jaws">Edit message:</label>
|
||||
<input type="text" name="message" id="gollum-editor-message-field" value="Write a small message here explaining this change. (Optional)">
|
||||
{{#is_create_page}}
|
||||
<input type="text" name="message" id="gollum-editor-message-field" value="Created {{page_name}} ({{format}})">
|
||||
{{/is_create_page}}
|
||||
{{#is_edit_page}}
|
||||
<input type="text" name="message" id="gollum-editor-message-field" value="Updated {{page_name}} ({{format}})">
|
||||
{{/is_edit_page}}
|
||||
</div>
|
||||
|
||||
|
||||
<span class="jaws"><br></span>
|
||||
<input type="submit" id="gollum-editor-submit" value="Save" title="Save current changes">
|
||||
<a href="/preview" id="gollum-editor-preview" class="minibutton" title="Preview this Page">Preview</a>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html;charset=utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="/css/_styles.css" media="all">
|
||||
<title>File View</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="home_button">
|
||||
<ul class="actions">
|
||||
<li class="minibutton">
|
||||
<a href="/" class="action-edit-page">Home</a>
|
||||
</li>
|
||||
<li class="minibutton" class="jaws">
|
||||
<a href="#" id="minibutton-new-page">New Page</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{{#has_results}}
|
||||
<div id="results">
|
||||
{{{results}}}
|
||||
</div>
|
||||
{{/has_results}}
|
||||
|
||||
{{#no_results}}
|
||||
<p id="no-results">
|
||||
There are no pages in <strong>{{ref}}</strong>.
|
||||
</p>
|
||||
{{/no_results}}
|
||||
</body>
|
||||
</html>
|
||||
@@ -7,6 +7,8 @@
|
||||
</li>
|
||||
<li class="minibutton"><a href="/pages"
|
||||
class="action-all-pages">All Pages</a></li>
|
||||
<li class="minibutton"><a href="/fileview"
|
||||
class="action-all-pages">File View</a></li>
|
||||
<li class="minibutton" class="jaws">
|
||||
<a href="#" id="minibutton-new-page">New Page</a></li>
|
||||
{{#editable}}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
module Precious
|
||||
module Views
|
||||
class FileView < Layout
|
||||
attr_reader :results, :ref
|
||||
|
||||
def title
|
||||
"All pages in #{@ref}"
|
||||
end
|
||||
|
||||
def has_results
|
||||
!@results.empty?
|
||||
end
|
||||
|
||||
def no_results
|
||||
@results.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user