html editor optimizations

This commit is contained in:
RainLoop Team 2014-02-11 20:00:01 +04:00
parent 8d994cf8cc
commit 96b37227b2
13 changed files with 361 additions and 287 deletions

View file

@ -102,8 +102,10 @@ Globals.oHtmlEditorDefaultConfig = {
'allowedContent': false, 'allowedContent': false,
'autoParagraph': false, 'autoParagraph': false,
'enterMode': window.CKEDITOR.ENTER_BR, // 'enterMode': window.CKEDITOR.ENTER_BR,
'shiftEnterMode': window.CKEDITOR.ENTER_P, // 'shiftEnterMode': window.CKEDITOR.ENTER_P,
'enterMode': window.CKEDITOR.ENTER_DIV,
'shiftEnterMode': window.CKEDITOR.ENTER_BR,
// 'floatSpaceDockedOffsetY': 1, // 'floatSpaceDockedOffsetY': 1,
'font_defaultLabel': 'Arial', 'font_defaultLabel': 'Arial',

View file

@ -10,6 +10,7 @@ function HtmlEditorWrapper(oElement, fOnBlur, fOnReady)
var self = this; var self = this;
self.editor = null; self.editor = null;
self.bHtml = true; self.bHtml = true;
self.bPlainDirty = false; self.bPlainDirty = false;
self.iBlurTimer = 0; self.iBlurTimer = 0;
@ -193,26 +194,11 @@ HtmlEditorWrapper.prototype.plainToHtml = function (sPlain)
.replace(/\r/g, '').replace(/\n/g, '<br />'); .replace(/\r/g, '').replace(/\n/g, '<br />');
}; };
HtmlEditorWrapper.prototype.fullScreenToggle = function ()
{
$('html').toggleClass('html-editor-wrapper-fullscreen');
$('body').toggleClass('html-editor-wrapper-fullscreen');
this.focus();
};
HtmlEditorWrapper.prototype.initToolbar = function () HtmlEditorWrapper.prototype.initToolbar = function ()
{ {
var self = this; var self = this;
// self.$fullscreen = $('<a tabindex="-1" href="jav' + 'ascript:void(0);">fullscreen</a>') self.$mode = $('<a tabindex="-1" href="jav' + 'ascript:v' + 'oid(0);"></a>')
// .addClass('html-editor-wrapper-fullscreen-button')
// .on('click', function () {
// self.fullScreenToggle();
// })
// ;
self.$mode = $('<a tabindex="-1" href="jav' + 'ascript:void(0);">html</a>')
.addClass('html-editor-wrapper-mode-button') .addClass('html-editor-wrapper-mode-button')
.on('click', function () { .on('click', function () {
self.modeToggle(true); self.modeToggle(true);
@ -221,7 +207,6 @@ HtmlEditorWrapper.prototype.initToolbar = function ()
self.$toolbar self.$toolbar
.append(self.$mode) .append(self.$mode)
// .append(self.$fullscreen)
; ;
}; };
@ -318,15 +303,20 @@ HtmlEditorWrapper.prototype.init = function ()
.hide() .hide()
; ;
// self.$html = $('<div></div>')
// .addClass('html-editor-wrapper-html')
// .attr('contenteditable', 'true')
// .on('blur', function() {
// self.blurTrigger();
// })
// .on('focus', function() {
// self.focusTrigger();
// })
// .hide()
// ;
self.$html = $('<div></div>') self.$html = $('<div></div>')
.addClass('html-editor-wrapper-html') .addClass('html-editor-wrapper-html')
.attr('contenteditable', 'true') .attr('contenteditable', 'true')
.on('blur', function() {
self.blurTrigger();
})
.on('focus', function() {
self.focusTrigger();
})
.hide() .hide()
; ;
@ -350,7 +340,15 @@ HtmlEditorWrapper.prototype.init = function ()
} }
oConfig.language = Globals.oHtmlEditorLangsMap[sLanguage] || 'en'; oConfig.language = Globals.oHtmlEditorLangsMap[sLanguage] || 'en';
// self.editor = window.CKEDITOR.appendTo(self.$html[0], oConfig);
self.editor = window.CKEDITOR.inline(self.$html[0], oConfig); self.editor = window.CKEDITOR.inline(self.$html[0], oConfig);
self.editor.on('blur', function() {
self.blurTrigger();
});
self.editor.on('focus', function() {
self.focusTrigger();
});
if (self.fOnReady) if (self.fOnReady)
{ {
@ -364,10 +362,25 @@ HtmlEditorWrapper.prototype.init = function ()
} }
}; };
HtmlEditorWrapper.prototype.toolbarReposition = function ()
{
if (this.bHtml && this.editor && this.editor.focusManager.hasFocus)
{
var oEd = this.editor;
oEd.focusManager.blur(true);
_.delay(function () {
oEd.focusManager.focus();
}, 1);
}
};
HtmlEditorWrapper.prototype.focus = function () HtmlEditorWrapper.prototype.focus = function ()
{ {
if (this.bHtml) { if (this.bHtml) {
this.$html.focus(); if (this.editor) {
this.editor.focusManager.focus();
}
} else { } else {
this.$plain.focus(); this.$plain.focus();
} }
@ -376,7 +389,9 @@ HtmlEditorWrapper.prototype.focus = function ()
HtmlEditorWrapper.prototype.blur = function () HtmlEditorWrapper.prototype.blur = function ()
{ {
if (this.bHtml) { if (this.bHtml) {
this.$html.blur(); if (this.editor) {
this.editor.focusManager.blur(true);
}
} else { } else {
this.$plain.blur(); this.$plain.blur();
} }
@ -400,27 +415,29 @@ HtmlEditorWrapper.prototype.modeToggle = function (bFocus)
this.blur(); this.blur();
} }
if (this.bHtml) { if (this.editor)
{
if (this.bHtml)
{
this.$html.hide(); this.$html.hide();
this.$plain.show();
this.$plain this.$plain.val(this.htmlToPlain(this.editor.getData()));
.val(this.htmlToPlain(this.$html.html()))
.show()
;
this.bHtml = false; this.bHtml = false;
this.bPlainDirty = true; this.bPlainDirty = true;
} else { }
else
{
this.$plain.hide(); this.$plain.hide();
this.$html.show();
this.$html this.editor.setData(this.plainToHtml(this.$plain.val()));
.html(this.plainToHtml(this.$plain.val()))
.show()
;
this.bHtml = true; this.bHtml = true;
this.bPlainDirty = true; this.bPlainDirty = true;
} }
}
this.setModeButtonText(); this.setModeButtonText();

View file

@ -7,6 +7,8 @@ function SettingsIdentities()
{ {
var oData = RL.data(); var oData = RL.data();
this.editor = null;
this.displayName = oData.displayName; this.displayName = oData.displayName;
this.signature = oData.signature; this.signature = oData.signature;
this.signatureToAll = oData.signatureToAll; this.signatureToAll = oData.signatureToAll;

View file

@ -7,6 +7,8 @@ function SettingsIdentity()
{ {
var oData = RL.data(); var oData = RL.data();
this.editor = null;
this.displayName = oData.displayName; this.displayName = oData.displayName;
this.signature = oData.signature; this.signature = oData.signature;
this.signatureToAll = oData.signatureToAll; this.signatureToAll = oData.signatureToAll;

View file

@ -77,7 +77,9 @@ html.html-editor-wrapper-fullscreen .html-editor-wrapper-html.styled, html.html-
border-radius: 0; border-radius: 0;
} }
.html-editor-wrapper-html.styled:focus, .html-editor-wrapper-plain.styled:focus { .html-editor-wrapper-html.styled:focus, .html-editor-wrapper-plain.styled:focus,
.html-editor-wrapper-html.styled.focused, .html-editor-wrapper-plain.styled.focused
{
border: 1px solid #999999; border: 1px solid #999999;
-webkit-box-shadow: none; -webkit-box-shadow: none;
@ -108,13 +110,17 @@ html.html-editor-wrapper-fullscreen .html-editor-wrapper-html.styled, html.html-
.html-editor-wrapper-mode-button, .html-editor-wrapper-fullscreen-button { .html-editor-wrapper-mode-button, .html-editor-wrapper-fullscreen-button {
position: absolute; position: absolute;
top: 5px; bottom: 5px;
right: 25px; right: 25px;
z-index: 100; z-index: 100;
color: #555; color: #555;
text-decoration: underline; text-decoration: underline;
font-family: Arial,Helvetica,Tahoma,Verdana,Sans-Serif; font-family: Arial,Helvetica,Tahoma,Verdana,Sans-Serif;
font-size: 12px; font-size: 12px;
background-color: #fff;
/*background-color: rgba(255, 255, 255, 0.8);*/
padding: 1px 3px;
} }
.html-editor-wrapper-mode-button:hover, .html-editor-wrapper-fullscreen-button:hover { .html-editor-wrapper-mode-button:hover, .html-editor-wrapper-fullscreen-button:hover {

View file

@ -156,6 +156,13 @@ function PopupsComposeViewModel()
} }
}, this); }, this);
this.emptyToError.subscribe(function (bValue) {
if (this.oEditor && bValue)
{
this.oEditor.toolbarReposition();
}
}, this);
this.canBeSended = ko.computed(function () { this.canBeSended = ko.computed(function () {
return !this.sending() && return !this.sending() &&
!this.saving() && !this.saving() &&

View file

@ -8628,7 +8628,9 @@ html.html-editor-wrapper-fullscreen .html-editor-wrapper-plain.styled {
border-radius: 0; border-radius: 0;
} }
.html-editor-wrapper-html.styled:focus, .html-editor-wrapper-html.styled:focus,
.html-editor-wrapper-plain.styled:focus { .html-editor-wrapper-plain.styled:focus,
.html-editor-wrapper-html.styled.focused,
.html-editor-wrapper-plain.styled.focused {
border: 1px solid #999999; border: 1px solid #999999;
-webkit-box-shadow: none; -webkit-box-shadow: none;
-moz-box-shadow: none; -moz-box-shadow: none;
@ -8655,13 +8657,17 @@ html.html-editor-wrapper-fullscreen .html-editor-wrapper-plain.styled {
.html-editor-wrapper-mode-button, .html-editor-wrapper-mode-button,
.html-editor-wrapper-fullscreen-button { .html-editor-wrapper-fullscreen-button {
position: absolute; position: absolute;
top: 5px; bottom: 5px;
right: 25px; right: 25px;
z-index: 100; z-index: 100;
color: #555; color: #555;
text-decoration: underline; text-decoration: underline;
font-family: Arial, Helvetica, Tahoma, Verdana, Sans-Serif; font-family: Arial, Helvetica, Tahoma, Verdana, Sans-Serif;
font-size: 12px; font-size: 12px;
background-color: #fff;
/*background-color: rgba(255, 255, 255, 0.8);*/
padding: 1px 3px;
} }
.html-editor-wrapper-mode-button:hover, .html-editor-wrapper-mode-button:hover,
.html-editor-wrapper-fullscreen-button:hover { .html-editor-wrapper-fullscreen-button:hover {

File diff suppressed because one or more lines are too long

View file

@ -180,8 +180,10 @@ Globals.oHtmlEditorDefaultConfig = {
'allowedContent': false, 'allowedContent': false,
'autoParagraph': false, 'autoParagraph': false,
'enterMode': window.CKEDITOR.ENTER_BR, // 'enterMode': window.CKEDITOR.ENTER_BR,
'shiftEnterMode': window.CKEDITOR.ENTER_P, // 'shiftEnterMode': window.CKEDITOR.ENTER_P,
'enterMode': window.CKEDITOR.ENTER_DIV,
'shiftEnterMode': window.CKEDITOR.ENTER_BR,
// 'floatSpaceDockedOffsetY': 1, // 'floatSpaceDockedOffsetY': 1,
'font_defaultLabel': 'Arial', 'font_defaultLabel': 'Arial',

File diff suppressed because one or more lines are too long

View file

@ -180,8 +180,10 @@ Globals.oHtmlEditorDefaultConfig = {
'allowedContent': false, 'allowedContent': false,
'autoParagraph': false, 'autoParagraph': false,
'enterMode': window.CKEDITOR.ENTER_BR, // 'enterMode': window.CKEDITOR.ENTER_BR,
'shiftEnterMode': window.CKEDITOR.ENTER_P, // 'shiftEnterMode': window.CKEDITOR.ENTER_P,
'enterMode': window.CKEDITOR.ENTER_DIV,
'shiftEnterMode': window.CKEDITOR.ENTER_BR,
// 'floatSpaceDockedOffsetY': 1, // 'floatSpaceDockedOffsetY': 1,
'font_defaultLabel': 'Arial', 'font_defaultLabel': 'Arial',
@ -3445,6 +3447,7 @@ function HtmlEditorWrapper(oElement, fOnBlur, fOnReady)
var self = this; var self = this;
self.editor = null; self.editor = null;
self.bHtml = true; self.bHtml = true;
self.bPlainDirty = false; self.bPlainDirty = false;
self.iBlurTimer = 0; self.iBlurTimer = 0;
@ -3628,26 +3631,11 @@ HtmlEditorWrapper.prototype.plainToHtml = function (sPlain)
.replace(/\r/g, '').replace(/\n/g, '<br />'); .replace(/\r/g, '').replace(/\n/g, '<br />');
}; };
HtmlEditorWrapper.prototype.fullScreenToggle = function ()
{
$('html').toggleClass('html-editor-wrapper-fullscreen');
$('body').toggleClass('html-editor-wrapper-fullscreen');
this.focus();
};
HtmlEditorWrapper.prototype.initToolbar = function () HtmlEditorWrapper.prototype.initToolbar = function ()
{ {
var self = this; var self = this;
// self.$fullscreen = $('<a tabindex="-1" href="jav' + 'ascript:void(0);">fullscreen</a>') self.$mode = $('<a tabindex="-1" href="jav' + 'ascript:v' + 'oid(0);"></a>')
// .addClass('html-editor-wrapper-fullscreen-button')
// .on('click', function () {
// self.fullScreenToggle();
// })
// ;
self.$mode = $('<a tabindex="-1" href="jav' + 'ascript:void(0);">html</a>')
.addClass('html-editor-wrapper-mode-button') .addClass('html-editor-wrapper-mode-button')
.on('click', function () { .on('click', function () {
self.modeToggle(true); self.modeToggle(true);
@ -3656,7 +3644,6 @@ HtmlEditorWrapper.prototype.initToolbar = function ()
self.$toolbar self.$toolbar
.append(self.$mode) .append(self.$mode)
// .append(self.$fullscreen)
; ;
}; };
@ -3753,15 +3740,20 @@ HtmlEditorWrapper.prototype.init = function ()
.hide() .hide()
; ;
// self.$html = $('<div></div>')
// .addClass('html-editor-wrapper-html')
// .attr('contenteditable', 'true')
// .on('blur', function() {
// self.blurTrigger();
// })
// .on('focus', function() {
// self.focusTrigger();
// })
// .hide()
// ;
self.$html = $('<div></div>') self.$html = $('<div></div>')
.addClass('html-editor-wrapper-html') .addClass('html-editor-wrapper-html')
.attr('contenteditable', 'true') .attr('contenteditable', 'true')
.on('blur', function() {
self.blurTrigger();
})
.on('focus', function() {
self.focusTrigger();
})
.hide() .hide()
; ;
@ -3785,7 +3777,15 @@ HtmlEditorWrapper.prototype.init = function ()
} }
oConfig.language = Globals.oHtmlEditorLangsMap[sLanguage] || 'en'; oConfig.language = Globals.oHtmlEditorLangsMap[sLanguage] || 'en';
// self.editor = window.CKEDITOR.appendTo(self.$html[0], oConfig);
self.editor = window.CKEDITOR.inline(self.$html[0], oConfig); self.editor = window.CKEDITOR.inline(self.$html[0], oConfig);
self.editor.on('blur', function() {
self.blurTrigger();
});
self.editor.on('focus', function() {
self.focusTrigger();
});
if (self.fOnReady) if (self.fOnReady)
{ {
@ -3799,10 +3799,25 @@ HtmlEditorWrapper.prototype.init = function ()
} }
}; };
HtmlEditorWrapper.prototype.toolbarReposition = function ()
{
if (this.bHtml && this.editor && this.editor.focusManager.hasFocus)
{
var oEd = this.editor;
oEd.focusManager.blur(true);
_.delay(function () {
oEd.focusManager.focus();
}, 1);
}
};
HtmlEditorWrapper.prototype.focus = function () HtmlEditorWrapper.prototype.focus = function ()
{ {
if (this.bHtml) { if (this.bHtml) {
this.$html.focus(); if (this.editor) {
this.editor.focusManager.focus();
}
} else { } else {
this.$plain.focus(); this.$plain.focus();
} }
@ -3811,7 +3826,9 @@ HtmlEditorWrapper.prototype.focus = function ()
HtmlEditorWrapper.prototype.blur = function () HtmlEditorWrapper.prototype.blur = function ()
{ {
if (this.bHtml) { if (this.bHtml) {
this.$html.blur(); if (this.editor) {
this.editor.focusManager.blur(true);
}
} else { } else {
this.$plain.blur(); this.$plain.blur();
} }
@ -3835,27 +3852,29 @@ HtmlEditorWrapper.prototype.modeToggle = function (bFocus)
this.blur(); this.blur();
} }
if (this.bHtml) { if (this.editor)
{
if (this.bHtml)
{
this.$html.hide(); this.$html.hide();
this.$plain.show();
this.$plain this.$plain.val(this.htmlToPlain(this.editor.getData()));
.val(this.htmlToPlain(this.$html.html()))
.show()
;
this.bHtml = false; this.bHtml = false;
this.bPlainDirty = true; this.bPlainDirty = true;
} else { }
else
{
this.$plain.hide(); this.$plain.hide();
this.$html.show();
this.$html this.editor.setData(this.plainToHtml(this.$plain.val()));
.html(this.plainToHtml(this.$plain.val()))
.show()
;
this.bHtml = true; this.bHtml = true;
this.bPlainDirty = true; this.bPlainDirty = true;
} }
}
this.setModeButtonText(); this.setModeButtonText();
@ -7818,6 +7837,13 @@ function PopupsComposeViewModel()
} }
}, this); }, this);
this.emptyToError.subscribe(function (bValue) {
if (this.oEditor && bValue)
{
this.oEditor.toolbarReposition();
}
}, this);
this.canBeSended = ko.computed(function () { this.canBeSended = ko.computed(function () {
return !this.sending() && return !this.sending() &&
!this.saving() && !this.saving() &&
@ -12613,6 +12639,8 @@ function SettingsIdentity()
{ {
var oData = RL.data(); var oData = RL.data();
this.editor = null;
this.displayName = oData.displayName; this.displayName = oData.displayName;
this.signature = oData.signature; this.signature = oData.signature;
this.signatureToAll = oData.signatureToAll; this.signatureToAll = oData.signatureToAll;
@ -12716,6 +12744,8 @@ function SettingsIdentities()
{ {
var oData = RL.data(); var oData = RL.data();
this.editor = null;
this.displayName = oData.displayName; this.displayName = oData.displayName;
this.signature = oData.signature; this.signature = oData.signature;
this.signatureToAll = oData.signatureToAll; this.signatureToAll = oData.signatureToAll;

File diff suppressed because one or more lines are too long