Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #23 from fatihacet/line-source-number
Browse files Browse the repository at this point in the history
Pass lineNumber and lineSource in changed event
  • Loading branch information
deckar01 authored Jan 22, 2019
2 parents 007fdec + 9ec942a commit d1c9645
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions app/assets/javascripts/task_list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,18 @@ class TaskList
@field.dispatchEvent changeEvent

unless changeEvent.defaultPrevented
@field.value = TaskList.updateSource(@field.value, index, item.checked)
{ result, lineNumber, lineSource } =
TaskList.updateSource(@field.value, index, item.checked)

@field.value = result
changeEvent = createEvent 'change'
@field.dispatchEvent changeEvent
changedEvent = createEvent 'tasklist:changed',
changedEvent = createEvent 'tasklist:changed', {
index: index
checked: item.checked
lineNumber: lineNumber
lineSource: lineSource
}
@field.dispatchEvent changedEvent

# Static interface
Expand Down Expand Up @@ -220,7 +226,10 @@ class TaskList
split("\n")
index = 0
inCodeBlock = false
result = for line in source.split("\n")
lineNumber
lineSource

result = for line, i in source.split("\n")
if inCodeBlock
# Lines inside of a code block are ignored.
if line.match(@endFencesPattern)
Expand All @@ -232,13 +241,19 @@ class TaskList
else if line in clean && line.match(@itemPattern)
index += 1
if index == itemIndex
lineNumber = i + 1
lineSource = line
line =
if checked
line.replace(@incompletePattern, @complete)
else
line.replace(@completePattern, @incomplete)
line
result.join("\n")
return {
result: result.join("\n")
lineNumber: lineNumber
lineSource: lineSource
}

if typeof jQuery != 'undefined'
jQuery.fn.taskList = (method) ->
Expand Down

0 comments on commit d1c9645

Please sign in to comment.