JSFiddle - React, Tailwind, and code Playground

by Derek Anderson

JavaScript

enyo.kind({
    name: 'randomEats',
    components: [{
        name: 'message',
        content: 'Looking for Lunch'
    }, {
        tag: 'br'
    }, {
        name: 'name'
    }, {
        name: 'city'
    }],
    create: function () {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(enyo.bind(this,
            this.handlePosition), enyo.bind(this, this.handleNoLocation));
        } else {
            this.handleNoLocation();
        }
        this.inherited(arguments);
    },
    handlePosition: function (position) {
        var x = new enyo.Ajax({
            url: "http://query.yahooapis.com/v1/public/yql?format=json"
        });

        var q = [
            'select * from geo.placefinder where text="',
        position.coords.latitude,
            ',',
        position.coords.longitude,
            '" and gflags="R"'];

        // send parameters the remote service using the 'go()' method
        x.go({
            q: q.join(''),
        });

        // attach responders to the transaction object
        x.response(this, function (inSender, inResponse) {
            var location = inResponse.query.results.Result;
            this._uzip = location.uzip;
            this.getLocal(location.uzip);
        });
    },
    handleNoLocation: function () {
        var zip = window.prompt("Enter Zip", "95136");
        this.getLocal(zip);
    },
    getLocal: function (zip) {

        var x = new enyo.Ajax({
            url: "http://query.yahooapis.com/v1/public/yql?format=json"
        });

        var q = [
            "select * from local.search(0,100) where zip='" + zip + "' and query='lunch'"];

        // send parameters the remote service using the 'go()' method
        x.go({
            q: q.join(''),
        });

        // attach responders to the transaction object
        x.response(this, function (inSender, inResponse) {
            var randomnumber = Math.floor(Math.random() * inResponse.query.count);
         ...