From 625108349a6e7919e331866eb46b1aef3477e9c3 Mon Sep 17 00:00:00 2001 From: Alex Pankratov Date: Wed, 31 Mar 2021 20:35:46 +0200 Subject: [PATCH] reshuffle the code a bit --- nullboard.html | 566 +++++++++++++++++++++++-------------------------- 1 file changed, 270 insertions(+), 296 deletions(-) diff --git a/nullboard.html b/nullboard.html index 598e7b4..1710589 100644 --- a/nullboard.html +++ b/nullboard.html @@ -1388,7 +1388,7 @@ return Object.assign(new Board(), board); } - nukeBoard(board_id, revision) + nukeBoard(board_id) { var meta = this.boardIndex.get(board_id); @@ -1397,29 +1397,13 @@ var title = meta.title + ''; - if (revision != null) - { - var i = meta.history.indexOf(revision); - if (i == -1) - return false; + for (var rev of meta.history) + this.delItem('board.' + board_id + '.' + rev); + this.delItem('board.' + board_id + '.meta'); + this.boardIndex.delete(board_id); - meta.history.splice(i, 1); - this.setJson('board.' + board_id + '.meta', meta); - this.delItem('board.' + board_id + '.' + revision); - - console.log( `Deleted revision ${revision} of ${board_id} (${title}) #` ); - } - else - { - for (var rev of meta.history) - this.delItem('board.' + board_id + '.' + rev); - - this.delItem('board.' + board_id + '.meta'); - this.boardIndex.delete(board_id); - - console.log( `Deleted board ${board_id} (${title})` ); - } + console.log( `Deleted board ${board_id} (${title})` ); } getBoardHistory(board_id) @@ -1998,234 +1982,7 @@ }); /* - * html ops - */ - function htmlEncode(raw) - { - return $('tt .encoder').text(raw).html(); - } - -// function htmlDecode(enc) -// { -// return $('tt .encoder').html(enc).text(); -// } - - function setText($note, text) - { - $note.attr('_text', text); - - text = htmlEncode(text); - hmmm = /\b(https?:\/\/[^\s]+)/mg; - - text = text.replace(hmmm, function(url){ - return '' + url + ''; - }); - - $note.html(text); - } - - function getText($note) - { - return $note.attr('_text'); - } - - /* - * board ops - save/load/parse/peek/nuke/import - */ - function saveBoard() - { - var $board = $('.wrap .board'); - var board = Object.assign({}, NB.board); // id, revision & title - - board.lists = []; - - $board.find('.list').each(function(){ - var $list = $(this); - var l = board.addList( getText($list.find('.head .text')) ); - - $list.find('.note').each(function(){ - var $note = $(this) - var n = l.addNote( getText($note.find('.text')) ); - n.raw = $note.hasClass('raw'); - n.min = $note.hasClass('collapsed'); - }); - }); - - NB.storage.saveBoard(board); - NB.board = board; - - updateUndoRedo(); - updateBoardIndex(); - } - - function nukeBoard() - { - NB.storage.nukeBoard(NB.board.id, null); - } - - /* - * export / import - */ - function exportBoard() - { - var blob, file; - - if (! NB.board) - { - var index = NB.storage.getBoardIndex(); - var all = []; - - boards.forEach(function(meta, board_id){ - all.push( NB.storage.loadBoard(board_id, null) ); - }) - - blob = JSON.stringify(all); - file = `Nullboard.nbx`; - } - else - { - var board = NB.board; - blob = JSON.stringify(board); - file = `Nullboard-${board.id}-${board.title}.nbx`; - } - - blob = encodeURIComponent(blob); - blob = "data:application/octet-stream," + blob; - - return { blob: blob, file: file }; - } - - function checkBoard(foo) - { - var props = [ 'format', 'id', 'revision', 'title', 'lists' ]; - - for (var i=0; i' + url + ''; + }); + + $note.html(text); + } + + function getText($note) + { + return $note.attr('_text'); + } + + /* + * inline editing */ function startEditing($text, ev) { @@ -2656,6 +2638,29 @@ addNote($item); } + function handleTab(ev) + { + var $this = $(this); + var $note = $this.closest('.note'); + var $sibl = ev.shiftKey ? $note.prev() : $note.next(); + + if ($sibl.length) + { + stopEditing($this, false, false); + $sibl.find('.text').click(); + } + } + + // + function setRevealState(ev) + { + var raw = ev.originalEvent; + var caps = raw.getModifierState && raw.getModifierState( 'CapsLock' ); + + if (caps) $('body').addClass('reveal'); + else $('body').removeClass('reveal'); + } + // function showDing() { @@ -2665,7 +2670,9 @@ .queue(function(){ $(this).removeClass('ding').dequeue(); }); } - // + /* + * overlay + */ function showOverlay($div) { $('.overlay') @@ -2687,7 +2694,9 @@ return $('.overlay').css('display') != 'none'; } - // + /* + * license popup + */ function formatLicense() { var text = document.head.childNodes[1].nodeValue; @@ -2727,30 +2736,9 @@ return bulk.trim(); } - // - function setRevealState(ev) - { - var raw = ev.originalEvent; - var caps = raw.getModifierState && raw.getModifierState( 'CapsLock' ); - - if (caps) $('body').addClass('reveal'); - else $('body').removeClass('reveal'); - } - - function handleTab(ev) - { - var $this = $(this); - var $note = $this.closest('.note'); - var $sibl = ev.shiftKey ? $note.prev() : $note.next(); - - if ($sibl.length) - { - stopEditing($this, false, false); - $sibl.find('.text').click(); - } - } - - // + /* + * adjust this and that + */ function adjustLayout() { var $body = $('body'); @@ -2806,7 +2794,6 @@ cloneScrollPos($lists, $scroller); } - // function cloneScrollPos($src, $dst) { var src = $src[0]; @@ -2839,18 +2826,7 @@ } /* - * this should *really* be in a separate file - */ - function noteLocation($item) - { - var loc = 0; - for (var $p = $item.closest('.note'); $p.length; $p = $p.prev(), loc += 1); - for (var $p = $item.closest('.list'); $p.length; $p = $p.prev(), loc += 10000); - return loc; - } - - /* - * our stuff + * some global variables, fiiinally */ var NB = { @@ -2863,7 +2839,7 @@ NB.drag = new Drag(), /* - * UI + * event handlers */ $(window).on('blur', function(){ $('body').removeClass('reveal'); @@ -3190,23 +3166,20 @@ return false; }); - // $(window).resize(adjustLayout); /* * the init() */ - if (! NB.storage.open()) { - alert("Failed to load minimal required data from the storage"); easyMartina = true; throw new Error(); } var boards = NB.storage.getBoardIndex(); - boards.forEach(function(meta, board_id){ + boards.forEach( function(meta, board_id) { var hist = meta.history.join(', '); console.log( `Found board ${board_id} - "${meta.title}", revision ${meta.current}, history [${hist}]` ); }); @@ -3232,6 +3205,7 @@ updateBoardIndex(); + // if (! NB.board && ! $('.config .load-board').length) NB.board = createDemoBoard();