Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 128 additions & 126 deletions src/config/common.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define([], function () {
define([], function() {
const waitForGlobal = (name, callback, errback = () => {}, interval = 500, max = 10) => {
if (window[name]) {
callback();
Expand All @@ -21,13 +21,13 @@ define([], function () {
shim: {
mathjax: {
exports: 'MathJax',
init: function () {
init: function() {
MathJax.Hub.Config({
messageStyle: 'none',
HTML: ['input/TeX', 'output/HTML-CSS'],
TeX: {
extensions: ['AMSmath.js', 'AMSsymbols.js'],
equationNumbers: {autoNumber: 'AMS'},
equationNumbers: { autoNumber: 'AMS' },
},
extensions: ['tex2jax.js'],
jax: ['input/TeX', 'output/HTML-CSS'],
Expand All @@ -44,7 +44,7 @@ define([], function () {
},
'HTML-CSS': {
availableFonts: ['TeX'],
linebreaks: {automatic: true},
linebreaks: { automatic: true },
},
});
MathJax.Hub.Startup.onload();
Expand All @@ -61,20 +61,19 @@ define([], function () {
'array-flat-polyfill',
'polyfill',
'js/dark-mode-switch',
], function () {
'js/adstoscix',
], function() {
// stub here to make sure these load before the main app

});

// set up handlebars helpers
require(['hbs/handlebars'], function (Handlebars) {

require(['hbs/handlebars'], function(Handlebars) {
// register helpers
// http://doginthehat.com.au/2012/02/comparison-block-helper-for-handlebars-templates/#comment-44

// eg (where current is a variable): {{#compare current 1 operator=">"}}

Handlebars.registerHelper('compare', function (lvalue, rvalue, options) {
Handlebars.registerHelper('compare', function(lvalue, rvalue, options) {
var operators;
var result;
var operator;
Expand All @@ -89,58 +88,56 @@ define([], function () {
}

operators = {
'==': function (l, r) {
'==': function(l, r) {
return l == r;
},
'===': function (l, r) {
'===': function(l, r) {
return l === r;
},
'!=': function (l, r) {
'!=': function(l, r) {
return l != r;
},
'!==': function (l, r) {
'!==': function(l, r) {
return l !== r;
},
'<': function (l, r) {
'<': function(l, r) {
return l < r;
},
'>': function (l, r) {
'>': function(l, r) {
return l > r;
},
'<=': function (l, r) {
'<=': function(l, r) {
return l <= r;
},
'>=': function (l, r) {
'>=': function(l, r) {
return l >= r;
},
typeof: function (l, r) {
typeof: function(l, r) {
return typeof l === r;
},
};
if (!operators[operator]) {
throw new Error(
"Handlerbars Helper 'compare' doesn't know the operator " + operator,
);
throw new Error("Handlerbars Helper 'compare' doesn't know the operator " + operator);
}
result = operators[operator](lvalue, rvalue);
if (result) {
return options.fn(this);
}
return options.inverse(this);
});
Handlebars.registerHelper('toJSON', function (object) {
Handlebars.registerHelper('toJSON', function(object) {
return JSON.stringify(object, null, 2);
});
Handlebars.registerHelper('isdefined', function (value) {
Handlebars.registerHelper('isdefined', function(value) {
return typeof value !== 'undefined';
});
Handlebars.registerHelper('ifInSet', function (s, value, options) {
Handlebars.registerHelper('ifInSet', function(s, value, options) {
if (s.has(value)) {
return options.fn(this);
}
return options.inverse(this);
});
Handlebars.registerHelper('ifSetEmpty', function (s, options) {
Handlebars.registerHelper('ifSetEmpty', function(s, options) {
if (s.size === 0) {
return options.fn(this);
}
Expand All @@ -160,7 +157,8 @@ define([], function () {
or() {
return Array.prototype.slice.call(arguments, 0, -1).some(Boolean);
},
startsWith: (str, prefix) => typeof str === 'string' && typeof prefix === 'string' ? str.startsWith(prefix) : false,
startsWith: (str, prefix) =>
typeof str === 'string' && typeof prefix === 'string' ? str.startsWith(prefix) : false,
});

// array helpers
Expand All @@ -173,37 +171,37 @@ define([], function () {
});

// set validation callbacks used by authentication and user settings widgets
require(['backbone-validation'], function () {
require(['backbone-validation'], function() {
// this allows for instant validation of form fields using the backbone-validation plugin
_.extend(Backbone.Validation.callbacks, {
valid: function (view, attr, selector) {
valid: function(view, attr, selector) {
var $el = view.$('input[name=' + attr + ']');

$el
.closest('.form-group')
.removeClass('has-error')
.find('.help-block')
.html('')
.addClass('no-show');
.closest('.form-group')
.removeClass('has-error')
.find('.help-block')
.html('')
.addClass('no-show');
},
invalid: function (view, attr, error, selector) {
invalid: function(view, attr, error, selector) {
var $el = view.$('[name=' + attr + ']');
$group = $el.closest('.form-group');

if (view.submit === true) {
// only show error states if there has been a submit event
$group.addClass('has-error');
$group
.find('.help-block')
.html(error)
.removeClass('no-show');
.find('.help-block')
.html(error)
.removeClass('no-show');
}
},
});
});

// d3/d3-cloud don't like to load normally from a CDN
require(['d3', 'd3-cloud'], function (d3, cloud) {
require(['d3', 'd3-cloud'], function(d3, cloud) {
var win = window;
if (!win.d3) {
win.d3 = d3;
Expand All @@ -217,103 +215,105 @@ define([], function () {
'd3',
() => {
window.d3.legend = function(g) {
g.each(function() {
var g = d3.select(this);
var items = {};
var svg = d3.select(g.property('nearestViewportElement'));
var legendPadding = g.attr('data-style-padding') || 5;
var lb = g.selectAll('.legend-box').data([true]);
var li = g.selectAll('.legend-items').data([true]);
g.each(function() {
var g = d3.select(this);
var items = {};
var svg = d3.select(g.property('nearestViewportElement'));
var legendPadding = g.attr('data-style-padding') || 5;
var lb = g.selectAll('.legend-box').data([true]);
var li = g.selectAll('.legend-items').data([true]);

lb.enter()
.append('rect')
.classed('legend-box', true);
li.enter()
.append('g')
.classed('legend-items', true);
lb.enter()
.append('rect')
.classed('legend-box', true);
li.enter()
.append('g')
.classed('legend-items', true);

try {
svg.selectAll('[data-legend]').each(function() {
var self = d3.select(this);
items[self.attr('data-legend')] = {
pos: self.attr('data-legend-pos') || this.getBBox().y,
color:
self.attr('data-legend-color') != undefined
? self.attr('data-legend-color')
: self.style('fill') != 'none'
? self.style('fill')
: self.style('stroke'),
};
});
} catch (e) {
// firefox tends to have issue with hidden elements
// should continue if it doesn't die here
}
try {
svg.selectAll('[data-legend]').each(function() {
var self = d3.select(this);
items[self.attr('data-legend')] = {
pos: self.attr('data-legend-pos') || this.getBBox().y,
color:
self.attr('data-legend-color') != undefined
? self.attr('data-legend-color')
: self.style('fill') != 'none'
? self.style('fill')
: self.style('stroke'),
};
});
} catch (e) {
// firefox tends to have issue with hidden elements
// should continue if it doesn't die here
}

items = d3.entries(items).sort(function(a, b) {
return a.value.pos - b.value.pos;
items = d3.entries(items).sort(function(a, b) {
return a.value.pos - b.value.pos;
});
var itemOffset = 0;
li.selectAll('text')
.data(items, function(d) {
return d.key;
})
.call(function(d) {
d.enter().append('text');
})
.call(function(d) {
d.exit().remove();
})
.attr('y', function(d, i) {
if (i === 0) {
return '0em';
}
itemOffset += 0.2;
return i + itemOffset + 'em';
})
.attr('x', '1em')
.text(function(d) {
return d.key;
});
var itemOffset = 0;
li.selectAll('text')
.data(items, function(d) {
return d.key;
})
.call(function(d) {
d.enter().append('text');
})
.call(function(d) {
d.exit().remove();
})
.attr('y', function(d, i) {
if (i === 0) {
return '0em';
}
itemOffset += 0.2;
return i + itemOffset + 'em';
})
.attr('x', '1em')
.text(function(d) {
return d.key;
});

li.selectAll('circle')
.data(items, function(d) {
return d.key;
})
.call(function(d) {
d.enter().append('circle');
})
.call(function(d) {
d.exit().remove();
})
.attr('cy', function(d, i) {
return i - 0.25 + 'em';
})
.attr('cx', 0)
.attr('r', '0.4em')
.style('fill', function(d) {
return d.value.color;
});
li.selectAll('circle')
.data(items, function(d) {
return d.key;
})
.call(function(d) {
d.enter().append('circle');
})
.call(function(d) {
d.exit().remove();
})
.attr('cy', function(d, i) {
return i - 0.25 + 'em';
})
.attr('cx', 0)
.attr('r', '0.4em')
.style('fill', function(d) {
return d.value.color;
});

// Reposition and resize the box
var lbbox = li[0][0].getBBox();
lb.attr('x', lbbox.x - legendPadding)
.attr('y', lbbox.y - legendPadding)
.attr('height', lbbox.height + 2 * legendPadding)
.attr('width', lbbox.width + 2 * legendPadding);
});
return g;
};
// Reposition and resize the box
var lbbox = li[0][0].getBBox();
lb.attr('x', lbbox.x - legendPadding)
.attr('y', lbbox.y - legendPadding)
.attr('height', lbbox.height + 2 * legendPadding)
.attr('width', lbbox.width + 2 * legendPadding);
});
return g;
};
},
() => {
window.whenSentryReady && window.whenSentryReady()
.then((sentry) => sentry.captureMessage('d3 not loaded'))
.catch(() => {});
window.whenSentryReady &&
window
.whenSentryReady()
.then((sentry) => sentry.captureMessage('d3 not loaded'))
.catch(() => {});
}
);
});

require(['jquery'], function ($) {
require(['jquery'], function($) {
waitForGlobal(
'$',
() => {
Expand Down Expand Up @@ -352,9 +352,11 @@ define([], function () {
};
},
() => {
window.whenSentryReady && window.whenSentryReady()
.then((sentry) => sentry.captureMessage('jQuery not loaded'))
.catch(() => {});
window.whenSentryReady &&
window
.whenSentryReady()
.then((sentry) => sentry.captureMessage('jQuery not loaded'))
.catch(() => {});
}
);
});
Expand Down
Loading