We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33992 ☆ A M B ☆
    • 455 Posts
    very nice.
    thank you!

    i tested on MODxHost template, it didn’t work.
    logged out to turning QuickEdit off, it worked well in IE7 but didn’t worked on opera 9.21 and firefox 2.
    remove mootools JSs from modxHost to test it, firefox problem solved but opera doesn’t display result well.
    ajax links work well, loading appears, new content appears but after a second content disappears.
    i test your test-site in opera, works well probably it has problem with other JSs in MODxHost. (i use jQuery 1.2.4)

    i only wanted to report it, your tutorial is very very good, useful, .... smiley

    we created the Persian MODx support site (and forums) at http://modxcms.ir/forums,
    i will share this great tutorial with other Persian users in Persian language, if you let me! wink
      God loves me. 【ツ】


      MODX.ir (Persian Support)

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

      very nice.
      thank you!

      i tested on MODxHost template, it didn’t work.
      logged out to turning QuickEdit off, it worked well in IE7 but didn’t worked on opera 9.21 and firefox 2.
      remove mootools JSs from modxHost to test it, firefox problem solved but opera doesn’t display result well.
      ajax links work well, loading appears, new content appears but after a second content disappears.
      i test your test-site in opera, works well probably it has problem with other JSs in MODxHost. (i use jQuery 1.2.4)

      i only wanted to report it, your tutorial is very very good, useful, .... smiley

      we created the Persian MODx support site (and forums) at http://modxcms.ir/forums,
      i will share this great tutorial with other Persian users in Persian language, if you let me! wink

      Please do share.

      I don’t know about those problems, i’ll try to look into it. For those with more JS knowledge: is it posible that if multiple JS libraries like jquery and mootools, are listening to the document.ready() event, one or more of them break?

        • 33992 ☆ A M B ☆
        • 455 Posts
        I did share! wink
        you may visit it here, you can’t understand anything because everything is Persian(farsi) but you can see your name well smiley

        now other Persian users waits your updates too wink


        thanks again
          God loves me. 【ツ】


          MODX.ir (Persian Support)

          Boplo.ir/modx/ (Persian)
          • 20289
          • 958 Posts
          Great job folks, Thanks for sharing andreasfruth & also to my friend, AHHP which has translated it to Persian.
          Keep up a good work, it might worth adding to wiki or confluence :-]
            [img]http://i10.tinypic.com/52c4eir.gif[/img][/td]
            [td][Wiki] [Persian support forum]
            [SVN] [RTL SVN Branch] [bugs] [FishEye+Crucible] [Learn MODx!] | [My Google Code]
            [font=tahoma][برای دسترسی به راهنمای فارسی به [url=http://www.modxcms.ir]
            • 1532
            • 5 Posts
            Ok, the same result but this time using Mootools (QuickEdit still doesn’t work sad - see bottom for QE problem )

            Requirements:

            Mootools v. 1.11 - http://mootools.net
            Pageloader plugin for mootools: http://www.phatfusion.net/pageloader/
            History plugin for mootools: http://www.phatfusion.net/pageloader/

            Include those three .js files in <head>

            Use this code in the template:
            <div id="content">
                <div id="toload">
                       [*content*]
                </div>
            </div>
            


            Use a class on all your links that should trigger ajax (let’s say .ajaxlink)

            Put the following code into a chunk and include the chunk in your template:

            <script>
            			window.addEvent('domready', function(){
            				new pageLoader({loadInTo:'content',
                                                                       loadFrom:'toload',
                                                                       links:'ajaxlink',
                                                                       onStart: $(this.options.loadInTo).replaceWith("<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>");});
            				new History();
            			});
            </script>


            on http://www.phatfusion.net/pageloader/ you’ll see explanations about the options you can use with pageloader.

            a little explanation:
            loadInTo:’content’, - the div to load Into
            loadFrom:’toload’, - the div to load from
            links:’ajaxlink’, - class of the links that trigger ajax
            onStart:’....’ - code that shows the nice Loading image

            If you want nice links, you have to hack the history.js file, look for the following code and add the line that begins with >>>:

            	set: function(str){
            		var url = this.formatURL(this.url);
            		str = this.formatHash(str);
               >>>     str = str.replace("replace this with your url that will be substracted", "");
            		this.url = url+'#'+str;
            		window.location.href = this.url;
            		if(window.ie){
            			this.iframe.setProperty('src', str);
            		}



            EDIT: - by following these indications: http://modxcms.com/bugs/task/989 you can get QuickEdit to work.
            Basically, QE included it’s own version of mootools, and this tip prevents mootools to be included twice.
            Downside: you have to include mootools manually or QE won’t work.

            Still i don’t see this as an elegant solution. That’s why i ask: is there any way to find out in a snippet if a module/pluggin is enabled/disabled?
            That way i could check if QE is enabled and showing and load or not mootools based on this.
              • 16680
              • 73 Posts
              Hey, great tutorial, thanks for writing it.

              I have a slight problem with it though. When I click on a link the loader icon begins to spin, but it just sits like that forever. No new content is displayed. Has anyone else experienced this?

              Oh by the way I just noticed an error that firebug gave me:

              Access to restricted URI denied" code: "1012
              [Break on this error] xhr.open(type,s.url,s.async);try{if(s.da...[s.url]=modRes;if(!jsonp)success();}else


              It is on line 28 in the assets/js/jQuery.js file:

              28xhr.open(type,s.url,s.async);try{if(s.data)xhr.setRequestHeader("Content-Type",s.contentType);if(s.ifModified)xhr.setRequestHeader("If-Modified-Since",jQuery.lastModified[s.url]||"Thu, 01 Jan 1970 00:00:00 GMT");xhr.setRequestHeader("X-Requested-With","XMLHttpRequest");xhr.setRequestHeader("Accept",s.dataType&&s.accepts[s.dataType]?s.accepts[s.dataType]+", */*":s.accepts._default);}catch(e){}if(s.beforeSend&&s.beforeSend(xhr,s)===false){s.global&&jQuery.active--;xhr.abort();return false;}if(s.global)jQuery.event.trigger("ajaxSend",[xhr,s]);var onreadystatechange=function(isTimeout){if(!requestDone&&xhr&&(xhr.readyState==4||isTimeout=="timeout")){requestDone=true;if(ival){clearInterval(ival);ival=null;}status=isTimeout=="timeout"&&"timeout"||!jQuery.httpSuccess(xhr)&&"error"||s.ifModified&&jQuery.httpNotModified(xhr,s.url)&&"notmodified"||"success";if(status=="success"){try{data=jQuery.httpData(xhr,s.dataType,s.dataFilter);}catch(e){status="parsererror";}}if(status=="success"){var modRes;try{modRes=xhr.getResponseHeader("Last-Modified");}catch(e){}if(s.ifModified&&modRes)jQuery.lastModified[s.url]=modRes;if(!jsonp)success();}else


              Unfortunately I don’t have a clue what that means..

              thanks, larsb
                Signature on it&#39;s way
                • 15001
                • 697 Posts
                Hi,

                I could AJAXify my MODx site by following the tutorial.

                Now, I’m trying to do something more sophisticated :
                1) loading in a div the summary (introtext) of a child document when the mouse is over a link (onmouseover event)
                2) and load the content of this child document in another div when the link is clicked.

                I thought that the first step for this was being able to add processing of mutiple events.
                So, I tried to define the processing function externally to the addEvent call.
                But this did not work. For the first call of the addEvent function, Firebug tells that evt is undefined. (code is below)

                I really don’t know how to implement this as (as long as I know) the class and rel attributes of my link only allow to define one target and one template. So, how to handle two types of events with two different targets ?

                Maybe an idea could be to include some div within or around the anchor element and define class and rel for this div.
                Then, define some action for onmouseover in Kudolink’s code.

                Does anyone have an idea for a flexible solution ?

                Unsuccessful try to modify Kudolink’s code :
                function processEvent (evt)
                {
                 evt = evt || window.event;
                 if (evt.which > 1 || evt.button > 1) return;
                 var src = evt.target || evt.srcElement;
                 if (src.nodeType && src.nodeType != 1) src = src.parentNode;
                 while (src)
                 {
                  var srcName = (src.nodeName||src.tagName||'').toLowerCase();
                  if (srcName == 'a' && src.className && src.className.match(/^(load|toggle)into-(.+)$/))
                  {
                   if (RegExp.$1 == 'load') return loadInto(src, RegExp.$2, evt);
                   if (RegExp.$1 == 'toggle') return toggleInto(src, RegExp.$2, evt);
                  }
                  src = src.parentNode;
                 }
                };
                addEvent(document, 'click', processEvent(evt), 1);
                addEvent(document, 'mouseover', processEvent(evt), 1);
                


                  • 15001
                  • 697 Posts
                  Summary : I want Ajax to retrieve different content and send it to different targets, depending on the event that occurs for an anchor (click or mouseover). See the first post of this thread (i.e. the tutorial) for an implementation that only handles the click event.
                  -----------------------------------------------------------------------------------------

                  I canceled my changes to the Kudolink’s script (see my previous post) and had another approach.

                  As the class rel defines which template is used to format what Ajax returns,
                  and as the rel class defines the container where to send Ajax’s output, I tried changing this dynamically in the row template chunk of the Wayfinder config file, using the onmouseover and onclick events.

                  Code below is wrong, because I mixed the roles of the class and rel attributes.
                  $rowTpl = '@CODE:<li><a 
                  	onmouseover="this.class=\'loadinto-resume_rubrique\';this.rel=\'Template_resume_rubrique\';" 
                  	onclick="this.class=\'loadinto-texte_rubrique\';this.rel=\'Template_texte_rubrique\';"
                  	href="[+wf.link+]" 
                  	title="[+wf.pagetitle+]">
                  	<div class="chapeau lettrine">[+wf.linktext+]</div><span></span>
                  	</a></li>';

                  Using some javascript alert boxes, I could confirm that the "class" and "rel" attributes were correctly set.

                  Unfortunately, my code still does not work.
                  It worked when the class and rel were defined "statically", i.e. without basing on the onmouseover and onclick events.

                  Who can help ?
                  Thanks.


                  There are two other errors that I did :

                  1) The behaviour for the click is defined in kudolink’s code, which is placed in the template for the "parent" page.
                  So, I have to modify this code instead of Wayfinder’s row chunk definition.

                  2) The click and mouseover events occurs for the div that is in the anchor and not for the anchor itself.

                  I’ll have to alter kudolink’s code.
                  Not obvious however...


                    • 15001
                    • 697 Posts
                    Yoohooo ! smiley I could change the code so that different contents are loaded by Ajax into different target containers depending on which event occurs: mouseover or click.

                    undecided There’s however a problem with my the target for the template defined by the rel attribute: it’s the parent document and not the content retrieved par Ajax.
                    The error comes most probably from the fact that I define the rel attribute for the src variable (src.rel) and I should do it for the target (target.rel) or something like this.

                    The code that I use is the one here : http://modxcms.com/forums/index.php?topic=6743
                    in the "3. Create 2 templates" section with the following changes :
                    1) Added an event handler for mouseover.
                    2) The class and rel attributes are defined dynamically (see code below)
                    addEvent(document, 'mouseover', function(evt){
                     evt = evt || window.event;
                     if (evt.which > 1 || evt.button > 1) return;
                     var src = evt.target || evt.srcElement;
                     src.rel='Template_resume_rubrique';
                     src.className="loadinto-resume_rubrique";
                     if (src.nodeType && src.nodeType != 1) src = src.parentNode;
                     while (src)
                     {
                      var srcName = (src.nodeName||src.tagName||'').toLowerCase();
                      if (srcName == 'a' && src.className && src.className.match(/^(load|toggle)into-(.+)$/))
                      {
                       if (RegExp.$1 == 'load') return loadInto(src, RegExp.$2, evt);
                       if (RegExp.$1 == 'toggle') return toggleInto(src, RegExp.$2, evt);
                      }
                      src = src.parentNode;
                     }
                    }
                    , 1);
                    
                    addEvent(document, 'click', function(evt){
                     evt = evt || window.event;
                     if (evt.which > 1 || evt.button > 1) return;
                     var src = evt.target || evt.srcElement;
                     if (src.nodeType && src.nodeType != 1) src = src.parentNode;
                     while (src)
                     {
                      var srcName = (src.nodeName||src.tagName||'').toLowerCase();
                      src.rel='Template_texte_rubrique';
                      src.className="loadinto-texte_rubrique";
                      if (srcName == 'a' && src.className && src.className.match(/^(load|toggle)into-(.+)$/))
                      {
                       if (RegExp.$1 == 'load') return loadInto(src, RegExp.$2, evt);
                       if (RegExp.$1 == 'toggle') return toggleInto(src, RegExp.$2, evt);
                      }
                      src = src.parentNode;
                     }
                    }
                    , 1);

                    Chunk for the links that do the Ajax calls :
                    $rowTpl = '@CODE:<li><a  
                    	href="[+wf.link+]" 
                    	title="[+wf.pagetitle+]">
                    	<div class="chapeau lettrine" >[+wf.linktext+]</div><span></span>
                    	</a></li>';

                    A possible improvement would be reducing code redundancy as the functions that handle the onclick and onmouseover events are 95% the same.
                      • 15001
                      • 697 Posts
                      Well. I removed the src.rel definitions in the event handlers and changed the definition of variable "template" in the loadInto function. Like this:

                      function loadInto(src, destId, evt) // Function modified by Heliotrope to accept REL attr - kudo
                      {
                      template = 'template=' + 'OwnTemplates_' + destId;      // Changed this line
                      url =  src.href;
                      src.href = (url.indexOf('?')>0)? url + '&' + template: url + '?' + template;
                      ...
                      

                      As you can see the template to use has the same name as the id of the destination container in which the output from Ajax has to be formatted, plus some prefix (OwnTemplates_).

                      huh For a mysterious reason, the appearance of the clicked or mouseovered link also changes when an event occurs. undecided
                      Any idea why ?