32c07059da
Squashed commit of the following: commit 0e5bd00043ffe0e8deba53447f998dc4b78da15a Author: Hideaki Tanabe <tanablog@gmail.com> Date: Sun Feb 17 02:32:48 2013 +0900 Update Google Analytics code. commit f8121229e63a5d96cb2dd3e2916f3b65924295ae Author: Hideaki Tanabe <tanablog@gmail.com> Date: Sun Feb 17 02:11:07 2013 +0900 Add copyright. commit b45120bb56d00f299907c1067a57a84df45ddc2f Author: Hideaki Tanabe <tanablog@gmail.com> Date: Sun Feb 17 01:46:48 2013 +0900 almost done. commit 52c2c58c1477a825d5f30ae05412ca4b1d54c31e Author: Hideaki Tanabe <tanablog@gmail.com> Date: Sun Feb 17 00:06:55 2013 +0900 Imprement core feature. commit b3ba7989a4dc285d3c15618ea267d29d8d8e6b6a Author: Hideaki Tanabe <tanablog@gmail.com> Date: Fri Feb 15 22:05:59 2013 +0900 Update libraries
126 lines
2.9 KiB
JavaScript
126 lines
2.9 KiB
JavaScript
var example = [
|
|
"# hello, This is Markdown Live Preview",
|
|
"",
|
|
"----",
|
|
"## what is Markdown?",
|
|
"see [Wikipedia](http://en.wikipedia.org/wiki/Markdown)",
|
|
"",
|
|
"> Markdown is a lightweight markup language, originally created by John Gruber and Aaron Swartz allowing people \"to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML)\".",
|
|
"",
|
|
"----",
|
|
"## usage",
|
|
"1. Write markdown text in this textarea.",
|
|
"2. Click 'HTML Preview' button.",
|
|
"",
|
|
"----",
|
|
"## markdown quick reference",
|
|
"# headers",
|
|
"",
|
|
"*emphasis*",
|
|
"",
|
|
"**strong**",
|
|
"",
|
|
"* list",
|
|
"",
|
|
">block quote",
|
|
"",
|
|
" code (4 spaces indent)",
|
|
"[links](http://wikipedia.org)",
|
|
"",
|
|
"----",
|
|
"## changelog",
|
|
"* 17-Feb-2013 re-design",
|
|
"",
|
|
"----",
|
|
"## thanks",
|
|
"* [markdown-js](https://github.com/evilstreak/markdown-js)",
|
|
""
|
|
].join("\n");
|
|
|
|
$(function() {
|
|
var currentMode = 'edit';
|
|
var container = $('#container');
|
|
var header = $('#header');
|
|
var headerHeight = header.outerHeight();
|
|
var titleHeight = $('#header h1').outerHeight();
|
|
var fixedTop = -titleHeight;
|
|
var scrollTops = {
|
|
'edit' : 0,
|
|
'preview' : 0
|
|
};
|
|
|
|
var isEdited = false;
|
|
|
|
$(window).scroll(function() {
|
|
var scrollTop = $(window).scrollTop();
|
|
scrollTops[currentMode] = scrollTop;
|
|
if ((scrollTop > titleHeight)) {
|
|
header.css({
|
|
'position' : 'fixed',
|
|
'top' : fixedTop + 'px',
|
|
'z-index' : '100'
|
|
});
|
|
|
|
container.css({
|
|
'margin-top' : headerHeight + 'px'
|
|
});
|
|
|
|
} else {
|
|
header.css('position', 'static');
|
|
container.css({
|
|
'margin-top' : 0
|
|
});
|
|
}
|
|
});
|
|
|
|
$('#markdown').val(example);
|
|
$('#output').html(markdown.toHTML(example));
|
|
$('#markdown').bind('keyup', function() {
|
|
isEdited = true;
|
|
$('#output').html(markdown.toHTML($('#markdown').val()));
|
|
});
|
|
|
|
//menu
|
|
var menuItems = $('#menu a');
|
|
menuItems.click(function(event) {
|
|
event.preventDefault();
|
|
|
|
menuItems.removeClass('active');
|
|
var sender = $(event.currentTarget);
|
|
sender.addClass('active');
|
|
|
|
$('#content .mode').hide();
|
|
var menuId = sender.data('menuId');
|
|
currentMode = menuId;
|
|
$('#' + menuId).show();
|
|
$(window).scrollTop(scrollTops[currentMode]);
|
|
|
|
});
|
|
|
|
//reference
|
|
$("table#reference tr td:odd").each(function(index, element) {
|
|
var self = $(element);
|
|
if (self.html() === "") {
|
|
self.html(markdown.toHTML(self.siblings().html()));
|
|
}
|
|
});
|
|
|
|
//clear
|
|
$('#clearButton').click(function(event) {
|
|
event.preventDefault();
|
|
if (window.confirm('Are you sure you want to delete?')) {
|
|
$('#markdown').val('');
|
|
}
|
|
});
|
|
|
|
//autoresize
|
|
$('textarea').autosize();
|
|
|
|
//leave
|
|
$(window).bind('beforeunload', function() {
|
|
if (isEdited) {
|
|
return 'Are you sure you want to leave? Your changes will be lost.';
|
|
}
|
|
});
|
|
});
|