aboutsummaryrefslogtreecommitdiffstats
path: root/extlib/leaflet/src/dom
diff options
context:
space:
mode:
Diffstat (limited to 'extlib/leaflet/src/dom')
-rw-r--r--extlib/leaflet/src/dom/DomEvent.DoubleTap.js41
-rw-r--r--extlib/leaflet/src/dom/DomEvent.js132
-rw-r--r--extlib/leaflet/src/dom/DomUtil.js124
-rw-r--r--extlib/leaflet/src/dom/Draggable.js129
-rw-r--r--extlib/leaflet/src/dom/transition/Transition.Native.js89
-rw-r--r--extlib/leaflet/src/dom/transition/Transition.Timer.js124
-rw-r--r--extlib/leaflet/src/dom/transition/Transition.js28
7 files changed, 667 insertions, 0 deletions
diff --git a/extlib/leaflet/src/dom/DomEvent.DoubleTap.js b/extlib/leaflet/src/dom/DomEvent.DoubleTap.js
new file mode 100644
index 00000000..08bd79b9
--- /dev/null
+++ b/extlib/leaflet/src/dom/DomEvent.DoubleTap.js
@@ -0,0 +1,41 @@
+L.Util.extend(L.DomEvent, {
+ // inspired by Zepto touch code by Thomas Fuchs
+ addDoubleTapListener: function(obj, handler, id) {
+ var last,
+ doubleTap = false,
+ delay = 250,
+ touch,
+ pre = '_leaflet_',
+ touchstart = 'touchstart',
+ touchend = 'touchend';
+
+ function onTouchStart(e) {
+ if (e.touches.length != 1) return;
+
+ var now = Date.now(),
+ delta = now - (last || now);
+
+ touch = e.touches[0];
+ doubleTap = (delta > 0 && delta <= delay);
+ last = now;
+ }
+ function onTouchEnd(e) {
+ if (doubleTap) {
+ touch.type = 'dblclick';
+ handler(touch);
+ last = null;
+ }
+ }
+ obj[pre + touchstart + id] = onTouchStart;
+ obj[pre + touchend + id] = onTouchEnd;
+
+ obj.addEventListener(touchstart, onTouchStart, false);
+ obj.addEventListener(touchend, onTouchEnd, false);
+ },
+
+ removeDoubleTapListener: function(obj, id) {
+ var pre = '_leaflet_';
+ obj.removeEventListener(obj, obj[pre + 'touchstart' + id], false);
+ obj.removeEventListener(obj, obj[pre + 'touchend' + id], false);
+ }
+}); \ No newline at end of file
diff --git a/extlib/leaflet/src/dom/DomEvent.js b/extlib/leaflet/src/dom/DomEvent.js
new file mode 100644
index 00000000..bcabebc2
--- /dev/null
+++ b/extlib/leaflet/src/dom/DomEvent.js
@@ -0,0 +1,132 @@
+/*
+ * L.DomEvent contains functions for working with DOM events.
+ */
+
+L.DomEvent = {
+ /* inpired by John Resig, Dean Edwards and YUI addEvent implementations */
+ addListener: function(/*HTMLElement*/ obj, /*String*/ type, /*Function*/ fn, /*Object*/ context) {
+ var id = L.Util.stamp(fn);
+
+ function handler(e) {
+ return fn.call(context || obj, e || L.DomEvent._getEvent());
+ }
+
+ if (L.Browser.touch && (type == 'dblclick') && this.addDoubleTapListener) {
+ this.addDoubleTapListener(obj, handler, id);
+ } else if ('addEventListener' in obj) {
+ if (type == 'mousewheel') {
+ obj.addEventListener('DOMMouseScroll', handler, false);
+ obj.addEventListener(type, handler, false);
+ } else if ((type == 'mouseenter') || (type == 'mouseleave')) {
+ var originalHandler = handler,
+ newType = (type == 'mouseenter' ? 'mouseover' : 'mouseout');
+ handler = function(e) {
+ if (!L.DomEvent._checkMouse(obj, e)) return;
+ return originalHandler(e);
+ };
+ obj.addEventListener(newType, handler, false);
+ } else {
+ obj.addEventListener(type, handler, false);
+ }
+ } else if ('attachEvent' in obj) {
+ obj.attachEvent("on" + type, handler);
+ }
+
+ obj['_leaflet_' + type + id] = handler;
+ },
+
+ removeListener: function(/*HTMLElement*/ obj, /*String*/ type, /*Function*/ fn) {
+ var id = L.Util.stamp(fn),
+ key = '_leaflet_' + type + id;
+ handler = obj[key];
+
+ if (L.Browser.mobileWebkit && (type == 'dblclick') && this.removeDoubleTapListener) {
+ this.removeDoubleTapListener(obj, id);
+ } else if ('removeEventListener' in obj) {
+ if (type == 'mousewheel') {
+ obj.removeEventListener('DOMMouseScroll', handler, false);
+ obj.removeEventListener(type, handler, false);
+ } else if ((type == 'mouseenter') || (type == 'mouseleave')) {
+ obj.removeEventListener((type == 'mouseenter' ? 'mouseover' : 'mouseout'), handler, false);
+ } else {
+ obj.removeEventListener(type, handler, false);
+ }
+ } else if ('detachEvent' in obj) {
+ obj.detachEvent("on" + type, handler);
+ }
+ obj[key] = null;
+ },
+
+ _checkMouse: function(el, e) {
+ var related = e.relatedTarget;
+
+ if (!related) return true;
+
+ try {
+ while (related && (related != el)) {
+ related = related.parentNode;
+ }
+ } catch(err) { return false; }
+
+ return (related != el);
+ },
+
+ _getEvent: function()/*->Event*/ {
+ var e = window.event;
+ if (!e) {
+ var caller = arguments.callee.caller;
+ while (caller) {
+ e = caller['arguments'][0];
+ if (e && Event == e.constructor) { break; }
+ caller = caller.caller;
+ }
+ }
+ return e;
+ },
+
+ stopPropagation: function(/*Event*/ e) {
+ if (e.stopPropagation) {
+ e.stopPropagation();
+ } else {
+ e.cancelBubble = true;
+ }
+ },
+
+ disableClickPropagation: function(/*HTMLElement*/ el) {
+ L.DomEvent.addListener(el, 'mousedown', L.DomEvent.stopPropagation);
+ L.DomEvent.addListener(el, 'click', L.DomEvent.stopPropagation);
+ L.DomEvent.addListener(el, 'dblclick', L.DomEvent.stopPropagation);
+ },
+
+ preventDefault: function(/*Event*/ e) {
+ if (e.preventDefault) {
+ e.preventDefault();
+ } else {
+ e.returnValue = false;
+ }
+ },
+
+ stop: function(e) {
+ L.DomEvent.preventDefault(e);
+ L.DomEvent.stopPropagation(e);
+ },
+
+ getMousePosition: function(e, container) {
+ var x = e.pageX ? e.pageX : e.clientX +
+ document.body.scrollLeft + document.documentElement.scrollLeft,
+ y = e.pageY ? e.pageY : e.clientY +
+ document.body.scrollTop + document.documentElement.scrollTop,
+ pos = new L.Point(x, y);
+
+ return (container ?
+ pos.subtract(L.DomUtil.getCumulativeOffset(container)) : pos);
+ },
+
+ getWheelDelta: function(e) {
+ var delta = 0;
+ if (e.wheelDelta) { delta = e.wheelDelta/120; }
+ if (e.detail) { delta = -e.detail/3; }
+ return delta;
+ }
+};
+
diff --git a/extlib/leaflet/src/dom/DomUtil.js b/extlib/leaflet/src/dom/DomUtil.js
new file mode 100644
index 00000000..7672bfba
--- /dev/null
+++ b/extlib/leaflet/src/dom/DomUtil.js
@@ -0,0 +1,124 @@
+/*
+ * L.DomUtil contains various utility functions for working with DOM
+ */
+
+L.DomUtil = {
+ get: function(id) {
+ return (typeof id == 'string' ? document.getElementById(id) : id);
+ },
+
+ getStyle: function(el, style) {
+ var value = el.style[style];
+ if (!value && el.currentStyle) {
+ value = el.currentStyle[style];
+ }
+ if (!value || value == 'auto') {
+ var css = document.defaultView.getComputedStyle(el, null);
+ value = css ? css[style] : null;
+ }
+ return (value == 'auto' ? null : value);
+ },
+
+ getCumulativeOffset: function(el) {
+ var top = 0,
+ left = 0;
+ do {
+ top += el.offsetTop || 0;
+ left += el.offsetLeft || 0;
+ el = el.offsetParent;
+ } while (el);
+ return new L.Point(left, top);
+ },
+
+ create: function(tagName, className, container) {
+ var el = document.createElement(tagName);
+ el.className = className;
+ if (container) {
+ container.appendChild(el);
+ }
+ return el;
+ },
+
+ disableTextSelection: function() {
+ if (document.selection && document.selection.empty) {
+ document.selection.empty();
+ }
+ if (!this._onselectstart) {
+ this._onselectstart = document.onselectstart;
+ document.onselectstart = L.Util.falseFn;
+ }
+ },
+
+ enableTextSelection: function() {
+ document.onselectstart = this._onselectstart;
+ this._onselectstart = null;
+ },
+
+ CLASS_RE: /(\\s|^)'+cls+'(\\s|$)/,
+
+ hasClass: function(el, name) {
+ return (el.className.length > 0) &&
+ new RegExp("(^|\\s)" + name + "(\\s|$)").test(el.className);
+ },
+
+ addClass: function(el, name) {
+ if (!L.DomUtil.hasClass(el, name)) {
+ el.className += (el.className ? ' ' : '') + name;
+ }
+ },
+
+ setOpacity: function(el, value) {
+ if (L.Browser.ie) {
+ el.style.filter = 'alpha(opacity=' + Math.round(value * 100) + ')';
+ } else {
+ el.style.opacity = value;
+ }
+ },
+
+ //TODO refactor away this ugly translate/position mess
+
+ testProp: function(props) {
+ var style = document.documentElement.style;
+
+ for (var i = 0; i < props.length; i++) {
+ if (props[i] in style) {
+ return props[i];
+ }
+ }
+ return false;
+ },
+
+ getTranslateString: function(point) {
+ return L.DomUtil.TRANSLATE_OPEN +
+ point.x + 'px,' + point.y + 'px' +
+ L.DomUtil.TRANSLATE_CLOSE;
+ },
+
+ getScaleString: function(scale, origin) {
+ return L.DomUtil.getTranslateString(origin) +
+ ' scale(' + scale + ') ' +
+ L.DomUtil.getTranslateString(origin.multiplyBy(-1));
+ },
+
+ setPosition: function(el, point) {
+ el._leaflet_pos = point;
+ if (L.Browser.webkit) {
+ el.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(point);
+ } else {
+ el.style.left = point.x + 'px';
+ el.style.top = point.y + 'px';
+ }
+ },
+
+ getPosition: function(el) {
+ return el._leaflet_pos;
+ }
+};
+
+L.Util.extend(L.DomUtil, {
+ TRANSITION: L.DomUtil.testProp(['transition', 'webkitTransition', 'OTransition', 'MozTransition', 'msTransition']),
+ TRANSFORM: L.DomUtil.testProp(['transformProperty', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform']),
+
+ TRANSLATE_OPEN: 'translate' + (L.Browser.webkit3d ? '3d(' : '('),
+ TRANSLATE_CLOSE: L.Browser.webkit3d ? ',0)' : ')'
+}); \ No newline at end of file
diff --git a/extlib/leaflet/src/dom/Draggable.js b/extlib/leaflet/src/dom/Draggable.js
new file mode 100644
index 00000000..c0aea23e
--- /dev/null
+++ b/extlib/leaflet/src/dom/Draggable.js
@@ -0,0 +1,129 @@
+/*
+ * L.Draggable allows you to add dragging capabilities to any element. Supports mobile devices too.
+ */
+
+L.Draggable = L.Class.extend({
+ includes: L.Mixin.Events,
+
+ statics: {
+ START: L.Browser.touch ? 'touchstart' : 'mousedown',
+ END: L.Browser.touch ? 'touchend' : 'mouseup',
+ MOVE: L.Browser.touch ? 'touchmove' : 'mousemove',
+ TAP_TOLERANCE: 15
+ },
+
+ initialize: function(element, dragStartTarget) {
+ this._element = element;
+ this._dragStartTarget = dragStartTarget || element;
+ },
+
+ enable: function() {
+ if (this._enabled) { return; }
+ L.DomEvent.addListener(this._dragStartTarget, L.Draggable.START, this._onDown, this);
+ this._enabled = true;
+ },
+
+ disable: function() {
+ if (!this._enabled) { return; }
+ L.DomEvent.removeListener(this._dragStartTarget, L.Draggable.START, this._onDown);
+ this._enabled = false;
+ },
+
+ _onDown: function(e) {
+ if (e.shiftKey || ((e.which != 1) && (e.button != 1) && !e.touches)) { return; }
+
+ if (e.touches && e.touches.length > 1) { return; }
+
+ var first = (e.touches && e.touches.length == 1 ? e.touches[0] : e);
+
+ L.DomEvent.preventDefault(e);
+
+ if (L.Browser.mobileWebkit) {
+ first.target.className += ' leaflet-active';
+ }
+
+ this._moved = false;
+
+ L.DomUtil.disableTextSelection();
+ this._setMovingCursor();
+
+ this._startPos = this._newPos = L.DomUtil.getPosition(this._element);
+ this._startPoint = new L.Point(first.clientX, first.clientY);
+
+ L.DomEvent.addListener(document, L.Draggable.MOVE, this._onMove, this);
+ L.DomEvent.addListener(document, L.Draggable.END, this._onUp, this);
+ },
+
+ _onMove: function(e) {
+ if (e.touches && e.touches.length > 1) { return; }
+
+ L.DomEvent.preventDefault(e);
+
+ var first = (e.touches && e.touches.length == 1 ? e.touches[0] : e);
+
+ if (!this._moved) {
+ this.fire('dragstart');
+ this._moved = true;
+ }
+
+ var newPoint = new L.Point(first.clientX, first.clientY);
+ this._newPos = this._startPos.add(newPoint).subtract(this._startPoint);
+
+ L.Util.requestAnimFrame(this._updatePosition, this, true);
+
+ this.fire('drag');
+ },
+
+ _updatePosition: function() {
+ L.DomUtil.setPosition(this._element, this._newPos);
+ },
+
+ _onUp: function(e) {
+ if (e.changedTouches) {
+ var first = e.changedTouches[0],
+ el = first.target,
+ dist = (this._newPos && this._newPos.distanceTo(this._startPos)) || 0;
+
+ el.className = el.className.replace(' leaflet-active', '');
+
+ if (dist < L.Draggable.TAP_TOLERANCE) {
+ this._simulateEvent('click', first);
+ }
+ }
+
+ L.DomUtil.enableTextSelection();
+
+ this._restoreCursor();
+
+ L.DomEvent.removeListener(document, L.Draggable.MOVE, this._onMove);
+ L.DomEvent.removeListener(document, L.Draggable.END, this._onUp);
+
+ if (this._moved) {
+ this.fire('dragend');
+ }
+ },
+
+ _removeActiveClass: function(el) {
+ },
+
+ _setMovingCursor: function() {
+ this._bodyCursor = document.body.style.cursor;
+ document.body.style.cursor = 'move';
+ },
+
+ _restoreCursor: function() {
+ document.body.style.cursor = this._bodyCursor;
+ },
+
+ _simulateEvent: function(type, e) {
+ var simulatedEvent = document.createEvent('MouseEvent');
+
+ simulatedEvent.initMouseEvent(
+ type, true, true, window, 1,
+ e.screenX, e.screenY,
+ e.clientX, e.clientY,
+ false, false, false, false, 0, null);
+
+ e.target.dispatchEvent(simulatedEvent);
+ }
+});
diff --git a/extlib/leaflet/src/dom/transition/Transition.Native.js b/extlib/leaflet/src/dom/transition/Transition.Native.js
new file mode 100644
index 00000000..6ce16a67
--- /dev/null
+++ b/extlib/leaflet/src/dom/transition/Transition.Native.js
@@ -0,0 +1,89 @@
+/*
+ * L.Transition native implementation that powers Leaflet animation
+ * in browsers that support CSS3 Transitions
+ */
+
+L.Transition = L.Transition.extend({
+ statics: (function() {
+ var transition = L.DomUtil.TRANSITION,
+ transitionEnd = (transition == 'webkitTransition' || transition == 'OTransition' ?
+ transition + 'End' : 'transitionend');
+
+ return {
+ NATIVE: !!transition,
+
+ TRANSITION: transition,
+ PROPERTY: transition + 'Property',
+ DURATION: transition + 'Duration',
+ EASING: transition + 'TimingFunction',
+ END: transitionEnd,
+
+ // transition-property value to use with each particular custom property
+ CUSTOM_PROPS_PROPERTIES: {
+ position: L.Browser.webkit ? L.DomUtil.TRANSFORM : 'top, left'
+ }
+ };
+ })(),
+
+ options: {
+ fakeStepInterval: 100
+ },
+
+ initialize: function(/*HTMLElement*/ el, /*Object*/ options) {
+ this._el = el;
+ L.Util.setOptions(this, options);
+
+ L.DomEvent.addListener(el, L.Transition.END, this._onTransitionEnd, this);
+ this._onFakeStep = L.Util.bind(this._onFakeStep, this);
+ },
+
+ run: function(/*Object*/ props) {
+ var prop,
+ propsList = [],
+ customProp = L.Transition.CUSTOM_PROPS_PROPERTIES;
+
+ for (prop in props) {
+ if (props.hasOwnProperty(prop)) {
+ prop = customProp[prop] ? customProp[prop] : prop;
+ prop = prop.replace(/([A-Z])/g, function(w) { return '-' + w.toLowerCase(); });
+ propsList.push(prop);
+ }
+ }
+
+ this._el.style[L.Transition.DURATION] = this.options.duration + 's';
+ this._el.style[L.Transition.EASING] = this.options.easing;
+ this._el.style[L.Transition.PROPERTY] = propsList.join(', ');
+
+ for (prop in props) {
+ if (props.hasOwnProperty(prop)) {
+ this._setProperty(prop, props[prop]);
+ }
+ }
+
+ this._inProgress = true;
+
+ this.fire('start');
+
+ if (L.Transition.NATIVE) {
+ this._timer = setInterval(this._onFakeStep, this.options.fakeStepInterval);
+ } else {
+ this._onTransitionEnd();
+ }
+ },
+
+ _onFakeStep: function() {
+ this.fire('step');
+ },
+
+ _onTransitionEnd: function() {
+ if (this._inProgress) {
+ this._inProgress = false;
+ clearInterval(this._timer);
+
+ this._el.style[L.Transition.PROPERTY] = 'none';
+
+ this.fire('step');
+ this.fire('end');
+ }
+ }
+}); \ No newline at end of file
diff --git a/extlib/leaflet/src/dom/transition/Transition.Timer.js b/extlib/leaflet/src/dom/transition/Transition.Timer.js
new file mode 100644
index 00000000..af4e4ef2
--- /dev/null
+++ b/extlib/leaflet/src/dom/transition/Transition.Timer.js
@@ -0,0 +1,124 @@
+/*
+ * L.Transition fallback implementation that powers Leaflet animation
+ * in browsers that don't support CSS3 Transitions
+ */
+
+L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
+ statics: {
+ getTime: Date.now || function() { return +new Date(); },
+
+ TIMER: true,
+
+ EASINGS: {
+ 'ease': [0.25, 0.1, 0.25, 1.0],
+ 'linear': [0.0, 0.0, 1.0, 1.0],
+ 'ease-in': [0.42, 0, 1.0, 1.0],
+ 'ease-out': [0, 0, 0.58, 1.0],
+ 'ease-in-out': [0.42, 0, 0.58, 1.0]
+ },
+
+ CUSTOM_PROPS_GETTERS: {
+ position: L.DomUtil.getPosition
+ },
+
+ //used to get units from strings like "10.5px" (->px)
+ UNIT_RE: /^[\d\.]+(\D*)$/
+ },
+
+ options: {
+ fps: 50
+ },
+
+ initialize: function(el, options) {
+ this._el = el;
+ L.Util.extend(this.options, options);
+
+ var easings = L.Transition.EASINGS[this.options.easing] || L.Transition.EASINGS['ease'];
+
+ this._p1 = new L.Point(0, 0);
+ this._p2 = new L.Point(easings[0], easings[1]);
+ this._p3 = new L.Point(easings[2], easings[3]);
+ this._p4 = new L.Point(1, 1);
+
+ this._step = L.Util.bind(this._step, this);
+ this._interval = Math.round(1000 / this.options.fps);
+ },
+
+ run: function(props) {
+ this._props = {};
+
+ var getters = L.Transition.CUSTOM_PROPS_GETTERS,
+ re = L.Transition.UNIT_RE;
+
+ this.fire('start');
+
+ for (var prop in props) {
+ if (props.hasOwnProperty(prop)) {
+ var p = {};
+ if (prop in getters) {
+ p.from = getters[prop](this._el);
+ } else {
+ var matches = this._el.style[prop].match(re);
+ p.from = parseFloat(matches[0]);
+ p.unit = matches[1];
+ }
+ p.to = props[prop];
+ this._props[prop] = p;
+ }
+ }
+
+ clearInterval(this._timer);
+ this._timer = setInterval(this._step, this._interval);
+ this._startTime = L.Transition.getTime();
+ },
+
+ _step: function() {
+ var time = L.Transition.getTime(),
+ elapsed = time - this._startTime,
+ duration = this.options.duration * 1000;
+
+ if (elapsed < duration) {
+ this._runFrame(this._cubicBezier(elapsed / duration));
+ } else {
+ this._runFrame(1);
+ this._complete();
+ }
+ },
+
+ _runFrame: function(percentComplete) {
+ var setters = L.Transition.CUSTOM_PROPS_SETTERS,
+ prop, p, value;
+
+ for (prop in this._props) {
+ if (this._props.hasOwnProperty(prop)) {
+ p = this._props[prop];
+ if (prop in setters) {
+ value = p.to.subtract(p.from).multiplyBy(percentComplete).add(p.from);
+ setters[prop](this._el, value);
+ } else {
+ this._el.style[prop] =
+ ((p.to - p.from) * percentComplete + p.from) + p.unit;
+ }
+ }
+ }
+ this.fire('step');
+ },
+
+ _complete: function() {
+ clearInterval(this._timer);
+ this.fire('end');
+ },
+
+ _cubicBezier: function(t) {
+ var a = Math.pow(1 - t, 3),
+ b = 3 * Math.pow(1 - t, 2) * t,
+ c = 3 * (1 - t) * Math.pow(t, 2),
+ d = Math.pow(t, 3),
+ p1 = this._p1.multiplyBy(a),
+ p2 = this._p2.multiplyBy(b),
+ p3 = this._p3.multiplyBy(c),
+ p4 = this._p4.multiplyBy(d);
+
+ return p1.add(p2).add(p3).add(p4).y;
+ }
+}); \ No newline at end of file
diff --git a/extlib/leaflet/src/dom/transition/Transition.js b/extlib/leaflet/src/dom/transition/Transition.js
new file mode 100644
index 00000000..ccf48572
--- /dev/null
+++ b/extlib/leaflet/src/dom/transition/Transition.js
@@ -0,0 +1,28 @@
+L.Transition = L.Class.extend({
+ includes: L.Mixin.Events,
+
+ statics: {
+ CUSTOM_PROPS_SETTERS: {
+ position: L.DomUtil.setPosition
+ //TODO transform custom attr
+ },
+
+ implemented: function() {
+ return L.Transition.NATIVE || L.Transition.TIMER;
+ }
+ },
+
+ options: {
+ easing: 'ease',
+ duration: 0.5
+ },
+
+ _setProperty: function(prop, value) {
+ var setters = L.Transition.CUSTOM_PROPS_SETTERS;
+ if (prop in setters) {
+ setters[prop](this._el, value);
+ } else {
+ this._el.style[prop] = value;
+ }
+ }
+}); \ No newline at end of file