<commit_before>angular.module('ngMeditor', []);
angular.module('ngMeditor')
    .provider('meditorProvider', function() {
        var commands = {
            'bold': {
                name: 'bold',
                faIcon: 'fa fa-bold',
                tag: 'b'
            },
            'italic': {
                name: 'italic',
                faIcon: 'fa fa-italic',
                tag: 'i'
            },
            'underline': {
                name: 'underline',
                faIcon: 'fa fa-underline',
                tag: 'u'
            },
            'hr': {
                name: 'insertHorizontalRule',
                faIcon: 'fa fa-minus',
                tag: 'hr'
            },
            'eraser': {
                name: 'removeFormat',
                faIcon: 'fa fa-eraser'
            },
            'insertOrderedList': {
                faIcon: 'fa fa-list-ul',
                children: [{
                    name: 'insertUnorderedList',
                    faIcon: 'fa fa-list-ul',
                    tag: 'ul'
                }, {
                    name: "insertOrderedList",
                    faIcon: 'fa fa-list-ol',
                    tag: 'ol'
                }]
            },
            'code': {
                name: 'formatBlock',
                param: 'pre',
                faIcon: 'fa fa-code',
                tag: 'pre'
            },
            'H1': {
                faIcon: 'fa fa-header',
                tag: 'h1',
                children: [{
                    name: "formatBlock",
                    param: 'H1',
                    text: 'H1',
                    tag: 'h1'
                }, {
                    name: "formatBlock",
                    param: 'H2',
                    text: 'H2',
                    tag: 'h2'
                }, {
                    name: "formatBlock",
                    param: 'H3',
                    text: 'H3',
                    tag: 'h3'
                }, {
                    name: "formatBlock",
                    param: 'H4',
                    text: 'H4',
                    tag: 'h4'
                }, {
                    name: "formatBlock",
                    param: 'H5',
                    text: 'H5',
                    tag: 'h5'
                }, {
                    name: "formatBlock",
                    param: 'H6',
                    text: 'H6',
                    tag: 'h6'
                }]
            },
            'justfy': {
                faIcon: 'fa fa-align-center',
                children: [{
                    name: 'justifyCenter',
                    faIcon: 'fa fa-align-center'
                }, {
                    name: 'justifyLeft',
                    faIcon: 'fa fa-align-left'
                }, {
                    name: 'justifyFull',
                    faIcon: 'fa fa-align-justify'
                }, {
                    name: 'justifyRight',
                    faIcon: 'fa fa-align-right'
                }]
            },
            'fullscreen': {
                name: "fullscreen",
                faIcon: 'fa fa-expand',
                tag: 'h1'
            },
            'image': {
                name: 'imgFile',
                faIcon: 'fa fa-image'
            }
        };

        var supportCommands = ['justfy', 'bold', 'italic', 'underline', 'H1', 'hr', 'code', 'insertOrderedList', 'eraser', 'image', 'fullscreen'];

        function getCommands(supportCommands) {
            var cmds = [];
            angular.forEach(supportCommands, function(cmd) {
                if (commands[cmd]) {
                    cmds.push(commands[cmd]);
                }
            });
            return cmds;
        }

        var config = {
            supportCommands: getCommands(supportCommands)
        };

        return {
            '$get': function() {
                return {
                    /*{
                     supportCommands:['bold','italic','underline']...
                     qnConfig:{
                     endPoint:'http://upload.qiniu.com',
                     tokenUrl:'<your server assign token url>'
                     }
                     }
                     */
                    config: function(conf) {
                        if (conf) {
                            if (conf.supportCommands) {
                                config.supportCommands = getCommands(conf.supportCommands);
                            }
                            if (conf.qnConfig) {
                                config.qnConfig = conf.qnConfig;
                            }
                        }
                        return config;
                    }
                };
            }
        };
    })
    .directive("ngMeditor", function($compile, $window, $timeout, $upload, meditorProvider) {
        return {
            restrict: "AE",
            scope: {
                ngModel: "="
            },
            require: "^ngModel",
            link: function(scope, el, attr) {
                var config = meditorProvider.config();

                scope.editId = new Date().getTime() + '';
                scope.showMenu = false;
                scope.menuX = 0;
                scope.menuY = 0;
                scope.commands = config.supportCommands;
                scope.editable = true;
                scope.placeholder = attr['placeholder'];
                console.log(scope.placeholder);
                var selection, range;
                var menuWidth = (scope.commands.length) * 32;

                var html = $compile('<div ' +
                    'ng-file-drop ng-model="imageFile" ng-file-change="pasteImage(imageFile[0])" ng-multiple="false" accept="image/*" ' +
                    'ng-keydown="doKeydown($event)" ' +
                    'ng-keyup="doKeyup($event)" ' +
                    'ng-mousedown="doMousedown($event)" ' +
                    'ng-mouseup="doMouseup($event)" ' +
                    'id="{{editId}}" class="editor" ng-class="{\'fullscreen\':fullscreen}" contenteditable="{{editable}}" placeholder="{{placeholder}}" ></div>'
                )(scope);

                var menuHtml = $compile(
                    '<div ng-style=\"{\'top\':menuY,\'left\':menuX}\" ng-show=\"showMenu\" class=\"editor-menu\">' +
                    '<ul ng-class="{\'at-top\':menuAtTop,\'at-bottom\':!menuAtTop}">' +
                    '    <li ng-mouseenter="cmd.showChildren=true;"  ng-class="{\'actived\':cmd.actived}" ng-repeat="cmd in commands" ng-click="doCommand($event,cmd)">' +
                    '      <i class="{{cmd.faIcon}}"></i>' +
                    '      <input class="image-selector" ng-if=\'cmd.name==="imgFile"\' type="file"  accept="image/*" ng-file-select="" ng-model="imageFile" name="file"  ng-file-change="pasteImage(imageFile[0])">' +
                    '      <ul ng-show="cmd.showChildren" ng-mouseleave="cmd.showChildren=false;" class="sub-menu" ng-if="cmd.children">' +
                    '          <li ng-class="{\'actived\':c.actived}" ng-repeat="c in cmd.children" ng-click="doCommand($event,c)"><i class="{{c.faIcon}}"></i> <span ng-if="!c.faIcon">{{c.text}}</span></li>' +
                    '      </ul>' +
                    '    </li>' +
                    '</ul>' +
                    '<\/div>')(scope);<commit_msg>fix(Editor) avoid error when placeholder is not defined, eliminate debug console message<commit_after>angular.module('ngMeditor', []);
angular.module('ngMeditor')
    .provider('meditorProvider', function() {
        var commands = {
            'bold': {
                name: 'bold',
                faIcon: 'fa fa-bold',
                tag: 'b'
            },
            'italic': {
                name: 'italic',
                faIcon: 'fa fa-italic',
                tag: 'i'
            },
            'underline': {
                name: 'underline',
                faIcon: 'fa fa-underline',
                tag: 'u'
            },
            'hr': {
                name: 'insertHorizontalRule',
                faIcon: 'fa fa-minus',
                tag: 'hr'
            },
            'eraser': {
                name: 'removeFormat',
                faIcon: 'fa fa-eraser'
            },
            'insertOrderedList': {
                faIcon: 'fa fa-list-ul',
                children: [{
                    name: 'insertUnorderedList',
                    faIcon: 'fa fa-list-ul',
                    tag: 'ul'
                }, {
                    name: "insertOrderedList",
                    faIcon: 'fa fa-list-ol',
                    tag: 'ol'
                }]
            },
            'code': {
                name: 'formatBlock',
                param: 'pre',
                faIcon: 'fa fa-code',
                tag: 'pre'
            },
            'H1': {
                faIcon: 'fa fa-header',
                tag: 'h1',
                children: [{
                    name: "formatBlock",
                    param: 'H1',
                    text: 'H1',
                    tag: 'h1'
                }, {
                    name: "formatBlock",
                    param: 'H2',
                    text: 'H2',
                    tag: 'h2'
                }, {
                    name: "formatBlock",
                    param: 'H3',
                    text: 'H3',
                    tag: 'h3'
                }, {
                    name: "formatBlock",
                    param: 'H4',
                    text: 'H4',
                    tag: 'h4'
                }, {
                    name: "formatBlock",
                    param: 'H5',
                    text: 'H5',
                    tag: 'h5'
                }, {
                    name: "formatBlock",
                    param: 'H6',
                    text: 'H6',
                    tag: 'h6'
                }]
            },
            'justfy': {
                faIcon: 'fa fa-align-center',
                children: [{
                    name: 'justifyCenter',
                    faIcon: 'fa fa-align-center'
                }, {
                    name: 'justifyLeft',
                    faIcon: 'fa fa-align-left'
                }, {
                    name: 'justifyFull',
                    faIcon: 'fa fa-align-justify'
                }, {
                    name: 'justifyRight',
                    faIcon: 'fa fa-align-right'
                }]
            },
            'fullscreen': {
                name: "fullscreen",
                faIcon: 'fa fa-expand',
                tag: 'h1'
            },
            'image': {
                name: 'imgFile',
                faIcon: 'fa fa-image'
            }
        };

        var supportCommands = ['justfy', 'bold', 'italic', 'underline', 'H1', 'hr', 'code', 'insertOrderedList', 'eraser', 'image', 'fullscreen'];

        function getCommands(supportCommands) {
            var cmds = [];
            angular.forEach(supportCommands, function(cmd) {
                if (commands[cmd]) {
                    cmds.push(commands[cmd]);
                }
            });
            return cmds;
        }

        var config = {
            supportCommands: getCommands(supportCommands)
        };

        return {
            '$get': function() {
                return {
                    /*{
                     supportCommands:['bold','italic','underline']...
                     qnConfig:{
                     endPoint:'http://upload.qiniu.com',
                     tokenUrl:'<your server assign token url>'
                     }
                     }
                     */
                    config: function(conf) {
                        if (conf) {
                            if (conf.supportCommands) {
                                config.supportCommands = getCommands(conf.supportCommands);
                            }
                            if (conf.qnConfig) {
                                config.qnConfig = conf.qnConfig;
                            }
                        }
                        return config;
                    }
                };
            }
        };
    })
    .directive("ngMeditor", function($compile, $window, $timeout, $upload, meditorProvider) {
        return {
            restrict: "AE",
            scope: {
                ngModel: "="
            },
            require: "^ngModel",
            link: function(scope, el, attr) {
                var config = meditorProvider.config();

                scope.editId = new Date().getTime() + '';
                scope.showMenu = false;
                scope.menuX = 0;
                scope.menuY = 0;
                scope.commands = config.supportCommands;
                scope.editable = true;
                scope.placeholder = (attr['placeholder']!=undefined ? attr['placeholder'] : '');
                var selection, range;
                var menuWidth = (scope.commands.length) * 32;

                var html = $compile('<div ' +
                    'ng-file-drop ng-model="imageFile" ng-file-change="pasteImage(imageFile[0])" ng-multiple="false" accept="image/*" ' +
                    'ng-keydown="doKeydown($event)" ' +
                    'ng-keyup="doKeyup($event)" ' +
                    'ng-mousedown="doMousedown($event)" ' +
                    'ng-mouseup="doMouseup($event)" ' +
                    'id="{{editId}}" class="editor" ng-class="{\'fullscreen\':fullscreen}" contenteditable="{{editable}}" placeholder="{{placeholder}}" ></div>'
                )(scope);

                var menuHtml = $compile(
                    '<div ng-style=\"{\'top\':menuY,\'left\':menuX}\" ng-show=\"showMenu\" class=\"editor-menu\">' +
                    '<ul ng-class="{\'at-top\':menuAtTop,\'at-bottom\':!menuAtTop}">' +
                    '    <li ng-mouseenter="cmd.showChildren=true;"  ng-class="{\'actived\':cmd.actived}" ng-repeat="cmd in commands" ng-click="doCommand($event,cmd)">' +
                    '      <i class="{{cmd.faIcon}}"></i>' +
                    '      <input class="image-selector" ng-if=\'cmd.name==="imgFile"\' type="file"  accept="image/*" ng-file-select="" ng-model="imageFile" name="file"  ng-file-change="pasteImage(imageFile[0])">' +
                    '      <ul ng-show="cmd.showChildren" ng-mouseleave="cmd.showChildren=false;" class="sub-menu" ng-if="cmd.children">' +
                    '          <li ng-class="{\'actived\':c.actived}" ng-repeat="c in cmd.children" ng-click="doCommand($event,c)"><i class="{{c.faIcon}}"></i> <span ng-if="!c.faIcon">{{c.text}}</span></li>' +
                    '      </ul>' +
                    '    </li>' +
                    '</ul>' +
                    '<\/div>')(scope);
{'fraction_non_alphanumeric': 0.1431185200243952, 'fraction_numerical': 0.003794809243071085, 'mean_word_length': 0.9962126335722982, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4350543', 'n_tokens_mistral': 4020, 'n_tokens_neox': 3740, 'n_words': 666}