From f81f763cfb878a05ed627b63160b5d91c05cf99f Mon Sep 17 00:00:00 2001 From: Christopher Charbonneau Wells Date: Sun, 20 Aug 2017 11:23:32 -0400 Subject: [PATCH] Refactor JS to use BabyBlotter as primary JS namespace. --- babyblotter/static_site/js/babyblotter.js | 12 ++++++++++ core/static/js/timer.js | 28 ++++++++++------------- core/templates/core/timer_detail.html | 2 +- gulpfile.js | 5 +++- 4 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 babyblotter/static_site/js/babyblotter.js diff --git a/babyblotter/static_site/js/babyblotter.js b/babyblotter/static_site/js/babyblotter.js new file mode 100644 index 00000000..c2ad43c8 --- /dev/null +++ b/babyblotter/static_site/js/babyblotter.js @@ -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; +}(); diff --git a/core/static/js/timer.js b/core/static/js/timer.js index f367e060..b9609b3e 100644 --- a/core/static/js/timer.js +++ b/core/static/js/timer.js @@ -1,25 +1,21 @@ -if (typeof jQuery === 'undefined') { - throw new Error('BabyBlotter Timer requires jQuery.') -} - -var BBTimer = function ($) { - /* Baby Blotter Timer - * - * Uses a supplied ID to run a timer. The element using the ID must have - * three children with the following classes: - * * timer-seconds - * * timer-minutes - * * timer-hours - */ +/* Baby Blotter Timer + * + * Uses a supplied ID to run a timer. The element using the ID must have + * three children with the following classes: + * * timer-seconds + * * timer-minutes + * * timer-hours + */ +BabyBlotter.Timer = function ($) { var runIntervalId = null; var timerElement = null; - var BBTimer = { + var Timer = { run: function(id) { timerElement = $('#' + id); if (timerElement.length == 0) { - console.error('BBTimer: Timer element not found.') + console.error('BBTimer: Timer element not found.'); return false; } @@ -61,5 +57,5 @@ var BBTimer = function ($) { } }; - return BBTimer; + return Timer; }(jQuery); diff --git a/core/templates/core/timer_detail.html b/core/templates/core/timer_detail.html index 8c27e8a7..b4968196 100644 --- a/core/templates/core/timer_detail.html +++ b/core/templates/core/timer_detail.html @@ -41,6 +41,6 @@ {% block javascript %} {% endblock %} \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 9aaea7ec..927d613b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,7 +5,10 @@ var concat = require('gulp-concat'); gulp.task('app:scripts', function() { 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(gulp.dest('babyblotter/static/babyblotter/js/'));