Open Source Content Management System

fi.protie.navigation

  1. Usage
  2. Public properties
    1. Navigating the site structure
    2. CSS class availability
    3. CSS styles
  3. Public methods
    1. public css_dropdown_headers()
      1. Notes
    2. public draw()
    3. public static get_node_path()

fi.protie.navigation is a library for drawing most of the cases needed for navigation. It uses class midcom.helper.nav to parse the path.

Usage

Here is an example of how to use fi.protie.navigation:

<?php
// Loads the component for the first time
$_MIDCOM->componentloader->load('fi.protie.navigation');

// Initializes the class
$navigation = new fi_protie_navigation();

// Display only nodes (folders)
$navigation->list_leaves = false;

// Expand the whole site tree instead of the active path
$navigation->follow_all = true;

// Skip 1 level from the beginning of the active path
$navigation->skip_levels = 1;

// Finally draw the navigation
$navigation->draw();
?>

Public properties

Navigating the site structure

  • root_id (integer)
    • ID for the folder to get the navigation. On default the navigation will start from the root folder.
  • skip_levels (integer)
    • The amount of lowest level elements to be skipped. On default no levels are skipped.
  • list_leaves (boolean)
    • Switch to determine if navigation should display leaves or pages. Default is true
  • list_nodes (boolean)
    • List only the leaf elements or pages. Default is false
  • follow_selected (boolean)
    • Switch to determine if navigation should follow node path (on true) or stop on the spot. Default is true.
  • follow_all (boolean)
    • Switch to determine if navigation should follow all the nodes or only the current Default is false.
  • show_only_current (boolean)
    • Switch to determine if navigation should show only the information of the currently selected node. Default is false.
  • list_levels (integer)
    • Numeric depth of the navigation. Set this to prevent any navigation level from going too deep. If no restricting is required, use 0 (default).

CSS class availability

  • url_name_to_class (boolean)
    • Add URL name to list item class name. Default is false.
  • component_name_to_class (boolean)
    • Add component name to list item ul class name. Default is false.

CSS styles

  • css_list_style (string)
    • CSS class for styling the lists. This will be the class of ul element. Default is fi_protie_navigation.
  • css_node (string).
    • CSS class for nodes. Default is node.
  • css_leaf (string)
    • CSS class for leaves. Default is leaf.
  • css_selected (string)
    • CSS class for the elements in node path. All the elements in node path will have this class. Default is selected.
  • css_active (string)
    • CSS class for the current, active node or leaf. There can be only one active element. Default is active.

Public methods

public css_dropdown_headers()

To activate CSS based dropdown menu proper CSS stylesheets should be loaded with the component. Therefore one should call out for method css_dropdown_headers() to include the link. This has to be done before calling for $_MIDCOM->print_head_elements();.

<?php
// Loads the component for the first time
$_MIDCOM->componentloader->load('fi.protie.navigation');

// Initializes the class
$navigation = new fi_protie_navigation();
$navigation->css_dropdown_headers();
?>

This will also set the property follow_all to true.

Notes

By default the CSS file navigation.css will be creating a dropdown list of any unordered list inside #navigation element.

fi.protie.navigation has also a version of Peter Nederlof's csshover.htc, which emulates :hover selector for any HTML element on Microsoft Internet Explorer 6.

This file will not be included automatically to the HTML, but it will be included in the package for web developers.

To use the behavior file include this to the head element.

<!--[if lte IE 6]>
  body
  {
    behavior: url('<?php echo MIDCOM_STATIC_URL; ?>/fi.protie.navigation/csshover.htc');
  }
<![endif]-->

public draw()

Method draw() draws the navigation as requested.

<?php
$navigation->draw();

// Results like this
?>
<ul class="fi_protie_navigation node-504">
  <li class="selected active">
    <a href="http://www.example.net/legacy.html">Legacy</a>
  </li>
  <li>
    <a href="http://www.example.net/scores/">Scores</a>
    <ul class="fi_protie_navigation node-506">
      <li>
        <a href="http://www.example.net/scores/team/e996dcf43bbbf20484011e5c8ade12cc/">Skull cap</a>
      </li>
      <li>
        <a href="http://www.example.net/scores/events/">Events</a>
      </li>
    </ul>
  </li>
</ul>

public static get_node_path()

Static method get_node_path parses all the visible active nodes (folders) and the possible current active leaf (page) and returns an array containing a list of the used IDs.

First item (array key 0) is the root folder of the web site and last will be the currently active page or folder.

<?php
$node_path = fi_protie_navigation::get_node_path();
print_r($node_path);

// Results:
// Array
// (
//     [0] => 504
//     [1] => 508
//     [2] => 509
//     [3] => 509-2572
// )
?>
Designed by Nemein, hosted by Anykey