From 4c4489a8909a169d1c25900b1728c9701136dffe Mon Sep 17 00:00:00 2001 From: Pablo Vazquez Date: Thu, 29 Sep 2016 12:22:53 +0200 Subject: [PATCH] Concatenate all general js files into tutti.js --- .gitignore | 2 + gulpfile.js | 19 +++++- src/scripts/tutti/00_utils.js | 52 ++++++++++++++++ .../tasks.js => src/scripts/tutti/10_tasks.js | 60 ------------------- src/templates/attract/layout.jade | 5 +- 5 files changed, 75 insertions(+), 63 deletions(-) create mode 100644 src/scripts/tutti/00_utils.js rename attract/static/assets/js/tasks.js => src/scripts/tutti/10_tasks.js (83%) diff --git a/.gitignore b/.gitignore index 66f6873..4b37359 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ __pycache__ /node_modules/ /attract/templates/ /attract/static/assets/css/ + +/attract/static/assets/js/*.min.js diff --git a/gulpfile.js b/gulpfile.js index eb65133..5a5e2fa 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -65,6 +65,22 @@ gulp.task('scripts', function() { }); +/* Collection of scripts in src/scripts/tutti/ to merge into tutti.min.js */ +/* Since it's always loaded, it's only for functions that we want site-wide */ +gulp.task('scripts_tutti', function() { + gulp.src('src/scripts/tutti/**/*.js') + .pipe(gulpif(enabled.failCheck, plumber())) + .pipe(cache('scripting_tutti')) + .pipe(gulpif(enabled.maps, sourcemaps.init())) + .pipe(concat("tutti.min.js")) + .pipe(gulpif(enabled.uglify, uglify())) + .pipe(gulpif(enabled.maps, sourcemaps.write("."))) + .pipe(chmod(644)) + .pipe(gulp.dest('attract/static/assets/js/')) + .pipe(gulpif(enabled.liveReload, livereload())); +}); + + // While developing, run 'gulp watch' gulp.task('watch',function() { // Only listen for live reloads if ran with --livereload @@ -75,8 +91,9 @@ gulp.task('watch',function() { gulp.watch('src/styles/**/*.sass',['styles']); gulp.watch('src/templates/**/*.jade',['templates']); gulp.watch('src/scripts/*.js',['scripts']); + gulp.watch('src/scripts/tutti/*.js',['scripts_tutti']); }); // Run 'gulp' to build everything at once -gulp.task('default', ['styles', 'templates', 'scripts']); +gulp.task('default', ['styles', 'templates', 'scripts', 'scripts_tutti']); diff --git a/src/scripts/tutti/00_utils.js b/src/scripts/tutti/00_utils.js new file mode 100644 index 0000000..9cd4293 --- /dev/null +++ b/src/scripts/tutti/00_utils.js @@ -0,0 +1,52 @@ +(function ( $ ) { + $.fn.flashOnce = function() { + var target = this; + this + .addClass('flash-on') + .delay(1000) // this delay is linked to the transition in the flash-on CSS class. + .queue(function() { + target + .removeClass('flash-on') + .addClass('flash-off') + .dequeue() + ;}) + .delay(1000) // this delay is just to clean up the flash-X classes. + .queue(function() { + target + .removeClass('flash-on flash-off') + .dequeue() + ;}) + ; + return this; + }; + + /** + * Fades out the element, then erases its contents and shows the now-empty element again. + */ + $.fn.fadeOutAndClear = function(fade_speed) { + var target = this; + this + .fadeOut(fade_speed, function() { + target + .html('') + .show(); + }); + } + + $.fn.hideAndRemove = function(hide_speed, finished) { + this.slideUp(hide_speed, function() { + this.remove(); + if (typeof finished !== 'undefined') finished(); + }); + } + + $.fn.removeClassPrefix = function(prefix) { + this.each(function(i, el) { + var classes = el.className.split(" ").filter(function(c) { + return c.lastIndexOf(prefix, 0) !== 0; + }); + el.className = $.trim(classes.join(" ")); + }); + return this; + }; +}(jQuery)); diff --git a/attract/static/assets/js/tasks.js b/src/scripts/tutti/10_tasks.js similarity index 83% rename from attract/static/assets/js/tasks.js rename to src/scripts/tutti/10_tasks.js index 65535d0..06beb11 100644 --- a/attract/static/assets/js/tasks.js +++ b/src/scripts/tutti/10_tasks.js @@ -1,56 +1,3 @@ -(function ( $ ) { - $.fn.flashOnce = function() { - var target = this; - this - .addClass('flash-on') - .delay(1000) // this delay is linked to the transition in the flash-on CSS class. - .queue(function() { - target - .removeClass('flash-on') - .addClass('flash-off') - .dequeue() - ;}) - .delay(1000) // this delay is just to clean up the flash-X classes. - .queue(function() { - target - .removeClass('flash-on flash-off') - .dequeue() - ;}) - ; - return this; - }; - - /** - * Fades out the element, then erases its contents and shows the now-empty element again. - */ - $.fn.fadeOutAndClear = function(fade_speed) { - var target = this; - this - .fadeOut(fade_speed, function() { - target - .html('') - .show(); - }); - } - - $.fn.hideAndRemove = function(hide_speed, finished) { - this.slideUp(hide_speed, function() { - this.remove(); - if (typeof finished !== 'undefined') finished(); - }); - } - - $.fn.removeClassPrefix = function(prefix) { - this.each(function(i, el) { - var classes = el.className.split(" ").filter(function(c) { - return c.lastIndexOf(prefix, 0) !== 0; - }); - el.className = $.trim(classes.join(" ")); - }); - return this; - }; -}(jQuery)); - /** * Removes the task from the task list and shot list, and show the 'task-add-link' * when this was the last task in its category. @@ -330,10 +277,3 @@ $(function() { }); }); -/* Copy to clipboard when clicking on an input with 'copy-to-clipboard' class */ -$('body').on('click', '.copy-to-clipboard', function(e){ - e.preventDefault(); - - $(this).select(); - document.execCommand('copy'); -}); diff --git a/src/templates/attract/layout.jade b/src/templates/attract/layout.jade index 63e8863..bd4f0eb 100644 --- a/src/templates/attract/layout.jade +++ b/src/templates/attract/layout.jade @@ -15,6 +15,8 @@ html(lang="en") link(href="{{ url_for('static_attract', filename='assets/css/main.css') }}", rel="stylesheet") link(href="{{ url_for('static_attract', filename='assets/css/plugins/js_select2.css') }}", rel="stylesheet") script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery-3.1.0.min.js')}}") + script(src="{{ url_for('static_pillar', filename='assets/js/tutti.min.js') }}") + script(src="{{ url_for('static_attract', filename='assets/js/tutti.min.js') }}") | {% block style %}{% endblock %} @@ -38,8 +40,7 @@ html(lang="en") h1 Right | {% endblock %} - script(src="{{ url_for('static_pillar', filename='assets/js/tutti.min.js') }}") - script(src="{{ url_for('static_attract', filename='assets/js/tasks.js') }}", async=true) + script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.select2.min.js') }}", async=true) | {% block footer_scripts %}{% endblock %}