Permalink
Browse files

Toasty

  • Loading branch information...
1 parent dd6ecb8 commit 4a29a3dc0bea6b08534ff69c30a55a6195551621 @enriquez committed Apr 27, 2009
Showing with 93 additions and 0 deletions.
  1. +1 −0 index.html
  2. +1 −0 javascripts/application.js
  3. +91 −0 javascripts/jquery.sound.js
View
@@ -8,6 +8,7 @@
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.7.0/build/reset/reset-min.css">
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" title="no title" charset="utf-8"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
+ <script src="javascripts/jquery.sound.js" type="text/javascript" charset="utf-8"></script>
<script src="javascripts/application.js" type="text/javascript" charset="utf-8"></script>
</head>
@@ -80,6 +80,7 @@ $(document).ready(function(){
// Toasty!
$("#mre").mouseover(function(){
+ $.sound.play('http://www.leedberg.com/MotaroFTP/sounds/toasty.wav');
$("#me").animate({left:0}, 100);
}).mouseleave(function(){
$("#me").animate({left:-292}, 100);
@@ -0,0 +1,91 @@
+/**
+ * jQuery sound plugin (no flash)
+ *
+ * port of script.aculo.us' sound.js (http://script.aculo.us), based on code by Jules Gravinese (http://www.webveteran.com/)
+ *
+ * Copyright (c) 2007 Jörn Zaefferer (http://bassistance.de)
+ *
+ * Licensed under the MIT license:
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * $Id: jquery.sound.js 5854 2008-10-04 10:22:25Z joern.zaefferer $
+ */
+
+/**
+ * API Documentation
+ *
+ * // play a sound from the url
+ * $.sound.play(url)
+ *
+ * // play a sound from the url, on a track, stopping any sound already running on that track
+ * $.sound.play(url, {
+ * track: "track1"
+ * });
+ *
+ * // increase the timeout to four seconds before removing the sound object from the dom for longer sounds
+ * $.sound.play(url, {
+ * timeout: 4000
+ * });
+ *
+ * // stop a sound by removing the element returned by play
+ * var sound = $.sound.play(url);
+ * sound.remove();
+ *
+ * // disable playing sounds
+ * $.sound.enabled = false;
+ *
+ * // enable playing sounds
+ * $.sound.enabled = true
+ */
+
+(function($) {
+
+$.sound = {
+ tracks: {},
+ enabled: true,
+ template: function(src) {
+ // todo: move bgsound element and browser sniffing in here
+ // todo: test wmv on windows: Builder.node('embed', {type:'application/x-mplayer2', pluginspage:'http://microsoft.com/windows/mediaplayer/en/download/', id:'mediaPlayer', name:'mediaPlayer', displaysize:'4', autosize:'-1', bgcolor:'darkblue', showcontrols:'false', showtracker:'-1', showdisplay:'0', showstatusbar:'-1', videoborder3d:'-1', width:'0', height:'0', src:audioFile, autostart:'true', designtimesp:'5311', loop:'false'});
+ // is_win = (agt.indexOf("windows") != -1);
+ return '<embed style="height:0" loop="false" src="' + src + '" autostart="true" hidden="true"/>';
+ },
+ play: function(url, options){
+ if (!this.enabled)
+ return;
+ options = $.extend({
+ url: url,
+ timeout: 2000
+ }, options);
+
+ if (options.track) {
+ if (this.tracks[options.track]) {
+ var current = this.tracks[options.track];
+ // TODO check when Stop is avaiable, certainly not on a jQuery object
+ current[0].Stop && current[0].Stop();
+ current.remove();
+ }
+ }
+
+ var element = $.browser.msie
+ ? $('<bgsound/>').attr({
+ src: options.url,
+ loop: 1,
+ autostart: true
+ })
+ : $(this.template(options.url));
+
+ element.appendTo("body");
+
+ if (options.track) {
+ this.tracks[options.track] = element;
+ }
+
+ setTimeout(function() {
+ element.remove();
+ }, options.timeout)
+
+ return element;
+ }
+};
+
+})(jQuery);

0 comments on commit 4a29a3d

Please sign in to comment.