Fix html editor

This commit is contained in:
RayMan 2014-02-10 20:14:25 +04:00
parent 17f6204d2a
commit 987fe4c2b7
15 changed files with 322 additions and 226 deletions

View file

@ -59,7 +59,7 @@ HtmlEditorWrapper.prototype.blurTrigger = function ()
var self = this;
window.clearTimeout(self.iBlurTimer);
self.iBlurTimer = window.setTimeout(function () {
self.fOnBlur();
self.fOnBlur();
}, 200);
}
};
@ -72,6 +72,14 @@ HtmlEditorWrapper.prototype.focusTrigger = function ()
}
};
HtmlEditorWrapper.prototype.hideEditorToolbar = function ()
{
if (this.editor)
{
$('.cke.cke_float').hide();
}
};
/**
* @param {string} sHtml
* @return {string}
@ -86,7 +94,7 @@ HtmlEditorWrapper.prototype.htmlToPlain = function (sHtml)
if (arguments && 1 < arguments.length)
{
var sText = $.trim(arguments[1])
.replace(/__bq__start__([\s\S\n\r]*)__bq__end__/gm, convertBlockquote)
.replace(/__bq__start__(.|[\s\S\n\r]*)__bq__end__/gm, convertBlockquote)
;
sText = '\n' + sQuoteChar + $.trim(sText).replace(/\n/gm, '\n' + sQuoteChar) + '\n>\n';
@ -105,7 +113,7 @@ HtmlEditorWrapper.prototype.htmlToPlain = function (sHtml)
var sText = $.trim(arguments[1]);
if (0 < sText.length)
{
sText = sText.replace(/<div[^>]*>([\s\S]*)<\/div>/gmi, convertDivs);
sText = sText.replace(/<div[^>]*>(.|[\s\S\r\n]*)<\/div>/gmi, convertDivs);
sText = '\n' + $.trim(sText) + '\n';
}
return sText;
@ -113,6 +121,15 @@ HtmlEditorWrapper.prototype.htmlToPlain = function (sHtml)
return '';
},
fixAttibuteValue = function () {
if (arguments && 1 < arguments.length)
{
return '' + arguments[1] + arguments[2].replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
return '';
},
convertLinks = function () {
if (arguments && 1 < arguments.length)
{
@ -135,6 +152,7 @@ HtmlEditorWrapper.prototype.htmlToPlain = function (sHtml)
sText = sHtml
.replace(/[\s]+/gm, ' ')
.replace(/((?:href|data)\s?=\s?)("[^"]+?"|'[^']+?')/gmi, fixAttibuteValue)
.replace(/<br\s?\/?>/gmi, '\n')
.replace(/<\/h\d>/gi, '\n')
.replace(/<\/p>/gi, '\n\n')
@ -143,10 +161,10 @@ HtmlEditorWrapper.prototype.htmlToPlain = function (sHtml)
.replace(/<\/tr>/gi, '\n')
.replace(/<hr[^>]*>/gmi, '\n_______________________________\n\n')
.replace(/<img [^>]*>/gmi, '')
.replace(/<div[^>]*>([\s\S]*)<\/div>/gmi, convertDivs)
.replace(/<div[^>]*>(.|[\s\S\r\n]*)<\/div>/gmi, convertDivs)
.replace(/<blockquote[^>]*>/gmi, '\n__bq__start__\n')
.replace(/<\/blockquote>/gmi, '\n__bq__end__\n')
.replace(/<a [^>]*>([\s\S]*?)<\/a>/gmi, convertLinks)
.replace(/<a [^>]*>(.|[\s\S\r\n]*)<\/a>/gmi, convertLinks)
.replace(/&nbsp;/gi, ' ')
.replace(/<[^>]*>/gm, '')
.replace(/&gt;/gi, '>')
@ -158,7 +176,7 @@ HtmlEditorWrapper.prototype.htmlToPlain = function (sHtml)
return sText
.replace(/\n[ \t]+/gm, '\n')
.replace(/[\n]{3,}/gm, '\n\n')
.replace(/__bq__start__([\s\S]*)__bq__end__/gm, convertBlockquote)
.replace(/__bq__start__(.|[\s\S\r\n]*)__bq__end__/gm, convertBlockquote)
.replace(/__bq__start__/gm, '')
.replace(/__bq__end__/gm, '')
;
@ -397,6 +415,4 @@ HtmlEditorWrapper.prototype.modeToggle = function (bFocus)
{
this.focus();
}
this.blurTrigger();
};