Jump to content

How to create a guidebook for jcink
   (2 reviews)

Kit the Human
  • This guide is addressed to jcink users but can be used by anyone. Just substitute in the correct terminology.

     

    Essentially, this guide is the creation of a guidebook. On the left of the screen are links. On the right of the screen is a blank space. You click on a link and the appropriate contents appear on the right hand side. You click another link, those previous contents vanish to be replaced by the new appropriate contents.

    Type: Javascript Software: Jcink

Before we get started, this is what we're going to create:

 

before_click.PNG.b4091cb0fe05bb796303c796f19ac9d6.PNG

 

link1.PNG.25201c12439457d5f54d50bab5d55524.PNG

 

link2.PNG.f4d370f95b7320d8c29a155f4bd145f7.PNG

 

You can add as many articles as you like without needing to alter the script.

 

Create Your Articles

  • Go to webpage maker (under skins & templates)
  • Click create new webpage
  • Give it a page title, doesn't matter what, we're not going to see it.
  • Give it a key, something memorable for you because you'll need it later.
  • Set allow key to use board wrappers to No.
  • Your contents need to include valid HTML, so wrap your paragraphs into paragraphs
<p>I'm a paragraph!</p>
  • and wrap the entire contents into a div with the class articles and it must have a unique ID. For IDs, I just use article_1 (number increasing for each new article) but you might prefer something more memorable. You will need to remember what it is.
<div id="article_1" class='articles'>
  <p>Yay! First paragraph!</p>
  <p>I'm a middle paragraph</p>
  <p>I'm another paragraph!</p>
</div>
  • Rinse and repeat until you have the articles you want. Or just make two for the purposes of this tutorial.

 

Create the Container

The container is what will house the articles, it will also include our magical menu.

  • Back in webpage maker (under skins & templates)
  • Click Create a New Webpage
  • Give it a page title, this one matters because it will appear in your nav strip.  (ie. My Community -> lore)
  • Set allow key to use board wrappers to Yes.
  • Paste in the following code:
<div id="welcome_articles">
  <h1>Lore</h1>
  Welcome to our lore. Here you can bla bla bla. Click the links on the left to read the relevant articles.
</div>
<div id="article_container">
  <aside>
    <ul class="article_container_list">
      <h3>Lore Index</h3>
      <li><a class="container_links" href="#" data-showdiv="article_1">Link 1</a></li>
      <li><a class="container_links" href="#" data-showdiv="article_2">Link 2</a></li>
    </ul>
  </aside>
  <div class="article_content">
    <% article_1 %>
    <% article_2 %>
  </div>
</div>
    
    <script>
$(".container_links").click(function(){
    $(".articles:visible").hide();
    $("#"+$(this).attr("data-showdiv")).show();
});
      
$('.container_links').click( function(){
    if ( $(this).hasClass('active') ) {
        $(this).removeClass('active');
    } else {
        $('.container_links.active').removeClass('active');
        $(this).addClass('active');    
    }
});
      // following is purely to prevent page jump when user clicks on link
      $('a.container_links').click(function(e){
        e.preventDefault();
      });
</script>

 where <% article_1 %> and <% article_2 %> are the keys to the articles you created earlier.

  • The javascript is already included and assuming that you don't replace your class names, it doesn't need to be altered.
  • Besides the aforementioned keys, the most important part of the code for you is
    <li><a class="container_links" href="#" data-showdiv="article_1">Link 1</a></li>
    the data-showdiv attribute needs to be the same as one of the articles you created earlier. So, say you created an article about species and you gave it an id of species. Your link should look like this
    <li><a class="container_links" href="#" data-showdiv="species">Species</a></li>

     

  • Once you have added the links and keys, save it. If you visit it now, you'll see that everything is displayed but clicking the link will make everything vanish except the for corresponding article. You'll also notice that the list sits on top of everything else. Time to hit the style sheets!

 

Stylesheet

  • Go to your stylesheets and paste in the following
#welcome_articles {
margin-bottom: 10px;
padding: 5px;
border-bottom: 1px solid rgba(0,0,0, .1);
}

#article_container { display: flex }

#article_container .article_content {
flex-grow: 2;
padding: 0 20px 20px;
border-left: 1px solid rgba(0,0,0, .1)
}

#article_container aside {
padding: 10px;
min-width: 15%
}

#article_container .articles { display: none }

ul.article_container_list {
list-style-type: none;
margin: 0;
padding: 0
}

ul.article_container_list li {
display: block;
margin: 1px;
}

a.container_links { 
display: block;
border-bottom: 1px solid rgba(0,0,0, .1);
padding: 5px 
}

a.container_links.active { padding-left: 15px }

ul.article_container_list h3 { margin-top: 0 }

