本文整理汇总了TypeScript中tinymce/core/util/Tools.trim函数的典型用法代码示例。如果您正苦于以下问题:TypeScript trim函数的具体用法?TypeScript trim怎么用?TypeScript trim使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了trim函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
const setup = function (editor) {
let editClass, nonEditClass;
const contentEditableAttrName = 'contenteditable';
editClass = ' ' + Tools.trim(Settings.getEditableClass(editor)) + ' ';
nonEditClass = ' ' + Tools.trim(Settings.getNonEditableClass(editor)) + ' ';
const hasEditClass = hasClass(editClass);
const hasNonEditClass = hasClass(nonEditClass);
const nonEditableRegExps = Settings.getNonEditableRegExps(editor);
editor.on('PreInit', function () {
if (nonEditableRegExps.length > 0) {
editor.on('BeforeSetContent', function (e) {
convertRegExpsToNonEditable(editor, nonEditableRegExps, e);
});
}
editor.parser.addAttributeFilter('class', function (nodes) {
let i = nodes.length, node;
while (i--) {
node = nodes[i];
if (hasEditClass(node)) {
node.attr(contentEditableAttrName, 'true');
} else if (hasNonEditClass(node)) {
node.attr(contentEditableAttrName, 'false');
}
}
});
editor.serializer.addAttributeFilter(contentEditableAttrName, function (nodes) {
let i = nodes.length, node;
while (i--) {
node = nodes[i];
if (!hasEditClass(node) && !hasNonEditClass(node)) {
continue;
}
if (nonEditableRegExps.length > 0 && node.attr('data-mce-content')) {
node.name = '#text';
node.type = 3;
node.raw = true;
node.value = node.attr('data-mce-content');
} else {
node.attr(contentEditableAttrName, null);
}
}
});
});
};
示例2: function
const applyBlockFormat = function (editor, patterns) {
let selection, dom, container, firstTextNode, node, format, textBlockElm, pattern, walker, rng, offset;
selection = editor.selection;
dom = editor.dom;
if (!selection.isCollapsed()) {
return;
}
textBlockElm = dom.getParent(selection.getStart(), 'p');
if (textBlockElm) {
walker = new TreeWalker(textBlockElm, textBlockElm);
while ((node = walker.next())) {
if (node.nodeType === 3) {
firstTextNode = node;
break;
}
}
if (firstTextNode) {
pattern = Patterns.findPattern(patterns, firstTextNode.data);
if (!pattern) {
return;
}
rng = selection.getRng(true);
container = rng.startContainer;
offset = rng.startOffset;
if (firstTextNode === container) {
offset = Math.max(0, offset - pattern.start.length);
}
if (Tools.trim(firstTextNode.data).length === pattern.start.length) {
return;
}
if (pattern.format) {
format = editor.formatter.get(pattern.format);
if (format && format[0].block) {
firstTextNode.deleteData(0, pattern.start.length);
editor.formatter.apply(pattern.format, {}, firstTextNode);
rng.setStart(container, offset);
rng.collapse(true);
selection.setRng(rng);
}
}
if (pattern.cmd) {
editor.undoManager.transact(function () {
firstTextNode.deleteData(0, pattern.start.length);
editor.execCommand(pattern.cmd);
});
}
}
}
};
示例3: function
const isEmpty = function (editor, html?) {
const forcedRootBlockName = editor.settings.forced_root_block;
html = Tools.trim(typeof html === 'undefined' ? editor.getBody().innerHTML : html);
return html === '' || new RegExp(
'^<' + forcedRootBlockName + '[^>]*>((\u00a0| |[ \t]|<br[^>]*>)+?|)<\/' + forcedRootBlockName + '>|<br>$', 'i'
).test(html);
};
示例4: TreeWalker
const moveEndPoint = (dom, rng: Range, node, start: boolean): void => {
const root = node, walker = new TreeWalker(node, root);
const nonEmptyElementsMap = dom.schema.getNonEmptyElements();
do {
// Text node
if (node.nodeType === 3 && Tools.trim(node.nodeValue).length !== 0) {
if (start) {
rng.setStart(node, 0);
} else {
rng.setEnd(node, node.nodeValue.length);
}
return;
}
// BR/IMG/INPUT elements but not table cells
if (nonEmptyElementsMap[node.nodeName] && !/^(TD|TH)$/.test(node.nodeName)) {
if (start) {
rng.setStartBefore(node);
} else {
if (node.nodeName === 'BR') {
rng.setEndBefore(node);
} else {
rng.setEndAfter(node);
}
}
return;
}
// Found empty text block old IE can place the selection inside those
if (Env.ie && Env.ie < 11 && dom.isBlock(node) && dom.isEmpty(node)) {
if (start) {
rng.setStart(node, 0);
} else {
rng.setEnd(node, 0);
}
return;
}
} while ((node = (start ? walker.next() : walker.prev())));
// Failed to find any text node or other suitable location then move to the root of body
if (root.nodeName === 'BODY') {
if (start) {
rng.setStart(root, 0);
} else {
rng.setEnd(root, root.childNodes.length);
}
}
};
示例5: function
suite.test('getOuterHTML', function () {
DOM.add(document.body, 'div', { id : 'test' });
DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');
LegacyUnit.equal(DOM.getOuterHTML('test2').toLowerCase().replace(/\"/g, ''), '<span id=test2><span>test</span><span>test2</span></span>');
DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');
DOM.setOuterHTML('test2', '<div id="test2">123</div>');
LegacyUnit.equal(Tools.trim(DOM.getOuterHTML('test2') || '').toLowerCase().replace(/\"/g, ''), '<div id=test2>123</div>');
DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');
DOM.setOuterHTML('test2', '<div id="test2">123</div><div id="test3">abc</div>');
LegacyUnit.equal(
Tools.trim(DOM.get('test').innerHTML).toLowerCase().replace(/>\s+</g, '><').replace(/\"/g, ''),
'<div id=test2>123</div><div id=test3>abc</div>'
);
DOM.setHTML('test', 'test');
LegacyUnit.equal(Tools.trim(DOM.getOuterHTML(DOM.get('test').firstChild)), 'test');
DOM.remove('test');
});
示例6: function
const cancel = function (editor) {
const h = Tools.trim(editor.startContent);
// Use callback instead
if (Settings.hasOnCancelCallback(editor)) {
editor.execCallback('save_oncancelcallback', editor);
return;
}
editor.setContent(h);
editor.undoManager.clear();
editor.nodeChanged();
};
示例7: function
const html2bbcode = function (s) {
s = Tools.trim(s);
const rep = function (re, str) {
s = s.replace(re, str);
};
// example: <strong> to [b]
rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi, '[url=$1]$2[/url]');
rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi, '[code][color=$1]$2[/color][/code]');
rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi, '[quote][color=$1]$2[/color][/quote]');
rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, '[code][color=$1]$2[/color][/code]');
rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, '[quote][color=$1]$2[/color][/quote]');
rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi, '[color=$1]$2[/color]');
rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, '[color=$1]$2[/color]');
rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi, '[size=$1]$2[/size]');
rep(/<font>(.*?)<\/font>/gi, '$1');
rep(/<img.*?src=\"(.*?)\".*?\/>/gi, '[img]$1[/img]');
rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi, '[code]$1[/code]');
rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi, '[quote]$1[/quote]');
rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi, '[code][b]$1[/b][/code]');
rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi, '[quote][b]$1[/b][/quote]');
rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi, '[code][i]$1[/i][/code]');
rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi, '[quote][i]$1[/i][/quote]');
rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi, '[code][u]$1[/u][/code]');
rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi, '[quote][u]$1[/u][/quote]');
rep(/<\/(strong|b)>/gi, '[/b]');
rep(/<(strong|b)>/gi, '[b]');
rep(/<\/(em|i)>/gi, '[/i]');
rep(/<(em|i)>/gi, '[i]');
rep(/<\/u>/gi, '[/u]');
rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi, '[u]$1[/u]');
rep(/<u>/gi, '[u]');
rep(/<blockquote[^>]*>/gi, '[quote]');
rep(/<\/blockquote>/gi, '[/quote]');
rep(/<br \/>/gi, '\n');
rep(/<br\/>/gi, '\n');
rep(/<br>/gi, '\n');
rep(/<p>/gi, '');
rep(/<\/p>/gi, '\n');
rep(/ |\u00a0/gi, ' ');
rep(/"/gi, '"');
rep(/</gi, '<');
rep(/>/gi, '>');
rep(/&/gi, '&');
return s;
};
示例8: function
const toString = function (rel) {
return Tools.trim(rel.sort().join(' '));
};
示例9: function
const open = function (editor, currentIndexState) {
let last: any = {}, selectedText;
editor.undoManager.add();
selectedText = Tools.trim(editor.selection.getContent({ format: 'text' }));
function updateButtonStates() {
win.statusbar.find('#next').disabled(Actions.hasNext(editor, currentIndexState) === false);
win.statusbar.find('#prev').disabled(Actions.hasPrev(editor, currentIndexState) === false);
}
function notFoundAlert() {
editor.windowManager.alert('Could not find the specified string.', function () {
win.find('#find')[0].focus();
});
}
const win = editor.windowManager.open({
layout: 'flex',
pack: 'center',
align: 'center',
onClose () {
editor.focus();
Actions.done(editor, currentIndexState);
editor.undoManager.add();
},
onSubmit (e) {
let count, caseState, text, wholeWord;
e.preventDefault();
caseState = win.find('#case').checked();
wholeWord = win.find('#words').checked();
text = win.find('#find').value();
if (!text.length) {
Actions.done(editor, currentIndexState, false);
win.statusbar.items().slice(1).disabled(true);
return;
}
if (last.text === text && last.caseState === caseState && last.wholeWord === wholeWord) {
if (!Actions.hasNext(editor, currentIndexState)) {
notFoundAlert();
return;
}
Actions.next(editor, currentIndexState);
updateButtonStates();
return;
}
count = Actions.find(editor, currentIndexState, text, caseState, wholeWord);
if (!count) {
notFoundAlert();
}
win.statusbar.items().slice(1).disabled(count === 0);
updateButtonStates();
last = {
text,
caseState,
wholeWord
};
},
buttons: [
{
text: 'Find', subtype: 'primary', onclick () {
win.submit();
}
},
{
text: 'Replace', disabled: true, onclick () {
if (!Actions.replace(editor, currentIndexState, win.find('#replace').value())) {
win.statusbar.items().slice(1).disabled(true);
currentIndexState.set(-1);
last = {};
}
}
},
{
text: 'Replace all', disabled: true, onclick () {
Actions.replace(editor, currentIndexState, win.find('#replace').value(), true, true);
win.statusbar.items().slice(1).disabled(true);
last = {};
}
},
{ type: 'spacer', flex: 1 },
{
text: 'Prev', name: 'prev', disabled: true, onclick () {
Actions.prev(editor, currentIndexState);
updateButtonStates();
}
},
{
text: 'Next', name: 'next', disabled: true, onclick () {
Actions.next(editor, currentIndexState);
updateButtonStates();
}
//.........这里部分代码省略.........