From 525243bd8d3990d48477e1d69cb378688332dead Mon Sep 17 00:00:00 2001 From: "Fedor A. Fetisov" Date: Mon, 19 May 2014 19:34:23 +0400 Subject: [PATCH 1/3] Improve sound playback (see Issue #4) --- .../chat/models/sound_managers/chat.js | 2 +- src/mibew/js/compiled/chat_app.js | 2 +- src/mibew/js/compiled/default/utils.js | 4 +- src/mibew/js/compiled/default_app.js | 4 +- src/mibew/js/compiled/soundcheck.js | 2 +- .../collection_views/threads_collection.js | 4 +- src/mibew/js/compiled/users_app.js | 4 +- .../source/chat/models/sound_managers/chat.js | 2 +- src/mibew/js/source/default/utils.js | 26 +++-- src/mibew/js/source/soundcheck.js | 4 +- .../collection_views/threads_collection.js | 2 +- src/mibew/sounds/new_message.mp3 | Bin 0 -> 10030 bytes src/mibew/sounds/new_user.mp3 | Bin 0 -> 10448 bytes .../dialogs/default/js/compiled/scripts.js | 4 +- .../client_side/templates.js | 109 +++++++++--------- .../client_side/default_app.tpl.js | 8 +- .../client_side/users_app.tpl.js | 56 ++++----- 17 files changed, 122 insertions(+), 111 deletions(-) create mode 100644 src/mibew/sounds/new_message.mp3 create mode 100644 src/mibew/sounds/new_user.mp3 diff --git a/src/mibew/js/compiled/chat/models/sound_managers/chat.js b/src/mibew/js/compiled/chat/models/sound_managers/chat.js index a1c22564..88b90a35 100644 --- a/src/mibew/js/compiled/chat/models/sound_managers/chat.js +++ b/src/mibew/js/compiled/chat/models/sound_managers/chat.js @@ -6,4 +6,4 @@ http://www.apache.org/licenses/LICENSE-2.0 */ (function(a,c){a.Models.ChatSoundManager=a.Models.BaseSoundManager.extend({defaults:c.extend({},a.Models.BaseSoundManager.prototype.defaults,{skipNextMessageSound:!1}),initialize:function(){var b=a.Objects,c=this;b.Collections.messages.on("multiple:add",this.playNewMessageSound,this);b.Models.messageForm.on("before:post",function(){c.set({skipNextMessageSound:!0})})},playNewMessageSound:function(){if(!this.get("skipNextMessageSound")){var b=a.Objects.Models.page.get("mibewRoot");"undefined"!==typeof b&& -this.play(b+"/sounds/new_message.wav")}this.set({skipNextMessageSound:!1})}})})(Mibew,_); +this.play(b+"/sounds/new_message")}this.set({skipNextMessageSound:!1})}})})(Mibew,_); diff --git a/src/mibew/js/compiled/chat_app.js b/src/mibew/js/compiled/chat_app.js index aa0fea56..fa6974ec 100644 --- a/src/mibew/js/compiled/chat_app.js +++ b/src/mibew/js/compiled/chat_app.js @@ -126,7 +126,7 @@ a):a.trigger("submit:error",a,{code:b.errorCode,message:b.errorMessage||""})},!0 http://www.apache.org/licenses/LICENSE-2.0 */ (function(a,c){a.Models.ChatSoundManager=a.Models.BaseSoundManager.extend({defaults:c.extend({},a.Models.BaseSoundManager.prototype.defaults,{skipNextMessageSound:!1}),initialize:function(){var b=a.Objects,c=this;b.Collections.messages.on("multiple:add",this.playNewMessageSound,this);b.Models.messageForm.on("before:post",function(){c.set({skipNextMessageSound:!0})})},playNewMessageSound:function(){if(!this.get("skipNextMessageSound")){var b=a.Objects.Models.page.get("mibewRoot");"undefined"!==typeof b&& -this.play(b+"/sounds/new_message.wav")}this.set({skipNextMessageSound:!1})}})})(Mibew,_); +this.play(b+"/sounds/new_message")}this.set({skipNextMessageSound:!1})}})})(Mibew,_); /* Copyright 2005-2014 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License"). diff --git a/src/mibew/js/compiled/default/utils.js b/src/mibew/js/compiled/default/utils.js index e1523270..e20e80fc 100644 --- a/src/mibew/js/compiled/default/utils.js +++ b/src/mibew/js/compiled/default/utils.js @@ -5,5 +5,5 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -(function(b,c){b.Utils={};b.Utils.toUpperCaseFirst=function(a){return"string"!=typeof a?!1:""===a?a:a.substring(0,1).toUpperCase()+a.substring(1)};b.Utils.toDashFormat=function(a){if("string"!=typeof a)return!1;a=a.match(/((?:[A-Z]?[a-z]+)|(?:[A-Z][a-z]*))/g);for(var b=0;b()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(a)}; -b.Utils.playSound=function(a){c("body").append('')}})(Mibew,$); +(function(c,d){c.Utils={};c.Utils.toUpperCaseFirst=function(a){return"string"!=typeof a?!1:""===a?a:a.substring(0,1).toUpperCase()+a.substring(1)};c.Utils.toDashFormat=function(a){if("string"!=typeof a)return!1;a=a.match(/((?:[A-Z]?[a-z]+)|(?:[A-Z][a-z]*))/g);for(var b=0;b()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(a)}; +c.Utils.playSound=function(a){var b=d('audio[data-file="'+a+'"]');0",{autoplay:!0,style:"display: none"}).append(''),d("body").append(b),d.isFunction(b.get(0).play)&&b.attr("data-file",a))}})(Mibew,$); diff --git a/src/mibew/js/compiled/default_app.js b/src/mibew/js/compiled/default_app.js index cf3f06d8..0b5861c2 100644 --- a/src/mibew/js/compiled/default_app.js +++ b/src/mibew/js/compiled/default_app.js @@ -41,8 +41,8 @@ else try{this.sendRequests(this.buffer),this.buffer=[]}catch(c){this.options.onU You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -(function(b,c){b.Utils={};b.Utils.toUpperCaseFirst=function(a){return"string"!=typeof a?!1:""===a?a:a.substring(0,1).toUpperCase()+a.substring(1)};b.Utils.toDashFormat=function(a){if("string"!=typeof a)return!1;a=a.match(/((?:[A-Z]?[a-z]+)|(?:[A-Z][a-z]*))/g);for(var b=0;b()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(a)}; -b.Utils.playSound=function(a){c("body").append('')}})(Mibew,$); +(function(c,d){c.Utils={};c.Utils.toUpperCaseFirst=function(a){return"string"!=typeof a?!1:""===a?a:a.substring(0,1).toUpperCase()+a.substring(1)};c.Utils.toDashFormat=function(a){if("string"!=typeof a)return!1;a=a.match(/((?:[A-Z]?[a-z]+)|(?:[A-Z][a-z]*))/g);for(var b=0;b()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(a)}; +c.Utils.playSound=function(a){var b=d('audio[data-file="'+a+'"]');0",{autoplay:!0,style:"display: none"}).append(''),d("body").append(b),d.isFunction(b.get(0).play)&&b.attr("data-file",a))}})(Mibew,$); /* Copyright 2005-2014 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License"). diff --git a/src/mibew/js/compiled/soundcheck.js b/src/mibew/js/compiled/soundcheck.js index 8f962abd..9a2076d5 100644 --- a/src/mibew/js/compiled/soundcheck.js +++ b/src/mibew/js/compiled/soundcheck.js @@ -5,4 +5,4 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -(function(b,a){a(document).ready(function(){a("#check-nv").click(function(){b.Utils.playSound("../sounds/new_user.wav")});a("#check-nm").click(function(){b.Utils.playSound("../sounds/new_message.wav")})})})(Mibew,$); +(function(b,a){a(document).ready(function(){a("#check-nv").click(function(){b.Utils.playSound("../sounds/new_user")});a("#check-nm").click(function(){b.Utils.playSound("../sounds/new_message")})})})(Mibew,$); diff --git a/src/mibew/js/compiled/users/collection_views/threads_collection.js b/src/mibew/js/compiled/users/collection_views/threads_collection.js index e7d60a19..cf0bd8ff 100644 --- a/src/mibew/js/compiled/users/collection_views/threads_collection.js +++ b/src/mibew/js/compiled/users/collection_views/threads_collection.js @@ -5,8 +5,8 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -(function(d,h,j){d.Views.ThreadsCollection=d.Views.CompositeBase.extend({template:h.templates.threads_collection,itemView:d.Views.QueuedThread,itemViewContainer:"#threads-container",emptyView:d.Views.NoThreads,className:"threads-collection",collectionEvents:{sort:"render","sort:field":"createSortField",add:"threadAdded"},itemViewOptions:function(a){return{tagName:d.Objects.Models.page.get("threadTag"),collection:a.get("controls")}},initialize:function(){window.setInterval(j.bind(this.updateTimers, +(function(d,h,k){d.Views.ThreadsCollection=d.Views.CompositeBase.extend({template:h.templates.threads_collection,itemView:d.Views.QueuedThread,itemViewContainer:"#threads-container",emptyView:d.Views.NoThreads,className:"threads-collection",collectionEvents:{sort:"render","sort:field":"createSortField",add:"threadAdded"},itemViewOptions:function(a){return{tagName:d.Objects.Models.page.get("threadTag"),collection:a.get("controls")}},initialize:function(){window.setInterval(k.bind(this.updateTimers, this),2E3);this.on("itemview:before:render",this.updateStyles,this);this.on("composite:collection:rendered",this.updateTimers,this)},updateStyles:function(a){var b=this.collection,c=a.model,d=this;if(c.id){var e=this.getQueueCode(c),f=!1,g=!1,b=b.filter(function(a){return d.getQueueCode(a)==e});0' + - '' + - ''; - $('body').append(soundHTML); + + var player = $('audio[data-file="'+file+'"]'); + if (player.length > 0) { + player.get(0).play(); + } + else { + + var audioTag = $("