1
|
$(function() {
|
2
|
// snippets init functions
|
3
|
altair_snippets.init();
|
4
|
});
|
5
|
|
6
|
altair_snippets = {
|
7
|
init: function () {
|
8
|
|
9
|
var $snippets = $('#snippets'),
|
10
|
$snippet_modal = $('#snippet_new'),
|
11
|
$html_editor = $('#snippet_content');
|
12
|
|
13
|
// show code on content click
|
14
|
$snippets
|
15
|
.find('.md-card-content')
|
16
|
.css({ 'cursor': 'pointer' })
|
17
|
.on('click',function() {
|
18
|
UIkit.modal.blockUI(
|
19
|
// snippet title
|
20
|
'<div class="uk-modal-header">'
|
21
|
+ '<h3 class="uk-modal-title">' + $(this).parent('.md-card').attr('data-snippet-title') + '</h3>'
|
22
|
+ '</div>'
|
23
|
|
24
|
// snipped code
|
25
|
+ $(this).html()
|
26
|
|
27
|
// hide modal
|
28
|
+ '<div class="uk-modal-footer uk-text-right">'
|
29
|
+ '<button type="button" class="md-btn md-btn-flat md-btn-flat-primary uk-modal-close">Close</button>'
|
30
|
+ '</div>'
|
31
|
);
|
32
|
});
|
33
|
|
34
|
var snippet_CodeMirror = UIkit.htmleditor($html_editor, {
|
35
|
'toolbar': '',
|
36
|
'height': '240'
|
37
|
}).editor;
|
38
|
|
39
|
// save snippet
|
40
|
$('#snippet_new_save').on('click',function() {
|
41
|
|
42
|
snippet_CodeMirror.save();
|
43
|
var language = $("#snippet_language").val(),
|
44
|
title = $("#snippet_title").val(),
|
45
|
content = snippet_CodeMirror.getValue();
|
46
|
|
47
|
// close main modal
|
48
|
$snippet_modal.find('.uk-modal-close').click();
|
49
|
|
50
|
// uncomment code bellow to save snippet to json
|
51
|
UIkit.modal.confirm('Do you want to save this snippet: <strong>"' + title + '"</strong>?', function(){
|
52
|
UIkit.modal.alert("Snipped saved!");
|
53
|
// uncoment following code to activate snippets saving
|
54
|
/*$.ajax({
|
55
|
type: "POST",
|
56
|
url: "./data/save_snippet.php",
|
57
|
data: {
|
58
|
language: language,
|
59
|
title: title,
|
60
|
content: content
|
61
|
},
|
62
|
dataType: 'text',
|
63
|
success: function(){
|
64
|
// clear fields
|
65
|
$("#snippet_language,#snippet_title").val('');
|
66
|
snippet_CodeMirror.setValue('');
|
67
|
// show message
|
68
|
UIkit.modal.alert("Snipped saved!");
|
69
|
}
|
70
|
});
|
71
|
*/
|
72
|
});
|
73
|
|
74
|
|
75
|
});
|
76
|
|
77
|
// refresh htmleditor on modal show
|
78
|
$snippet_modal.on({
|
79
|
'show.uk.modal': function(){
|
80
|
$("#snippet_title").focus();
|
81
|
snippet_CodeMirror.refresh();
|
82
|
}
|
83
|
});
|
84
|
|
85
|
}
|
86
|
};
|