Results 1 to 5 of 5

Thread: Making a rule stand out from the rest of the rules when I need to

  1. #1
    Join Date
    Jun 2010
    Posts
    40
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Cool Making a rule stand out from the rest of the rules when I need to

    I'll be short

    I want to know how can I make a rule stand out from the rest when I need to, like the phpBB (the official site) forum rules, by clicking a link at the end of a rule and the rule (text) changes color and also gaines a pink-ish background.

    Thank you !

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    It's probably a css styling. Do you have a link to where this can be seen?
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Jun 2010
    Posts
    40
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    I hope it's ok if I do leave a link

    http://www.phpbb.com/rules/

    Click the "#" at any rule you want and you'll see

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Oh, okay. That is being controlled by javascript. The js adds a class that is styled using css to the div.

    The javascript doing it is this

    Code:
    <script type="text/javascript">
    // <![CDATA[
    /**
     * Javascript highlight fragment code
     * By David Lewis (Highway of Life) http://startrekguide.com (c) 2007
     * Inspired by JavaScript highlight code by David Dorward; (http://dorward.me.uk/software/frag/hi.js)
     * copyright 2003 by David Dorward; http://dorward.me.uk
     *
     * Complies with phpBB3 Coding Standards
     * - Correct naming format
     * - Correct bracket placement and spacing
     * Access code removed to simplify script
     * - Refined loops
     * - Removed unused classes
     */
    
    var target_fragment = '';
    
    /* Highlight link target if the visitor arrives at the page with a # */
    function highlight_load()
    {
    	frag_highlight(location.hash.substring(1));
    }
    
    /* Highlight link target from an onclick event after unhighlighting the old one */
    function frag_highlight(frag)
    {
    	var fragment = document.getElementById(frag);
    
    	if (target_fragment.length > 0 && document.getElementById(target_fragment))
    	{
    		document.getElementById(target_fragment).className = '';
    	}
    
    	if (frag.length > 0 && fragment)
    	{
    		target_fragment = frag;
    		fragment.className = 'fragment';
    	}
    }
    
    /* Add onclick events to all <a> with hrefs that include a "#" */
    function onclick_highlight()
    {
    	if (document.getElementsByTagName)
    	{
    		var alinks = document.getElementById('rules').getElementsByTagName('a');
    		for (i = 0; i < alinks.length; i++)
    		{
    			if (alinks[i].getAttribute('href').indexOf('#') >= 0)
    			{
    				var fragment = alinks[i].getAttribute('href').substring(alinks[i].getAttribute('href').indexOf('#') + 1);
    
    				var e_onclick_function = "frag_highlight('" + fragment + "')";
    				var new_function = new Function('e', e_onclick_function);
    				alinks[i].onclick = new_function;
    			}
    		}
    	}
    }
    
    /* Load the script */
    window.onload = function() {
    	highlight_load();
    	onclick_highlight();
    };
    
    // ]]>
    </script>
    Corrections to my coding/thoughts welcome.

  5. The Following User Says Thank You to bluewalrus For This Useful Post:

    Wisdom (10-13-2010)

  6. #5
    Join Date
    Jun 2010
    Posts
    40
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    I'll look into it when I have the time, thank you bluewalrus

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •