Wednesday, 31 May 2017

jQuery Post With and Without Json Response


1.    jQuery Post Method Without json Response


var post_data = 'operation=add&name=Rahul&email=rahul@gmail.com';
jQuery.post('/admin/ajax/do.php', post_data, function(response){
    if(response.msg=="success"){
        alert("Insert Successfully");
    }else{
        alert("Error Occured");
    }
});



2.    jQuery Post Method With json Response


var post_data = 'operation=add&name=Rahul&email=rahul@gmail.com';
jQuery.post('/admin/ajax/do.php', post_data, function(response){
    if(response.msg=="success"){
        alert("Insert Successfully");
    }else{
        alert("Error Occured");
    }
},'json');

Wednesday, 24 May 2017

How to hide Carousel Left and Right arrow on First and last slide



Simply just add the following script



    Script

    $('#carousel-example-generic').on('slid', '', function() {
        var $this = $(this);
        $this.children('.carousel-control').show();

        if($('.carousel-inner .item:first').hasClass('active')) {
            $this.children('.left').addClass("hideElement");
            $this.children('.left.carousel-control').hide();
        } else{
            $this.children('.left').removeClass("hideElement");
            }
       
         if($('.carousel-inner .item:last').hasClass('active')) {
            $this.children('.right.carousel-control').hide();
            $this.children('.right').addClass("hideElement");
        }else{
            $this.children('.right').removeClass("hideElement");
        }
    });

   
    Add "hideElement" class on left parent element
   
    Html
       
      <div id="carousel-example-generic" class="carousel slide" data-ride="carousel" data-interval="false">
         <!-- Indicators -->
         <ol class="carousel-indicators">
            <li data-target="#carousel-example-generic" data-slide-to="0" class="active">1</li>
            <li data-target="#carousel-example-generic" data-slide-to="1">2</li>
            <li data-target="#carousel-example-generic" data-slide-to="2">3</li>
         </ol>
         <!-- Wrapper for slides -->
       
         <div class="carousel-inner" role="listbox">
            <div class="item active">
               <div class="slide-content" id="slide-1">
                  <p class="slide-content-left-1">Someone liked your profile. Now it's your turn.</p>
                  <p class="right-main">Review these profiles and check which you like.</p>
                  <p class="slide-content-left-2">When you both like each other, you'll get a match notification.</p>
               </div>
            </div>
            <div class="item">
               <div class="slide-content" id="slide-2">
                  <p class="slide-2-contetnt-1">To like the user, push here on the check mark.</p>
                  <p class="slide-2-contetnt-2">Or skip the profile by pushing the X mark, to see the next profile.</p>
               </div>
            </div>
            <div class="item">
               <div class="slide-content" id="slide-3">
                  <p>It's your turn now. Like as many as you want.</p>
               </div>
            </div>
         </div>
       
         <!-- Controls -->
         <a class="left carousel-control hideElement" href="#carousel-example-generic" role="button" data-slide="prev">
         <span class="sr-only">Previous</span>
         </a>
         <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
         <span class="sr-only">Next</span>
         </a>
      </div>
   
   
    Css
   
    .hideElement {display:none !important;}
             

Tuesday, 23 May 2017

How to show a div content in popup in facnybox


We assume that you already have added the fancybox js and css in your project



<html>

<div id="add_photo_notify_wrap">
    <div class="fancy_add_photo_notify_wrap">
        <div class="fancycontent">
            <p>This is my content sectioin.</p>
        </div>
        <div class="fancybtn">
            <a href="javascript:void(0)" class="btn add_photo_now">Add my photo now</a>
            <a href="javascript:void(0)" class="skip-it-now" onclick="$.fancybox.close();">Keep reviewing photos. I'll add my photo later.</a>
        </div>
    </div>
</div>

</html>

<script>

jQuery.fancybox({
  content: jQuery('#add_photo_notify_wrap').html(),
  modal: true,
  beforeShow: function(){
        jQuery(".fancybox-wrap").addClass('fancy_photo_notify');
    },
});

</script>

In this div id#add_photo_notify_wrap inner content will show in pop

and line jQuery(".fancybox-wrap").addClass('fancy_photo_notify'); will add class "fancy_photo_notify" to our popup

How to close Fancybox on anchor or button click

