1- var editorController = function ( dataService ) {
2-
3- function save ( publish ) {
4- $ ( '#PostItem_Content' ) . val ( simplemde . value ( ) ) ;
5- $ ( '#PostItem_Status' ) . val ( publish === 'P' ? 2 : 1 ) ;
6- $ ( '#frmEditor' ) . submit ( ) ;
7- }
8-
9- function publish ( ) {
10- $ ( '#PostItem_Content' ) . val ( simplemde . value ( ) ) ;
11- $ ( '#PostItem_Status' ) . val ( 2 ) ;
12- $ ( '#frmEditor' ) . submit ( ) ;
13- }
14-
15- function unpublish ( ) {
16- $ ( '#PostItem_Content' ) . val ( simplemde . value ( ) ) ;
17- $ ( '#PostItem_Status' ) . val ( 3 ) ;
18- $ ( '#frmEditor' ) . submit ( ) ;
19- }
20-
21- function remove ( ) {
22- $ ( '.loading' ) . fadeIn ( 'fast' ) ;
23- dataService . remove ( "admin/removepost/" + $ ( '#PostItem_Id' ) . val ( ) , removeCallback , fail ) ;
24- }
25-
26- function removeCallback ( data ) {
27- toastr . success ( 'Deleted' ) ;
28- setTimeout ( function ( ) {
29- $ ( '.loading' ) . fadeOut ( 'fast' ) ;
30- window . location . href = webRoot + 'admin' ;
31- } , 1000 ) ;
32- }
33-
34- function loadCover ( ) {
35- var postId = $ ( '#hdnPostId' ) . val ( ) ;
36- var postImg = $ ( '#hdnPostImg' ) . val ( ) ;
37- $ ( '#post-image' ) . empty ( ) ;
38- if ( ! postImg . length > 0 ) {
39- var btn = '<button type="button" title="Add Cover" class="btn btn-secondary btn-block" data-placement="bottom" onclick="return editorController.openFilePicker(' + postId + ');">Upload Post Cover</button >' ;
40- }
41- $ ( '#post-image' ) . append ( btn ) ;
42- if ( postImg . length > 0 ) {
43- var dd = '<div class="admin-editor-cover-image"><img src="' + postImg + '" /></div>' ;
44- dd += '<button type="button" class="btn btn-danger btn-block" onclick="return editorController.resetPostImage();">Remove Cover</button>' ;
45- }
46- $ ( '#post-image' ) . append ( dd ) ;
47- }
48-
49- function loadButtons ( id ) {
50- if ( id > 0 ) {
51- $ ( '.act-upd' ) . css ( 'display' , 'inline-block' ) ;
52- $ ( '.act-new' ) . css ( 'display' , 'none' ) ;
53- }
54- else {
55- $ ( '.act-new' ) . css ( 'display' , 'inline-block' ) ;
56- $ ( '.act-upd' ) . css ( 'display' , 'none' ) ;
57- }
58- }
59-
60- function settings ( ) {
61- $ ( '#postSettings' ) . modal ( ) ;
62- return false ;
63- }
64-
65- return {
66- save : save ,
67- publish : publish ,
68- unpublish : unpublish ,
69- remove : remove ,
70- loadCover : loadCover ,
71- loadButtons : loadButtons ,
72- settings : settings
73- } ;
74- } ( DataService ) ;
75-
76- function getEditor ( ) {
1+ function getEditor ( post ) {
772 var simplemde = new SimpleMDE ( {
783 toolbar : [
794 "bold" , "italic" , "heading-2" , "|" ,
@@ -127,7 +52,7 @@ function getEditor() {
12752 syncSideBySidePreviewScroll : false
12853 } ) ;
12954
130- var txt = $ ( '#PostItem_Content' ) . val ( ) ;
55+ var txt = post . content ? post . content : '' ;
13156
13257 simplemde . value ( txt
13358 . replace ( / & # x A ; / g, '\r\n' )
@@ -162,4 +87,4 @@ var scrollDiv = document.createElement("div");
16287scrollDiv . className = "scrollbar-measure" ;
16388document . body . appendChild ( scrollDiv ) ;
16489var scrollbarWidth = scrollDiv . offsetWidth - scrollDiv . clientWidth ;
165- document . body . removeChild ( scrollDiv ) ;
90+ document . body . removeChild ( scrollDiv ) ;
0 commit comments