Skip to content

Commit

Permalink
Update to 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
IonDen committed Aug 1, 2014
1 parent a935158 commit 3340d5d
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 14 deletions.
7 changes: 5 additions & 2 deletions ion-sound.jquery.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ion-sound",
"version": "2.0.0",
"version": "2.0.1",
"title": "Ion.Sound",
"description": "JavaScript plugin for playing sounds on user actions and events. Today websites are full of events (new mail, new chat-message, content update etc.). Often it is not enough to indicate this events only visually to get user attention. You need sounds! This library, made for playing small sounds, will help you with this task.",
"keywords": [
Expand Down Expand Up @@ -29,5 +29,8 @@
"homepage": "https://github.com/IonDen/ion.sound",
"docs": "https://github.com/IonDen/ion.sound/blob/master/readme.md",
"demo": "http://ionden.com/a/plugins/ion.sound/en.html",
"download": "http://ionden.com/a/plugins/ion.sound/ion.sound-2.0.0.zip"
"download": "http://ionden.com/a/plugins/ion.sound/ion.sound-2.0.1.zip",
"dependencies": {
"jquery": ">=1.3"
}
}
4 changes: 2 additions & 2 deletions js/ion.sound.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Ion.Sound
* version 2.0.0 Build 31
* version 2.0.1 Build 32
* © 2014 Denis Ineshin | IonDen.com
*
* Project page: http://ionden.com/a/plugins/ion.sound/en.html
Expand Down Expand Up @@ -186,7 +186,7 @@ var ion = ion || {};
}
};

ion.sound.version = "2.0.0";
ion.sound.version = "2.0.1";

