/*
Word Count Plugin
*/
(function () {
var html = '
' +
'
' +
'
' +
_cb.out('Word Count') +
'
✕
' +
'
' +
'
' +
'
words
' +
'
' +
'Characters:
' +
'Characters (no spaces): ' +
'
' +
'
' +
'
' +
'
' +
'
' +
'';
_cb.addHtml(html);
var css = '' +
'' +
'';
_cb.addCss(css);
var button = '';
_cb.addButton('wordcount', button, '.wordcount-button', function () {
var modal = document.querySelector(".is-modal.wordcount");
_cb.showModal(modal, true);
modal.querySelector('#tmp_wordcount').innerHTML = _cb.html();
var txt = modal.querySelector('#tmp_wordcount').textContent;
modal.querySelector('#tmp_wordcount').innerHTML = '';
// https://stackoverflow.com/questions/9864644/jquery-character-and-word-count
var chars = txt.length;
var charsnospaces = txt.replace(/\s/g, "").length;
var words = txt.replace(/[^\w ]/g, "").split(/\s+/).length;
modal.querySelector('#spanWords').innerText = words;
modal.querySelector('#spanChars').innerText = chars;
modal.querySelector('#spanCharsNoSpaces').innerText = charsnospaces;
var btnClose = modal.querySelector('.is-modal-close');
btnClose.addEventListener('click', function(e){
_cb.hideModal(modal);
});
});
})();