Skip to content

Commit

Permalink
Make ko binding handlers fire on update instead of init.
Browse files Browse the repository at this point in the history
  • Loading branch information
lo5 committed May 9, 2014
1 parent a6c62be commit 7c6fef5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions client/src/scripts/knockout.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@

ko.bindingHandlers.paragraph =
update: (element, valueAccessor, allBindings, viewModel, bindingContext) ->
html = ''
if data = ko.unwrap valueAccessor()
if -1 isnt data.indexOf '\n'
ko.utils.setHtml element, "<span>#{data.replace /\n/g, '<br/>'}</span>"
html = "<span>#{data.replace /\n/g, '<br/>'}</span>"
else
ko.utils.setTextContent element, data
else
ko.utils.setTextContent element, ''
html = data
ko.utils.setHtml element, html

ko.bindingHandlers.json =
init: (element, valueAccessor, allBindings, viewModel, bindingContext) ->
update: (element, valueAccessor, allBindings, viewModel, bindingContext) ->
data = ko.unwrap valueAccessor()

$(element).text JSON.stringify data, null, 2
Expand Down Expand Up @@ -97,7 +97,7 @@ ko.bindingHandlers.tooltip =
timeagoUpdateInterval = 60000
momentTimestampFormat = 'MMMM Do YYYY, h:mm:ss a'
ko.bindingHandlers.timeago =
init: (element, valueAccessor, allBindings, viewModel, bindingContext) ->
update: (element, valueAccessor, allBindings, viewModel, bindingContext) ->
timestamp = ko.unwrap valueAccessor()
timestamp = parseInt timestamp if isString timestamp
$element = $ element
Expand Down

0 comments on commit 7c6fef5

Please sign in to comment.