How to close Fancybox on anchor or button click

Nothing special to achieve this just siply write the fancybox close script inline with your tag just like

<a href="javascript:void(0)" onclick="$.fancybox.close();">Close</a>

or

<button onclick="$.fancybox.close();">Close</button>

Thursday, 18 May 2017

Scroll to Specific Height Jquery




<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<div class="">
    <a href="#commment" class="paythis">Go To comments</a>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <div id="commment" style="height:300px;width:300px;background:#d7d7d7; text-align:center;">
    <h3>Comment Section</h3>
</div>



<script>


        $('html, body').animate({
            scrollTop: $(window).scrollTop() + 100
        });

Friday, 12 May 2017

How to open file and folder as administrator in Ubuntu ?


How to open file as administrator ?

To open a file as administrator you have to install GUI interface for this.

To install GUI Interface open Ubuntu Center and search for gksu


Open-as-Administrator in Ubuntu

To install Open-as-Administrator in Ubuntu open Terminal  and paste the following commands in the terminal:


sudo add-apt-repository ppa:noobslab/apps

sudo apt-get update

sudo apt-get install open-as-administrator
nautilus -q
Reboot
Ubuntu 16.04
sudo apt-get install -y nautilus-admin
Then
nautilus -q
 

How to load specific part or page

How to load specific part or page



page.html

<div id="product82">
    <span class="sku">sku-3</span>
    <span class="brand">Test Brand 1</span>
    <span class="avail">Test Content 1</span>
</div>
<div id="product83">
    <span class="sku">sku-4</span>
    <span class="brand">Test Brand 2</span>
    <span class="avail">Test Content 2</span>
</div>
<div id="product84">
    <span class="sku">sku-5</span>
    <span class="brand">Test Brand 3</span>
    <span class="avail">Test Content 3</span>
</div>


Script :

<script>
    $('.mycontainer').load('http://www.yourpageurl.com/page.html #product83 .avail');
</script>


Html :

<div class="mycontainer"></div>

This script will load external page content in our . div and result will

<div class="mycontainer">
    <span class="avail">Test Content 2</span>
</div>



Tuesday, 9 May 2017

htaccess code for drupal 7

Here is .htaccess code for drupal 7




#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|tpl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock))$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
  <IfModule !mod_authz_core.c>
    Order allow,deny
  </IfModule>
</FilesMatch>

# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Set the default handler.
DirectoryIndex index.php index.html index.htm

# Add correct encoding for SVGZ.
AddType image/svg+xml svg svgz
AddEncoding gzip svgz

# Most of the following PHP settings cannot be changed at runtime. See
# sites/default/default.settings.php and
# Drupal\Core\DrupalKernel::bootEnvironment() for settings that can be
# changed at runtime.

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
  php_value assert.active                   0
  php_flag session.auto_start               off
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_flag mbstring.encoding_translation    off
  # PHP 5.6 has deprecated $HTTP_RAW_POST_DATA and produces warnings if this is
  # not set.
  php_value always_populate_raw_post_data   -1
</IfModule>

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

