Facebook

Wednesday, November 18, 2015

Maps - enable scroll after first click on map only

Complete script for google map that will enable zoom on clicking in the map area only



<script type='text javascript' src="https://maps.googleapis.com/maps/api/js?key=&sensor=false&extension=.js">
<script type='text javascript'="">
    jQuery(document).ready(function(){
        var latitude = $('#map_latitude').val();
        var longitude = $('#map_longitude').val();
        // When the window has finished loading create our google map below
        google.maps.event.addDomListener(window, 'load', init);
        function init() {
            // Basic options for a simple Google Map
            // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
            var mapOptions = {
                // How zoomed in you want the map to start at (always required)
                zoom: 14,
                // The latitude and longitude to center the map (always required)
                center: new google.maps.LatLng(latitude,longitude),
                //Disable scroll wheel by default,
                scrollwheel: false,
                // How you would like to style the map.
                // This is where you would paste any style found on Snazzy Maps.
            // Get the HTML DOM element that will contain your map
            // We are using a div with id='map' seen below in the 
            var mapElement = document.getElementById('map');
            // Create the Google Map using out element and options defined above
            var map = new google.maps.Map(mapElement, mapOptions);
            var marker = new google.maps.Marker({

                map: map,

                position: map.getCenter(),

                icon: 'images/google-map-cion.png'

            });
            // Listen to click event on map and enable zoom
            map.addListener('click', function() {
                map.set('scrollwheel', true);
            });


        }
    })
    

</script>

DEMO

Wednesday, November 11, 2015

Simple Ajax Pagination Script on Scroll Down


Credit: Jaspreet Singh

<script type="text/javascript">
    jQuery(document).ready(function($) {
    //Set current page to 1     var count = 1;
    $(window).scroll(function(){
          if  ($(window).scrollTop() == $(document).height() - $(window).height()){
             //Load artices of current page              loadArticle(count);
             //Increment current page after loading              count++;
          }
    });

    function loadArticle(pageNumber){
          //Show loader           $(".sk-circle").removeClass("hideme");
          //Get search string           var search_string = $("#search_name").val();
          $.ajax({
              url: "ajaxsearch.php",
              type:"POST",
              data: "search_string="+search_string+"&page_no="+ pageNumber,
              success: function(html){
                  //Hide loader                   $(".sk-circle").addClass("hideme");
                   if(html == "error"){

                    } else {
                        $("#search_list").append(html);
                    }
                      // This will be the div where our content will be loaded
              }
          });
      return false;
    }

    });

</script>

Server side code
$search_string = $_POST['search_string'];
$perpage = 10;
$limit = $pages*$perpage;
$search = 'SELECT * FROM `table_name` WHERE `description` like '%$search_string%' or `PartNo` like '%$search_string%' and status='1' order by id ASC limit $limit, $perpage';

Thursday, November 5, 2015

PHP Tips and Tricks - Handy


1. ini_set('memory_limit', '-1');
Usage: To temporarily set memory limit to unlimited

2. ini_set('memory_limit', '512M');
Usage: How to temporarily set memory limit to 512MB

3. set_time_limit(0);

4. ini_set('max_execution_time', 0);
Usage: How to temporarily set max execution time to infinite

5. error_reporting(E_ALL);
Usage: Report all PHP errors

6. error_reporting(0);
Usage: Turn off all error reporting

7. ini_set("display_errors", 1);
Usage: Run-time configuration

8.
function getClientIp()
{
    $ip = '';
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }

    return $ip;
}
Usage: Get user ip

/*
 *9.Generate accented seo friendly url
 */

function accented_seo_url($str) {
    mb_internal_encoding('UTF-8');
    $str = utf8_encode($str);

    $new_string = preg_replace('~[^\\pL\d]+~u', "-", ltrim(rtrim(($str))));

    return mb_strtolower($new_string);
}
Usage: Generate accented seo friendly url

10. header('Content-Type: text/html; charset=utf-8');
Usage: Set utf8 in header

11.
/*
* Get 2nd monday of the month
*/

//First monday of the month
$dt = new DateTime('first Monday of jan 2017');

//Second monday of the month
$interval = new DateInterval('P1W');
$next_week = $dt->add($interval);
echo $next_week->format('Y-m-d');
Usage: Get 2nd monday of the month. Example https://eval.in/716901
12.
/*
* Get 3rd tuesday of the month
*/

//First tuesday of the month
$dt = new DateTime('first Tuesday of jan 2017');

//Third Tuesday of the month
$interval = new DateInterval('P2W');
$next_week = $dt->add($interval);
echo $next_week->format('Y-m-d');
Usage: Get 3rd Tuesday of the month. Example https://eval.in/716901