2015-09-15 05:22:43 +00:00
|
|
|
define(function(require, exports, module) {
|
|
|
|
main.consumes = [
|
|
|
|
"PreferencePanel", "ui", "dialog.confirm", "settings",
|
2015-09-15 05:39:31 +00:00
|
|
|
"preferences", "c9"
|
2015-09-15 05:22:43 +00:00
|
|
|
];
|
|
|
|
main.provides = ["preferences.experimental"];
|
|
|
|
return main;
|
|
|
|
|
|
|
|
function main(options, imports, register) {
|
|
|
|
var PreferencePanel = imports.PreferencePanel;
|
|
|
|
var prefs = imports.preferences;
|
2015-09-15 05:39:31 +00:00
|
|
|
var settings = imports.settings;
|
2015-09-15 05:22:43 +00:00
|
|
|
var ui = imports.ui;
|
2015-09-15 05:39:31 +00:00
|
|
|
var c9 = imports.c9;
|
2015-09-15 05:22:43 +00:00
|
|
|
|
|
|
|
/***** Initialization *****/
|
|
|
|
|
|
|
|
var plugin = new PreferencePanel("Ajax.org", main.consumes, {
|
2015-09-15 06:01:31 +00:00
|
|
|
caption: "Experimental",
|
2015-09-15 05:22:43 +00:00
|
|
|
form: true,
|
|
|
|
index: 50
|
|
|
|
});
|
|
|
|
var emit = plugin.getEmitter();
|
|
|
|
emit.setMaxListeners(1000);
|
|
|
|
|
|
|
|
var intro;
|
|
|
|
|
|
|
|
var loaded = false;
|
|
|
|
function load() {
|
|
|
|
if (loaded) return false;
|
|
|
|
loaded = true;
|
|
|
|
|
2015-09-15 06:13:11 +00:00
|
|
|
settings.setDefaults("state/experiments", [["@enabled", true]]);
|
|
|
|
|
2015-09-15 05:22:43 +00:00
|
|
|
plugin.form.add([{
|
|
|
|
type: "custom",
|
|
|
|
title: "Introduction",
|
|
|
|
position: 1,
|
|
|
|
node: intro = new ui.bar({
|
|
|
|
height: 102,
|
|
|
|
"class" : "intro",
|
|
|
|
style: "padding:12px;position:relative;"
|
|
|
|
})
|
|
|
|
}], plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
var drawn = false;
|
|
|
|
function draw(e) {
|
|
|
|
if (drawn) return;
|
|
|
|
drawn = true;
|
|
|
|
|
|
|
|
intro.$int.innerHTML =
|
2015-09-15 06:20:27 +00:00
|
|
|
'<h1>Experimental Features</h1><p style="white-space:normal">Cloud9 is continuously in '
|
2015-09-15 05:22:43 +00:00
|
|
|
+ 'development. New features in alpha or beta are first hidden '
|
|
|
|
+ 'and can be enabled via this page. <i>Use at your own risk</i></p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** Methods *****/
|
|
|
|
|
2015-09-15 05:39:31 +00:00
|
|
|
// =0 means the value should be set to 0 to disable otherwise it is enabled
|
|
|
|
// =1 means the value should be set to 1 to enable otherwise it is disabled
|
2015-09-15 06:01:31 +00:00
|
|
|
var found = {};
|
2015-09-15 05:22:43 +00:00
|
|
|
function addExperiment(query, name){
|
2015-09-15 06:01:31 +00:00
|
|
|
if (found[name]) return;
|
|
|
|
found[name] = true;
|
|
|
|
|
2015-09-15 05:39:31 +00:00
|
|
|
var key = query.split("=");
|
|
|
|
var defValue = Number(key[1]); key = key[0];
|
|
|
|
var uniqueId = key.replace(/\//g, "-");
|
|
|
|
|
2015-09-15 05:22:43 +00:00
|
|
|
var parts = name.split("/");
|
2015-09-15 06:01:31 +00:00
|
|
|
var current, obj = { "Experimental": current = {} };
|
2015-09-15 05:22:43 +00:00
|
|
|
for (var i = 0; i < parts.length; i++) {
|
|
|
|
current[parts[i]] = current = {};
|
|
|
|
}
|
|
|
|
current.type = "checkbox";
|
2015-09-15 05:39:31 +00:00
|
|
|
current.setting = "state/experiments/" + uniqueId;
|
2015-09-15 05:22:43 +00:00
|
|
|
|
2015-09-15 06:01:31 +00:00
|
|
|
plugin.add(obj, plugin);
|
2015-09-15 05:25:55 +00:00
|
|
|
|
2015-09-15 05:39:31 +00:00
|
|
|
var idx = c9.location.indexOf(query);
|
|
|
|
var enabled = defValue == 1 ? idx > -1 : idx === -1;
|
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
enabled = settings.getBool("state/experiments/" + uniqueId);
|
|
|
|
|
|
|
|
return enabled;
|
2015-09-15 05:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***** Lifecycle *****/
|
|
|
|
|
|
|
|
plugin.on("load", function() {
|
|
|
|
load();
|
|
|
|
});
|
|
|
|
plugin.on("draw", function(e) {
|
|
|
|
draw(e);
|
|
|
|
});
|
|
|
|
plugin.on("unload", function() {
|
|
|
|
loaded = false;
|
|
|
|
drawn = false;
|
|
|
|
intro = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
/***** Register and define API *****/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
plugin.freezePublicAPI({
|
|
|
|
_events: [
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
addExperiment: addExperiment
|
|
|
|
});
|
|
|
|
|
|
|
|
register(null, {
|
|
|
|
"preferences.experimental": plugin
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|