Book Image

concrete5 Beginner's Guide

Book Image

concrete5 Beginner's Guide

Overview of this book

Table of Contents (19 chapters)
concrete5
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – direct link with dynamic content


  1. Open view.js from the previous template again.

  2. Replace everything with this content:

    function getLinkHash(linkHref) {
      linkHref = linkHref.replace(CCM_DISPATCHER_FILENAME,"");	
      return linkHref.replace(new RegExp("[^a-zA-Z0-9_]","g"), "");
    }
    
    $(document).ready(function() {
    
      // check if there's a hash in the url and
      // dynamically load the page
      if (window.location.hash) {
        $(".nav a").each(function(index, value) {
          if ("#" + getLinkHash($(this).attr("href")) == window.location.hash) {
            $("#content").load($(this).attr("href") + " #content > *");
          }
        })
      }
    
      $(".nav a").click(function() {
        var linkHref = $(this).attr("href"); 
        var pageUrl = linkHref + " #content > *";		
    
        window.location.hash = getLinkHash(linkHref);
    
        $("#content").slideUp("normal",function() {
          $("#content").load(pageUrl,"", function() {
            $("#content").slideDown("normal");			
          });
        });
    
        return false...