-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplemark.controller.js
48 lines (35 loc) · 1.69 KB
/
simplemark.controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
app.controller("rhs.simplemarkcontroller", function ($scope, $log, $timeout, assetsService, dialogService, imageHelper) {
/* Syntax coloring */
if ($scope.model.config.coloredSyntax === null) {
$scope.model.config.coloredSyntax = 0;
}
/* Use default value if present and editor is empty */
if ($scope.model.value === null || $scope.model.value === "") {
$scope.model.value = $scope.model.config.defaultValue;
}
/* Load ghostdown */
assetsService.load(["/app_plugins/simplemark/lib/ghostdown.js", "/app_plugins/simplemark/lib/jquery.ghostdown.js"]).then(function () {
var theEditor = $("#editor_" + $scope.model.alias).ghostDown();
theEditor.ghostDown.getEditor().refresh();
$('a[data-toggle="tab"]').on('shown', function (e) {
theEditor.ghostDown.getEditor().refresh();
});
$timeout(function () {
theEditor.ghostDown.getEditor().refresh();
theEditor.ghostDown.getEditor().on("change", function (editor, args) {
$scope.model.value = editor.getValue();
});
});
});
/* Insert image */
$scope.insertImage = function () {
dialogService.mediaPicker({ callback: function (data) {
var imagePropVal = imageHelper.getImagePropertyValue({ imageModel: data, scope: $scope }),
theEditor = $("#editor_" + $scope.model.alias).ghostDown.getEditor();
theEditor.replaceSelection(' <img src="' + imagePropVal + '" style="max-width:100%" /> ', 'end');
$scope.model.value = theEditor.getValue();
}
});
}
assetsService.loadCss("/app_plugins/simplemark/lib/ghostdown.css");
});