summaryrefslogtreecommitdiffstats
path: root/js/directive/NewsAudio.js
blob: 422f5ff195f3e88c6e3f440d073e312bf2ae5a88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
 * ownCloud - News
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Bernhard Posselt <dev@bernhard-posselt.com>
 * @copyright Bernhard Posselt 2014
 */
app.directive('newsAudio', function () {
    'use strict';
    return {
        restrict: 'E',
        scope: {
            src: '@',
            type: '@'
        },
        transclude: true,
        template: '' +
        '<audio controls="controls" preload="none" ng-hide="cantPlay()">' +
            '<source ng-src="{{ src|trustUrl }}">' +
        '</audio>' +
        '<a ng-href="{{ src|trustUrl }}" class="button" ng-show="cantPlay()" ' +
            'ng-transclude></a>',
        link: function (scope, elm) {
            var source = elm.children().children('source')[0];
            var cantPlay = false;

            source.addEventListener('error', function () {
                scope.$apply(function () {
                    cantPlay = true;
                });
            });

            scope.cantPlay = function () {
                return cantPlay;
            };
        }
    };
});