Commit 739e2d71 authored by Tom Kirkpatrick's avatar Tom Kirkpatrick
Browse files

Issue #2084841 by mrfelton: Fixed JS errors if favicon can not be found.

parent f8839139
......@@ -143,7 +143,9 @@ Drupal.environmentIndicator.affectFavicon = function (color) {
}
};
iconImg.src = icon.href;
if (icon !== null) {
iconImg.src = icon.href;
}
return this;
};
......
......@@ -6,4 +6,4 @@
*
* affectFavicon() originally written by James Andres for WhatSite.js
* (https://github.com/jamesandres/WhatSite)
*/(function(e){Drupal.environmentIndicator=Drupal.environmentIndicator||{};Drupal.behaviors.environmentIndicator={attach:function(t,n){n.environment_indicator=e.extend({text:" ",color:"#d00c0c",suppress:!1,margin:!1,position:"left"},n.environment_indicator||{});if(n.environment_indicator.suppress)return;if(e("body:not(.environment-indicator-processed, .overlay)",t).length){n.environment_indicator.cssClass="environment-indicator-"+n.environment_indicator.position;var r=e("#environment-indicator",t);if(!r.length){e("body",t).prepend('<div id="environment-indicator">'+n.environment_indicator.text+"</div>");e("body",t).addClass(n.environment_indicator.cssClass);r=e("#environment-indicator",t);r.css("background-color",n.environment_indicator.color);r.html(n.environment_indicator.text.replace(/(.)/g,"$1<br />"));if(n.environment_indicator.margin){e("body:not(.environment-indicator-adjust)",t).addClass("environment-indicator-adjust");e("#toolbar").length&&e("#toolbar").css("margin-"+n.environment_indicator.position,"10px")}}Drupal.environmentIndicator.affectFavicon(n.environment_indicator.color);e("body:not(.environment-indicator-processed)",t).addClass("environment-indicator-processed")}}};Drupal.environmentIndicator.affectFavicon=function(e){if(!Drupal.environmentIndicator.canvasSupport())return;var t,n=document.getElementsByTagName("link"),r=null,i,s,o;for(t=n.length;t>=0;t-=1){if(typeof n[t]!="object")continue;i=n[t].getAttribute("rel");if(typeof i=="undefined")continue;if(i==="shortcut icon"||i==="icon"){r=n[t];break}}s=new Image;o=Drupal.environmentIndicator.splitColor(e).join(",");s.onload=function(){var e=document.createElement("canvas");e.setAttribute("width","16px");e.setAttribute("height","16px");typeof G_vmlCanvasManager!="undefined"&&G_vmlCanvasManager.initElement(e);var t=e.getContext("2d");t.lineCap="butt";t.drawImage(s,0,0);t.beginPath();t.strokeStyle="rgba("+o+",1)";t.lineWidth=4;t.moveTo(0,0);t.lineTo(e.width,0);t.stroke();t.beginPath();t.strokeStyle="rgba(0,0,0,0.7)";t.lineWidth=1;t.moveTo(0,2.5);t.lineTo(e.width,2.5);t.stroke();try{var n=r.cloneNode(!0);n.setAttribute("href",t.canvas.toDataURL());r.parentNode.replaceChild(n,r)}catch(i){}};s.src=r.href;return this};Drupal.environmentIndicator.splitColor=function(e){var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:null};Drupal.environmentIndicator.canvasSupport=function(){var e=!1;try{e=!!document.createElement("canvas").getContext("2d")}catch(t){e=!!document.createElement("canvas").getContext}return e}})(jQuery);
\ No newline at end of file
*/(function(e){Drupal.environmentIndicator=Drupal.environmentIndicator||{};Drupal.behaviors.environmentIndicator={attach:function(t,n){n.environment_indicator=e.extend({text:" ",color:"#d00c0c",suppress:false,margin:false,position:"left"},n.environment_indicator||{});if(n.environment_indicator.suppress){return}if(e("body:not(.environment-indicator-processed, .overlay)",t).length){n.environment_indicator.cssClass="environment-indicator-"+n.environment_indicator.position;var r=e("#environment-indicator",t);if(!r.length){e("body",t).prepend('<div id="environment-indicator">'+n.environment_indicator.text+"</div>");e("body",t).addClass(n.environment_indicator.cssClass);r=e("#environment-indicator",t);r.css("background-color",n.environment_indicator.color);r.html(n.environment_indicator.text.replace(/(.)/g,"$1<br />"));if(n.environment_indicator.margin){e("body:not(.environment-indicator-adjust)",t).addClass("environment-indicator-adjust");if(e("#toolbar").length){e("#toolbar").css("margin-"+n.environment_indicator.position,"10px")}}}Drupal.environmentIndicator.affectFavicon(n.environment_indicator.color);e("body:not(.environment-indicator-processed)",t).addClass("environment-indicator-processed")}}};Drupal.environmentIndicator.affectFavicon=function(e){if(!Drupal.environmentIndicator.canvasSupport()){return}var t,n=document.getElementsByTagName("link"),r=null,i,s,o;for(t=n.length;t>=0;t-=1){if(typeof n[t]!=="object"){continue}i=n[t].getAttribute("rel");if(typeof i==="undefined"){continue}if(i==="shortcut icon"||i==="icon"){r=n[t];break}}s=new Image;o=Drupal.environmentIndicator.splitColor(e).join(",");s.onload=function(){var e=document.createElement("canvas");e.setAttribute("width","16px");e.setAttribute("height","16px");if(typeof G_vmlCanvasManager!=="undefined"){G_vmlCanvasManager.initElement(e)}var t=e.getContext("2d");t.lineCap="butt";t.drawImage(s,0,0);t.beginPath();t.strokeStyle="rgba("+o+",1)";t.lineWidth=4;t.moveTo(0,0);t.lineTo(e.width,0);t.stroke();t.beginPath();t.strokeStyle="rgba(0,0,0,0.7)";t.lineWidth=1;t.moveTo(0,2.5);t.lineTo(e.width,2.5);t.stroke();try{var n=r.cloneNode(true);n.setAttribute("href",t.canvas.toDataURL());r.parentNode.replaceChild(n,r)}catch(i){}};if(r!==null){s.src=r.href}return this};Drupal.environmentIndicator.splitColor=function(e){var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:null};Drupal.environmentIndicator.canvasSupport=function(){var e=false;try{e=!!document.createElement("canvas").getContext("2d")}catch(t){e=!!document.createElement("canvas").getContext}return e}})(jQuery)
\ No newline at end of file
......@@ -87,7 +87,7 @@ function environment_indicator_init() {
// Performance: Defer execution.
drupal_add_js($path .'/environment_indicator.min.js');
//drupal_add_js($path .'/environment_indicator.js', array('preprocess' => FALSE));
drupal_add_js($path .'/environment_indicator.js', array('preprocess' => FALSE));
if ($setting = variable_get('environment_indicator_margin', 1)) {
$settings['margin'] = check_plain($setting);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment