]*>(.|[\s\S\r\n]*)<\/div>/gmi, convertDivs);
sText = '\n' + $.trim(sText) + '\n';
}
return sText;
}
return '';
},
fixAttibuteValue = function () {
if (arguments && 1 < arguments.length)
{
return '' + arguments[1] + arguments[2].replace(//g, '>');
}
return '';
},
convertLinks = function () {
if (arguments && 1 < arguments.length)
{
var
sName = $.trim(arguments[1])
// sHref = $.trim(arguments[0].replace(/
/gmi, '$1'))
;
return sName;
// sName = (0 === trim(sName).length) ? '' : sName;
// sHref = ('mailto:' === sHref.substr(0, 7)) ? '' : sHref;
// sHref = ('http' === sHref.substr(0, 4)) ? sHref : '';
// sHref = (sName === sHref) ? '' : sHref;
// sHref = (0 < sHref.length) ? ' (' + sHref + ') ' : '';
// return (0 < sName.length) ? sName + sHref : sName;
}
return '';
}
;
sText = sHtml
.replace(/[\s]+/gm, ' ')
.replace(/((?:href|data)\s?=\s?)("[^"]+?"|'[^']+?')/gmi, fixAttibuteValue)
.replace(/
/gmi, '\n')
.replace(/<\/h\d>/gi, '\n')
.replace(/<\/p>/gi, '\n\n')
.replace(/<\/li>/gi, '\n')
.replace(/<\/td>/gi, '\n')
.replace(/<\/tr>/gi, '\n')
.replace(/
]*>/gmi, '\n_______________________________\n\n')
.replace(/]*>/gmi, '')
.replace(/]*>(.|[\s\S\r\n]*)<\/div>/gmi, convertDivs)
.replace(/
]*>/gmi, '\n__bq__start__\n')
.replace(/<\/blockquote>/gmi, '\n__bq__end__\n')
.replace(/]*>(.|[\s\S\r\n]*)<\/a>/gmi, convertLinks)
.replace(/ /gi, ' ')
.replace(/<[^>]*>/gm, '')
.replace(/>/gi, '>')
.replace(/</gi, '<')
.replace(/&/gi, '&')
.replace(/&\w{2,6};/gi, '')
;
return sText
.replace(/\n[ \t]+/gm, '\n')
.replace(/[\n]{3,}/gm, '\n\n')
.replace(/__bq__start__(.|[\s\S\r\n]*)__bq__end__/gm, convertBlockquote)
.replace(/__bq__start__/gm, '')
.replace(/__bq__end__/gm, '')
;
};
/**
* @param {string} sPlain
* @return {string}
*/
Utils.plainToHtml = function (sPlain)
{
return sPlain.toString()
.replace(/&/g, '&').replace(/>/g, '>').replace(/');
};
Utils.resizeAndCrop = function (sUrl, iValue, fCallback)
{
var oTempImg = new window.Image();
oTempImg.onload = function() {
var
aDiff = [0, 0],
oCanvas = document.createElement('canvas'),
oCtx = oCanvas.getContext('2d')
;
oCanvas.width = iValue;
oCanvas.height = iValue;
if (this.width > this.height)
{
aDiff = [this.width - this.height, 0];
}
else
{
aDiff = [0, this.height - this.width];
}
oCtx.fillStyle = '#fff';
oCtx.fillRect(0, 0, iValue, iValue);
oCtx.drawImage(this, aDiff[0] / 2, aDiff[1] / 2, this.width - aDiff[0], this.height - aDiff[1], 0, 0, iValue, iValue);
fCallback(oCanvas.toDataURL('image/jpeg'));
};
oTempImg.src = sUrl;
};
Utils.computedPagenatorHelper = function (koCurrentPage, koPageCount)
{
return function() {
var
iPrev = 0,
iNext = 0,
iLimit = 2,
aResult = [],
iCurrentPage = koCurrentPage(),
iPageCount = koPageCount(),
/**
* @param {number} iIndex
* @param {boolean=} bPush
* @param {string=} sCustomName
*/
fAdd = function (iIndex, bPush, sCustomName) {
var oData = {
'current': iIndex === iCurrentPage,
'name': Utils.isUnd(sCustomName) ? iIndex.toString() : sCustomName.toString(),
'custom': Utils.isUnd(sCustomName) ? false : true,
'title': Utils.isUnd(sCustomName) ? '' : iIndex.toString(),
'value': iIndex.toString()
};
if (Utils.isUnd(bPush) ? true : !!bPush)
{
aResult.push(oData);
}
else
{
aResult.unshift(oData);
}
}
;
if (1 < iPageCount || (0 < iPageCount && iPageCount < iCurrentPage))
// if (0 < iPageCount && 0 < iCurrentPage)
{
if (iPageCount < iCurrentPage)
{
fAdd(iPageCount);
iPrev = iPageCount;
iNext = iPageCount;
}
else
{
if (3 >= iCurrentPage || iPageCount - 2 <= iCurrentPage)
{
iLimit += 2;
}
fAdd(iCurrentPage);
iPrev = iCurrentPage;
iNext = iCurrentPage;
}
while (0 < iLimit) {
iPrev -= 1;
iNext += 1;
if (0 < iPrev)
{
fAdd(iPrev, false);
iLimit--;
}
if (iPageCount >= iNext)
{
fAdd(iNext, true);
iLimit--;
}
else if (0 >= iPrev)
{
break;
}
}
if (3 === iPrev)
{
fAdd(2, false);
}
else if (3 < iPrev)
{
fAdd(Math.round((iPrev - 1) / 2), false, '...');
}
if (iPageCount - 2 === iNext)
{
fAdd(iPageCount - 1, true);
}
else if (iPageCount - 2 > iNext)
{
fAdd(Math.round((iPageCount + iNext) / 2), true, '...');
}
// first and last
if (1 < iPrev)
{
fAdd(1, false);
}
if (iPageCount > iNext)
{
fAdd(iPageCount, true);
}
}
return aResult;
};
};
Utils.selectElement = function (element)
{
/* jshint onevar: false */
if (window.getSelection)
{
var sel = window.getSelection();
sel.removeAllRanges();
var range = document.createRange();
range.selectNodeContents(element);
sel.addRange(range);
}
else if (document.selection)
{
var textRange = document.body.createTextRange();
textRange.moveToElementText(element);
textRange.select();
}
/* jshint onevar: true */
};
Utils.disableKeyFilter = function ()
{
if (window.key)
{
key.filter = function () {
return RL.data().useKeyboardShortcuts();
};
}
};
Utils.restoreKeyFilter = function ()
{
if (window.key)
{
key.filter = function (event) {
if (RL.data().useKeyboardShortcuts())
{
var
element = event.target || event.srcElement,
tagName = element ? element.tagName : ''
;
tagName = tagName.toUpperCase();
return !(tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA' ||
(element && tagName === 'DIV' && 'editorHtmlArea' === element.className && element.contentEditable)
);
}
return false;
};
}
};
Utils.detectDropdownVisibility = _.debounce(function () {
Globals.dropdownVisibility(!!_.find(BootstrapDropdowns, function (oItem) {
return oItem.hasClass('open');
}));
}, 50);