question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Done Counter for Individual Terms

See original GitHub issue

For me it felt like a callback function is missing. The filter feature was quite nice and I was able to use that. Still, it does not feels like the correct way to work with this.

Steps to reproduce

https://github.com/jenstornell/kirby-keyword-map/blob/master/fields/keywordmap/assets/js/src/script.js#L42

'filter': function(textNode, keyword, totalCounter, counter){
	var keyword = keyword.toLowerCase();
	var count = parseInt(counter+1);
	var tag = field.find('.keywordmap-tags [data-tag="' + keyword + '"]');
	tag.addClass('active');
	tag.find('button').html(keyword + '<span class="kwt-count">' + count + '</span>');
	return true;
}

Is there a better way or is this just fine?

If you want to know what it does, this is it:

image

Environment

  • mark.js version 8.8.3

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Mottiecommented, Mar 10, 2017

Hi @jenstornell!

You can use the done callback… I set up this very basic demo that uses it.

$(function() {
  var keywords = ["lorem ipsum", "elitr", "test"],
    context = $(".context").unmark(),
    field = $('.keywordmap-tags').empty();
  keywords.forEach(function(keyword) {
    $(`<span data-tag="${keyword}"></span>`)
      .html("<button type='button'></button>")
      .appendTo(field);
    context.mark(keyword, {
      'separateWordSearch': false,
      'diacritics': false,
      'accuracy': {
        'value': 'exactly',
        'limiters': ['-', '#', ',', '.']
      },
      'done': function(totalMatches) {
        var tag = field.find('[data-tag="' + keyword.toLowerCase() + '"]'),
          html = keyword;
        tag.addClass('active');
        if (totalMatches) {
          html += '<span class="kwt-count">' + totalMatches + '</span>';
        }
        tag.find('button').html(html);
      }
    });
  });
});
0reactions
stale[bot]commented, Aug 20, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Word Frequency Counter - Count Word Occurrences - Online
Useful, free online tool that counts how many times each word appears in a string or text. No ads, nonsense, or garbage, just...
Read more >
Words and Characters Counter
Load or copy and paste any text to calculate its words and characters or phrases and punctuation. Count words in any PDF or...
Read more >
How do we Count the Number of Terms in an Algebraic ...
To learn more about Algebraic Expression, enroll in our full course now: ...
Read more >
Word Count Tool: Word Counter
Word Count Tool offers: ✓ 100% FREE word counter ✓ No Usage Limits ✓ More FREE tools to help you write better.
Read more >
Counteroffer: Definition, Examples, and Strategies
A counteroffer is a response given to an initial offer. A counteroffer means the original offer was rejected and replaced with another one....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found