We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8895
    • 76 Posts
    Where do i get the template switcher? OR even better, is it possible to do this without template switcher? (as ive alredy got my template setup and working and i dont really want to fiddle arround with it too much.

    thnx for your help - and if this should work -> you rule! =)
      • 33992 ☆ A M B ☆
      • 455 Posts
        God loves me. 【ツ】


        MODX.ir (Persian Support)

        Boplo.ir/modx/ (Persian)
        • 21908
        • 8 Posts
        Wow, this tutorial rocks!

        I have only question: How does google handle such ajax based sites? Is google bot able to index all those ajaxed pages?
          modx is amazing and brilliant. So is modx community!
          • 24531
          • 213 Posts
          guys i just wanted to thank you for this tutorial!!!

          Quote from: numberblack at Nov 28, 2007, 06:37 PM

          Is google bot able to index all those ajaxed pages?
          i think yes cause bot uses no js so it’ll get actual links to pages
            • 1532
            • 5 Posts
            This post is obsolete - please see http://modxcms.com/forums/index.php/topic,6743.msg157954.html#msg157954 for the tutorial.
              • 29076
              • 615 Posts
              I’m definitely interested in this. I need this on my site about the flora on Svalbard. Please make a tutorial if you can, and please continue any developement on this. laugh
                I think, thererfor I am! But what I am, and why...?
                • 33992 ☆ A M B ☆
                • 455 Posts
                thank you very very much laugh
                I’m waiting for your complete tutorial! wink

                the attached file (history.zip) is damaged!! is it exactly file in this page? http://plugins.jquery.com/files/jquery.history.js_0.txt
                  God loves me. 【ツ】


                  MODX.ir (Persian Support)

                  Boplo.ir/modx/ (Persian)
                  • 1532
                  • 5 Posts
                  Quote from: AHHP at May 20, 2008, 06:34 AM

                  thank you very very much laugh
                  I’m waiting for your complete tutorial! wink

                  the attached file (history.zip) is damaged!! is it exactly file in this page? http://plugins.jquery.com/files/jquery.history.js_0.txt

                  Yes, just copy/paste what’s in there into a file called histoy.js (or whatever you want).

                  I’m currently rewriting the above two posts, and i hope i’ll have a more understable tutorial up today or tommorrow.
                    • 29076
                    • 615 Posts
                    Great news!
                      I think, thererfor I am! But what I am, and why...?
                      • 1532
                      • 5 Posts
                      Ok, so here is another method of getting your modX site Ajaxified, complete with history and bookmark capability.
                      You won’t need the template switcher for this.
                      Also, I found some problems between jquery and QuickEdit. I disabled QuickEdit (I don’t usually have a need for it). If someone could find why they don’t work together please share.

                      You can find an working example at: http://cumvreau.eu/test/

                      Requirements:

                      jQuery 1.2.3 – http://www.jQuery.com (1.2.3 is the version I used, it might work with newer versions also)
                      History plugin for jQuery: http://plugins.jquery.com/files/jquery.history.js_0.txt - copy all the text into a file named history.js

                      Crash course:

                      Step 1:

                      Include the two .js files (jquery.js, and history.js) in your template <head>.

                      Put the following code in the head also:
                      (You can put the code in a chunk, and then include the chunk in your template <head>)

                      <script>
                      var linkstyle = ".ajaxlink";
                      var content = "#content";
                      var toload = "#toload";
                      var uglyurl = "[(site_url)]"
                      
                      function callback(hash)
                      {
                      	if (hash != '') {
                      		var loadstr = uglyurl + hash;
                      		$(content).html("<div id='loader'><img src='assets/images/ajax-loader.gif' /><br /><p style='font-size:20px; color:red;'>Loading content <br />please wait!</p></div>");
                      		$(content).load(loadstr+" "+toload);
                      	}
                      }
                      $(document).ready(function() {
                          $.history.init(callback);
                          $(linkstyle).click(function(event){
                              event.preventDefault();
                              var str = this.href.replace(uglyurl, "");
                              $.history.load(str.replace(/^.*#/, ''));
                              $(content).html("<div id='loader'><img src='assets/images/ajax-loader.gif' /><br /><p style='font-size:20px; color:red;'>Loading content <br />please wait!</p></div>");
                              $(content).load(this.href+" "+toload);
                              return false;
                          });
                      });
                      </script>
                      


                      Little explainer for the first four variables in the script:

                      linkstyle: put the class that you will use for the links that trigger ajax.
                      content: id for the <div> that your content will be loaded into.
                      toload: id of the div that will be brought from the outside pages along with all it’s contents and placed into ‘content’.
                      uglyurl: part of the link url to be stripped in order to beautify your link. eg: when you click an ajaxified link you will get an url in your browser like this:

                      ht tp://yoursite.com/index#http://yoursite.com/page-two

                      If you set your ‘uglyurl’ variable to “ht tp://yoursite.com/” the above url will look like this:

                      ht tp://yoursite.com/index#page-two

                      It’s just for good looks.

                      Set your four variables how you like them. I’ll use:

                      var linkstyle = ".ajaxlink";
                      var content = "#content";
                      var toload = "#toload";
                      var uglyurl = "[(site_url)]"


                      Step 2:

                      Build your template with the following in mind:

                      Wrap ‘toload’ (or whatever you set the toload var to) around your [*content*] TV, and then wrap ‘content’ (or whatever you set the content var to) around ‘toload’ like this:


                      …template code…
                      <div id="content">
                      		<div id="toload">
                      				[*content*]
                      		</div>
                      </div>
                      …more template code…
                      


                      Apply the ‘linkstyle’ (or whatever you set the linkstyle var to) class to any link you’d like to trigger Ajax like this:
                      <a class="ajaxlink" href="[~1~]">Link to main page</a>
                      <a class="ajaxlink" href="[~2~]">Link to page 1</a>
                      <a class="ajaxlink" href="[~3~]">Link to page 2</a>
                      <a class="ajaxlink" href="[~4~]">Link to page 3</a>
                      


                      That’s it for the crash course, you should be good to go.


                      Thorough explanation:

                      How it works:

                      $(document).ready(function() {

                      When the page loads, the JS in the head activates.

                      $.history.init(callback);

                      This is a function that checks if the browser URL has a # in it. If it does, the function runs the callback function with anything that’s after # as a parameter.
                      The callback function prepends what’s in your ‘uglylink’ variable to the received parameter and loads into ‘content’ the ‘toload’ div from the specified url.
                      This allows you to have bookmarks and history on your site.

                      $(linkstyle).click(function(event){

                      Puts an onclick function on every element with a class of ‘linkstyle’. This means that your browser will listen and intercept any click on a link with that class.
                      We use this instead of putting functions directly on the onclick event in the links because this way, if the user has JS off, he’ll still be able to navigate your site the traditional way.

                      event.preventDefault();

                      We don’t want the browser to go to that link directly so we prevent that.

                      var str = this.href.replace(uglyurl, "");


                      The above is a little string replacement to beautify your links. What it does: it takes the url from the clicked link, and substracts what you have defined in the ‘uglyurl’ var. This way we will have links like this: ht tp://yoursite.com/index#page-two instead of ht tp://yoursite.com/index#http://yoursite.com/page-two.

                      $.history.load(str.replace(/^.*#/, ’’));

                      We put the new address in the history stack, adding a # to it to trick the browser.

                      $(content).html("<div id=’loader’><img src=’assets/images/ajax-loader.gif’ />
                      <p style=’font-size:20px; color:red;’>Loading content
                      please wait!</p></div>");
                      $(content).load(this.href+" "+toload);


                      The first line puts a nice Loading image and text until the target page is loaded, and the second gets ‘toload’ div and all it’s contents from the target page, putting it into the ‘content’ div in our page (and replacing any existing content).


                      I hope this tutorial is more understandable than my previous posts smiley.