aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-08-10 21:04:41 -0400
committerPaul Duncan <pabs@pablotron.org>2016-08-10 21:04:41 -0400
commit25199ab4c29057d7c0a73812fc8f2ac3605c1d86 (patch)
tree78f93a21b23da48b8cd0113e8262876426cfa7e6 /js
parent533ee3ceb098919da478a6be57a2f4342712aca5 (diff)
downloadzip-crystal-25199ab4c29057d7c0a73812fc8f2ac3605c1d86.tar.bz2
zip-crystal-25199ab4c29057d7c0a73812fc8f2ac3605c1d86.zip
add documentation
Diffstat (limited to 'js')
-rw-r--r--js/doc.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/js/doc.js b/js/doc.js
new file mode 100644
index 0000000..8846c54
--- /dev/null
+++ b/js/doc.js
@@ -0,0 +1,89 @@
+document.addEventListener('DOMContentLoaded', function() {
+ var sessionStorage = window.sessionStorage;
+ if(!sessionStorage) {
+ sessionStorage = {
+ setItem: function() {},
+ getItem: function() {},
+ removeItem: function() {}
+ };
+ }
+
+ var repositoryName = document.getElementById('repository-name').getAttribute('content');
+ var typesList = document.getElementById('types-list');
+ var searchInput = document.getElementById('search-input');
+ var parents = document.querySelectorAll('#types-list li.parent');
+
+ for(var i = 0; i < parents.length; i++) {
+ var _parent = parents[i];
+ _parent.addEventListener('click', function(e) {
+ e.stopPropagation();
+
+ if(e.target.tagName.toLowerCase() == 'li') {
+ if(e.target.className.match(/open/)) {
+ sessionStorage.removeItem(e.target.getAttribute('data-id'));
+ e.target.className = e.target.className.replace(/ +open/g, '');
+ } else {
+ sessionStorage.setItem(e.target.getAttribute('data-id'), '1');
+ if(e.target.className.indexOf('open') == -1) {
+ e.target.className += ' open';
+ }
+ }
+ }
+ });
+
+ if(sessionStorage.getItem(_parent.getAttribute('data-id')) == '1') {
+ _parent.className += ' open';
+ }
+ };
+
+ var childMatch = function(type, regexp){
+ var types = type.querySelectorAll("ul li");
+ for (var j = 0; j < types.length; j ++) {
+ var t = types[j];
+ if(regexp.exec(t.getAttribute('data-name'))){ return true; };
+ };
+ return false;
+ };
+
+ var searchTimeout;
+ searchInput.addEventListener('keyup', function() {
+ clearTimeout(searchTimeout);
+ searchTimeout = setTimeout(function() {
+ var text = searchInput.value;
+ var types = document.querySelectorAll('#types-list li');
+ var words = text.toLowerCase().split(/\s+/).filter(function(word) {
+ return word.length > 0;
+ });
+ var regexp = new RegExp(words.join('|'));
+
+ for(var i = 0; i < types.length; i++) {
+ var type = types[i];
+ if(words.length == 0 || regexp.exec(type.getAttribute('data-name')) || childMatch(type, regexp)) {
+ type.className = type.className.replace(/ +hide/g, '');
+ var is_parent = new RegExp("parent").exec(type.className);
+ var is_not_opened = !(new RegExp("open").exec(type.className));
+ if(childMatch(type,regexp) && is_parent && is_not_opened){
+ type.className += " open";
+ };
+ } else {
+ if(type.className.indexOf('hide') == -1) {
+ type.className += ' hide';
+ };
+ };
+ if(words.length == 0){
+ type.className = type.className.replace(/ +open/g, '');
+ };
+ }
+ }, 200);
+ });
+
+ typesList.onscroll = function() {
+ var y = typesList.scrollTop;
+ sessionStorage.setItem(repositoryName + '::types-list:scrollTop', y);
+ };
+
+ var initialY = parseInt(sessionStorage.getItem(repositoryName + '::types-list:scrollTop') + "", 10);
+ if(initialY > 0) {
+ typesList.scrollTop = initialY;
+ }
+});