Skip to content

Commit

Permalink
hook up listener for checklist
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Jan 10, 2017
1 parent 51c03ba commit adb980d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
11 changes: 7 additions & 4 deletions assets/core.styl
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ resets(arr)
list-style-type: none
ul > li::before
content: '\25CF'
ul[data-checked=true] > li::before,
ul[data-checked=false] > li::before
color: #777
cursor: pointer
ul[data-checked=true],
ul[data-checked=false]
pointer-events: none
> li::before
color: #777
cursor: pointer
pointer-events: all
ul[data-checked=true] > li::before
content: '\2611'
ul[data-checked=false] > li::before
Expand Down
13 changes: 13 additions & 0 deletions formats/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ class List extends Container {
return undefined;
}

constructor(domNode) {
super(domNode)
domNode.addEventListener('click', (e) => {
let format = this.statics.formats(domNode);
if (e.target.parentNode !== domNode) return;
if (format === 'checked') {
this.format('list', 'unchecked');
} else if(format === 'unchecked') {
this.format('list', 'checked');
}
});
}

format(name, value) {
if (this.children.length > 0) {
this.children.tail.format(name, value);
Expand Down
25 changes: 19 additions & 6 deletions modules/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,6 @@ Toolbar.DEFAULTS = {
}
this.quill.format('direction', value, Quill.sources.USER);
},
link: function(value) {
if (value === true) {
value = prompt('Enter link URL:');
}
this.quill.format('link', value, Quill.sources.USER);
},
indent: function(value) {
let range = this.quill.getSelection();
let formats = this.quill.getFormat(range);
Expand All @@ -240,6 +234,25 @@ Toolbar.DEFAULTS = {
if (formats.direction === 'rtl') modifier *= -1;
this.quill.format('indent', indent + modifier, Quill.sources.USER);
}
},
link: function(value) {
if (value === true) {
value = prompt('Enter link URL:');
}
this.quill.format('link', value, Quill.sources.USER);
},
list: function(value) {
let range = this.quill.getSelection();
let formats = this.quill.getFormat(range);
if (value === 'check') {
if (formats['list'] === 'checked' || formats['list'] === 'unchecked') {
this.quill.format('list', false, Quill.sources.USER);
} else {
this.quill.format('list', 'unchecked', Quill.sources.USER);
}
} else {
this.quill.format('list', value, Quill.sources.USER);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
'list': {
'ordered' : require('../assets/icons/list-ordered.svg'),
'bullet' : require('../assets/icons/list-bullet.svg'),
'unchecked' : require('../assets/icons/list-check.svg')
'check' : require('../assets/icons/list-check.svg')
},
'script': {
'sub' : require('../assets/icons/subscript.svg'),
Expand Down

0 comments on commit adb980d

Please sign in to comment.