if (styleValue) {
returnValue[styleKey] = styleValue;
}
});
return returnValue;
},
hasCommandApplied: function(jNodes, commandName) {
var result = false;
var commandConfig = configuration.commands[commandName];
jNodes.each(function() {
var $this = $(this);
if (this.nodeType === constants.nodeType.TEXT) {
result = false;
return result;
}
var styles = dom.getStyles($this);
result = (commandConfig.classNameRegex && dom.hasClassWithPattern($this, commandConfig.classNameRegex)) ||
(commandConfig.styleName && styles[commandConfig.styleName]) ||
(commandConfig.tagName && this.tagName === commandConfig.tagName);
return result;
});
return result;
},
hasCommandValue: function(jNode, options) {
var result = false;
jNode.each(function() {
var $this = $(this);
result = (options.className && $this.hasClass(options.className)) ||
(options.styleName && dom.getStyles($this)[options.styleName] === options.styleValue) ||
(options.tagName && $this.prop("tagName") === options.tagName);
return result;
});
return result;
},
getCommandValue: function(jNode, options) {
var result = {};
var commandConfig = configuration.commands[options.commandName];
jNode.each(function() {
var $this = $(this);
var styles = dom.getStyles($this);
if (options.className && $this.hasClass(options.className)) {
result.className = options.className;
} else if (dom.hasClassWithPattern($this, commandConfig.classNameRegex)) {
result.className = dom.getClassWithPattern($this, commandConfig.classNameRegex)[0];
} else if (options.styleName && styles[options.styleName]) {
result.styleName = styles[options.styleName];
} else if (options.tagName && $this.prop("tagName") === commandConfig.tagName) {
result.tagName = $this.prop("tagName");
}
return result;
});
return result;
},
hasClassWithPattern: function(jNode, pattern) {
return pattern.test(jNode.attr("class"));
},
getClassWithPattern: function(jNode, pattern) {
return pattern.exec(jNode.attr("class"));
},
removeClassWithPattern: function(jNode, pattern) {
var classNames = dom.getClassWithPattern(jNode, pattern) || [];
$.each(classNames, function(index, className) {
jNode.removeClass(className);
});
},
hasSameListParent: function(jNodes) {
var parent = jNodes.first().closest(constants.tagName.LI).parent();
if (parent.length === 0) {
return false;
}
var hasSameParent = true;
jNodes.each(function() {
hasSameParent = parent.has(this).length !== 0;
return hasSameParent;
});
return hasSameParent;
},
allHaveClass: function(jNodes, className) {
var hasClass = true;
jNodes.each(function() {
hasClass = $(this).hasClass(className);
return hasClass;
});
return hasClass;
},
hasSameClass: function(jLeftNode, jRightNode) {
var thisClasses = {};
var thatClasses = {};
$.each(dom.getClasses(jLeftNode), function() {
thisClasses[this] = 1;
});
$.each(dom.getClasses(jRightNode), function() {
thatClasses[this] = 1;
});
return util.all(thisClasses, function(key) {
return thatClasses[key];
}) &&
util.all(thatClasses, function(key) {
return thisClasses[key];
});
},
hasSameStyle: function(jLeftNode, jRightNode) {
var thisStyles = dom.getStyles(jLeftNode);
var thatStyles = dom.getStyles(jRightNode);
return util.all(thisStyles, function(key, value) {
return thatStyles[key] === value;
}) &&
util.all(thatStyles, function(key, value) {
return thisStyles[key] === value;
});
},
hasSameStyleAndClass: function(jLeftNode, jRightNode) {
return dom.hasSameStyle(jLeftNode, jRightNode) && dom.hasSameClass(jLeftNode, jRightNode);
},
closestWithCommandValue: function(jNode, options) {
return dom.closestWithCommand(jNode, $.extend(options, {
checkValue: 1
}));
},
closestWithCommand: function(jNode, options) {
var result = $();
var commandConfig = util.getCommandConfig(options);
if (!commandConfig) {
return result;
}
jNode.each(function() {
var $this = $(this);
var topLevelNode = options.topEditableParent || dom.getTopEditableParent($this).get(0);
if (topLevelNode) {
var parentsAndSelf = $this.parentsUntil(topLevelNode.parentNode);
parentsAndSelf.splice(0, 0, this);
parentsAndSelf.each(function() {
if (dom.hasCommandApplied($(this), commandConfig.commandName)) {