{"version":3,"file":"L.Control.Bookmarks.js","sources":["../src/string.js","../src/storage/global.js","../src/storage/localstorage.js","../src/storage.js","../src/formpopup.js","../src/leaflet.delegate.js","../src/bookmarks.js","../index.js"],"sourcesContent":["/**\n * Substitutes {{ obj.field }} in strings\n *\n * @param {String} str\n * @param {Object} object\n * @param {RegExp=} regexp\n * @return {String}\n */\nexport function substitute(str, object, regexp) {\n return str.replace(regexp || (/{{([\\s\\S]+?)}}/g), function(match, name) {\n name = trim(name);\n\n if (name.indexOf('.') === -1) {\n if (match.charAt(0) == '\\\\') return match.slice(1);\n return (object[name] != null) ? object[name] : '';\n\n } else { // nested\n let result = object;\n name = name.split('.');\n for (var i = 0, len = name.length; i < len; i++) {\n if (name[i] in result) result = result[name[i]];\n else return '';\n }\n return result;\n }\n });\n}\n\nconst alpha = 'abcdefghijklmnopqrstuvwxyz';\n/**\n * Unique string from date. Puts character at the beginning,\n * for the sake of good manners\n *\n * @return {String}\n */\nexport function unique(prefix) {\n return (prefix || alpha[Math.floor(Math.random() * alpha.length)]) +\n (new Date()).getTime().toString(16);\n}\n\n/**\n * Trim whitespace\n * @param {String} str\n * @return {String}\n */\nexport function trim(str) {\n return str.replace(/^\\s+|\\s+$/g, '');\n}\n\n/**\n * Clean and trim\n * @param {String} str\n * @return {String}\n */\nexport function clean(str) {\n return trim(str.replace(/\\s+/g, ' '));\n}\n","/**\n * @type {Object}\n */\nconst data = {};\n\n/**\n * Object based storage\n * @class Storage.Engine.Global\n * @constructor\n */\nexport default class GlobalStorage {\n constructor (prefix) {\n\n /**\n * @type {String}\n */\n this._prefix = prefix;\n }\n\n /**\n * @param {String} key\n * @param {Function} callback\n */\n getItem (key, callback) {\n callback(data[this._prefix + key]);\n }\n\n /**\n * @param {String} key\n * @param {*} item\n * @param {Function} callback\n */\n setItem (key, item, callback) {\n data[this._prefix + key] = item;\n callback(item);\n }\n\n /**\n * @param {Function} callback\n */\n getAllItems (callback) {\n const items = [];\n for (const key in data) {\n if (data.hasOwnProperty(key) && key.indexOf(this_prefix) === 0) {\n items.push(data[key]);\n }\n }\n callback(items);\n }\n\n /**\n * @param {String} key\n * @param {Function} callback\n */\n removeItem (key, callback) {\n this.getItem(key, (item) => {\n if (item) {\n delete data[this._prefix + key];\n } else {\n item = null;\n }\n if (callback) callback(item);\n });\n }\n}\n","/**\n * @const\n * @type {RegExp}\n */\nconst JSON_RE = /^[\\{\\[](.)*[\\]\\}]$/;\n\n/**\n * LocalStoarge based storage\n */\nexport default class LocalStorage {\n\n constructor (prefix) {\n /**\n * @type {String}\n */\n this._prefix = prefix;\n\n /**\n * @type {LocalStorage}\n */\n this._storage = window.localStorage;\n }\n\n /**\n * @param {String} key\n * @param {Function} callback\n */\n getItem (key, callback) {\n let item = this._storage.getItem(this._prefix + key);\n if (item && JSON_RE.test(item)) {\n item = JSON.parse(item);\n }\n callback(item);\n }\n\n /**\n * @param {Function} callback\n */\n getAllItems (callback) {\n const items = [];\n const prefixLength = this._prefix.length;\n for (const key in this._storage) {\n if (this._storage.getItem(key) !== null &&\n key.indexOf(this._prefix) === 0) {\n this.getItem(key.substring(prefixLength), (item) => items.push(item));\n }\n }\n callback(items);\n }\n\n /**\n * @param {String} key\n * @param {Function} callback\n */\n removeItem (key, callback) {\n const self = this;\n this.getItem(key, (item) => {\n this._storage.removeItem(self._prefix + key);\n if (callback) callback(item);\n });\n }\n\n /**\n * @param {String} key\n * @param {*} item\n * @param {Function} callback\n */\n setItem (key, item, callback) {\n let itemStr = item.toString();\n if (itemStr === '[object Object]') {\n itemStr = JSON.stringify(item)\n }\n this._storage.setItem(this._prefix + key, itemStr);\n callback(item);\n }\n}\n","import { unique } from './string';\n\nimport XHR from './storage/xhr';\nimport GlobalStorage from './storage/global';\nimport LocalStorage from './storage/localstorage';\n\n/**\n * @const\n * @enum {Number}\n */\nexport const EngineType = {\n // XHR: 1, // we don't have it included\n GLOBALSTORAGE: 2,\n LOCALSTORAGE: 3\n};\n\n/**\n * Persistent storage, depends on engine choice: localStorage/ajax\n * @param {String} name\n */\nexport default class Storage {\n\n constructor(name, engineType) {\n\n if (typeof name !== 'string') {\n engineType = name;\n name = unique();\n }\n\n /**\n * @type {String}\n */\n this._name = name;\n\n /**\n * @type {Storage.Engine}\n */\n this._engine = Storage.createEngine(engineType,\n this._name, Array.prototype.slice.call(arguments, 2));\n }\n\n /**\n * Engine factory\n * @param {Number} type\n * @param {String} prefix\n * @return {Storage.Engine}\n */\n static createEngine (type, prefix, args) {\n if (type === EngineType.GLOBALSTORAGE) {\n return new GlobalStorage(prefix);\n }\n if (type === EngineType.LOCALSTORAGE) {\n return new LocalStorage(prefix);\n }\n }\n\n /**\n * @param {String} key\n * @param {*} item\n * @param {Function} callback\n */\n setItem (key, item, callback) {\n this._engine.setItem(key, item, callback);\n return this;\n }\n\n /**\n * @param {String} key\n * @param {Function} callback\n */\n getItem (key, callback) {\n this._engine.getItem(key, callback);\n return this;\n }\n\n /**\n * @param {Function} callback\n */\n getAllItems (callback) {\n this._engine.getAllItems(callback);\n }\n\n /**\n * @param {String} key\n * @param {Function} callback\n */\n removeItem (key, callback) {\n this._engine.removeItem(key, callback);\n }\n}\n\n","import L from 'leaflet';\nimport { unique, substitute } from './string';\n\nconst modes = {\n CREATE: 1,\n UPDATE: 2,\n SHOW: 3,\n OPTIONS: 4\n};\n\n/**\n * New bookmark form popup\n *\n * @class FormPopup\n * @extends {L.Popup}\n */\nexport default L.Popup.extend( /** @lends FormPopup.prototype */ {\n\n statics: { modes },\n\n /**\n * @type {Object}\n */\n options: {\n mode: modes.CREATE,\n className: 'leaflet-bookmarks-form-popup',\n templateOptions: {\n formClass: 'leaflet-bookmarks-form',\n inputClass: 'leaflet-bookmarks-form-input',\n inputErrorClass: 'has-error',\n idInputClass: 'leaflet-bookmarks-form-id',\n coordsClass: 'leaflet-bookmarks-form-coords',\n submitClass: 'leaflet-bookmarks-form-submit',\n inputPlaceholder: 'Bookmark name',\n removeClass: 'leaflet-bookmarks-form-remove',\n editClass: 'leaflet-bookmarks-form-edit',\n cancelClass: 'leaflet-bookmarks-form-cancel',\n editableClass: 'editable',\n removableClass: 'removable',\n menuItemClass: 'nav-item',\n editMenuText: 'Edit',\n removeMenuText: 'Remove',\n cancelMenuText: 'Cancel',\n submitTextCreate: '+',\n submitTextEdit: ''\n },\n generateNames: false,\n minWidth: 160,\n generateNamesPrefix: 'Bookmark ',\n template: '
',\n menuTemplate: '{{ latlng }}, {{ zoom }}