本文整理汇总了TypeScript中tinymce/core/api/dom/DOMUtils.DOMUtils.parseStyle方法的典型用法代码示例。如果您正苦于以下问题:TypeScript DOMUtils.parseStyle方法的具体用法?TypeScript DOMUtils.parseStyle怎么用?TypeScript DOMUtils.parseStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tinymce/core/api/dom/DOMUtils.DOMUtils
的用法示例。
在下文中一共展示了DOMUtils.parseStyle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
const extractAdvancedStyles = function (dom: DOMUtils, elm): Node {
const css = dom.parseStyle(dom.getAttrib(elm, 'style'));
const data: any = {};
if (css['border-style']) {
data.borderStyle = css['border-style'];
}
if (css['border-color']) {
data.borderColor = css['border-color'];
}
if (css['background-color']) {
data.backgroundColor = css['background-color'];
}
data.style = dom.serializeStyle(css);
return data;
};
示例2: function
this.compare = function (node1, node2) {
// Not the same name
if (node1.nodeName !== node2.nodeName) {
return false;
}
/**
* Returns all the nodes attributes excluding internal ones, styles and classes.
*
* @private
* @param {Node} node Node to get attributes from.
* @return {Object} Name/value object with attributes and attribute values.
*/
const getAttribs = function (node) {
const attribs = {};
each(dom.getAttribs(node), function (attr) {
const name = attr.nodeName.toLowerCase();
// Don't compare internal attributes or style
if (name.indexOf('_') !== 0 && name !== 'style' && name.indexOf('data-') !== 0) {
attribs[name] = dom.getAttrib(node, name);
}
});
return attribs;
};
/**
* Compares two objects checks if it's key + value exists in the other one.
*
* @private
* @param {Object} obj1 First object to compare.
* @param {Object} obj2 Second object to compare.
* @return {boolean} True/false if the objects matches or not.
*/
const compareObjects = function (obj1, obj2) {
let value, name;
for (name in obj1) {
// Obj1 has item obj2 doesn't have
if (obj1.hasOwnProperty(name)) {
value = obj2[name];
// Obj2 doesn't have obj1 item
if (typeof value === 'undefined') {
return false;
}
// Obj2 item has a different value
if (obj1[name] !== value) {
return false;
}
// Delete similar value
delete obj2[name];
}
}
// Check if obj 2 has something obj 1 doesn't have
for (name in obj2) {
// Obj2 has item obj1 doesn't have
if (obj2.hasOwnProperty(name)) {
return false;
}
}
return true;
};
// Attribs are not the same
if (!compareObjects(getAttribs(node1), getAttribs(node2))) {
return false;
}
// Styles are not the same
if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style')))) {
return false;
}
return !Bookmarks.isBookmarkNode(node1) && !Bookmarks.isBookmarkNode(node2);
};