/
script.js
55 lines (49 loc) · 1.65 KB
/
script.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
/*
GFMarkdownEditor 0.2
Example script
please see https://github.com/romaricdrigon/GFMarkdownEditor
*/
/*
Our app is composed of loosely-coupled modules
Here we do the strapping between modules and with our UI,
that's just an example script
*/
$(document).ready(function() {
// set up an editor in "#editor" div
GfmEditor.init('editor');
// we need a preview loader objet
GfmPreviewLoader.init('parent', 'preview', 'inner-preview', GfmEditor.resize);
GfmPreviewLoader.addButtons('toolbar');
GfmPreviewLoader.setMode('panes');
// we use Github API for preview
GapiPreview.init(GfmPreviewLoader.load);
var previewer = GapiPreview;
// preview when the user clicks a button
$('#preview-button').on('click', function(e) {
e.preventDefault();
previewer.preview(GfmEditor.getContent());
});
// user can log in using his GitHub Account
GfmGithubAuth.init(
function(credentials) {
previewer.setGithubCredentials(credentials);
previewer.preview(GfmEditor.getContent()); // preview after login
},
function() {
GapiPreview.setGithubCredentials(null); // only GapiPreview have a such method
}
);
GfmGithubAuth.addButtons('toolbar');
// lastly, content will be saved when user try to leave
GfmBackup.init(
function(text) {
GfmEditor.setContent(text);
previewer.preview(text);
},
GfmEditor.getContent,
true
);
// we add the GFM cheatsheet
GfmCheatSheet.init(GfmPreviewLoader.load, $('#cheat-sheet').html());
GfmCheatSheet.addButtons('toolbar');
});