L.Browser and translate refactor and cleanup

This commit is contained in:
Vladimir Agafonkin 2012-06-25 18:58:37 +03:00
parent 99dd46b538
commit 2ac4a6d364
4 changed files with 114 additions and 103 deletions

109
dist/leaflet-src.js vendored
View File

@ -291,61 +291,64 @@ L.Mixin.Events.fire = L.Mixin.Events.fireEvent;
(function () {
var ua = navigator.userAgent.toLowerCase(),
ie = !!window.ActiveXObject,
ie6 = ie && !window.XMLHttpRequest,
webkit = ua.indexOf("webkit") !== -1,
gecko = ua.indexOf("gecko") !== -1,
mobile = typeof orientation !== 'undefined' ? true : false,
opera = window.opera,
android = ua.indexOf("android") !== -1,
opera = window.opera;
mobile = typeof orientation !== 'undefined' ? true : false,
doc = document.documentElement,
ie3d = ie && ('transition' in doc.style),
webkit3d = webkit && ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()),
gecko3d = gecko && ('MozPerspective' in doc.style),
opera3d = opera && ('OTransition' in doc.style);
var touch = (function () {
var startName = 'ontouchstart';
// WebKit, etc
if (startName in doc) {
return true;
}
// Firefox/Gecko
var div = document.createElement('div'),
supported = false;
if (!div.setAttribute) {
return false;
}
div.setAttribute(startName, 'return;');
if (typeof div[startName] === 'function') {
supported = true;
}
div.removeAttribute(startName);
div = null;
return supported;
}());
L.Browser = {
ie: ie,
ie6: ie && !window.XMLHttpRequest,
ie3d: ie && ('transition' in document.createElement('div').style),
ie6: ie6,
webkit: webkit,
webkit3d: webkit && ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()),
gecko: gecko,
gecko3d: gecko && ('MozPerspective' in document.createElement('div').style),
opera: opera,
opera3d: opera && ('OTransition' in document.createElement('div').style),
android: android,
mobileWebkit: mobile && webkit,
mobileOpera: mobile && opera,
ie3d: ie3d,
webkit3d: webkit3d,
gecko3d: gecko3d,
opera3d: opera3d,
any3d: ie3d || webkit3d || gecko3d || opera3d,
mobile: mobile,
touch: (function () {
var touchSupported = false,
startName = 'ontouchstart';
// WebKit, etc
if (startName in document.documentElement) {
return true;
}
// Firefox/Gecko
var e = document.createElement('div');
// If no support for basic event stuff, unlikely to have touch support
if (!e.setAttribute || !e.removeAttribute) {
return false;
}
e.setAttribute(startName, 'return;');
if (typeof e[startName] === 'function') {
touchSupported = true;
}
e.removeAttribute(startName);
e = null;
return touchSupported;
}())
mobileWebkit: mobile && webkit,
mobileWebkit3d: mobile && webkit3d,
mobileOpera: mobile && opera
};
L.Browser.any3d = !!L.Browser.webkit3d || !!L.Browser.gecko3d || !!L.Browser.opera3d || !!L.Browser.ie3d;
}());
@ -641,9 +644,11 @@ L.DomUtil = {
},
getTranslateString: function (point) {
return L.DomUtil.TRANSLATE_OPEN +
point.x + 'px,' + point.y + 'px' +
L.DomUtil.TRANSLATE_CLOSE;
var is3d = L.Browser.mobileWebkit3d,
open = 'translate' + (is3d ? '3d' : '') + '(',
close = (is3d ? ',0' : '') + ')';
return open + point.x + 'px,' + point.y + 'px' + close;
},
getScaleString: function (scale, origin) {
@ -658,7 +663,10 @@ L.DomUtil = {
el._leaflet_pos = point;
if (!disable3D && L.Browser.any3d) {
el.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(point);
el.style[L.DomUtil.BACKFACEVISIBILITY] = 'hidden';
if (L.Browser.mobileWebkit3d) {
el.style.WebkitBackfaceVisibility = 'hidden';
}
} else {
el.style.left = point.x + 'px';
el.style.top = point.y + 'px';
@ -672,11 +680,7 @@ L.DomUtil = {
L.Util.extend(L.DomUtil, {
TRANSITION: L.DomUtil.testProp(['transition', 'webkitTransition', 'OTransition', 'MozTransition', 'msTransition']),
TRANSFORM: L.DomUtil.testProp(['transform', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform']),
BACKFACEVISIBILITY: L.DomUtil.testProp(['backfaceVisibility', 'WebkitBackfaceVisibility', 'OBackfaceVisibility', 'MozBackfaceVisibility', 'msBackfaceVisibility']),
TRANSLATE_OPEN: 'translate' + (L.Browser.webkit3d ? '3d(' : '('),
TRANSLATE_CLOSE: L.Browser.webkit3d ? ',0)' : ')'
TRANSFORM: L.DomUtil.testProp(['transform', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform'])
});
@ -4735,6 +4739,9 @@ L.Draggable = L.Class.extend({
L.DomEvent.removeListener(document, L.Draggable.END, this._onUp);
if (this._moved) {
// ensure drag is not fired after dragend
L.Util.cancelAnimFrame(this._animRequest);
this.fire('dragend');
}
this._moving = false;

2
dist/leaflet.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,59 +1,62 @@
(function () {
var ua = navigator.userAgent.toLowerCase(),
ie = !!window.ActiveXObject,
ie6 = ie && !window.XMLHttpRequest,
webkit = ua.indexOf("webkit") !== -1,
gecko = ua.indexOf("gecko") !== -1,
mobile = typeof orientation !== 'undefined' ? true : false,
opera = window.opera,
android = ua.indexOf("android") !== -1,
opera = window.opera;
mobile = typeof orientation !== 'undefined' ? true : false,
doc = document.documentElement,
ie3d = ie && ('transition' in doc.style),
webkit3d = webkit && ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()),
gecko3d = gecko && ('MozPerspective' in doc.style),
opera3d = opera && ('OTransition' in doc.style);
var touch = (function () {
var startName = 'ontouchstart';
// WebKit, etc
if (startName in doc) {
return true;
}
// Firefox/Gecko
var div = document.createElement('div'),
supported = false;
if (!div.setAttribute) {
return false;
}
div.setAttribute(startName, 'return;');
if (typeof div[startName] === 'function') {
supported = true;
}
div.removeAttribute(startName);
div = null;
return supported;
}());
L.Browser = {
ie: ie,
ie6: ie && !window.XMLHttpRequest,
ie3d: ie && ('transition' in document.createElement('div').style),
ie6: ie6,
webkit: webkit,
webkit3d: webkit && ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()),
gecko: gecko,
gecko3d: gecko && ('MozPerspective' in document.createElement('div').style),
opera: opera,
opera3d: opera && ('OTransition' in document.createElement('div').style),
android: android,
mobileWebkit: mobile && webkit,
mobileOpera: mobile && opera,
ie3d: ie3d,
webkit3d: webkit3d,
gecko3d: gecko3d,
opera3d: opera3d,
any3d: ie3d || webkit3d || gecko3d || opera3d,
mobile: mobile,
touch: (function () {
var touchSupported = false,
startName = 'ontouchstart';
// WebKit, etc
if (startName in document.documentElement) {
return true;
}
// Firefox/Gecko
var e = document.createElement('div');
// If no support for basic event stuff, unlikely to have touch support
if (!e.setAttribute || !e.removeAttribute) {
return false;
}
e.setAttribute(startName, 'return;');
if (typeof e[startName] === 'function') {
touchSupported = true;
}
e.removeAttribute(startName);
e = null;
return touchSupported;
}())
mobileWebkit: mobile && webkit,
mobileWebkit3d: mobile && webkit3d,
mobileOpera: mobile && opera
};
L.Browser.any3d = !!L.Browser.webkit3d || !!L.Browser.gecko3d || !!L.Browser.opera3d || !!L.Browser.ie3d;
}());

View File

@ -124,9 +124,11 @@ L.DomUtil = {
},
getTranslateString: function (point) {
return L.DomUtil.TRANSLATE_OPEN +
point.x + 'px,' + point.y + 'px' +
L.DomUtil.TRANSLATE_CLOSE;
var is3d = L.Browser.mobileWebkit3d,
open = 'translate' + (is3d ? '3d' : '') + '(',
close = (is3d ? ',0' : '') + ')';
return open + point.x + 'px,' + point.y + 'px' + close;
},
getScaleString: function (scale, origin) {
@ -141,7 +143,10 @@ L.DomUtil = {
el._leaflet_pos = point;
if (!disable3D && L.Browser.any3d) {
el.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(point);
el.style[L.DomUtil.BACKFACEVISIBILITY] = 'hidden';
if (L.Browser.mobileWebkit3d) {
el.style.WebkitBackfaceVisibility = 'hidden';
}
} else {
el.style.left = point.x + 'px';
el.style.top = point.y + 'px';
@ -155,9 +160,5 @@ L.DomUtil = {
L.Util.extend(L.DomUtil, {
TRANSITION: L.DomUtil.testProp(['transition', 'webkitTransition', 'OTransition', 'MozTransition', 'msTransition']),
TRANSFORM: L.DomUtil.testProp(['transform', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform']),
BACKFACEVISIBILITY: L.DomUtil.testProp(['backfaceVisibility', 'WebkitBackfaceVisibility', 'OBackfaceVisibility', 'MozBackfaceVisibility', 'msBackfaceVisibility']),
TRANSLATE_OPEN: 'translate' + (L.Browser.webkit3d ? '3d(' : '('),
TRANSLATE_CLOSE: L.Browser.webkit3d ? ',0)' : ')'
TRANSFORM: L.DomUtil.testProp(['transform', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform'])
});