Refactor JS to use BabyBlotter as primary JS namespace.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-20 11:23:32 -04:00
parent 78eb20ab91
commit f81f763cfb
4 changed files with 29 additions and 18 deletions

View File

@ -0,0 +1,12 @@
/* Baby Blotter
*
* Default namespace for the Baby Blotter app.
*/
if (typeof jQuery === 'undefined') {
throw new Error('Baby Blotter requires jQuery.')
}
var BabyBlotter = function () {
var BabyBlotter = {};
return BabyBlotter;
}();

View File

@ -1,8 +1,3 @@
if (typeof jQuery === 'undefined') {
throw new Error('BabyBlotter Timer requires jQuery.')
}
var BBTimer = function ($) {
/* Baby Blotter Timer /* Baby Blotter Timer
* *
* Uses a supplied ID to run a timer. The element using the ID must have * Uses a supplied ID to run a timer. The element using the ID must have
@ -11,15 +6,16 @@ var BBTimer = function ($) {
* * timer-minutes * * timer-minutes
* * timer-hours * * timer-hours
*/ */
BabyBlotter.Timer = function ($) {
var runIntervalId = null; var runIntervalId = null;
var timerElement = null; var timerElement = null;
var BBTimer = { var Timer = {
run: function(id) { run: function(id) {
timerElement = $('#' + id); timerElement = $('#' + id);
if (timerElement.length == 0) { if (timerElement.length == 0) {
console.error('BBTimer: Timer element not found.') console.error('BBTimer: Timer element not found.');
return false; return false;
} }
@ -61,5 +57,5 @@ var BBTimer = function ($) {
} }
}; };
return BBTimer; return Timer;
}(jQuery); }(jQuery);

View File

@ -41,6 +41,6 @@
{% block javascript %} {% block javascript %}
<script type="application/javascript"> <script type="application/javascript">
BBTimer.run('timer-status'); BabyBlotter.Timer.run('timer-status');
</script> </script>
{% endblock %} {% endblock %}

View File

@ -5,7 +5,10 @@ var concat = require('gulp-concat');
gulp.task('app:scripts', function() { gulp.task('app:scripts', function() {
return gulp.src([ return gulp.src([
'core/static/js/timer.js' 'babyblotter/static_site/js/babyblotter.js',
'api/static/js/*.js',
'core/static/js/*.js',
'dashboard/static/js/*.js'
]) ])
.pipe(concat('app.js')) .pipe(concat('app.js'))
.pipe(gulp.dest('babyblotter/static/babyblotter/js/')); .pipe(gulp.dest('babyblotter/static/babyblotter/js/'));