Fix debug mode

manipulating window.location.search isn't reliable
This commit is contained in:
Lorenz Hübschle-Schneider 2014-12-22 21:14:28 +01:00 committed by Tor Hveem
parent 12ac7f742a
commit 51e5817cbd

View file

@ -1,7 +1,10 @@
(function() {
'use strict';
var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'plugins', 'IrcUtils', 'ngSanitize', 'ngWebsockets', 'ngTouch']);
var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'plugins', 'IrcUtils', 'ngSanitize', 'ngWebsockets', 'ngTouch'], function($compileProvider) {
// hacky way to be able to find out if we're in debug mode
weechat.compileProvider = $compileProvider;
});
weechat.config(['$compileProvider', function ($compileProvider) {
// hack to determine whether we're executing the tests
if (typeof(it) === "undefined" && typeof(describe) === "undefined") {
@ -69,22 +72,16 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// Enable debug mode if "?debug=1" or "?debug=true" is set
(function() {
var hasReloaded = false;
window.location.search.substring(1).split('&').forEach(function(f) {
var segs = f.split('=');
if (segs[0] === "debug" && ["true", "1"].indexOf(segs[1]) != -1) {
$rootScope.debugMode = true;
} else if (segs[0] === "debugReload" && segs[1] === "1") {
hasReloaded = true;
}
});
// If we haven't reloaded yet, do an angular reload with debug infos
// store whether this has happened yet in a GET parameter
if ($rootScope.debugMode && !hasReloaded) {
document.location.search += "&debugReload=1";
setTimeout(function() {
if ($rootScope.debugMode && !weechat.compileProvider.debugInfoEnabled()) {
angular.reloadWithDebugInfo();
}, 0);
}
})();