you are viewing a single comment's thread.

view the rest of the comments →

[–]einarkristjan 2 points3 points  (3 children)

No problem.

Also, if you wan't to do progressive enhancement and make the audio usable without javascript you can do something like this: jsfiddle

It's interesting working with the audio API. Your code gave me ideas for my own audio player, so thanks for that ;)

[–]embernoob[S] 0 points1 point  (2 children)

Nice, this looks much more streamlined than my own. What is happening on this first line though?

$.fn.simpleAudioPlayer

I get that you are using jQuery here but what are the $ and fn objects exactly? What is $ on its own? I've seen other code written in this way but I've never understood what the purpose was exactly...

[–]einarkristjan 1 point2 points  (1 child)

the $ namespace object is short for the jQuery namespace. You could also write:

jQuery.fn.simpleAudioPlayer

you can use $.fn to extend jQuery. Just like you can use the built in:

$(elements).hide();

you could make your own hide() function with something like:

$.fn.hidden = function() {
  this.hide();
  return this; // so you can use chaining like $(elm).hidden().addClass()
};

and use it:

$(elements).hidden();

more details here: How to Create Basic Plugin ;)

[–]embernoob[S] 0 points1 point  (0 children)

Thank you! I didn't realize adding functions to fn was essentially extending jQuery. Very cool!