mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 12:09:20 +03:00
Html editor improvements (new toolbar type)
This commit is contained in:
parent
96b37227b2
commit
8da34e8d5f
105 changed files with 1423 additions and 1545 deletions
203
dev/Common/NewHtmlEditorWrapper.js
Normal file
203
dev/Common/NewHtmlEditorWrapper.js
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object} oElement
|
||||
* @param {Function=} fOnBlur
|
||||
* @param {Function=} fOnReady
|
||||
*/
|
||||
function NewHtmlEditorWrapper(oElement, fOnBlur, fOnReady)
|
||||
{
|
||||
var self = this;
|
||||
self.editor = null;
|
||||
self.iBlurTimer = 0;
|
||||
self.fOnBlur = fOnBlur || null;
|
||||
self.fOnReady = fOnReady || null;
|
||||
|
||||
self.$element = $(oElement);
|
||||
|
||||
self.init();
|
||||
}
|
||||
|
||||
NewHtmlEditorWrapper.prototype.blurTrigger = function ()
|
||||
{
|
||||
if (this.fOnBlur)
|
||||
{
|
||||
var self = this;
|
||||
window.clearTimeout(self.iBlurTimer);
|
||||
self.iBlurTimer = window.setTimeout(function () {
|
||||
self.fOnBlur();
|
||||
}, 200);
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.focusTrigger = function ()
|
||||
{
|
||||
if (this.fOnBlur)
|
||||
{
|
||||
window.clearTimeout(this.iBlurTimer);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
NewHtmlEditorWrapper.prototype.isHtml = function ()
|
||||
{
|
||||
window.console.log(this.editor.mode);
|
||||
return this.editor ? 'wysiwyg' === this.editor.mode : false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
NewHtmlEditorWrapper.prototype.checkDirty = function ()
|
||||
{
|
||||
return this.editor ? this.editor.checkDirty() : false;
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.resetDirty = function ()
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
this.editor.resetDirty();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
NewHtmlEditorWrapper.prototype.getData = function ()
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
if ('plain' === this.editor.mode && this.editor.plugins.plain && this.editor.__plain)
|
||||
{
|
||||
return this.editor.__plain.getRawData();
|
||||
}
|
||||
|
||||
return this.editor.getData();
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.modeToggle = function (bPlain)
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
if (bPlain)
|
||||
{
|
||||
if ('plain' === this.editor.mode)
|
||||
{
|
||||
this.editor.setMode('wysiwyg');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ('wysiwyg' === this.editor.mode)
|
||||
{
|
||||
this.editor.setMode('plain');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.setHtml = function (sHtml, bFocus)
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
this.modeToggle(true);
|
||||
this.editor.setData(sHtml);
|
||||
|
||||
if (bFocus)
|
||||
{
|
||||
this.focus();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.setPlain = function (sPlain, bFocus)
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
this.modeToggle(false);
|
||||
this.editor.setData(sPlain);
|
||||
|
||||
if (bFocus)
|
||||
{
|
||||
this.focus();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.init = function ()
|
||||
{
|
||||
if (this.$element && this.$element[0])
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
oConfig = Globals.oHtmlEditorDefaultConfig,
|
||||
sLanguage = RL.settingsGet('Language'),
|
||||
bSource = !!RL.settingsGet('AllowHtmlEditorSourceButton')
|
||||
;
|
||||
|
||||
if (bSource && oConfig.toolbarGroups && !oConfig.toolbarGroups.__SourceInited)
|
||||
{
|
||||
oConfig.toolbarGroups.__SourceInited = true;
|
||||
oConfig.toolbarGroups.push({name: 'document', groups: ['mode', 'document', 'doctools']});
|
||||
}
|
||||
|
||||
oConfig.language = Globals.oHtmlEditorLangsMap[sLanguage] || 'en';
|
||||
self.editor = window.CKEDITOR.appendTo(self.$element[0], oConfig);
|
||||
|
||||
self.editor.on('blur', function() {
|
||||
self.blurTrigger();
|
||||
});
|
||||
|
||||
self.editor.on('mode', function() {
|
||||
self.blurTrigger();
|
||||
});
|
||||
|
||||
self.editor.on('focus', function() {
|
||||
self.focusTrigger();
|
||||
});
|
||||
|
||||
if (self.fOnReady)
|
||||
{
|
||||
self.editor.on('instanceReady', function () {
|
||||
self.fOnReady();
|
||||
self.resize();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.focus = function ()
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
this.editor.focusManager.focus();
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.blur = function ()
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
this.editor.focusManager.blur(true);
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.resize = function ()
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
this.editor.resize(this.$element.width(), this.$element.innerHeight());
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.clear = function (bFocus)
|
||||
{
|
||||
this.setHtml('', bFocus);
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue