1.1 --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js Mon Jan 21 22:10:08 2013 +0100
1.2 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js Tue Jan 22 19:48:10 2013 +0100
1.3 @@ -120,19 +120,59 @@
1.4 + "}\n";
1.5
1.6
1.7 + $scope.makeMarker = function( editor, line ) {
1.8 + var marker = document.createElement("div");
1.9 + marker.innerHTML = " ";
1.10 + marker.className = "issue";
1.11 +
1.12 + var info = editor.lineInfo(line);
1.13 + editor.setGutterMarker(line, "issues", info.markers ? null : marker);
1.14 +
1.15 + return marker;
1.16 + };
1.17 +
1.18 +
1.19 + // Returns a function, that, as long as it continues to be invoked, will not
1.20 + // be triggered. The function will be called after it stops being called for
1.21 + // N milliseconds. If `immediate` is passed, trigger the function on the
1.22 + // leading edge, instead of the trailing.
1.23 + $scope.debounce = function(func, wait, immediate) {
1.24 + var timeout, result;
1.25 + return function() {
1.26 + var context = this, args = arguments;
1.27 + var later = function() {
1.28 + timeout = null;
1.29 + if (!immediate) result = func.apply(context, args);
1.30 + };
1.31 + var callNow = immediate && !timeout;
1.32 + clearTimeout(timeout);
1.33 + timeout = setTimeout(later, wait);
1.34 + if (callNow) result = func.apply(context, args);
1.35 + return result;
1.36 + };
1.37 + };
1.38 +
1.39 $scope.reload = function() {
1.40 $scope.errors = null;
1.41 var frame = document.getElementById("result");
1.42 frame.src = "result.html";
1.43 frame.contentDocument.location.reload(true);
1.44 frame.contentWindow.location.reload();
1.45 + document.getElementById("editorJava").codeMirror.clearGutter("issues");
1.46 };
1.47
1.48 $scope.fail = function( data ) {
1.49 $scope.errors = eval( data );
1.50 + var editor = document.getElementById("editorJava").codeMirror;
1.51 + editor.clearGutter( "issues" );
1.52 +
1.53 + for( var i = 0; i < $scope.errors.length; i ++ ) {
1.54 + $scope.makeMarker( editor, $scope.errors[i].line - 1 );
1.55 + }
1.56 +
1.57 };
1.58
1.59 - $scope.post = function(html, java) {
1.60 + $scope.post = function() {
1.61 return $http({url: ".",
1.62 method: "POST",
1.63 //headers: this.headers,
1.64 @@ -151,7 +191,7 @@
1.65
1.66 $scope.gotoError = function( line, col ) {
1.67 var editor = document.getElementById("editorJava").codeMirror;
1.68 - editor.setCursor({ line: line - 1, ch : col });
1.69 + editor.setCursor({ line: line - 1, ch : col - 1 });
1.70 editor.focus();
1.71 };
1.72
1.73 @@ -159,11 +199,8 @@
1.74 $scope.html= templateHtml;
1.75 $scope.java = templateJava;
1.76
1.77 - $scope.tabActive = function( tab ) {
1.78 - return tab === $scope.tab ? "active" : "";
1.79 - };
1.80 -
1.81 - // $scope.$watch( "html", htmlChange );
1.82 + $scope.$watch( "html", $scope.debounce( $scope.post, 2000 ) );
1.83 + $scope.$watch( "java", $scope.debounce( $scope.post, 2000 ) );
1.84 $scope.post();
1.85
1.86 }