Directives.directive (' Ueditor ', [ ' Common ', ' $rootScope ', function (Common, $rootScope) { return { Restrict: ' EA ', Require: ' Ngmodel ', Link:function (Scope, Ele, Attrs, ctrl) { $rootScope. $emit (' Loading ', ' Initialize editor ... ');//Broadcast loading event, you can delete var _self = this, _initcontent, Editor Editorready = False, Base = '/public/vendor/utf8_qiniu_ueditor-master ',//ueditor directory _id = Attrs.ueditor; var Editorhandler = { Init:function () { Window. Ueditor_home_url = base + '/'; var _self = this; if (typeof UE!= ' undefined ') { Editor = Ue.geteditor (_id, { Toolbars: [ [ ' FontSize ', ' | ', ' blockquote ', ' horizontal ', ' | ', ' Removeformat ', ' | ', ' Insertimage ', ' | ', ' Bold ', ' italic ', ' underline ', ' ForeColor ', ' BackColor ', ' | ', ' Justifyleft ', ' justifycenter ', ' justifyright ', ' justifyjustify ', ' Rowspacingtop ', ' rowspacingbottom ', ' lineheight ', ' | ', ' Insertorderedlist ', ' insertunorderedlist ', ' | ', ' Link ', ' unlink ', ' | ', ' Emotion ' ] ] }); Editor.ready (function () { Editor.setheight (500); Editorready = true; $rootScope. $emit (' Loading ', ');//editor Initialization complete Editor.addlistener (' Contentchange ', function () {//bidirectional binding if (!scope.$ $phase) { Scope. $apply (function () { Ctrl. $setViewValue (Editor.getcontent ()); }); } }); }); } else { Common.loadscript (base + '/ueditor.config.js ', null); Common.loadscript (base + '/ueditor.all.min.js ', function () { _self.init (); }); } }, Setcontent:function (content) { if (editor && Editorready) { Editor.setcontent (content); } } }; Ctrl. $render = function () { _initcontent = Ctrl. $isEmpty (CTRL. $viewValue)? ': Ctrl. $viewValue; Editorhandler.setcontent (_initcontent);/bi-directional binding }; Editorhandler.init (); Event $rootScope. $on (' $routeChangeStart ', function () { Editor && Editor.destroy (); }); } } } ]); |