mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 05:29:20 +03:00
CommonJS (research)
This commit is contained in:
parent
2fa2cd191e
commit
56607de87c
91 changed files with 20220 additions and 12933 deletions
|
|
@ -1,260 +1,274 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object} oElement
|
||||
* @param {Function=} fOnBlur
|
||||
* @param {Function=} fOnReady
|
||||
* @param {Function=} fOnModeChange
|
||||
*/
|
||||
function NewHtmlEditorWrapper(oElement, fOnBlur, fOnReady, fOnModeChange)
|
||||
{
|
||||
var self = this;
|
||||
self.editor = null;
|
||||
self.iBlurTimer = 0;
|
||||
self.fOnBlur = fOnBlur || null;
|
||||
self.fOnReady = fOnReady || null;
|
||||
self.fOnModeChange = fOnModeChange || null;
|
||||
(function (module) {
|
||||
|
||||
self.$element = $(oElement);
|
||||
'use strict';
|
||||
|
||||
self.resize = _.throttle(_.bind(self.resize, self), 100);
|
||||
var
|
||||
window = require('../External/window.js'),
|
||||
Globals = require('./Globals.js')
|
||||
;
|
||||
|
||||
self.init();
|
||||
}
|
||||
|
||||
NewHtmlEditorWrapper.prototype.blurTrigger = function ()
|
||||
{
|
||||
if (this.fOnBlur)
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object} oElement
|
||||
* @param {Function=} fOnBlur
|
||||
* @param {Function=} fOnReady
|
||||
* @param {Function=} fOnModeChange
|
||||
*/
|
||||
function NewHtmlEditorWrapper(oElement, fOnBlur, fOnReady, fOnModeChange)
|
||||
{
|
||||
var self = this;
|
||||
window.clearTimeout(self.iBlurTimer);
|
||||
self.iBlurTimer = window.setTimeout(function () {
|
||||
self.fOnBlur();
|
||||
}, 200);
|
||||
self.editor = null;
|
||||
self.iBlurTimer = 0;
|
||||
self.fOnBlur = fOnBlur || null;
|
||||
self.fOnReady = fOnReady || null;
|
||||
self.fOnModeChange = fOnModeChange || null;
|
||||
|
||||
self.$element = $(oElement);
|
||||
|
||||
self.resize = _.throttle(_.bind(self.resize, self), 100);
|
||||
|
||||
self.init();
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.focusTrigger = function ()
|
||||
{
|
||||
if (this.fOnBlur)
|
||||
NewHtmlEditorWrapper.prototype.blurTrigger = function ()
|
||||
{
|
||||
window.clearTimeout(this.iBlurTimer);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
NewHtmlEditorWrapper.prototype.isHtml = function ()
|
||||
{
|
||||
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 (bWrapIsHtml)
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
if ('plain' === this.editor.mode && this.editor.plugins.plain && this.editor.__plain)
|
||||
if (this.fOnBlur)
|
||||
{
|
||||
return this.editor.__plain.getRawData();
|
||||
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 ()
|
||||
{
|
||||
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 (bWrapIsHtml)
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
if ('plain' === this.editor.mode && this.editor.plugins.plain && this.editor.__plain)
|
||||
{
|
||||
return this.editor.__plain.getRawData();
|
||||
}
|
||||
|
||||
return bWrapIsHtml ?
|
||||
'<div data-html-editor-font-wrapper="true" style="font-family: arial, sans-serif; font-size: 13px;">' +
|
||||
this.editor.getData() + '</div>' : this.editor.getData();
|
||||
}
|
||||
|
||||
return bWrapIsHtml ?
|
||||
'<div data-html-editor-font-wrapper="true" style="font-family: arial, sans-serif; font-size: 13px;">' +
|
||||
this.editor.getData() + '</div>' : this.editor.getData();
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.modeToggle = function (bPlain)
|
||||
{
|
||||
if (this.editor)
|
||||
NewHtmlEditorWrapper.prototype.modeToggle = function (bPlain)
|
||||
{
|
||||
if (bPlain)
|
||||
if (this.editor)
|
||||
{
|
||||
if ('plain' === this.editor.mode)
|
||||
if (bPlain)
|
||||
{
|
||||
this.editor.setMode('wysiwyg');
|
||||
if ('plain' === this.editor.mode)
|
||||
{
|
||||
this.editor.setMode('wysiwyg');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ('wysiwyg' === this.editor.mode)
|
||||
{
|
||||
this.editor.setMode('plain');
|
||||
}
|
||||
}
|
||||
|
||||
this.resize();
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.setHtml = function (sHtml, bFocus)
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
this.modeToggle(true);
|
||||
this.editor.setData(sHtml);
|
||||
|
||||
if (bFocus)
|
||||
{
|
||||
this.focus();
|
||||
}
|
||||
}
|
||||
else
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.setPlain = function (sPlain, bFocus)
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
if ('wysiwyg' === this.editor.mode)
|
||||
this.modeToggle(false);
|
||||
if ('plain' === this.editor.mode && this.editor.plugins.plain && this.editor.__plain)
|
||||
{
|
||||
this.editor.setMode('plain');
|
||||
return this.editor.__plain.setRawData(sPlain);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.editor.setData(sPlain);
|
||||
}
|
||||
|
||||
if (bFocus)
|
||||
{
|
||||
this.focus();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.resize();
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.setHtml = function (sHtml, bFocus)
|
||||
{
|
||||
if (this.editor)
|
||||
NewHtmlEditorWrapper.prototype.init = function ()
|
||||
{
|
||||
this.modeToggle(true);
|
||||
this.editor.setData(sHtml);
|
||||
|
||||
if (bFocus)
|
||||
if (this.$element && this.$element[0])
|
||||
{
|
||||
this.focus();
|
||||
}
|
||||
}
|
||||
};
|
||||
var
|
||||
self = this,
|
||||
fInit = function () {
|
||||
|
||||
NewHtmlEditorWrapper.prototype.setPlain = function (sPlain, bFocus)
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
this.modeToggle(false);
|
||||
if ('plain' === this.editor.mode && this.editor.plugins.plain && this.editor.__plain)
|
||||
{
|
||||
return this.editor.__plain.setRawData(sPlain);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.editor.setData(sPlain);
|
||||
}
|
||||
var
|
||||
oConfig = Globals.oHtmlEditorDefaultConfig,
|
||||
sLanguage = RL.settingsGet('Language'), // TODO cjs
|
||||
bSource = !!RL.settingsGet('AllowHtmlEditorSourceButton')
|
||||
;
|
||||
|
||||
if (bFocus)
|
||||
{
|
||||
this.focus();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.init = function ()
|
||||
{
|
||||
if (this.$element && this.$element[0])
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
fInit = function () {
|
||||
|
||||
var
|
||||
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.enterMode = window.CKEDITOR.ENTER_BR;
|
||||
oConfig.shiftEnterMode = window.CKEDITOR.ENTER_BR;
|
||||
|
||||
oConfig.language = Globals.oHtmlEditorLangsMap[sLanguage] || 'en';
|
||||
if (window.CKEDITOR.env)
|
||||
{
|
||||
window.CKEDITOR.env.isCompatible = true;
|
||||
}
|
||||
|
||||
self.editor = window.CKEDITOR.appendTo(self.$element[0], oConfig);
|
||||
|
||||
self.editor.on('key', function(oEvent) {
|
||||
if (oEvent && oEvent.data && 9 /* Tab */ === oEvent.data.keyCode)
|
||||
if (bSource && oConfig.toolbarGroups && !oConfig.toolbarGroups.__SourceInited)
|
||||
{
|
||||
return false;
|
||||
oConfig.toolbarGroups.__SourceInited = true;
|
||||
oConfig.toolbarGroups.push({name: 'document', groups: ['mode', 'document', 'doctools']});
|
||||
}
|
||||
});
|
||||
|
||||
self.editor.on('blur', function() {
|
||||
self.blurTrigger();
|
||||
});
|
||||
oConfig.enterMode = window.CKEDITOR.ENTER_BR;
|
||||
oConfig.shiftEnterMode = window.CKEDITOR.ENTER_BR;
|
||||
|
||||
self.editor.on('mode', function() {
|
||||
|
||||
self.blurTrigger();
|
||||
|
||||
if (self.fOnModeChange)
|
||||
oConfig.language = Globals.oHtmlEditorLangsMap[sLanguage] || 'en';
|
||||
if (window.CKEDITOR.env)
|
||||
{
|
||||
self.fOnModeChange('plain' !== self.editor.mode);
|
||||
window.CKEDITOR.env.isCompatible = true;
|
||||
}
|
||||
});
|
||||
|
||||
self.editor.on('focus', function() {
|
||||
self.focusTrigger();
|
||||
});
|
||||
self.editor = window.CKEDITOR.appendTo(self.$element[0], oConfig);
|
||||
|
||||
if (self.fOnReady)
|
||||
{
|
||||
self.editor.on('instanceReady', function () {
|
||||
|
||||
self.editor.setKeystroke(window.CKEDITOR.CTRL + 65 /* A */, 'selectAll');
|
||||
|
||||
self.fOnReady();
|
||||
self.__resizable = true;
|
||||
self.resize();
|
||||
self.editor.on('key', function(oEvent) {
|
||||
if (oEvent && oEvent.data && 9 /* Tab */ === oEvent.data.keyCode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
self.editor.on('blur', function() {
|
||||
self.blurTrigger();
|
||||
});
|
||||
|
||||
self.editor.on('mode', function() {
|
||||
|
||||
self.blurTrigger();
|
||||
|
||||
if (self.fOnModeChange)
|
||||
{
|
||||
self.fOnModeChange('plain' !== self.editor.mode);
|
||||
}
|
||||
});
|
||||
|
||||
self.editor.on('focus', function() {
|
||||
self.focusTrigger();
|
||||
});
|
||||
|
||||
if (self.fOnReady)
|
||||
{
|
||||
self.editor.on('instanceReady', function () {
|
||||
|
||||
self.editor.setKeystroke(window.CKEDITOR.CTRL + 65 /* A */, 'selectAll');
|
||||
|
||||
self.fOnReady();
|
||||
self.__resizable = true;
|
||||
self.resize();
|
||||
});
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
if (window.CKEDITOR)
|
||||
{
|
||||
fInit();
|
||||
}
|
||||
else
|
||||
{
|
||||
window.__initEditor = fInit;
|
||||
}
|
||||
;
|
||||
|
||||
if (window.CKEDITOR)
|
||||
{
|
||||
fInit();
|
||||
}
|
||||
else
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.focus = function ()
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
window.__initEditor = fInit;
|
||||
this.editor.focus();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.focus = function ()
|
||||
{
|
||||
if (this.editor)
|
||||
NewHtmlEditorWrapper.prototype.blur = function ()
|
||||
{
|
||||
this.editor.focus();
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.blur = function ()
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
this.editor.focusManager.blur(true);
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.resize = function ()
|
||||
{
|
||||
if (this.editor && this.__resizable)
|
||||
{
|
||||
try
|
||||
if (this.editor)
|
||||
{
|
||||
this.editor.resize(this.$element.width(), this.$element.innerHeight());
|
||||
this.editor.focusManager.blur(true);
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.clear = function (bFocus)
|
||||
{
|
||||
this.setHtml('', bFocus);
|
||||
};
|
||||
NewHtmlEditorWrapper.prototype.resize = function ()
|
||||
{
|
||||
if (this.editor && this.__resizable)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.editor.resize(this.$element.width(), this.$element.innerHeight());
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
};
|
||||
|
||||
NewHtmlEditorWrapper.prototype.clear = function (bFocus)
|
||||
{
|
||||
this.setHtml('', bFocus);
|
||||
};
|
||||
|
||||
|
||||
module.exports = NewHtmlEditorWrapper;
|
||||
|
||||
}(module));
|
||||
Loading…
Add table
Add a link
Reference in a new issue