本文整理汇总了TypeScript中tinymce/core/api/util/Tools.trim函数的典型用法代码示例。如果您正苦于以下问题:TypeScript trim函数的具体用法?TypeScript trim怎么用?TypeScript trim使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了trim函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: if
const getContentFromBody = (editor, args, body) => {
let content;
args.format = args.format ? args.format : defaultFormat;
args.get = true;
args.getInner = true;
if (!args.no_events) {
editor.fire('BeforeGetContent', args);
}
if (args.format === 'raw') {
content = Tools.trim(TrimHtml.trimExternal(editor.serializer, body.innerHTML));
} else if (args.format === 'text') {
content = Zwsp.trim(body.innerText || body.textContent);
} else if (args.format === 'tree') {
return editor.serializer.serialize(body, args);
} else {
content = trimEmptyContents(editor, editor.serializer.serialize(body, args));
}
if (args.format !== 'text') {
args.content = Tools.trim(content);
} else {
args.content = content;
}
if (!args.no_events) {
editor.fire('GetContent', args);
}
return args.content;
};
开发者ID:nyroDev,项目名称:tinymce,代码行数:33,代码来源:EditorContent.ts
示例2: 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);
}
}
});
});
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:53,代码来源:FilterContent.ts
示例3: TreeWalker
const findBlockPattern = (dom: DOMUtils, patterns: BlockPattern[], rng: Range): Option<BlockPattern> => {
const block = dom.getParent(rng.startContainer, dom.isBlock);
if (!(dom.is(block, 'p') && isElement(block))) {
return Option.none();
}
const walker = new TreeWalker(block, block);
let node: Node;
let firstTextNode: Text;
while ((node = walker.next())) {
if (isText(node)) {
firstTextNode = node;
break;
}
}
if (!firstTextNode) {
return Option.none();
}
const pattern = findPattern(patterns, firstTextNode.data);
if (!pattern) {
return Option.none();
}
if (Tools.trim(block.textContent).length === pattern.start.length) {
return Option.none();
}
return Option.some(pattern);
};
开发者ID:tinymce,项目名称:tinymce,代码行数:27,代码来源:FindPatterns.ts
示例4: 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);
});
}
}
}
};
开发者ID:abstask,项目名称:tinymce,代码行数:59,代码来源:Formatter.ts
示例5: RegExp
const isEmpty = (editor: Editor, html?: string) => {
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);
};
开发者ID:tinymce,项目名称:tinymce,代码行数:9,代码来源:Storage.ts
示例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;
}
// Reset the editor content back to the initial state
editor.resetContent(h);
};
开发者ID:tinymce,项目名称:tinymce,代码行数:12,代码来源:Actions.ts
示例7: 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();
};
开发者ID:abstask,项目名称:tinymce,代码行数:13,代码来源:Actions.ts
示例8: 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');
});
开发者ID:abstask,项目名称:tinymce,代码行数:22,代码来源:DomUtilsTest.ts
示例9: if
const getContent = (editor: Editor, args: GetContentArgs = {}): Content => {
let content;
const body = editor.getBody();
if (editor.removed) {
return '';
}
args.format = args.format ? args.format : defaultFormat;
args.get = true;
args.getInner = true;
if (!args.no_events) {
editor.fire('BeforeGetContent', args);
}
if (args.format === 'raw') {
content = Tools.trim(TrimHtml.trimExternal(editor.serializer, body.innerHTML));
} else if (args.format === 'text') {
content = body.innerText || body.textContent;
} else if (args.format === 'tree') {
return editor.serializer.serialize(body, args);
} else {
content = editor.serializer.serialize(body, args);
}
if (args.format !== 'text') {
args.content = Tools.trim(content);
} else {
args.content = content;
}
if (!args.no_events) {
editor.fire('GetContent', args);
}
return args.content;
};
开发者ID:abstask,项目名称:tinymce,代码行数:38,代码来源:EditorContent.ts
示例10: Serializer
const setContentTree = (editor: Editor, body: HTMLElement, content: Node, args: SetContentArgs): Node => {
FilterNode.filter(editor.parser.getNodeFilters(), editor.parser.getAttributeFilters(), content);
const html = Serializer({ validate: editor.validate }, editor.schema).serialize(content);
args.content = isWsPreserveElement(Element.fromDom(body)) ? html : Tools.trim(html);
setEditorHtml(editor, args.content);
if (!args.no_events) {
editor.fire('SetContent', args);
}
return content;
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:14,代码来源:SetContent.ts
注:本文中的tinymce/core/api/util/Tools.trim函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论