Я использую Rails 4 и Turbolinks, я использую плагин jquery "contextMenu" для создания небольшого меню. Если я перезагружу свое приложение и нажму кнопку, мое contextMenu сработает, но если я перейду в свое приложение и вернусь на эту страницу и нажмите на мою кнопку, contextMenu не работает.
Кто-нибудь может помочь мне с моим кодом, пожалуйста?
$(document).on "page:change", ->
# uncheck tous les checkbox
uncheckAllBox = ->
$("#table_sounds :checkbox").each ->
$("#sound_id").prop "checked", false
@checked = false
return
$("#delete_sounds").css "display", "none"
count_checkbox_true == 0
return
# check tous les checkbox
checkAllBox = ->
$("#table_sounds :checkbox").each ->
$("#sound_id").prop "checked", true
@checked = true
$("#delete_sounds").css "display", "inline"
count_checkbox_true = count_checkbox_max
return
# Check le checkbox du table en fonction de la progression des sons
checkType = (type) ->
uncheckAllBox()
$("#table_sounds tr").each ->
# Check les checkbox qui ne sont pas encore checked et qui sont du type selectionner
if type is $(this).attr("class")
$(this).find(":checkbox").each ->
@checked = true
count_checkbox_true++
return
return
return
# Les différent test pour rendre visible l'image de la corbeille et check la checkbox du th
count_checkbox_true = 0
count_checkbox_max = 0
if $("#table_sounds").length > 0
########################### BUG ON THIS PART ########################
$(document).on "click", "#table_sounds #button_select", ->
$.contextMenu
selector: "#button_select"
trigger: "left"
callback: (key, options) ->
m = "clicked: " + key
window.console and console.log(m) or alert(m)
return
items:
all:
name: "Tout"
callback: (key, options) ->
checkAllBox()
return
none:
name: "Aucun"
callback: (key, options) ->
uncheckAllBox()
return
success:
name: "Finie"
callback: (key, options) ->
checkType "success"
return
error:
name: "Erreur"
callback: (key, options) ->
checkType "error"
return
in_progress:
name: "En cours"
callback: (key, options) ->
checkType "info"
return
###################### END OF BUG PART ###########################
$ ->
$("#table_sounds :checkbox").each ->
count_checkbox_max++
if @checked
count_checkbox_true++
$("#delete_sounds").css "display", "inline"
return
count_checkbox_max--
document.getElementById("delete_system").style.display = "none" if count_checkbox_max is 0
count_checkbox_true = count_checkbox_max if count_checkbox_true > count_checkbox_max
return
$(".checkbox_sounds").click ->
if @checked
count_checkbox_true++
$("#delete_sounds").css "display", "inline"
else
count_checkbox_true--
$("#delete_sounds").css "display", "none"
if count_checkbox_true is count_checkbox_max
$("#sound_id").prop "checked", true
else
if count_checkbox_true > 0
$("#delete_sounds").css "display", "inline"
$("#sound_id").prop "checked", false
return
$("#sound_id").click ->
if @checked
checkAllBox()
else
uncheckAllBox()
return
return
Но если я попробую просто с предупреждением, это сработает.
$(document).on "click", "#table_sounds #button_select", ->
alert("that's work)
Я не понимаю, что мне нужно изменить для работы с кофе в коде.
Спасибо за вашу помощь.
page:change
? Также вам не нужен драгоценный камень, функцияon
будет работать. - person Mandeep   schedule 04.08.2014page:change
. У вас уже есть событие click для#button_select
, так что оно должно работать. - person Mandeep   schedule 04.08.2014page:change
. Ваше оповещение также работает, у которого нет события page:change - person Mandeep   schedule 04.08.2014