cms/app-client/app/services/player.js
author ymh <ymh.work@gmail.com>
Sat, 06 Aug 2016 21:29:33 +0700
changeset 261 02e2396bcbbc
parent 254 a7cf2887e993
child 271 e234339fe8df
permissions -rw-r--r--
Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)

import Ember from 'ember';

export default Ember.Service.extend(Ember.Evented, {

    items: [],
    item: null,
    model: null,
    transcript: null,

    window: '',
    playing: false,
    progress: 0, // In Milliseconds
    videoscreen: false,

    modelObserver: Ember.observer('model', function() {
        this.toggleVideoscreen(this.get('model').get('video'));
    }),

    displayAdditionalInformation: function(el) {
        if(el === 'video') {
            this.toggleVideoscreen();
        } else {
            this.displayMetadata(el);
        }
    },

    displayMetadata: function(el) {
         if(this.get('window') !== el) {
            this.set('window', el);
        } else {
            this.set('window', '');
        }
    },

    toggleVideoscreen: function(state) {
        if(typeof state === 'undefined') {
            this.set('videoscreen', !this.get('videoscreen'));
        } else {
            this.set('videoscreen', state);
        }        
    },

    init: function() {
        this.on('reset', Ember.run.bind(this, this.get('reset')));
    },

    setProgress: function(time) {
        this.set('progress', time);
    },

    select: function (id) {
        this.set('item', id);
    },

    play: function(id) {
        this.select(id);
        this.set('playing', true);
    },

    pause: function() {
        this.set('playing', false);
    },

    reset: function(id) {
        this.set('item', id);
    }
});