[
    {
        "created": "20180908045351232",
        "text": "<pre>{{!!filter}}</pre>",
        "title": "get-geo-location.bundle",
        "tags": "$:/tags/Filter",
        "description": "Bundle of widget and demo tiddler for geo-location button",
        "filter": "[[get-geo-location.bundle]] [[Get GeoLocation]] [[$:/ext/modules/widgets/geolocation-widget.js]]",
        "modified": "20180908045625539",
        "wiki-owner": "PSaTCore"
    },
    {
        "created": "20180908041916840",
        "text": "<$geoloc target=\"Get GeoLocation\" />",
        "title": "Get GeoLocation",
        "tags": "",
        "modified": "20180908045312132",
        "points": "",
        "source": "https://sycom.github.io/TiddlyWiki-Plugins/",
        "info": "Requires reload on Install",
        "wiki-owner": "PSaTCore"
    },
    {
        "text": "/*\\\ntitle: $:/ext/modules/wigets/geolocation-widget.js\ntype: application/javascript\nmodule-type: widget\n\nGeolocation widget\n\n\\*/\n(function () {\n    /*jslint node: true, browser: true */\n    /*global $tw: false */\n    \"use strict\";\n    var Widget = require(\"$:/core/modules/widgets/widget.js\").widget;\n    var GeolocationWidget = function (parseTreeNode, options) {\n        this.initialise(parseTreeNode, options);\n    };\n\n\n\n    /* Inherit from the base widget class */\n    GeolocationWidget.prototype = new Widget();\n\n    /* Compute the internal state of the widget  */\n    GeolocationWidget.prototype.execute = function () {\n        // Get attributes\n        this.target = this.getAttribute(\"target\") || this.getVariable(\"currentTiddler\");\n        this.icon = this.getAttribute(\"icon\") || \"$:/core/images/globe\";\n        this.text = this.getAttribute(\"text\") || undefined;\n        this.accuracy = this.getAttribute(\"accuracy\");\n        this.type = this.getAttribute(\"type\") || \"point\";\n        // Make child widgets\n        this.makeChildWidgets();\n    };\n\n    /* Render this widget into the DOM */\n    GeolocationWidget.prototype.render = function (parent, nextSibling) {\n        var self = this;\n        // Remember parent\n        this.parentDomNode = parent;\n        // Compute attributes and execute state\n        this.computeAttributes();\n        this.execute();\n        // Create element\n        var tag = \"button\";\n        if (this.buttonTag && $tw.config.htmlUnsafeElements.indexOf(this.buttonTag) === -1) {\n            tag = this.buttonTag;\n        }\n        var domNode = this.document.createElement(tag);\n        // Add a click event handler\n        domNode.addEventListener(\"click\", function (event) {\n            if (navigator.geolocation) {\n                navigator.geolocation.getCurrentPosition(\n                    // success callback\n                    function (position) {\n                        /* to replace by field populating (point(s) polyline(s) or polygon(s)) */\n                        /* default : if tiddler has point field, will create a points field to store new data;\n        if tiddler has points field, will add a new point to the tiddler field;\t*/\n                        var target = self.target;\n                        var accuracy = self.accuracy;\n                        var type = self.type;\n                        console.log(\"Lat: \" + position.coords.latitude + \" - Long: \" + position.coords.longitude);\n                        var newPoint = position.coords.latitude + \",\" + position.coords.longitude;\n                        /* check if tiddler has a geofield */\n                        var track = \"\";\n                        if (!$tw.wiki.getTiddler(target)) $tw.wiki.setText(target, \"text\", null, \"\", null);\n                        var flds = $tw.wiki.getTiddler(target).fields\n                        if (flds.points) {\n                            track = flds.points;\n                            $tw.wiki.setText(target, \"points\", null, track + \" \" + newPoint, null);\n                            infoLocation(\"new point \" + newPoint + \" added to \" + target);\n\n                        } else {\n                            if (flds.point && flds.point !== null) {\n                                track = flds.point;\n                                $tw.wiki.setText(target, \"points\", null, track + \" \" + newPoint, null);\n                                $tw.wiki.setText(target, \"point\", null, null, null);\n                                infoLocation(\"new point \" + newPoint + \" added to \" + target);\n                            } else {\n                                $tw.wiki.setText(target, \"point\", null, newPoint, null);\n                                infoLocation(\"new point \" + newPoint + \" added to \" + target);\n                            }\n                        }\n                    },\n                    // error callback\n                    function (error) {\n                        noLocation(error.message + \". You may not are connected via httpS://\")\n                    }\n                );\n            } else {\n                noLocation(\"position disabled or not supported by your browser\");\n            }\n        }, false);\n        /* dress up button */\n        var buttonContent;\n        // if text parameter, will use it for the button\n        if (self.text) {\n            buttonContent = self.text;\n        } else {\n            // if not, looking for an icon\n            /* !todo: ?question: should the icon depend on \"type\" parameter? */\n            buttonContent = $tw.wiki.getTiddler(self.icon).fields.text;\n        }\n        domNode.innerHTML = buttonContent;\n        // Insert element\n        parent.insertBefore(domNode, nextSibling);\n        this.renderChildren(domNode, null);\n        this.domNodes.push(domNode);\n    };\n\n    function noLocation(message) {\n        /* !todo: ?question: replace by \"modal\" alert? */\n        // create or update a temporary message tiddler \n        $tw.wiki.setText(\"$:/temp/noLocationMessage\", \"text\", null, \"geolocation access denied: \" + message, null);\n        // displays it in modal\n        $tw.modal.display(\"$:/temp/noLocationMessage\");\n    }\n\n    function infoLocation(message) {\n        // create or update a temporary message tiddler \n        $tw.wiki.setText(\"$:/temp/viewLocationMessage\", \"text\", null, message, null);\n        // displays it in modal\n        $tw.notifier.display(\"$:/temp/viewLocationMessage\");\n    }\n    /*\n    We don't allow actions to propagate because we trigger actions ourselves\n    */\n    GeolocationWidget.prototype.allowActionPropagation = function () {\n        return false;\n    };\n\n    exports.geoloc = GeolocationWidget;\n\n})();",
        "type": "application/javascript",
        "title": "$:/ext/modules/widgets/geolocation-widget.js",
        "tags": "",
        "module-type": "widget"
    }
]