Friday, December 16, 2011

Plugin jQuery Klik-Kanan

jQuery Right-Click
// jQuery Right-Click Plugin
// Version 1.01
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// 20 December 2008
// License: This plugin is dual-licensed under the GNU General Public License and the MIT License
// and is copyright 2008 A Beautiful Site, LLC. 

if(jQuery) (function(){
 
 $.extend($.fn, {
  
  rightClick: function(handler) {
   $(this).each( function() {
    $(this).mousedown( function(e) {
     var evt = e;
     $(this).mouseup( function() {
      $(this).unbind('mouseup');
      if( evt.button == 2 ) {
       handler.call( $(this), evt );
       return false;
      } else {
       return true;
      }
     });
    });
    $(this)[0].oncontextmenu = function() {
     return false;
    }
   });
   return $(this);
  },  
  
  rightMouseDown: function(handler) {
   $(this).each( function() {
    $(this).mousedown( function(e) {
     if( e.button == 2 ) {
      handler.call( $(this), e );
      return false;
     } else {
      return true;
     }
    });
    $(this)[0].oncontextmenu = function() {
     return false;
    }
   });
   return $(this);
  },
  
  rightMouseUp: function(handler) {
   $(this).each( function() {
    $(this).mouseup( function(e) {
     if( e.button == 2 ) {
      handler.call( $(this), e );
      return false;
     } else {
      return true;
     }
    });
    $(this)[0].oncontextmenu = function() {
     return false;
    }
   });
   return $(this);
  },
  
  noContext: function() {
   $(this).each( function() {
    $(this)[0].oncontextmenu = function() {
     return false;
    }
   });
   return $(this);
  }
  
 });
 
})(jQuery);

Dasar Penggunaan

Aksi Klik Kanan

$('#selektor').rightClick(function(e) {
     ...
});

MouseDown dengan Klik Kanan

$('#selektor').rightMouseDown(function(e) {
     ...
});

MouseUp dengan Klik Kanan

$('#selektor').rightMouseUp(function(e) {
     ...
});

Menonaktifkan Klik Kanan

$('#selektor').noContext();

Sumber: http://abeautifulsite.net

Labels: ,

3 Comments:

At Saturday, December 17, 2011 at 5:08:00 AM GMT+7, Blogger Sinto said...

Ngomeng2 Gimana cara nerapinnya nih,

 
At Saturday, December 17, 2011 at 8:50:00 AM GMT+7, Blogger Taufik Nurrohman said...

@Zh!nTho: Yang namanya plugin ya cuma tambahan. Tinggal taruh saja di antara script JQuery. Nanti plugin itu bisa bertugas sendiri saat kamu menuliskan dasar penggunaannya.

 
At Saturday, December 17, 2011 at 12:37:00 PM GMT+7, Blogger Sinto said...

Namax juga orang gak ngerti gan pasti bingung mau naruh di mana

 

Post a Comment

<< Home