-
Notifications
You must be signed in to change notification settings - Fork 6
/
base.js
69 lines (59 loc) · 1.77 KB
/
base.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var Timeline = require('./lib/timeline-data')
var EventEmitter = require('events').EventEmitter
var inherits = require('inherits')
var indexOfName = require('./indexof-name')
function EditorBase() {
if (!(this instanceof EditorBase))
return new EditorBase()
EventEmitter.call(this)
this.timelinesData = []
this._playhead = 0
}
inherits(EditorBase, EventEmitter)
//Sets the playhead value and emits a playhead change event
EditorBase.prototype.playhead = function(time) {
if (typeof time === 'number') {
var old = this._playhead
this._playhead = Math.max(0, time)
if (old !== this._playhead)
this.emit('playhead', this._playhead)
} else
return this._playhead
}
EditorBase.prototype._generateName = function() {
var count = this.timelinesData.length
var base = 'timeline'
var idx
while ( (idx = indexOfName(this.timelinesData, base+count)) >= 0 )
count++
return base+count
}
//Creates a new timeline object which has { element, open, name, dispose }
EditorBase.prototype._createTimeline = function(timeline, name) {
return Timeline(timeline, name)
}
EditorBase.prototype.timelineData = function(name) {
var idx = typeof name === 'number' ? name : indexOfName(this.timelinesData, name)
if (idx === -1)
return null
return this.timelinesData[idx]
}
//gets timeline by name or index
EditorBase.prototype.timeline = function(name) {
var ret = this.timelineData(name)
return ret ? ret.timeline : null
}
EditorBase.prototype.open = function(name, show) {
show = show !== false
var ret = this.timelineData(name)
if (ret)
ret.open = show
}
EditorBase.prototype.add = function(timeline, name) {
name = name||this._generateName()
var data = this._createTimeline(timeline, name)
this.timelinesData.push(data)
this.emit('load')
return data
}
module.exports = EditorBase