2012-04-25 7 views
2

私は自分の画像にDrupal 7とGalleria fullscreenテーマを使用しています。右クリックして画像を保存する必要はありません。だから、私は私のjQueryのファイルにこのコードを追加:ギャラリアの右クリックを無効にするフルスクリーンテーマ

$('img').bind('contextmenu', function(e){ 
    return false; 
}); 

この機能は、自分のサイトの画像に取り組んが、ガレリアフルスクリーン上で動作していません。これは私のギャラリアフルスクリーンjsです:

(function($) { 

Galleria.addTheme({ 
    name: 'fullscreen', 
    author: 'Galleria', 
    version: '2.0', 
    css: 'galleria.fullscreen.css', 
    defaults: { 
     transition: 'fade', 
     image_crop: true, 
     thumb_crop: 'height' 
    }, 
    init: function(options) { 

     this.addElement('thumbnails-tab'); 
     this.appendChild('thumbnails-container','thumbnails-tab'); 

     var tab = this.$('thumbnails-tab'); 
     var loader = this.$('loader'); 
     var thumbs = this.$('thumbnails-container'); 
     var list = this.$('thumbnails-list'); 
     var infotext = this.$('info-text'); 
     var info = this.$('info'); 

     var OPEN = false; 
     var POS = 0; 

     if (Galleria.IE) { 
      this.addElement('iefix'); 
      this.appendChild('container','iefix'); 
      this.setStyle(this.get('iefix'), { 
       zIndex:3, 
       position:'absolute', 
       backgroundColor: '#000', 
       opacity:.4 
      }) 
     } 

     if (options.thumbnails === false) { 
      thumbs.hide(); 
     } 

     var fixCaption = this.proxy(function(img) { 
      if (!(img || img.width)) { 
       return; 
      } 
      var w = Math.min(img.width, $(window).width()); 
      infotext.width(w-40); 
      if (Galleria.IE && this.options.show_caption) { 
       this.$('iefix').width(info.outerWidth()).height(info.outerHeight()); 
      } 
     }); 

     this.bind(Galleria.RESCALE, function() { 
      POS = this.stageHeight - tab.height()-2; 
      thumbs.css('top', OPEN ? POS - list.outerHeight() + 2 : POS); 
      var img = this.getActiveImage(); 
      if (img) { 
       fixCaption(img); 
      } 
     }); 

     this.bind(Galleria.LOADSTART, function(e) { 
      if (!e.cached) { 
       loader.show().fadeTo(100, 1); 
      } 
      $(e.thumbTarget).css('opacity',1).parent().siblings('.active').children().css('opacity',.5); 
     }); 

     this.bind(Galleria.LOADFINISH, function(e) { 
      loader.fadeOut(300); 
      this.$('info,iefix').toggle(this.hasInfo()); 
     }); 

     this.bind(Galleria.IMAGE, function(e) { 
      fixCaption(e.imageTarget); 
     }); 

     this.bind(Galleria.THUMBNAIL, function(e) { 
      $(e.thumbTarget).click(function() { 
       if (OPEN) { 
        tab.click(); 
       } 
      }); 
     }); 

     this.trigger(Galleria.RESCALE); 

     this.addIdleState(thumbs, { opacity:0 }); 
     this.addIdleState(this.get('info'), { opacity:0 }); 

     if (Galleria.IE) { 
      this.addIdleState(this.get('iefix'), { opacity:0 }); 
     } 

     this.attachKeyboard({ 
      up: function(e) { 
       if (!OPEN) { 
        tab.click(); 
       } 
       e.preventDefault(); 
      }, 
      down: function(e) { 
       if (OPEN) { 
        tab.click(); 
       } 
       e.preventDefault(); 
      } 
     }); 

     this.$('image-nav-left, image-nav-right').hover(function() { 
      //$(this).animate({opacity:1},100); 
     }, function() { 
      //$(this).animate({opacity:0}); 
     }).show(); 

     tab.click(this.proxy(function() { 
      tab.toggleClass('open', !OPEN); 
      if (!OPEN) { 
       thumbs.animate({ 
        top: POS - list.outerHeight() + 2 
       },400,'galleria'); 
      } else { 
       thumbs.animate({ 
        top: POS 
       },400,'galleria'); 
      } 
      OPEN = !OPEN; 
     })); 

     this.$('thumbnails').children().hover(function() { 
      $(this).not('.active').children().css('opacity', 1); 
     }, function() { 
      $(this).not('.active').children().fadeTo(200, .5); 
     }).children().css('opacity',.5) 

     this.enterFullscreen(); 
    } 
}); 

})(jQuery); 

ガレリアのフルスクリーンモードで右クリックを無効にする方法はありますか?

+0

のような右クリックはガレリアは「IMG」か、それとも別のブロックに包まれた画像であり、無効にしますか? Galleriaのブロックが何であれ、おそらくその要素をバインドする必要があります。開発ツールのDOMを調べて、それが何であるか調べてください。 – veeTrain

答えて

0

バインドの代わりにライブを試しましたか?あなたのセレクタに一致するimgは常にそれを持っています

$('img').live('contextmenu', function(e){ 
return false; 

});

Jquery .live()

それが役に立てば幸い!

+0

'.live()'メソッドは廃止されました。 –

+0

@ RokoC.Buljanそうです!それを指摘してくれてありがとう!ライブの代わりに.on()にする必要があります。 $(document).on( 'contextmenu'、 'img'、function(){return false;}); –

3

で試してみてください。

$('.galleria-images').on('contextmenu','img',function(e){ 
    alert('Images you are attempting to download are copyrighted material.'); 
    e.preventDefault(); 
}); 
2

この

$('body').mousedown(function(event) { 
    switch (event.which) { 
     case 3: return false; break; 
    } 
}); 
+0

+1私はこれを私の心の中から得ることができませんでした。 –

関連する問題