Your IP : 216.73.216.240


Current Path : /home/juvelize/www/modules/mod_gmap_embed/fields/
Upload File :
Current File : /home/juvelize/www/modules/mod_gmap_embed/fields/lgxgeocomplete.php

<?php
    /* .............................................................................
    * Author:--------------- LogicHunt Team
    * AuthorEmail:-----------logichunt.info@gmail.com
    * Technical Support:---- http://logichunt.com/
    * Websites:------------- http://logichunt.com/
    * Copyright:------------ Copyright (C) 2015 logichunt.com. All Rights Reserved.
    * License:-------------- http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
    * ..............................................................................
    * File:-  lgxgeocomplete.php - Module - Google Map Embed
    ................................................................................ */


    // Check to ensure this file is included in Joomla!
    defined ('_JEXEC') or die('Restricted access');


    class JFormFieldLgxgeocomplete extends JFormFieldText {

        protected function getInput () {
            $document     = JFactory::getDocument ();
            $hint         = $this->translateHint ? JText::_ ($this->hint) : $this->hint;
            $size         = !empty($this->size) ? ' size="' . $this->size . '"' : '';
            $maxLength    = !empty($this->maxLength) ? ' maxlength="' . $this->maxLength . '"' : '';
            $class        = !empty($this->class) ? ' class="' . $this->class . '"' : '';
            $readonly     = $this->readonly ? ' readonly' : '';
            $disabled     = $this->disabled ? ' disabled' : '';
            $required     = $this->required ? ' required aria-required="true"' : '';
            $hint         = $hint ? ' placeholder="' . $hint . '"' : '';
            $autocomplete = !$this->autocomplete ? ' autocomplete="off"' : ' autocomplete="' . $this->autocomplete . '"';
            $autocomplete = $autocomplete == ' autocomplete="on"' ? '' : $autocomplete;
            $autofocus    = $this->autofocus ? ' autofocus' : '';
            $spellcheck   = $this->spellcheck ? '' : ' spellcheck="false"';
            $pattern      = !empty($this->pattern) ? ' pattern="' . $this->pattern . '"' : '';
            $inputmode    = !empty($this->inputmode) ? ' inputmode="' . $this->inputmode . '"' : '';
            $dirname      = !empty($this->dirname) ? ' dirname="' . $this->dirname . '"' : '';

            // Initialize JavaScript field attributes.
            $onchange = !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : '';

            // Including fallback code for HTML5 non supported browsers.
            JHtml::_ ('jquery.framework');
            JHtml::_ ('script', 'system/html5fallback.js', false, true);

            $app       = JFactory::getApplication ();
            $module_id = (int)$app->input->getInt ('id', 0);


            if ($module_id > 0) {
                $mod_row = JTable::getInstance ('Module', 'JTable');
                $mod_row->load ($module_id);
                $mod_params = new JRegistry($mod_row->params);
            }


            $apikey                     = $mod_params['lgxgmap_api_key'];
            $lat                       = ($mod_params['lgxgmap_latitude']) ? $mod_params['lgxgmap_latitude'] : 0;
            $long                      = ($mod_params['lgxgmap_longitude']) ? $mod_params['lgxgmap_longitude'] : 0;
            $lgxgmap_info_show         = (int)$mod_params['lgxgmap_info_show'];
            $lgxgmap_info_title_show   = (int)$mod_params['lgxgmap_info_title_show'];
            $lgxgmap_info_title        = (!$lgxgmap_info_title_show) ? $mod_params['lgxgmap_info_title'] : '';
            $lgxgmap_info_content_show = (int)$mod_params['lgxgmap_info_content_show'];
            $lgxgmap_info_content      = (!$lgxgmap_info_content_show) ? $mod_params['lgxgmap_info_content'] : '';
            $showinfowindow            = "false";
            $infoWindow                = '';
            if ($lgxgmap_info_show):
                $showinfowindow = "true";

                $infoWindow
                    = ' infoWindow: [
                {
                title: " ' . $lgxgmap_info_title . '",
                content: "' . $lgxgmap_info_content . '"

                }
                ]';
            endif;

            //$apikey = "AIzaSyDwOcvCdm9efjKIXq6PSFrRZ5Cl2FIH2j4";
            $document->addScript ('http://maps.googleapis.com/maps/api/js?key='.$apikey.'&amp;libraries=places');

            //$document->addScript ('https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap');

            $document->addScript (JUri::root () . 'modules/mod_gmap_embed/assets/js/jquery.geocomplete.js?v=1');
            /*$document->addScript (JUri::root () . 'modules/mod_gmap_embed/assets/js/lgxgmap.js');*/
            $document->addScriptDeclaration ('jQuery(document).ready(function ($) {

                                            $(function () {

                                                var options = {
                                                    map: "#lgx-gmap-canvas-admin'.$module_id.'",
                                                    details: "form ",
                                                    location: [' . $lat . ', ' . $long . '],
                                                    markerOptions: {
                                                        draggable: true
                                                    },
                                                    center: true,
                                                    zoom: 8,
                                                    mapType: "satellite", //google.maps.MapTypeId.ROADMAP
                                                    icon: "",
                                                    showinfowindow: ' . $showinfowindow . ',
                                                    ' . $infoWindow . '

                                                };
                                                $("#jform_params_lgxgmap_location").geocomplete(options);

                                            });
                                            $(function () {

                                                $("#jform_params_lgxgmap_location").geocomplete()
                                                .bind("geocode:result", function (event, result) {
                                                // console.log (result);
                                                $("#jform_params_lgxgmap_latitude").val(result.geometry.location.lat());
                                                $("#jform_params_lgxgmap_longitude").val(result.geometry.location.lng());
                                                // $.log("Result: " + result.formatted_address);
                                                })
                                                .bind("geocode:dragged", function (event, latLng) {
                                                //console.log (latLng);
                                                $("#jform_params_lgxgmap_latitude").val(latLng.lat());
                                                $("#jform_params_lgxgmap_longitude").val(latLng.lng());
                                                // $.log("Result: " + result.formatted_address);
                                                })
                                                .bind("geocode:error", function (event, status) {
                                                // $.log("ERROR: " + status);
                                                })
                                                .bind("geocode:multiple", function (event, results) {
                                                // $.log("Multiple: " + results.length + " results found");
                                                });


                                            });

                                        });');

            $datalist = '';
            $list     = '';

                       $options = (array)$this->getSuggestions ();

            if ($options) {
                $datalist = '<datalist id="' . $this->id . '_datalist">';

                foreach ($options as $option) {
                    if (!$option->value) {
                        continue;
                    }

                    $datalist .= '<option value="' . $option->value . '">' . $option->text . '</option>';
                }

                $datalist .= '</datalist>';
                $list = ' list="' . $this->id . '_datalist"';
            }

            $html[] = '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . $dirname . ' value="' . htmlspecialchars ($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $readonly . $list . $hint . $onchange . $maxLength . $required . $autocomplete . $autofocus . $spellcheck . $inputmode . $pattern . ' />';
            $html[] = $datalist;


            //extra contents
            $html[] = '<div class="clearfix"></div>';
            $html[] = '<div id="lgx-gmap-canvas-admin'.$module_id.'" class="lgx-gmap-canvas-admin form-field" style="max-width: 500px; height: 300px;"></div>';

            return implode ($html);
        }

        /**
         */
        protected function getInput2 () {
            JHtml::_ ('jquery.framework');

            // Added By V
            $app       = JFactory::getApplication ();
            $module_id = (int)$app->input->getInt ('id', 0);


            $document = JFactory::getDocument ();
            $document->addScript ('http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places');
            $document->addScript (JUri::root () . 'modules/mod_gmap_embed/lgxgmap/js/jquery.geocomplete.js?v=1');
            $document->addStyleDeclaration ('
                .lgx-gmap-canvas-admin {
                    display: block;
                    border: 1px solid #616366;
                    margin-top: 20px;
                    background-color: rgba(216, 208, 208, 0.27);
                }
            ');
            $output = '<input type="text" name="jform[params][lgx_gmap_loc]" id="jform_params_lgxgmap_locationation">';
            $output .= '<div class="clearfix"></div>';
            $output .= '<div id="lgx-gmap-canvas-admin'.$module_id.'" class="lgx-gmap-canvas lgx-gmap-canvas-admin form-field" style="max-width: 500px; height: 300px;"></div>';


            return $output;

        }

    }

?>