# Set a fallback resource if mod_rewrite is not enabled. This allows Drupal to
# work without clean URLs. This requires Apache version >= 2.2.16. If Drupal is
# not accessed by the top level URL (i.e.: http://example.com/drupal/ instead of
# http://example.com/), the path to index.php will need to be adjusted.
<IfModule !mod_rewrite.c>
  FallbackResource /index.php
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # Set "protossl" to "s" if we were accessed via https://.  This is used later
  # if you enable "www." stripping or enforcement, in order to ensure that
  # you don't bounce between http and https.
  RewriteRule ^ - [E=protossl]
  RewriteCond %{HTTPS} on
  RewriteRule ^ - [E=protossl:s]

  # Make sure Authorization HTTP header is available to PHP
  # even when running as CGI or FastCGI.
  RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

  # Block access to "hidden" directories whose names begin with a period. This
  # includes directories used by version control systems such as Subversion or
  # Git to store control files. Files whose names begin with a period, as well
  # as the control files used by CVS, are protected by the FilesMatch directive
  # above.
  #
  # NOTE: This only works when mod_rewrite is loaded. Without mod_rewrite, it is
  # not possible to block access to entire directories from .htaccess because
  # <DirectoryMatch> is not allowed here.
  #
  # If you do not have mod_rewrite installed, you should remove these
  # directories from your webroot or otherwise protect them from being
  # downloaded.
  RewriteRule "/\.|^\.(?!well-known/)" - [F]

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/foo will be redirected to http://www.example.com/foo)
  # uncomment the following:
  # RewriteCond %{HTTP_HOST} .
  # RewriteCond %{HTTP_HOST} !^www\. [NC]
  # RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/foo will be redirected to http://example.com/foo)
  # uncomment the following:
  # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  # RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  # RewriteBase /

  # Redirect common PHP files to their new locations.
  RewriteCond %{REQUEST_URI} ^(.*)?/(install.php) [OR]
  RewriteCond %{REQUEST_URI} ^(.*)?/(rebuild.php)
  RewriteCond %{REQUEST_URI} !core
  RewriteRule ^ %1/core/%2 [L,QSA,R=301]

  # Rewrite install.php during installation to see if mod_rewrite is working
  RewriteRule ^core/install.php core/install.php?rewrite=ok [QSA,L]

  # Pass all requests not referring directly to files in the filesystem to
  # index.php.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L]

  # For security reasons, deny access to other PHP files on public sites.
  # Note: The following URI conditions are not anchored at the start (^),
  # because Drupal may be located in a subdirectory. To further improve
  # security, you can replace '!/' with '!^/'.
  # Allow access to PHP files in /core (like authorize.php or install.php):
  RewriteCond %{REQUEST_URI} !/core/[^/]*\.php$
  # Allow access to test-specific PHP files:
  RewriteCond %{REQUEST_URI} !/core/modules/system/tests/https?.php
  # Allow access to Statistics module's custom front controller.
  # Copy and adapt this rule to directly execute PHP files in contributed or
  # custom modules or to run another PHP application in the same directory.
  RewriteCond %{REQUEST_URI} !/core/modules/statistics/statistics.php$
  # Deny access to any other PHP files that do not match the rules above.
  # Specifically, disallow autoload.php from being served directly.
  RewriteRule "^(.+/.*|autoload)\.php($|/)" - [F]

  # Rules to correctly serve gzip compressed CSS and JS files.
  # Requires both mod_rewrite and mod_headers to be enabled.
  <IfModule mod_headers.c>
    # Serve gzip compressed CSS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

    # Serve gzip compressed JS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

    # Serve correct content types, and prevent mod_deflate double gzip.
    RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
    RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]

    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type.
      Header set Content-Encoding gzip
      # Force proxies to cache gzipped & non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
  </IfModule>
</IfModule>

# Various header fixes.
<IfModule mod_headers.c>
  # Disable content sniffing, since it's an attack vector.
  Header always set X-Content-Type-Options nosniff
  # Disable Proxy header, since it's an attack vector.
  RequestHeader unset Proxy
</IfModule>

Saturday, 6 May 2017

Remove file extension from url using htaccess


Remove .php or .html or .any extension using .htaccess


RewriteEngine on

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ $1.html [L]








 add your extension instead of php

Remove image if image not exists

To Remove image if image not exists or "src" is not correct



$(function(){
    $("img").on("error",function(){
        $(this).remove();
    })
})


Hide on body click


Hide div on body click or hide on anywhere click on body


jQuery(document).mouseup(function(e) {
    var $container = jQuery("id or class of container you want to hide");

    // if the target of the click isn't the container nor a descendant of the container
    if (!$container.is(e.target) && $container.has(e.target).length === 0) {
        $container.hide();
    }
});

Wednesday, 3 May 2017

Request for the Documents




Hello Sir,

I would like to inform you that I have successfully completed x.x year with Compnay family on xx-November xxxx.

Here I am writing to request you to provide me my documents listed below.

# 1    Marksheet of 10th
# 2    Marksheet of 12th
# 3    Marksheet of 8th Semester
# 4    Provisional Degree

I would be very grateful if you would provide me soon.



Thank you.

Salary increment Sample






Sample 1 :


Hello Sir,

It's been a pleasure working with you and contributing to the company for the past xx year. It has been a great learning experience and I have acquired invaluable knowledge during my time here. I would like to request a salary increment. As I have always given my best performance as XXX Developer and given my work with sincerity.

