Last active
March 21, 2018 09:24
-
-
Save bettysteger/f756abac5455177d454f2add2e10ab61 to your computer and use it in GitHub Desktop.
Simple angular wrapper for alloy editor (Angular 1.x component)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* Alloy editor component | |
*/ | |
angular.module('myApp').component('alloyEditor', { | |
template: '<div id="alloyeditor"></div>', | |
require: { | |
ngModel: 'ngModel' | |
}, | |
controller: function () { | |
var ctrl = this, | |
alloyEditor = AlloyEditor.editable('alloyeditor'), | |
nativeEditor = alloyEditor.get('nativeEditor'); | |
// model -> view | |
// Content of contenteditable element will be set | |
var render = function() { | |
var content = ctrl.ngModel && ctrl.ngModel.$viewValue; | |
nativeEditor.setData(content || ''); | |
}; | |
ctrl.$onInit = function () { | |
ctrl.ngModel.$render = render; | |
}; | |
// view -> model | |
nativeEditor.on('change', function() { | |
ctrl.ngModel.$setViewValue(nativeEditor.getData() || ''); | |
}); | |
nativeEditor.once('focus', function() { | |
ctrl.ngModel.$setTouched(); | |
}); | |
ctrl.$onDestroy = function () { | |
alloyEditor.destroy(); | |
}; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For uploading the images instead of storing them as base64, use something like this: