-
Notifications
You must be signed in to change notification settings - Fork 0
/
editinplace.js
107 lines (80 loc) · 3.02 KB
/
editinplace.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
$(document).ready(function() {
var giveDoseEditorzDaHookupBiotch = function() {
console.debug('hookin up da editorz, biotch!');
$('.editable').on('mouseenter', onEditableMouseover);
$('.editable').on('mouseleave', onEditableMouseout);
$('.editable').on('click', onEditableClick);
$('.savebtn').on('click', onSaveBtnClick);
};
var onEditableMouseover = function() {
console.debug('mouse over ', $(this));
$('.editable').removeClass('rolled-over');
$(this).addClass('rolled-over');
};
var onEditableMouseout = function() {
console.debug('mouse out ', $(this));
$(this).removeClass('rolled-over');
};
var onEditableClick = function() {
console.debug("Editing ", $(this).data('id'));
var cid = $(this).data('id');
var type = $(this).data('type');
var content = $(this).html();
var editor = "#editor-"+type;
var panel = ".editor-panel-"+type;
currentElement = this;
currentEditor = editor;
$("#editor-modal .modal-title").html(cid);
if(type === 'html') {
$(editor).html(content);
tinymce.activeEditor.execCommand('mceSetContent', false, content);
} else {
$(editor).val(content);
}
$("#editor-modal").modal();
$(".editor-panel").hide();
$(panel).show();
if(!contentHistory[cid]) {
contentHistory[cid] = [];
contentHistory[cid].push({"date": "Original", "content": content});
}
populateHistoryPanel(cid);
};
var onSaveBtnClick = function() {
var type = $(currentElement).data('type');
var cid = $(currentElement).data('id');
if(type === 'html') {
content = tinymce.activeEditor.getContent();
} else {
content = $(currentEditor).val();
}
if(!contentHistory[cid]) {
contentHistory[cid] = [];
}
contentHistory[cid].push({"date": new Date(), "content": content});
$(currentElement).html(content);
$("#editor-modal").modal('hide');
};
var populateHistoryPanel = function(cid) {
var historyPanel = $('#editor-modal .history');
var html = "<ul class='nav nav-pills nav-stacked'>";
if(contentHistory[cid]) {
for (var i = 0; i < contentHistory[cid].length; i++) {
var content = contentHistory[cid][i];
html += "<li><a href=\"javascript:setContentToHistory("+i+")\">"+contentHistory[cid][i].date+"</a></li>";
}
} else {
html += "<li>This content has not yet been changed.</li>"
}
html += "</ul>";
historyPanel.html(html);
};
giveDoseEditorzDaHookupBiotch();
});
var currentElement = null;
var currentEditor = null;
var contentHistory = {};
var setContentToHistory = function(i) {
$(currentElement).html(contentHistory[$(currentElement).data('id')][i].content);
$("#editor-modal").modal('hide');
};