var ngrok = angular.module("ngrok", []);
ngrok.directive({
"keyval": function() {
return {
scope: {
title: "@",
tuples: "=",
},
replace: true,
restrict: "E",
template: "" +
'
' +
'
{{title}}
' +
'
' +
'' +
'{{ key }} | ' +
'{{ value }} | ' +
'
' +
'
' +
'
',
link: function($scope) {
$scope.hasKeys = false;
for (key in $scope.tuples) { $scope.hasKeys = true; break; }
}
};
},
"tabs": function() {
return {
scope: {
"tabs": "@",
"btn": "@",
"onbtnclick": "&"
},
replace: true,
template: '' +
'' +
'- ' +
'{{tab}}' +
'
' +
'-
' +
'
',
link: function postLink(scope, element, attrs) {
scope.tabNames = attrs.tabs.split(",");
scope.activeTab = scope.tabNames[0];
scope.setTab = function(t) {
scope.activeTab = t;
};
scope.$parent.isTab = scope.isTab = function(t) {
return t == scope.activeTab;
};
},
};
},
"body": function($timeout) {
return {
scope: {
"body": "="
},
template: '' +
'' +
'{{ Body.Length }} bytes ' +
'{{ Body.RawContentType }}' +
'
' +
'' +
'' +
'
{{ Body.Text }}
' +
'
' +
'' +
'' +
'' +
'
' +
'' +
'{{ Body.Error }}' +
'
',
controller: function($scope) {
var body = $scope.body;
$scope.isForm = (body.ContentType == "application/x-www-form-urlencoded");
$scope.hasBody = (body.Length > 0);
$scope.hasError = !!body.Error;
$scope.syntaxClass = {
"text/xml": "xml",
"application/xml": "xml",
"text/html": "xml",
"text/css": "css",
"application/json": "json",
"text/javascript": "javascript",
"application/javascript": "javascript",
}[body.ContentType];
var transform = {
"xml": "xml",
"json": "json"
}[$scope.syntaxClass];
if (!$scope.hasError && !!transform) {
try {
body.Text = vkbeautify[transform](body.Text);
} catch (e) {
}
}
$scope.Body = body;
},
link: function($scope, $elem) {
$timeout(function() {
$code = $elem.find("code").get(0);
hljs.highlightBlock($code);
if ($scope.Body.ErrorOffset > -1) {
var offset = $scope.Body.ErrorOffset;
function textNodes(node) {
var textNodes = [];
function getTextNodes(node) {
if (node.nodeType == 3) {
textNodes.push(node);
} else {
for (var i = 0, len = node.childNodes.length; i < len; ++i) {
getTextNodes(node.childNodes[i]);
}
}
}
getTextNodes(node);
return textNodes;
}
var tNodes = textNodes($elem.find("code").get(0));
for (var i=0; i