-
Notifications
You must be signed in to change notification settings - Fork 0
/
wikiLingoInlineEditor.js
executable file
·85 lines (66 loc) · 2.97 KB
/
wikiLingoInlineEditor.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
var wikiLingoInlineEditor;
wikiLingoInlineEditor = (function ($) {
"use strict";
return function (editButton, menu, articleId, editable, siteUrl) {
var saveButton = $('<span class="save-link"><a href="#">Save</a></span>')
.appendTo(menu),
cancelButton = $('<span class="cancel-link"><a href="#">Cancel</a></span>')
.appendTo(menu),
sourceEditorContainer = $('<div id="editableSource">')
.insertAfter(editable),
editableAreaParent = $('<div id="editable">')
.insertAfter(editable)
.append(editable),
editableSource = $('<textarea name="content"></textarea>')
.appendTo(sourceEditorContainer),
toggleEditorButton = $('<input type="button" class="button" value="Toggle Editor"/>')
.insertAfter(sourceEditorContainer),
reflectUrl = siteUrl + '/wp-content/plugins/wikiLingo/wikiLingoReflect.php',
folderUrl = siteUrl + '/wp-content/plugins/wikiLingo/vendor/wikilingo/wikilingo/',
editor = wikiLingoEditor(reflectUrl, folderUrl, editable, editableSource[0]),
wikiLingoBubbles = $('nav.wikiLingo-bubble');
editButton.hide();
saveButton.click(function () {
saveButton.hide();
cancelButton.hide();
editButton.show();
});
cancelButton.click(function () {
cancelButton.hide();
saveButton.hide();
editButton.show();
});
toggleEditorButton.click(function () {
if (sourceEditorContainer.is(':visible')) {
$.ajax({
type: 'POST',
dataType: 'json',
url: siteUrl + '/wp-content/plugins/wikiLingo/wikiLingoReflect.php',
data: {w: editableSource.innerHTML, reflect: 'WYSIWYGWikiLingo'},
success: function (result) {
editable.html = result.output;
window.wLPlugins = result.plugins;
sourceEditorContainer.hide();
editableAreaParent.show();
wikiLingoBubbles.hide();
}
});
} else {
$.ajax({
type: 'POST',
dataType: 'json',
url: siteUrl + '/wp-content/plugins/wikiLingo/wikiLingoReflect.php',
data: {w: editable.innerHTML, reflect: 'wikiLingoWYSIWYG'},
success: function (result) {
editableSource.html = result.output;
window.wLPlugins = result.plugins;
sourceEditorContainer.show();
editableAreaParent.hide();
wikiLingoBubbles.show();
}
});
}
sourceEditorContainer.hide();
});
}
})(jQuery);