Browse Source

Text and Background colors

Yedidya Kennard 8 years ago
parent
commit
a7267c1016

+ 8
- 0
src/RichTextEditor.js View File

336
     this._sendAction(actions.setOutdent);
336
     this._sendAction(actions.setOutdent);
337
   }
337
   }
338
 
338
 
339
+  setBackgroundColor(color) {
340
+    this._sendAction(actions.setBackgroundColor, color);
341
+  }
342
+
343
+  setTextColor(color) {
344
+    this._sendAction(actions.setTextColor, color);
345
+  }
346
+
339
   setTitlePlaceholder() {
347
   setTitlePlaceholder() {
340
     this._sendAction(actions.setTitlePlaceholder);
348
     this._sendAction(actions.setTitlePlaceholder);
341
   }
349
   }

+ 6
- 0
src/WebviewMessageHandler.js View File

129
         case '${actions.setCustomCSS}':
129
         case '${actions.setCustomCSS}':
130
           zss_editor.setCustomCSS(action.data);
130
           zss_editor.setCustomCSS(action.data);
131
           break;
131
           break;
132
+        case '${actions.setTextColor}':
133
+          zss_editor.setTextColor(action.data);
134
+          break;
135
+        case '${actions.setBackgroundColor}':
136
+          zss_editor.setBackgroundColor(action.data);
137
+          break;
132
       }
138
       }
133
     };
139
     };
134
   }
140
   }

+ 8
- 3
src/ZSSRichTextEditor/ZSSRichTextEditor.js View File

371
 }
371
 }
372
 
372
 
373
 zss_editor.setTextColor = function(color) {
373
 zss_editor.setTextColor = function(color) {
374
-		
375
-    zss_editor.restorerange();
374
+
375
+    if(zss_editor.currentSelection) {
376
+        zss_editor.restorerange();
377
+    }
376
     document.execCommand("styleWithCSS", null, true);
378
     document.execCommand("styleWithCSS", null, true);
377
     document.execCommand('foreColor', false, color);
379
     document.execCommand('foreColor', false, color);
378
     document.execCommand("styleWithCSS", null, false);
380
     document.execCommand("styleWithCSS", null, false);
382
 }
384
 }
383
 
385
 
384
 zss_editor.setBackgroundColor = function(color) {
386
 zss_editor.setBackgroundColor = function(color) {
385
-    zss_editor.restorerange();
387
+    
388
+    if(zss_editor.currentSelection) {
389
+        zss_editor.restorerange();
390
+    }
386
     document.execCommand("styleWithCSS", null, true);
391
     document.execCommand("styleWithCSS", null, true);
387
     document.execCommand('hiliteColor', false, color);
392
     document.execCommand('hiliteColor', false, color);
388
     document.execCommand("styleWithCSS", null, false);
393
     document.execCommand("styleWithCSS", null, false);

+ 3
- 1
src/const.js View File

39
   setContentFocusHandler: 'SET_CONTENT_FOCUS_HANDLER',
39
   setContentFocusHandler: 'SET_CONTENT_FOCUS_HANDLER',
40
   prepareInsert: 'PREPARE_INSERT',
40
   prepareInsert: 'PREPARE_INSERT',
41
   restoreSelection: 'RESTORE_SELECTION',
41
   restoreSelection: 'RESTORE_SELECTION',
42
-  setCustomCSS: 'SET_CUSTOM_CSS'
42
+  setCustomCSS: 'SET_CUSTOM_CSS',
43
+  setTextColor: 'SET_TEXT_COLOR',
44
+  setBackgroundColor: 'SET_BACKGROUND_COLOR'
43
 };
45
 };
44
 
46
 
45
 
47