Plugin Directory

Changeset 1494045


Ignore:
Timestamp:
09/11/2016 12:27:13 PM (9 years ago)
Author:
lopinopulos
Message:

Don't proofread html attributes

Location:
russian-texts-proofreader-glvrd/tags/1.2.2
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • russian-texts-proofreader-glvrd/tags/1.2.2/css/glvrd.css

    r1336247 r1494045  
    3737    font-size: .8em;
    3838    line-height: 1.4em;
     39    height: 2.3em;
    3940    overflow: hidden;
    4041}
     
    7475}
    7576
     77#glvrd_section .stats-score.green {
     78    color: #077213;
     79}
     80
     81#glvrd_section .stats-score.orange {
     82    color: #da570f;
     83}
     84
     85#glvrd_section .stats-score.red {
     86    color: #bb0002;
     87}
     88
    7689#glvrd_section .stats .stats-sections {
    7790    margin-right: -1em;
  • russian-texts-proofreader-glvrd/tags/1.2.2/js/glvrd-plugin.js

    r1336247 r1494045  
    11(function () {
     2
    23    tinymce.create('tinymce.plugins.glvrd', {
    34
     
    67        hoverHintCls  : 'glvrd-underline-hover',
    78
     9        myUrl            : undefined,
    810        isFirstLaunch    : true,
    911        delayedProofread : undefined,
     
    1921        init : function (ed, url) {
    2022            var me = this;
     23           
     24            me.url = url;
    2125
    2226            ed.addButton('glvrd', {
     
    4650                    jQuery(ed.getDoc()).find('.' + me.activeHintCls).toggleClass(me.activeHintCls).toggleClass(me.hintCls);
    4751                    me.showTooltip(ed, html, target);
    48 
    4952                });
    5053            });
     
    6366            ed.on('SaveContent', function (e) {
    6467                e.content = me.removeMarkup(e.content);
     68            });
     69
     70            ed.on('change', function (e) {
     71                me.hideTooltip();
    6572            });
    6673
     
    9299            var me = this,
    93100                content = me.removeMarkup(editor.getContent({format : 'raw'})),
    94                 strippedContent = editor.getContent({format : 'text'})
     101                strippedContent = editor.getContent({format : 'text'}),
     102                textInAttributes = me.getHtmlAttributes(content);
     103
     104            jQuery('#glvrd_section .stats .stats-score').removeClass('green orange red')
     105                                                        .html('<img src="' + me.url + '/../images/loader.gif" width="30"/>');
    95106
    96107            window.glvrd.proofread(content, function (result) {
    97                
    98108                if (result.status = 'ok') {
    99109                    if (strippedContent !== this.getContent({format: 'text'})) {
     
    104114
    105115                    jQuery('#glvrd_section .info').hide('fast').remove();
    106                     $statsBlock.find('.stats-score').text(result.score);
     116                    $statsBlock.find('.stats-score').addClass(me.getScoreColor(result.score)).text(result.score);
    107117                    $statsBlock.find('.stats-stopwords').text(sprintf(me.pluralize(result.fragments.length, '%d стоп-слов', '%d стоп-слово', '%d стоп-слова'), result.fragments.length));
    108118
     
    112122                    var wordQuantity = me.countWords(strippedContent);
    113123                    $statsBlock.find('.stats-words').text(sprintf(me.pluralize(wordQuantity, '%d слов', '%d слово', '%d слово'), wordQuantity));
    114                     var charQuantity = me.countChars(strippedContent, true);
    115                     var charQuantityWithoutSpaces  = me.countChars(strippedContent, false);
    116                     $statsBlock.find('.stats-chars').text(
    117                         sprintf(me.pluralize(charQuantity, '%d знаков', '%d знак', '%d знака'), charQuantity) +
    118                         ' (' + charQuantityWithoutSpaces + ' без пробелов) '
    119                     );
     124                    var charQuantity = me.countChars(strippedContent);
     125                    $statsBlock.find('.stats-chars').text(sprintf(me.pluralize(charQuantity, '%d знаков', '%d знак', '%d знака'), charQuantity));
    120126
    121127                    if (result.fragments.length) {
     
    127133                        var tagOpen = '<span class="glvrd-underline" data-glvrd="true" data-description="' + fragment.hint.description + '" data-name="' + fragment.hint.name + '" >',
    128134                            tagClose = '</span>',
    129                             tagsLength = tagOpen.length + tagClose.length;
     135                            tagsLength = tagOpen.length + tagClose.length,
     136                            skip = textInAttributes.some(function(attributeContent) {
     137                                return attributeContent.start <=fragment.start && fragment.end <= attributeContent.end;
     138                            });
     139
     140                        if (skip) {
     141                            return;
     142                        }
    130143
    131144                        content = content.substring(0, fragment.start + offset)
     
    177190        },
    178191
     192        hideTooltip: function() {
     193            var me = this;
     194
     195            if (me.tooltip) {
     196                me.tooltip.hide();
     197            }
     198        },
     199
    179200        countSentences : function (text) {
    180201            if (text.length === 0) {
     
    183204
    184205            var sentencesQuantity = text.match(/[^\s](\.|…|\!|\?)(?!\w)(?!\.\.)/g).length;
    185             if (!/(\.|…|\!|\?)/g.test(text.slice(-1))) {
     206            if (!(/(\.|…|\!|\?)/g).test(text.slice(-1))) {
    186207                sentencesQuantity++;
    187208            }
     
    197218        },
    198219
    199         countChars : function (text, countSpaces) {
     220        countChars : function (text) {
    200221            if (text.length === 0) {
    201222                return 0;
    202223            }
    203224
    204             var regexp = countSpaces ? /[^А-Яа-яA-Za-z0-9-\s.,:()-]+/g : /[^А-Яа-яA-Za-z0-9-.,:()-]+/g;
    205             return text.replace(regexp, "").length;
     225            return text.replace(/[^А-Яа-яA-Za-z0-9-\s.,()-]+/g, "").length;
    206226        },
    207227
     
    227247                    return zeroWord;
    228248            }
     249        },
     250
     251        getHtmlAttributes: function(content) {
     252            var regexp = /\w+=\s*["|']([\sА-Яа-яё,.!?]+)["|']/g,
     253                chunks = [],
     254                attribute, attributeContent, globalStartPos, globalEndPos;
     255
     256            while ((result = regexp.exec(content))!== null) {
     257                attribute = result[0];
     258                attributeContent = result[1];
     259                globalStartPos = result.index;
     260
     261                if (attributeContent.length > 0) {
     262                    globalStartPos += attribute.indexOf(attributeContent);
     263                    globalEndPos = globalStartPos + attributeContent.length;
     264                    chunks.push({
     265                        text: attributeContent,
     266                        start: globalStartPos,
     267                        end: globalEndPos
     268                    });
     269                }
     270            }
     271
     272            return chunks;
     273        },
     274
     275        getScoreColor: function(score) {
     276            if (score < 5) {
     277                return 'red';
     278            }
     279
     280            if (score < 7.5) {
     281                return 'orange';
     282            }
     283
     284            return 'green';
    229285        },
    230286
  • russian-texts-proofreader-glvrd/tags/1.2.2/readme.txt

    r1336247 r1494045  
    44Donate link: https://paypal.me/NLopin
    55Requires at least: 4.2
    6 Tested up to: 4.4
     6Tested up to: 4.5
    77Stable tag: 1.2.2
    88License: GPLv2 or later
     
    5858== Changelog ==
    5959= 1.2.2 =
    60 * Добавлен счетчик знаков без пробелов
     60* Главред больше не ломает HTML разметку в тех случаях, когда внутри тегов есть текст на русском языке
     61* Цветные метки у оценок
    6162
    6263= 1.2.1 =
Note: See TracChangeset for help on using the changeset viewer.