ion.sound.play = function (name, options) {
if (sounds[name]) {
Expand Down
6 changes: 3 additions & 3 deletions js/ion.sound.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

227 changes: 227 additions & 0 deletions js/jquery.ion.sound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
/**
* jQuery.Ion.Sound
* version 2.0.1 Build 32
* © 2014 Denis Ineshin | IonDen.com
*
* Project page: http://ionden.com/a/plugins/$.ionSound/en.html
* GitHub page: https://github.com/IonDen/$.ionSound
*
* Released under MIT licence:
* http://ionden.com/a/plugins/licence-en.html
*/

(function ($) {

var warn = function (text) {
if (text && console) {
if (console.warn && typeof console.warn === "function") {
console.warn(text);
} else if (console.log && typeof console.log === "function") {
console.log(text);
}
}
};

if ($.ionSound) {
warn("$.ionSound already exists!");
return;
}

if (typeof Audio !== "function" && typeof Audio !== "object") {
var func = function () {
warn("HTML5 Audio is not supported in this browser");
};
$.ionSound = function () {};
$.ionSound.play = func;
$.ionSound.stop = func;
$.ionSound.destroy = func;
func();
return;
}



var settings = {},
sounds = {},
sounds_num,
can_play_mp3,
ext,
i;



var Sound = function (options) {
this.name = options.name;
this.volume = settings.volume || 0.5;
this.preload = settings.preload ? "auto" : "none";
this.loop = false;
this.sound = null;

if ("volume" in options) {
this.volume = +options.volume;
}

if ("preload" in options) {
this.preload = options.preload ? "auto" : "none"
}
};

Sound.prototype = {
init: function () {
this.sound = new Audio();
this.sound.src = settings.path + this.name + ext;
this.sound.load();
this.sound.preload = this.preload;
this.sound.volume = this.volume;

this.sound.addEventListener("ended", this._ended.bind(this), false);
},

play: function (obj) {
if (!obj) {
obj = {};
}

if (obj.volume) {
this.volume = +obj.volume;
this.sound.volume = this.volume;
}

if (obj.loop) {
this._playLoop(obj.loop);
} else {
this.loop = false;
this._play();
}
},

_play: function () {
try {
this.sound.currentTime = 0;
} catch (e) {}

this.sound.play();
},

_playLoop: function (loop) {
if (typeof loop === "boolean") {
// FF 3.6 and iOS,
// sound.loop = true not supported or buggy
this.loop = 9999999;
this._play();
} else if (typeof loop === "number") {
this.loop = loop - 1;
this._play();
}
},

_ended: function () {
if (this.loop > 0) {
this.loop -= 1;
this._play();
}
},

stop: function () {
this.loop = false;
this.sound.pause();

try {
this.sound.currentTime = 0;
} catch (e) {}
},

destroy: function () {
this.stop();
this.sound.removeEventListener("ended", this._ended.bind(this), false);
this.sound.src = "";
this.sound = null;
}
};



var checkSupport = function () {
var sound_item = new Audio();
can_play_mp3 = sound_item.canPlayType("audio/mpeg");

switch (can_play_mp3) {
case "probably":
case "maybe":
ext = ".mp3";
break;
default:
ext = ".ogg";
break;
}

sound_item = null;
};

var createSound = function (obj) {
sounds[obj.name] = new Sound(obj);
sounds[obj.name].init();
};

$.ionSound = function (options) {
settings = JSON.parse(JSON.stringify(options));
settings.path = settings.path || "";
settings.volume = settings.volume || 0.5;
settings.preload = settings.preload || false;
settings.mix = settings.mix || true;

sounds_num = settings.sounds.length;

if (!sounds_num) {
warn("No sound-files provided!");
return;
}

checkSupport();

for (i = 0; i < sounds_num; i++) {
createSound(settings.sounds[i]);
}
};

$.ionSound.version = "2.0.1";

$.ionSound.play = function (name, options) {
if (sounds[name]) {
sounds[name].play(options);
}
};

$.ionSound.stop = function (name) {
if (name && sounds[name]) {
sounds[name].stop();
} else {
for (i in sounds) {
if (!sounds.hasOwnProperty(i)) {
continue;
}
if (sounds[i]) {
sounds[i].stop();
}
}
}
};

$.ionSound.destroy = function (name) {
if (name && sounds[name]) {
sounds[name].destroy();
sounds[name] = null;
} else {
for (i in sounds) {
if (!sounds.hasOwnProperty(i)) {
continue;
}
if (sounds[i]) {
sounds[i].destroy();
sounds[i] = null;
}
}
}
};

} (jQuery));
4 changes: 4 additions & 0 deletions js/jquery.ion.sound.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Ion.Sound 2.0.0
# Ion.Sound 2.0.1

> English description | <a href="readme.ru.md">Описание на русском</a>
JavaScript plugin for playing sounds on user actions and page events.
* <a href="http://ionden.com/a/plugins/ion.sound/en.html">Project page and demos</a>
* <a href="http://ionden.com/a/plugins/ion.sound/ion.sound-2.0.0.zip">Download ion.sound-2.0.0.zip</a>
* <a href="http://ionden.com/a/plugins/ion.sound/ion.sound-2.0.1.zip">Download ion.sound-2.0.1.zip</a>

***

Expand Down Expand Up @@ -33,11 +33,12 @@ Today websites are full of events (new mail, new chat-message, content update et


## Dependencies
* No dependencies, jQuery dependency was dropped since 2.0
* 2 versions of plugin: jQuery and standalone


## Usage
Import this libraries:
* jquery.js - optional
* ion.sound.min.js

Prepare sound-files (25 sounds are included) and put them in some folder (eg. "sounds"):
Expand Down Expand Up @@ -175,7 +176,13 @@ ion.sound.destroy();
```


## jQuery and non-jQuery plugin differences
* jQuery method call: <code>$.ionSound.method(...);</code>
* non-jQuery method call: <code>ion.sound.method(...);</code>


## Update history
* 2.0.1: August 01, 2014 - 2 versions of plugin, jQuery and non-jQuery
* 2.0.0: June 31, 2014 - dropped jQuery dependency, new API, loop sounds feature
* 1.3.0: November 30, 2013 - new methods "stop" and "kill". Ability to reset sound volume
* October 13, 2013 - now you can set individual volume for any sound. Improved test environment
Expand Down
14 changes: 10 additions & 4 deletions readme.ru.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Ion.Sound 2.0.0
# Ion.Sound 2.0.1

> <a href="readme.md">English description</a> | Описание на русском
JavaScript-плагин для воспроизведения звуков
* <a href="http://ionden.com/a/plugins/ion.sound/index.html">Сайт проекта и демо</a>
* <a href="http://ionden.com/a/plugins/ion.sound/ion.sound-2.0.0.zip">Скачать ion.sound-2.0.0.zip</a>
* <a href="http://ionden.com/a/plugins/ion.sound/ion.sound-2.0.1.zip">Скачать ion.sound-2.0.1.zip</a>

***

Expand Down Expand Up @@ -33,11 +33,12 @@ JavaScript-плагин для воспроизведения звуков


## Зависимости
* Никаких. Зависимость от jQuery была убрана в версии 2.0
* 2 версии плагина, с зависимостью от jQuery и без


## Подключение
Подключаем библиотеку:
Подключаем библиотеки:
* jquery.js - опционально
* ion.sound.min.js

Готовим звуковые файлы (15 звуков включены в поставку) и складываем их в какую-либо папку (например "sounds"):
Expand Down Expand Up @@ -173,8 +174,13 @@ ion.sound.destroy();
```


## Отличия jQuery-версии плагина от обычной
* jQuery вызов метода: <code>$.ionSound.method(...);</code>
* не-jQuery вызов метода: <code>ion.sound.method(...);</code>


## История обновлений
* 2.0.1: 01 августа 2014 - 2 версии плагина, с jQuery-зависимостью и без
* 2.0.0: 31 июня 2014 - убрана зависимость от jQuery. Новое API. Возможность повторного воспроизведения звуков
* 1.3.0: 30 ноября 2013 - новые методы "stop" и "kill". Возможность изменять громкость звука при каждом запуске
* 13 октября 2013 - добавлена возмоность устанавливать индивидуальную громкость для каждого звука. Улучшено тестовое окружение
Expand Down

0 comments on commit 3340d5d

Please sign in to comment.