2015-02-05 16:05:29 +01:00
|
|
|
|
/**
|
|
|
|
|
* configurator.js
|
|
|
|
|
*
|
|
|
|
|
* Marlin Configuration Utility
|
|
|
|
|
* - Web form for entering configuration options
|
|
|
|
|
* - A reprap calculator to calculate movement values
|
|
|
|
|
* - Uses HTML5 to generate downloadables in Javascript
|
|
|
|
|
* - Reads and parses standard configuration files from local folders
|
|
|
|
|
*
|
|
|
|
|
* Supporting functions
|
|
|
|
|
* - Parser to read Marlin Configuration.h and Configuration_adv.h files
|
|
|
|
|
* - Utilities to replace values in configuration files
|
|
|
|
|
*/
|
2015-02-05 17:22:51 +01:00
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
2015-02-05 16:05:29 +01:00
|
|
|
|
$(function(){
|
|
|
|
|
|
2015-02-11 13:59:07 +01:00
|
|
|
|
/**
|
|
|
|
|
* Github API useful GET paths. (Start with "https://api.github.com/repos/:owner/:repo/")
|
|
|
|
|
*
|
|
|
|
|
* contributors Get a list of contributors
|
|
|
|
|
* tags Get a list of tags
|
|
|
|
|
* contents/[path]?ref=branch/tag/commit Get the contents of a file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// GitHub
|
|
|
|
|
// Warning! Limited to 60 requests per hour!
|
|
|
|
|
var config = {
|
|
|
|
|
type: 'github',
|
|
|
|
|
host: 'https://api.github.com',
|
|
|
|
|
owner: 'thinkyhead',
|
|
|
|
|
repo: 'Marlin',
|
|
|
|
|
ref: 'marlin_configurator',
|
|
|
|
|
path: 'Marlin/configurator/config'
|
|
|
|
|
};
|
|
|
|
|
/**/
|
|
|
|
|
|
|
|
|
|
/* // Remote
|
|
|
|
|
var config = {
|
|
|
|
|
type: 'remote',
|
|
|
|
|
host: 'http://www.thinkyhead.com',
|
|
|
|
|
path: '_marlin/config'
|
|
|
|
|
};
|
|
|
|
|
/**/
|
|
|
|
|
|
|
|
|
|
/* // Local
|
|
|
|
|
var config = {
|
|
|
|
|
type: 'local',
|
|
|
|
|
path: 'config'
|
|
|
|
|
};
|
|
|
|
|
/**/
|
|
|
|
|
|
|
|
|
|
function github_command(conf, command, path) {
|
|
|
|
|
var req = conf.host+'/repos/'+conf.owner+'/'+conf.repo+'/'+command;
|
|
|
|
|
if (path) req += '/' + path;
|
|
|
|
|
return req;
|
|
|
|
|
}
|
|
|
|
|
function config_path(item) {
|
|
|
|
|
var path = '', ref = '';
|
|
|
|
|
switch(config.type) {
|
|
|
|
|
case 'github':
|
|
|
|
|
path = github_command(config, 'contents', config.path);
|
|
|
|
|
if (config.ref !== undefined) ref = '?ref=' + config.ref;
|
|
|
|
|
break;
|
|
|
|
|
case 'remote':
|
|
|
|
|
path = config.host + '/' + config.path + '/';
|
|
|
|
|
break;
|
|
|
|
|
case 'local':
|
|
|
|
|
path = config.path + '/';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return path + '/' + item + ref;
|
|
|
|
|
}
|
2015-02-05 16:05:29 +01:00
|
|
|
|
|
2015-02-09 13:34:57 +01:00
|
|
|
|
// Extend builtins
|
2015-02-05 16:05:29 +01:00
|
|
|
|
String.prototype.lpad = function(len, chr) {
|
|
|
|
|
if (chr === undefined) { chr = ' '; }
|
|
|
|
|
var s = this+'', need = len - s.length;
|
|
|
|
|
if (need > 0) { s = new Array(need+1).join(chr) + s; }
|
|
|
|
|
return s;
|
|
|
|
|
};
|
2015-02-11 13:59:07 +01:00
|
|
|
|
|
2015-02-07 09:46:14 +01:00
|
|
|
|
String.prototype.prePad = function(len, chr) { return len ? this.lpad(len, chr) : this; };
|
|
|
|
|
String.prototype.zeroPad = function(len) { return this.prePad(len, '0'); };
|
2015-02-07 20:58:19 +01:00
|
|
|
|
String.prototype.toHTML = function() { return jQuery('<div>').text(this).html(); };
|
2015-02-07 09:46:14 +01:00
|
|
|
|
String.prototype.regEsc = function() { return this.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); }
|
2015-03-06 17:48:53 +01:00
|
|
|
|
String.prototype.lineCount = function(ind) { var len = (ind === undefined ? this : this.substr(0,ind*1)).split(/\r?\n|\r/).length; return len > 0 ? len - 1 : 0; };
|
|
|
|
|
String.prototype.line = function(num) { var arr = this.split(/\r?\n|\r/); return num < arr.length ? arr[1*num] : ''; };
|
|
|
|
|
String.prototype.replaceLine = function(num,txt) { var arr = this.split(/\r?\n|\r/); if (num < arr.length) { arr[num] = txt; return arr.join('\n'); } else return this; }
|
2015-03-02 10:45:53 +01:00
|
|
|
|
String.prototype.toLabel = function() { return this.replace(/[\[\]]/g, '').replace(/_/g, ' ').toTitleCase(); }
|
2015-02-09 13:34:57 +01:00
|
|
|
|
String.prototype.toTitleCase = function() { return this.replace(/([A-Z])(\w+)/gi, function(m,p1,p2) { return p1.toUpperCase() + p2.toLowerCase(); }); }
|
|
|
|
|
Number.prototype.limit = function(m1, m2) {
|
|
|
|
|
if (m2 == null) return this > m1 ? m1 : this;
|
|
|
|
|
return this < m1 ? m1 : this > m2 ? m2 : this;
|
|
|
|
|
};
|
2015-02-11 13:59:07 +01:00
|
|
|
|
Date.prototype.fileStamp = function(filename) {
|
|
|
|
|
var fs = this.getFullYear()
|
|
|
|
|
+ ((this.getMonth()+1)+'').zeroPad(2)
|
|
|
|
|
+ (this.getDate()+'').zeroPad(2)
|
|
|
|
|
+ (this.getHours()+'').zeroPad(2)
|
|
|
|
|
+ (this.getMinutes()+'').zeroPad(2)
|
|
|
|
|
+ (this.getSeconds()+'').zeroPad(2);
|
|
|
|
|
|
|
|
|
|
if (filename !== undefined)
|
|
|
|
|
return filename.replace(/^(.+)(\.\w+)$/g, '$1-['+fs+']$2');
|
|
|
|
|
|
|
|
|
|
return fs;
|
|
|
|
|
}
|
2015-02-06 04:30:11 +01:00
|
|
|
|
|
2015-02-05 16:05:29 +01:00
|
|
|
|
/**
|
|
|
|
|
* selectField.addOptions takes an array or keyed object
|
|
|
|
|
*/
|
|
|
|
|
$.fn.extend({
|
|
|
|
|
addOptions: function(arrObj) {
|
|
|
|
|
return this.each(function() {
|
|
|
|
|
var sel = $(this);
|
|
|
|
|
var isArr = Object.prototype.toString.call(arrObj) == "[object Array]";
|
|
|
|
|
$.each(arrObj, function(k, v) {
|
|
|
|
|
sel.append( $('<option>',{value:isArr?v:k}).text(v) );
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-02-11 13:59:07 +01:00
|
|
|
|
},
|
|
|
|
|
noSelect: function() {
|
|
|
|
|
return this
|
|
|
|
|
.attr('unselectable', 'on')
|
|
|
|
|
.css('user-select', 'none')
|
|
|
|
|
.on('selectstart', false);
|
2015-03-02 10:45:53 +01:00
|
|
|
|
},
|
|
|
|
|
unblock: function(on) {
|
|
|
|
|
on ? this.removeClass('blocked') : this.addClass('blocked');
|
|
|
|
|
return this;
|
2015-02-05 16:05:29 +01:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// The app is a singleton
|
2015-02-28 06:08:09 +01:00
|
|
|
|
window.configuratorApp = (function(){
|
2015-02-05 16:05:29 +01:00
|
|
|
|
|
|
|
|
|
// private variables and functions go here
|
|
|
|
|
var self,
|
|
|
|
|
pi2 = Math.PI * 2,
|
2015-02-07 02:57:31 +01:00
|
|
|
|
has_boards = false, has_config = false, has_config_adv = false,
|
2015-02-05 20:14:31 +01:00
|
|
|
|
boards_file = 'boards.h',
|
|
|
|
|
config_file = 'Configuration.h',
|
|
|
|
|
config_adv_file = 'Configuration_adv.h',
|
2015-02-11 13:59:07 +01:00
|
|
|
|
$msgbox = $('#message'),
|
2015-02-09 13:34:57 +01:00
|
|
|
|
$form = $('#config_form'),
|
2015-02-07 18:03:00 +01:00
|
|
|
|
$tooltip = $('#tooltip'),
|
2015-02-20 11:12:00 +01:00
|
|
|
|
$cfg = $('#config_text'), $adv = $('#config_adv_text'),
|
|
|
|
|
$config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
|
2015-03-02 14:23:36 +01:00
|
|
|
|
config_file_list = [ boards_file, config_file, config_adv_file ],
|
|
|
|
|
config_list = [ $config, $config_adv ],
|
2015-03-06 17:48:53 +01:00
|
|
|
|
define_info = {}, // info for all defines, by name
|
|
|
|
|
define_list = [[],[]], // arrays with all define names
|
|
|
|
|
define_occur = [{},{}], // lines where defines occur in each file
|
|
|
|
|
define_groups = [{},{}], // similarly-named defines that group in the form
|
|
|
|
|
define_section = {}, // the section of each define
|
|
|
|
|
dependent_groups = {},
|
2015-02-05 16:05:29 +01:00
|
|
|
|
boards_list = {},
|
2015-02-07 02:57:31 +01:00
|
|
|
|
therms_list = {},
|
|
|
|
|
total_config_lines,
|
2015-02-07 16:39:10 +01:00
|
|
|
|
total_config_adv_lines,
|
2015-02-07 19:45:56 +01:00
|
|
|
|
hover_timer,
|
|
|
|
|
pulse_offset = 0;
|
2015-02-05 16:05:29 +01:00
|
|
|
|
|
|
|
|
|
// Return this anonymous object as configuratorApp
|
|
|
|
|
return {
|
|
|
|
|
my_public_var: 4,
|
2015-02-06 04:30:11 +01:00
|
|
|
|
logging: 1,
|
2015-02-05 16:05:29 +01:00
|
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
|
self = this; // a 'this' for use when 'this' is something else
|
|
|
|
|
|
2015-02-09 13:34:57 +01:00
|
|
|
|
// Set up the form, creating fields and fieldsets as-needed
|
2015-02-07 08:46:16 +01:00
|
|
|
|
this.initConfigForm();
|
2015-02-07 02:57:31 +01:00
|
|
|
|
|
2015-02-09 13:34:57 +01:00
|
|
|
|
// Make tabs for all the fieldsets
|
|
|
|
|
this.makeTabsForFieldsets();
|
2015-02-06 05:28:39 +01:00
|
|
|
|
|
2015-02-11 13:59:07 +01:00
|
|
|
|
// No selection on errors
|
2015-02-13 12:02:56 +01:00
|
|
|
|
// $msgbox.noSelect();
|
2015-02-11 13:59:07 +01:00
|
|
|
|
|
2015-02-07 08:46:16 +01:00
|
|
|
|
// Make a droppable file uploader, if possible
|
2015-02-05 20:14:31 +01:00
|
|
|
|
var $uploader = $('#file-upload');
|
|
|
|
|
var fileUploader = new BinaryFileUploader({
|
|
|
|
|
element: $uploader[0],
|
2015-02-06 04:30:11 +01:00
|
|
|
|
onFileLoad: function(file) { self.handleFileLoad(file, $uploader); }
|
2015-02-05 20:14:31 +01:00
|
|
|
|
});
|
2015-02-07 08:46:16 +01:00
|
|
|
|
if (!fileUploader.hasFileUploaderSupport())
|
|
|
|
|
this.setMessage("Your browser doesn't support the file reading API.", 'error');
|
|
|
|
|
|
2015-02-09 13:34:57 +01:00
|
|
|
|
// Make the disclosure items work
|
|
|
|
|
$('.disclose').click(function(){
|
2015-02-11 13:59:07 +01:00
|
|
|
|
var $dis = $(this), $pre = $dis.nextAll('pre:first');
|
2015-02-09 13:34:57 +01:00
|
|
|
|
var didAnim = function() {$dis.toggleClass('closed almost');};
|
|
|
|
|
$dis.addClass('almost').hasClass('closed')
|
2015-02-11 13:59:07 +01:00
|
|
|
|
? $pre.slideDown(200, didAnim)
|
|
|
|
|
: $pre.slideUp(200, didAnim);
|
2015-02-09 13:34:57 +01:00
|
|
|
|
});
|
|
|
|
|
|
2015-02-20 11:12:00 +01:00
|
|
|
|
// Adjust the form layout for the window size
|
|
|
|
|
$(window).bind('scroll resize', this.adjustFormLayout).trigger('resize');
|
2015-02-19 12:41:41 +01:00
|
|
|
|
|
2015-02-07 08:46:16 +01:00
|
|
|
|
// Read boards.h, Configuration.h, Configuration_adv.h
|
|
|
|
|
var ajax_count = 0, success_count = 0;
|
|
|
|
|
var loaded_items = {};
|
2015-02-11 13:59:07 +01:00
|
|
|
|
var isGithub = config.type == 'github';
|
|
|
|
|
var rateLimit = 0;
|
2015-03-02 14:23:36 +01:00
|
|
|
|
$.each(config_file_list, function(i,fname){
|
2015-02-11 13:59:07 +01:00
|
|
|
|
var url = config_path(fname);
|
2015-02-07 08:46:16 +01:00
|
|
|
|
$.ajax({
|
2015-02-11 13:59:07 +01:00
|
|
|
|
url: url,
|
2015-02-07 08:46:16 +01:00
|
|
|
|
type: 'GET',
|
2015-02-11 13:59:07 +01:00
|
|
|
|
dataType: isGithub ? 'jsonp' : undefined,
|
2015-02-07 08:46:16 +01:00
|
|
|
|
async: true,
|
|
|
|
|
cache: false,
|
2015-02-11 13:59:07 +01:00
|
|
|
|
error: function(req, stat, err) {
|
|
|
|
|
self.log(req, 1);
|
|
|
|
|
if (req.status == 200) {
|
|
|
|
|
if (typeof req.responseText === 'string') {
|
|
|
|
|
var txt = req.responseText;
|
2015-03-02 14:23:36 +01:00
|
|
|
|
loaded_items[fname] = function(){ self.fileLoaded(fname, txt, true); };
|
2015-02-11 13:59:07 +01:00
|
|
|
|
success_count++;
|
|
|
|
|
// self.setMessage('The request for "'+fname+'" may be malformed.', 'error');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
self.setRequestError(req.status ? req.status : '(Access-Control-Allow-Origin?)', url);
|
|
|
|
|
}
|
|
|
|
|
},
|
2015-02-07 08:46:16 +01:00
|
|
|
|
success: function(txt) {
|
2015-02-11 13:59:07 +01:00
|
|
|
|
if (isGithub && typeof txt.meta.status !== undefined && txt.meta.status != 200) {
|
|
|
|
|
self.setRequestError(txt.meta.status, url);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// self.log(txt, 1);
|
|
|
|
|
if (isGithub) {
|
|
|
|
|
rateLimit = {
|
|
|
|
|
quota: 1 * txt.meta['X-RateLimit-Remaining'],
|
|
|
|
|
timeLeft: Math.floor(txt.meta['X-RateLimit-Reset'] - Date.now()/1000),
|
|
|
|
|
};
|
|
|
|
|
}
|
2015-03-09 05:54:17 +01:00
|
|
|
|
loaded_items[fname] = function(){ self.fileLoaded(fname, isGithub ? decodeURIComponent(escape(atob(txt.data.content))) : txt, true); };
|
2015-02-11 13:59:07 +01:00
|
|
|
|
success_count++;
|
|
|
|
|
}
|
2015-02-07 08:46:16 +01:00
|
|
|
|
},
|
|
|
|
|
complete: function() {
|
|
|
|
|
ajax_count++;
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (ajax_count >= config_file_list.length) {
|
2015-02-13 12:02:56 +01:00
|
|
|
|
// If not all files loaded set an error
|
2015-02-07 08:46:16 +01:00
|
|
|
|
if (success_count < ajax_count)
|
2015-02-11 13:59:07 +01:00
|
|
|
|
self.setMessage('Unable to load configurations. Try the upload field.', 'error');
|
2015-02-13 12:02:56 +01:00
|
|
|
|
|
|
|
|
|
// Is the request near the rate limit? Set an error.
|
2015-02-11 13:59:07 +01:00
|
|
|
|
var r;
|
|
|
|
|
if (r = rateLimit) {
|
|
|
|
|
if (r.quota < 20) {
|
|
|
|
|
self.setMessage(
|
|
|
|
|
'Approaching request limit (' +
|
|
|
|
|
r.quota + ' remaining.' +
|
2015-02-13 12:02:56 +01:00
|
|
|
|
' Reset in ' + Math.floor(r.timeLeft/60) + ':' + (r.timeLeft%60+'').zeroPad(2) + ')',
|
|
|
|
|
'warning'
|
2015-02-11 13:59:07 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-13 12:02:56 +01:00
|
|
|
|
// Post-process all the loaded files
|
2015-03-02 14:23:36 +01:00
|
|
|
|
$.each(config_file_list, function(){ if (loaded_items[this]) loaded_items[this](); });
|
2015-02-07 08:46:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-02-05 16:05:29 +01:00
|
|
|
|
});
|
2015-02-07 08:46:16 +01:00
|
|
|
|
},
|
2015-02-05 16:05:29 +01:00
|
|
|
|
|
2015-02-13 12:02:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* Make a download link visible and active
|
|
|
|
|
*/
|
2015-03-02 14:23:36 +01:00
|
|
|
|
activateDownloadLink: function(cindex) {
|
|
|
|
|
var filename = config_file_list[cindex+1];
|
|
|
|
|
var $c = config_list[cindex], txt = $c.text();
|
2015-02-11 13:59:07 +01:00
|
|
|
|
$c.prevAll('.download:first')
|
2015-02-13 12:02:56 +01:00
|
|
|
|
.unbind('mouseover click')
|
2015-02-11 13:59:07 +01:00
|
|
|
|
.mouseover(function() {
|
|
|
|
|
var d = new Date(), fn = d.fileStamp(filename);
|
|
|
|
|
$(this).attr({ download:fn, href:'download:'+fn, title:'download:'+fn });
|
|
|
|
|
})
|
|
|
|
|
.click(function(){
|
|
|
|
|
var $button = $(this);
|
|
|
|
|
$(this).attr({ href:'data:text/plain;charset=utf-8,' + encodeURIComponent($c.text()) });
|
|
|
|
|
setTimeout(function(){
|
|
|
|
|
$button.attr({ href:$button.attr('title') });
|
|
|
|
|
}, 100);
|
|
|
|
|
return true;
|
|
|
|
|
})
|
|
|
|
|
.css({visibility:'visible'});
|
|
|
|
|
},
|
|
|
|
|
|
2015-02-20 11:12:00 +01:00
|
|
|
|
/**
|
|
|
|
|
* Make the download-all link visible and active
|
|
|
|
|
*/
|
|
|
|
|
activateDownloadAllLink: function() {
|
|
|
|
|
$('.download-all')
|
|
|
|
|
.unbind('mouseover click')
|
|
|
|
|
.mouseover(function() {
|
|
|
|
|
var d = new Date(), fn = d.fileStamp('MarlinConfig.zip');
|
|
|
|
|
$(this).attr({ download:fn, href:'download:'+fn, title:'download:'+fn });
|
|
|
|
|
})
|
|
|
|
|
.click(function(){
|
|
|
|
|
var $button = $(this);
|
|
|
|
|
var zip = new JSZip();
|
2015-03-02 14:23:36 +01:00
|
|
|
|
for (var e in [0,1]) zip.file(config_file_list[e+1], config_list[e].text());
|
2015-02-20 11:12:00 +01:00
|
|
|
|
var zipped = zip.generate({type:'blob'});
|
|
|
|
|
saveAs(zipped, $button.attr('download'));
|
|
|
|
|
return false;
|
|
|
|
|
})
|
|
|
|
|
.css({visibility:'visible'});
|
|
|
|
|
},
|
|
|
|
|
|
2015-02-07 08:46:16 +01:00
|
|
|
|
/**
|
|
|
|
|
* Init the boards array from a boards.h file
|
|
|
|
|
*/
|
2015-02-05 20:14:31 +01:00
|
|
|
|
initBoardsFromText: function(txt) {
|
|
|
|
|
boards_list = {};
|
2015-02-06 04:30:11 +01:00
|
|
|
|
var r, findDef = new RegExp('[ \\t]*#define[ \\t]+(BOARD_[\\w_]+)[ \\t]+(\\d+)[ \\t]*(//[ \\t]*)?(.+)?', 'gm');
|
2015-02-05 20:14:31 +01:00
|
|
|
|
while((r = findDef.exec(txt)) !== null) {
|
|
|
|
|
boards_list[r[1]] = r[2].prePad(3, ' ') + " — " + r[4].replace(/\).*/, ')');
|
|
|
|
|
}
|
2015-02-09 14:07:05 +01:00
|
|
|
|
this.log("Loaded boards:\n" + Object.keys(boards_list).join('\n'), 3);
|
2015-02-07 08:46:16 +01:00
|
|
|
|
has_boards = true;
|
2015-02-05 20:14:31 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-07 08:46:16 +01:00
|
|
|
|
/**
|
|
|
|
|
* Init the thermistors array from the Configuration.h file
|
|
|
|
|
*/
|
2015-03-01 07:40:20 +01:00
|
|
|
|
initThermistorList: function(txt) {
|
2015-02-05 20:14:31 +01:00
|
|
|
|
// Get all the thermistors and save them into an object
|
|
|
|
|
var r, s, findDef = new RegExp('(//.*\n)+\\s+(#define[ \\t]+TEMP_SENSOR_0)', 'g');
|
|
|
|
|
r = findDef.exec(txt);
|
|
|
|
|
findDef = new RegExp('^//[ \\t]*([-\\d]+)[ \\t]+is[ \\t]+(.*)[ \\t]*$', 'gm');
|
|
|
|
|
while((s = findDef.exec(r[0])) !== null) {
|
|
|
|
|
therms_list[s[1]] = s[1].prePad(4, ' ') + " — " + s[2];
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2015-02-09 13:34:57 +01:00
|
|
|
|
/**
|
2015-03-06 17:48:53 +01:00
|
|
|
|
* Get all the unique define names, building lists that will be used
|
|
|
|
|
* when gathering info about each define.
|
|
|
|
|
*
|
|
|
|
|
* define_list[c][j] : Define names in each config (in order of occurrence)
|
|
|
|
|
* define_section[name] : Section where define should appear in the form
|
|
|
|
|
* define_occur[c][name][i] : Lines in each config where the same define occurs
|
|
|
|
|
* .cindex Config file index
|
|
|
|
|
* .lineNum Line number of the occurrence
|
|
|
|
|
* .line The occurrence line
|
2015-02-09 13:34:57 +01:00
|
|
|
|
*/
|
2015-03-02 14:23:36 +01:00
|
|
|
|
initDefineList: function(cindex) {
|
2015-02-20 11:12:00 +01:00
|
|
|
|
var section = 'hidden',
|
|
|
|
|
leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'],
|
2015-02-15 08:44:01 +01:00
|
|
|
|
define_sect = {},
|
2015-03-06 17:48:53 +01:00
|
|
|
|
occ_list = {},
|
2015-03-02 14:23:36 +01:00
|
|
|
|
txt = config_list[cindex].text(),
|
2015-03-06 17:48:53 +01:00
|
|
|
|
r, findDef = new RegExp('^.*(@section|#define)[ \\t]+(\\w+).*$', 'gm');
|
2015-02-09 13:34:57 +01:00
|
|
|
|
while((r = findDef.exec(txt)) !== null) {
|
2015-02-15 08:44:01 +01:00
|
|
|
|
var name = r[2];
|
2015-03-06 17:48:53 +01:00
|
|
|
|
if (r[1] == '@section') {
|
2015-02-15 08:44:01 +01:00
|
|
|
|
section = name;
|
2015-03-06 17:48:53 +01:00
|
|
|
|
}
|
|
|
|
|
else if ($.inArray(name, leave_out_defines) < 0) {
|
|
|
|
|
var lineNum = txt.lineCount(r.index),
|
|
|
|
|
inst = { cindex:cindex, lineNum:lineNum, line:r[0] },
|
|
|
|
|
in_sect = (name in define_sect);
|
|
|
|
|
if (!in_sect) {
|
|
|
|
|
occ_list[name] = [ inst ];
|
|
|
|
|
}
|
|
|
|
|
if (!(name in define_section) && !in_sect) {
|
|
|
|
|
define_sect[name] = section; // new first-time define
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
occ_list[name].push(inst);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-09 13:34:57 +01:00
|
|
|
|
}
|
2015-03-02 14:23:36 +01:00
|
|
|
|
define_list[cindex] = Object.keys(define_sect);
|
2015-03-06 17:48:53 +01:00
|
|
|
|
define_occur[cindex] = occ_list;
|
2015-02-15 08:44:01 +01:00
|
|
|
|
$.extend(define_section, define_sect);
|
2015-03-02 14:23:36 +01:00
|
|
|
|
this.log(define_list[cindex], 2);
|
2015-03-06 17:48:53 +01:00
|
|
|
|
this.log(occ_list, 2);
|
|
|
|
|
this.log(define_sect, 2);
|
2015-02-09 13:34:57 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-03-02 10:45:53 +01:00
|
|
|
|
/**
|
|
|
|
|
* Find the defines in one of the configs that are just variants.
|
|
|
|
|
* Group them together for form-building and other uses.
|
2015-03-06 17:48:53 +01:00
|
|
|
|
*
|
|
|
|
|
* define_groups[c][name]
|
|
|
|
|
* .pattern regexp matching items in the group
|
|
|
|
|
* .title title substitution
|
|
|
|
|
* .count number of items in the group
|
2015-03-02 10:45:53 +01:00
|
|
|
|
*/
|
2015-03-02 14:23:36 +01:00
|
|
|
|
refreshDefineGroups: function(cindex) {
|
2015-03-06 17:48:53 +01:00
|
|
|
|
var findDef = /^(|.*_)(([XYZE](MAX|MIN))|(E[0-3]|[XYZE01234])|MAX|MIN|(bed)?K[pid]|HOTEND|HPB|JAPAN|WESTERN|LEFT|RIGHT|BACK|FRONT|[XYZ]_POINT)(_.*|)$/i;
|
2015-03-02 10:45:53 +01:00
|
|
|
|
var match_prev, patt, title, nameList, groups = {}, match_section;
|
2015-03-02 14:23:36 +01:00
|
|
|
|
$.each(define_list[cindex], function(i, name) {
|
2015-03-02 10:45:53 +01:00
|
|
|
|
if (match_prev) {
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (match_prev.exec(name) && define_section[name] == match_section) {
|
|
|
|
|
nameList.push(name);
|
2015-03-02 10:45:53 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (nameList.length > 1) {
|
2015-03-02 14:23:36 +01:00
|
|
|
|
$.each(nameList, function(i,n){
|
|
|
|
|
groups[n] = {
|
2015-03-02 10:45:53 +01:00
|
|
|
|
pattern: patt,
|
|
|
|
|
title: title,
|
|
|
|
|
count: nameList.length
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
match_prev = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!match_prev) {
|
2015-03-02 14:23:36 +01:00
|
|
|
|
var r = findDef.exec(name);
|
2015-03-02 10:45:53 +01:00
|
|
|
|
if (r != null) {
|
2015-03-06 17:48:53 +01:00
|
|
|
|
title = '';
|
|
|
|
|
switch(r[2].toUpperCase()) {
|
2015-03-02 10:45:53 +01:00
|
|
|
|
case '0':
|
|
|
|
|
patt = '([0123])';
|
|
|
|
|
title = 'N';
|
|
|
|
|
break;
|
|
|
|
|
case 'X':
|
|
|
|
|
patt = '([XYZE])';
|
|
|
|
|
title = 'AXIS';
|
|
|
|
|
break;
|
|
|
|
|
case 'E0':
|
|
|
|
|
patt = 'E([0-3])';
|
|
|
|
|
title = 'E';
|
|
|
|
|
break;
|
2015-03-06 17:48:53 +01:00
|
|
|
|
case 'BEDKP':
|
2015-03-02 10:45:53 +01:00
|
|
|
|
patt = 'bed(K[pid])';
|
|
|
|
|
title = 'BED_PID';
|
|
|
|
|
break;
|
2015-03-06 17:48:53 +01:00
|
|
|
|
case 'KP':
|
2015-03-02 10:45:53 +01:00
|
|
|
|
patt = '(K[pid])';
|
|
|
|
|
title = 'PID';
|
|
|
|
|
break;
|
2015-03-06 17:48:53 +01:00
|
|
|
|
case 'LEFT':
|
|
|
|
|
case 'RIGHT':
|
|
|
|
|
case 'BACK':
|
|
|
|
|
case 'FRONT':
|
|
|
|
|
patt = '([LRBF])(EFT|IGHT|ACK|RONT)';
|
|
|
|
|
break;
|
2015-03-02 10:45:53 +01:00
|
|
|
|
case 'MAX':
|
|
|
|
|
case 'MIN':
|
|
|
|
|
patt = '(MAX|MIN)';
|
2015-03-06 17:48:53 +01:00
|
|
|
|
break;
|
|
|
|
|
case 'HOTEND':
|
|
|
|
|
case 'HPB':
|
|
|
|
|
patt = '(HOTEND|HPB)';
|
|
|
|
|
break;
|
|
|
|
|
case 'JAPAN':
|
|
|
|
|
case 'WESTERN':
|
|
|
|
|
patt = '(JAPAN|WESTERN)';
|
2015-03-02 10:45:53 +01:00
|
|
|
|
break;
|
|
|
|
|
case 'XMIN':
|
|
|
|
|
case 'XMAX':
|
|
|
|
|
patt = '([XYZ])'+r[4];
|
|
|
|
|
title = 'XYZ_'+r[4];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
patt = null;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (patt) {
|
|
|
|
|
patt = '^' + r[1] + patt + r[7] + '$';
|
|
|
|
|
title = r[1] + title + r[7];
|
2015-03-06 17:48:53 +01:00
|
|
|
|
match_prev = new RegExp(patt, 'i');
|
2015-03-02 14:23:36 +01:00
|
|
|
|
match_section = define_section[name];
|
|
|
|
|
nameList = [ name ];
|
2015-03-02 10:45:53 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-03-02 14:23:36 +01:00
|
|
|
|
define_groups[cindex] = groups;
|
2015-03-06 17:48:53 +01:00
|
|
|
|
this.log(define_groups[cindex], 2);
|
2015-03-02 10:45:53 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-03-01 07:40:20 +01:00
|
|
|
|
/**
|
2015-03-06 17:48:53 +01:00
|
|
|
|
* Get all conditional blocks and their line ranges
|
|
|
|
|
* and store them in the dependent_groups list.
|
|
|
|
|
*
|
|
|
|
|
* dependent_groups[condition][i]
|
|
|
|
|
*
|
|
|
|
|
* .cindex config file index
|
|
|
|
|
* .start starting line
|
|
|
|
|
* .end ending line
|
|
|
|
|
*
|
2015-03-01 07:40:20 +01:00
|
|
|
|
*/
|
|
|
|
|
initDependentGroups: function() {
|
2015-03-02 10:45:53 +01:00
|
|
|
|
var findBlock = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm,
|
2015-03-01 07:40:20 +01:00
|
|
|
|
leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'];
|
2015-03-06 17:48:53 +01:00
|
|
|
|
dependent_groups = {};
|
2015-03-02 14:23:36 +01:00
|
|
|
|
$.each(config_list, function(i, $v) {
|
2015-03-01 07:40:20 +01:00
|
|
|
|
var ifStack = [];
|
|
|
|
|
var r, txt = $v.text();
|
2015-03-02 10:45:53 +01:00
|
|
|
|
while((r = findBlock.exec(txt)) !== null) {
|
2015-03-06 17:48:53 +01:00
|
|
|
|
var lineNum = txt.lineCount(r.index);
|
2015-03-01 07:40:20 +01:00
|
|
|
|
var code = r[2].replace(/[ \t]*\/\/.*$/, '');
|
|
|
|
|
switch(r[1]) {
|
|
|
|
|
case 'if':
|
|
|
|
|
var code = code
|
|
|
|
|
.replace(/([A-Z][A-Z0-9_]+)/g, 'self.defineValue("$1")')
|
|
|
|
|
.replace(/defined[ \t]*\(?[ \t]*self.defineValue\(("[A-Z][A-Z0-9_]+")\)[ \t]*\)?/g, 'self.defineIsEnabled($1)');
|
|
|
|
|
ifStack.push(['('+code+')', lineNum]); // #if starts on next line
|
|
|
|
|
self.log("push if " + code, 4);
|
|
|
|
|
break;
|
|
|
|
|
case 'ifdef':
|
|
|
|
|
if ($.inArray(code, leave_out_defines) < 0) {
|
|
|
|
|
ifStack.push(['self.defineIsEnabled("' + code + '")', lineNum]);
|
|
|
|
|
self.log("push ifdef " + code, 4);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ifStack.push(0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'ifndef':
|
|
|
|
|
if ($.inArray(code, leave_out_defines) < 0) {
|
|
|
|
|
ifStack.push(['!self.defineIsEnabled("' + code + '")', lineNum]);
|
|
|
|
|
self.log("push ifndef " + code, 4);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ifStack.push(0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'else':
|
|
|
|
|
case 'endif':
|
|
|
|
|
var c = ifStack.pop();
|
|
|
|
|
if (c) {
|
|
|
|
|
var cond = c[0], line = c[1];
|
|
|
|
|
self.log("pop " + c[0], 4);
|
2015-03-06 17:48:53 +01:00
|
|
|
|
if (dependent_groups[cond] === undefined) dependent_groups[cond] = [];
|
|
|
|
|
dependent_groups[cond].push({cindex:i,start:line,end:lineNum});
|
2015-03-01 07:40:20 +01:00
|
|
|
|
if (r[1] == 'else') {
|
|
|
|
|
// Reverse the condition
|
|
|
|
|
cond = (cond.indexOf('!') === 0) ? cond.substr(1) : ('!'+cond);
|
|
|
|
|
ifStack.push([cond, lineNum]);
|
|
|
|
|
self.log("push " + cond, 4);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (r[1] == 'else') ifStack.push(0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}); // text blobs loop
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Init all the defineInfo structures after reload
|
|
|
|
|
* The "enabled" field may need an update for newly-loaded dependencies
|
|
|
|
|
*/
|
|
|
|
|
initDefineInfo: function() {
|
|
|
|
|
$.each(define_list, function(e,def_list){
|
2015-03-02 14:23:36 +01:00
|
|
|
|
$.each(def_list, function(i, name) {
|
|
|
|
|
define_info[name] = self.getDefineInfo(name, e);
|
2015-03-01 07:40:20 +01:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2015-02-09 13:34:57 +01:00
|
|
|
|
/**
|
2015-03-02 10:45:53 +01:00
|
|
|
|
* Create fields for defines in a config that have none
|
|
|
|
|
* Use define_groups data to group fields together
|
2015-02-09 13:34:57 +01:00
|
|
|
|
*/
|
2015-03-02 14:23:36 +01:00
|
|
|
|
createFieldsForDefines: function(cindex) {
|
|
|
|
|
// var n = 0;
|
|
|
|
|
var grouping = false, group = define_groups[cindex],
|
|
|
|
|
g_pattern, g_regex, g_subitem, g_section, g_class,
|
|
|
|
|
fail_list = [];
|
|
|
|
|
$.each(define_list[cindex], function(i, name) {
|
2015-02-15 08:44:01 +01:00
|
|
|
|
var section = define_section[name];
|
|
|
|
|
if (section != 'hidden' && !$('#'+name).length) {
|
2015-03-01 07:40:20 +01:00
|
|
|
|
var inf = define_info[name];
|
2015-02-15 08:44:01 +01:00
|
|
|
|
|
2015-02-09 13:34:57 +01:00
|
|
|
|
if (inf) {
|
2015-02-15 08:44:01 +01:00
|
|
|
|
|
2015-03-02 10:45:53 +01:00
|
|
|
|
var label_text = name, sublabel;
|
|
|
|
|
|
|
|
|
|
// Is this field in a sequence?
|
|
|
|
|
// Then see if it's the second or after
|
|
|
|
|
if (grouping) {
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (name in group && g_pattern == group[name].pattern && g_section == section) {
|
|
|
|
|
g_subitem = true;
|
|
|
|
|
sublabel = g_regex.exec(name)[1];
|
2015-03-02 10:45:53 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
grouping = false;
|
|
|
|
|
}
|
|
|
|
|
// Start grouping?
|
|
|
|
|
if (!grouping && name in group) {
|
|
|
|
|
grouping = true;
|
2015-03-02 14:23:36 +01:00
|
|
|
|
g_subitem = false;
|
2015-03-02 10:45:53 +01:00
|
|
|
|
var grp = group[name];
|
2015-03-06 17:48:53 +01:00
|
|
|
|
g_section = section;
|
2015-03-02 14:23:36 +01:00
|
|
|
|
g_class = 'one_of_' + grp.count;
|
2015-03-06 17:48:53 +01:00
|
|
|
|
g_pattern = grp.pattern;
|
|
|
|
|
g_regex = new RegExp(g_pattern, 'i');
|
2015-03-02 10:45:53 +01:00
|
|
|
|
label_text = grp.title;
|
2015-03-02 14:23:36 +01:00
|
|
|
|
sublabel = g_regex.exec(name)[1];
|
2015-03-02 10:45:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-15 08:44:01 +01:00
|
|
|
|
var $ff = $('#'+section), $newfield,
|
2015-03-02 10:45:53 +01:00
|
|
|
|
avail = eval(inf.enabled);
|
|
|
|
|
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (!(grouping && g_subitem)) {
|
2015-03-02 10:45:53 +01:00
|
|
|
|
|
|
|
|
|
var $newlabel = $('<label>',{for:name,class:'added'}).text(label_text.toLabel());
|
2015-02-15 08:44:01 +01:00
|
|
|
|
|
2015-03-02 10:45:53 +01:00
|
|
|
|
$newlabel.unblock(avail);
|
2015-03-01 07:40:20 +01:00
|
|
|
|
|
2015-03-02 10:45:53 +01:00
|
|
|
|
// if (!(++n % 3))
|
|
|
|
|
$newlabel.addClass('newline');
|
2015-02-13 12:02:56 +01:00
|
|
|
|
|
2015-03-02 10:45:53 +01:00
|
|
|
|
$ff.append($newlabel);
|
|
|
|
|
|
|
|
|
|
}
|
2015-02-15 08:44:01 +01:00
|
|
|
|
|
|
|
|
|
// Multiple fields?
|
|
|
|
|
if (inf.type == 'list') {
|
|
|
|
|
for (var i=0; i<inf.size; i++) {
|
|
|
|
|
var fieldname = i > 0 ? name+'-'+i : name;
|
2015-03-02 10:45:53 +01:00
|
|
|
|
$newfield = $('<input>',{type:'text',size:6,maxlength:10,id:fieldname,name:fieldname,class:'subitem added',disabled:!avail}).unblock(avail);
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (grouping) $newfield.addClass(g_class);
|
2015-02-15 08:44:01 +01:00
|
|
|
|
$ff.append($newfield);
|
|
|
|
|
}
|
2015-02-13 12:02:56 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2015-02-15 08:44:01 +01:00
|
|
|
|
// Items with options, either toggle or select
|
|
|
|
|
// TODO: Radio buttons for other values
|
|
|
|
|
if (inf.options !== undefined) {
|
|
|
|
|
if (inf.type == 'toggle') {
|
|
|
|
|
$newfield = $('<input>',{type:'checkbox'});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Otherwise selectable
|
|
|
|
|
$newfield = $('<select>');
|
|
|
|
|
}
|
|
|
|
|
// ...Options added when field initialized
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$newfield = inf.type == 'switch' ? $('<input>',{type:'checkbox'}) : $('<input>',{type:'text',size:10,maxlength:40});
|
|
|
|
|
}
|
2015-03-02 10:45:53 +01:00
|
|
|
|
$newfield.attr({id:name,name:name,class:'added',disabled:!avail}).unblock(avail);
|
|
|
|
|
if (grouping) {
|
2015-03-02 14:23:36 +01:00
|
|
|
|
$newfield.addClass(g_class);
|
2015-03-06 17:48:53 +01:00
|
|
|
|
if (sublabel) {
|
2015-03-02 14:23:36 +01:00
|
|
|
|
$ff.append($('<label>',{class:'added sublabel',for:name}).text(sublabel.toTitleCase()).unblock(avail));
|
2015-03-06 17:48:53 +01:00
|
|
|
|
}
|
2015-03-02 10:45:53 +01:00
|
|
|
|
}
|
2015-02-15 08:44:01 +01:00
|
|
|
|
// Add the new field to the form
|
|
|
|
|
$ff.append($newfield);
|
2015-02-13 12:02:56 +01:00
|
|
|
|
}
|
2015-02-09 13:34:57 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
fail_list.push(name);
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (fail_list.length) this.log('Unable to parse:\n' + fail_list.join('\n'), 2);
|
2015-02-09 13:34:57 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-07 08:46:16 +01:00
|
|
|
|
/**
|
|
|
|
|
* Handle a file being dropped on the file field
|
|
|
|
|
*/
|
|
|
|
|
handleFileLoad: function(txt, $uploader) {
|
|
|
|
|
txt += '';
|
2015-02-05 20:14:31 +01:00
|
|
|
|
var filename = $uploader.val().replace(/.*[\/\\](.*)$/, '$1');
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if ($.inArray(filename, config_file_list))
|
|
|
|
|
this.fileLoaded(filename, txt);
|
|
|
|
|
else
|
|
|
|
|
this.setMessage("Can't parse '"+filename+"'!");
|
2015-02-07 08:46:16 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-07 15:20:04 +01:00
|
|
|
|
/**
|
|
|
|
|
* Process a file after it's been successfully loaded
|
|
|
|
|
*/
|
2015-03-02 14:23:36 +01:00
|
|
|
|
fileLoaded: function(filename, txt, wait) {
|
2015-02-07 08:46:16 +01:00
|
|
|
|
this.log("fileLoaded:"+filename,4);
|
2015-03-02 14:23:36 +01:00
|
|
|
|
var err, cindex;
|
2015-02-07 08:46:16 +01:00
|
|
|
|
switch(filename) {
|
|
|
|
|
case boards_file:
|
|
|
|
|
this.initBoardsFromText(txt);
|
2015-02-05 20:14:31 +01:00
|
|
|
|
$('#MOTHERBOARD').html('').addOptions(boards_list);
|
2015-02-07 02:57:31 +01:00
|
|
|
|
if (has_config) this.initField('MOTHERBOARD');
|
|
|
|
|
break;
|
|
|
|
|
case config_file:
|
|
|
|
|
if (has_boards) {
|
2015-02-07 08:46:16 +01:00
|
|
|
|
$config.text(txt);
|
2015-02-07 09:46:14 +01:00
|
|
|
|
total_config_lines = txt.lineCount();
|
2015-03-01 07:40:20 +01:00
|
|
|
|
// this.initThermistorList(txt);
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (!wait) cindex = 0;
|
2015-02-07 08:46:16 +01:00
|
|
|
|
has_config = true;
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (has_config_adv) {
|
2015-02-20 11:12:00 +01:00
|
|
|
|
this.activateDownloadAllLink();
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (wait) cindex = 2;
|
|
|
|
|
}
|
2015-02-07 02:57:31 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2015-02-09 13:34:57 +01:00
|
|
|
|
err = boards_file;
|
2015-02-07 02:57:31 +01:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case config_adv_file:
|
|
|
|
|
if (has_config) {
|
2015-02-07 08:46:16 +01:00
|
|
|
|
$config_adv.text(txt);
|
2015-02-07 09:46:14 +01:00
|
|
|
|
total_config_adv_lines = txt.lineCount();
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (!wait) cindex = 1;
|
2015-02-07 08:46:16 +01:00
|
|
|
|
has_config_adv = true;
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (has_config) {
|
2015-02-20 11:12:00 +01:00
|
|
|
|
this.activateDownloadAllLink();
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (wait) cindex = 2;
|
|
|
|
|
}
|
2015-02-07 02:57:31 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2015-02-09 13:34:57 +01:00
|
|
|
|
err = config_file;
|
2015-02-07 02:57:31 +01:00
|
|
|
|
}
|
2015-02-05 20:14:31 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2015-03-01 07:40:20 +01:00
|
|
|
|
// When a config file loads defines need update
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (cindex != null) this.prepareConfigData(cindex);
|
|
|
|
|
|
|
|
|
|
this.setMessage(err
|
|
|
|
|
? 'Please upload a "' + boards_file + '" file first!'
|
|
|
|
|
: '"' + filename + '" loaded successfully.', err ? 'error' : 'message'
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
prepareConfigData: function(cindex) {
|
|
|
|
|
var inds = (cindex == 2) ? [ 0, 1 ] : [ cindex ];
|
|
|
|
|
$.each(inds, function(i,e){
|
2015-03-01 07:40:20 +01:00
|
|
|
|
// Purge old fields from the form, clear the define list
|
2015-03-02 14:23:36 +01:00
|
|
|
|
self.purgeAddedFields(e);
|
2015-03-01 07:40:20 +01:00
|
|
|
|
// Build the define_list
|
2015-03-02 14:23:36 +01:00
|
|
|
|
self.initDefineList(e);
|
2015-02-20 11:12:00 +01:00
|
|
|
|
// TODO: Find sequential names and group them
|
|
|
|
|
// Allows related settings to occupy one line in the form
|
2015-03-02 14:23:36 +01:00
|
|
|
|
self.refreshDefineGroups(e);
|
|
|
|
|
});
|
|
|
|
|
// Build the dependent defines list
|
|
|
|
|
this.initDependentGroups(); // all config text
|
|
|
|
|
// Get define_info for all known defines
|
|
|
|
|
this.initDefineInfo(); // all config text
|
|
|
|
|
$.each(inds, function(i,e){
|
2015-03-01 07:40:20 +01:00
|
|
|
|
// Create new fields
|
2015-03-02 14:23:36 +01:00
|
|
|
|
self.createFieldsForDefines(e); // create new fields
|
2015-03-01 07:40:20 +01:00
|
|
|
|
// Init the fields, set values, etc
|
2015-03-02 14:23:36 +01:00
|
|
|
|
self.refreshConfigForm(e);
|
|
|
|
|
self.activateDownloadLink(e);
|
|
|
|
|
});
|
2015-02-05 20:14:31 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-07 08:46:16 +01:00
|
|
|
|
/**
|
2015-02-13 12:02:56 +01:00
|
|
|
|
* Add initial enhancements to the existing form
|
2015-02-07 08:46:16 +01:00
|
|
|
|
*/
|
|
|
|
|
initConfigForm: function() {
|
2015-02-05 16:05:29 +01:00
|
|
|
|
// Modify form fields and make the form responsive.
|
|
|
|
|
// As values change on the form, we could update the
|
|
|
|
|
// contents of text areas containing the configs, for
|
|
|
|
|
// example.
|
|
|
|
|
|
|
|
|
|
// while(!$config_adv.text() == null) {}
|
|
|
|
|
// while(!$config.text() == null) {}
|
|
|
|
|
|
|
|
|
|
// Go through all form items with names
|
2015-02-09 13:34:57 +01:00
|
|
|
|
$form.find('[name]').each(function() {
|
2015-02-05 16:05:29 +01:00
|
|
|
|
// Set its id to its name
|
|
|
|
|
var name = $(this).attr('name');
|
|
|
|
|
$(this).attr({id: name});
|
|
|
|
|
// Attach its label sibling
|
2015-02-07 15:20:04 +01:00
|
|
|
|
var $label = $(this).prev('label');
|
|
|
|
|
if ($label.length) $label.attr('for',name);
|
2015-02-05 16:05:29 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Get all 'switchable' class items and add a checkbox
|
2015-02-15 08:44:01 +01:00
|
|
|
|
// $form.find('.switchable').each(function(){
|
|
|
|
|
// $(this).after(
|
|
|
|
|
// $('<input>',{type:'checkbox',value:'1',class:'enabler added'})
|
|
|
|
|
// .prop('checked',true)
|
|
|
|
|
// .attr('id',this.id + '-switch')
|
|
|
|
|
// .change(self.handleSwitch)
|
|
|
|
|
// );
|
|
|
|
|
// });
|
2015-02-05 16:05:29 +01:00
|
|
|
|
|
2015-02-07 08:46:16 +01:00
|
|
|
|
// Add options to the popup menus
|
2015-02-13 12:02:56 +01:00
|
|
|
|
// $('#SERIAL_PORT').addOptions([0,1,2,3,4,5,6,7]);
|
|
|
|
|
// $('#BAUDRATE').addOptions([2400,9600,19200,38400,57600,115200,250000]);
|
|
|
|
|
// $('#EXTRUDERS').addOptions([1,2,3,4]);
|
|
|
|
|
// $('#POWER_SUPPLY').addOptions({'1':'ATX','2':'Xbox 360'});
|
2015-02-05 20:14:31 +01:00
|
|
|
|
|
2015-02-07 08:46:16 +01:00
|
|
|
|
// Replace the Serial popup menu with a stepper control
|
2015-02-13 12:02:56 +01:00
|
|
|
|
/*
|
2015-02-07 02:57:31 +01:00
|
|
|
|
$('#serial_stepper').jstepper({
|
|
|
|
|
min: 0,
|
2015-02-07 08:46:16 +01:00
|
|
|
|
max: 3,
|
2015-02-07 02:57:31 +01:00
|
|
|
|
val: $('#SERIAL_PORT').val(),
|
|
|
|
|
arrowWidth: '18px',
|
|
|
|
|
arrowHeight: '15px',
|
|
|
|
|
color: '#FFF',
|
|
|
|
|
acolor: '#F70',
|
|
|
|
|
hcolor: '#FF0',
|
|
|
|
|
id: 'select-me',
|
|
|
|
|
textStyle: {width:'1.5em',fontSize:'120%',textAlign:'center'},
|
|
|
|
|
onChange: function(v) { $('#SERIAL_PORT').val(v).trigger('change'); }
|
|
|
|
|
});
|
2015-02-13 12:02:56 +01:00
|
|
|
|
*/
|
2015-02-05 20:14:31 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-09 13:34:57 +01:00
|
|
|
|
/**
|
|
|
|
|
* Make tabs to switch between fieldsets
|
|
|
|
|
*/
|
|
|
|
|
makeTabsForFieldsets: function() {
|
|
|
|
|
// Make tabs for the fieldsets
|
2015-02-13 12:02:56 +01:00
|
|
|
|
var $fset = $form.find('fieldset'),
|
|
|
|
|
$tabs = $('<ul>',{class:'tabs'}),
|
|
|
|
|
ind = 1;
|
2015-02-09 13:34:57 +01:00
|
|
|
|
$fset.each(function(){
|
|
|
|
|
var tabID = 'TAB'+ind;
|
|
|
|
|
$(this).addClass(tabID);
|
|
|
|
|
var $leg = $(this).find('legend');
|
|
|
|
|
var $link = $('<a>',{href:'#'+ind,id:tabID}).text($leg.text());
|
|
|
|
|
$tabs.append($('<li>').append($link));
|
|
|
|
|
$link.click(function(e){
|
|
|
|
|
e.preventDefault;
|
|
|
|
|
var ind = this.id;
|
|
|
|
|
$tabs.find('.active').removeClass('active');
|
|
|
|
|
$(this).addClass('active');
|
|
|
|
|
$fset.hide();
|
|
|
|
|
$fset.filter('.'+this.id).show();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
ind++;
|
|
|
|
|
});
|
|
|
|
|
$('#tabs').html('').append($tabs);
|
|
|
|
|
$('<br>',{class:'clear'}).appendTo('#tabs');
|
|
|
|
|
$tabs.find('a:first').trigger('click');
|
|
|
|
|
},
|
|
|
|
|
|
2015-02-07 15:20:04 +01:00
|
|
|
|
/**
|
|
|
|
|
* Update all fields on the form after loading a configuration
|
|
|
|
|
*/
|
2015-03-02 14:23:36 +01:00
|
|
|
|
refreshConfigForm: function(cindex) {
|
2015-02-05 20:14:31 +01:00
|
|
|
|
|
2015-02-05 16:05:29 +01:00
|
|
|
|
/**
|
2015-02-09 13:34:57 +01:00
|
|
|
|
* Any manually-created form elements will remain
|
|
|
|
|
* where they are. Unknown defines (currently most)
|
2015-02-15 08:44:01 +01:00
|
|
|
|
* are added to tabs based on section
|
2015-02-05 16:05:29 +01:00
|
|
|
|
*
|
2015-02-09 13:34:57 +01:00
|
|
|
|
* Specific exceptions can be managed by applying
|
|
|
|
|
* classes to the associated form fields.
|
|
|
|
|
* Sorting and arrangement can come from an included
|
2015-02-13 12:02:56 +01:00
|
|
|
|
* Javascript file that describes the configuration
|
|
|
|
|
* in JSON, or using information added to the config
|
|
|
|
|
* files.
|
2015-02-05 16:05:29 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2015-02-13 12:02:56 +01:00
|
|
|
|
// Refresh the motherboard menu with new options
|
2015-02-07 02:57:31 +01:00
|
|
|
|
$('#MOTHERBOARD').html('').addOptions(boards_list);
|
2015-02-05 16:05:29 +01:00
|
|
|
|
|
2015-03-01 07:40:20 +01:00
|
|
|
|
// Init all existing fields, getting define info for those that need it
|
2015-02-13 12:02:56 +01:00
|
|
|
|
// refreshing the options and updating their current values
|
2015-03-02 14:23:36 +01:00
|
|
|
|
$.each(define_list[cindex], function(i, name) {
|
|
|
|
|
if ($('#'+name).length) {
|
|
|
|
|
self.initField(name);
|
|
|
|
|
self.initFieldValue(name);
|
2015-03-01 07:40:20 +01:00
|
|
|
|
}
|
2015-02-13 12:02:56 +01:00
|
|
|
|
else
|
2015-03-02 14:23:36 +01:00
|
|
|
|
self.log(name + " is not on the page yet.", 2);
|
2015-02-13 12:02:56 +01:00
|
|
|
|
});
|
2015-03-01 07:40:20 +01:00
|
|
|
|
|
|
|
|
|
// Set enabled state based on dependencies
|
|
|
|
|
// this.enableForDependentConditions();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2015-03-06 17:48:53 +01:00
|
|
|
|
* Enable / disable fields in dependent groups
|
|
|
|
|
* based on their dependencies.
|
2015-03-01 07:40:20 +01:00
|
|
|
|
*/
|
|
|
|
|
refreshDependentFields: function() {
|
|
|
|
|
$.each(define_list, function(e,def_list){
|
2015-03-02 14:23:36 +01:00
|
|
|
|
$.each(def_list, function(i, name) {
|
|
|
|
|
var inf = define_info[name];
|
2015-03-01 07:40:20 +01:00
|
|
|
|
if (inf && inf.enabled != 'true') {
|
2015-03-02 14:23:36 +01:00
|
|
|
|
var $elm = $('#'+name), ena = eval(inf.enabled);
|
|
|
|
|
var isEnabled = (inf.type == 'switch') || self.defineIsEnabled(name);
|
|
|
|
|
$('#'+name+'-switch').attr('disabled', !ena);
|
2015-03-02 10:45:53 +01:00
|
|
|
|
$elm.attr('disabled', !(ena && isEnabled)).unblock(ena);
|
2015-03-02 14:23:36 +01:00
|
|
|
|
$('label[for="'+name+'"]').unblock(ena);
|
2015-03-01 07:40:20 +01:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-02-07 08:46:16 +01:00
|
|
|
|
},
|
2015-02-05 20:44:43 +01:00
|
|
|
|
|
2015-02-06 04:30:11 +01:00
|
|
|
|
/**
|
2015-03-02 14:23:36 +01:00
|
|
|
|
* Make a field responsive, tooltip its label(s), add enabler if needed
|
2015-02-06 04:30:11 +01:00
|
|
|
|
*/
|
2015-03-01 07:40:20 +01:00
|
|
|
|
initField: function(name) {
|
2015-02-07 08:46:16 +01:00
|
|
|
|
this.log("initField:"+name,4);
|
2015-03-01 07:40:20 +01:00
|
|
|
|
var $elm = $('#'+name), inf = define_info[name];
|
|
|
|
|
$elm[0].defineInfo = inf;
|
2015-02-13 12:02:56 +01:00
|
|
|
|
|
2015-02-15 08:44:01 +01:00
|
|
|
|
// Create a tooltip on the label if there is one
|
2015-02-13 12:02:56 +01:00
|
|
|
|
if (inf.tooltip) {
|
2015-03-02 14:23:36 +01:00
|
|
|
|
// label for the item
|
|
|
|
|
var $tipme = $('label[for="'+name+'"]');
|
2015-02-13 12:02:56 +01:00
|
|
|
|
if ($tipme.length) {
|
|
|
|
|
$tipme.unbind('mouseenter mouseleave');
|
|
|
|
|
$tipme.hover(
|
|
|
|
|
function() {
|
|
|
|
|
if ($('#tipson input').prop('checked')) {
|
2015-03-06 17:48:53 +01:00
|
|
|
|
var pos = $tipme.position(), px = $tipme.width()/2;
|
2015-02-13 12:02:56 +01:00
|
|
|
|
$tooltip.html(inf.tooltip)
|
|
|
|
|
.append('<span>')
|
2015-03-06 17:48:53 +01:00
|
|
|
|
.css({bottom:($tooltip.parent().outerHeight()-pos.top+10)+'px',left:(pos.left+px)+'px'})
|
2015-02-13 12:02:56 +01:00
|
|
|
|
.show();
|
|
|
|
|
if (hover_timer) {
|
|
|
|
|
clearTimeout(hover_timer);
|
2015-02-07 16:39:10 +01:00
|
|
|
|
hover_timer = null;
|
2015-02-13 12:02:56 +01:00
|
|
|
|
}
|
2015-02-07 16:39:10 +01:00
|
|
|
|
}
|
2015-02-13 12:02:56 +01:00
|
|
|
|
},
|
|
|
|
|
function() {
|
|
|
|
|
hover_timer = setTimeout(function(){
|
|
|
|
|
hover_timer = null;
|
|
|
|
|
$tooltip.fadeOut(400);
|
|
|
|
|
}, 400);
|
|
|
|
|
}
|
|
|
|
|
);
|
2015-02-07 15:20:04 +01:00
|
|
|
|
}
|
2015-02-06 04:30:11 +01:00
|
|
|
|
}
|
2015-02-13 12:02:56 +01:00
|
|
|
|
|
2015-02-15 08:44:01 +01:00
|
|
|
|
// Make the element(s) respond to events
|
|
|
|
|
if (inf.type == 'list') {
|
|
|
|
|
// Multiple fields need to respond
|
|
|
|
|
for (var i=0; i<inf.size; i++) {
|
|
|
|
|
if (i > 0) $elm = $('#'+name+'-'+i);
|
|
|
|
|
$elm.unbind('input');
|
|
|
|
|
$elm.on('input', this.handleChange);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var elmtype = $elm.attr('type');
|
|
|
|
|
// Set options on single fields if there are any
|
|
|
|
|
if (inf.options !== undefined && elmtype === undefined)
|
|
|
|
|
$elm.html('').addOptions(inf.options);
|
|
|
|
|
$elm.unbind('input change');
|
|
|
|
|
$elm.on(elmtype == 'text' ? 'input' : 'change', this.handleChange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add an enabler checkbox if it needs one
|
|
|
|
|
if (inf.switchable && $('#'+name+'-switch').length == 0) {
|
|
|
|
|
// $elm = the last element added
|
|
|
|
|
$elm.after(
|
|
|
|
|
$('<input>',{type:'checkbox',value:'1',class:'enabler added'})
|
|
|
|
|
.prop('checked',self.defineIsEnabled(name))
|
|
|
|
|
.attr({id: name+'-switch'})
|
|
|
|
|
.change(self.handleSwitch)
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-02-05 16:05:29 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-07 08:46:16 +01:00
|
|
|
|
/**
|
|
|
|
|
* Handle any value field being changed
|
2015-02-15 08:44:01 +01:00
|
|
|
|
* this = the field
|
2015-02-07 08:46:16 +01:00
|
|
|
|
*/
|
2015-03-01 07:40:20 +01:00
|
|
|
|
handleChange: function() {
|
|
|
|
|
self.updateDefineFromField(this.id);
|
|
|
|
|
self.refreshDependentFields();
|
|
|
|
|
},
|
2015-02-05 16:05:29 +01:00
|
|
|
|
|
2015-02-07 08:46:16 +01:00
|
|
|
|
/**
|
|
|
|
|
* Handle a switch checkbox being changed
|
2015-02-15 08:44:01 +01:00
|
|
|
|
* this = the switch checkbox
|
2015-02-07 08:46:16 +01:00
|
|
|
|
*/
|
|
|
|
|
handleSwitch: function() {
|
2015-02-15 08:44:01 +01:00
|
|
|
|
var $elm = $(this),
|
|
|
|
|
name = $elm[0].id.replace(/-.+/,''),
|
2015-03-01 07:40:20 +01:00
|
|
|
|
inf = define_info[name],
|
2015-02-15 08:44:01 +01:00
|
|
|
|
on = $elm.prop('checked') || false;
|
|
|
|
|
|
|
|
|
|
self.setDefineEnabled(name, on);
|
|
|
|
|
|
|
|
|
|
if (inf.type == 'list') {
|
|
|
|
|
// Multiple fields?
|
|
|
|
|
for (var i=0; i<inf.size; i++) {
|
|
|
|
|
$('#'+name+(i?'-'+i:'')).attr('disabled', !on);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$elm.prev().attr('disabled', !on);
|
|
|
|
|
}
|
2015-02-05 16:05:29 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-07 02:57:31 +01:00
|
|
|
|
/**
|
2015-03-06 17:48:53 +01:00
|
|
|
|
* Get the current value of a #define
|
2015-02-07 02:57:31 +01:00
|
|
|
|
*/
|
|
|
|
|
defineValue: function(name) {
|
|
|
|
|
this.log('defineValue:'+name,4);
|
2015-03-01 07:40:20 +01:00
|
|
|
|
var inf = define_info[name];
|
2015-02-07 08:46:16 +01:00
|
|
|
|
if (inf == null) return 'n/a';
|
2015-03-06 17:48:53 +01:00
|
|
|
|
var r = inf.regex.exec(inf.line), val = r[inf.val_i];
|
2015-02-07 02:57:31 +01:00
|
|
|
|
|
2015-03-06 17:48:53 +01:00
|
|
|
|
this.log(r,2);
|
2015-02-07 02:57:31 +01:00
|
|
|
|
|
2015-03-06 17:48:53 +01:00
|
|
|
|
return (inf.type == 'switch') ? (val === undefined || val.trim() != '//') : val;
|
2015-02-07 02:57:31 +01:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2015-03-06 17:48:53 +01:00
|
|
|
|
* Get the current enabled state of a #define
|
2015-02-07 02:57:31 +01:00
|
|
|
|
*/
|
|
|
|
|
defineIsEnabled: function(name) {
|
|
|
|
|
this.log('defineIsEnabled:'+name,4);
|
2015-03-01 07:40:20 +01:00
|
|
|
|
var inf = define_info[name];
|
2015-02-07 08:46:16 +01:00
|
|
|
|
if (inf == null) return false;
|
2015-03-06 17:48:53 +01:00
|
|
|
|
var r = inf.regex.exec(inf.line);
|
2015-02-07 02:57:31 +01:00
|
|
|
|
|
2015-03-06 17:48:53 +01:00
|
|
|
|
this.log(r,2);
|
2015-02-07 02:57:31 +01:00
|
|
|
|
|
2015-03-06 17:48:53 +01:00
|
|
|
|
var on = r[1] != null ? r[1].trim() != '//' : true;
|
2015-02-07 08:46:16 +01:00
|
|
|
|
this.log(name + ' = ' + on, 2);
|
2015-02-07 02:57:31 +01:00
|
|
|
|
|
|
|
|
|
return on;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a #define enabled or disabled by altering the config text
|
|
|
|
|
*/
|
2015-02-06 04:30:11 +01:00
|
|
|
|
setDefineEnabled: function(name, val) {
|
2015-02-07 02:57:31 +01:00
|
|
|
|
this.log('setDefineEnabled:'+name,4);
|
2015-03-01 07:40:20 +01:00
|
|
|
|
var inf = define_info[name];
|
2015-02-09 13:34:57 +01:00
|
|
|
|
if (inf) {
|
|
|
|
|
var slash = val ? '' : '//';
|
|
|
|
|
var newline = inf.line
|
|
|
|
|
.replace(/^([ \t]*)(\/\/)([ \t]*)/, '$1$3') // remove slashes
|
|
|
|
|
.replace(inf.pre+inf.define, inf.pre+slash+inf.define); // add them back
|
|
|
|
|
this.setDefineLine(name, newline);
|
|
|
|
|
}
|
2015-02-05 16:05:29 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-07 02:57:31 +01:00
|
|
|
|
/**
|
|
|
|
|
* Update a #define (from the form) by altering the config text
|
|
|
|
|
*/
|
|
|
|
|
updateDefineFromField: function(name) {
|
|
|
|
|
this.log('updateDefineFromField:'+name,4);
|
2015-02-15 08:44:01 +01:00
|
|
|
|
|
|
|
|
|
// Drop the suffix on sub-fields
|
|
|
|
|
name = name.replace(/-\d+$/, '');
|
|
|
|
|
|
2015-03-01 07:40:20 +01:00
|
|
|
|
var $elm = $('#'+name), inf = define_info[name];
|
2015-02-07 08:46:16 +01:00
|
|
|
|
if (inf == null) return;
|
2015-02-06 04:30:11 +01:00
|
|
|
|
|
|
|
|
|
var isCheck = $elm.attr('type') == 'checkbox',
|
2015-02-15 08:44:01 +01:00
|
|
|
|
val = isCheck ? $elm.prop('checked') : $elm.val().trim();
|
2015-02-06 04:30:11 +01:00
|
|
|
|
|
|
|
|
|
var newline;
|
|
|
|
|
switch(inf.type) {
|
|
|
|
|
case 'switch':
|
|
|
|
|
var slash = val ? '' : '//';
|
2015-02-07 11:04:44 +01:00
|
|
|
|
newline = inf.line.replace(inf.repl, '$1'+slash+'$3');
|
2015-02-06 04:30:11 +01:00
|
|
|
|
break;
|
2015-02-15 08:44:01 +01:00
|
|
|
|
case 'list':
|
2015-02-06 04:30:11 +01:00
|
|
|
|
case 'quoted':
|
|
|
|
|
case 'plain':
|
2015-02-15 08:44:01 +01:00
|
|
|
|
if (isCheck) this.setMessage(name + ' should not be a checkbox!', 'error');
|
|
|
|
|
case 'toggle':
|
|
|
|
|
if (isCheck) {
|
|
|
|
|
val = val ? inf.options[1] : inf.options[0];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (inf.type == 'list')
|
|
|
|
|
for (var i=1; i<inf.size; i++) val += ', ' + $('#'+name+'-'+i).val().trim();
|
|
|
|
|
}
|
|
|
|
|
newline = inf.line.replace(inf.repl, '$1'+(''+val).replace('$','\\$')+'$3');
|
2015-02-06 04:30:11 +01:00
|
|
|
|
break;
|
2015-02-05 16:05:29 +01:00
|
|
|
|
}
|
2015-02-07 08:46:16 +01:00
|
|
|
|
this.setDefineLine(name, newline);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the define's line in the text to a new line,
|
|
|
|
|
* then update, highlight, and scroll to the line
|
|
|
|
|
*/
|
|
|
|
|
setDefineLine: function(name, newline) {
|
2015-02-07 20:58:19 +01:00
|
|
|
|
this.log('setDefineLine:'+name+'\n'+newline,4);
|
2015-03-01 07:40:20 +01:00
|
|
|
|
var inf = define_info[name];
|
2015-02-07 08:46:16 +01:00
|
|
|
|
var $c = $(inf.field), txt = $c.text();
|
|
|
|
|
|
|
|
|
|
var hilite_token = '[HIGHLIGHTER-TOKEN]';
|
|
|
|
|
|
2015-03-06 17:48:53 +01:00
|
|
|
|
txt = txt.replaceLine(inf.lineNum, hilite_token + newline); // for override line and lineNum would be changed
|
2015-02-06 04:30:11 +01:00
|
|
|
|
inf.line = newline;
|
2015-02-07 08:46:16 +01:00
|
|
|
|
|
|
|
|
|
// Convert txt into HTML before storing
|
2015-02-07 20:58:19 +01:00
|
|
|
|
var html = txt.toHTML().replace(hilite_token, '<span></span>');
|
2015-02-07 08:46:16 +01:00
|
|
|
|
|
|
|
|
|
// Set the final text including the highlighter
|
|
|
|
|
$c.html(html);
|
2015-02-07 02:57:31 +01:00
|
|
|
|
|
2015-02-07 03:09:14 +01:00
|
|
|
|
// Scroll to reveal the define
|
2015-02-09 13:34:57 +01:00
|
|
|
|
if ($c.is(':visible')) this.scrollToDefine(name);
|
2015-02-07 03:09:14 +01:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2015-02-07 08:46:16 +01:00
|
|
|
|
* Scroll a pre box to reveal a #define
|
2015-02-07 03:09:14 +01:00
|
|
|
|
*/
|
|
|
|
|
scrollToDefine: function(name, always) {
|
|
|
|
|
this.log('scrollToDefine:'+name,4);
|
2015-03-01 07:40:20 +01:00
|
|
|
|
var inf = define_info[name], $c = $(inf.field);
|
2015-02-07 03:09:14 +01:00
|
|
|
|
|
2015-02-07 02:57:31 +01:00
|
|
|
|
// Scroll to the altered text if it isn't visible
|
|
|
|
|
var halfHeight = $c.height()/2, scrollHeight = $c.prop('scrollHeight'),
|
2015-03-02 14:23:36 +01:00
|
|
|
|
lineHeight = scrollHeight/[total_config_lines, total_config_adv_lines][inf.cindex],
|
2015-02-09 13:34:57 +01:00
|
|
|
|
textScrollY = (inf.lineNum * lineHeight - halfHeight).limit(0, scrollHeight - 1);
|
2015-02-07 02:57:31 +01:00
|
|
|
|
|
2015-02-09 13:34:57 +01:00
|
|
|
|
if (always || Math.abs($c.prop('scrollTop') - textScrollY) > halfHeight) {
|
|
|
|
|
$c.find('span').height(lineHeight);
|
|
|
|
|
$c.animate({ scrollTop: textScrollY });
|
|
|
|
|
}
|
2015-02-05 16:05:29 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-07 02:57:31 +01:00
|
|
|
|
/**
|
|
|
|
|
* Set a form field to the current #define value in the config text
|
|
|
|
|
*/
|
2015-03-01 07:40:20 +01:00
|
|
|
|
initFieldValue: function(name) {
|
|
|
|
|
var $elm = $('#'+name), inf = define_info[name],
|
2015-02-15 08:44:01 +01:00
|
|
|
|
val = this.defineValue(name);
|
2015-02-05 16:05:29 +01:00
|
|
|
|
|
2015-03-01 07:40:20 +01:00
|
|
|
|
this.log('initFieldValue:' + name + ' to ' + val, 2);
|
2015-02-06 04:30:11 +01:00
|
|
|
|
|
2015-03-02 10:45:53 +01:00
|
|
|
|
// If the item is switchable then set enabled state too
|
2015-03-01 07:40:20 +01:00
|
|
|
|
var $cb = $('#'+name+'-switch'), avail = eval(inf.enabled), on = true;
|
2015-02-05 16:05:29 +01:00
|
|
|
|
if ($cb.length) {
|
2015-02-15 08:44:01 +01:00
|
|
|
|
on = self.defineIsEnabled(name);
|
|
|
|
|
$cb.prop('checked', on);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (inf.type == 'list') {
|
|
|
|
|
$.each(val.split(','),function(i,v){
|
|
|
|
|
var $e = i > 0 ? $('#'+name+'-'+i) : $elm;
|
|
|
|
|
$e.val(v.trim());
|
2015-03-02 10:45:53 +01:00
|
|
|
|
$e.attr('disabled', !(on && avail)).unblock(avail);
|
2015-02-15 08:44:01 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (inf.type == 'toggle') val = val == inf.options[1];
|
|
|
|
|
$elm.attr('type') == 'checkbox' ? $elm.prop('checked', val) : $elm.val(''+val);
|
2015-03-02 10:45:53 +01:00
|
|
|
|
$elm.attr('disabled', !(on && avail)).unblock(avail); // enable/disable the form field (could also dim it)
|
2015-02-05 16:05:29 +01:00
|
|
|
|
}
|
2015-03-01 07:40:20 +01:00
|
|
|
|
|
2015-03-02 14:23:36 +01:00
|
|
|
|
$('label[for="'+name+'"]').unblock(avail);
|
2015-02-05 16:05:29 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-07 02:57:31 +01:00
|
|
|
|
/**
|
2015-02-15 08:44:01 +01:00
|
|
|
|
* Purge added fields and all their define info
|
2015-02-07 02:57:31 +01:00
|
|
|
|
*/
|
2015-03-02 14:23:36 +01:00
|
|
|
|
purgeAddedFields: function(cindex) {
|
|
|
|
|
$.each(define_list[cindex], function(i, name){
|
|
|
|
|
$('#'+name + ",[id^='"+name+"-'],label[for='"+name+"']").filter('.added').remove();
|
2015-02-07 02:57:31 +01:00
|
|
|
|
});
|
2015-03-02 14:23:36 +01:00
|
|
|
|
define_list[cindex] = [];
|
2015-02-07 02:57:31 +01:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get information about a #define from configuration file text:
|
|
|
|
|
*
|
2015-02-09 13:34:57 +01:00
|
|
|
|
* - Pre-examine the #define for its prefix, value position, suffix, etc.
|
2015-03-06 17:48:53 +01:00
|
|
|
|
* - Construct RegExp's for the #define to find and replace values.
|
2015-02-09 13:34:57 +01:00
|
|
|
|
* - Store the existing #define line as a fast key to finding it later.
|
2015-03-06 17:48:53 +01:00
|
|
|
|
* - Determine the line number of the #define
|
2015-02-09 13:34:57 +01:00
|
|
|
|
* - Gather nearby comments to be used as tooltips.
|
2015-03-06 17:48:53 +01:00
|
|
|
|
* - Look for JSON in nearby comments for use as select options.
|
|
|
|
|
*
|
|
|
|
|
* define_info[name]
|
|
|
|
|
* .type type of define: switch, list, quoted, plain, or toggle
|
|
|
|
|
* .size the number of items in a "list" type
|
|
|
|
|
* .options select options, if any
|
|
|
|
|
* .cindex config index
|
|
|
|
|
* .field pre containing the config text (config_list[cindex][0])
|
|
|
|
|
* .line the full line from the config text
|
|
|
|
|
* .pre any text preceding #define
|
|
|
|
|
* .define the "#define NAME" text (may have leading spaces)
|
|
|
|
|
* .post the text following the "#define NAME val" part
|
|
|
|
|
* .regex regexp to get the value from the line
|
|
|
|
|
* .repl regexp to replace the value in the line
|
|
|
|
|
* .val_i the value's index in the .regex result
|
2015-02-07 02:57:31 +01:00
|
|
|
|
*/
|
2015-03-02 14:23:36 +01:00
|
|
|
|
getDefineInfo: function(name, cindex) {
|
|
|
|
|
if (cindex === undefined) cindex = 0;
|
2015-02-06 04:30:11 +01:00
|
|
|
|
this.log('getDefineInfo:'+name,4);
|
2015-03-06 17:48:53 +01:00
|
|
|
|
var $c = config_list[cindex], txt = $c.text(),
|
|
|
|
|
info = { type:0, cindex:cindex, field:$c[0], val_i:2 }, post;
|
2015-02-06 04:30:11 +01:00
|
|
|
|
|
|
|
|
|
// a switch line with no value
|
2015-03-06 17:48:53 +01:00
|
|
|
|
var find = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + name + ')([ \\t]*(/[*/].*)?)$', 'm'),
|
|
|
|
|
r = find.exec(txt);
|
|
|
|
|
if (r !== null) {
|
|
|
|
|
post = r[3] == null ? '' : r[3];
|
2015-02-07 11:04:44 +01:00
|
|
|
|
$.extend(info, {
|
2015-03-06 17:48:53 +01:00
|
|
|
|
type: 'switch',
|
|
|
|
|
val_i: 1,
|
|
|
|
|
regex: new RegExp('([ \\t]*//)?([ \\t]*' + r[2].regEsc() + post.regEsc() + ')', 'm'),
|
|
|
|
|
repl: new RegExp('([ \\t]*)(\/\/)?([ \\t]*' + r[2].regEsc() + post.regEsc() + ')', 'm')
|
2015-02-07 11:04:44 +01:00
|
|
|
|
});
|
2015-02-05 16:05:29 +01:00
|
|
|
|
}
|
2015-02-07 11:04:44 +01:00
|
|
|
|
else {
|
2015-02-13 12:02:56 +01:00
|
|
|
|
// a define with curly braces
|
2015-03-06 17:48:53 +01:00
|
|
|
|
find = new RegExp('^(.*//)?(.*#define[ \\t]+' + name + '[ \\t]+)(\{[^\}]*\})([ \\t]*(/[*/].*)?)$', 'm');
|
|
|
|
|
r = find.exec(txt);
|
|
|
|
|
if (r !== null) {
|
|
|
|
|
post = r[4] == null ? '' : r[4];
|
2015-02-07 11:04:44 +01:00
|
|
|
|
$.extend(info, {
|
2015-03-06 17:48:53 +01:00
|
|
|
|
type: 'list',
|
|
|
|
|
size: r[3].split(',').length,
|
|
|
|
|
regex: new RegExp('([ \\t]*//)?[ \\t]*' + r[2].regEsc() + '\{([^\}]*)\}' + post.regEsc(), 'm'),
|
|
|
|
|
repl: new RegExp('(([ \\t]*//)?[ \\t]*' + r[2].regEsc() + '\{)[^\}]*(\}' + post.regEsc() + ')', 'm')
|
2015-02-07 11:04:44 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-02-13 12:02:56 +01:00
|
|
|
|
// a define with quotes
|
2015-03-06 17:48:53 +01:00
|
|
|
|
find = new RegExp('^(.*//)?(.*#define[ \\t]+' + name + '[ \\t]+)("[^"]*")([ \\t]*(/[*/].*)?)$', 'm');
|
|
|
|
|
r = find.exec(txt);
|
|
|
|
|
if (r !== null) {
|
|
|
|
|
post = r[4] == null ? '' : r[4];
|
2015-02-07 11:04:44 +01:00
|
|
|
|
$.extend(info, {
|
2015-03-06 17:48:53 +01:00
|
|
|
|
type: 'quoted',
|
|
|
|
|
regex: new RegExp('([ \\t]*//)?[ \\t]*' + r[2].regEsc() + '"([^"]*)"' + post.regEsc(), 'm'),
|
|
|
|
|
repl: new RegExp('(([ \\t]*//)?[ \\t]*' + r[2].regEsc() + '")[^"]*("' + post.regEsc() + ')', 'm')
|
2015-02-07 11:04:44 +01:00
|
|
|
|
});
|
2015-02-13 12:02:56 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// a define with no quotes
|
2015-03-06 17:48:53 +01:00
|
|
|
|
find = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + name + '[ \\t]+)(\\S*)([ \\t]*(/[*/].*)?)$', 'm');
|
|
|
|
|
r = find.exec(txt);
|
|
|
|
|
if (r !== null) {
|
|
|
|
|
post = r[4] == null ? '' : r[4];
|
2015-02-13 12:02:56 +01:00
|
|
|
|
$.extend(info, {
|
2015-03-06 17:48:53 +01:00
|
|
|
|
type: 'plain',
|
|
|
|
|
regex: new RegExp('([ \\t]*//)?[ \\t]*' + r[2].regEsc() + '(\\S*)' + post.regEsc(), 'm'),
|
|
|
|
|
repl: new RegExp('(([ \\t]*//)?[ \\t]*' + r[2].regEsc() + ')\\S*(' + post.regEsc() + ')', 'm')
|
2015-02-13 12:02:56 +01:00
|
|
|
|
});
|
2015-03-06 17:48:53 +01:00
|
|
|
|
if (r[3].match(/false|true/)) {
|
2015-02-15 08:44:01 +01:00
|
|
|
|
info.type = 'toggle';
|
|
|
|
|
info.options = ['false','true'];
|
|
|
|
|
}
|
2015-02-13 12:02:56 +01:00
|
|
|
|
}
|
2015-02-07 11:04:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-06 04:30:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-11 13:59:07 +01:00
|
|
|
|
// Success?
|
2015-02-07 11:04:44 +01:00
|
|
|
|
if (info.type) {
|
2015-03-06 17:48:53 +01:00
|
|
|
|
$.extend(info, {
|
|
|
|
|
line: r[0],
|
|
|
|
|
pre: r[1] == null ? '' : r[1].replace('//',''),
|
|
|
|
|
define: r[2],
|
|
|
|
|
post: post
|
|
|
|
|
});
|
2015-02-07 15:20:04 +01:00
|
|
|
|
// Get the end-of-line comment, if there is one
|
2015-02-19 12:11:16 +01:00
|
|
|
|
var tooltip = '', eoltip = '';
|
2015-03-06 17:48:53 +01:00
|
|
|
|
find = new RegExp('.*#define[ \\t].*/[/*]+[ \\t]*(.*)');
|
|
|
|
|
if (info.line.search(find) >= 0)
|
|
|
|
|
eoltip = tooltip = info.line.replace(find, '$1');
|
2015-02-07 20:58:19 +01:00
|
|
|
|
|
|
|
|
|
// Get all the comments immediately before the item
|
2015-03-06 17:48:53 +01:00
|
|
|
|
var s;
|
|
|
|
|
find = new RegExp('(([ \\t]*(//|#)[^\n]+\n){1,4})' + info.line.regEsc(), 'g');
|
|
|
|
|
if (r = find.exec(txt)) {
|
2015-02-15 08:44:01 +01:00
|
|
|
|
// Get the text of the found comments
|
2015-03-06 17:48:53 +01:00
|
|
|
|
find = new RegExp('^[ \\t]*//+[ \\t]*(.*)[ \\t]*$', 'gm');
|
|
|
|
|
while((s = find.exec(r[1])) !== null) {
|
2015-02-19 12:11:16 +01:00
|
|
|
|
var tip = s[1].replace(/[ \\t]*(={5,}|(#define[ \\t]+.*|@section[ \\t]+\w+))[ \\t]*/g, '');
|
2015-02-15 08:44:01 +01:00
|
|
|
|
if (tip.length) {
|
2015-02-19 12:11:16 +01:00
|
|
|
|
if (tip.match(/^#define[ \\t]/) != null) tooltip = eoltip;
|
2015-02-15 08:44:01 +01:00
|
|
|
|
// JSON data? Save as select options
|
|
|
|
|
if (!info.options && tip.match(/:[\[{]/) != null) {
|
|
|
|
|
// TODO
|
|
|
|
|
// :[1-6] = value limits
|
|
|
|
|
var o; eval('o=' + tip.substr(1));
|
|
|
|
|
info.options = o;
|
|
|
|
|
if (Object.prototype.toString.call(o) == "[object Array]" && o.length == 2 && !eval(''+o[0]))
|
|
|
|
|
info.type = 'toggle';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Other lines added to the tooltip
|
|
|
|
|
tooltip += ' ' + tip + '\n';
|
|
|
|
|
}
|
2015-02-13 12:02:56 +01:00
|
|
|
|
}
|
2015-02-07 15:20:04 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-07 20:58:19 +01:00
|
|
|
|
|
2015-02-15 08:44:01 +01:00
|
|
|
|
// Add .tooltip and .lineNum properties to the info
|
2015-03-06 17:48:53 +01:00
|
|
|
|
find = new RegExp('^'+name); // Strip the name from the tooltip
|
2015-03-01 07:40:20 +01:00
|
|
|
|
var lineNum = this.getLineNumberOfText(info.line, txt);
|
|
|
|
|
|
|
|
|
|
// See if this define is enabled conditionally
|
|
|
|
|
var enable_cond = '';
|
2015-03-06 17:48:53 +01:00
|
|
|
|
$.each(dependent_groups, function(cond,dat){
|
2015-03-01 07:40:20 +01:00
|
|
|
|
$.each(dat, function(i,o){
|
2015-03-02 14:23:36 +01:00
|
|
|
|
if (o.cindex == cindex && lineNum > o.start && lineNum < o.end) {
|
2015-03-01 07:40:20 +01:00
|
|
|
|
if (enable_cond != '') enable_cond += ' && ';
|
|
|
|
|
enable_cond += '(' + cond + ')';
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-02-07 15:20:04 +01:00
|
|
|
|
$.extend(info, {
|
2015-03-06 17:48:53 +01:00
|
|
|
|
tooltip: '<strong>'+name+'</strong> '+tooltip.trim().replace(find,'').toHTML(),
|
2015-03-01 07:40:20 +01:00
|
|
|
|
lineNum: lineNum,
|
|
|
|
|
switchable: (info.type != 'switch' && info.line.match(/^[ \t]*\/\//)) || false, // Disabled? Mark as "switchable"
|
|
|
|
|
enabled: enable_cond ? enable_cond : 'true'
|
2015-02-07 15:20:04 +01:00
|
|
|
|
});
|
2015-03-01 07:40:20 +01:00
|
|
|
|
|
2015-02-05 16:05:29 +01:00
|
|
|
|
}
|
2015-02-07 11:04:44 +01:00
|
|
|
|
else
|
|
|
|
|
info = null;
|
2015-02-06 04:30:11 +01:00
|
|
|
|
|
2015-03-01 07:40:20 +01:00
|
|
|
|
this.log(info, 2);
|
2015-02-07 15:20:04 +01:00
|
|
|
|
|
2015-02-07 11:04:44 +01:00
|
|
|
|
return info;
|
2015-02-05 16:05:29 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-07 08:46:16 +01:00
|
|
|
|
/**
|
|
|
|
|
* Count the number of lines before a match, return -1 on fail
|
|
|
|
|
*/
|
2015-02-07 11:04:44 +01:00
|
|
|
|
getLineNumberOfText: function(line, txt) {
|
2015-02-07 02:57:31 +01:00
|
|
|
|
var pos = txt.indexOf(line);
|
2015-03-06 17:48:53 +01:00
|
|
|
|
return (pos < 0) ? pos : txt.lineCount(pos);
|
2015-02-06 04:30:11 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-09 13:34:57 +01:00
|
|
|
|
/**
|
|
|
|
|
* Add a temporary message to the page
|
|
|
|
|
*/
|
|
|
|
|
setMessage: function(msg,type) {
|
|
|
|
|
if (msg) {
|
|
|
|
|
if (type === undefined) type = 'message';
|
2015-02-11 13:59:07 +01:00
|
|
|
|
var $err = $('<p class="'+type+'">'+msg+'<span>x</span></p>').appendTo($msgbox), err = $err[0];
|
2015-02-09 13:34:57 +01:00
|
|
|
|
var baseColor = $err.css('color').replace(/rgba?\(([^),]+,[^),]+,[^),]+).*/, 'rgba($1,');
|
|
|
|
|
err.pulse_offset = (pulse_offset += 200);
|
2015-02-11 13:59:07 +01:00
|
|
|
|
err.startTime = Date.now() + pulse_offset;
|
2015-02-09 13:34:57 +01:00
|
|
|
|
err.pulser = setInterval(function(){
|
2015-02-11 13:59:07 +01:00
|
|
|
|
var pulse_time = Date.now() + err.pulse_offset;
|
|
|
|
|
var opac = 0.5+Math.sin(pulse_time/200)*0.4;
|
|
|
|
|
$err.css({color:baseColor+(opac)+')'});
|
|
|
|
|
if (pulse_time - err.startTime > 2500 && opac > 0.899) {
|
2015-02-09 13:34:57 +01:00
|
|
|
|
clearInterval(err.pulser);
|
|
|
|
|
}
|
|
|
|
|
}, 50);
|
2015-02-20 11:12:00 +01:00
|
|
|
|
$err.click(function(e) {
|
|
|
|
|
$(this).remove();
|
|
|
|
|
self.adjustFormLayout();
|
|
|
|
|
return false;
|
|
|
|
|
}).css({cursor:'pointer'});
|
2015-02-09 13:34:57 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2015-02-11 13:59:07 +01:00
|
|
|
|
$msgbox.find('p.error, p.warning').each(function() {
|
2015-02-09 13:34:57 +01:00
|
|
|
|
if (this.pulser !== undefined && this.pulser)
|
|
|
|
|
clearInterval(this.pulser);
|
|
|
|
|
$(this).remove();
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-02-20 11:12:00 +01:00
|
|
|
|
self.adjustFormLayout();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
adjustFormLayout: function() {
|
|
|
|
|
var wtop = $(window).scrollTop(),
|
|
|
|
|
ctop = $cfg.offset().top,
|
|
|
|
|
thresh = $form.offset().top+100;
|
|
|
|
|
if (ctop < thresh) {
|
|
|
|
|
var maxhi = $form.height(); // pad plus heights of config boxes can't be more than this
|
|
|
|
|
var pad = wtop > ctop ? wtop-ctop : 0; // pad the top box to stay in view
|
|
|
|
|
var innerpad = Math.ceil($cfg.height() - $cfg.find('pre').height());
|
|
|
|
|
// height to use for the inner boxes
|
|
|
|
|
var hi = ($(window).height() - ($cfg.offset().top - pad) + wtop - innerpad)/2;
|
|
|
|
|
if (hi < 200) hi = 200;
|
|
|
|
|
$cfg.css({ paddingTop: pad });
|
|
|
|
|
var $pre = $('pre.config');
|
|
|
|
|
$pre.css({ height: Math.floor(hi) - $pre.position().top });
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$cfg.css({ paddingTop: wtop > ctop ? wtop-ctop : 0, height: '' });
|
|
|
|
|
}
|
2015-02-09 13:34:57 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-02-11 13:59:07 +01:00
|
|
|
|
setRequestError: function(stat, path) {
|
|
|
|
|
self.setMessage('Error '+stat+' – ' + path.replace(/^(https:\/\/[^\/]+\/)?.+(\/[^\/]+)$/, '$1...$2'), 'error');
|
|
|
|
|
},
|
|
|
|
|
|
2015-02-06 04:30:11 +01:00
|
|
|
|
log: function(o,l) {
|
|
|
|
|
if (l === undefined) l = 0;
|
|
|
|
|
if (this.logging>=l*1) console.log(o);
|
2015-02-05 16:05:29 +01:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
logOnce: function(o) {
|
2015-02-07 11:04:44 +01:00
|
|
|
|
if (o.didLogThisObject === undefined) {
|
2015-02-06 04:30:11 +01:00
|
|
|
|
this.log(o);
|
2015-02-05 16:05:29 +01:00
|
|
|
|
o.didLogThisObject = true;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
EOF: null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
// Typically the app would be in its own file, but this would be here
|
2015-02-28 06:08:09 +01:00
|
|
|
|
window.configuratorApp.init();
|
2015-02-05 16:05:29 +01:00
|
|
|
|
|
|
|
|
|
});
|