aboutsummaryrefslogtreecommitdiffstats
path: root/extlib/leaflet/src/dom/transition
diff options
context:
space:
mode:
Diffstat (limited to 'extlib/leaflet/src/dom/transition')
-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
3 files changed, 241 insertions, 0 deletions
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