Skip to content

Commit 8ceebb6

Browse files
authored
Merge pull request #15 from ibrahemomari/fix-wysiwyg-on-load
fix WYSIWYG editor content appears empty after refresh
2 parents 578c832 + 7475070 commit 8ceebb6

1 file changed

Lines changed: 27 additions & 58 deletions

File tree

control/content/index.html

Lines changed: 27 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,7 @@
3232

3333
<script>
3434
/// create a new instance of the buildfire carousel editor
35-
var editor = new buildfire.components.carousel.editor("#contentCarousel");
36-
37-
tinymce.init({
38-
selector: "#wysiwygContent",
39-
setup: function (editor) {
40-
editor.on('change', function () {
41-
saveWYSContent(editor.getContent())
42-
});
43-
}
44-
});
35+
const editor = new buildfire.components.carousel.editor("#contentCarousel");
4536

4637
/// handle the loading
4738
function loadItems(carouselItems) {
@@ -52,37 +43,23 @@
5243
/// call buildfire datastore to see if there are any previously saved items
5344
buildfire.datastore.get(function (err, obj) {
5445
if (err)
55-
alert('error');
46+
console.error('error');
5647
else
5748
loadItems(obj.data.carouselItems)
5849
});
5950

6051
/// save any changes in items
6152
function save(items) {
62-
console.log('saving...');
6353
buildfire.datastore.save({ carouselItems: items }, function (e) {
6454
if (e)
65-
alert("error");
55+
console.error("error");
6656
else
6757
console.log('saved.');
6858
});
6959
}
7060

71-
72-
// this method will be called when a new item added to the list
73-
editor.onAddItems = function (items) {
74-
save(editor.items);
75-
};
76-
// this method will be called when an item deleted from the list
77-
editor.onDeleteItem = function (item, index) {
78-
save(editor.items);
79-
};
80-
// this method will be called when you edit item details
81-
editor.onItemChange = function (item) {
82-
save(editor.items);
83-
};
84-
// this method will be called when you change the order of items
85-
editor.onOrderChange = function (item, oldIndex, newIndex) {
61+
// // this method will be called when a new item added to the list
62+
editor.onAddItems = editor.onDeleteItem = editor.onItemChange = editor.onOrderChange = function () {
8663
save(editor.items);
8764
};
8865

@@ -98,15 +75,28 @@
9875
}
9976
}
10077

101-
102-
// Check datastore for previous content
103-
buildfire.datastore.get("wysContent", (err, result) => {
104-
if (err) return console.error("Error while getting your data", err);
105-
if (result && result.data && result.data.content) {
106-
console.log("Content found in datastore", result.data.content);
107-
tinymce.activeEditor.setContent(result.data.content);
108-
saveWYSContent(result.data.content);
109-
}
78+
let timerDelay = null;
79+
tinymce.init({
80+
selector: "#wysiwygContent",
81+
setup: (editor) => {
82+
editor.on("change keyUp", (e) => {
83+
if (timerDelay) clearTimeout(timerDelay);
84+
timerDelay = setTimeout(() => {
85+
let wysiwygContent = tinymce.activeEditor.getContent();
86+
saveWYSContent(wysiwygContent);
87+
}, 500);
88+
});
89+
editor.on("init", () => {
90+
// Check datastore for previous content
91+
buildfire.datastore.get("wysContent", (err, result) => {
92+
if (err) return console.error("Error while getting your data", err);
93+
if (result && result.data && result.data.content) {
94+
console.log("Content found in datastore", result);
95+
editor.setContent(result.data.content);
96+
}
97+
});
98+
});
99+
}
110100
});
111101

112102
// Save content to datastore
@@ -122,27 +112,6 @@
122112
}
123113
}
124114

125-
126-
127-
// function createLeaderboard() {
128-
// let sb = new buildfire.gamify.Scoreboard("Scoreboard", 100, true);
129-
// leaderboardLB = new leaderboard(sb);
130-
// console.log("Created a new Scoreboard")
131-
// console.log(leaderboardLB.getSize())
132-
// }
133-
134-
// function changeSize() {
135-
// let size = lbSize.value
136-
// if (isNaN(size)) {
137-
// console.log("Must input numbers");
138-
// return false;
139-
// }
140-
// else {
141-
// leaderboardLB.setSize(parseInt(size))
142-
// console.log(leaderboardLB.getSize())
143-
// }
144-
// }
145-
146115
load()
147116
</script>
148117
</body>

0 commit comments

Comments
 (0)