@@ -5,9 +5,19 @@ import StatusBar from './article-edit-statusbar';
5
5
import ArticleMeta from "./article-edit-meta" ;
6
6
7
7
8
+ const ArticleContentEditable = {
9
+ save ( title , body , token ) {
10
+ saveArticle ( title , body , token ) ;
11
+ }
12
+ } ;
13
+
14
+ export default ArticleContentEditable ;
15
+
16
+ // --------------- //
17
+
8
18
function cacheTextHashForComparison ( )
9
19
{
10
- jQuery ( '[contenteditable=true ]' ) . each ( function ( ) {
20
+ jQuery ( '[data-tli-editable-id ]' ) . each ( function ( ) {
11
21
12
22
let editableId = jQuery ( this ) . data ( 'tli-editable-id' ) ;
13
23
window [ editableId ] = fastHash16ElementHtml ( this ) ;
@@ -17,10 +27,10 @@ function cacheTextHashForComparison()
17
27
// pageload init
18
28
cacheTextHashForComparison ( ) ;
19
29
20
- jQuery ( document ) . on ( 'input' , '[contenteditable=true ]' , debounce ( function ( ) {
30
+ jQuery ( document ) . on ( 'input' , '[data-tli-editable-id ]' , debounce ( function ( ) {
21
31
22
32
let differenceFound = false ;
23
- jQuery ( '[contenteditable=true ]' ) . each ( function ( ) {
33
+ jQuery ( '[data-tli-editable-id ]' ) . each ( function ( ) {
24
34
25
35
let fastHashedHtml = fastHash16ElementHtml ( this ) ;
26
36
let editableId = jQuery ( this ) . data ( 'tli-editable-id' ) ;
@@ -42,7 +52,7 @@ jQuery(document).on('input', '[contenteditable=true]', debounce(function() {
42
52
43
53
function clearCacheTextHashForComparison ( )
44
54
{
45
- jQuery ( '[contenteditable=true ]' ) . each ( function ( ) {
55
+ jQuery ( '[data-tli-editable-id ]' ) . each ( function ( ) {
46
56
47
57
let editableId = jQuery ( this ) . data ( 'tli-editable-id' ) ;
48
58
window [ editableId ] = null ;
@@ -51,8 +61,7 @@ function clearCacheTextHashForComparison()
51
61
52
62
53
63
var articleSaveRequest = null ;
54
-
55
- function saveArticle ( )
64
+ function saveArticle ( title , body , token )
56
65
{
57
66
// set to "unknown" until actually saved
58
67
clearCacheTextHashForComparison ( ) ;
@@ -66,9 +75,9 @@ function saveArticle()
66
75
let article = jQuery ( 'article' ) ;
67
76
let endpoint = article . attr ( 'data-save-url' ) ;
68
77
let payload = {
69
- "title" : jQuery ( '[data-tli-editable-id=title]' ) . html ( ) ,
70
- "body" : jQuery ( '[data-tli-editable-id=body]' ) . html ( ) ,
71
- "token" : null
78
+ "title" : title ?? jQuery ( '[data-tli-editable-id=title]' ) . html ( ) ,
79
+ "body" : body ?? jQuery ( '[data-tli-editable-id=body]' ) . html ( ) ,
80
+ "token" : token ?? null
72
81
} ;
73
82
74
83
articleSaveRequest =
0 commit comments