Web development server initial prototype.
3 // Declare app level module which depends on filters, and services
4 angular.module('bck2brwsr', []).
5 directive('uiCodemirror', ['$timeout', function($timeout) {
8 var events = ["cursorActivity", "viewportChange", "gutterClick", "focus", "blur", "scroll", "update"];
12 link: function(scope, elm, attrs, ngModel) {
13 var options, opts, onChange, deferCodeMirror, codeMirror, timeoutId, val;
15 if (elm[0].type !== 'textarea') {
16 throw new Error('uiCodemirror3 can only be applied to a textarea element');
19 options = /* uiConfig.codemirror || */ {};
20 opts = angular.extend({}, options, scope.$eval(attrs.uiCodemirror));
22 onChange = function(instance, changeObj) {
23 val = instance.getValue();
24 $timeout.cancel(timeoutId);
25 timeoutId = $timeout(function() {
26 ngModel.$setViewValue(val);
30 deferCodeMirror = function() {
31 codeMirror = CodeMirror.fromTextArea(elm[0], opts);
32 // codeMirror.on("change", onChange(opts.onChange));
33 codeMirror.on("change", onChange);
35 for (var i = 0, n = events.length, aEvent; i < n; ++i) {
36 aEvent = opts["on" + events[i].charAt(0).toUpperCase() + events[i].slice(1)];
37 if (aEvent === void 0)
39 if (typeof aEvent !== "function")
42 var bound = _.bind( aEvent, scope );
44 codeMirror.on(events[i], bound);
47 // CodeMirror expects a string, so make sure it gets one.
48 // This does not change the model.
49 ngModel.$formatters.push(function(value) {
50 if (angular.isUndefined(value) || value === null) {
53 else if (angular.isObject(value) || angular.isArray(value)) {
54 throw new Error('ui-codemirror cannot use an object or an array as a model');
59 // Override the ngModelController $render method, which is what gets called when the model is updated.
60 // This takes care of the synchronizing the codeMirror element with the underlying model, in the case that it is changed by something else.
61 ngModel.$render = function() {
62 codeMirror.setValue(ngModel.$viewValue);
67 $timeout(deferCodeMirror);
73 function DevCtrl( $scope, $http ) {
75 $scope.reload= function() {
76 var frame = document.getElementById("result");
77 frame.src = "result.html";
78 frame.contentDocument.location.reload(true);
79 frame.contentWindow.location.reload();
82 $scope.post = function(html, java) {
83 return $http({url: ".",
85 //headers: this.headers,
86 data: { html : $scope.html, java : $scope.java}
87 }).success( $scope.reload );
94 $scope.tabActive = function( tab ) {
95 return tab === $scope.tab ? "active" : "";
98 // $scope.$watch( "html", htmlChange );