Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Multiple instances possible? #3

Closed
jenswaern opened this issue Feb 8, 2014 · 2 comments
Closed

Multiple instances possible? #3

jenswaern opened this issue Feb 8, 2014 · 2 comments

Comments

@jenswaern
Copy link

Hi, great plugin!
I'm trying to create an additional ajax-menu inside a piece of content that is loaded via my main ajax-menu, however I can't get it working.

I've tried running two separate pushers ( $('#menu_1').pusher(...) + $('#menu_2').pusher(...) (once menu_2 gets loaded ofcourse)) and also adding menu_2 via 'watch' from the start, but neither seems to work.

Is there some way around this?

Best regards

Jens

@salvan13
Copy link
Owner

salvan13 commented Feb 8, 2014

Hello,
actually the plugin does not support multiple instances, but you can handle it using the state object.
You can use the onStateCreation function to add your custom data to the state object and then use it in the handler function.

Here an expample:

<body>
    <nav id="main.nav">
      <a href="link1.html" data-target="wrapper">Link 1</a>
      <a href="link2.html" data-target="wrapper">Link 2</a>
      <a href="link3.html" data-target="wrapper">Link 3</a>
    </nav>
    <nav id="secondary-nav">
      <a href="link4.html" data-target="content">Link 4</a>
      <a href="link5.html" data-target="content">Link 5</a>
      <a href="link6.html" data-target="content">Link 6</a>
    </nav>
    <div id="wrapper">wrapper home</div>
    <div id="content">content home</div>
</body>
jQuery(function($){
  $("body").pusher({
    watch: "nav a",
    onStateCreation: function(state, elem) {
      if(elem) {
        state.target = elem.data('target');
      }
    },
    handler: function() {
      this.updateText("title");
      if(this.state.target) {
        this.updateHtml("#" + this.state.target);
      }
    }
  });
});

I hope this is helpful.

@jenswaern
Copy link
Author

Worked like a charm, thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants