Permalink
Browse files

Add js bind implementation when not available to exported files

  • Loading branch information...
1 parent be0ca00 commit 0a8819c4cf756c546261420bed17e4e50c6aa227 @rburhum rburhum committed Dec 18, 2012
Showing with 38 additions and 0 deletions.
  1. +38 −0 geocamTiePoint/templates/geocamTiePoint/simple-view.html
@@ -1,3 +1,5 @@
+<!DOCTYPE html>
+<html>
<head>
<title>MapFasten: {{ name }}</title>
<style>
@@ -11,6 +13,7 @@
}
</style>
</head>
+<body>
<div>
You can save this web page and serve it from your own web site as an easy way
to share your overlay.
@@ -42,6 +45,39 @@
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
+/********************************************
+
+bind() does not work correctly in the Webkit versions shipped in iOS 5.1.1.
+
+Therefore, the following is an approximate bind implementation.
+
+Source: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind
+
+********************************************/
+if (!Function.prototype.bind) {
+ Function.prototype.bind = function (oThis) {
+ if (typeof this !== "function") {
+ // closest thing possible to the ECMAScript 5 internal IsCallable function
+ throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
+ }
+
+ var aArgs = Array.prototype.slice.call(arguments, 1),
+ fToBind = this,
+ fNOP = function () {},
+ fBound = function () {
+ return fToBind.apply(this instanceof fNOP && oThis
+ ? this
+ : oThis,
+ aArgs.concat(Array.prototype.slice.call(arguments)));
+ };
+
+ fNOP.prototype = this.prototype;
+ fBound.prototype = new fNOP();
+
+ return fBound;
+ };
+}
+
function MapFastenOverlay(name, slug, tileRootUrl, bounds) {
this.name = name;
this.tileRootUrl = tileRootUrl;
@@ -143,3 +179,5 @@
google.maps.event.addDomListener(window, 'load', initialize);
</script>
+</body>
+</html>

4 comments on commit 0a8819c

Thanks for hacking on MapFasten!

A couple of comments.

  1. simple-view.html is deprecated. Does it actually still work? We've replaced it with a UI that uses client-side MVC (backbone) to improve the user experience, and that's where the new UI features will show up. All the action these days is in the not-very-creatively-named backbone.html

  2. The new UI depends on underscore.js, so we've been using underscore's _.bind() function for this purpose. It uses the browser's native function.bind() if available, and its own implementation otherwise. I'd rather not have two different .bind() implementations in the code base, so can you check to see if the underscore version works on iOS?

Cheers,
Ted

Hi Ted. The I realize the main application uses backbone. This file is the one that is used to render the "view.html" provided in the standalone tar.gz file that gets generated during an "export". For example, go here: http://mapfasten.appspot.com/b/#overlay/92/export

You will notice that the view.html is not correct, but will render OK. If you try it on an iPad 1, it will not work. The view.html is a minimalistic html file that only relies on Google Maps (doesn't have backbone nor underscore.js). This fix continues with that philosophy and only adds a custom bind when the underlying web renderer (in this case Webkit on iOS 5.1.1) doesn't have it.

Also, FYI, I have this other pull request geocam/geocamUtilWeb#2

Ah, yes. My mistake. I had it confused with overlay-view.html, which we've already removed.

Please sign in to comment.