summaryrefslogtreecommitdiffstats
path: root/js/directive/NewsPlayOne.js
blob: df73bbd0f5600c14ab71f2facc6818b7757fa651 (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
/**
 * Nextcloud - 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
 */

/**
 * Pause playback on elements other than the current one
 */
app.directive('newsPlayOne', function ($rootScope) {
    'use strict';
    return {
        restrict: 'A',
        link: function (scope, elem) {
            elem.on('play', function () {
                $rootScope.$broadcast('playing', elem);
            });

            $rootScope.$on('playing', function (scope, args) {
                if (args[0] !== elem[0]) {
                    elem[0].pause();
                }
            });
        }
    };
});