make egAudio respect eg.audio.disable
authorGalen Charlton <gmc@esilibrary.com>
Tue, 13 Sep 2016 21:21:51 +0000 (17:21 -0400)
committerKathy Lussier <klussier@masslnc.org>
Tue, 22 Nov 2016 19:10:03 +0000 (14:10 -0500)
This patch also removes some console.debug noise.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/web/js/ui/default/staff/services/audio.js

index 1b88978..8cab872 100644 (file)
@@ -40,37 +40,41 @@ angular.module('egCoreMod')
 
     service.play_url = function(path, orig_path) {
 
-        var url = service.url_cache[path] || 
-            service.base_url + path.replace(/\./g, '/') + '.wav';
+        egHatch.getItem('eg.audio.disable').then(function(audio_disabled) {
+            if (!audio_disabled) {
+        
+                var url = service.url_cache[path] || 
+                    service.base_url + path.replace(/\./g, '/') + '.wav';
 
-        var player = new Audio(url);
+                var player = new Audio(url);
 
-        player.onloadeddata = function() {
-            console.debug('Playing audio URL: ' + url);
-            service.url_cache[orig_path] = url;
-            player.play();
-        };
+                player.onloadeddata = function() {
+                    service.url_cache[orig_path] = url;
+                    player.play();
+                };
 
-        if (service.url_cache[path]) {
-            // when serving from the cache, avoid secondary URL lookups.
-            return;
-        }
+                if (service.url_cache[path]) {
+                    // when serving from the cache, avoid secondary URL lookups.
+                    return;
+                }
 
-        player.onerror = function() {
-            // Unable to play path at the requested URL.
+                player.onerror = function() {
+                    // Unable to play path at the requested URL.
             
-            if (!path.match(/\./)) {
-                // all fall-through options have been exhausted.
-                // No path to play.
-                console.warn(
-                    "No suitable URL found for path '" + orig_path + "'");
-                return;
-            }
+                    if (!path.match(/\./)) {
+                        // all fall-through options have been exhausted.
+                        // No path to play.
+                        console.warn(
+                            "No suitable URL found for path '" + orig_path + "'");
+                        return;
+                    }
 
-            // Fall through to the next (more generic) option
-            path = path.replace(/\.[^\.]+$/, '');
-            service.play_url(path, orig_path);
-        }
+                    // Fall through to the next (more generic) option
+                    path = path.replace(/\.[^\.]+$/, '');
+                    service.play_url(path, orig_path);
+                }
+            }
+        });
     }
 
     return service;