2010-07-13 52 views
0

正如您所看到的,我使用Cookie来弹出模式确认框和警报。虽然这些工作在很长一段时间之前一直工作到最近,但我一定是在这段代码中添加了一些东西,并且一切都变得不合时宜。模式上的“关闭”功能应该可以清除cookie,所以弹出窗口不会再弹出,现在它不会清除cookie,除非网页上有一个CKEditor,因为编辑器的调用是困扰我的之后的模式...jQuery cookie不会在用户界面关闭时清除

我忘了我以什么顺序添加每个元素 - 愚蠢的,我知道 - 而且很难有什么可能导致的问题。我最近也写了一堆mod_rewrite规则,但我不确定这是否会改变任何内容。

请帮助!我需要这个项目做这个星期...

这是我整个的jQuery块:

<script type="text/javascript"> 

$(document).ready(function(){ 
    $("body").prepend('<div id="topbar" class=""><\/div><div id="subnavbar" class="subnavbar-<?php echo $nav_id; ?>"><\/div>'); 
    $("#group-left a").prepend('- '); 
    $("input").hint(); 

    $("#mypassword").focus(function(){ 
     this.type='password'; 
     $(this).val(''); 
     }); 
    $("#mypassword").blur(function(){ 
     if($(this).val() == "Password") { 
      this.type='text'; 
     } 
     }); 
    $("label.required").append('<span style="color: #F00; float: none;">*<\/span>'); 
    $("#coupon_start").datepicker({dateFormat: 'yy-mm-dd'}); 
    $("#coupon_end").datepicker({dateFormat: 'yy-mm-dd'}); 

    $("div.blog-entry img").each(function() { 
     var blogImgFloat = $(this).css("float"); 
     if(blogImgFloat == "left") { 
      $(this).css("margin-right", "15px"); 
     } else if(blogImgFloat == "right") { 
      $(this).css("margin-left", "15px");   
     } 
    }); 

    $.fn.tipper = function() { 
     if($(this).attr('alt')) { 
      if($(this).hasClass('height')) { 
       $(this).qtip({ 
         content: $(this).attr('alt'), 
         position: { 
          corner: { 
           target: 'topMiddle', 
           tooltip: 'bottomMiddle' 
          } 
         }, 
         style: { 
          name: 'cream', // Inherit from preset style 
          padding: 10, 
          tip: 'bottomMiddle', 
          border: { 
          width: 5, 
          radius: 5 
          } 
         }, 
         show: 'focus', 
         hide: 'blur' 
        }); 
      } 

      else {        
       $(this).qtip({ 
         content: $(this).attr('alt'), 
         position: { 
          corner: { 
           target: 'rightMiddle', 
           tooltip: 'leftMiddle' 
          } 
         }, 
         style: { 
          name: 'cream', // Inherit from preset style 
          padding: 10, 
          tip: 'leftMiddle', 
          border: { 
          width: 5, 
          radius: 5 
          } 
         }, 
         show: 'focus', 
         hide: 'blur' 
        }); 
      } 
     } else { return false; } 
    }; 

    $("#content input").each(function(){ $(this).tipper(); }); 
    $("#content textarea").each(function(){ $(this).tipper(); }); 

    // calendar 
    $("#ajax-datepicker").datepicker({ 
     onSelect: function(date,instance){ 
      $(".eventdateheader").html(date); 
      $.ajax 
      ({ 
       type: "GET", 
       url: "/grab_events.php", 
       data: "date=" + $.datepicker.formatDate("yy-mm-dd", $(this).datepicker('getDate')), 
       success: function(result) 
       { 
        $("#eventslist").html(result); 
       } 
      }); 
     }, 
     minDate: '-2W', 
     dateFormat: 'M d, yy' 
    }); 

    $("#event-datepicker").datepicker({ 
     onSelect: function(date,instance){ 
      window.location = "/events.php?date=" + $.datepicker.formatDate("yy-mm-dd", $(this).datepicker('getDate')); 
     }, 
     minDate: '-2W', 
     gotoCurrent: true, 
     dateFormat: 'M d, yy' 
    }); 

    $("#event-datepicker").datepicker('setDate', '<?php echo $selected_date; ?>'); 

    $(".date").datepicker({ 
     dateFormat: 'yy-mm-dd', 
     showOn: 'button', 
     buttonImage: '/images/calendar.gif', 
     buttonImageOnly: true 
    }); 

    // regular dialog box 
    $("#dialog").dialog({autoOpen: false, modal: true}); 
    $("#dialog_link").click(function(){ 
     $("#dialog").dialog("open"); 
     return false; }); 

    // user context menu 
    $("a.user").contextMenu(
     { menu: 'HKPopUpMenu' }, 
     function(action, el, pos) { 
      var username = $(el).attr('id'); 
      if(action == "viewprofile") { window.location = "/profile.php?req="+username; } 
      else if(action == "viewblog") { window.location = "/profile_blog.php?req="+username; } 
      else if(action == "sendmsg") { 
       $("#sendmsg_to").val(username); 
       $("#sendmsg_div").dialog("open"); 
       return false; 
      } 
      else if(action == "sendwink") { 
       $.cookie("modal_confirm", "<?php echo $alert_13_send_wink_frag; ?>"+username+"?"); 
       $.cookie("confirmGo", "/sendwink_process.php?req="+username+"&nexturl=<?php echo curPageURL(); ?>"); 
       window.location.reload();     
      } 
      else { 
       alert(
         'Action: ' + action + '\n\n' + 
         'Element text: ' + thisid + '\n\n' + 
         'X: ' + pos.x + ' Y: ' + pos.y + ' (relative to element)\n\n' + 
         'X: ' + pos.docX + ' Y: ' + pos.docY+ ' (relative to document)' 
       ); 
      } 
     } 
    ); 

    // send message form 
    $("#sendmsg_div").dialog({ 
     autoOpen: false, 
     height: 300, 
     width: 500, 
     modal: true, 
     buttons: { 
      '<?php echo $popmenu_sendmsg; ?>': function() { 

       //validate 
       var m_to = $('input[name=sendmsg_to]'); 
       var m_subject = $('input[name=sendmsg_subject]'); 
       var m_body = $('textarea[name=sendmsg_body]'); 

       if (m_to.val()=='') { 
        m_to.addClass('highlight'); 
        return false; 
       } else { m_to.removeClass('highlight'); } 

       if (m_subject.val()=='') { 
        m_subject.addClass('highlight'); 
        return false; 
       } else { m_subject.removeClass('highlight'); } 

       if (m_body.val()=='') { 
        m_body.addClass('highlight'); 
        return false; 
       } else { m_body.removeClass('highlight'); } 

       $("#sendmsg_form").submit();     
       $(this).dialog('close'); 
      }, 
      Cancel: function() { 
       $(this).dialog('close'); 
      } 
     }, 
     close: function() { 
     } 
    }); 


    $("a.leftmenu_compose_message").click(function(){ 
     $("#sendmsg_div").dialog("open"); 
     return false; }); 
    $("a.mail").click(function(){ 
     $("#sendmsg_to").val($(this).attr('id')); 
     $("#sendmsg_div").dialog("open"); 
     return false; }); 


    // save search form 
    $("#savequery_div").dialog({ 
     autoOpen: false, 
     height: 220, 
     width: 300, 
     modal: true, 
     buttons: { 
      '<?php echo $popmenu_savequery; ?>': function() {       
       $("#savequery_form").submit();    
       $(this).dialog('close'); 
      }, 
      Cancel: function() { 
       $(this).dialog('close'); 
      } 
     }, 
     close: function() { 
     } 
    }); 


    $("a.savequery").click(function(){ 
     $("#savequery_div").dialog("open"); 
     return false; }); 


    // confirm box 
    if($.cookie("modal_confirm")!==null) { 
     $("body").prepend('<div id="confirm" title="System Message">'+$.cookie("modal_confirm")+'<\/div>'); 
     var g = $("#confirm"); 
     g.html(g.html().replace(/\+/g," ")); 
     $("#confirm").dialog({ 
      modal: true, 
      stack: true, 
      buttons: { 
       'OK': function() { 
        window.location = "\/" + $.cookie("confirmGo"); 
        $(this).dialog('close'); 
       }, 
       Cancel: function() { 
        $(this).dialog('close'); 
       } 
      }, 
      close: function(){ 
       $.cookie("modal_confirm",null); 
       $.cookie("confirmGo",null); 
       $(this).remove; 
      } 
     }); 
    } 

    // alert box 
    if($.cookie("alert")!==null) { 
     $("body").prepend('<div id="alert" title="System Message">'+$.cookie("alert")+'<\/div>'); 
     var f = $("#alert"); 
     f.html(f.html().replace(/\+/g," ")); 
     $("#alert").dialog({ 
      modal: true, 
      stack: true, 
      buttons: { 
       'OK': function() { 
        $(this).dialog('close'); 
       } 
      }, 
      close: function(){ 
       $.cookie("alert",null); $(this).remove; 
      } 
     }); 
    } 

    <?php if($include_editor) { ?> 
    // editors 
    $("textarea.editor").ckeditor({ 
     skin: 'kama', 
     toolbar: 'HKEditor', 
     filebrowserImageUploadUrl: '/php/upload.php', 
     language: <?php if($_SESSION["user_lng"] == "kor") { echo "'ko'"; } else { echo "'en'"; } ?> 
    }); 
    <?php } ?> 

}); // END DOC.READY  

回答

0

我想通了。 它不工作,因为JavaScript无法处理与服务器相关的URL。 我通过指定的cookie的路径固定它:

$.cookie("modal_confirm", null, { path: '/' });