Monday, 18 July 2016

How to place top menu to left side bar in magento 2


Add below code in <body> tag in Magento_Theme/view/frontend/layout/default.xml

<referenceContainer name="sidebar.main">
<block class="Magento\Framework\View\Element\Template" name="store.menu" group="navigation-sections" template="Magento_Theme::html/container.phtml">
<arguments>
<argument name="title" translate="true" xsi:type="string">Menu</argument>
</arguments>
</block>
</referenceContainer>

magento 2 call newsletter in sidebar

add below code in <body> tag in module-newsletter/view/frontend/layout/default.xml

<referenceContainer name="sidebar.additional">
            <block class="Magento\Newsletter\Block\Subscribe" name="form.subscribe" as="subscribe" after="wishlist_sidebar" template="subscribe.phtml"/>

        </referenceContainer>

Note :- You can use sidebar.main instead of sidebar.additional  for show in top of sidebar.

Wednesday, 22 June 2016

Google Maps Calculate Distance,Travel Duration, draw (plot) Route and display Directions between two locations

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places"></script>
<script type="text/javascript">
        var source, destination;
        var directionsDisplay;
        var directionsService = new google.maps.DirectionsService();
        google.maps.event.addDomListener(window, 'load', function () {
            new google.maps.places.SearchBox(document.getElementById('txtSource'));
            new google.maps.places.SearchBox(document.getElementById('txtDestination'));
            directionsDisplay = new google.maps.DirectionsRenderer({ 'draggable': true });
        });

        function GetRoute() {
            var mumbai = new google.maps.LatLng(18.9750, 72.8258);
            var mapOptions = {
                zoom: 7,
                center: mumbai
            };
            map = new google.maps.Map(document.getElementById('dvMap'), mapOptions);
            directionsDisplay.setMap(map);
            directionsDisplay.setPanel(document.getElementById('dvPanel'));

            //*********DIRECTIONS AND ROUTE**********************//
            source = document.getElementById("txtSource").value;
            destination = document.getElementById("txtDestination").value;

            var request = {
                origin: source,
                destination: destination,
                travelMode: google.maps.TravelMode.DRIVING
            };
            directionsService.route(request, function (response, status) {
                if (status == google.maps.DirectionsStatus.OK) {
                    directionsDisplay.setDirections(response);
                }
            });

            //*********DISTANCE AND DURATION**********************//
            var service = new google.maps.DistanceMatrixService();
            service.getDistanceMatrix({
                origins: [source],
                destinations: [destination],
                travelMode: google.maps.TravelMode.DRIVING,
                unitSystem: google.maps.UnitSystem.METRIC,
                avoidHighways: false,
                avoidTolls: false
            }, function (response, status) {
                if (status == google.maps.DistanceMatrixStatus.OK && response.rows[0].elements[0].status != "ZERO_RESULTS") {
                    var distance = response.rows[0].elements[0].distance.text;
                    var duration = response.rows[0].elements[0].duration.text;
                    var dvDistance = document.getElementById("dvDistance");
                    dvDistance.innerHTML = "";
                    dvDistance.innerHTML += "Distance: " + distance + "<br />";
                    dvDistance.innerHTML += "Duration:" + duration;

                } else {
                    alert("Unable to find the distance via road.");
                }
            });
        }
    </script>
<body onLoad="GetRoute();">
<table border="0" cellpadding="0" cellspacing="3">
  <tbody>
    <tr>
      <td colspan="2"> Source:
        <input type="text" id="txtSource" value="Behror, Rajasthan, India" style="width: 250px" placeholder="Enter a query" autocomplete="off">
        &nbsp;&nbsp; Destination:
        <input type="text" id="txtDestination" value="Jaipur, Rajasthan, India" style="width: 250px" placeholder="Enter a query" autocomplete="off">
        <br>
        <br>
        <input type="button" value="Get Route" onclick="GetRoute()">
        <hr></td>
    </tr>
    <tr>
      <td colspan="2"><div id="dvDistance"> </div></td>
    </tr>
    <tr>
      <td><div id="dvMap" style="width: 500px; height: 500px"> </div></td>
      <td><div id="dvPanel" style="width: 500px; height: 500px;overflow-y:auto"> </div></td>
    </tr>
  </tbody>
</table>
</body>

Monday, 30 May 2016

Saturday, 21 May 2016

detect browser language and redirect using javascript

When first time user open the site and detect browser language and redirect website according to languge using javascript.

 <script>
function GetCookie(name) {
        var arg=name+"=";
        var alen=arg.length;
        var clen=document.cookie.length;
        var i=0;

        while (i<clen) {
            var j=i+alen;
                if (document.cookie.substring(i,j)==arg)
                    return "here";
                i=document.cookie.indexOf(" ",i)+1;
                if (i==0)
                    break;
        }

        return null;
    }
$(function getck() {
    var visit=GetCookie("COOKIE1");
    if (visit==null){
        var userLang = navigator.language || navigator.userLanguage;
if(userLang=="fr"){
window.location='http://french.domain.com/';
}else if(userLang=="en-US"){
window.location='http://english.domain.com/';
}else{
window.location='http://domain.com/';
}
    }
    var expire=new Date();
    expire.setTime(expire.getTime()+(1*24*60*60*1000));
    document.cookie="COOKIE1=here; expires="+expire;
});
</script>

Saturday, 7 May 2016

Detect when an HTML5 video finishes

<video id="myVideo" width="1349" height="758" preload="metadata" autoplay="1" controls>
<source src="http://id-cardz.com/wp-content/uploads/2016/05/upwork-damjikamran.mp4?_=1" type="video/mp4"></source>
</video>
<img id="myimg" onClick="playvid();" style="display:none;" src="image/path.jpg">
<a href="#" onClick="document.getElementById('myVideo').play();">Play video</a>
<script type='text/javascript'>
    document.getElementById('myVideo').addEventListener('ended',myHandler,false);
    function myHandler(e) { //on video stop ------------
        document.getElementById('myVideo').style.display = 'none';
        document.getElementById('myimg').style.display = 'block';
    }
    function playvid() { //on click video play ------------
    document.getElementById('myimg').style.display = 'none';
    document.getElementById('myVideo').style.display = 'block';
    document.getElementById('myVideo').play();
    }
</script>

Google map show a map using address on website

 <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>
<script>
 var geocoder;
  var map;

  function codeAddress() {
   geocoder = new google.maps.Geocoder();
  
    var latlng = new google.maps.LatLng(33.449204, -112.074387);
   
    var mapOptions = {
     
      center: latlng,
          zoom: 12,
    mapTypeId: google.maps.MapTypeId.TERRAIN
        }
    map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
   
    var address = 'Indira Gandhi International Airport, New Delhi, Delhi, India';
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {

     var lat=results[0].geometry.location.lat();
   
     var lng=results[0].geometry.location.lng();
   
     map.setCenter(new google.maps.LatLng(lat, lng));
   
     var marker = new google.maps.Marker({
       
            position: results[0].geometry.location,
            map: map,
            animation: google.maps.Animation.DROP,
           
        });
       
              var infowindow = new google.maps.InfoWindow();
            infowindow.setContent('<div class="mapinfo"> Indira Gandhi International Airport, New Delhi, Delhi, India</div>');
            infowindow.open(map, marker);     
           
            }

    });
   
   
    }


           
</script>
<body onload="codeAddress();">
 <div id="form2left">
        <div id="map-canvas" style="width: 100%; height: 100%;"></div>
      </div>
      </body>