Fix timestamp button for CKEditor

This commit is contained in:
nathangray 2017-09-27 10:16:27 -06:00
parent 285eb8494b
commit 9f4f62c7aa

View File

@ -68,7 +68,7 @@ var et2_timestamper = (function(){ "use strict"; return et2_button.extend([],
}, },
_insert_text: function() { _insert_text: function() {
var text = ""; var text = "\n";
var now = new Date(); var now = new Date();
text += date(egw.preference('dateformat') + ' ' + (egw.preference("timeformat") === "12" ? "h:ia" : "H:i")+' ',now); text += date(egw.preference('dateformat') + ' ' + (egw.preference("timeformat") === "12" ? "h:ia" : "H:i")+' ',now);
@ -91,6 +91,7 @@ var et2_timestamper = (function(){ "use strict"; return et2_button.extend([],
"standards" : (document.selection ? "ie" : false ) ); "standards" : (document.selection ? "ie" : false ) );
var pos = 0; var pos = 0;
var CK = CKEDITOR && CKEDITOR.instances[input.id] || false;
// Find cursor or selection // Find cursor or selection
if (browser == "ie") if (browser == "ie")
@ -105,36 +106,37 @@ var et2_timestamper = (function(){ "use strict"; return et2_button.extend([],
pos = input.selectionStart; pos = input.selectionStart;
}; };
// Insert the text
var front = (input.value).substring(0, pos);
var back = (input.value).substring(pos, input.value.length);
input.value = front+text+back;
// If CKEDitor, update it // If CKEDitor, update it
if(CKEDITOR && CKEDITOR.instances[input.id]) if(CKEDITOR && CKEDITOR.instances[input.id])
{ {
CKEDITOR.instances[input.id].insertText(text);
window.setTimeout(function() { window.setTimeout(function() {
CKEDITOR.instances[input.id].focus(); CKEDITOR.instances[input.id].focus();
}, 10); }, 10);
} }
else else
{ {
// Clean up a little // Insert the text
pos = pos + text.length; var front = (input.value).substring(0, pos);
if (browser == "ie") { var back = (input.value).substring(pos, input.value.length);
input.focus(); input.value = front+text+back;
var range = document.selection.createRange();
range.moveStart ("character", -input.value.length); // Clean up a little
range.moveStart ("character", pos); pos = pos + text.length;
range.moveEnd ("character", 0); if (browser == "ie") {
range.select(); input.focus();
} var range = document.selection.createRange();
else if (browser == "standards") { range.moveStart ("character", -input.value.length);
input.selectionStart = pos; range.moveStart ("character", pos);
input.selectionEnd = pos; range.moveEnd ("character", 0);
input.focus(); range.select();
} }
input.scrollTop = scrollPos; else if (browser == "standards") {
input.selectionStart = pos;
input.selectionEnd = pos;
input.focus();
}
input.scrollTop = scrollPos;
} }
}, },