bhm-google-maps 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +2 -2
- data/bhm-google-maps.gemspec +4 -4
- data/coffeescripts/gmap.coffee +37 -33
- data/javascripts/gmap.js +19 -39
- data/lib/bhm/google_maps/version.rb +1 -1
- metadata +9 -4
data/Rakefile
CHANGED
@@ -25,12 +25,12 @@ end
|
|
25
25
|
|
26
26
|
desc "Compiles the javascript from Coffeescript to Javascript"
|
27
27
|
task :compile_scripts do
|
28
|
-
system "coffee --no-wrap -
|
28
|
+
system "coffee --no-wrap -o javascripts/ -c coffeescripts/"
|
29
29
|
end
|
30
30
|
|
31
31
|
desc "Interactively compiles coffeescripts as they're changed"
|
32
32
|
task :watch_scripts do
|
33
|
-
system "coffee --no-wrap -w -
|
33
|
+
system "coffee --no-wrap -w -o javascripts/ -c coffeescripts/"
|
34
34
|
end
|
35
35
|
|
36
36
|
desc "Compile scripts, and produce a minified version."
|
data/bhm-google-maps.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bhm-google-maps}
|
8
|
-
s.version = "0.1
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Darcy Laycock"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-21}
|
13
13
|
s.description = %q{A set of helpers and javascript files that makes it trivial to implement google maps unobtrusively in an application.}
|
14
14
|
s.email = %q{darcy.laycock@youthtree.org.au}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
|
|
40
40
|
s.homepage = %q{http://github.com/YouthTree/bhm-google-maps}
|
41
41
|
s.rdoc_options = ["--charset=UTF-8"]
|
42
42
|
s.require_paths = ["lib"]
|
43
|
-
s.rubygems_version = %q{1.3.
|
43
|
+
s.rubygems_version = %q{1.3.7}
|
44
44
|
s.summary = %q{Helpers for Google Maps v3 in Rails - Using html 5, the google maps api v3 and the static maps api}
|
45
45
|
s.test_files = [
|
46
46
|
"test/builder_test.rb",
|
@@ -53,7 +53,7 @@ Gem::Specification.new do |s|
|
|
53
53
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
54
|
s.specification_version = 3
|
55
55
|
|
56
|
-
if Gem::Version.new(Gem::
|
56
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
57
|
else
|
58
58
|
end
|
59
59
|
else
|
data/coffeescripts/gmap.coffee
CHANGED
@@ -1,82 +1,86 @@
|
|
1
1
|
# GMap is a simply, unobtrusive google map adder for jQuery + HTML5.
|
2
2
|
# It uses data attributes to store map locations, works with a rails
|
3
3
|
# plugin to generate static alternatives and most importantly is simple.
|
4
|
-
@['GMap']
|
4
|
+
@['GMap'] = (($) ->
|
5
5
|
|
6
6
|
# The actual object we'll be exporting.
|
7
|
-
map
|
7
|
+
map = {}
|
8
8
|
|
9
9
|
# Map and marker options to autoextract.
|
10
|
-
mapOptionKeys
|
11
|
-
markerOptionKeys
|
10
|
+
mapOptionKeys = ["zoom", "title"]
|
11
|
+
markerOptionKeys = ["title"]
|
12
12
|
|
13
13
|
# Exposed options / data.
|
14
|
-
map.count
|
15
|
-
map.autoIDPrefix
|
16
|
-
map.maps
|
14
|
+
map.count = 0
|
15
|
+
map.autoIDPrefix = "gmap-"
|
16
|
+
map.maps = []
|
17
17
|
|
18
18
|
# Use a function for the roadmap value to avoid load order issues.
|
19
19
|
# e.g. if the google maps library is loaded after this one.
|
20
|
-
map.defaultOptions
|
20
|
+
map.defaultOptions =
|
21
21
|
zoom: 15
|
22
22
|
mapTypeId: -> google.maps.MapTypeId.ROADMAP
|
23
23
|
scrollwheel: false
|
24
|
-
}
|
25
24
|
|
26
25
|
# Very, very simple wrapper for generating a data key - tbh possibly un-needed.
|
27
|
-
dataKey
|
26
|
+
dataKey = (key, spacer) ->
|
28
27
|
spacer?= ""
|
29
|
-
"data
|
28
|
+
"data-#{spacer}#{key}"
|
30
29
|
|
31
30
|
# Returns true iff the given element has the set data element, false otherwise.
|
32
|
-
hasData
|
33
|
-
e.is "[
|
31
|
+
hasData = (e, key, spacer) ->
|
32
|
+
e.is "[#{dataKey key, spacer}]"
|
34
33
|
|
35
34
|
# Return the value of a given data attribute.
|
36
|
-
getData
|
35
|
+
getData = (e, key, spacer) ->
|
37
36
|
e.attr dataKey(key, spacer)
|
38
37
|
|
39
38
|
# Merges a given object w/ values retrieved using data element.
|
40
39
|
# automatically namespaces keys etc.
|
41
|
-
mergeDataOptions
|
40
|
+
mergeDataOptions = (element, options, keys, spacer) ->
|
42
41
|
for key in keys
|
43
42
|
options[key] = getData(element, key, spacer) if hasData element, key, spacer
|
44
43
|
|
45
44
|
# Return the map options for a given element.
|
46
|
-
mapOptionsForElement
|
47
|
-
options
|
45
|
+
mapOptionsForElement = (element) ->
|
46
|
+
options = $.extend {}, map.defaultOptions
|
48
47
|
# Set the mapTypeId if it's a function
|
49
|
-
options.mapTypeId
|
48
|
+
options.mapTypeId = options.mapTypeId() if $.isFunction options.mapTypeId
|
50
49
|
mergeDataOptions element, options, mapOptionKeys
|
51
50
|
options
|
52
51
|
|
53
52
|
# Install the google map onto each option with the .gmap key.
|
54
|
-
map.install
|
53
|
+
map.install = ->
|
55
54
|
$('.gmap').each -> map.setupElement this
|
56
|
-
|
55
|
+
|
57
56
|
# Called with a single html dom element as an argument, will
|
58
57
|
# automatically set it up as a google map.
|
59
|
-
map.setupElement
|
60
|
-
$e
|
61
|
-
id
|
62
|
-
$e.attr "id", "
|
58
|
+
map.setupElement = (e) ->
|
59
|
+
$e = $ e
|
60
|
+
id = $e.attr "id"
|
61
|
+
$e.attr "id", "#{map.autoIDPrefix}#{map.count++}" unless id?
|
63
62
|
# Get the position of the current marker.
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
if hasData $e, "latitude" and hasData $e, "longitude"
|
64
|
+
lat = Number getData($e, "latitude")
|
65
|
+
lng = Number getData($e, "longitude")
|
66
|
+
map.drawLatLng $e, e, lat, lng
|
67
|
+
else
|
68
|
+
address = getData $e, "address"
|
69
|
+
# TODO: Map the address.
|
70
|
+
point = new google.maps.LatLng lat, lng
|
67
71
|
# Start setting up the map / create a map element.
|
68
|
-
mapOptions
|
69
|
-
mapOptions.center
|
72
|
+
mapOptions = mapOptionsForElement $e
|
73
|
+
mapOptions.center = point
|
70
74
|
$e.empty().addClass('dynamic-google-map').removeClass('static-google-map')
|
71
|
-
currentMap
|
75
|
+
currentMap = new google.maps.Map e, mapOptions
|
72
76
|
map.maps.push currentMap
|
73
77
|
# Now, we need to finally add the marker to the map.
|
74
|
-
markerOptions
|
78
|
+
markerOptions =
|
75
79
|
position: point
|
76
80
|
map: currentMap
|
77
|
-
|
81
|
+
|
78
82
|
mergeDataOptions $e, markerOptions, markerOptionKeys, "marker-"
|
79
|
-
marker
|
83
|
+
marker = new google.maps.Marker markerOptions
|
80
84
|
currentMap
|
81
85
|
|
82
86
|
# On load, we'll install the maps.
|
data/javascripts/gmap.js
CHANGED
@@ -1,93 +1,75 @@
|
|
1
|
-
|
2
|
-
// GMap is a simply, unobtrusive google map adder for jQuery + HTML5.
|
3
|
-
// It uses data attributes to store map locations, works with a rails
|
4
|
-
// plugin to generate static alternatives and most importantly is simple.
|
5
|
-
GMap = (function($) {
|
1
|
+
this['GMap'] = (function($) {
|
6
2
|
var dataKey, getData, hasData, map, mapOptionKeys, mapOptionsForElement, markerOptionKeys, mergeDataOptions;
|
7
|
-
// The actual object we'll be exporting.
|
8
3
|
map = {};
|
9
|
-
// Map and marker options to autoextract.
|
10
4
|
mapOptionKeys = ["zoom", "title"];
|
11
5
|
markerOptionKeys = ["title"];
|
12
|
-
// Exposed options / data.
|
13
6
|
map.count = 0;
|
14
7
|
map.autoIDPrefix = "gmap-";
|
15
8
|
map.maps = [];
|
16
|
-
// Use a function for the roadmap value to avoid load order issues.
|
17
|
-
// e.g. if the google maps library is loaded after this one.
|
18
9
|
map.defaultOptions = {
|
19
10
|
zoom: 15,
|
20
|
-
mapTypeId: function
|
11
|
+
mapTypeId: function() {
|
21
12
|
return google.maps.MapTypeId.ROADMAP;
|
22
13
|
},
|
23
14
|
scrollwheel: false
|
24
15
|
};
|
25
|
-
|
26
|
-
dataKey = function dataKey(key, spacer) {
|
16
|
+
dataKey = function(key, spacer) {
|
27
17
|
spacer = (typeof spacer !== "undefined" && spacer !== null) ? spacer : "";
|
28
|
-
return "data-" + spacer + key;
|
18
|
+
return "data-" + (spacer) + (key);
|
29
19
|
};
|
30
|
-
|
31
|
-
hasData = function hasData(e, key, spacer) {
|
20
|
+
hasData = function(e, key, spacer) {
|
32
21
|
return e.is(("[" + (dataKey(key, spacer)) + "]"));
|
33
22
|
};
|
34
|
-
|
35
|
-
getData = function getData(e, key, spacer) {
|
23
|
+
getData = function(e, key, spacer) {
|
36
24
|
return e.attr(dataKey(key, spacer));
|
37
25
|
};
|
38
|
-
|
39
|
-
// automatically namespaces keys etc.
|
40
|
-
mergeDataOptions = function mergeDataOptions(element, options, keys, spacer) {
|
26
|
+
mergeDataOptions = function(element, options, keys, spacer) {
|
41
27
|
var _a, _b, _c, _d, key;
|
42
28
|
_a = []; _c = keys;
|
43
29
|
for (_b = 0, _d = _c.length; _b < _d; _b++) {
|
44
30
|
key = _c[_b];
|
45
31
|
_a.push((function() {
|
46
32
|
if (hasData(element, key, spacer)) {
|
47
|
-
options[key] = getData(element, key, spacer);
|
48
|
-
return options[key];
|
33
|
+
return (options[key] = getData(element, key, spacer));
|
49
34
|
}
|
50
35
|
})());
|
51
36
|
}
|
52
37
|
return _a;
|
53
38
|
};
|
54
|
-
|
55
|
-
mapOptionsForElement = function mapOptionsForElement(element) {
|
39
|
+
mapOptionsForElement = function(element) {
|
56
40
|
var options;
|
57
41
|
options = $.extend({}, map.defaultOptions);
|
58
|
-
// Set the mapTypeId if it's a function
|
59
42
|
if ($.isFunction(options.mapTypeId)) {
|
60
43
|
options.mapTypeId = options.mapTypeId();
|
61
44
|
}
|
62
45
|
mergeDataOptions(element, options, mapOptionKeys);
|
63
46
|
return options;
|
64
47
|
};
|
65
|
-
|
66
|
-
map.install = function install() {
|
48
|
+
map.install = function() {
|
67
49
|
return $('.gmap').each(function() {
|
68
50
|
return map.setupElement(this);
|
69
51
|
});
|
70
52
|
};
|
71
|
-
|
72
|
-
|
73
|
-
map.setupElement = function setupElement(e) {
|
74
|
-
var $e, currentMap, id, lat, lng, mapOptions, marker, markerOptions, point;
|
53
|
+
map.setupElement = function(e) {
|
54
|
+
var $e, address, currentMap, id, lat, lng, mapOptions, marker, markerOptions, point;
|
75
55
|
$e = $(e);
|
76
56
|
id = $e.attr("id");
|
77
57
|
if (!((typeof id !== "undefined" && id !== null))) {
|
78
58
|
$e.attr("id", ("" + (map.autoIDPrefix) + (map.count++)));
|
79
59
|
}
|
80
|
-
|
81
|
-
|
82
|
-
|
60
|
+
if (hasData($e, "latitude" && hasData($e, "longitude"))) {
|
61
|
+
lat = Number(getData($e, "latitude"));
|
62
|
+
lng = Number(getData($e, "longitude"));
|
63
|
+
map.drawLatLng($e, e, lat, lng);
|
64
|
+
} else {
|
65
|
+
address = getData($e, "address");
|
66
|
+
}
|
83
67
|
point = new google.maps.LatLng(lat, lng);
|
84
|
-
// Start setting up the map / create a map element.
|
85
68
|
mapOptions = mapOptionsForElement($e);
|
86
69
|
mapOptions.center = point;
|
87
70
|
$e.empty().addClass('dynamic-google-map').removeClass('static-google-map');
|
88
71
|
currentMap = new google.maps.Map(e, mapOptions);
|
89
72
|
map.maps.push(currentMap);
|
90
|
-
// Now, we need to finally add the marker to the map.
|
91
73
|
markerOptions = {
|
92
74
|
position: point,
|
93
75
|
map: currentMap
|
@@ -96,10 +78,8 @@ GMap = (function($) {
|
|
96
78
|
marker = new google.maps.Marker(markerOptions);
|
97
79
|
return currentMap;
|
98
80
|
};
|
99
|
-
// On load, we'll install the maps.
|
100
81
|
$(document).ready(function() {
|
101
82
|
return map.install();
|
102
83
|
});
|
103
|
-
// Return map to set it up.
|
104
84
|
return map;
|
105
85
|
})(jQuery);
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bhm-google-maps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
8
|
+
- 2
|
7
9
|
- 1
|
8
|
-
|
9
|
-
version: 0.1.3
|
10
|
+
version: 0.2.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Darcy Laycock
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-08-21 00:00:00 +08:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -57,23 +58,27 @@ rdoc_options:
|
|
57
58
|
require_paths:
|
58
59
|
- lib
|
59
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
60
62
|
requirements:
|
61
63
|
- - ">="
|
62
64
|
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
63
66
|
segments:
|
64
67
|
- 0
|
65
68
|
version: "0"
|
66
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
67
71
|
requirements:
|
68
72
|
- - ">="
|
69
73
|
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
70
75
|
segments:
|
71
76
|
- 0
|
72
77
|
version: "0"
|
73
78
|
requirements: []
|
74
79
|
|
75
80
|
rubyforge_project:
|
76
|
-
rubygems_version: 1.3.
|
81
|
+
rubygems_version: 1.3.7
|
77
82
|
signing_key:
|
78
83
|
specification_version: 3
|
79
84
|
summary: Helpers for Google Maps v3 in Rails - Using html 5, the google maps api v3 and the static maps api
|