aboutsummaryrefslogtreecommitdiff
path: root/coqCounter.js
diff options
context:
space:
mode:
authorCamil Staps2015-05-08 13:02:09 +0300
committerCamil Staps2015-05-08 13:02:09 +0300
commitf714efc1b0b88ec5041c1acb5405e0dc34553815 (patch)
treebea85a9c544e0ebc064199e83b3a3398d59e624a /coqCounter.js
parentThis seems to work (diff)
Bugfix; licensing; copyright & contact details; readme
Diffstat (limited to 'coqCounter.js')
-rw-r--r--coqCounter.js74
1 files changed, 51 insertions, 23 deletions
diff --git a/coqCounter.js b/coqCounter.js
index 72f7ad7..1f81915 100644
--- a/coqCounter.js
+++ b/coqCounter.js
@@ -1,30 +1,58 @@
-$.fn.coqCounter = function(output) {
- $(this).change(function(){
- var regex = /[\n^]([a-zA-Z_'0-9]+)/g;
- var value = $(this).val();
- var matches = [], i = 0;
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Camil Staps <info@camilstaps.nl>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
- do {
- match = regex.exec(value);
- if (match != null) {
- matches[i++] = match[1];
- }
- } while (match != null);
+(function($){
+ $.fn.coqCounter = function(output) {
+ $(this).change(function(){
+ var regex = /(?:^|\n)([a-zA-Z_'0-9]+)/g;
+ var value = $(this).val();
+ var matches = [], i = 0;
- matches.sort();
+ do {
+ match = regex.exec(value);
+ if (match != null) {
+ matches[i++] = match[1];
+ }
+ } while (match != null);
- var counts = {};
- matches.forEach(function(x) { counts[x] = (counts[x] || 0)+1; });
+ if (matches.length == 0) {
+ $(output).val("No Coq commands found.");
+ } else {
+ matches.sort();
- var counts_output = [], i = 0;
- for (cmd in counts) {
- counts_output[i++] = counts[cmd] + "x " + cmd;
- }
+ var counts = {};
+ matches.forEach(function(x) { counts[x] = (counts[x] || 0)+1; });
- console.log(counts_output);
+ var counts_output = [], i = 0;
+ for (cmd in counts) {
+ counts_output[i++] = counts[cmd] + "x " + cmd;
+ }
- $(output).val(counts_output.join(", "));
- });
+ $(output).val(counts_output.join(", "));
+ }
+ });
- return this;
-}; \ No newline at end of file
+ return this;
+ };
+})(jQuery); \ No newline at end of file