Fix checkbox matching

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-10-11 15:18:37 +02:00
parent 7cb5045dff
commit 2bd77fd2ce
4 changed files with 32 additions and 15 deletions

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -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]');
}

View File

@@ -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);
/**
* <div class="checkbox">
*/
@@ -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;