+ Post New Thread
Results 1 to 3 of 3
Coding Thread, Selective Javascript in Coding and Web Development; Im using this Javascript in a Moodle Theme, it currently uses images to create rounded corners by inserting some classes. ...
  1. #1

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29

    Selective Javascript

    Im using this Javascript in a Moodle Theme, it currently uses images to create rounded corners by inserting some classes. Moodle is broken down into three sections, left - Middle - right, and this Javascript references them all.

    I want the javascript to only be applied to the Middle section, can anyone see how this might be accomplished by modifying the below script:

    Code:
    <script type="text/javascript" charset="utf-8">
    /* <![CDATA[ */
        var CSSClass={};CSSClass.is=function(e,c){if(typeof e=="string")e=document.getElementById(e);var classes=e.className;if(!classes)return false;if(classes==c)return true;return e.className.search("\\b"+c+"\\b")!=-1;};CSSClass.add=function(e,c){if(typeof e=="string")e=document.getElementById(e);if(CSSClass.is(e,c))return;if(e.className)c=" "+c;e.className+=c;};CSSClass.remove=function(e,c){if(typeof e=="string")e=document.getElementById(e);e.className=e.className.replace(new RegExp("\\b"+c+"\\b\\s*","g"),"");};
        
        var script = {
            corrections: function () {
                if (top.user) {
                    top.document.getElementsByTagName('frameset')[0].rows = "117,30%,0,200";
                }
                
                // check for layouttabel and add layouttable classes to body
                var tagname = 'nolayouttable';
                if (document.getElementById('middle-column')) {
                    var lc = document.getElementById('left-column');
                    var rc = document.getElementById('right-column');
                    if ( lc && rc ) {
                        tagname = 'haslayouttable rightandleftcolumn';
                    } else if (lc) {
                        tagname = 'haslayouttable onlyleftcolumn';
                    } else if (rc) {
                        tagname = 'haslayouttable onlyrightcolumn';
                    } else {
                        tagname = 'haslayouttable onlymiddlecolumn';
                    }
                } else if(document.getElementsByTagName('body')[0].id.substring(0,9)=='calendar-') {
                    tagname='haslayouttable onlyrightcolumn';
                }
                
                function setbodytag (tagname) {
                    var bd = document.getElementsByTagName('body')[0];
                    if (bd) {
                        CSSClass.add(bd, tagname);
                    } else {
                        setTimeout(function() { setbodytag(tagname) }, 30);
                    }
                }
                
                setTimeout(function() { setbodytag(tagname) }, 30);
            },
            
            init: function() {
                script.corrections();
            }
        };
    /* ]]> */
    </script>
    Any ideas?

  2. #2

    Join Date
    Oct 2008
    Location
    Gosport
    Posts
    64
    Thank Post
    1
    Thanked 18 Times in 13 Posts
    Rep Power
    15
    There's some deep stuff happening elsewhere I suspect, but my first attempt would be to replace:
    Code:
                   var lc = document.getElementById('left-column');
                    var rc = document.getElementById('right-column');
                    if ( lc && rc ) {
                        tagname = 'haslayouttable rightandleftcolumn';
                    } else if (lc) {
                        tagname = 'haslayouttable onlyleftcolumn';
                    } else if (rc) {
                        tagname = 'haslayouttable onlyrightcolumn';
                    } else {
                        tagname = 'haslayouttable onlymiddlecolumn';
                    }
    with
    Code:
                    tagname = 'haslayouttable onlymiddlecolumn';
    From the look of it, that's what defines which columns get the special treatment.

    Hello
    :-Dave

  3. #3

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29
    I;ve tried that without sucess, infact if i delete the contents of the file it still applies the style and i have no idea how?

SHARE:
+ Post New Thread

Similar Threads

  1. Javascript - Timed Script
    By danIT in forum Scripts
    Replies: 2
    Last Post: 26th November 2008, 02:04 PM
  2. html/ javascript help
    By strawberry in forum Coding
    Replies: 2
    Last Post: 2nd July 2008, 11:22 AM
  3. Javascript - Change text
    By danIT in forum Scripts
    Replies: 6
    Last Post: 11th February 2008, 03:12 PM
  4. PHP or JavaScript password obfuscator
    By ajbritton in forum Web Development
    Replies: 2
    Last Post: 18th October 2006, 08:30 AM
  5. JavaScript. Yea or Nae?
    By Irazmus in forum General Chat
    Replies: 5
    Last Post: 30th June 2006, 09:35 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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