forked from OscarGodson/EpicEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
77 lines (65 loc) · 2.85 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*global $:false, prettyPrint:false */
$(function () {
var zipUrl = 'docs/downloads/EpicEditor-v' + EpicEditor.version + '.zip';
// TODO: Now that we have automatic ID creation, use element IDs instead of counting DOM elements
$('#wrapper').before('<div id="toc"><h2><a href="#">EpicEditor</a></h2><ul id="toc-list"></ul></div>');
$("h2, h3").each(function (idx, val) {
var h = $(this)
, title = h.text()
, link = title.toLowerCase().replace(/(\,|\(|\)|\[|\]|\:|\.)/g, '').replace(/\s/g, '-')
// The first h2 is always the EpicEditor TOC header injected above
// Give them all IDs so there's something to hook into
if (idx > 0) {
h.attr("id", link);
}
if (idx > 1) {
h.html('<a href="#' + link + '">' + title + '</a>');
$("#toc-list").append('<li class="toc-' + this.nodeName.toLowerCase() + '"><a id="" href="#' + link + '">' + title + '</a></li>');
}
});
$('#wrapper h1').append('<span>beta ' + EpicEditor.version + '</span>');
$('#why').before('<h2 id="download">Download</h2><p class="btn"><a class="zip" href="' + zipUrl + '">EpicEditor v' + EpicEditor.version + '</a></p>')
$('#quick-start').before('<p class="btn btn-small"><a id="try-it">Try it!</a></p><div id="epiceditor"></div>');
$('#an-embeddable-javascript-markdown-editor + p').after('<div class="epiceditors" id="example-1"></div>');
$('#step-1-download + p').html('<a href="#download">Download the latest release (' + EpicEditor.version + ')</a> or clone the repo:');
$('tr:even').addClass('even');
var opts =
{ container: 'example-1'
, file: { defaultContent: "#EpicEditor\nThis is some default content. Go ahead, _change me_. " }
, focusOnLoad: true
, autogrow: {
minHeight: 350
}
}
, editor = new EpicEditor(opts).load()
, example = new EpicEditor()
, tryItStatus = false
, tryItBtn = document.getElementById('try-it');
// So people can play with it in their console
window.editor = editor;
window.example = example;
tryItBtn.onclick = function () {
if (!tryItStatus) {
tryItStatus = true;
tryItBtn.innerHTML = 'Unload';
$('#epiceditor').addClass('epiceditors')
example.load();
}
else {
tryItStatus = false;
tryItBtn.innerHTML = 'Try it!';
$('#epiceditor').removeClass('epiceditors')
example.unload();
$('#epiceditor').height('auto');
}
}
$('pre').addClass('prettyprint')
prettyPrint()
$(['OscarGodson', 'johnmdonahue', 'adam_bickford', 'sebnitu']).each(function (idx, val) {
var twimg = 'https://twitter.com/' + val + '/profile_image', twlink = 'https://twitter.com/' + val
$('#avatars').append('<a href="' + twlink + '"><img class="avatar" src="' + twimg + '">')
})
$(window).resize(function () {
$('#toc').height(window.innerHeight + 'px');
}).trigger('resize');
});