this is my controller code
$scope.aceOptions = {
workerPath: 'http://localhost:50871/Scripts/app/vendor/',
useWrapMode: true,
showGutter: true,
theme: 'chrome',
firstLineNumber: 1,
onLoad: function (_editor) {
$scope.script = {};
$scope.script.scriptCode = "function fieldName_columnName_" + "functionName(){\n\n\n}";
var _session = _editor.getSession();
_session.setMode('ace/mode/javascript');
var _renderer = _editor.renderer;
_session.on('changeAnnotation', function () {
$scope.annotations = [];
$scope.annotations = _editor.getSession().getAnnotations();
}),
_editor.$blockScrolling = Infinity;
_session.on("change", function (e) {
var currentValue = _editor.getSession().getValue();
$scope.script.scriptCode = currentValue;
});
},
require: ['ace/ext/language_tools'],
advanced: {
enableSnippets: true,
enableBasicAutocompletion: true,
enableLiveAutocompletion: true
}
}
i wrote directive for ui-ace this is my html code
<javascript-editor code="script.scriptCode" ace-option="aceOptions"></javascript-editor>
and directive code is
SCSApp
.directive('javascriptEditor', [
function () {
return {
restrict: 'E',
scope: {
data: '=code',
aceOption: '='
},
templateUrl: '/Scripts/app/shared/directives/javascripEditor/partials/javascriptEditor.html',
link: function (scope, element, attrs) {
}
}
}]);
and this is my javascriptEditor.html
<div class="e1" ui-ace="aceOption" ng-model="data"></div>
i just want to restrict user not to write morethan one javascript function in ui-ace editor
You can create your own javascript simple function parser or use a lib like parser3
Then write logic rules to show the success/fail to the UI based on the content of the ACE editor.
It is string / sentences parsing like compilers do in order to create the low level code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With