|
@@ -36,23 +36,41 @@ zss_editor.updateScrollOffset = false;
|
36
|
36
|
/**
|
37
|
37
|
* The initializer function that must be called onLoad
|
38
|
38
|
*/
|
39
|
|
-zss_editor.init = function() {
|
40
|
39
|
|
|
40
|
+function setupTouchEndEnableEditing(editorId) {
|
|
41
|
+ $(`#${editorId}`).on('touchend', function(e) {
|
|
42
|
+ zss_editor.enabledEditingItems(e);
|
|
43
|
+ var clicked = $(e.target);
|
|
44
|
+ if (!clicked.hasClass('zs_active')) {
|
|
45
|
+ $('img').removeClass('zs_active');
|
|
46
|
+ }
|
|
47
|
+ });
|
|
48
|
+}
|
41
|
49
|
|
42
|
|
- $('#zss_editor_content').on('touchend', function(e) {
|
43
|
|
- zss_editor.enabledEditingItems(e);
|
44
|
|
- var clicked = $(e.target);
|
45
|
|
- if (!clicked.hasClass('zs_active')) {
|
46
|
|
- $('img').removeClass('zs_active');
|
47
|
|
- }
|
48
|
|
- });
|
49
|
|
-
|
|
50
|
+function setupSelectionChange(editorId) {
|
50
|
51
|
$(document).on('selectionchange',function(e){
|
51
|
|
- zss_editor.calculateEditorHeightWithCaretPosition();
|
52
|
|
- zss_editor.setScrollPosition();
|
53
|
|
- zss_editor.enabledEditingItems(e);
|
54
|
|
- });
|
55
|
|
-
|
|
52
|
+ zss_editor.calculateEditorHeightWithCaretPosition(editorId);
|
|
53
|
+ zss_editor.setScrollPosition();
|
|
54
|
+ zss_editor.enabledEditingItems(e);
|
|
55
|
+ });
|
|
56
|
+}
|
|
57
|
+
|
|
58
|
+function setupTouchEndFocus(editorId) {
|
|
59
|
+ $(window).on('touchend', function(e) {
|
|
60
|
+ if (!zss_editor.isDragging && (e.target.id == "zss_editor_footer"||e.target.nodeName.toLowerCase() == "html")) {
|
|
61
|
+ zss_editor.focusEditor(editorId);
|
|
62
|
+ }
|
|
63
|
+ });
|
|
64
|
+}
|
|
65
|
+
|
|
66
|
+zss_editor.init = function() {
|
|
67
|
+
|
|
68
|
+ setupTouchEndEnableEditing('zss_editor_title');
|
|
69
|
+ setupTouchEndEnableEditing('zss_editor_content');
|
|
70
|
+
|
|
71
|
+ setupSelectionChange('zss_editor_title');
|
|
72
|
+ setupSelectionChange('zss_editor_content');
|
|
73
|
+
|
56
|
74
|
$(window).on('scroll', function(e) {
|
57
|
75
|
zss_editor.updateOffset();
|
58
|
76
|
});
|
|
@@ -67,12 +85,9 @@ zss_editor.init = function() {
|
67
|
85
|
$(window).on('touchstart', function(e) {
|
68
|
86
|
zss_editor.isDragging = false;
|
69
|
87
|
});
|
70
|
|
- $(window).on('touchend', function(e) {
|
71
|
|
- if (!zss_editor.isDragging && (e.target.id == "zss_editor_footer"||e.target.nodeName.toLowerCase() == "html")) {
|
72
|
|
- zss_editor.focusEditor();
|
73
|
|
- }
|
74
|
|
- });
|
75
|
88
|
|
|
89
|
+ setupTouchEndFocus('zss_editor_title');
|
|
90
|
+ setupTouchEndFocus('zss_editor_content');
|
76
|
91
|
|
77
|
92
|
setTimeout(function() {
|
78
|
93
|
WebViewBridge.send(JSON.stringify({type: 'ZSS_INITIALIZED'}))
|
|
@@ -113,24 +128,27 @@ zss_editor.setScrollPosition = function() {
|
113
|
128
|
WebViewBridge.send(JSON.stringify({type: 'SCROLL', data: position}));
|
114
|
129
|
}
|
115
|
130
|
|
116
|
|
-
|
117
|
|
-zss_editor.setPlaceholder = function(placeholder) {
|
118
|
|
-
|
119
|
|
- var editor = $('#zss_editor_content');
|
|
131
|
+function setPlaceholder(editorId, placeholder) {
|
|
132
|
+ var editor = $(`#${editorId}`);
|
120
|
133
|
|
121
|
134
|
//set placeHolder
|
122
|
|
- editor.attr("placeholder",placeholder);
|
|
135
|
+ editor.attr("placeholder",placeholder);
|
123
|
136
|
|
124
|
137
|
//set focus
|
125
|
|
- editor.focusout(function(){
|
126
|
|
- var element = $(this);
|
|
138
|
+ editor.focusout(function(){
|
|
139
|
+ var element = $(this);
|
127
|
140
|
if (!element.text().trim().length) {
|
128
|
141
|
element.empty();
|
129
|
142
|
}
|
130
|
143
|
});
|
131
|
|
-
|
132
|
|
-
|
133
|
|
-
|
|
144
|
+}
|
|
145
|
+
|
|
146
|
+zss_editor.setTitlePlaceholder = function(placeholder) {
|
|
147
|
+ setPlaceholder('zss_editor_title', placeholder);
|
|
148
|
+}
|
|
149
|
+
|
|
150
|
+zss_editor.setContentPlaceholder = function(placeholder) {
|
|
151
|
+ setPlaceholder('zss_editor_content', placeholder);
|
134
|
152
|
}
|
135
|
153
|
|
136
|
154
|
zss_editor.setFooterHeight = function(footerHeight) {
|
|
@@ -151,13 +169,13 @@ zss_editor.getCaretYPosition = function() {
|
151
|
169
|
return topPosition;
|
152
|
170
|
}
|
153
|
171
|
|
154
|
|
-zss_editor.calculateEditorHeightWithCaretPosition = function() {
|
|
172
|
+zss_editor.calculateEditorHeightWithCaretPosition = function(editorId) {
|
155
|
173
|
|
156
|
174
|
var padding = 50;
|
157
|
175
|
var c = zss_editor.getCaretYPosition();
|
158
|
|
- var e = document.getElementById('zss_editor_content');
|
|
176
|
+ var e = document.getElementById(editorId);
|
159
|
177
|
|
160
|
|
- var editor = $('#zss_editor_content');
|
|
178
|
+ var editor = $(`#${editorId}`);
|
161
|
179
|
|
162
|
180
|
var offsetY = window.document.body.scrollTop;
|
163
|
181
|
var height = zss_editor.contentHeight;
|
|
@@ -488,54 +506,73 @@ zss_editor.insertImageBase64String = function(imageBase64String, alt) {
|
488
|
506
|
zss_editor.enabledEditingItems();
|
489
|
507
|
}
|
490
|
508
|
|
491
|
|
-zss_editor.setHTML = function(html) {
|
492
|
|
- var editor = $('#zss_editor_content');
|
|
509
|
+function setHTML(editorId, html) {
|
|
510
|
+ var editor = $(`#${editorId}`);
|
493
|
511
|
editor.html(html);
|
494
|
512
|
}
|
495
|
513
|
|
|
514
|
+zss_editor.setTitleHTML = function(html) {
|
|
515
|
+ setHTML('zss_editor_title', html);
|
|
516
|
+}
|
|
517
|
+
|
|
518
|
+zss_editor.setContentHTML = function(html) {
|
|
519
|
+ setHTML('zss_editor_content', html);
|
|
520
|
+}
|
|
521
|
+
|
496
|
522
|
zss_editor.insertHTML = function(html) {
|
497
|
523
|
document.execCommand('insertHTML', false, html);
|
498
|
524
|
zss_editor.enabledEditingItems();
|
499
|
525
|
}
|
500
|
526
|
|
501
|
|
-zss_editor.getHTML = function() {
|
502
|
|
-
|
|
527
|
+function getHtml(editorId) {
|
503
|
528
|
// Images
|
504
|
529
|
var img = $('img');
|
505
|
530
|
if (img.length != 0) {
|
506
|
531
|
$('img').removeClass('zs_active');
|
507
|
532
|
$('img').each(function(index, e) {
|
508
|
|
- var image = $(this);
|
509
|
|
- var zs_class = image.attr('class');
|
510
|
|
- if (typeof(zs_class) != "undefined") {
|
511
|
|
- if (zs_class == '') {
|
512
|
|
- image.removeAttr('class');
|
513
|
|
- }
|
514
|
|
- }
|
515
|
|
- });
|
|
533
|
+ var image = $(this);
|
|
534
|
+ var zs_class = image.attr('class');
|
|
535
|
+ if (typeof(zs_class) != "undefined") {
|
|
536
|
+ if (zs_class == '') {
|
|
537
|
+ image.removeAttr('class');
|
|
538
|
+ }
|
|
539
|
+ }
|
|
540
|
+ });
|
516
|
541
|
}
|
517
|
|
-
|
|
542
|
+
|
518
|
543
|
// Blockquote
|
519
|
544
|
var bq = $('blockquote');
|
520
|
545
|
if (bq.length != 0) {
|
521
|
546
|
bq.each(function() {
|
522
|
|
- var b = $(this);
|
523
|
|
- if (b.css('border').indexOf('none') != -1) {
|
|
547
|
+ var b = $(this);
|
|
548
|
+ if (b.css('border').indexOf('none') != -1) {
|
524
|
549
|
b.css({'border': ''});
|
525
|
|
- }
|
526
|
|
- if (b.css('padding').indexOf('0px') != -1) {
|
|
550
|
+ }
|
|
551
|
+ if (b.css('padding').indexOf('0px') != -1) {
|
527
|
552
|
b.css({'padding': ''});
|
528
|
|
- }
|
529
|
|
- });
|
|
553
|
+ }
|
|
554
|
+ });
|
530
|
555
|
}
|
531
|
|
-
|
|
556
|
+
|
532
|
557
|
// Get the contents
|
533
|
|
- var h = document.getElementById("zss_editor_content").innerHTML;
|
534
|
|
-
|
|
558
|
+ var h = document.getElementById(editorId).innerHTML;
|
|
559
|
+
|
535
|
560
|
return h;
|
536
|
561
|
}
|
537
|
562
|
|
538
|
|
-zss_editor.getText = function() {
|
|
563
|
+zss_editor.getTitleHTML = function() {
|
|
564
|
+ return getHtml("zss_editor_title");
|
|
565
|
+}
|
|
566
|
+
|
|
567
|
+zss_editor.getContentHTML = function() {
|
|
568
|
+ return getHtml("zss_editor_content");
|
|
569
|
+}
|
|
570
|
+
|
|
571
|
+zss_editor.getTitleText = function() {
|
|
572
|
+ return $('#zss_editor_title').text();
|
|
573
|
+}
|
|
574
|
+
|
|
575
|
+zss_editor.getContentText = function() {
|
539
|
576
|
return $('#zss_editor_content').text();
|
540
|
577
|
}
|
541
|
578
|
|
|
@@ -658,11 +695,11 @@ zss_editor.enabledEditingItems = function(e) {
|
658
|
695
|
}
|
659
|
696
|
}
|
660
|
697
|
|
661
|
|
-zss_editor.focusEditor = function() {
|
|
698
|
+zss_editor.focusEditor = function(editorId) {
|
662
|
699
|
|
663
|
700
|
// the following was taken from http://stackoverflow.com/questions/1125292/how-to-move-cursor-to-end-of-contenteditable-entity/3866442#3866442
|
664
|
701
|
// and ensures we move the cursor to the end of the editor
|
665
|
|
- var editor = $('#zss_editor_content');
|
|
702
|
+ var editor = $(`#${editorId}`);
|
666
|
703
|
var range = document.createRange();
|
667
|
704
|
range.selectNodeContents(editor.get(0));
|
668
|
705
|
range.collapse(false);
|
|
@@ -672,7 +709,12 @@ zss_editor.focusEditor = function() {
|
672
|
709
|
editor.focus();
|
673
|
710
|
}
|
674
|
711
|
|
675
|
|
-zss_editor.blurEditor = function() {
|
|
712
|
+
|
|
713
|
+zss_editor.blurTitleEditor = function() {
|
|
714
|
+ $('#zss_editor_title').blur();
|
|
715
|
+}
|
|
716
|
+
|
|
717
|
+zss_editor.blurContentEditor = function() {
|
676
|
718
|
$('#zss_editor_content').blur();
|
677
|
719
|
}
|
678
|
720
|
|