-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
102 lines (97 loc) · 3.49 KB
/
scripts.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function ScriptPanel() {
ViewController.call(this, 'Scripts');
this.pane.textarea.remove();
this.addScriptButton = document.createElement('button');
this.addScriptButton.innerText = '+';
this.addScriptButton.onclick = function(scriptPanel) {
return function(evt) {
scriptPanel.addScript(puppeteer.timelinePanel);
}
}(this)
this.pane.div.insertBefore(this.addScriptButton, this.pane.titleSpan.nextSibling);
}
ScriptPanel.prototype = Object.create(ViewController.prototype);
function copyKey(k){
return {c:k.c,t:k.t,v:k.v};
}
function selectElementContents(el) {
var range = document.createRange();
range.selectNodeContents(el);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
function scriptPanelClick(scriptPanel,script) {
return function(evt) {
scriptPanel.scriptSpan = evt.target;
if(scriptPanel.scriptSpan.contentEditable=='true'){
return;
}
scriptPanel.popupMenu = new PupMenu(evt,[
'rename:rename',
'delete:delete',
'copy:copy from timeline',
'paste:paste to timeline'],script,function(choice,target) {
scriptPanel.popupMenu = undefined;
if(choice=='rename'){
scriptPanel.scriptSpan.spellcheck = false;
scriptPanel.scriptSpan.contentEditable = 'true';
selectElementContents(scriptPanel.scriptSpan);
scriptPanel.scriptSpan.onkeyup=function(evt){
if(evt.key == 'Enter'){
scriptPanel.scriptSpan.contentEditable = 'inherit';
evt.preventDefault();
var newName = scriptPanel.scriptSpan.innerText;
newName=newName.replace(/[^A-Za-z0-9]/g, '');
newName=newName.replace(/(\r\n|\n|\r)/gm,'');
scriptPanel.scriptSpan.script.name = newName;
scriptPanel.rebuildFromModel();
return false;
}
}
scriptPanel.scriptSpan.focus();
}else
if(choice=='delete'){
var id = scriptPanel.pane.model.scripts.indexOf(target);
if(id>=0){
scriptPanel.pane.model.scripts.splice(id,1);
scriptPanel.rebuildFromModel();
}
}else
if(choice=='copy'){
}else
if(choice=='paste'){
}
}
);
}
}
ScriptPanel.prototype.rebuildFromModel = function() {
var br = this.addScriptButton.nextSibling;
while (br && br.nextSibling)
br.nextSibling.remove();
this.model = this.pane.model;
if (this.model.scripts) {
for (var i = 0; i < this.model.scripts.length; i++) {
var act = this.model.scripts[i];
var span = document.createElement('span');
span.className = 'menu-span';
span.innerText = act.name;
span.script = act;
span.onclick = scriptPanelClick(this,act);
this.pane.div.appendChild(span);
// this.pane.div.appendChild(document.createElement('br'));
}
}
}
ScriptPanel.prototype.addScript = function(timeline) {
if (!this.model.scripts) {
this.model.scripts = [];
}
var act = {
name: 'Unnamed',
keys:[]
}
this.model.scripts.push(act);
this.rebuildFromModel();
}