In closing, I would like you to know that I have truly enjoyed my time on the job and hope that you understand and appreciate the basis of my request. I am more than happy to sit down to discuss further the details of my request.

Thank you for your consideration.

Thanks and Regards,



-------------------------------------------------------------------------------------------------------------------------------------


Sample 2 :

Hello Sir,

Since last 1.6 year I have been part of this company have been great ones. I feel like it is here where I was given the opportunity to learn many new things and improve on the skills that I needed to become a better and more efficient worker. It's been a pleasure working with you and contributing to the company for the past 1.6 year.

It has been a great learning experience and I have acquired invaluable knowledge during my time here. I would like to request a salary increment. As I have always given my best performance as Software Developer (Php, Codeigniter, Angularjs etc) and given my work with sincerity.

I also believe that I have performed consistently and continuously at my best in the Development Department where I was assigned. I sincerely hope that you will take the time to look into and review my request. I think that it would be best if given the opportunity to sit with you to discuss my case further. I am looking forward to hearing from you about this.

Thank you very much..!!

--
Thanks & Regards


-------------------------------------------------------------------------------------------------------------------------------------


Sample 3 :

Hello Sir,

Since last 1.6 year I have been part of this company have been great ones. I feel like it is here where I was given the opportunity to learn many new things and improve on the skills that I needed to become a better and more efficient worker. It's been a pleasure working with you and contributing to the company for the past 1.6 year.

It has been a great learning experience and I have acquired invaluable knowledge during my time here. I would like to request a salary increment. As I have always given my best performance as Software Developer (Php, Codeigniter, Angularjs etc) and given my work with sincerity.

I sincerely hope that you will take the time to look into and review my request. I think that it would be best if given the opportunity to sit with you to discuss my case further. I am more than happy to sit down to discuss further the details of my request.


Thank you for your consideration.


--
Thanks & Regards

How to Redirect non-www to www



To redirect your site from non-www to www just paste the following code in you existing .htaccess file if does not have .htaccess create it on root folder and past it


RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]




How to Redirect HTTP to HTTPS





To redirect your site from http to https just paste the following code in you existing .htaccess file if does not have .htaccess create it on root folder and past it


RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]




Implode array key and value


I want to print like

'id'='1', 'name'='Ravi', 'email'='test@gmail.com'

And I have array like

$input = array(
    'id'  => 1,
    'name'  => 'Ravi',
    'email'  => 'test@gmail.com',
);


$output = implode(', ', array_map(
    function ($v, $k) { return sprintf("'%s'='%s'", $k, $v); },
    $input,
    array_keys($input)
));
 
print_r($output);         // it will result as 'id'='1', 'name'='Ravi', 'email'='test@gmail.com'
 
 
 

Monday, 1 May 2017

Make Iframe or image resizable

To make any image or div or iframe resizable follow the steps




Step 1:

    Create a parent div and give height and width to it whatever you want

Step 2:

    Place the image or iframe inside it and give height="100%" and width="100%"
  
    <div class="resizable" style="height:300px;width:300px;">
        <iframe src="http://w3schools.com/" style="height:100%;width:100%;"></iframe>
    </div>
  
Step 3:

add the following jQuery Script

<script type="text/javascript">
    $(function() {
      $(".resizable").resizable({
        helper: "ui-resizable-helper",
        //aspectRatio: 16 / 9,
      });
    });
</script>



Note : we assume that you have already included jQuery library in your Project

Get Browser name or Detect Browser Using Jquery




function BrowserDetection() {
               
    //Check if browser is IE or not
    if (navigator.userAgent.search("MSIE") >= 0) {
        return "InternetExplorer";
    }
    //Check if browser is Chrome or not
    else if (navigator.userAgent.search("Chrome") >= 0) {
        return "chrome";
    }
    //Check if browser is Firefox or not
    else if (navigator.userAgent.search("Firefox") >= 0) {
        return "fireFox";
    }
    //Check if browser is Safari or not
    else if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0) {
        return "safari";
    }
    //Check if browser is Opera or not
    else if (navigator.userAgent.search("Opera") >= 0) {
        return "opera";
    }
}
           
           
var browsername=BrowserDetection();

alert(browsername);