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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | 1 30 30 30 30 30 1 1 29 29 29 29 29 29 29 29 29 29 29 9 9 4 4 4 29 3 3 29 29 29 5 5 2 2 2 5 2 3 3 29 7 9 29 29 1 28 29 29 | /** * Copyright (c) 2013 JeongHoon Byun aka "Outsider", <http://blog.outsider.ne.kr/> * Licensed under the MIT license. * <http://outsider.mit-license.org/> */ /* global angular */ angular.module('summernote', []) .controller('SummernoteController', ['$scope', '$attrs', function($scope, $attrs) { 'use strict'; var currentElement, summernoteConfig = $scope.summernoteConfig || {}; if (angular.isDefined($attrs.height)) { summernoteConfig.height = $attrs.height; } if (angular.isDefined($attrs.focus)) { summernoteConfig.focus = true; } if (angular.isDefined($attrs.airmode)) { summernoteConfig.airMode = true; } if (angular.isDefined($attrs.lang)) { Eif (!angular.isDefined($.summernote.lang[$attrs.lang])) { throw new Error('"' + $attrs.lang + '" lang file must be exist.'); } summernoteConfig.lang = $attrs.lang; } summernoteConfig.oninit = $scope.init; summernoteConfig.onenter = function(evt) { $scope.enter({evt:evt}); }; summernoteConfig.onfocus = function(evt) { $scope.focus({evt:evt}); }; summernoteConfig.onblur = function(evt) { $scope.blur({evt:evt}); }; summernoteConfig.onpaste = function(evt) { $scope.paste({evt:evt}); }; summernoteConfig.onkeyup = function(evt) { $scope.keyup({evt:evt}); }; summernoteConfig.onkeydown = function(evt) { $scope.keydown({evt:evt}); }; summernoteConfig.onChange = function(contents, editable$) { $scope.change({contents:contents, editable$: editable$}); }; Iif (angular.isDefined($attrs.onImageUpload)) { summernoteConfig.onImageUpload = function(files, editor, welEditable) { $scope.imageUpload({files:files, editor:editor, welEditable:welEditable}); }; } this.activate = function(scope, element, ngModel) { var updateNgModel = function() { var newValue = element.code(); if (ngModel && ngModel.$viewValue !== newValue) { ngModel.$setViewValue(newValue); Eif ($scope.$$phase !== '$apply' || $scope.$$phase !== '$digest' ) { scope.$apply(); } } }; summernoteConfig.onChange = function(contents, editable$) { updateNgModel(); $scope.change({contents:contents, editable$: editable$}); }; element.summernote(summernoteConfig); var editor$ = element.next('.note-editor'), unwatchNgModel; editor$.find('.note-toolbar').click(function() { updateNgModel(); // sync ngModel in codeview mode if (editor$.hasClass('codeview')) { editor$.on('keyup', updateNgModel); Eif (ngModel) { unwatchNgModel = scope.$watch(function () { return ngModel.$modelValue; }, function(newValue, oldValue) { editor$.find('.note-codable').val(newValue); }); } } else { editor$.off('keyup', updateNgModel); Iif (angular.isFunction(unwatchNgModel)) { unwatchNgModel(); } } }); if (ngModel) { ngModel.$render = function() { element.code(ngModel.$viewValue || ''); }; } currentElement = element; }; $scope.$on('$destroy', function () { currentElement.destroy(); }); }]) .directive('summernote', [function() { 'use strict'; return { restrict: 'EA', transclude: true, replace: true, require: ['summernote', '^?ngModel'], controller: 'SummernoteController', scope: { summernoteConfig: '=config', init: '&onInit', enter: '&onEnter', focus: '&onFocus', blur: '&onBlur', paste: '&onPaste', keyup: '&onKeyup', keydown: '&onKeydown', change: '&onChange', imageUpload: '&onImageUpload' }, template: '<div class="summernote"></div>', link: function(scope, element, attrs, ctrls) { var summernoteController = ctrls[0], ngModel = ctrls[1]; summernoteController.activate(scope, element, ngModel); } }; }]); |