From 61ce4651340ed4e01b4be7af1379ce2212251ee7 Mon Sep 17 00:00:00 2001 From: danzel Date: Mon, 25 Jun 2012 12:16:46 +1200 Subject: [PATCH] Fix up the unit tests. Polyline.closestLayerPoint and noConflict were broken. --- spec/suites/LeafletSpec.js | 11 +++++------ src/Leaflet.js | 7 ++++--- src/layer/vector/Polyline.js | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/suites/LeafletSpec.js b/spec/suites/LeafletSpec.js index c67879cf..ee7bea71 100644 --- a/spec/suites/LeafletSpec.js +++ b/spec/suites/LeafletSpec.js @@ -1,15 +1,14 @@ describe('L#noConflict', function() { it('should restore the previous L value and return Leaflet namespace', function(){ - expect(L.VERSION).toBeDefined(); + expect(L.version).toBeDefined(); var L2 = L.noConflict(); - - expect(L).toEqual('test'); - expect(L2.VERSION).toBeDefined(); - - this.after(function() { + this.after(function () { window.L = L2; }); + + expect(L).toEqual('test'); + expect(L2.version).toBeDefined(); }); }); \ No newline at end of file diff --git a/src/Leaflet.js b/src/Leaflet.js index 87757840..2bbf3d4e 100644 --- a/src/Leaflet.js +++ b/src/Leaflet.js @@ -3,13 +3,14 @@ var L, originalL; if (typeof exports !== 'undefined') { L = exports; } else { - L = {}; - + originalL = window.L; + L = {}; L.noConflict = function () { + var l = window.L; window.L = originalL; - return L; + return l; }; window.L = L; diff --git a/src/layer/vector/Polyline.js b/src/layer/vector/Polyline.js index 2f876fc3..c1bdbb7b 100644 --- a/src/layer/vector/Polyline.js +++ b/src/layer/vector/Polyline.js @@ -63,10 +63,10 @@ L.Polyline = L.Path.extend({ for (var i = 1, len = points.length; i < len; i++) { p1 = points[i - 1]; p2 = points[i]; - var point = L.LineUtil._sqClosestPointOnSegment(p, p1, p2); - if (point._sqDist < minDistance) { - minDistance = point._sqDist; - minPoint = point; + var sqDist = L.LineUtil._sqClosestPointOnSegment(p, p1, p2, true); + if (sqDist < minDistance) { + minDistance = sqDist; + minPoint = L.LineUtil._sqClosestPointOnSegment(p, p1, p2); } } }