|
32 | 32 |
|
33 | 33 | <script> |
34 | 34 | /// 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"); |
45 | 36 |
|
46 | 37 | /// handle the loading |
47 | 38 | function loadItems(carouselItems) { |
|
52 | 43 | /// call buildfire datastore to see if there are any previously saved items |
53 | 44 | buildfire.datastore.get(function (err, obj) { |
54 | 45 | if (err) |
55 | | - alert('error'); |
| 46 | + console.error('error'); |
56 | 47 | else |
57 | 48 | loadItems(obj.data.carouselItems) |
58 | 49 | }); |
59 | 50 |
|
60 | 51 | /// save any changes in items |
61 | 52 | function save(items) { |
62 | | - console.log('saving...'); |
63 | 53 | buildfire.datastore.save({ carouselItems: items }, function (e) { |
64 | 54 | if (e) |
65 | | - alert("error"); |
| 55 | + console.error("error"); |
66 | 56 | else |
67 | 57 | console.log('saved.'); |
68 | 58 | }); |
69 | 59 | } |
70 | 60 |
|
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 () { |
86 | 63 | save(editor.items); |
87 | 64 | }; |
88 | 65 |
|
|
98 | 75 | } |
99 | 76 | } |
100 | 77 |
|
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 | + } |
110 | 100 | }); |
111 | 101 |
|
112 | 102 | // Save content to datastore |
|
122 | 112 | } |
123 | 113 | } |
124 | 114 |
|
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 | | - |
146 | 115 | load() |
147 | 116 | </script> |
148 | 117 | </body> |
|
0 commit comments