diff options
author | Camil Staps | 2015-05-08 13:02:09 +0300 |
---|---|---|
committer | Camil Staps | 2015-05-08 13:02:09 +0300 |
commit | f714efc1b0b88ec5041c1acb5405e0dc34553815 (patch) | |
tree | bea85a9c544e0ebc064199e83b3a3398d59e624a | |
parent | This seems to work (diff) |
Bugfix; licensing; copyright & contact details; readme
-rw-r--r-- | LICENSE | 2 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | coqCounter.js | 74 | ||||
-rw-r--r-- | index.html | 11 |
4 files changed, 64 insertions, 26 deletions
@@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Camil Staps +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 @@ -1,2 +1,5 @@ # CoqCommandsCounter Count used coq commands + +# Usage +Simply open `index.html` in your browser. A working internet connection is required, since jQuery is loaded from CDN. 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 @@ -4,14 +4,21 @@ <title>Coq commands counter</title> </head> <body> - <textarea id="input" cols="60" rows="20"></textarea><br/> + <h1>Count commands used in a Coq script</h1> + <p>Copyright © 2015 <a href="http://www.camilstaps.nl/">Camil Staps</a> - licensed under <a href="LICENSE">MIT</a>.</p> + + <textarea id="input" cols="60" rows="20">Enter Coq script here</textarea><br/> <textarea id="output" cols="60" rows="2"></textarea> <script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="coqCounter.js"></script> <script type="text/javascript"> $(function(){ - $('#input').coqCounter('#output'); + $('#input') + .coqCounter('#output') + .focus(function(){ + $(this).val(''); + }); }); </script> </body> |