leaflet-hash-rails 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ff8101949067047c53edb3287e0c10da0c22cc3
4
+ data.tar.gz: a5a83549c4da619d8deba2b9bf5c968004ecdaca
5
+ SHA512:
6
+ metadata.gz: 70e74c5713968de79510397c976b5e14bd2d6ea0f419fc9eeb730d348ff9ca5f94cd6db16222579d2b7e0f9d72edbf028475b60de504560e7374a1d5fc862424
7
+ data.tar.gz: 7bba266d5ca7229fd387a8ddc635bffa9faa336ee60196ced31f950df23c319714b0ec844fd8f3fce2da24ed1261932eea1b279da03e13172b51e732f5b85ad5
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in leaflet-hash-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Rodrigo Frederic
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # leaflet-hash for Rails
2
+
3
+ Packaged for the Rails 3.1+ asset pipeline.
4
+ Check [leaflet-hash project home page](https://github.com/mlevans/leaflet-hash).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'leaflet-hash-rails'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install leaflet-hash-rails
19
+
20
+ ## Usage
21
+
22
+ Add the following JavaScript file to `app/assets/javascripts/application.js`:
23
+
24
+ //= require leaflet-hash-rails.js
25
+
26
+ ## License
27
+
28
+ Simplecolorpicker is licensed under the MIT license, this gem too.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/leaflet-hash-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Frederic Rodrigo"]
6
+ gem.email = ["fred.rodrigo@gmail.com"]
7
+ gem.description = %q{Add URL hashes to web pages with Leaflet maps}
8
+ gem.summary = %q{Leaflet-hash lets you to add dynamic URL hashes to web pages with Leaflet maps. You can easily link users to specific map views.}
9
+ gem.homepage = "https://github.com/mlevans/leaflet-hash"
10
+ gem.license = 'MIT'
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "leaflet-hash-rails"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = Leaflet::Hash::Rails::VERSION
18
+
19
+ gem.add_dependency 'railties', '>= 3.1.0'
20
+ end
@@ -0,0 +1,10 @@
1
+ require "leaflet-hash-rails/version"
2
+
3
+ module Leaflet
4
+ module Hash
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Leaflet
2
+ module Hash
3
+ module Rails
4
+ VERSION = "0.2.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,162 @@
1
+ (function(window) {
2
+ var HAS_HASHCHANGE = (function() {
3
+ var doc_mode = window.documentMode;
4
+ return ('onhashchange' in window) &&
5
+ (doc_mode === undefined || doc_mode > 7);
6
+ })();
7
+
8
+ L.Hash = function(map) {
9
+ this.onHashChange = L.Util.bind(this.onHashChange, this);
10
+
11
+ if (map) {
12
+ this.init(map);
13
+ }
14
+ };
15
+
16
+ L.Hash.parseHash = function(hash) {
17
+ if(hash.indexOf('#') === 0) {
18
+ hash = hash.substr(1);
19
+ }
20
+ var args = hash.split("/");
21
+ if (args.length == 3) {
22
+ var zoom = parseInt(args[0], 10),
23
+ lat = parseFloat(args[1]),
24
+ lon = parseFloat(args[2]);
25
+ if (isNaN(zoom) || isNaN(lat) || isNaN(lon)) {
26
+ return false;
27
+ } else {
28
+ return {
29
+ center: new L.LatLng(lat, lon),
30
+ zoom: zoom
31
+ };
32
+ }
33
+ } else {
34
+ return false;
35
+ }
36
+ };
37
+
38
+ L.Hash.formatHash = function(map) {
39
+ var center = map.getCenter(),
40
+ zoom = map.getZoom(),
41
+ precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
42
+
43
+ return "#" + [zoom,
44
+ center.lat.toFixed(precision),
45
+ center.lng.toFixed(precision)
46
+ ].join("/");
47
+ },
48
+
49
+ L.Hash.prototype = {
50
+ map: null,
51
+ lastHash: null,
52
+
53
+ parseHash: L.Hash.parseHash,
54
+ formatHash: L.Hash.formatHash,
55
+
56
+ init: function(map) {
57
+ this.map = map;
58
+
59
+ // reset the hash
60
+ this.lastHash = null;
61
+ this.onHashChange();
62
+
63
+ if (!this.isListening) {
64
+ this.startListening();
65
+ }
66
+ },
67
+
68
+ removeFrom: function(map) {
69
+ if (this.changeTimeout) {
70
+ clearTimeout(this.changeTimeout);
71
+ }
72
+
73
+ if (this.isListening) {
74
+ this.stopListening();
75
+ }
76
+
77
+ this.map = null;
78
+ },
79
+
80
+ onMapMove: function() {
81
+ // bail if we're moving the map (updating from a hash),
82
+ // or if the map is not yet loaded
83
+
84
+ if (this.movingMap || !this.map._loaded) {
85
+ return false;
86
+ }
87
+
88
+ var hash = this.formatHash(this.map);
89
+ if (this.lastHash != hash) {
90
+ location.replace(hash);
91
+ this.lastHash = hash;
92
+ }
93
+ },
94
+
95
+ movingMap: false,
96
+ update: function() {
97
+ var hash = location.hash;
98
+ if (hash === this.lastHash) {
99
+ return;
100
+ }
101
+ var parsed = this.parseHash(hash);
102
+ if (parsed) {
103
+ this.movingMap = true;
104
+
105
+ this.map.setView(parsed.center, parsed.zoom);
106
+
107
+ this.movingMap = false;
108
+ } else {
109
+ this.onMapMove(this.map);
110
+ }
111
+ },
112
+
113
+ // defer hash change updates every 100ms
114
+ changeDefer: 100,
115
+ changeTimeout: null,
116
+ onHashChange: function() {
117
+ // throttle calls to update() so that they only happen every
118
+ // `changeDefer` ms
119
+ if (!this.changeTimeout) {
120
+ var that = this;
121
+ this.changeTimeout = setTimeout(function() {
122
+ that.update();
123
+ that.changeTimeout = null;
124
+ }, this.changeDefer);
125
+ }
126
+ },
127
+
128
+ isListening: false,
129
+ hashChangeInterval: null,
130
+ startListening: function() {
131
+ this.map.on("moveend", this.onMapMove, this);
132
+
133
+ if (HAS_HASHCHANGE) {
134
+ L.DomEvent.addListener(window, "hashchange", this.onHashChange);
135
+ } else {
136
+ clearInterval(this.hashChangeInterval);
137
+ this.hashChangeInterval = setInterval(this.onHashChange, 50);
138
+ }
139
+ this.isListening = true;
140
+ },
141
+
142
+ stopListening: function() {
143
+ this.map.off("moveend", this.onMapMove, this);
144
+
145
+ if (HAS_HASHCHANGE) {
146
+ L.DomEvent.removeListener(window, "hashchange", this.onHashChange);
147
+ } else {
148
+ clearInterval(this.hashChangeInterval);
149
+ }
150
+ this.isListening = false;
151
+ }
152
+ };
153
+ L.hash = function(map) {
154
+ return new L.Hash(map);
155
+ };
156
+ L.Map.prototype.addHash = function() {
157
+ this._hash = L.hash(this);
158
+ };
159
+ L.Map.prototype.removeHash = function() {
160
+ this._hash.removeFrom();
161
+ };
162
+ })(window);
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: leaflet-hash-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Frederic Rodrigo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.0
27
+ description: Add URL hashes to web pages with Leaflet maps
28
+ email:
29
+ - fred.rodrigo@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - leaflet-hash-rails.gemspec
40
+ - lib/leaflet-hash-rails.rb
41
+ - lib/leaflet-hash-rails/version.rb
42
+ - vendor/assets/javascripts/leaflet-hash.js
43
+ homepage: https://github.com/mlevans/leaflet-hash
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.4.5.1
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Leaflet-hash lets you to add dynamic URL hashes to web pages with Leaflet
67
+ maps. You can easily link users to specific map views.
68
+ test_files: []