-
Notifications
You must be signed in to change notification settings - Fork 9
/
console.js
136 lines (123 loc) · 3.79 KB
/
console.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var $console = null;
var in_command = false;
function validate(line) {
return line != '';
}
function scrollDown() {
$('body').scrollTop($('body').innerHeight());
window.scroll(0,$('body').innerHeight());
}
function handle(line) {
in_command = true;
setTimeout(function() {in_command = false;}, 0);
setTimeout(scrollDown, 0);
try {
var swf = $('#rdio_api').get(0);
with(swf) {
var result = eval(line);
}
if (typeof result == 'undefined') {
return true;
} else {
try {
result = stringify(result);
} catch(e) {
result = result.toString();
}
return [{'msg': result, 'className': 'result'}];
}
} catch(e) {
return [{'msg': e.toString(), 'className': 'error'}];
}
}
$(document).ready(function() {
$console = $('#console').console({
promptLabel: '>>> ',
autofocus: true,
commandValidate: validate,
commandHandle: handle
});
$console.typer.insertAfter($console.inner).wrap($('<form>')).css({
'position':'relative',
'top':'-1px',
'height':'1px',
'resize': 'none',
'font-size':'1px',
'line-height': '1px',
'margin': 0,
'padding': 0,
'border': 0
}).parent().css('margin-top', '-20px');
var playbackToken = tokens[document.domain];
if (playbackToken == null) {
$console.inner.prepend($('<div>').text('ERROR: no playback token found for: '+document.domain).addClass('error'));
return;
}
$('#welcome-text').detach().prependTo($console.inner).removeAttr('id');
var flashvars = {
'playbackToken': playbackToken, // from token.js
'domain': document.domain, // from token.js
'listener': 'callback' // the global name of the object that will receive callbacks from the SWF
};
var params = {
'allowScriptAccess': 'always'
};
var attributes = {};
swfobject.embedSWF('http://www.rdio.com/api/swf/', // the location of the Rdio Playback API SWF
'rdio_api', // the ID of the element that will be replaced with the SWF
1, 1, '9.0.0', 'expressInstall.swf', flashvars, params, attributes);
});
$('html').click(function() { $('#console').click(); });
function logCallback(message) {
var prompt = $('.jquery-console-prompt-box', $console.inner).last();
var div = $('<div></div>').text(message).addClass('callback');
if (in_command) {
div.insertAfter(prompt);
} else {
div.insertBefore(prompt);
}
scrollDown();
}
function stringify(o) {
return JSON.stringify(o);
}
window.callback = { };
window.callback.ready = function (a) {
logCallback('ready('+stringify(a)+')');
};
window.callback.freeRemainingChanged = function (a) {
logCallback('freeRemainingChanged('+stringify(a)+')');
};
window.callback.playStateChanged = function (a) {
logCallback('playStateChanged('+stringify(a)+')');
};
window.callback.playingTrackChanged = function (a, b) {
logCallback('playingTrackChanged('+stringify(a, b)+')');
};
window.callback.playingSourceChanged = function (a) {
logCallback('playingSourceChanged('+stringify(a)+')');
};
window.callback.volumeChanged = function (a) {
logCallback('volumeChanged('+stringify(a)+')');
};
window.callback.muteChanged = function (a) {
logCallback('muteChanged('+stringify(a)+')');
};
window.callback.positionChanged = function (a) {
logCallback('positionChanged('+stringify(a)+')');
};
window.callback.queueChanged = function (a) {
logCallback('queueChanged('+stringify(a)+')');
};
window.callback.shuffleChanged = function (a) {
logCallback('shuffleChanged('+stringify(a)+')');
};
window.callback.repeatChanged = function (a) {
logCallback('repeatChanged('+stringify(a)+')');
};
window.callback.playingSomewhereElse = function () {
logCallback('playingSomewhereElse()');
};
window.callback.updateFrequencyData = function (a) {
logCallback('updateFrequencyData('+stringify(a)+')');
};