@@ -24,20 +24,23 @@ block content
2424
2525 .item-row
2626 ul#pages-tabs .nav.nav-tabs.nav-justified
27- li#tab-page-announce .active ( role ="presentation" )
27+ li#tab-page-announce ( role ="presentation" )
2828 a#btn-page-announce ( href ="#" ) Announce
29- li#tab-page-content ( role ="presentation" )
29+ li#tab-page-content .active ( role ="presentation" )
3030 a#btn-page-content ( href ="#" ) Content
31+ li#tab-page-preview ( role ="presentation" )
32+ a#btn-page-preview ( href ="#" ) Preview
33+
3134
3235 div#pages
3336
34- div#page-announce
37+ div#page-announce ( style = "display:none" )
3538
3639 .item-row
3740 textarea.form-control #announcement ( name ="announcement" )
3841 = postForm .getAnnouncement ()
3942
40- div#page-content ( style = "display:none" )
43+ div#page-content
4144
4245 .item-row
4346 textarea.form-control #content ( name ="content" , style ="display:none;" )
@@ -111,6 +114,12 @@ block content
111114 else
112115 option( value ="#{ogLocale .getId ()} " ) #{ogLocale .getName ()}
113116
117+ div#page-preview ( style ="display:none" )
118+
119+ .item-row
120+ div#content-preview
121+ img#loading .loading.borderless ( src ="/images/loading.gif" )
122+
114123
115124 .item-row
116125 hr
@@ -137,8 +146,9 @@ block content
137146 $(document).ready(function () {
138147 // page Announcement
139148 $("#btn-page-announce").click(function () {
140- $("#page-announce ").show ();
149+ $("#page-preview ").hide ();
141150 $("#page-content").hide();
151+ $("#page-announce").show();
142152 $("#pages-tabs li").each(function () {
143153 $(this).removeClass("active");
144154 });
@@ -147,10 +157,41 @@ block content
147157 //page Content
148158 $("#btn-page-content").click(function () {
149159 $("#page-announce").hide();
160+ $("#page-preview").hide();
150161 $("#page-content").show();
151162 $("#pages-tabs li").each(function () {
152163 $(this).removeClass("active");
153164 });
154165 $("#tab-page-content").addClass("active");
155166 });
167+ //page Preview
168+ $("#btn-page-preview").click(function () {
169+ $("#page-announce").hide();
170+ $("#page-content").hide();
171+ $("#page-preview").show();
172+ $("#pages-tabs li").each(function () {
173+ $(this).removeClass("active");
174+ });
175+ $("#tab-page-preview").addClass("active");
176+
177+ $("#content-preview").html("<img class='loading borderless' src='/images/loading.gif'/>");
178+ var token = $("input[name='_csrf']").val();
179+ var header = "X-CSRF-TOKEN";
180+ $(document).ajaxSend(function (e, xhr, options) {
181+ xhr.setRequestHeader(header, token);
182+ });
183+ $.ajax({
184+ type: 'post',
185+ contentType: 'application/json',
186+ url: '/admin/posts/preview',
187+ data: JSON.stringify({
188+ content: editor.getValue()
189+ })
190+ }).done(function(data) {
191+ $("#content-preview").html(data.content);
192+ }).fail(function() {
193+ $("#content-preview").html("<img class='loading-error borderless' src='/images/icon_error.svg'/>");
194+ });
195+
196+ });
156197 });
0 commit comments