iitc-project / ingress-intel-total-conversion

ingress.com/intel total conversion user script with some new features. Should allow easier extension of the intel map.
http://iitc.jonatkins.com/
ISC License
991 stars 552 forks source link

TypeError: L is not a constructor #964

Closed AndOne1974 closed 8 years ago

AndOne1974 commented 9 years ago

TypeError: L is not a constructor

...n.m.N.call(this)};function Jd(){this.Xc=new L;this.fj=new vg;this.dk=lk.e();this...

gen_dashboard.js (Zeile 299, Spalte 276)

latest test build

jonatkins commented 9 years ago

This is remnants of the stock intel site, and fires on the first click only.

Not sure if there's anything we can do to fix this.

reckter commented 8 years ago

Shouldn't this be closed?

McBen commented 7 years ago

It's a conflict between stockintel's function "L" and iitc object 'L' (LeafLet).

dingram commented 7 years ago

It's theoretically possible to cheat this, but I don't know if it would actually gain anything. For example:

We could use something like L.noConflict() to help:

var L_ = L.noConflict();
// window.L is now back to its original value

and just use L_ everywhere instead. This would break third-party plugins, however.

We could do something more sneaky, and copy everything from L to L_:

var L_ = L.noConflict();
Object.keys(L_).each(function(k){
  L[k] = L_[k];
});

However this wouldn't work if something tries to edit properties on L or L_, as they wouldn't get updated on the other object. Plus, they'd risk overwriting things on the original L from the Ingress codebase.

It looks like trying to be clever with the L variable isn't really going to help us much. What other options are there?

Well really, the issue is that the Ingress code adds an event handler before the IITC code loads, and we can't remove that. Or can we? In main.js, we replace the entire contents of the <head> and <body> nodes. If instead we replace the nodes themselves, we lose all of the event listeners bound to them.

There is a potential catch — it's not immediately clear to me whether the handler causing the error is registered on the <body> element or the document itself. If the event handler is registered on the document, then the error will still occur. In that case, there would need to be some magic around replacing the way that event listeners get added to the page, so that we can remove any listeners that get added before IITC itself starts up.

Sorry, this was a bit of a braindump. But hopefully it explains why this is not an easy issue to solve, and presents a potential fix.

McBen commented 7 years ago

@dingram in PR1164 I performed the "renaming" way

hayeswise commented 7 years ago

IMHO, _L and L_ are a bit odd (unless that's some JavaScript standard approach that I have yet to learn). I'd prefer Leaflet since it's obvious (I sure like the way jQuery provides both jQuery and $).

For my "Portals-in-Polygons" plugin, I've extended (via prototype) L.LatLng and L.Polyline with functions isLeft and getWindingNumber respectively. I'm happy to read that you're looking for a solution that will be reasonably easy to adjust to. Changes like Leaflet.LatLng, _L.LatLng, or L_.LngLng would be easy enough.

McBen commented 7 years ago

@hayeswise yeah, you're right. My "_L" choice was bad - just wanted something short. "Leaflet" is better.

hayeswise commented 7 years ago

While I doubt it would happen, it would be nice if Leafletcould change their base class name from L to Leaflet.

nhamer commented 7 years ago

It's actually a "mousedown" event registered on document.body -

The exception can be removed by (main.js@62):

dingram commented 7 years ago

Awesome, thanks @nhamer! It makes sense to completely replace the head and body elements, rather than just their content.

Can you propose a pull request that does exactly that, please? I'll get that merged ASAP.