Postings

You can freely browse the forum and post in the community forum.
However, you need a valid license to write posts for support (own a valid commercial software license or have purchased a support membership).

Posts only show once reviewed. This is mainly preventive to keep spam away. Thank you for your understanding!

audio on-click event not working

More
IP: 118.172.99.103 13 years 7 months ago #1964 by mamboze
Hi all,
As part of an English education site, I'm trying to get an on-click event to play an audio file. I've got it to work in a static webpage, but I've not been able to get it to run in joomla 2.5.
I've installed jquery easy just to make things easier for myself :)
this is the relevant html
Code:
... <div> <p id="one"> this is the first paragraph</p> .... <p id="four"> this is the fourth paragraph</p> </div>
and this the jquery code
Code:
jQuery.noConflict(); jQuery(document).ready(function() { jQuery("p").click(function (event) { var element = jQuery(this); var elementID = event.target.id; var oggVar = (elementID +".ogg"); var audioElement = document.createElement('audio'); audioElement.setAttribute('src', oggVar); audioElement.load(); audioElement.addEventListener("load", function() { audioElement.play(); }, true); audioElement.play(); }); });
The audio files, one.ogg, two.ogg etc, are located in the joomla audio folder and the jquery code in the template js folder.
I've enabled jquery in the jquery easy config page in joomla. I'm lost as to why the static website works but the joomla setup doesn't.
Any help would be much appreciated.
More
IP: 207.229.172.231 13 years 7 months ago #1965 by admin
Hello,
I am almost certain that it has to do with the location of your audio files. Nothing in this code tells where to find them. For the sake of testing, I would suggest you leave the audio files with your script file.

Olivier.
More
IP: 118.172.99.103 13 years 7 months ago #1966 by mamboze
Thank you for your help.
I've placed the audio files, one.ogg thru four.ogg in the template js folder but the click code is still not working. I also placed a copy of jsquery.js in the js folder but this did not help either (is this necessary given that jquery is enabled in jquery easy?).
Here is the actual html code generated by joomla
Code:
<p id="one" style="text-align: left; font-size: 10pt;">this is paragraph one</p> <p id="two" style="text-align: left; font-size: 10pt;">this is paragraph one</p> ....
More
IP: 207.229.172.231 13 years 7 months ago #1969 by admin
The forum is moderated so the posts won't show until they are 'filtered' for spam (see the 'rules' tab for more explanations).

It is rather difficult to help you without actually seeing the whole source code and trying it out. Do you have a URL I can check out?

The jQuery Easy plugin loads jQuery so you should not have to do it manually.
I am not really familiar with loading audio files through jQuery.
Where is your code actually located? Did you include it into your template manually or through a module, or a plugin?

Olivier.
The following user(s) said Thank You: mamboze
More
IP: 118.172.99.103 13 years 7 months ago #1970 by mamboze
Hi Olivier,
Yes I do have a URL www.english2theworld.com
The jquery file is slightly different to the one I posted yesterday, as it includes, additionally, some hover functionality, nothing complex tho that's for sure :). Here it is
Code:
jQuery.noConflict(); jQuery(document).ready(function() { jQuery("p").hover( function() { jQuery(this).css({"color": "red", "font-weight" : ""}); }, function() { jQuery(this).css({"color": "black", "font-weight" : ""}); } ); jQuery("p").click(function (event) { var element = jQuery(this); var elementID = event.target.id; var oggVar = (elementID +".ogg"); var audioElement = document.createElement('audio'); audioElement.setAttribute('src', oggVar); audioElement.load(); audioElement.addEventListener("load", function() { audioElement.play(); }, true); audioElement.play(); }); });
The 4 sample audio files have been placed at /audio, and in the js and javascript folders in the beez_2 template area.
More
IP: 118.172.99.103 13 years 7 months ago #1972 by mamboze
I forgot to mention that I included the jquery code into joomla manually.

I think audio is a pretty underdeveloped aspect of web site technology. From what I can gather from the internet, Html5 audio is still maturing, let's hope it grows up quickly :)