The most important bits are

  • #article_container { display: flex } this makes the aside and div.article_content sit next to each other. Sometimes however, the aside can look a little bit claustrophobic, so I add 
    #article_container aside {
      padding: 10px;
      min-width: 15%
    }

     

  • To ensure that the div.article_content grows to fill the entire space left over, I add 
    #article_container .article_content {
      flex-grow: 2
    }
  • To hide all of the articles by default, I add 
    #article_container .articles { display: none }
    if you are having problems with the script after adding this code, move #article_container .articles { display: none } to your guidebook page so that it sits above the scripts: ie
    <style>
      #article_container .articles { display: none }
    </style>
    
    <script>
    $(".container_links").click(function(){
        $(".articles:visible").hide();
        $("#"+$(this).attr("data-showdiv")).show();
    });
      
    $('.container_links').click( function(){
        if ( $(this).hasClass('active') ) {
            $(this).removeClass('active');
        } else {
            $('.container_links.active').removeClass('active');
            $(this).addClass('active');    
        }
    });
      
      // following is purely to prevent page jump when user clicks on link
      $('a.container_links').click(function(e){
        e.preventDefault();
      });
    </script>

     

  • Finally, it is useful if the displayed article's link is different from the others. To do this I add 
    a.container_links.active { padding-left: 15px }

     

Responsiveness

  • Make sure your head (in the global wrappers) includes the following
    <meta name="viewport" content="width=device-width, initial-scale=1">

     

  • This will ensure the zoom is at 100%. If you have any fixed width elements in your header or footer you may find that that user now needs to scroll horizontally. I recommend fixing that so that those elements no longer include a fixed width. I've addressed the default fixed widths in the following code
    @media screen and (max-width: 979px) {
      body { font-size: 1rem }
      #wrapper { width: calc(100% - 20px); margin: 0 auto; }
      #article_container { display: block; }
      ul.article_container_list { text-align: center }
      #userlinks { width: 90% }
      ul.article_container_list li { margin-bottom: 10px }
      ul.article_container_list li:last-child { margin-bottom: 0 }
    }

     

  • The important part (applicable to the guidebook) is as follows
  • #article_container { display: block; } now the aside sits above the content.
  • ul.article_container_list { text-align: center } we center the links (note that they automatically expand to fill the available space because we made the links into blocks earlier.)
  • ul.article_container_list li { margin-bottom: 10px } we make the links easier to tap for a chunky finger.
  • ul.article_container_list li:last-child { margin-bottom: 0 } but the last list item doesn't need a bottom margin, so we get rid of it.

The end result for mobiles becomes this:

mobile.PNG.888cdc990d65dfc8752d8360258b42f2.PNG

 

Just want some copy and paste?

 

<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<div id="welcome_articles"><h1>Lore</h1>
Welcome to our lore. Here you can bla bla bla. Click the links on the left to read the relevant articles.
</div>
<div id="article_container">
<aside>
<ul class="article_container_list">
<h3>Lore Index</h3>
<li><a class="container_links" href="#" data-showdiv="article_1">Link 1</a></li>
<li><a class="container_links" href="#" data-showdiv="article_2">Link 2</a></li>
</ul>
</aside>
<div class="article_content">
<% article_1 %>
<% article_2 %>
</div>
</div>

<style>
#welcome_articles {
margin-bottom: 10px;
padding: 5px;
border-bottom: 1px solid rgba(0,0,0, .1);
}


#article_container { display: flex }

#article_container .article_content {
flex-grow: 2;
padding: 0 20px 20px;
border-left: 1px solid rgba(0,0,0, .1)
}

#article_container aside {
padding: 10px;
min-width: 15%
}

#article_container .articles { display: none }

ul.article_container_list {
list-style-type: none;
margin: 0;
padding: 0
}

ul.article_container_list li {
display: block;
margin: 1px;
}

a.container_links { 
display: block;
border-bottom: 1px solid rgba(0,0,0, .1);
padding: 5px 
}

a.container_links.active { padding-left: 15px }

ul.article_container_list h3 { margin-top: 0 }

@media screen and (max-width: 979px) {
body { font-size: 1rem }
#wrapper { width: calc(100% - 20px); margin: 0 auto; }
#article_container { display: block; }
ul.article_container_list { text-align: center }
#userlinks { width: 90% }
ul.article_container_list li { margin-bottom: 10px }
ul.article_container_list li:last-child { margin-bottom: 0 }
}
</style>

<script>
$(".container_links").click(function(){
    $(".articles:visible").hide();
    $("#"+$(this).attr("data-showdiv")).show();
});
  
$('.container_links').click( function(){
    if ( $(this).hasClass('active') ) {
        $(this).removeClass('active');
    } else {
        $('.container_links.active').removeClass('active');
        $(this).addClass('active');    
    }
});
  
  // following is purely to prevent page jump when user clicks on link
  $('a.container_links').click(function(e){
    e.preventDefault();
  });
</script>

I hope that someone finds this useful! As already noted, any forum software can utilise this guide, the actual magic is the script and that is not software specific.


  • I read this! 1
  • Love 1
  • Thank you 1
  • Preach it! 1



User Feedback

Create an account or sign in to leave a review

You need to be a member in order to leave a review

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Ash

· Edited by Ash

  

If you want the first link content to show on page load, add an active element to it -- i.e.

<li><a class="container_links" href="#" data-showdiv="article_1 active">Link 1</a></li>

and slap this into the script at the top, right under the <script> tag:

 

$(document).ready(function(){ if ($(".container_links").hasClass('active')){ $("#"+$(".container_links").attr("data-showdiv")).show(); }; });

 

I don't know if this was the best or easiest or most elegant solution, but it worked, so I called it good!

Share this review


Link to review
Hades101

  

This is incredibly detailed and easy to follow. Thank you! 

Share this review


Link to review

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use, Guidelines and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.