From e3a32f29a879f90ac0278b9c2a3f999e5e048262 Mon Sep 17 00:00:00 2001 From: Gregers Gram Rygg Date: Mon, 21 May 2012 16:40:36 +0200 Subject: [PATCH 01/16] Util methods to detect vendor prefix for DOM properties and CSS --- lib/OpenLayers/Util.js | 82 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index ac598f2604..871288a418 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -1508,6 +1508,88 @@ OpenLayers.Util.getBrowserName = function() { return OpenLayers.BROWSER_NAME; }; +/** + * Constant: VENDOR_DOM_PREFIXES + * {Array} A list of prefixes to test support for vendor-prefixed properties + */ +OpenLayers.Util.VENDOR_DOM_PREFIXES = ["", "O", "ms", "Moz", "Webkit"]; + +/** + * Method: getVendorPrefixedCss + * + * Parameters: + * property - {String} The standard CSS property name + * + * Returns: + * {String} The CSS property name supported by the browser or null if + * unsupported + */ +OpenLayers.Util.getVendorPrefixedCss = (function() { + var cache = {}; + + function domToCss(prefixedDom) { + return prefixedDom. + replace(/([A-Z])/g, function(char) { return "-" + char.toLowerCase(); }). + replace(/^ms-/, "-ms-"); + } + + return function(property) { + // clear cache for tests + if (property === "clear cache") { cache = {}; return; } + + if (cache[property] === undefined) { + var domProperty = property. + replace(/(-.)/g, function(c) { return c.charAt(1).toUpperCase(); }); + var prefixedDom = OpenLayers.Util.getVendorPrefixedDom(domProperty); + cache[property] = domToCss(prefixedDom); + } + return cache[property]; + }; +})(); + +/** + * Method: getVendorPrefixedDom + * + * Parameters: + * property - {String} The standard DOM property name + * + * Returns: + * {String} The DOM property name supported by the browser or null if + * unsupported + */ +OpenLayers.Util.getVendorPrefixedDom = (function() { + var cache = {}; + + return function(property) { + // clear cache for tests + if (property === "clear cache") { cache = {}; return; } + + if (cache[property] === undefined) { + var el = document.createElement("div"), + tmpProp, + i = 0, + l = OpenLayers.Util.VENDOR_DOM_PREFIXES.length, + prefix; + + cache[property] = null; + for(var i=0,l=OpenLayers.Util.VENDOR_DOM_PREFIXES.length; i Date: Mon, 21 May 2012 16:41:55 +0200 Subject: [PATCH 02/16] Tests for vendor prefix detection --- tests/Util.html | 68 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/tests/Util.html b/tests/Util.html index ecb583beb0..84f67b1664 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -1119,6 +1119,71 @@ t.eq(OpenLayers.Util.getFormattedLonLat(-181, "lon"), "179°00'00\"E", "crossing dateline from the west results in correct east coordinate"); t.eq(OpenLayers.Util.getFormattedLonLat(181, "lon"), "179°00'00\"W", "crossing dateline from the east results in correct west coordinate"); } + + /** + * Test vendor prefixing + */ + function test_vendor_prefixes(t) { + t.plan(12); + var o = {}, err; + var orgCreateElement = document.createElement; + // wrap document.createElement to control property values + document.createElement = function(type) { + var el = orgCreateElement.call(document, type); + // Since o is an object we can change prop for each test + if(o.prop) { + el.style[o.prop] = o.val; + } + return el; + }; + + function curryTestPrefix(type) { + return function(standardProp, expectedPrefix, msg) { + var prefixedProp, err, method = "getVendorPrefixed" + type; + try { + OpenLayers.Util[method]("clear cache"); + prefixedProp = OpenLayers.Util[method](standardProp); + } catch(e) { + err = e; + } + if(!err) { + t.eq(prefixedProp, expectedPrefix, msg); + } else { + t.fail("Error when testing " + type.toUpperCase() + " vendor prefix: " + err.message); + } + }; + } + var testDomPrefix = curryTestPrefix("Dom"), + testCssPrefix = curryTestPrefix("Css"); + + o.prop = "test"; + o.val = ""; + testDomPrefix("test", "test", "DOM vendor prefix - single word"); + testCssPrefix("test", "test", "CSS vendor prefix - single word"); + + o.prop = "testMultiWord"; + testDomPrefix("testMultiWord", "testMultiWord", "DOM vendor prefix - multiple words"); + testCssPrefix("test-multi-word", "test-multi-word", "CSS vendor prefix - multiple words"); + + o.prop = "WebkitMultiWord"; + testDomPrefix("multiWord", "WebkitMultiWord", "DOM vendor prefix - multiple words for WebKit"); + testCssPrefix("multi-word", "-webkit-multi-word", "CSS vendor prefix - multiple words for WebKit"); + + o.prop = "MozMultiWord"; + testDomPrefix("multiWord", "MozMultiWord", "DOM vendor prefix - multiple words for Mozilla"); + testCssPrefix("multi-word", "-moz-multi-word", "CSS vendor prefix - multiple words for Mozilla"); + + o.prop = "OMultiWord"; + testDomPrefix("multiWord", "OMultiWord", "DOM vendor prefix - multiple words for Opera"); + testCssPrefix("multi-word", "-o-multi-word", "CSS vendor prefix - multiple words for Opera"); + + o.prop = "msMultiWord"; + testDomPrefix("multiWord", "msMultiWord", "DOM vendor prefix - multiple words for Internet Explorer"); + testCssPrefix("multi-word", "-ms-multi-word", "CSS vendor prefix - multiple words for Internet Explorer"); + + // unwrap document.createElement + document.createElement = orgCreateElement; + } /** * To test that we can safely call OpenLayers.Util.extend with an Event @@ -1127,7 +1192,7 @@ var loadEvent; window.onload = function(evt) { loadEvent = evt || window.event; - } + }; function test_extend_event(t) { t.plan(2); t.ok(loadEvent, "loadEvent recorded"); @@ -1143,6 +1208,7 @@ t.eq(extended && extended.foo, "bar", "extended with event"); } } + From 875a2b98fff0ae4feee791e5a571cbf96d0d1558 Mon Sep 17 00:00:00 2001 From: Gregers Gram Rygg Date: Tue, 22 May 2012 17:05:13 +0200 Subject: [PATCH 03/16] API description should inform that the method only tests for DOM style properties. Not object properties. --- lib/OpenLayers/Util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 871288a418..6ae9a2987b 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -1551,10 +1551,10 @@ OpenLayers.Util.getVendorPrefixedCss = (function() { * Method: getVendorPrefixedDom * * Parameters: - * property - {String} The standard DOM property name + * property - {String} The standard DOM style property name * * Returns: - * {String} The DOM property name supported by the browser or null if + * {String} The DOM style property name supported by the browser or null if * unsupported */ OpenLayers.Util.getVendorPrefixedDom = (function() { From a18ce5adf65efed0e440aaa0d3ebb6e41e7fdf25 Mon Sep 17 00:00:00 2001 From: Gregers Gram Rygg Date: Tue, 22 May 2012 17:06:03 +0200 Subject: [PATCH 04/16] Rewrite PinchZoom to detect vendor-prefix, so it works in more browsers --- lib/OpenLayers/Control/PinchZoom.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Control/PinchZoom.js b/lib/OpenLayers/Control/PinchZoom.js index 89240190a9..bd502f3d7d 100644 --- a/lib/OpenLayers/Control/PinchZoom.js +++ b/lib/OpenLayers/Control/PinchZoom.js @@ -162,8 +162,10 @@ OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, { */ applyTransform: function(transform) { var style = this.map.layerContainerDiv.style; - style['-webkit-transform'] = transform; - style['-moz-transform'] = transform; + var transformProperty = OpenLayers.Util.getVendorPrefixedDom("transform"); + if (transformProperty) { + style[transformProperty] = transform; + } }, /** From b9670a292b72f304c6f72e93544f022c8798da06 Mon Sep 17 00:00:00 2001 From: Gregers Gram Rygg Date: Sat, 23 Jun 2012 21:48:44 +0200 Subject: [PATCH 05/16] Added support to detect vendor-prefixes for non-style objects --- lib/OpenLayers/Control/PinchZoom.js | 2 +- lib/OpenLayers/Util.js | 32 +++++++++++++++++------------ tests/Util.html | 24 ++++++++++++++++++---- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/lib/OpenLayers/Control/PinchZoom.js b/lib/OpenLayers/Control/PinchZoom.js index bd502f3d7d..e7e3827e1d 100644 --- a/lib/OpenLayers/Control/PinchZoom.js +++ b/lib/OpenLayers/Control/PinchZoom.js @@ -162,7 +162,7 @@ OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, { */ applyTransform: function(transform) { var style = this.map.layerContainerDiv.style; - var transformProperty = OpenLayers.Util.getVendorPrefixedDom("transform"); + var transformProperty = OpenLayers.Util.getVendorPrefixedObj("transform"); if (transformProperty) { style[transformProperty] = transform; } diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 6ae9a2987b..ce84785701 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -1509,10 +1509,10 @@ OpenLayers.Util.getBrowserName = function() { }; /** - * Constant: VENDOR_DOM_PREFIXES + * Constant: VENDOR_PREFIXES * {Array} A list of prefixes to test support for vendor-prefixed properties */ -OpenLayers.Util.VENDOR_DOM_PREFIXES = ["", "O", "ms", "Moz", "Webkit"]; +OpenLayers.Util.VENDOR_PREFIXES = ["", "O", "ms", "Moz", "webkit"]; /** * Method: getVendorPrefixedCss @@ -1530,7 +1530,8 @@ OpenLayers.Util.getVendorPrefixedCss = (function() { function domToCss(prefixedDom) { return prefixedDom. replace(/([A-Z])/g, function(char) { return "-" + char.toLowerCase(); }). - replace(/^ms-/, "-ms-"); + replace(/^ms-/, "-ms-"). + replace(/^webkit-/, "-webkit-"); } return function(property) { @@ -1540,7 +1541,7 @@ OpenLayers.Util.getVendorPrefixedCss = (function() { if (cache[property] === undefined) { var domProperty = property. replace(/(-.)/g, function(c) { return c.charAt(1).toUpperCase(); }); - var prefixedDom = OpenLayers.Util.getVendorPrefixedDom(domProperty); + var prefixedDom = OpenLayers.Util.getVendorPrefixedObj(domProperty); cache[property] = domToCss(prefixedDom); } return cache[property]; @@ -1548,39 +1549,44 @@ OpenLayers.Util.getVendorPrefixedCss = (function() { })(); /** - * Method: getVendorPrefixedDom + * Method: getVendorPrefixedObj * * Parameters: + * object - {Object} Optional object to test for vendor-prefixed properties. Defaults to a DIV's style object. * property - {String} The standard DOM style property name * * Returns: * {String} The DOM style property name supported by the browser or null if * unsupported */ -OpenLayers.Util.getVendorPrefixedDom = (function() { +OpenLayers.Util.getVendorPrefixedObj = (function() { var cache = {}; - return function(property) { + return function getVendorPrefixedObj(obj, property) { + // emulate method overloading + if (typeof obj === "string") { + return getVendorPrefixedObj(document.createElement("div").style, obj); + } + // clear cache for tests if (property === "clear cache") { cache = {}; return; } if (cache[property] === undefined) { - var el = document.createElement("div"), - tmpProp, + var tmpProp, i = 0, - l = OpenLayers.Util.VENDOR_DOM_PREFIXES.length, + l = OpenLayers.Util.VENDOR_PREFIXES.length, prefix; cache[property] = null; - for(var i=0,l=OpenLayers.Util.VENDOR_DOM_PREFIXES.length; i Date: Sat, 23 Jun 2012 22:46:43 +0200 Subject: [PATCH 06/16] Style vendor prefixes should start with first char uppercase, js properties should be lower --- lib/OpenLayers/Util.js | 12 ++++++++---- tests/Util.html | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index ce84785701..254f4aa58e 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -1512,7 +1512,7 @@ OpenLayers.Util.getBrowserName = function() { * Constant: VENDOR_PREFIXES * {Array} A list of prefixes to test support for vendor-prefixed properties */ -OpenLayers.Util.VENDOR_PREFIXES = ["", "O", "ms", "Moz", "webkit"]; +OpenLayers.Util.VENDOR_PREFIXES = ["", "O", "ms", "Moz", "Webkit"]; /** * Method: getVendorPrefixedCss @@ -1530,8 +1530,7 @@ OpenLayers.Util.getVendorPrefixedCss = (function() { function domToCss(prefixedDom) { return prefixedDom. replace(/([A-Z])/g, function(char) { return "-" + char.toLowerCase(); }). - replace(/^ms-/, "-ms-"). - replace(/^webkit-/, "-webkit-"); + replace(/^ms-/, "-ms-"); } return function(property) { @@ -1575,12 +1574,17 @@ OpenLayers.Util.getVendorPrefixedObj = (function() { var tmpProp, i = 0, l = OpenLayers.Util.VENDOR_PREFIXES.length, - prefix; + prefix, + isStyleObj = (typeof obj.cssText !== "undefined"); cache[property] = null; for(var i=0,l=OpenLayers.Util.VENDOR_PREFIXES.length; i Date: Sun, 24 Jun 2012 23:48:24 +0200 Subject: [PATCH 07/16] Renamed char (reserved word in ES3) --- lib/OpenLayers/Util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 0693b38986..967c9fde99 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -1522,7 +1522,7 @@ OpenLayers.Util.getVendorPrefixedCss = (function() { function domToCss(prefixedDom) { return prefixedDom. - replace(/([A-Z])/g, function(char) { return "-" + char.toLowerCase(); }). + replace(/([A-Z])/g, function(c) { return "-" + c.toLowerCase(); }). replace(/^ms-/, "-ms-"); } From b394b93723cbc8e39c865e784745bfc198e4fd59 Mon Sep 17 00:00:00 2001 From: Gregers Gram Rygg Date: Mon, 25 Jun 2012 09:38:23 +0200 Subject: [PATCH 08/16] Removed unrelated changes --- tests/Util.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Util.html b/tests/Util.html index ba380348b1..e78fd71ed6 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -1199,7 +1199,7 @@ var loadEvent; window.onload = function(evt) { loadEvent = evt || window.event; - }; + } function test_extend_event(t) { t.plan(2); t.ok(loadEvent, "loadEvent recorded"); @@ -1215,7 +1215,6 @@ t.eq(extended && extended.foo, "bar", "extended with event"); } } - From 58a83b0d17da731551163fed61c39ff8f9614679 Mon Sep 17 00:00:00 2001 From: Gregers Gram Rygg Date: Mon, 25 Jun 2012 13:44:35 +0200 Subject: [PATCH 09/16] Refactored vendor methods to it's own module --- lib/OpenLayers.js | 1 + lib/OpenLayers/Control/PinchZoom.js | 2 +- lib/OpenLayers/Util.js | 92 ------------------- lib/OpenLayers/Vendor.js | 136 ++++++++++++++++++++++++++++ tests/Util.html | 81 ----------------- tests/Vendor.html | 118 ++++++++++++++++++++++++ tests/list-tests.html | 1 + 7 files changed, 257 insertions(+), 174 deletions(-) create mode 100644 lib/OpenLayers/Vendor.js create mode 100644 tests/Vendor.html diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index 676549fca5..672ebdde97 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -132,6 +132,7 @@ jsFiles = [ "OpenLayers/BaseTypes/Class.js", "OpenLayers/Util.js", + "OpenLayers/Vendor.js", "OpenLayers/Animation.js", "OpenLayers/BaseTypes.js", "OpenLayers/BaseTypes/Bounds.js", diff --git a/lib/OpenLayers/Control/PinchZoom.js b/lib/OpenLayers/Control/PinchZoom.js index e7e3827e1d..44492d404d 100644 --- a/lib/OpenLayers/Control/PinchZoom.js +++ b/lib/OpenLayers/Control/PinchZoom.js @@ -162,7 +162,7 @@ OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, { */ applyTransform: function(transform) { var style = this.map.layerContainerDiv.style; - var transformProperty = OpenLayers.Util.getVendorPrefixedObj("transform"); + var transformProperty = OpenLayers.Vendor.stylePrefix("transform"); if (transformProperty) { style[transformProperty] = transform; } diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 967c9fde99..562ca489f6 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -1501,98 +1501,6 @@ OpenLayers.Util.getBrowserName = function() { return OpenLayers.BROWSER_NAME; }; -/** - * Constant: VENDOR_PREFIXES - * {Array} A list of prefixes to test support for vendor-prefixed properties - */ -OpenLayers.Util.VENDOR_PREFIXES = ["", "O", "ms", "Moz", "Webkit"]; - -/** - * Method: getVendorPrefixedCss - * - * Parameters: - * property - {String} The standard CSS property name - * - * Returns: - * {String} The CSS property name supported by the browser or null if - * unsupported - */ -OpenLayers.Util.getVendorPrefixedCss = (function() { - var cache = {}; - - function domToCss(prefixedDom) { - return prefixedDom. - replace(/([A-Z])/g, function(c) { return "-" + c.toLowerCase(); }). - replace(/^ms-/, "-ms-"); - } - - return function(property) { - // clear cache for tests - if (property === "clear cache") { cache = {}; return; } - - if (cache[property] === undefined) { - var domProperty = property. - replace(/(-.)/g, function(c) { return c.charAt(1).toUpperCase(); }); - var prefixedDom = OpenLayers.Util.getVendorPrefixedObj(domProperty); - cache[property] = domToCss(prefixedDom); - } - return cache[property]; - }; -})(); - -/** - * Method: getVendorPrefixedObj - * - * Parameters: - * object - {Object} Optional object to test for vendor-prefixed properties. Defaults to a DIV's style object. - * property - {String} The standard DOM style property name - * - * Returns: - * {String} The DOM style property name supported by the browser or null if - * unsupported - */ -OpenLayers.Util.getVendorPrefixedObj = (function() { - var cache = {}; - - return function getVendorPrefixedObj(obj, property) { - // emulate method overloading - if (typeof obj === "string") { - return getVendorPrefixedObj(document.createElement("div").style, obj); - } - - // clear cache for tests - if (property === "clear cache") { cache = {}; return; } - - if (cache[property] === undefined) { - var tmpProp, - i = 0, - l = OpenLayers.Util.VENDOR_PREFIXES.length, - prefix, - isStyleObj = (typeof obj.cssText !== "undefined"); - - cache[property] = null; - for(var i=0,l=OpenLayers.Util.VENDOR_PREFIXES.length; i transform-origin + * or WebkitTransformOrigin -> -webkit-transform-origin + * + * Parameters: + * prefixedDom - {String} The property to convert + * + * Returns: + * {String} The CSS property + */ + function domToCss(prefixedDom) { + if (!prefixedDom) { return null; } + return prefixedDom. + replace(/([A-Z])/g, function(c) { return "-" + c.toLowerCase(); }). + replace(/^ms-/, "-ms-"); + } + + /** + * APIMethod: cssPrefix + * Detect which property is used for a CSS property + * + * Parameters: + * property - {String} The standard (unprefixed) CSS property name + * + * Returns: + * {String} The standard CSS property, prefixed property or null if not + * supported + */ + function cssPrefix(property) { + if (cssCache[property] === undefined) { + var domProperty = property. + replace(/(-[\s\S])/g, function(c) { return c.charAt(1).toUpperCase(); }); + var prefixedDom = stylePrefix(domProperty); + cssCache[property] = domToCss(prefixedDom); + } + return cssCache[property]; + } + + /** + * APIMethod: jsPrefix + * Detect which property is used for a JS property/method + * + * Parameters: + * obj - {Object} The object to test on + * property - {String} The standard (unprefixed) JS property name + * + * Returns: + * {String} The standard JS property, prefixed property or null if not + * supported + */ + function jsPrefix(obj, property) { + if (jsCache[property] === undefined) { + var tmpProp, + i = 0, + l = VENDOR_PREFIXES.length, + prefix, + isStyleObj = (typeof obj.cssText !== "undefined"); + + jsCache[property] = null; + for(var i=0,l=VENDOR_PREFIXES.length; i + + + Vendor.js Tests + + + + + + + \ No newline at end of file diff --git a/tests/list-tests.html b/tests/list-tests.html index c883ed34d7..0b544f22f7 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -231,6 +231,7 @@
  • Tween.html
  • Kinetic.html
  • Util.html
  • +
  • Vendor.html
  • deprecated/Ajax.html
  • deprecated/Util.html
  • deprecated/BaseTypes/Class.html
  • From ab6b2ef008203bc29c4eddaf231889baa889ed85 Mon Sep 17 00:00:00 2001 From: Gregers Gram Rygg Date: Mon, 25 Jun 2012 13:45:33 +0200 Subject: [PATCH 10/16] Use vendor detection for requestAnimationFrame --- lib/OpenLayers/Animation.js | 14 ++++---------- tests/Animation.html | 1 + 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/OpenLayers/Animation.js b/lib/OpenLayers/Animation.js index cadc14dedb..4a4ccc5637 100644 --- a/lib/OpenLayers/Animation.js +++ b/lib/OpenLayers/Animation.js @@ -5,6 +5,7 @@ * full text of the license. * * @requires OpenLayers/SingleFile.js + * @requires OpenLayers/Vendor.js */ /** @@ -19,11 +20,8 @@ OpenLayers.Animation = (function(window) { * Property: isNative * {Boolean} true if a native requestAnimationFrame function is available */ - var isNative = !!(window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame || - window.msRequestAnimationFrame); + var requestAnimationFrame = OpenLayers.Vendor.jsPrefix(window, "requestAnimationFrame"); + var isNative = !!(requestAnimationFrame); /** * Function: requestFrame @@ -36,11 +34,7 @@ OpenLayers.Animation = (function(window) { * element - {DOMElement} Optional element that visually bounds the animation. */ var requestFrame = (function() { - var request = window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame || - window.msRequestAnimationFrame || + var request = window[requestAnimationFrame] || function(callback, element) { window.setTimeout(callback, 16); }; diff --git a/tests/Animation.html b/tests/Animation.html index f113690933..b07308d3e0 100644 --- a/tests/Animation.html +++ b/tests/Animation.html @@ -6,6 +6,7 @@ // dependencies for tests var OpenLayers = [ + "OpenLayers/Vendor.js", "OpenLayers/Animation.js" ]; From f40d677164c1044f41fecce0f9f4c65e68d5c15d Mon Sep 17 00:00:00 2001 From: Gregers Gram Rygg Date: Wed, 27 Jun 2012 11:07:41 +0200 Subject: [PATCH 11/16] Removed declaration of OpenLayers if it's not defined (already requires SingleFile.js) --- lib/OpenLayers/Vendor.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/OpenLayers/Vendor.js b/lib/OpenLayers/Vendor.js index 0bf23916e3..7b7d6e74f2 100644 --- a/lib/OpenLayers/Vendor.js +++ b/lib/OpenLayers/Vendor.js @@ -6,12 +6,11 @@ * * @requires OpenLayers/SingleFile.js */ - + /** * Namespace: OpenLayers.Vendor * A collection of utility functions to detect vendor prefixed features */ -var OpenLayers = OpenLayers || {}; OpenLayers.Vendor = (function() { "use strict"; From d1ed8bb952b427a439236d089de674bc36b29031 Mon Sep 17 00:00:00 2001 From: Gregers Gram Rygg Date: Wed, 27 Jun 2012 11:57:04 +0200 Subject: [PATCH 12/16] Removed duplicate declarations of i and l --- lib/OpenLayers/Vendor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Vendor.js b/lib/OpenLayers/Vendor.js index 7b7d6e74f2..47a477e910 100644 --- a/lib/OpenLayers/Vendor.js +++ b/lib/OpenLayers/Vendor.js @@ -81,7 +81,7 @@ OpenLayers.Vendor = (function() { isStyleObj = (typeof obj.cssText !== "undefined"); jsCache[property] = null; - for(var i=0,l=VENDOR_PREFIXES.length; i Date: Wed, 27 Jun 2012 12:39:47 +0200 Subject: [PATCH 13/16] Expose caches instead of _clearCache method --- lib/OpenLayers/Vendor.js | 6 ++---- tests/Vendor.html | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/OpenLayers/Vendor.js b/lib/OpenLayers/Vendor.js index 47a477e910..b0e271009c 100644 --- a/lib/OpenLayers/Vendor.js +++ b/lib/OpenLayers/Vendor.js @@ -124,10 +124,8 @@ OpenLayers.Vendor = (function() { stylePrefix: stylePrefix, // used for testing - _clearCache: function() { - cssCache = {}; - jsCache = {}; - }, + cssCache: cssCache, + jsCache: jsCache, _mockStyle: function(mock) { divStyle = mock; } diff --git a/tests/Vendor.html b/tests/Vendor.html index 2979d8d1aa..1e7b205d00 100644 --- a/tests/Vendor.html +++ b/tests/Vendor.html @@ -35,11 +35,18 @@ return el; };*/ + function clearCache(type) { + var cache = OpenLayers.Vendor[type.replace("style", "js") + "Cache"]; + for (var key in cache) { + delete cache[key]; + } + } + function curryTestPrefix(type) { return function(standardProp, expectedPrefix, msg) { var prefixedProp, err, method = type + "Prefix"; try { - OpenLayers.Vendor._clearCache(); + clearCache(type); var fakeStyle = { cssText: "" }; if (o.prop != null) { fakeStyle[o.prop] = o.val; @@ -90,22 +97,22 @@ testCssPrefix("multi-word", "-ms-multi-word", "CSS vendor prefix - multiple words for Internet Explorer"); // test vendor prefix on object - OpenLayers.Vendor._clearCache(); + clearCache("js"); t.eq( OpenLayers.Vendor.jsPrefix( {}, "unsupported" ), null, "Standard object property - unsupported"); - OpenLayers.Vendor._clearCache(); + clearCache("js"); t.eq( OpenLayers.Vendor.jsPrefix( { "test": true }, "test" ), "test", "Standard object property"); - OpenLayers.Vendor._clearCache(); + clearCache("js"); t.eq( OpenLayers.Vendor.jsPrefix( { "oTest": true }, "test" ), "oTest", "Standard object property"); - OpenLayers.Vendor._clearCache(); + clearCache("js"); t.eq( OpenLayers.Vendor.jsPrefix( { "msTest": true }, "test" ), "msTest", "Standard object property"); - OpenLayers.Vendor._clearCache(); + clearCache("js"); t.eq( OpenLayers.Vendor.jsPrefix( { "mozTest": true }, "test" ), "mozTest", "Standard object property"); - OpenLayers.Vendor._clearCache(); + clearCache("js"); t.eq( OpenLayers.Vendor.jsPrefix( { "webkitTest": true }, "test" ), "webkitTest", "Standard object property"); // unwrap document.createElement From 7f32342ec38002fb5ae516dd44874034acc506ab Mon Sep 17 00:00:00 2001 From: Gregers Gram Rygg Date: Wed, 27 Jun 2012 13:28:43 +0200 Subject: [PATCH 14/16] Moved OpenLayers.Vendor to OpenLayers.Util.vendorPrefix --- lib/OpenLayers.js | 2 +- lib/OpenLayers/Animation.js | 4 ++-- lib/OpenLayers/Control/PinchZoom.js | 3 ++- .../{Vendor.js => Util/vendorPrefix.js} | 7 +++--- tests/Animation.html | 2 +- tests/{Vendor.html => Util/vendorPrefix.html} | 24 +++++++++---------- tests/list-tests.html | 2 +- 7 files changed, 23 insertions(+), 21 deletions(-) rename lib/OpenLayers/{Vendor.js => Util/vendorPrefix.js} (96%) rename tests/{Vendor.html => Util/vendorPrefix.html} (77%) diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index 672ebdde97..0399d2c1fa 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -132,7 +132,7 @@ jsFiles = [ "OpenLayers/BaseTypes/Class.js", "OpenLayers/Util.js", - "OpenLayers/Vendor.js", + "OpenLayers/Util/vendorPrefix.js", "OpenLayers/Animation.js", "OpenLayers/BaseTypes.js", "OpenLayers/BaseTypes/Bounds.js", diff --git a/lib/OpenLayers/Animation.js b/lib/OpenLayers/Animation.js index 4a4ccc5637..3507652252 100644 --- a/lib/OpenLayers/Animation.js +++ b/lib/OpenLayers/Animation.js @@ -5,7 +5,7 @@ * full text of the license. * * @requires OpenLayers/SingleFile.js - * @requires OpenLayers/Vendor.js + * @requires OpenLayers/Util/vendorPrefix.js */ /** @@ -20,7 +20,7 @@ OpenLayers.Animation = (function(window) { * Property: isNative * {Boolean} true if a native requestAnimationFrame function is available */ - var requestAnimationFrame = OpenLayers.Vendor.jsPrefix(window, "requestAnimationFrame"); + var requestAnimationFrame = OpenLayers.Util.vendorPrefix.jsPrefix(window, "requestAnimationFrame"); var isNative = !!(requestAnimationFrame); /** diff --git a/lib/OpenLayers/Control/PinchZoom.js b/lib/OpenLayers/Control/PinchZoom.js index 44492d404d..d42cfd15ba 100644 --- a/lib/OpenLayers/Control/PinchZoom.js +++ b/lib/OpenLayers/Control/PinchZoom.js @@ -4,6 +4,7 @@ * full text of the license. */ /** + * @requires OpenLayers/Util/vendorPrefix.js * @requires OpenLayers/Handler/Pinch.js */ @@ -162,7 +163,7 @@ OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, { */ applyTransform: function(transform) { var style = this.map.layerContainerDiv.style; - var transformProperty = OpenLayers.Vendor.stylePrefix("transform"); + var transformProperty = OpenLayers.Util.vendorPrefix.stylePrefix("transform"); if (transformProperty) { style[transformProperty] = transform; } diff --git a/lib/OpenLayers/Vendor.js b/lib/OpenLayers/Util/vendorPrefix.js similarity index 96% rename from lib/OpenLayers/Vendor.js rename to lib/OpenLayers/Util/vendorPrefix.js index b0e271009c..2bb760725d 100644 --- a/lib/OpenLayers/Vendor.js +++ b/lib/OpenLayers/Util/vendorPrefix.js @@ -6,12 +6,13 @@ * * @requires OpenLayers/SingleFile.js */ - + +OpenLayers.Util = OpenLayers.Util || {}; /** - * Namespace: OpenLayers.Vendor + * Namespace: OpenLayers.Util.vendorPrefix * A collection of utility functions to detect vendor prefixed features */ -OpenLayers.Vendor = (function() { +OpenLayers.Util.vendorPrefix = (function() { "use strict"; var VENDOR_PREFIXES = ["", "O", "ms", "Moz", "Webkit"], diff --git a/tests/Animation.html b/tests/Animation.html index b07308d3e0..c24ae49363 100644 --- a/tests/Animation.html +++ b/tests/Animation.html @@ -6,7 +6,7 @@ // dependencies for tests var OpenLayers = [ - "OpenLayers/Vendor.js", + "OpenLayers/Util/vendorPrefix.js", "OpenLayers/Animation.js" ]; diff --git a/tests/Vendor.html b/tests/Util/vendorPrefix.html similarity index 77% rename from tests/Vendor.html rename to tests/Util/vendorPrefix.html index 1e7b205d00..7978a8a3fa 100644 --- a/tests/Vendor.html +++ b/tests/Util/vendorPrefix.html @@ -1,16 +1,16 @@ - Vendor.js Tests + vendorPrefix.js Tests - +