Maddening scope issue

56 views Asked by At

Little things like this drive me crazy!

Working with a typical Joomla website and all it's complexity.

Start with a functioning website. Edit a particular javascript file of a template to add a simple function:

   function socialShare(title, url) {
    alert("goop!");
  }

I reference it in a link:

<a class="icon-facebook" 
     onclick="socialShare('blog-entries', '11-blog-article/15-oppressive-tyranny&title=Triumph Over Tyranny')"> </a>

The function is included along with 37 other external scripts in a file at the end of the page, included within the body element like this:

<script src="/bts/templates/vg_progressive/js/articleRev.js"></script>

I inserted the sociaShare function definition as the first thing in the include articleRev.js file. The list of external scripts include core functionality like bootstrap, jquery etc etc.

I can see the function in the included script file with firebug's debugger & the include line in the page source near the bottom. BUT IT DOESN'T GET EXECUTED!! If I include the exact same function within a element anywhere on the page it works just fine. For some reason the instance in the external script file is not within the scope of that page / article, tho I can see it clearly in the page source.

I can also put the function within script tags as the last thing inside the body and it is within scope and works fine. I discovered I can define the function in a different included javascript file that is found in the very same folder and it also works fine.

Like I said, things like this make me pull my hair out! What can cause this behavior? How can I narrow it down?

As per Ed Cotrel, here are 2 files which [may] be helpful, tho I don't think so. Rename articleRev.txt to .js and pageSrc.txt to pageSrc.html. As for your comments Ed, I believe I've stated the issue as clearly as I can.

The desired behavior is to see an alert box when the anchor tag is clicked. Simple. The anchor tag displays a social media icon based on one of the class definitions. The onclick attribute should call the javascript function socialShare and display an alert box containing a text message with the 2 parameters. The alert never shows up. If the socialSharing function is moved to the main.js script file located in the same folder and included the same way in the same place in the page flow it works. Is that clearer?

1) http://thecomingbitsharesrevolution.website/media/articleRev.txt 2) http://thecomingbitsharesrevolution.website/media/pageSrc.txt

0

There are 0 answers