|
|
@ -926,6 +926,63 @@ exports.RGBToHSV = function(red,green,blue) { |
|
|
|
return {h:hue,s:saturation,v:value}; |
|
|
|
}; |
|
|
|
|
|
|
|
var cssUtil = { |
|
|
|
// split a string with css styles into an object with key/values
|
|
|
|
split: function (cssText) { |
|
|
|
var styles = {}; |
|
|
|
|
|
|
|
cssText.split(';').forEach(function (style) { |
|
|
|
if (style.trim() != '') { |
|
|
|
var parts = style.split(':'); |
|
|
|
var key = parts[0].trim(); |
|
|
|
var value = parts[1].trim(); |
|
|
|
styles[key] = value; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
return styles; |
|
|
|
}, |
|
|
|
|
|
|
|
// build a css text string from an object with key/values
|
|
|
|
join: function (styles) { |
|
|
|
return Object.keys(styles) |
|
|
|
.map(function (key) { |
|
|
|
return key + ': ' + styles[key]; |
|
|
|
}) |
|
|
|
.join('; '); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Append a string with css styles to an element |
|
|
|
* @param {Element} element |
|
|
|
* @param {String} cssText |
|
|
|
*/ |
|
|
|
exports.addCssText = function (element, cssText) { |
|
|
|
var currentStyles = cssUtil.split(element.style.cssText); |
|
|
|
var newStyles = cssUtil.split(cssText); |
|
|
|
var styles = exports.extend(currentStyles, newStyles); |
|
|
|
|
|
|
|
element.style.cssText = cssUtil.join(styles); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Remove a string with css styles from an element |
|
|
|
* @param {Element} element |
|
|
|
* @param {String} cssText |
|
|
|
*/ |
|
|
|
exports.removeCssText = function (element, cssText) { |
|
|
|
var styles = cssUtil.split(element.style.cssText); |
|
|
|
var removeStyles = cssUtil.split(cssText); |
|
|
|
|
|
|
|
for (var key in removeStyles) { |
|
|
|
if (removeStyles.hasOwnProperty(key)) { |
|
|
|
delete styles[key]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
element.style.cssText = cssUtil.join(styles); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* https://gist.github.com/mjijackson/5311256
|
|
|
|