From 4a7e8126b8c34b4026c1daba75735d26017601d8 Mon Sep 17 00:00:00 2001
From: "Mark Allen Matney, Jr" <mmatney@library.ucla.edu>
Date: Mon, 6 Aug 2018 15:40:05 -0700
Subject: [PATCH] scope Mirador's jQuery UI CSS rules to '.mirador-container'

---
 .gitignore   |  1 +
 Gruntfile.js | 25 ++++++++++++++++++++++---
 package.json |  1 +
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore
index b6695270f..70eb45898 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@ _SpecRunner.html
 bkp
 css/discovery.css
 css/mirador.css
+css/jquery-ui-scoped.css
 dev.html
 discovery.html
 js/discovery
diff --git a/Gruntfile.js b/Gruntfile.js
index 60d1f7533..bafe2c97d 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -13,6 +13,7 @@ module.exports = function(grunt) {
   grunt.loadNpmTasks('grunt-contrib-cssmin');
   grunt.loadNpmTasks('grunt-contrib-copy');
   grunt.loadNpmTasks('grunt-githooks');
+  grunt.loadNpmTasks('grunt-css-selectors');
 
   // ----------
   var distribution = 'build/mirador/mirador.js',
@@ -94,7 +95,7 @@ module.exports = function(grunt) {
           'css/bootstrap.modals.css',
           'css/normalize.css',
           'node_modules/font-awesome/css/font-awesome.min.css',
-          'css/jquery-ui.min.css',
+          'css/jquery-ui-scoped.css',
           'node_modules/jstree/dist/themes/default/style.min.css',
           'css/collection-tree-mod.css',
           'node_modules/qtip2/dist/jquery.qtip.min.css',
@@ -249,6 +250,19 @@ module.exports = function(grunt) {
       ci: {
         src: 'reports/coverage/PhantomJS*/lcov.info'
       }
+    },
+
+    css_selectors: {
+      options: {
+        mutations: [{
+          prefix: '.mirador-container'
+        }]
+      },
+      your_target: {
+        files: {
+          'css/jquery-ui-scoped.css': ['css/jquery-ui.min.css']
+        }
+      }
     }
   });
 
@@ -268,15 +282,20 @@ module.exports = function(grunt) {
   // Lint task
   grunt.registerTask('lint', ['jshint', 'eslint']);
 
+  // ----------
+  // jQueryUI CSS task.
+  // Scopes all jQueryUI CSS selectors with '.mirador-container'.
+  grunt.registerTask('jqueryui_css', ['css_selectors']);
+
   // ----------
   // Build task.
   // Cleans out the build folder and builds the code and images into it, checking lint.
-  grunt.registerTask('build', [ 'clean:build', 'git-describe', 'lint', 'less', 'concat', 'uglify', 'cssmin', 'copy']);
+  grunt.registerTask('build', [ 'clean:build', 'git-describe', 'lint', 'less', 'jqueryui_css', 'concat', 'uglify', 'cssmin', 'copy']);
 
   // ----------
   // Dev Build task.
   // Build, but skip the time-consuming and obscurantist minification and uglification.
-  grunt.registerTask('dev_build', [ 'clean:build', 'git-describe', 'lint', 'less', 'concat', 'copy']);
+  grunt.registerTask('dev_build', [ 'clean:build', 'git-describe', 'lint', 'less', 'jqueryui_css', 'concat', 'copy']);
 
   // ----------
   // Default task.
diff --git a/package.json b/package.json
index e27b32cc2..ad0b31ef4 100644
--- a/package.json
+++ b/package.json
@@ -28,6 +28,7 @@
     "grunt-contrib-less": "^1.4.0",
     "grunt-contrib-uglify": "*",
     "grunt-contrib-watch": "*",
+    "grunt-css-selectors": "^1.3.0",
     "grunt-git-describe": "*",
     "grunt-githooks": "^0.3.1",
     "grunt-template-jasmine-istanbul": "^0.3.3",
-- 
GitLab