summaryrefslogtreecommitdiffstats
path: root/js/directive/NewsEnclosure.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/directive/NewsEnclosure.js')
-rw-r--r--js/directive/NewsEnclosure.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/js/directive/NewsEnclosure.js b/js/directive/NewsEnclosure.js
new file mode 100644
index 000000000..c424b50c3
--- /dev/null
+++ b/js/directive/NewsEnclosure.js
@@ -0,0 +1,53 @@
+/**
+ * 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('newsEnclosure', function () {
+ 'use strict';
+ return {
+ restrict: 'E',
+ scope: {
+ link: '@',
+ type: '@'
+ },
+ transclude: true,
+ template: '<div>' +
+ '<video controls preload="none" ' +
+ 'ng-show="mediaType==\'video\' && !cantPlay()">' +
+ '<source ng-src="{{ link|trustUrl }}" type="{{ type }}">' +
+ '</video>' +
+ '<audio controls preload="none" ' +
+ 'ng-show="mediaType==\'audio\' && !cantPlay()">' +
+ '<source ng-src="{{ link|trustUrl }}" type="{{ type }}">' +
+ '</audio>' +
+ '<div ng-transclude ng-show="cantPlay()"></div>' +
+ '</div>',
+ link: function (scope, elem) {
+ if (scope.type.indexOf('audio') === 0) {
+ scope.mediaType = 'audio';
+ } else {
+ scope.mediaType = 'video';
+ }
+ var source = elem.children()
+ .children(scope.mediaType)
+ .children('source')[0];
+
+ var cantPlay = false;
+
+ scope.cantPlay = function () {
+ return cantPlay;
+ };
+
+ source.addEventListener('error', function () {
+ scope.$apply(function () {
+ cantPlay = true;
+ });
+ });
+ }
+ };
+}); \ No newline at end of file