From 25b6290f4dae65e8f864289440aff1861f676298 Mon Sep 17 00:00:00 2001 From: tyr Date: Thu, 6 Dec 2012 09:04:28 +0100 Subject: [PATCH 1/5] cutomizable prefix grabber. proper support3d test. removed -o- prefix from transform property. --- js/id/renderer/map.js | 17 +++++++++++++++-- js/id/util.js | 5 +++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index fcad51151..25b911a87 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -53,8 +53,21 @@ iD.Map = function() { class_fill = iD.Style.styleClasses('stroke'), class_area = iD.Style.styleClasses('area'), class_casing = iD.Style.styleClasses('casing'), - transformProp = iD.util.prefix() + 'transform', - support3d = iD.util.prefix() === 'O', + transformProp = iD.util.prefix(['webkit', 'ms', 'Moz']) + 'transform', + support3d = (function() { + // test for translate3d support. Based on https://gist.github.com/3794226 by lorenzopolidori and webinista + var el = document.createElement('div'), + has3d = false, + transform = iD.util.prefix(['webkit', 'ms', 'Moz']) + 'transform'; + document.body.insertBefore(el,null); + if (el.style[transform] !== undefined) { + el.style[transform] = 'translate3d(1px,1px,1px)'; + has3d = window.getComputedStyle(el).getPropertyValue(transform); + } + document.body.removeChild(el); + + return (has3d && has3d.length>0 && has3d!=="none"); + })(), supersurface, surface, defs, tilegroup, r, g, alength; function map() { diff --git a/js/id/util.js b/js/id/util.js index bcde828ea..46ff08448 100644 --- a/js/id/util.js +++ b/js/id/util.js @@ -64,12 +64,13 @@ iD.util.qsString = function(obj) { }).join('&'); }; -iD.util.prefix = function() { +iD.util.prefix = function(browsers) { + if (!browsers) browsers = ['webkit', 'ms', 'Moz', 'O']; return (function prefixMatch(p) { // via mbostock var i = -1, n = p.length, s = document.body.style; while (++i < n) if (p[i] + 'Transform' in s) return '-' + p[i].toLowerCase() + '-'; return ''; - })(['webkit', 'ms', 'Moz', 'O']); + })(browsers); }; iD.util.geo = {}; From e4ceca76ecea35e32a849e0c60f59240f55f5b55 Mon Sep 17 00:00:00 2001 From: tyr Date: Thu, 6 Dec 2012 10:32:02 +0100 Subject: [PATCH 2/5] more clever prefix detection. (use unprefixed property when available.) --- js/id/renderer/map.js | 2 +- js/id/util.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index 25b911a87..cc754d875 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -53,7 +53,7 @@ iD.Map = function() { class_fill = iD.Style.styleClasses('stroke'), class_area = iD.Style.styleClasses('area'), class_casing = iD.Style.styleClasses('casing'), - transformProp = iD.util.prefix(['webkit', 'ms', 'Moz']) + 'transform', + transformProp = iD.util.prefixProperty('Transform'), support3d = (function() { // test for translate3d support. Based on https://gist.github.com/3794226 by lorenzopolidori and webinista var el = document.createElement('div'), diff --git a/js/id/util.js b/js/id/util.js index 46ff08448..817958f04 100644 --- a/js/id/util.js +++ b/js/id/util.js @@ -72,6 +72,15 @@ iD.util.prefix = function(browsers) { return ''; })(browsers); }; +iD.util.prefixProperty = function(property) { + prefixes = ['webkit', 'ms', 'Moz', 'O']; + return (function prefixMatch(p) { // via mbostock + var i = -1, n = p.length, s = document.body.style; + if (property.toLowerCase() in s) return property.toLowerCase(); + while (++i < n) if (p[i] + property in s) return '-' + p[i].toLowerCase() + '-' + property.toLowerCase(); + return ''; + })(prefixes); +}; iD.util.geo = {}; From 2b84eaad73b9ded5913e5cfea089f9e79c92772b Mon Sep 17 00:00:00 2001 From: tyr Date: Thu, 6 Dec 2012 10:42:45 +0100 Subject: [PATCH 3/5] removed now obsolete prefix() utility method --- js/id/util.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/js/id/util.js b/js/id/util.js index 817958f04..10c230fd4 100644 --- a/js/id/util.js +++ b/js/id/util.js @@ -64,14 +64,6 @@ iD.util.qsString = function(obj) { }).join('&'); }; -iD.util.prefix = function(browsers) { - if (!browsers) browsers = ['webkit', 'ms', 'Moz', 'O']; - return (function prefixMatch(p) { // via mbostock - var i = -1, n = p.length, s = document.body.style; - while (++i < n) if (p[i] + 'Transform' in s) return '-' + p[i].toLowerCase() + '-'; - return ''; - })(browsers); -}; iD.util.prefixProperty = function(property) { prefixes = ['webkit', 'ms', 'Moz', 'O']; return (function prefixMatch(p) { // via mbostock From 87252a73f1188004357ab4129ed45383bf4a3c65 Mon Sep 17 00:00:00 2001 From: tyr Date: Thu, 6 Dec 2012 11:09:09 +0100 Subject: [PATCH 4/5] fixed support3d to reuse transformProp. prefixProperty returns false instead of "" when the property isn't supported at all --- js/id/renderer/map.js | 10 ++++------ js/id/util.js | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index cc754d875..b3e2a54c1 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -57,15 +57,13 @@ iD.Map = function() { support3d = (function() { // test for translate3d support. Based on https://gist.github.com/3794226 by lorenzopolidori and webinista var el = document.createElement('div'), - has3d = false, - transform = iD.util.prefix(['webkit', 'ms', 'Moz']) + 'transform'; + has3d = false; document.body.insertBefore(el,null); - if (el.style[transform] !== undefined) { - el.style[transform] = 'translate3d(1px,1px,1px)'; - has3d = window.getComputedStyle(el).getPropertyValue(transform); + if (el.style[transformProp] !== undefined) { + el.style[transformProp] = 'translate3d(1px,1px,1px)'; + has3d = window.getComputedStyle(el).getPropertyValue(transformProp); } document.body.removeChild(el); - return (has3d && has3d.length>0 && has3d!=="none"); })(), supersurface, surface, defs, tilegroup, r, g, alength; diff --git a/js/id/util.js b/js/id/util.js index 10c230fd4..41e14ede0 100644 --- a/js/id/util.js +++ b/js/id/util.js @@ -70,7 +70,7 @@ iD.util.prefixProperty = function(property) { var i = -1, n = p.length, s = document.body.style; if (property.toLowerCase() in s) return property.toLowerCase(); while (++i < n) if (p[i] + property in s) return '-' + p[i].toLowerCase() + '-' + property.toLowerCase(); - return ''; + return false; })(prefixes); }; From b18fa96f952c6a3f1e73c081164d8150678fc62e Mon Sep 17 00:00:00 2001 From: tyr Date: Thu, 6 Dec 2012 11:37:57 +0100 Subject: [PATCH 5/5] fixed global var leak --- js/id/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/id/util.js b/js/id/util.js index 41e14ede0..7128673f0 100644 --- a/js/id/util.js +++ b/js/id/util.js @@ -65,7 +65,7 @@ iD.util.qsString = function(obj) { }; iD.util.prefixProperty = function(property) { - prefixes = ['webkit', 'ms', 'Moz', 'O']; + var prefixes = ['webkit', 'ms', 'Moz', 'O']; return (function prefixMatch(p) { // via mbostock var i = -1, n = p.length, s = document.body.style; if (property.toLowerCase() in s) return property.toLowerCase();