]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2342 Don't display if browser does not support HTML5 localstorage
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Wed, 21 Nov 2012 11:27:37 +0000 (12:27 +0100)
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Wed, 21 Nov 2012 16:11:35 +0000 (17:11 +0100)
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_resource_history.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb
sonar-server/src/main/webapp/javascripts/application.js
sonar-server/src/main/webapp/javascripts/recent-history.js
sonar-server/src/main/webapp/stylesheets/layout.css

index 46937d5d91b11bbcb505916e7d9cd8fda6013f7f..ae8dfd5f849b2037614673f466593e215d43160d 100644 (file)
@@ -1,17 +1,24 @@
 <script>
-  var sonarRecentHistory = new Sonar.RecentHistory('<%= ApplicationController.root_context -%>')
-                                       .addTranslation('clear', '<%= message('layout.recent_history.clear') -%>')
-                                       .addTranslation('no_history_yet', '<%= message('layout.recent_history.no_history_yet') -%>');
-  
-  sonarRecentHistory.add('<%= @resource ? @resource.key : "" -%>', 
-                         '<%= @resource ? @resource.name : "" -%>', 
-                         '<%= @resource ? @resource.qualifier : "" -%>');  
+  if (supports_html5_storage()) {
+    var sonarRecentHistory = new Sonar.RecentHistory('<%= ApplicationController.root_context -%>')
+                                      .addTranslation('clear', '<%= message('layout.recent_history.clear') -%>')
+                                      .addTranslation('no_history_yet', '<%= message('layout.recent_history.no_history_yet') -%>');
+  }
 </script>
 
-<div class="dropdown">
+<div class="dropdown" id="sonar_recent_history_div">
   <a href="#" class="link-more" onclick="sonarRecentHistory.populateRecentHistoryDropDown(); $('sonar_recent_history_dropdown').toggle();return false;"><%= message('layout.recent_history.link') -%></a>
   
   <ul style="display: none" class="dropdown-menu" id="sonar_recent_history_dropdown" onmouseout="this.hide();" onmouseover="this.show();">
   </ul>
-  
-</div>
\ No newline at end of file
+</div>
+
+<script>
+  if (sonarRecentHistory == null) {
+    $j('#sonar_recent_history_div').detach();
+  } else {
+    sonarRecentHistory.add('<%= @resource ? @resource.key : "" -%>', 
+                           '<%= @resource ? @resource.name(true) : "" -%>', 
+                           '<%= @resource ? @resource.qualifier : "" -%>');
+  }
+</script>
\ No newline at end of file
index a5c092c063d89d0f2d216ec0650036140915849c..55724f089507302e1cb5f01ee74440a60d9ffbd6 100644 (file)
@@ -1,7 +1,9 @@
 <script>
-  sonarRecentHistory.add('<%= @resource.key -%>', 
-                         '<%= @resource.name -%>', 
-                         '<%= @resource.qualifier -%>');  
+  if (sonarRecentHistory != null) {
+    sonarRecentHistory.add('<%= @resource.key -%>', 
+                           '<%= @resource.name(true) -%>', 
+                           '<%= @resource.qualifier -%>');
+  }  
 </script>
 
 <%= render :partial => 'tabs' -%>
index 345802d5411a92851d3c0f90b11d8f66206e9abd..adb76a2821a7410052df9aca7b7eb7d6c7730338 100644 (file)
@@ -327,4 +327,12 @@ Treemap.prototype.onLoaded = function (componentsSize) {
 function closeModalWindow() {
   $j('#modal').dialog('close');
   return false;
+}
+
+function supports_html5_storage() {
+  try {
+    return 'localStorage' in window && window['localStorage'] !== null;
+  } catch (e) {
+    return false;
+  }
 }
\ No newline at end of file
index 986bc362d43e1280895f452a5a951569e87c1c1e..ad734f5ce0b10dd0e18fde7ac6015395003a89df 100644 (file)
@@ -6,7 +6,7 @@ Sonar.RecentHistory = function (applicationContext) {
   this.addTranslation = function (key, value) {
     this.translations[key] = value;
     return this;
-  }
+  };
 };
 
 Sonar.RecentHistory.prototype.getRecentHistory = function() {
index a3ce8614e73ee980d5df658e190c09e38d573514..af735aeb47ca2c422d47f396b5cbc20999814c96 100644 (file)
@@ -148,6 +148,10 @@ body, a {
   padding: 0 5px 0 0;
 }
 
+#sonar_recent_history_dropdown {
+  max-width: none !important;
+}
+
 #sonar_recent_history_dropdown a {
   color: #000 !important;
   display: inline !important;