I do have a site that does some kind of management. There I used JQuery Tab for the structure and call all panel using AJAX. I Use also JQuery Address for the bookmarking as per a post I found somewhere
I've got 2 problems
1) While this all works fine with FF, I can't make it work in IE (well, just the bookmarking stuff) 2) My javascript looks horrible (and I can't see how to simplify it)
Could you be of any help here ?
Thanks
Here is the code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>title</title>
<link type="text/css" href="Style/style.css" rel="stylesheet"/>
<link href="Style/jquery-ui.css" rel="stylesheet" type="text/css"/>
<link href="Style/colorbox.css" rel="stylesheet" type="text/css"/>
<script src="JS/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="JS/jquery-ui-1.8.14.custom.min.js" type="text/javascript"></script>
<script src="JS/jquery.address-1.3.1.min.js" type="text/javascript"></script>
<script src="JS/jquery.colorbox-min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("a[rel='colorBox']").colorbox();
$(".tabs1").tabs( {
ajaxOptions: {
error: function( xhr, status, index, anchor )
{ $( anchor.hash ).html("Couldn\'t load this tab. We\'ll try to fix this as soon as possible. ");
},
success: function()
{
$(".tabs1").tabs( {
ajaxOptions: {
error: function( xhr, status, index, anchor )
{ $( anchor.hash ).html("Couldn\'t load this tab. We\'ll try to fix this as soon as possible. ");
},
success: function()
{ $(".tabs1").tabs(); $(".tabs2").tabs(); $(".tabs3").tabs();
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
$('ul li a').bind('click', function()
{
var value = $(this).attr('href').substring(1); $.address.value(value);
});
}
} } );
$(".tabs2").tabs( {
ajaxOptions: {
error: function( xhr, status, index, anchor )
{ $( anchor.hash ).html("Couldn\'t load this tab. We\'ll try to fix this as soon as possible. ");
},
success: function()
{ $(".tabs1").tabs(); $(".tabs2").tabs(); $(".tabs3").tabs();
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
$('ul li a').bind('click', function()
{
var value = $(this).attr('href').substring(1); $.address.value(value);
});
}
} } );
$(".tabs3").tabs( {
ajaxOptions: {
error: function( xhr, status, index, anchor )
{ $( anchor.hash ).html("Couldn\'t load this tab. We\'ll try to fix this as soon as possible. ");
},
success: function()
{ $(".tabs1").tabs(); $(".tabs2").tabs(); $(".tabs3").tabs();
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
$('ul li a').bind('click', function()
{
var value = $(this).attr('href').substring(1); $.address.value(value);
});
}
} } );
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
$('ul li a').bind('click', function()
{
var value = $(this).attr('href').substring(1); $.address.value(value);
});
}
} } );
$(".tabs2").tabs( {
ajaxOptions: {
error: function( xhr, status, index, anchor )
{ $( anchor.hash ).html("Couldn\'t load this tab. We\'ll try to fix this as soon as possible. ");
},
success: function()
{ $(".tabs1").tabs(); $(".tabs2").tabs(); $(".tabs3").tabs(); 开发者_高级运维
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
$('ul li a').bind('click', function()
{
var value = $(this).attr('href').substring(1); $.address.value(value);
});
}
} } );
$(".tabs3").tabs( {
ajaxOptions: {
error: function( xhr, status, index, anchor )
{ $( anchor.hash ).html("Couldn\'t load this tab. We\'ll try to fix this as soon as possible. ");
},
success: function()
{ $(".tabs1").tabs(); $(".tabs2").tabs(); $(".tabs3").tabs();
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
$('ul li a').bind('click', function()
{
var value = $(this).attr('href').substring(1); $.address.value(value);
});
}
} } );
});
$(function(){
var title = 'title';
$('head title').text(title);
// jQuery Address
$.address.strict(0);
$.address.tracker(0);
if ($.address.value() == '') {
$(".tabs1").tabs("select", "#index");
//$(".tabs2").tabs("select", "#list");
$.address.value('index');
}
$.address.init(function(event) {
$(".tabs1").tabs( {
ajaxOptions: {
error: function( xhr, status, index, anchor )
{ $( anchor.hash ).html("Couldn\'t load this tab. We\'ll try to fix this as soon as possible. ");
},
success: function()
{
$(".tabs1").tabs( {
ajaxOptions: {
error: function( xhr, status, index, anchor )
{ $( anchor.hash ).html("Couldn\'t load this tab. We\'ll try to fix this as soon as possible. ");
},
success: function()
{ $(".tabs1").tabs(); $(".tabs2").tabs(); $(".tabs3").tabs();
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
$('ul li a').bind('click', function()
{
var value = $(this).attr('href').substring(1); $.address.value(value);
});
}
} } );
$(".tabs2").tabs( {
ajaxOptions: {
error: function( xhr, status, index, anchor )
{ $( anchor.hash ).html("Couldn\'t load this tab. We\'ll try to fix this as soon as possible. ");
},
success: function()
{ $(".tabs1").tabs(); $(".tabs2").tabs(); $(".tabs3").tabs();
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
$('ul li a').bind('click', function()
{
var value = $(this).attr('href').substring(1); $.address.value(value);
});
}
} } );
$(".tabs3").tabs( {
ajaxOptions: {
error: function( xhr, status, index, anchor )
{ $( anchor.hash ).html("Couldn\'t load this tab. We\'ll try to fix this as soon as possible. ");
},
success: function()
{ $(".tabs1").tabs(); $(".tabs2").tabs(); $(".tabs3").tabs();
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
$('ul li a').bind('click', function()
{
var value = $(this).attr('href').substring(1); $.address.value(value);
});
}
} } );
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
$('ul li a').bind('click', function()
{
var value = $(this).attr('href').substring(1); $.address.value(value);
});
}
} } );
$(".tabs2").tabs( {
ajaxOptions: {
error: function( xhr, status, index, anchor )
{ $( anchor.hash ).html("Couldn\'t load this tab. We\'ll try to fix this as soon as possible. ");
},
success: function()
{ $(".tabs1").tabs(); $(".tabs2").tabs(); $(".tabs3").tabs();
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
$('ul li a').bind('click', function()
{
var value = $(this).attr('href').substring(1); $.address.value(value);
});
}
} } );
$(".tabs3").tabs( {
ajaxOptions: {
error: function( xhr, status, index, anchor )
{ $( anchor.hash ).html("Couldn\'t load this tab. We\'ll try to fix this as soon as possible. ");
},
success: function()
{ $(".tabs1").tabs(); $(".tabs2").tabs(); $(".tabs3").tabs();
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
$('ul li a').bind('click', function()
{
var value = $(this).attr('href').substring(1); $.address.value(value);
});
}
} } );
});
$.address.change(function(event) {
var value = $.address.value();
$.address.title(title + ' @ #' + value);
});
$.address.externalChange(function(event) {
var value = $.address.value();
var value_array = value.split('-');
$(".tabs1").tabs("select", value_array[0]);
$(".tabs2").tabs("select", value_array[1]);
$(".tabs3").tabs("select", value_array[2]);
$.address.value(value);
});
$.address.history(true);
$('ul li a').bind('click', function() {
var value = $(this).attr('href').substring(1);
$.address.value(value);
});
});
</script>
</head>
<body>
<div class="tabs1">
<ul>
<li><a href="indexTab.php" title="index"><span>Home</span></a></li>
<li><a href="memberTab.php" title="member"><span>Données membre</span></a></li>
<li><a href="clubTab.php" title="club"><span>Club</span></a></li>
<li><a href="gestionTab.php" title="gestion"><span>Gestion</span></a></li>
<li><a href="toolsTab.php" title="tools"><span>Outils</span></a></li>
</ul>
<div id="index" class="ui-tabs-hide"></div>
<div id="member" class="ui-tabs-hide"></div>
<div id="club" class="ui-tabs-hide"></div>
<div id="gestion" class="ui-tabs-hide"></div>
<div id="tools" class="ui-tabs-hide"></div>
</div>
</body>
</html>
Use $('selector').delegate()
it watches the DOM of 'selector' and .live()
is deprecated.
Use this to watch your elements AND fire the colorbox initilization. This way the colorbox is not dependent on the DOM element, but the other way around.
Replace:
$("a[rel='colorBox']").colorbox();
With:
$("body").delegate("a[rel='colorBox']", "click", function (event) {
event.preventDefault();
var props = {href:$(this).attr("href")}
if($(this).hasClass("ajaxColorBox"))
props['width'] = "75%";
props['height'] = "75%";
}else if($(this).hasClass("ajaxColorBoxForm")){
props['width'] = "75%";
props['height'] = "75%";
props['inline'] = true;
props['href'] = "#inline_form";
}else if($(this).hasClass("ajaxColorBoxiFrame")){
props['width'] = "75%";
props['height'] = "75%";
props['iframe'] = true;
props['onClosed'] = function(){ location.reload(true); }
}
$.colorbox(props);
});
This should basically solve your problem and is cross browser tested. The a[rel='colorbox'] in the delegate closure is the reference to what ever link you're clicking to fire the colorbox, whether it has been loaded with the initial DOM or with an AJAX request and has been added to the DOM in a live fashion. ie: any tag like this:
<a rel='colorbox' href="http://some.website.com">Launch Colorbox</a>
You can also now remove every instance of:
$(".ajaxColorBox").colorbox({width:"75%", height:"75%"});
$(".ajaxColorBoxLabel").colorbox();
$(".ajaxColorBoxForm").colorbox({width:"75%", height:"75%",inline:true, href:"#inline_form"});
$(".ajaxColorBoxiFrame").colorbox({width:"75%", height:"75%",iframe:true,onClosed:function(){ location.reload(true); }});
from every single success: function(){}
精彩评论