diff --git a/app/Http/Controllers/MicropubClientController.php b/app/Http/Controllers/MicropubClientController.php index 0623ab43..672c66f2 100644 --- a/app/Http/Controllers/MicropubClientController.php +++ b/app/Http/Controllers/MicropubClientController.php @@ -224,7 +224,7 @@ class MicropubClientController extends Controller } return response()->json([ - 'url' => $place, + 'uri' => $place, 'name' => $request->input('place-name'), 'latitude' => $request->input('place-latitude'), 'longitude' => $request->input('place-longitude'), diff --git a/app/Http/Controllers/MicropubController.php b/app/Http/Controllers/MicropubController.php index 1858fc8b..8714ea28 100644 --- a/app/Http/Controllers/MicropubController.php +++ b/app/Http/Controllers/MicropubController.php @@ -150,7 +150,7 @@ class MicropubController extends Controller $distance = (count($matches[0]) == 3) ? 100 * $matches[0][2] : 1000; $places = Place::near($matches[0][0], $matches[0][1], $distance); foreach ($places as $place) { - $place->uri = config('app.url') . '/place/' . $place->slug; + $place->uri = config('app.url') . '/places/' . $place->slug; } return response()->json([ diff --git a/app/Http/Controllers/NotesController.php b/app/Http/Controllers/NotesController.php index 5b795a30..dda192ec 100644 --- a/app/Http/Controllers/NotesController.php +++ b/app/Http/Controllers/NotesController.php @@ -141,10 +141,12 @@ class NotesController extends Controller $note->placeLink = '/places/' . $note->place->slug; } - $note->photoURLs = []; - foreach ($note->getMedia() as $photo) { - $note->photoURLs[] = $photo->getUrl(); + $photoURLs = []; + $photos = $note->getMedia(); + foreach ($photos as $photo) { + $photoURLs[] = $photo->getUrl(); } + $note->photoURLs = $photoURLs; return view('singlenote', [ 'note' => $note, diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index 409ff790..b2258dbf 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -22,14 +22,14 @@ class NoteService if ($request->header('Content-Type') == 'application/json') { $content = $request->input('properties.content')[0]; $inReplyTo = $request->input('properties.in-reply-to')[0]; - $place = $request->input('properties.location'); - if (is_array($place)) { - $place = $place[0]; + $location = $request->input('properties.location'); + if (is_array($location)) { + $location = $location[0]; } } else { $content = $request->input('content'); $inReplyTo = $request->input('in-reply-to'); - $place = $request->input('location'); + $location = $request->input('location'); } $note = Note::create( @@ -40,19 +40,19 @@ class NoteService ] ); - if ($place !== null && $place !== 'no-location') { - if (substr($place, 0, strlen(config('app.url'))) == config('app.url')) { - //uri of form http://host/place/slug, we want slug so chop off start - //that’s the app’s url plus `/place/` - $slug = mb_substr($place, mb_strlen(config('app.url')) + 7); - $placeModel = Place::where('slug', '=', $slug)->first(); - $note->place()->associate($placeModel); + if ($location !== null && $location !== 'no-location') { + if (substr($location, 0, strlen(config('app.url'))) == config('app.url')) { + //uri of form http://host/places/slug, we want slug so chop off start + //that’s the app’s url plus `/places/` + $slug = mb_substr($location, mb_strlen(config('app.url')) + 8); + $place = Place::where('slug', '=', $slug)->first(); + $note->place()->associate($place); $note->save(); } - if (substr($place, 0, 4) == 'geo:') { + if (substr($location, 0, 4) == 'geo:') { preg_match_all( '/([0-9\.\-]+)/', - $place, + $location, $matches ); $note->location = $matches[0][0] . ', ' . $matches[0][1]; @@ -64,7 +64,7 @@ class NoteService if ($request->hasFile('photo')) { $files = $request->file('photo'); foreach ($files as $file) { - $note->addMedia($file)->toMediaLibrary('images', 's3'); + $note->addMedia($file)->toCollectionOnDisk('images', 's3'); } } diff --git a/changelog.md b/changelog.md index 395ce93b..d28ef0c0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Changelog +## Version 0.0.14 (2016-10-07) + - Fix image upload for notes + - Allow co-ordinates to be sent by the client as a geo: URI + - Allow endpoint to process geo: URIs for location + ## Version 0.0.13.9 (2016-10-06) - Hotfix, add missing semi-colon diff --git a/composer.lock b/composer.lock index 34e7aa4d..d88dde5d 100644 --- a/composer.lock +++ b/composer.lock @@ -58,16 +58,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.19.12", + "version": "3.19.13", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "5d5697c7bc9ab22ce718afb51e5496d0c5cb8778" + "reference": "57b0efed8fcf5d8c854bc1c26cf4a685af9108d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/5d5697c7bc9ab22ce718afb51e5496d0c5cb8778", - "reference": "5d5697c7bc9ab22ce718afb51e5496d0c5cb8778", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/57b0efed8fcf5d8c854bc1c26cf4a685af9108d9", + "reference": "57b0efed8fcf5d8c854bc1c26cf4a685af9108d9", "shasum": "" }, "require": { @@ -134,7 +134,7 @@ "s3", "sdk" ], - "time": "2016-09-29 21:07:49" + "time": "2016-10-06 21:17:44" }, { "name": "barnabywalters/mf-cleaner", @@ -1532,16 +1532,16 @@ }, { "name": "laravel/framework", - "version": "v5.3.15", + "version": "v5.3.17", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "f034a02f38db77d4b0b3e89942394cae456a627f" + "reference": "67fb3e638eb4d862279f50642101910163d14e61" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/f034a02f38db77d4b0b3e89942394cae456a627f", - "reference": "f034a02f38db77d4b0b3e89942394cae456a627f", + "url": "https://api.github.com/repos/laravel/framework/zipball/67fb3e638eb4d862279f50642101910163d14e61", + "reference": "67fb3e638eb4d862279f50642101910163d14e61", "shasum": "" }, "require": { @@ -1656,7 +1656,7 @@ "framework", "laravel" ], - "time": "2016-09-29 22:13:17" + "time": "2016-10-06 18:06:32" }, { "name": "lcobucci/jwt", @@ -2891,16 +2891,16 @@ }, { "name": "spatie/laravel-medialibrary", - "version": "4.9.1", + "version": "4.9.2", "source": { "type": "git", "url": "https://github.com/spatie/laravel-medialibrary.git", - "reference": "bb8786724f87c2d187897809849b7dc79a84a4d9" + "reference": "8799c17ca99c49718d7effe49de06b55117e8662" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/bb8786724f87c2d187897809849b7dc79a84a4d9", - "reference": "bb8786724f87c2d187897809849b7dc79a84a4d9", + "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/8799c17ca99c49718d7effe49de06b55117e8662", + "reference": "8799c17ca99c49718d7effe49de06b55117e8662", "shasum": "" }, "require": { @@ -2953,7 +2953,7 @@ "media", "spatie" ], - "time": "2016-09-23 11:54:31" + "time": "2016-10-06 05:42:25" }, { "name": "spatie/pdf-to-image", @@ -3007,24 +3007,24 @@ }, { "name": "spatie/string", - "version": "2.1.0", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/spatie/string.git", - "reference": "1843189c711be4dcf62b655824f2f17120c2dc7d" + "reference": "42b433803942494ee96dabd8f763f5b455e8de1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/string/zipball/1843189c711be4dcf62b655824f2f17120c2dc7d", - "reference": "1843189c711be4dcf62b655824f2f17120c2dc7d", + "url": "https://api.github.com/repos/spatie/string/zipball/42b433803942494ee96dabd8f763f5b455e8de1a", + "reference": "42b433803942494ee96dabd8f763f5b455e8de1a", "shasum": "" }, "require": { "anahkiasen/underscore-php": "^2.0", - "php": ">=5.5.0" + "php": ">=5.6.0" }, "require-dev": { - "phpunit/phpunit": "4.*", + "phpunit/phpunit": "5.*", "scrutinizer/ocular": "~1.1" }, "type": "library", @@ -3056,7 +3056,7 @@ "spatie", "string" ], - "time": "2015-11-02 13:00:37" + "time": "2016-10-04 15:31:55" }, { "name": "swiftmailer/swiftmailer", @@ -3113,20 +3113,21 @@ }, { "name": "symfony/console", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "8ea494c34f0f772c3954b5fbe00bffc5a435e563" + "reference": "6cb0872fb57b38b3b09ff213c21ed693956b9eb0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/8ea494c34f0f772c3954b5fbe00bffc5a435e563", - "reference": "8ea494c34f0f772c3954b5fbe00bffc5a435e563", + "url": "https://api.github.com/repos/symfony/console/zipball/6cb0872fb57b38b3b09ff213c21ed693956b9eb0", + "reference": "6cb0872fb57b38b3b09ff213c21ed693956b9eb0", "shasum": "" }, "require": { "php": ">=5.5.9", + "symfony/debug": "~2.8|~3.0", "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { @@ -3169,20 +3170,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2016-08-19 06:48:39" + "time": "2016-09-28 00:11:12" }, { "name": "symfony/debug", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "34f6ac18c2974ca5fce68adf419ee7d15def6f11" + "reference": "e2b3f74a67fc928adc3c1b9027f73e1bc01190a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/34f6ac18c2974ca5fce68adf419ee7d15def6f11", - "reference": "34f6ac18c2974ca5fce68adf419ee7d15def6f11", + "url": "https://api.github.com/repos/symfony/debug/zipball/e2b3f74a67fc928adc3c1b9027f73e1bc01190a8", + "reference": "e2b3f74a67fc928adc3c1b9027f73e1bc01190a8", "shasum": "" }, "require": { @@ -3226,11 +3227,11 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2016-08-23 13:39:15" + "time": "2016-09-06 11:02:40" }, { "name": "symfony/event-dispatcher", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", @@ -3290,16 +3291,16 @@ }, { "name": "symfony/finder", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "e568ef1784f447a0e54dcb6f6de30b9747b0f577" + "reference": "205b5ffbb518a98ba2ae60a52656c4a31ab00c6f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/e568ef1784f447a0e54dcb6f6de30b9747b0f577", - "reference": "e568ef1784f447a0e54dcb6f6de30b9747b0f577", + "url": "https://api.github.com/repos/symfony/finder/zipball/205b5ffbb518a98ba2ae60a52656c4a31ab00c6f", + "reference": "205b5ffbb518a98ba2ae60a52656c4a31ab00c6f", "shasum": "" }, "require": { @@ -3335,20 +3336,20 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2016-08-26 12:04:02" + "time": "2016-09-28 00:11:12" }, { "name": "symfony/http-foundation", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "63592e00fd90632b57ee50220a1ddb29b6bf3bb4" + "reference": "5114f1becca9f29e3af94374f1689c83c1aa3d97" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/63592e00fd90632b57ee50220a1ddb29b6bf3bb4", - "reference": "63592e00fd90632b57ee50220a1ddb29b6bf3bb4", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/5114f1becca9f29e3af94374f1689c83c1aa3d97", + "reference": "5114f1becca9f29e3af94374f1689c83c1aa3d97", "shasum": "" }, "require": { @@ -3388,20 +3389,20 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2016-08-22 12:11:19" + "time": "2016-09-21 20:55:10" }, { "name": "symfony/http-kernel", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "aeda215d6b01f119508c090d2a09ebb5b0bc61f3" + "reference": "dc339d6eebadfa6e39c52868b4d4a715eff13c69" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/aeda215d6b01f119508c090d2a09ebb5b0bc61f3", - "reference": "aeda215d6b01f119508c090d2a09ebb5b0bc61f3", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/dc339d6eebadfa6e39c52868b4d4a715eff13c69", + "reference": "dc339d6eebadfa6e39c52868b4d4a715eff13c69", "shasum": "" }, "require": { @@ -3470,7 +3471,7 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2016-09-03 15:28:24" + "time": "2016-10-03 19:01:06" }, { "name": "symfony/polyfill-mbstring", @@ -3641,16 +3642,16 @@ }, { "name": "symfony/process", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "e64e93041c80e77197ace5ab9385dedb5a143697" + "reference": "66de154ae86b1a07001da9fbffd620206e4faf94" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/e64e93041c80e77197ace5ab9385dedb5a143697", - "reference": "e64e93041c80e77197ace5ab9385dedb5a143697", + "url": "https://api.github.com/repos/symfony/process/zipball/66de154ae86b1a07001da9fbffd620206e4faf94", + "reference": "66de154ae86b1a07001da9fbffd620206e4faf94", "shasum": "" }, "require": { @@ -3686,11 +3687,11 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-08-16 14:58:24" + "time": "2016-09-29 14:13:09" }, { "name": "symfony/routing", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/routing.git", @@ -3765,16 +3766,16 @@ }, { "name": "symfony/translation", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "a35edc277513c9bc0f063ca174c36b346f974528" + "reference": "93013a18d272e59dab8e67f583155b78c68947eb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/a35edc277513c9bc0f063ca174c36b346f974528", - "reference": "a35edc277513c9bc0f063ca174c36b346f974528", + "url": "https://api.github.com/repos/symfony/translation/zipball/93013a18d272e59dab8e67f583155b78c68947eb", + "reference": "93013a18d272e59dab8e67f583155b78c68947eb", "shasum": "" }, "require": { @@ -3825,20 +3826,20 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2016-08-05 08:37:39" + "time": "2016-09-06 11:02:40" }, { "name": "symfony/var-dumper", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "62ee73706c421654a4c840028954510277f7dfc8" + "reference": "70bfe927b86ba9999aeebd829715b0bb2cd39a10" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/62ee73706c421654a4c840028954510277f7dfc8", - "reference": "62ee73706c421654a4c840028954510277f7dfc8", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/70bfe927b86ba9999aeebd829715b0bb2cd39a10", + "reference": "70bfe927b86ba9999aeebd829715b0bb2cd39a10", "shasum": "" }, "require": { @@ -3888,7 +3889,7 @@ "debug", "dump" ], - "time": "2016-08-31 09:05:42" + "time": "2016-09-29 14:13:09" }, { "name": "themattharris/tmhoauth", @@ -4851,16 +4852,16 @@ }, { "name": "phpunit/phpunit", - "version": "5.5.6", + "version": "5.6.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "146e0fe0bb7f44d1cefade0c93e86fe0b206dd79" + "reference": "a7f2db56518e50ab92f28f739810dfad2f223b6b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/146e0fe0bb7f44d1cefade0c93e86fe0b206dd79", - "reference": "146e0fe0bb7f44d1cefade0c93e86fe0b206dd79", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a7f2db56518e50ab92f28f739810dfad2f223b6b", + "reference": "a7f2db56518e50ab92f28f739810dfad2f223b6b", "shasum": "" }, "require": { @@ -4894,7 +4895,6 @@ "ext-pdo": "*" }, "suggest": { - "ext-tidy": "*", "ext-xdebug": "*", "phpunit/php-invoker": "~1.1" }, @@ -4904,7 +4904,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.5.x-dev" + "dev-master": "5.6.x-dev" } }, "autoload": { @@ -4930,20 +4930,20 @@ "testing", "xunit" ], - "time": "2016-10-03 07:48:45" + "time": "2016-10-06 15:20:39" }, { "name": "phpunit/phpunit-mock-objects", - "version": "3.3.0", + "version": "3.3.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "7462c19bdb9814f6e6bdeb5cad3eb3ce72c6e0da" + "reference": "03500345483e1e17b52e2e4d34a89c9408ab2902" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/7462c19bdb9814f6e6bdeb5cad3eb3ce72c6e0da", - "reference": "7462c19bdb9814f6e6bdeb5cad3eb3ce72c6e0da", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/03500345483e1e17b52e2e4d34a89c9408ab2902", + "reference": "03500345483e1e17b52e2e4d34a89c9408ab2902", "shasum": "" }, "require": { @@ -4989,7 +4989,7 @@ "mock", "xunit" ], - "time": "2016-09-27 03:17:40" + "time": "2016-10-04 11:03:26" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -5506,16 +5506,16 @@ }, { "name": "symfony/css-selector", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "2851e1932d77ce727776154d659b232d061e816a" + "reference": "ca809c64072e0fe61c1c7fb3c76cdc32265042ac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/2851e1932d77ce727776154d659b232d061e816a", - "reference": "2851e1932d77ce727776154d659b232d061e816a", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/ca809c64072e0fe61c1c7fb3c76cdc32265042ac", + "reference": "ca809c64072e0fe61c1c7fb3c76cdc32265042ac", "shasum": "" }, "require": { @@ -5555,11 +5555,11 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2016-06-29 05:41:56" + "time": "2016-09-06 11:02:40" }, { "name": "symfony/dom-crawler", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/dom-crawler.git", @@ -5615,16 +5615,16 @@ }, { "name": "symfony/yaml", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "f291ed25eb1435bddbe8a96caaef16469c2a092d" + "reference": "368b9738d4033c8b93454cb0dbd45d305135a6d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/f291ed25eb1435bddbe8a96caaef16469c2a092d", - "reference": "f291ed25eb1435bddbe8a96caaef16469c2a092d", + "url": "https://api.github.com/repos/symfony/yaml/zipball/368b9738d4033c8b93454cb0dbd45d305135a6d3", + "reference": "368b9738d4033c8b93454cb0dbd45d305135a6d3", "shasum": "" }, "require": { @@ -5660,7 +5660,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-09-02 02:12:52" + "time": "2016-09-25 08:27:07" }, { "name": "webmozart/assert", diff --git a/config/laravel-medialibrary.php b/config/laravel-medialibrary.php index c6abd4c5..9a85c547 100644 --- a/config/laravel-medialibrary.php +++ b/config/laravel-medialibrary.php @@ -29,7 +29,12 @@ return [ * When urls to files get generated this class will be called. Leave empty * if your files are stored locally above the site root or on s3. */ - 'custom_url_generator_class' => '', + 'custom_url_generator_class' => null, + + /* + * The class that contains the strategy for determining a media file's path. + */ + 'custom_path_generator_class' => null, 's3' => [ /* @@ -37,4 +42,18 @@ return [ */ 'domain' => env('AWS_S3_URL'), ], + + 'remote' => [ + /** + * Any extra headers that should be included when uploading media to + * a remote disk. Even though supported headers may vary between + * different drivers, a sensible default has been provided. + * + * Supported by S3: CacheControl, Expires, StorageClass, + * ServerSideEncryption, Metadata, ACL, ContentEncoding + */ + 'extra_headers' => [ + 'CacheControl' => 'max-age=604800', + ] + ], ]; diff --git a/public/assets/js/maps/newnote.js.map b/public/assets/js/maps/newnote.js.map index ae43e7bb..eb379534 100644 --- a/public/assets/js/maps/newnote.js.map +++ b/public/assets/js/maps/newnote.js.map @@ -1 +1 @@ -{"version":3,"sources":["newnote.js"],"names":["getLocation","navigator","geolocation","getCurrentPosition","position","addPlacesMap","coords","latitude","longitude","accuracy","uncertainty","fetch","credentials","method","then","response","json","j","error","alertify","reset","error_description","places","length","i","latlng","parseLocation","location","name","uri","push","addMap","catch","err","console","arguments","form","button","parentNode","div","document","createElement","setAttribute","appendChild","L","mapbox","accessToken","map","setView","addLayer","tileLayer","detectRetina","marker","draggable","addTo","on","placeFormLatitude","querySelector","value","getLatitudeFromMapboxMarker","getLatLng","placeFormLongitude","getLongitudeFromMapboxMarker","selectEl","noLocation","noLocText","createTextNode","insertBefore","forEach","item","option","text","dataset","placeMarker","icon","marker-size","marker-symbol","marker-color","bindPopup","closeButton","panTo","selectPlace","addEventListener","placeLat","selectedIndex","placeLon","newLocButton","nameLabel","classList","add","nameEl","descLabel","descEl","latLabel","latEl","lonLabel","lonEl","placeSubmit","formData","FormData","append","body","placeJson","Error","urlParts","split","slug","pop","removeChild","labels","querySelectorAll","removeLayer","newOption","newPlaceMarker","newName","placeError","point","re","resultArray","exec","selected","replace","disabled"],"mappings":"AAWA,QAASA,eACLC,UAAUC,YAAYC,mBAAmB,SAAUC,GAE/CC,aAAaD,EAASE,OAAOC,SAAUH,EAASE,OAAOE,UAAWJ,EAASE,OAAOG,YAI1F,QAASJ,cAAaE,EAAUC,EAAWE,GAEvCC,MAAM,gBAAkBJ,EAAW,IAAMC,EAAY,MAAQE,GACzDE,YAAa,cACbC,OAAQ,QACTC,KAAK,SAAUC,GACd,MAAOA,GAASC,SACjBF,KAAK,SAAUG,GAKd,GAJe,GAAXA,EAAEC,QACFC,SAASC,QACTD,SAASD,MAAMD,EAAEI,oBAEjBJ,EAAEK,OAAOC,OAAS,EAAG,CACrB,GAAIC,GACAF,IACJ,KAAKE,EAAI,EAAGA,EAAIP,EAAEK,OAAOC,SAAUC,EAAG,CAClC,GAAIC,GAASC,cAAcT,EAAEK,OAAOE,GAAGG,UACnCC,EAAOX,EAAEK,OAAOE,GAAGI,KACnBC,EAAMZ,EAAEK,OAAOE,GAAGK,GACtBP,GAAOQ,MAAMF,EAAMC,EAAKJ,EAAO,GAAIA,EAAO,KAG9CM,OAAOxB,EAAUC,EAAWc,OAG5BS,QAAOxB,EAAUC,KAEtBwB,MAAM,SAAUC,GACfC,QAAQhB,MAAMe,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AASD,MAAMiG,SAI3B/E,EAAK+B,aAAamB,EAAc/C,GAGpC,QAASb,eAAc0F,GACnB,GAAIC,GAAK,WACLC,EAAcD,EAAGE,KAAKH,GACtBzF,EAAW2F,EAAY,GAAGb,MAAM,IAEpC,QAAQ9E,EAAS,GAAIA,EAAS,IAGlC,QAASsD,aAAYyB,GACjBlE,SAASiB,cAAc,iBAAmBiD,EAAO,KAAKc,UAAW,EAGrE,QAAS7D,6BAA4BlC,GACjC,GAAI6F,GAAc,WAAWC,KAAK9F,GAC9BE,EAAW2F,EAAY,GAAGb,MAAM,IAEpC,OAAO9E,GAAS,GAAG8F,QAAQ,IAAK,IAGpC,QAAS3D,8BAA6BrC,GAClC,GAAI6F,GAAc,WAAWC,KAAK9F,GAC9BE,EAAW2F,EAAY,GAAGb,MAAM,IAEpC,OAAO9E,GAAS,GAvRpB,GAAI,eAAiB1B,WAAW,CAC5B,GAAIoC,QAASG,SAASiB,cAAc,UAChCpB,QAAO6C,mBAGP7C,OAAOqF,UAAW,EAClBrF,OAAO6C,iBAAiB,QAASlF","file":"newnote.js","sourcesContent":["/* global L, alertify */\nif ('geolocation' in navigator) {\n var button = document.querySelector('#locate');\n if (button.addEventListener) {\n //if we have javascript, event listeners and geolocation, make the locate\n //button clickable and add event\n button.disabled = false;\n button.addEventListener('click', getLocation);\n }\n}\n\nfunction getLocation() {\n navigator.geolocation.getCurrentPosition(function (position) {\n //the locate button has been clicked so add the places/map\n addPlacesMap(position.coords.latitude, position.coords.longitude, position.coords.accuracy);\n });\n}\n\nfunction addPlacesMap(latitude, longitude, uncertainty) {\n //get the nearby places\n fetch('/places/near/' + latitude + '/' + longitude + '?u=' + uncertainty, {\n credentials: 'same-origin',\n method: 'get'\n }).then(function (response) {\n return response.json();\n }).then(function (j) {\n if (j.error == true) {\n alertify.reset();\n alertify.error(j.error_description);\n }\n if (j.places.length > 0) {\n var i;\n var places = [];\n for (i = 0; i < j.places.length; ++i) {\n var latlng = parseLocation(j.places[i].location);\n var name = j.places[i].name;\n var uri = j.places[i].uri;\n places.push([name, uri, latlng[0], latlng[1]]);\n }\n //add a map with the nearby places\n addMap(latitude, longitude, places);\n } else {\n //add a map with just current location\n addMap(latitude, longitude);\n }\n }).catch(function (err) {\n console.error(err);\n });\n}\n\nfunction addMap(latitude, longitude, places) {\n //make places null if not supplied\n if (arguments.length == 2) {\n places = null;\n }\n var form = button.parentNode;\n var div = document.createElement('div');\n div.setAttribute('id', 'map');\n //add the map div\n form.appendChild(div);\n L.mapbox.accessToken = 'pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiVlpndW1EYyJ9.aP9fxAqLKh7lj0LpFh5k1w';\n var map = L.mapbox.map('map', 'jonnybarnes.gnoihnim')\n .setView([latitude, longitude], 15)\n .addLayer(L.mapbox.tileLayer('jonnybarnes.gnoihnim', {\n detectRetina: true\n }));\n //add a marker for the current location\n var marker = L.marker([latitude, longitude], {\n draggable: true\n }).addTo(map);\n //when the location marker is dragged, if the new place form elements exist\n //update the lat/lng values\n marker.on('dragend', function () {\n var placeFormLatitude = document.querySelector('#place-latitude');\n if (placeFormLatitude !== null) {\n placeFormLatitude.value = getLatitudeFromMapboxMarker(marker.getLatLng());\n }\n var placeFormLongitude = document.querySelector('#place-longitude');\n if (placeFormLongitude !== null) {\n placeFormLongitude.value = getLongitudeFromMapboxMarker(marker.getLatLng());\n }\n });\n //create the \n places.forEach(function (item) {\n var option = document.createElement('option');\n option.setAttribute('value', item[1]);\n var text = document.createTextNode(item[0]);\n option.appendChild(text);\n option.dataset.latitude = item[2];\n option.dataset.longitude = item[3];\n selectEl.appendChild(option);\n var placeMarker = L.marker([item[2], item[3]], {\n icon: L.mapbox.marker.icon({\n 'marker-size': 'large',\n 'marker-symbol': 'building',\n 'marker-color': '#fa0'\n })\n }).addTo(map);\n var name = 'Name: ' + item[0];\n placeMarker.bindPopup(name, {\n closeButton: true\n });\n placeMarker.on('click', function () {\n map.panTo([item[2], item[3]]);\n selectPlace(item[1]);\n });\n });\n //add an event listener\n selectEl.addEventListener('change', function () {\n if (selectEl.value !== 'no-location') {\n var placeLat = selectEl[selectEl.selectedIndex].dataset.latitude;\n var placeLon = selectEl[selectEl.selectedIndex].dataset.longitude;\n map.panTo([placeLat, placeLon]);\n }\n });\n }\n //add a button to add a new place\n var newLocButton = document.createElement('button');\n newLocButton.setAttribute('type', 'button');\n newLocButton.setAttribute('id', 'create-new-place');\n newLocButton.appendChild(document.createTextNode('Create New Place?'));\n //the event listener\n newLocButton.addEventListener('click', function() {\n //add the form elements\n var nameLabel = document.createElement('label');\n nameLabel.setAttribute('for', 'place-name');\n nameLabel.classList.add('place-label');\n nameLabel.appendChild(document.createTextNode('Place Name:'));\n var nameEl = document.createElement('input');\n nameEl.setAttribute('placeholder', 'Name');\n nameEl.setAttribute('name', 'place-name');\n nameEl.setAttribute('id', 'place-name');\n nameEl.setAttribute('type', 'text');\n var descLabel = document.createElement('label');\n descLabel.setAttribute('for', 'place-description');\n descLabel.classList.add('place-label');\n descLabel.appendChild(document.createTextNode('Place Description:'));\n var descEl = document.createElement('input');\n descEl.setAttribute('placeholder', 'Description');\n descEl.setAttribute('name', 'place-description');\n descEl.setAttribute('id', 'place-description');\n descEl.setAttribute('type', 'text');\n var latLabel = document.createElement('label');\n latLabel.setAttribute('for', 'place-latitude');\n latLabel.classList.add('place-label');\n latLabel.appendChild(document.createTextNode('Place Latitude:'));\n var latEl = document.createElement('input');\n latEl.setAttribute('name', 'place-latitude');\n latEl.setAttribute('id', 'place-latitude');\n latEl.setAttribute('type', 'text');\n latEl.value = getLatitudeFromMapboxMarker(marker.getLatLng());\n var lonLabel = document.createElement('label');\n lonLabel.setAttribute('for', 'place-longitude');\n lonLabel.classList.add('place-label');\n lonLabel.appendChild(document.createTextNode('Place Longitude:'));\n var lonEl = document.createElement('input');\n lonEl.setAttribute('name', 'place-longitude');\n lonEl.setAttribute('id', 'place-longitude');\n lonEl.setAttribute('type', 'text');\n lonEl.value = getLongitudeFromMapboxMarker(marker.getLatLng());\n var placeSubmit = document.createElement('button');\n placeSubmit.setAttribute('id', 'place-submit');\n placeSubmit.setAttribute('value', 'Submit New Place');\n placeSubmit.setAttribute('name', 'place-submit');\n placeSubmit.setAttribute('type', 'button');\n placeSubmit.appendChild(document.createTextNode('Submit New Place'));\n form.appendChild(nameLabel);\n form.appendChild(nameEl);\n form.appendChild(descLabel);\n form.appendChild(descEl);\n form.appendChild(latLabel);\n form.appendChild(latEl);\n form.appendChild(lonLabel);\n form.appendChild(lonEl);\n form.appendChild(placeSubmit);\n //the event listener for the new place form\n placeSubmit.addEventListener('click', function () {\n //create the form data to send\n var formData = new FormData();\n formData.append('place-name', document.querySelector('#place-name').value);\n formData.append('place-description', document.querySelector('#place-description').value);\n formData.append('place-latitude', document.querySelector('#place-latitude').value);\n formData.append('place-longitude', document.querySelector('#place-longitude').value);\n //post the new place\n fetch('/places/new', {\n //send cookies with the request\n credentials: 'same-origin',\n method: 'post',\n body: formData\n })\n .then(function (response) {\n return response.json();\n })\n .then(function (placeJson) {\n if (placeJson.error == true) {\n throw new Error(placeJson.error_description);\n }\n //create the slug from the url\n var urlParts = placeJson.split('/');\n var slug = urlParts.pop();\n //remove un-needed form elements\n form.removeChild(document.querySelector('#place-name'));\n form.removeChild(document.querySelector('#place-description'));\n form.removeChild(document.querySelector('#place-latitude'));\n form.removeChild(document.querySelector('#place-longitude'));\n var labels = document.querySelectorAll('.place-label');\n for (var i = 0; i < labels.length; ++i) {\n form.removeChild(labels[i]);\n }\n form.removeChild(document.querySelector('#place-submit'));\n form.removeChild(document.querySelector('#create-new-place'));\n //remove location marker\n map.removeLayer(marker);\n //add place marker\n var newOption = document.createElement('option');\n newOption.setAttribute('value', slug);\n newOption.appendChild(document.createTextNode(placeJson['name']));\n newOption.dataset.latitude = placeJson['latitude'];\n newOption.dataset.longitude = placeJson['longitude'];\n selectEl.appendChild(newOption);\n var newPlaceMarker = L.marker([placeJson['latitude'], placeJson['longitude']], {\n icon: L.mapbox.marker.icon({\n 'marker-size': 'large',\n 'marker-symbol': 'building',\n 'marker-color': '#fa0'\n })\n }).addTo(map);\n var newName = 'Name: ' + placeJson['name'];\n newPlaceMarker.bindPopup(newName, {\n closeButton: true\n });\n newPlaceMarker.on('click', function () {\n map.panTo([placeJson['latitude'], placeJson['longitude']]);\n selectPlace(slug);\n });\n //make selected\n selectPlace(slug);\n }).catch(function (placeError) {\n alertify.reset();\n alertify.error(placeError);\n });\n });\n });\n form.insertBefore(newLocButton, div);\n}\n\nfunction parseLocation(point) {\n var re = /\\((.*)\\)/;\n var resultArray = re.exec(point);\n var location = resultArray[1].split(' ');\n\n return [location[1], location[0]];\n}\n\nfunction selectPlace(slug) {\n document.querySelector('select [value=' + slug + ']').selected = true;\n}\n\nfunction getLatitudeFromMapboxMarker(latlng) {\n var resultArray = /\\((.*)\\)/.exec(latlng);\n var location = resultArray[1].split(' ');\n\n return location[0].replace(',', '');\n}\n\nfunction getLongitudeFromMapboxMarker(latlng) {\n var resultArray = /\\((.*)\\)/.exec(latlng);\n var location = resultArray[1].split(' ');\n\n return location[1];\n}\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["newnote.js"],"names":["getLocation","navigator","geolocation","getCurrentPosition","position","addPlacesMap","coords","latitude","longitude","accuracy","uncertainty","fetch","credentials","method","then","response","json","j","error","alertify","reset","error_description","places","length","i","latlng","parseLocation","location","name","uri","push","addMap","catch","err","console","arguments","form","button","parentNode","div","document","createElement","setAttribute","appendChild","L","mapbox","accessToken","map","setView","addLayer","tileLayer","detectRetina","marker","draggable","addTo","on","mapMarkerLatitude","getLatitudeFromMapboxMarker","getLatLng","mapMarkerLongitude","getLongitudeFromMapboxMarker","coordsOption","querySelector","value","placeFormLatitude","placeFormLongitude","selectEl","noLocation","createTextNode","geoLocation","insertBefore","forEach","item","option","text","dataset","placeMarker","icon","marker-size","marker-symbol","marker-color","bindPopup","closeButton","panTo","selectPlace","addEventListener","placeLat","selectedIndex","placeLon","newLocButton","nameLabel","classList","add","nameEl","descLabel","descEl","latLabel","latEl","lonLabel","lonEl","placeSubmit","formData","FormData","append","body","placeJson","Error","removeChild","labels","querySelectorAll","removeLayer","newOption","newPlaceMarker","newName","placeError","point","re","resultArray","exec","split","selected","replace","disabled"],"mappings":"AAWA,QAASA,eACLC,UAAUC,YAAYC,mBAAmB,SAAUC,GAE/CC,aAAaD,EAASE,OAAOC,SAAUH,EAASE,OAAOE,UAAWJ,EAASE,OAAOG,YAI1F,QAASJ,cAAaE,EAAUC,EAAWE,GAEvCC,MAAM,gBAAkBJ,EAAW,IAAMC,EAAY,MAAQE,GACzDE,YAAa,cACbC,OAAQ,QACTC,KAAK,SAAUC,GACd,MAAOA,GAASC,SACjBF,KAAK,SAAUG,GAKd,GAJe,GAAXA,EAAEC,QACFC,SAASC,QACTD,SAASD,MAAMD,EAAEI,oBAEjBJ,EAAEK,OAAOC,OAAS,EAAG,CACrB,GAAIC,GACAF,IACJ,KAAKE,EAAI,EAAGA,EAAIP,EAAEK,OAAOC,SAAUC,EAAG,CAClC,GAAIC,GAASC,cAAcT,EAAEK,OAAOE,GAAGG,UACnCC,EAAOX,EAAEK,OAAOE,GAAGI,KACnBC,EAAMZ,EAAEK,OAAOE,GAAGK,GACtBP,GAAOQ,MAAMF,EAAMC,EAAKJ,EAAO,GAAIA,EAAO,KAG9CM,OAAOxB,EAAUC,EAAWc,OAG5BS,QAAOxB,EAAUC,KAEtBwB,MAAM,SAAUC,GACfC,QAAQhB,MAAMe,KAItB,QAASF,QAAOxB,EAAUC,EAAWc,GAET,GAApBa,UAAUZ,SACVD,EAAS,KAEb,IAAIc,GAAOC,OAAOC,WACdC,EAAMC,SAASC,cAAc,MACjCF,GAAIG,aAAa,KAAM,OAEvBN,EAAKO,YAAYJ,GACjBK,EAAEC,OAAOC,YAAc,wEACvB,IAAIC,GAAMH,EAAEC,OAAOE,IAAI,MAAO,wBACzBC,SAASzC,EAAUC,GAAY,IAC/ByC,SAASL,EAAEC,OAAOK,UAAU,w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SAASD,MAAMgG,SAI3B9E,EAAKkC,aAAamB,EAAclD,GAGpC,QAASb,eAAcyF,GACnB,GAAIC,GAAK,WACLC,EAAcD,EAAGE,KAAKH,GACtBxF,EAAW0F,EAAY,GAAGE,MAAM,IAEpC,QAAQ5F,EAAS,GAAIA,EAAS,IAGlC,QAASyD,aAAYvD,GACjBW,SAASsB,cAAc,kBAAoBjC,EAAM,MAAM2F,UAAW,EAGtE,QAAS/D,6BAA4BhC,GACjC,GAAI4F,GAAc,WAAWC,KAAK7F,GAC9BE,EAAW0F,EAAY,GAAGE,MAAM,IAEpC,OAAO5F,GAAS,GAAG8F,QAAQ,IAAK,IAGpC,QAAS7D,8BAA6BnC,GAClC,GAAI4F,GAAc,WAAWC,KAAK7F,GAC9BE,EAAW0F,EAAY,GAAGE,MAAM,IAEpC,OAAO5F,GAAS,GA/RpB,GAAI,eAAiB1B,WAAW,CAC5B,GAAIoC,QAASG,SAASsB,cAAc,UAChCzB,QAAOgD,mBAGPhD,OAAOqF,UAAW,EAClBrF,OAAOgD,iBAAiB,QAASrF","file":"newnote.js","sourcesContent":["/* global L, alertify */\nif ('geolocation' in navigator) {\n var button = document.querySelector('#locate');\n if (button.addEventListener) {\n //if we have javascript, event listeners and geolocation, make the locate\n //button clickable and add event\n button.disabled = false;\n button.addEventListener('click', getLocation);\n }\n}\n\nfunction getLocation() {\n navigator.geolocation.getCurrentPosition(function (position) {\n //the locate button has been clicked so add the places/map\n addPlacesMap(position.coords.latitude, position.coords.longitude, position.coords.accuracy);\n });\n}\n\nfunction addPlacesMap(latitude, longitude, uncertainty) {\n //get the nearby places\n fetch('/places/near/' + latitude + '/' + longitude + '?u=' + uncertainty, {\n credentials: 'same-origin',\n method: 'get'\n }).then(function (response) {\n return response.json();\n }).then(function (j) {\n if (j.error == true) {\n alertify.reset();\n alertify.error(j.error_description);\n }\n if (j.places.length > 0) {\n var i;\n var places = [];\n for (i = 0; i < j.places.length; ++i) {\n var latlng = parseLocation(j.places[i].location);\n var name = j.places[i].name;\n var uri = j.places[i].uri;\n places.push([name, uri, latlng[0], latlng[1]]);\n }\n //add a map with the nearby places\n addMap(latitude, longitude, places);\n } else {\n //add a map with just current location\n addMap(latitude, longitude);\n }\n }).catch(function (err) {\n console.error(err);\n });\n}\n\nfunction addMap(latitude, longitude, places) {\n //make places null if not supplied\n if (arguments.length == 2) {\n places = null;\n }\n var form = button.parentNode;\n var div = document.createElement('div');\n div.setAttribute('id', 'map');\n //add the map div\n form.appendChild(div);\n L.mapbox.accessToken = 'pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiVlpndW1EYyJ9.aP9fxAqLKh7lj0LpFh5k1w';\n var map = L.mapbox.map('map', 'jonnybarnes.gnoihnim')\n .setView([latitude, longitude], 15)\n .addLayer(L.mapbox.tileLayer('jonnybarnes.gnoihnim', {\n detectRetina: true\n }));\n //add a marker for the current location\n var marker = L.marker([latitude, longitude], {\n draggable: true\n }).addTo(map);\n //when the location marker is dragged, if the new place form elements exist\n //update the lat/lng values\n marker.on('dragend', function () {\n var mapMarkerLatitude = getLatitudeFromMapboxMarker(marker.getLatLng());\n var mapMarkerLongitude = getLongitudeFromMapboxMarker(marker.getLatLng());\n var coordsOption = document.querySelector('#option-coords');\n if (coordsOption != null) {\n coordsOption.value = 'geo:' + mapMarkerLatitude + ',' + mapMarkerLongitude;\n }\n var placeFormLatitude = document.querySelector('#place-latitude');\n if (placeFormLatitude !== null) {\n placeFormLatitude.value = mapMarkerLatitude;\n }\n var placeFormLongitude = document.querySelector('#place-longitude');\n if (placeFormLongitude !== null) {\n placeFormLongitude.value = mapMarkerLongitude;\n }\n });\n //create the \n places.forEach(function (item) {\n var option = document.createElement('option');\n option.setAttribute('value', item[1]);\n var text = document.createTextNode(item[0]);\n option.appendChild(text);\n option.dataset.latitude = item[2];\n option.dataset.longitude = item[3];\n selectEl.appendChild(option);\n var placeMarker = L.marker([item[2], item[3]], {\n icon: L.mapbox.marker.icon({\n 'marker-size': 'large',\n 'marker-symbol': 'building',\n 'marker-color': '#fa0'\n })\n }).addTo(map);\n var name = 'Name: ' + item[0];\n placeMarker.bindPopup(name, {\n closeButton: true\n });\n placeMarker.on('click', function () {\n map.panTo([item[2], item[3]]);\n selectPlace(item[1]);\n });\n });\n //add an event listener\n selectEl.addEventListener('change', function () {\n if (selectEl.value !== 'no-location') {\n var placeLat = selectEl[selectEl.selectedIndex].dataset.latitude;\n var placeLon = selectEl[selectEl.selectedIndex].dataset.longitude;\n map.panTo([placeLat, placeLon]);\n }\n });\n }\n //add a button to add a new place\n var newLocButton = document.createElement('button');\n newLocButton.setAttribute('type', 'button');\n newLocButton.setAttribute('id', 'create-new-place');\n newLocButton.appendChild(document.createTextNode('Create New Place?'));\n //the event listener\n newLocButton.addEventListener('click', function() {\n //add the form elements\n var nameLabel = document.createElement('label');\n nameLabel.setAttribute('for', 'place-name');\n nameLabel.classList.add('place-label');\n nameLabel.appendChild(document.createTextNode('Place Name:'));\n var nameEl = document.createElement('input');\n nameEl.setAttribute('placeholder', 'Name');\n nameEl.setAttribute('name', 'place-name');\n nameEl.setAttribute('id', 'place-name');\n nameEl.setAttribute('type', 'text');\n var descLabel = document.createElement('label');\n descLabel.setAttribute('for', 'place-description');\n descLabel.classList.add('place-label');\n descLabel.appendChild(document.createTextNode('Place Description:'));\n var descEl = document.createElement('input');\n descEl.setAttribute('placeholder', 'Description');\n descEl.setAttribute('name', 'place-description');\n descEl.setAttribute('id', 'place-description');\n descEl.setAttribute('type', 'text');\n var latLabel = document.createElement('label');\n latLabel.setAttribute('for', 'place-latitude');\n latLabel.classList.add('place-label');\n latLabel.appendChild(document.createTextNode('Place Latitude:'));\n var latEl = document.createElement('input');\n latEl.setAttribute('name', 'place-latitude');\n latEl.setAttribute('id', 'place-latitude');\n latEl.setAttribute('type', 'text');\n latEl.value = getLatitudeFromMapboxMarker(marker.getLatLng());\n var lonLabel = document.createElement('label');\n lonLabel.setAttribute('for', 'place-longitude');\n lonLabel.classList.add('place-label');\n lonLabel.appendChild(document.createTextNode('Place Longitude:'));\n var lonEl = document.createElement('input');\n lonEl.setAttribute('name', 'place-longitude');\n lonEl.setAttribute('id', 'place-longitude');\n lonEl.setAttribute('type', 'text');\n lonEl.value = getLongitudeFromMapboxMarker(marker.getLatLng());\n var placeSubmit = document.createElement('button');\n placeSubmit.setAttribute('id', 'place-submit');\n placeSubmit.setAttribute('value', 'Submit New Place');\n placeSubmit.setAttribute('name', 'place-submit');\n placeSubmit.setAttribute('type', 'button');\n placeSubmit.appendChild(document.createTextNode('Submit New Place'));\n form.appendChild(nameLabel);\n form.appendChild(nameEl);\n form.appendChild(descLabel);\n form.appendChild(descEl);\n form.appendChild(latLabel);\n form.appendChild(latEl);\n form.appendChild(lonLabel);\n form.appendChild(lonEl);\n form.appendChild(placeSubmit);\n //the event listener for the new place form\n placeSubmit.addEventListener('click', function () {\n //create the form data to send\n var formData = new FormData();\n formData.append('place-name', document.querySelector('#place-name').value);\n formData.append('place-description', document.querySelector('#place-description').value);\n formData.append('place-latitude', document.querySelector('#place-latitude').value);\n formData.append('place-longitude', document.querySelector('#place-longitude').value);\n //post the new place\n fetch('/places/new', {\n //send cookies with the request\n credentials: 'same-origin',\n method: 'post',\n body: formData\n })\n .then(function (response) {\n return response.json();\n })\n .then(function (placeJson) {\n if (placeJson.error == true) {\n throw new Error(placeJson.error_description);\n }\n //remove un-needed form elements\n form.removeChild(document.querySelector('#place-name'));\n form.removeChild(document.querySelector('#place-description'));\n form.removeChild(document.querySelector('#place-latitude'));\n form.removeChild(document.querySelector('#place-longitude'));\n var labels = document.querySelectorAll('.place-label');\n for (var i = 0; i < labels.length; ++i) {\n form.removeChild(labels[i]);\n }\n form.removeChild(document.querySelector('#place-submit'));\n form.removeChild(document.querySelector('#create-new-place'));\n //remove location marker\n map.removeLayer(marker);\n //add place marker\n var newOption = document.createElement('option');\n newOption.setAttribute('value', placeJson.uri);\n newOption.appendChild(document.createTextNode(placeJson.name));\n newOption.dataset.latitude = placeJson.latitude;\n newOption.dataset.longitude = placeJson.longitude;\n selectEl.appendChild(newOption);\n var newPlaceMarker = L.marker([placeJson.latitude, placeJson.longitude], {\n icon: L.mapbox.marker.icon({\n 'marker-size': 'large',\n 'marker-symbol': 'building',\n 'marker-color': '#fa0'\n })\n }).addTo(map);\n map.panTo([placeJson.latitude, placeJson.longitude]);\n var newName = 'Name: ' + placeJson.name;\n newPlaceMarker.bindPopup(newName, {\n closeButton: true\n });\n newPlaceMarker.on('click', function () {\n map.panTo([placeJson.latitude, placeJson.longitude]);\n selectPlace(placeJson.uri);\n });\n //make selected\n selectPlace(placeJson.uri);\n }).catch(function (placeError) {\n alertify.reset();\n alertify.error(placeError);\n });\n });\n });\n form.insertBefore(newLocButton, div);\n}\n\nfunction parseLocation(point) {\n var re = /\\((.*)\\)/;\n var resultArray = re.exec(point);\n var location = resultArray[1].split(' ');\n\n return [location[1], location[0]];\n}\n\nfunction selectPlace(uri) {\n document.querySelector('select [value=\"' + uri + '\"]').selected = true;\n}\n\nfunction getLatitudeFromMapboxMarker(latlng) {\n var resultArray = /\\((.*)\\)/.exec(latlng);\n var location = resultArray[1].split(' ');\n\n return location[0].replace(',', '');\n}\n\nfunction getLongitudeFromMapboxMarker(latlng) {\n var resultArray = /\\((.*)\\)/.exec(latlng);\n var location = resultArray[1].split(' ');\n\n return location[1];\n}\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/public/assets/js/newnote.js b/public/assets/js/newnote.js index 5a092f6e..a64104bb 100644 --- a/public/assets/js/newnote.js +++ b/public/assets/js/newnote.js @@ -1,2 +1,2 @@ -function getLocation(){navigator.geolocation.getCurrentPosition(function(e){addPlacesMap(e.coords.latitude,e.coords.longitude,e.coords.accuracy)})}function addPlacesMap(e,t,a){fetch("/places/near/"+e+"/"+t+"?u="+a,{credentials:"same-origin",method:"get"}).then(function(e){return e.json()}).then(function(a){if(1==a.error&&(alertify.reset(),alertify.error(a.error_description)),a.places.length>0){var n,r=[];for(n=0;n0){var n,r=[];for(n=0;n element and give it a no location default var selectEl = document.createElement('select'); selectEl.setAttribute('name', 'location'); var noLocation = document.createElement('option'); - noLocation.setAttribute('selected', 'selected'); noLocation.setAttribute('value', 'no-location'); - var noLocText = document.createTextNode('Select no location'); - noLocation.appendChild(noLocText); + noLocation.appendChild(document.createTextNode('Don’t send location')); selectEl.appendChild(noLocation); + var geoLocation = document.createElement('option'); + geoLocation.setAttribute('selected', 'selected'); + geoLocation.setAttribute('id', 'option-coords'); + geoLocation.setAttribute('value', 'geo:' + latitude + ',' + longitude); + geoLocation.appendChild(document.createTextNode('Send co-ordinates')); + selectEl.appendChild(geoLocation); form.insertBefore(selectEl, div); if (places !== null) { //add the places both to the map and