From 2bd77fd2cee0ebb4847b93417d3200a28e33b115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 11 Oct 2018 15:18:37 +0200 Subject: [PATCH 1/2] Fix checkbox matching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- css/style.scss | 15 +++++++++++++-- js/controller/BoardController.js | 8 ++++---- js/controller/CardController.js | 4 ++-- js/legacy/markdown-it-checkbox.js | 20 +++++++++++++------- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/css/style.scss b/css/style.scss index c8224f230..9fc25765c 100644 --- a/css/style.scss +++ b/css/style.scss @@ -1517,8 +1517,19 @@ input.input-inline { display: inline-block; min-height: 12px; } - li input[type=checkbox] { - margin: 0px 10px 0px -20px; + + li input[type="checkbox"].checkbox + label::before { + margin-left: -15px; + + } + input[type="checkbox"].checkbox + label::before { + position: relative; + z-index: 100; + margin-right: 10px; + margin-top: 0; + } + li input[type="checkbox"].checkbox:not(:checked) + label::before { + background-color: $color-main-background; } } diff --git a/js/controller/BoardController.js b/js/controller/BoardController.js index b131c66bc..5b224e4ad 100644 --- a/js/controller/BoardController.js +++ b/js/controller/BoardController.js @@ -100,8 +100,8 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St * @returns array of [finished, total] checkboxes */ $scope.getCheckboxes = function(text) { - const regTotal = /\[(X|\s|\_|\-)\]\s(.*)/ig; - const regFinished = /\[(X|\_|\-)\]\s(.*)/ig; + const regTotal = /\[(X|\s|\_|\-)\]/igm; + const regFinished = /\[(X|\_|\-)\]/igm; return [ ((text || '').match(regFinished) || []).length, ((text || '').match(regTotal) || []).length @@ -375,7 +375,7 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St itemMoved: function (event) { event.source.itemScope.modelValue.status = event.dest.sortableScope.$parent.column; var order = event.dest.index; - var card = event.source.itemScope.c; + var card = $scope.cardservice.get(event.source.itemScope.c.id); var newStack = event.dest.sortableScope.$parent.s.id; var oldStack = card.stackId; card.stackId = newStack; @@ -391,7 +391,7 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St }, orderChanged: function (event) { var order = event.dest.index; - var card = event.source.itemScope.c; + var card = $scope.cardservice.get(event.source.itemScope.c.id); var stack = event.dest.sortableScope.$parent.s.id; CardService.reorder(card, order).then(function (data) { StackService.reorderCard(card, order); diff --git a/js/controller/CardController.js b/js/controller/CardController.js index 9c2fd2fce..acb235a30 100644 --- a/js/controller/CardController.js +++ b/js/controller/CardController.js @@ -101,11 +101,11 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location, $scope.toggleCheckbox = function (id) { $('#markdown input[type=checkbox]').attr('disabled', true); $scope.status.edit = angular.copy(CardService.getCurrent()); - var reg = /\[(X|\s|\_|\-)\]\s(.*)/ig; + var reg = /\[(X|\s|\_|\-)\]/ig; var nth = 0; $scope.status.edit.description = $scope.status.edit.description.replace(reg, function (match, i, original) { var result = match; - if (nth++ === id) { + if ('' + nth++ === '' + id) { if (match.match(/^\[\s\]/i)) { result = match.replace(/\[\s\]/i, '[x]'); } diff --git a/js/legacy/markdown-it-checkbox.js b/js/legacy/markdown-it-checkbox.js index 1aa1ecf95..e28d663ce 100644 --- a/js/legacy/markdown-it-checkbox.js +++ b/js/legacy/markdown-it-checkbox.js @@ -17,11 +17,15 @@ checkboxReplace = function(md, options, Token) { idPrefix: 'checkbox' }; options = Object.assign(defaults, options); - pattern = /\[(X|\s|\_|\-)\]\s(.*)/i; - createTokens = function(checked, label, Token) { + pattern = /(.*?)(\[(X|\s|\_|\-)\])(.*)/igm; + createTokens = function(checked, label, Token, before) { var id, idNumeric, nodes, token; nodes = []; + token = new Token("text", "", 0); + token.content = before; + nodes.push(token); + /** *
*/ @@ -42,6 +46,7 @@ checkboxReplace = function(md, options, Token) { if (checked === true) { token.attrs.push(["checked", "true"]); } + token.attrs.push(["class", "checkbox"]); nodes.push(token); /** @@ -68,19 +73,20 @@ checkboxReplace = function(md, options, Token) { return nodes; }; splitTextToken = function(original, Token) { - var checked, label, matches, text, value; + var checked, label, matches, text, value, before; text = original.content; - matches = text.match(pattern); + matches = pattern.exec(text); if (matches === null) { return original; } checked = false; - value = matches[1]; - label = matches[2]; + before = matches[1]; + value = matches[3]; + label = matches[4]; if (value === "X" || value === "x") { checked = true; } - return createTokens(checked, label, Token); + return createTokens(checked, label, Token, before); }; return function(state) { lastId = 0; From 71e6ff1b79f208366af693968658a5802a942e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 7 Nov 2018 20:53:38 +0100 Subject: [PATCH 2/2] Make checkbox id order ascending (fixes #678) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- js/legacy/markdown-it-checkbox.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/legacy/markdown-it-checkbox.js b/js/legacy/markdown-it-checkbox.js index e28d663ce..a156bc822 100644 --- a/js/legacy/markdown-it-checkbox.js +++ b/js/legacy/markdown-it-checkbox.js @@ -100,11 +100,11 @@ checkboxReplace = function(md, options, Token) { continue; } tokens = blockTokens[j].children; - i = tokens.length - 1; - while (i >= 0) { + i = 0; + while (i < tokens.length) { token = tokens[i]; blockTokens[j].children = tokens = arrayReplaceAt(tokens, i, splitTextToken(token, state.Token)); - i--; + i++; } j++; }