diff --git a/demos/calendar/js/calendar.js b/demos/calendar/js/calendar.js index 38ad81c1..472c8ba1 100644 --- a/demos/calendar/js/calendar.js +++ b/demos/calendar/js/calendar.js @@ -11,7 +11,7 @@ Ox.load('UI', {debug: true, hideScreen: true, showScreen: true, theme: 'modern'} //Ox.print('$$$$', Ox.Calendar) - new Ox.Calendar({ + Ox.Calendar({ date: new Date(0), dates: [ {name: 'Genghis Khan', start: new Date('1162'), stop: new Date('1228'), type: 'Person'}, diff --git a/demos/listmap2/js/listmap.js b/demos/listmap2/js/listmap.js index b2434c3b..b35b4ec2 100644 --- a/demos/listmap2/js/listmap.js +++ b/demos/listmap2/js/listmap.js @@ -42,6 +42,11 @@ Ox.load('UI', { }), width: window.innerWidth }) + .bindEvent({ + geocode: function(event, data) { + Ox.print(JSON.stringify(data)) + } + }) .appendTo(Ox.UI.$body); $(window).resize(function() { Ox.print('RESIZE', window.innerHeight) diff --git a/source/Ox.UI/js/Form/Ox.Picker.js b/source/Ox.UI/js/Form/Ox.Picker.js index 34eb90f8..a1a70f07 100644 --- a/source/Ox.UI/js/Form/Ox.Picker.js +++ b/source/Ox.UI/js/Form/Ox.Picker.js @@ -20,7 +20,7 @@ Ox.Picker = function(options, self) { .click(showMenu) .appendTo(that); - self.$menu = new Ox.Element({}) + self.$menu = new Ox.Element() .addClass('OxPicker') .css({ width: self.options.elementWidth + 'px', diff --git a/source/Ox.UI/js/Form/Ox.PlacePicker.js b/source/Ox.UI/js/Form/Ox.PlacePicker.js index 3993587a..e89f79e0 100644 --- a/source/Ox.UI/js/Form/Ox.PlacePicker.js +++ b/source/Ox.UI/js/Form/Ox.PlacePicker.js @@ -9,7 +9,7 @@ Ox.PlacePicker = function(options, self) { }), that; - self.$element = new Ox.Element({}) + self.$element = new Ox.Element() .css({ width: '256px', height: '192px' @@ -33,7 +33,7 @@ Ox.PlacePicker = function(options, self) { ) ) .append( - self.$container = new Ox.Element({}) + self.$container = new Ox.Element() .css({ width: '256px', height: '160px' diff --git a/source/Ox.UI/js/Map/Ox.ListMap.js b/source/Ox.UI/js/Map/Ox.ListMap.js index 37a5fe0a..6ac4c141 100644 --- a/source/Ox.UI/js/Map/Ox.ListMap.js +++ b/source/Ox.UI/js/Map/Ox.ListMap.js @@ -265,6 +265,9 @@ Ox.ListMap = function(options, self) { addplace: function(event, data) { that.triggerEvent('addplace', data); }, + geocode: function(event, data) { + that.triggerEvent('geocode', data); + }, resize: function() { self.$map.resizeMap(); // fixme: don't need event }, diff --git a/source/Ox.UI/js/Map/Ox.Map.js b/source/Ox.UI/js/Map/Ox.Map.js index be6e6693..0c6b0408 100644 --- a/source/Ox.UI/js/Map/Ox.Map.js +++ b/source/Ox.UI/js/Map/Ox.Map.js @@ -131,7 +131,7 @@ Ox.Map = function(options, self) { .appendTo(self.$toolbar) } - self.$map = new Ox.Element({}) + self.$map = new Ox.Element() .css({ left: 0, top: self.options.toolbar * 24 + 'px', @@ -317,6 +317,7 @@ Ox.Map = function(options, self) { } function canContain(outerBounds, innerBounds) { + // checks if outerBounds _can_ contain innerBounds var outerSpan = outerBounds.toSpan(), innerSpan = innerBounds.toSpan(); return outerSpan.lat() > innerSpan.lat() && @@ -336,6 +337,7 @@ Ox.Map = function(options, self) { Ox.print('Ox.Map clickMap') if (self.options.clickable/* && !editing()*/) { getPlaceByLatLng(event.latLng, self.map.getBounds(), function(place) { + Ox.print('>>>>', place) if (place) { addPlaceToMap(place); //selectPlace(place.id); @@ -434,6 +436,7 @@ Ox.Map = function(options, self) { } function getPlaceByLatLng(latlng, bounds, callback) { + // gets the largest place at latlng that would fit in bounds Ox.print('ll b', latlng, bounds) var callback = arguments.length == 3 ? callback : bounds, bounds = arguments.length == 3 ? bounds : null; @@ -443,25 +446,30 @@ Ox.Map = function(options, self) { Ox.print('results', results) var length = results.length; if (status == google.maps.GeocoderStatus.OK) { - if (status != google.maps.GeocoderStatus.ZERO_RESULTS) { - if (bounds) { - Ox.forEach(results.reverse(), function(result, i) { - if ( - i == length - 1 || - canContain(bounds, result.geometry.bounds || result.geometry.viewport) - ) { - callback(new Ox.MapPlace(parseGeodata(results[i]))); - return false; - } - }); - } else { - callback(new Ox.MapPlace(parseGeodata(results[0]))); - } + if (bounds) { + Ox.forEach(results.reverse(), function(result, i) { + if ( + i == length - 1 || + canContain(bounds, result.geometry.bounds || result.geometry.viewport) + ) { + callback(new Ox.MapPlace(parseGeodata(results[i]))); + return false; + } + }); } else { - callback(null); + callback(new Ox.MapPlace(parseGeodata(results[0]))); } + } + if ( + status == google.maps.GeocoderStatus.OK || + status == google.maps.GeocoderStatus.ZERO_RESULTS + ) { + triggerGeocodeEvent({ + latLng: latlng, + results: results + }); } else { - //Ox.print('geocode failed:', status); + Ox.print('geocode failed:', status); callback(null); } }); @@ -472,12 +480,16 @@ Ox.Map = function(options, self) { address: name }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { - if (status != google.maps.GeocoderStatus.ZERO_RESULTS) { - Ox.print('GEOCODER RESULT', results[0]) - callback(new Ox.MapPlace(parseGeodata(results[0]))); - } else { - callback(null); - } + callback(new Ox.MapPlace(parseGeodata(results[0]))); + } + if ( + status == google.maps.GeocoderStatus.OK || + status == google.maps.GeocoderStatus.ZERO_RESULTS + ) { + triggerGeocodeEvent({ + address: name, + results: results + }); } else { Ox.print('geocode failed:', status); callback(null); @@ -804,6 +816,41 @@ Ox.Map = function(options, self) { }); } + function triggerGeocodeEvent(data) { + // someone may want to cache google geocode data, so we fire an event. + // google puts functions like lat or lng on the objects' prototypes, + // so we create properly named properties, for json encoding + if (data.latLng) { + data.latLng = { + lat: data.latLng.lat(), + lng: data.latLng.lng() + } + } + data.results.forEach(function(result) { + ['bounds', 'viewport'].forEach(function(key) { + if (result.geometry[key]) { + result.geometry[key] = { + northEast: { + lat: result.geometry[key].getNorthEast().lat(), + lng: result.geometry[key].getNorthEast().lng() + }, + southWest: { + lat: result.geometry[key].getSouthWest().lat(), + lng: result.geometry[key].getSouthWest().lng() + } + } + } + }); + if (result.geometry.location) { + result.geometry.location = { + lat: result.geometry.location.lat(), + lng: result.geometry.location.lng() + } + } + }); + that.triggerEvent('geocode', data); + } + function undo() { Ox.print('Map undo') var place = getSelectedPlace(); diff --git a/source/Ox.UI/js/Video/Ox.AnnotationPanel.js b/source/Ox.UI/js/Video/Ox.AnnotationPanel.js index bc7f3229..110a6b94 100644 --- a/source/Ox.UI/js/Video/Ox.AnnotationPanel.js +++ b/source/Ox.UI/js/Video/Ox.AnnotationPanel.js @@ -39,7 +39,7 @@ Ox.AnnotationPanel = function(options, self) { self.$annotations = new Ox.List({ construct: function(data) { - return new Ox.Element({}) + return new Ox.Element() .addClass('OxAnnotation OxEditable OxTarget') .html(Ox.parseHTML(data.value)); }, @@ -68,11 +68,11 @@ Ox.AnnotationPanel = function(options, self) { .appendTo(that.$content); /* - self.$annotations = new Ox.Element({}) + self.$annotations = new Ox.Element() .appendTo(that.$content); self.$annotation = []; self.options.items.forEach(function(item, i) { - self.$annotation[i] = new Ox.Element({}) + self.$annotation[i] = new Ox.Element() .addClass('OxAnnotation') .html(item.value.replace(/\n/g, '
')) .click(function() { diff --git a/source/Ox.UI/js/Video/Ox.BlockTimeline.js b/source/Ox.UI/js/Video/Ox.BlockTimeline.js index 32a22760..efab3707 100644 --- a/source/Ox.UI/js/Video/Ox.BlockTimeline.js +++ b/source/Ox.UI/js/Video/Ox.BlockTimeline.js @@ -85,7 +85,7 @@ Ox.BlockTimeline = function(options, self) { function addLine(i) { // fixme: get URLs once, not once for every line - self.$lines[i] = new Ox.Element({}) + self.$lines[i] = new Ox.Element() .css({ top: i * (self.height + self.margin) + 'px', width: self.options.width + 'px' diff --git a/source/Ox.js b/source/Ox.js index 093cbd23..3607535a 100644 --- a/source/Ox.js +++ b/source/Ox.js @@ -915,6 +915,17 @@ Ox.values = function(obj) { return values; }; +Ox.walk = function(obj, fn) { + /* + >>> a = 0; Ox.walk({a: 1, b: {c: 2, d: 3}}, function(v, k) { a += Ox.isNumber(v) ? v : 0}); a + 6 + */ + Ox.forEach(obj, function(val, key) { + fn(val, key, obj); + Ox.walk(obj[key], fn); + }); +}; + Ox.zip = function() { /* >>> Ox.zip([[0, 1], [2, 3], [4, 5]])