Skip to content

Instantly share code, notes, and snippets.

@hui
Last active December 16, 2015 12:29
Show Gist options
  • Select an option

  • Save hui/5435247 to your computer and use it in GitHub Desktop.

Select an option

Save hui/5435247 to your computer and use it in GitHub Desktop.
kindeditor for angularjs
angular.module('kindeditor', []).directive 'kindeditor', ->
require: '?ngModel'
link: (scope, elm, attr, ngModel)->
unless ngModel then return
ngModel.$render = (value)->
unless ngModel.editor
csrfToken = $('meta[name=csrf-token]').attr('content')
csrfParam = $('meta[name=csrf-param]').attr('content')
extraParams = {}
extraParams[csrfParam] = csrfToken
ke = KindEditor.create $(elm[0]), basePath: '/kindeditor/', uploadJson: '/upload', extraFileUploadParams: extraParams, afterChange: ()->
if ke
ngModel.$setViewValue(ke.html())
ngModel.editor = ke
ngModel.editor.html(ngModel.$viewValue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment