Commit df5bbad5 authored by leonardo menezes's avatar leonardo menezes Committed by GitHub
Browse files

Merge pull request #26 from Tonyko/fix-favicon

Fix favicon
parents 64074d96 5f280950
Loading
Loading
Loading
Loading
+886 B
Loading image diff...
+1 KiB
Loading image diff...
+932 B
Loading image diff...
+955 B
Loading image diff...
+11 −23
Original line number Diff line number Diff line
@@ -2125,15 +2125,17 @@ angular.module('cerebro').factory('ModalService', ['$sce', function($sce) {
angular.module('cerebro').factory('PageService', ['DataService', '$rootScope',
  '$document', function(DataService, $rootScope, $document) {

    var link = $document[0].querySelector('link[rel~=\'icon\']');
    var clusterName;
    var clusterStatus;

    if (link) {
      var faviconUrl = link.href;
      var img = $document[0].createElement('img');
      img.src = faviconUrl;
    }
    var link = $document[0].querySelector('link[rel~=\'icon\']');

    var colors = {
      green: 'img/green-favicon.png',
      yellow: 'img/yellow-favicon.png',
      red: 'img/red-favicon.png',
      black: 'img/black-favicon.png'
    };

    this.setup = function(newName, newStatus) {
      setPageTitle(newName);
@@ -2155,23 +2157,9 @@ angular.module('cerebro').factory('PageService', ['DataService', '$rootScope',
    var setFavIconColor = function(newClusterStatus) {
      if (link) {
        clusterStatus = newClusterStatus;
        try {
          var colors = {green: '#1AC98E', yellow: '#E4D836', red: '#E64759'};
          var color = clusterStatus ? colors[clusterStatus] : '#222426';
          var canvas = $document[0].createElement('canvas');
          canvas.width = 32;
          canvas.height = 34;
          var context = canvas.getContext('2d');
          context.drawImage(img, 0, 0);
          context.globalCompositeOperation = 'source-in';
          context.fillStyle = color;
          context.fillRect(0, 0, 32, 34);
          context.fill();
        var url = clusterStatus ? colors[clusterStatus] : colors.black;
        link.type = 'image/png';
          link.href = canvas.toDataURL();
        } catch (exception) {
          //
        }
        link.href = url;
      }
    };

Loading