Url Decoder for Karma
by navyflower
HTML
<!-- Karma output url decoder ->
<!-- Hit "Remove new lines" once, then "Decode" a few times, then hit "Tidy" to restore lines -->
<div ng-app="myapp" ng-controller="Decoder">
<textarea rows="20" cols="100" ng-model="src"></textarea>
<p> <input type="button" value="Remove new lines" ng-click="decode1()" /> -- click once
</p>
<p> <input type="button" value="Decode" ng-click="decode2()" /> -- click a few times
</p>
<p>
<input type="button" value="Restore new lines" ng-click="tidy()" /> -- click once
</p>
</div>
CSS
input {
display: block;
clear: both;
}
JavaScript
angular.module("myapp", [])
.controller("Decoder", ['$scope', function($scope) {
$scope.decode1 = function() {
var str = $scope.src;
str = str.replace(/(\r\n|\n|\r)([ ]{2,})/gm, 'mynewline$2');
str = str.replace(/(\r\n|\n|\r)/gm, '');
$scope.src = str;
};
$scope.decode2 = function() {
var str = $scope.src;
str = decodeURIComponent(str);
$scope.src = str;
};
$scope.tidy = function() {
var str = $scope.src;
str = str.replace(/mynewline/gm, '\n');
$scope.src = str;
}
}])
;