diff --git a/app/assets/javascripts/highlightTags.js b/app/assets/javascripts/highlightTags.js new file mode 100644 index 000000000..05eee1343 --- /dev/null +++ b/app/assets/javascripts/highlightTags.js @@ -0,0 +1,47 @@ +(function(Modules) { + "use strict"; + + Modules.HighlightTags = function() { + + this.start = function(textarea) { + + this.$textbox = $(textarea) + .wrap( + "
" + ) + .after(this.$backgroundMaskForeground = $( + "" + + "" + + "" + )) + .on("input", this.update.bind(this)) + .on("scroll", this.maintainScrollParity.bind(this)); + + this.$textbox + .trigger("input"); + + }; + + this.update = function(event) { + this.$backgroundMaskForeground.html( + replaceTags(this.$textbox.val()) + ); + }; + + this.maintainScrollParity = function() { + this.$backgroundMaskForeground.scrollTop( + this.$textbox.scrollTop() + ); + }; + + }; + + function replaceTag(match) { + return ("" + match + ""); + } + + function replaceTags(content) { + return content.replace(/\(\([^\)\(]+\)\)/g, replaceTag); + } + +})(window.GOVUK.Modules); diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 5f96d14b0..df347f460 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -1,5 +1,8 @@ //= include ../../../bower_components/jquery/dist/jquery.js +//= include ../govuk_frontend_toolkit/javascripts/govuk/modules.js -(function() { - console.log("Hello world"); -})(); +//= include highlightTags.js + +$(function(){ + GOVUK.modules.start(); +}); diff --git a/app/assets/stylesheets/components/textbox.scss b/app/assets/stylesheets/components/textbox.scss new file mode 100644 index 000000000..1d2807709 --- /dev/null +++ b/app/assets/stylesheets/components/textbox.scss @@ -0,0 +1,83 @@ +.textbox-highlight { + + &-wrapper { + position: relative; + } + + &-textbox { + resize: none; + z-index: 20; + background: none; + } + + &-textbox, + &-background, + &-foreground, + &-mask { + @include core-19; + display: block; + box-sizing: border-box; + position: relative; + width: 500px; + height: 200px; + margin: 0; + padding: 4px; + overflow: hidden; + } + + &-background, + &-foreground, + &-mask { + position: absolute; + top: 0; + left: 0; + pointer-events: none; + color: transparent; + white-space: pre-wrap; + border: 2px solid transparent; + } + + &-background { + + z-index: 10; + + .tag { + background: $light-blue; + border-radius: 3px; + color: transparent; + display: inline; + } + + } + + &-mask { + + z-index: 30; + + .tag { + color: $white; + text-shadow: 0 1px 0 $light-blue, 0 -1px 0 $light-blue; + position: relative; + display: inline; + overflow: hidden; + } + + } + + &-foreground { + + z-index: 40; + + .tag { + color: transparent; + border-radius: 3px; + overflow: hidden; + display: inline; + box-shadow: inset 0.75em 0 0 0 rgba($light-blue, .7), + inset -0.75em 0 0 0 rgba($light-blue, .7); + } + + } + + +} diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index 13ac54a99..ece58780a 100644 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -38,6 +38,7 @@ @import 'components/navigation'; @import 'components/big-number'; @import 'components/banner'; +@import 'components/textbox'; @import 'views/job'; diff --git a/app/templates/admin_template.html b/app/templates/admin_template.html index bff13ff6f..76947a435 100644 --- a/app/templates/admin_template.html +++ b/app/templates/admin_template.html @@ -47,5 +47,5 @@ {% endblock %} {% block body_end %} - + {% endblock %} diff --git a/app/templates/components/textbox.html b/app/templates/components/textbox.html index 7d5e640bd..a32a76c4b 100644 --- a/app/templates/components/textbox.html +++ b/app/templates/components/textbox.html @@ -1,10 +1,15 @@ -{% macro textbox(name, label, value='', small=True) %} +{% macro textbox(name, label, value='', small=True, highlight_tags=False) %}- Sent with template {{ template_used }} at {{ uploaded_file_time }} + Sent with template {{ template_used }} at {{ uploaded_file_time }}
{% call(item) table( diff --git a/bower.json b/bower.json index 312bf3293..efa72b2c5 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,6 @@ "name": "GOV.UK Notify admin frontend", "version": "0.0.1", "dependencies": { - "jquery": "1.11.2", "govuk_template": "https://github.com/alphagov/govuk_template/releases/download/v0.16.0/jinja_govuk_template-0.16.0.tgz" } } diff --git a/gulpfile.js b/gulpfile.js index f480f2bc7..e316b67eb 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -34,6 +34,20 @@ gulp.task('copy:govuk_template:assets', function() { // Concatenate and minify +gulp.task('jquery', function () { + return plugins.jquery.src({ + release: 1, + flags: [ + '-ajax', '-ajax/jsonp', '-ajax/load', '-ajax/parseJSON', + '-ajax/parseXML', '-ajax/script', '-ajax/var/nonce', + '-ajax/var/rquery', '-ajax/xhr', '-manipulation/_evalUrl', + '-deprecated', '-effects', '-effects/Tween', + '-effects/animatedSelector', '-effects/support', '-event-alias' + ] + }) + .pipe(gulp.dest(paths.dist + 'javascripts/')); +}); + gulp.task('javascripts', function() { return gulp.src(paths.src + 'javascripts/main.js') .pipe(plugins.include()) @@ -68,7 +82,7 @@ gulp.task('watchForChanges', function() { // Default: compile everything gulp.task('default', - ['copy:govuk_template:template', 'copy:govuk_template:assets', 'javascripts', 'sass', 'images'] + ['copy:govuk_template:template', 'copy:govuk_template:assets', 'jquery', 'javascripts', 'sass', 'images'] ); // Optional: recompile on changes diff --git a/package.json b/package.json index 20c6dd27a..6f62fee9d 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,10 @@ "bower": "1.7.1", "gulp": "3.9.0", "gulp-include": "2.1.0", + "gulp-jquery": "1.1.1", "gulp-load-plugins": "1.1.0", "gulp-sass": "2.1.1", - "gulp-uglify": "1.5.1" + "gulp-uglify": "1.5.1", + "jquery": "1.11.2" } }