aboutsummaryrefslogtreecommitdiffstats
path: root/tests/wpt/css-tests/css-values-3_dev/xhtml1/support/vendorPrefix.js
diff options
context:
space:
mode:
authorMs2ger <Ms2ger@gmail.com>2015-10-31 14:35:08 +0100
committerMs2ger <Ms2ger@gmail.com>2015-10-31 16:21:47 +0100
commit5450053b026bb842a00824ab0be1211ba0288540 (patch)
treeb5647bf0632bf902289f56125be5656981742e44 /tests/wpt/css-tests/css-values-3_dev/xhtml1/support/vendorPrefix.js
parentb492a3e8b1762491f84ab134d9d2904fce69b1ea (diff)
downloadservo-5450053b026bb842a00824ab0be1211ba0288540.tar.gz
servo-5450053b026bb842a00824ab0be1211ba0288540.zip
Update CSS tests to revision d13905941293af83ea8c3c1750dba652e0423fb0
Diffstat (limited to 'tests/wpt/css-tests/css-values-3_dev/xhtml1/support/vendorPrefix.js')
-rw-r--r--tests/wpt/css-tests/css-values-3_dev/xhtml1/support/vendorPrefix.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/wpt/css-tests/css-values-3_dev/xhtml1/support/vendorPrefix.js b/tests/wpt/css-tests/css-values-3_dev/xhtml1/support/vendorPrefix.js
new file mode 100644
index 00000000000..6cf3c5a3783
--- /dev/null
+++ b/tests/wpt/css-tests/css-values-3_dev/xhtml1/support/vendorPrefix.js
@@ -0,0 +1,86 @@
+//
+// Vendor-Prefix Helper Functions For Testing CSS
+//
+
+(function(root) {
+'use strict';
+
+var prefixCache = {};
+
+// convert "foo-bar" to "fooBar"
+function camelCase(str) {
+ return str.replace(/\-(\w)/g, function(match, letter){
+ return letter.toUpperCase();
+ });
+}
+
+// vendor-prefix a css property
+root.addVendorPrefix = function (name) {
+ var prefix = getVendorPrefix(name);
+ if (prefix === false) {
+ // property unknown to browser
+ return name;
+ }
+
+ return prefix + name;
+};
+
+// vendor-prefix a css property value
+root.addValueVendorPrefix = function (property, value) {
+ var prefix = getValueVendorPrefix(property, value);
+ if (prefix === false) {
+ // property unknown to browser
+ return name;
+ }
+
+ return prefix + value;
+};
+
+// identify vendor-prefix for css property
+root.getVendorPrefix = function(name) {
+ if (prefixCache[name] !== undefined) {
+ return prefixCache[name];
+ }
+
+ var elem = document.createElement("div");
+ name = camelCase(name);
+
+ if (name in elem.style) {
+ return prefixCache[name] = "";
+ }
+
+ var prefixes = ["Webkit", "Moz", "O", "ms"];
+ var styles = ["-webkit-", "-moz-", "-o-", "-ms-"];
+ var _name = name.substring(0, 1).toUpperCase() + name.substring(1);
+
+ for (var i = 0, length = prefixes.length; i < length; i++) {
+ if (prefixes[i] + _name in elem.style) {
+ return prefixCache[name] = styles[i];
+ }
+ }
+
+ return prefixCache[name] = name in elem.style ? "" : false;
+};
+
+// identify vendor-prefix for css property value
+root.getValueVendorPrefix = function(property, value) {
+ var elem = document.createElement("div");
+ // note: webkit needs the element to be attached to the dom
+ document.body.appendChild(elem);
+ var styles = ["-webkit-", "-moz-", "-o-", "-ms-", ""];
+ var _property = getVendorPrefix(property) + property;
+ for (var i=0, length = styles.length; i < length; i++) {
+ var _value = styles[i] + value;
+ elem.setAttribute('style', _property + ": " + _value);
+ var _computed = computedStyle(elem, _property);
+ if (_computed && _computed !== 'none') {
+ document.body.removeChild(elem);
+ return styles[i];
+ }
+ }
+ document.body.removeChild(elem);
+ return false;
+};
+
+
+})(window); \ No newline at end of file