allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [06/16] allura git commit: [#8230] Add checklist.js
Date Mon, 15 Oct 2018 16:02:30 GMT
[#8230] Add checklist.js


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/1c2b26d4
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/1c2b26d4
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/1c2b26d4

Branch: refs/heads/master
Commit: 1c2b26d4b2b4db4dc4877b4bb189bf8b06b9f866
Parents: 181b82e
Author: Shalitha <shalithasuranga@gmail.com>
Authored: Tue Oct 9 21:50:33 2018 +0530
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon Oct 15 15:50:29 2018 +0000

----------------------------------------------------------------------
 Allura/allura/public/nf/js/checklist.js         | 56 ++++++++++++++++++++
 .../allura/templates/jinja_master/master.html   |  1 +
 2 files changed, 57 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/1c2b26d4/Allura/allura/public/nf/js/checklist.js
----------------------------------------------------------------------
diff --git a/Allura/allura/public/nf/js/checklist.js b/Allura/allura/public/nf/js/checklist.js
new file mode 100644
index 0000000..c1edac2
--- /dev/null
+++ b/Allura/allura/public/nf/js/checklist.js
@@ -0,0 +1,56 @@
+/*jslint white: true, vars: true */
+/*global Checklists, jQuery */
+
+var Checklists = (function($) {
+
+    "use strict";
+    
+    // makes Markdown checklists interactive
+    // `container` is either a DOM element, jQuery collection or selector containing
+    // the Markdown content
+    // `retriever` is a function being passed the respective checkbox and a
+    // callback - the latter is epxected to be called with the container's raw
+    // Markdown source
+    // `storer` is a function being passed the updated Markdown content, the
+    // respective checkbox and a callback
+    // both functions' are invoked with the respective `Checklists` instance as
+    // execution context (i.e. `this`)
+    function Checklists(container, retriever, storer) {
+        this.container = container.jquery ? container : $(container);
+        this.retriever = retriever;
+        this.storer = storer;
+    
+        var checklists = $(".checklist", container);
+        checklists.find(this.checkboxSelector).prop("disabled", false);
+        var self = this;
+        checklists.on("change", this.checkboxSelector, function() {
+            var args = Array.prototype.slice.call(arguments);
+            args.push(self);
+            self.onChange.apply(this, args);
+        });
+    }
+    Checklists.prototype.checkboxSelector = "> li > input:checkbox";
+    Checklists.prototype.onChange = function(ev, self) {
+        var checkbox = $(this).prop("disabled", true);
+        var index = $("ul" + self.checkboxSelector, self.container).index(this);
+        var reactivate = function() { checkbox.prop("disabled", false); };
+        self.retriever(checkbox, function(markdown) {
+            markdown = self.toggleCheckbox(index, markdown);
+            self.storer(markdown, checkbox, reactivate);
+        });
+    };
+    Checklists.prototype.toggleCheckbox = function(index, markdown) {
+        var pattern = /^([*-]) \[([ Xx])\]/mg; // XXX: duplicates server-side logic!?
+        var count = 0;
+        return markdown.replace(pattern, function(match, prefix, marker) {
+            if(count === index) {
+                marker = marker === " " ? "x" : " ";
+            }
+            count++;
+            return prefix + " [" + marker + "]";
+        });
+    };
+    
+    return Checklists;
+    
+    }(jQuery));
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/allura/blob/1c2b26d4/Allura/allura/templates/jinja_master/master.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/master.html b/Allura/allura/templates/jinja_master/master.html
index 649699c..e16a5bc 100644
--- a/Allura/allura/templates/jinja_master/master.html
+++ b/Allura/allura/templates/jinja_master/master.html
@@ -29,6 +29,7 @@
 {% do g.register_forge_js('js/twemoji.min.js') %}
 {% do g.register_forge_js('js/pb.transformie.min.js') %}
 {% do g.register_forge_js('js/allura-base.js') %}
+{% do g.register_forge_js('js/checklist.js') %}
 {% do g.register_forge_css('css/forge/hilite.css') %}
 {% do g.register_forge_css('css/forge/tooltipster.css') %}
 {% do g.register_forge_css('css/font-awesome.min.css', compress=False) %}


Mime
View raw message