lazyload google maps
This commit is contained in:
parent
feb7a876b7
commit
e25043765a
|
@ -218,40 +218,37 @@ requires
|
|||
var config = data;
|
||||
Ox.print('config', config);
|
||||
document.title = config.site.name;
|
||||
window.google = function() {};
|
||||
$.getScript('http://maps.google.com/maps/api/js?callback=google&sensor=false', function() {
|
||||
loadImages(function() {
|
||||
that.api.api(function(result) {
|
||||
$.each(result.data.actions, function(i, action) {
|
||||
that.api[action] = function(data, callback) {
|
||||
if (arguments.length == 1) {
|
||||
callback = data;
|
||||
data = {};
|
||||
}
|
||||
return Ox.Request.send({
|
||||
url: self.options.apiURL,
|
||||
data: {
|
||||
action: action,
|
||||
data: JSON.stringify(data)
|
||||
},
|
||||
callback: callback
|
||||
});
|
||||
};
|
||||
});
|
||||
that.api[self.options.init](getUserData(), function(data) {
|
||||
var user = data.data.user;
|
||||
$(function() {
|
||||
var $div = $body.find('div');
|
||||
$body.find('img').remove();
|
||||
$div.animate({
|
||||
opacity: 0
|
||||
}, 1000, function() {
|
||||
$div.remove();
|
||||
});
|
||||
callback({
|
||||
config: config,
|
||||
user: user
|
||||
});
|
||||
loadImages(function() {
|
||||
that.api.api(function(result) {
|
||||
$.each(result.data.actions, function(i, action) {
|
||||
that.api[action] = function(data, callback) {
|
||||
if (arguments.length == 1) {
|
||||
callback = data;
|
||||
data = {};
|
||||
}
|
||||
return Ox.Request.send({
|
||||
url: self.options.apiURL,
|
||||
data: {
|
||||
action: action,
|
||||
data: JSON.stringify(data)
|
||||
},
|
||||
callback: callback
|
||||
});
|
||||
};
|
||||
});
|
||||
that.api[self.options.init](getUserData(), function(data) {
|
||||
var user = data.data.user;
|
||||
$(function() {
|
||||
var $div = $body.find('div');
|
||||
$body.find('img').remove();
|
||||
$div.animate({
|
||||
opacity: 0
|
||||
}, 1000, function() {
|
||||
$div.remove();
|
||||
});
|
||||
callback({
|
||||
config: config,
|
||||
user: user
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -7270,40 +7267,56 @@ requires
|
|||
key_escape: deselectPlace
|
||||
});
|
||||
|
||||
$.extend(self, {
|
||||
geocoder: new google.maps.Geocoder(),
|
||||
selected: -1
|
||||
});
|
||||
if (Ox.isObject(self.options.places[0])) {
|
||||
$.each(self.options.places, function(i, place) {
|
||||
place.bounds = getBounds(),
|
||||
place.center = place.bounds.getCenter();
|
||||
$.extend(place, {
|
||||
marker: new Marker(place),
|
||||
polygon: new Polygon(place)
|
||||
});
|
||||
self.bounds = i == 0 ? getBounds() : self.bounds.union(place.bounds);
|
||||
self.options.places[i] = place;
|
||||
function getBounds() {
|
||||
return new google.maps.LatLngBounds(
|
||||
new google.maps.LatLng(place.points.southwest[0], place.points.southwest[1]),
|
||||
new google.maps.LatLng(place.points.northeast[0], place.points.northeast[1])
|
||||
);
|
||||
}
|
||||
});
|
||||
loadMap();
|
||||
} else {
|
||||
self.counter = 0;
|
||||
$.each(self.options.places, function(i, place) {
|
||||
getLocationByName(place, function(place) {
|
||||
Ox.print(self.counter, i, place);
|
||||
self.options.places[i] = place;
|
||||
if (self.counter++ == self.options.places.length - 1) {
|
||||
loadMap();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
if (Ox.isUndefined(window.google)) {
|
||||
window.google = function() {};
|
||||
$.getScript('http://maps.google.com/maps/api/js?callback=google&sensor=false', function() {
|
||||
var interval = setInterval(function() {
|
||||
if (!Ox.isUndefined(google.maps)) {
|
||||
clearInterval(interval);
|
||||
initMap();
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
} else {
|
||||
initMap();
|
||||
}
|
||||
|
||||
function initMap() {
|
||||
$.extend(self, {
|
||||
geocoder: new google.maps.Geocoder(),
|
||||
selected: -1
|
||||
});
|
||||
if (Ox.isObject(self.options.places[0])) {
|
||||
$.each(self.options.places, function(i, place) {
|
||||
place.bounds = getBounds(),
|
||||
place.center = place.bounds.getCenter();
|
||||
$.extend(place, {
|
||||
marker: new Marker(place),
|
||||
polygon: new Polygon(place)
|
||||
});
|
||||
self.bounds = i == 0 ? getBounds() : self.bounds.union(place.bounds);
|
||||
self.options.places[i] = place;
|
||||
function getBounds() {
|
||||
return new google.maps.LatLngBounds(
|
||||
new google.maps.LatLng(place.points.southwest[0], place.points.southwest[1]),
|
||||
new google.maps.LatLng(place.points.northeast[0], place.points.northeast[1])
|
||||
);
|
||||
}
|
||||
});
|
||||
loadMap();
|
||||
} else {
|
||||
self.counter = 0;
|
||||
$.each(self.options.places, function(i, place) {
|
||||
getLocationByName(place, function(place) {
|
||||
Ox.print(self.counter, i, place);
|
||||
self.options.places[i] = place;
|
||||
if (self.counter++ == self.options.places.length - 1) {
|
||||
loadMap();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function loadMap() {
|
||||
self.center = self.bounds ? self.bounds.getCenter() : new google.maps.LatLng(0, 0);
|
||||
|
@ -7328,9 +7341,9 @@ requires
|
|||
});
|
||||
resize();
|
||||
that.gainFocus();
|
||||
that.triggerEvent('loaded');
|
||||
}
|
||||
|
||||
|
||||
function canContain(outerBounds, innerBounds) {
|
||||
var outerSpan = outerBounds.toSpan(),
|
||||
innerSpan = innerBounds.toSpan();
|
||||
|
|
Loading…
Reference in New Issue
Block a user