Last active
August 29, 2015 14:04
-
-
Save mkawalec/7e8c80a08e8c8496961e to your computer and use it in GitHub Desktop.
Edyt debug mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
if (typeof window === 'undefined') { | |
return ; | |
} | |
var XHR = window.XMLHttpRequest, | |
tmpSend = XHR.prototype.send, | |
tmpOpen = XHR.prototype.open; | |
XHR.prototype.open = function (type, url, async, user, pass) { | |
url = url.split('/'); | |
if (url[1] === '') { | |
//remove domain in exists | |
url = '/' + url.splice(3) .join('/'); | |
} else { | |
url = url.join('/'); | |
} | |
return tmpOpen.apply(this, arguments); | |
}; | |
XHR.prototype.send = function (data) { | |
// Any change before sending xhr request ? | |
return tmpSend.apply(this, arguments); | |
} | |
var isObject = function (obj) { | |
return obj === Object(obj); | |
}; | |
require(["dijit/registry", "dojo/topic", 'dojo/on', 'dojo/_base/lang'], | |
function (registry, topic, on, lang) { | |
// If inbetween is true, it means that there was a | |
// DOMSubtreeModified event that has not resulted | |
// in plugin recomputation and thus the recomputation | |
// needs to be fired on the root of the DOM. | |
var listener, lastCall, inbetween=false; | |
var markNodes = function (rootNode) { | |
rootNode = rootNode || document; | |
var nodes = rootNode.getElementsByTagName("*"), | |
forEach = Array.prototype.forEach; | |
forEach.call(nodes, function (node) { | |
var dojoInfo = registry.byNode(node); | |
if (dojoInfo) { | |
node.setAttribute('data-debug-class', dojoInfo.declaredClass); | |
} | |
}); | |
}; | |
topic.subscribe('teampatent.onLayoutChange', function () { | |
markNodes(); | |
if (listener) { | |
listener.remove(); | |
} | |
listener = on(document, 'DOMSubtreeModified', function (e) { | |
var call = Math.random(); | |
lastCall = call; | |
setTimeout(function () { | |
if (lastCall === call) { | |
if (inbetween) { | |
markNodes(); | |
} else { | |
markNodes(e.target); | |
} | |
inbetween = false; | |
} else { | |
inbetween = true; | |
} | |
}, 100); | |
}); | |
}); | |
}); | |
}) (); | |
(function () { | |
if (typeof window === 'undefined') { | |
return ; | |
} | |
//inform about no TPDebug | |
if (window.location.search.indexOf('TPDebug') === - 1) { | |
if (confirm('Do you want to open this site with TPDebug?')) { | |
window.location.search = (window.location.search ? window.location.search + '&' : '?') + 'TPDebug=true&allowErrors=true&theme=vienna2'; | |
} | |
} | |
}) (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment