2012-05-26 14:38:15 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2015-02-21 10:43:37 +00:00
|
|
|
pandora.ui.scriptDialog = function() {
|
2012-05-26 14:38:15 +00:00
|
|
|
|
2012-06-11 07:17:39 +00:00
|
|
|
var dialogHeight = Math.round((window.innerHeight - 48) * 0.75),
|
|
|
|
dialogWidth = Math.round(window.innerWidth * 0.75),
|
2015-02-21 10:52:56 +00:00
|
|
|
$text = Ox.$('<div>')
|
2015-02-21 10:57:50 +00:00
|
|
|
.css({height: '16px', margin: '16px'})
|
2015-02-21 10:52:56 +00:00
|
|
|
.html(Ox._(
|
2015-02-21 10:57:50 +00:00
|
|
|
'Any JavaScript you paste here will run on load. '
|
2015-02-21 10:52:56 +00:00
|
|
|
+ 'If you ever need to bypass it, '
|
|
|
|
+ 'press escape while the page is loading.'
|
|
|
|
)),
|
2012-06-11 07:17:39 +00:00
|
|
|
$input = Ox.Input({
|
2015-02-21 10:57:50 +00:00
|
|
|
height: dialogHeight - 64,
|
2012-06-11 07:17:39 +00:00
|
|
|
type: 'textarea',
|
2015-02-21 10:32:48 +00:00
|
|
|
value: pandora.user.script || '',
|
2012-06-11 07:17:39 +00:00
|
|
|
width: dialogWidth - 32
|
|
|
|
})
|
|
|
|
.css({margin: '16px'}),
|
2012-05-26 14:38:15 +00:00
|
|
|
that = Ox.Dialog({
|
|
|
|
buttons: [
|
|
|
|
Ox.Button({
|
2013-05-09 10:13:58 +00:00
|
|
|
title: Ox._('Clear')
|
2012-05-26 14:38:15 +00:00
|
|
|
})
|
|
|
|
.css({margin: '4px 4px 4px 0'})
|
|
|
|
.bindEvent({
|
|
|
|
click: function() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
Ox.Button({
|
|
|
|
id: 'done',
|
2013-05-09 10:13:58 +00:00
|
|
|
title: Ox._('Done'),
|
2012-05-26 14:38:15 +00:00
|
|
|
width: 48
|
|
|
|
}).bindEvent({
|
|
|
|
click: function() {
|
|
|
|
that.close();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
closeButton: true,
|
2015-02-21 10:52:56 +00:00
|
|
|
content: Ox.Element().append($text).append($input),
|
2012-05-26 14:38:15 +00:00
|
|
|
height: dialogHeight,
|
|
|
|
maximizeButton: true,
|
|
|
|
minHeight: 256,
|
|
|
|
minWidth: 512,
|
|
|
|
removeOnClose: true,
|
2013-05-09 10:13:58 +00:00
|
|
|
title: Ox._('Run Script on Load'),
|
2012-05-26 14:38:15 +00:00
|
|
|
width: dialogWidth
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
resize: resize
|
|
|
|
});
|
|
|
|
|
|
|
|
function resize(data) {
|
|
|
|
dialogHeight = data.height;
|
|
|
|
dialogWidth = data.width;
|
2012-06-11 07:17:39 +00:00
|
|
|
$input.options({
|
2015-02-21 10:57:50 +00:00
|
|
|
height: dialogHeight - 64,
|
2012-06-11 07:17:39 +00:00
|
|
|
width: dialogWidth - 32
|
2012-05-26 14:38:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function clear() {
|
2015-02-21 10:32:48 +00:00
|
|
|
pandora.api.editPreferences({script: ''});
|
2012-06-11 07:17:39 +00:00
|
|
|
$input.options({value: ''});
|
2012-05-26 14:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
that.superClose = that.close;
|
|
|
|
that.close = function() {
|
2012-06-11 07:17:39 +00:00
|
|
|
var value = $input.value();
|
2015-02-21 10:32:48 +00:00
|
|
|
pandora.api.editPreferences({script: value || ''});
|
2012-05-26 14:38:15 +00:00
|
|
|
that.superClose();
|
|
|
|
};
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|
|
|
|
|