/    Sign up×
Community /Pin to ProfileBookmark

Jquery history plugin customizing

So, i have this code which retrieves php files for me and id love to get jquery history plugin workin with this ( [URL=”http://tkyk.github.com/jquery-history-plugin/”]Jquery history plugin[/URL] ) I tried modifying the code i got from the ajax demo to work for me, but i just couldnt do it as i do not know any javascript really.. ( actually what i tried was simply to change “#ajax-links a” to “#menu li a” but nothing.. 😮 )
[B]
Id be very gratefull if someone would help me out with this one.
[/B]

All related code can be found bellow (the ones that should be needed anyways):

This is the code that retrieves php files inside “#content” when item from “#menu li a” with the specified id is clicked

[CODE]
$(document).ready(function(){
//References
var change = $(“#menu li a”);
var loading = $(“#loading”);
var content = $(“#content”);

//Manage click events
change.click(function(){
//show the loading bar
showLoading();
//load selected section
if(this.id == “home”)
{
change.load(this.className=’current-page’);
content.slideUp();
content.load(“pages/index.php”, hideLoading);
content.slideDown();
}
else if(this.id == “tokasivu”)
{
change.load(this.className=’current-page’);
content.slideUp();
content.load(“pages/secondpage.php”, hideLoading);
content.slideDown();
}
else
{
//hide loading bar if there is no selected section
hideLoading();
}
});

//show loading bar
function showLoading(){
loading
.css({visibility:”visible”})
.css({opacity:”1″})
.css({display:”block”})
;
}

//hide loading bar
function hideLoading(){
loading.fadeTo(1000, 0);
};
});
[/CODE]

Heres the structure of the menu/content

[CODE]
<ul id=”menu”>
<li><a id=”home” class=”normal” href=”#Home”></a></li>
<li><a id=”secondpage” class=”normal” href=”#Secondpage”></a></li>
</ul>

<div id=”content”>
<ul id=”sec-menu”>
<li><a id=”link1″ class=”normal” href=”#”>Link1</a></li>
<li><a id=”link2″ class=”normal” href=”#”>Link2</a></li>
</ul>
</div>
[/CODE]

Heres the code that jquery history plugin uses in demo for ajax

[CODE]
jQuery(document).ready(function($) {
function load(num) {
$(‘#content’).load(num +”.html”);
}

$.history.init(function(url) {
load(url == “” ? “1” : url);
});

$(‘#ajax-links a’).live(‘click’, function(e) {
var url = $(this).attr(‘href’);
url = url.replace(/^.*#/, ”);
$.history.load(url);
return false;
});
});
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@majavaauthorNov 01.2010 — And yes [B]" else if(this.id == "tokasivu") "[/B]

[B]" tokasivu "[/B] is supposed to be [B]" secondpage "[/B] ( i translated the stuff i had written in Finnish just to make things simple )
×

Success!

Help @majava spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...