mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Merge branch 'master' into editor
This commit is contained in:
@@ -92,26 +92,31 @@ describe "Template", ->
|
||||
expect(view.subview.header.view()).toBe view.subview
|
||||
|
||||
describe "when a view is inserted within another element with jquery", ->
|
||||
attachHandler = null
|
||||
[attachHandler, subviewAttachHandler] = []
|
||||
|
||||
beforeEach ->
|
||||
attachHandler = jasmine.createSpy 'attachHandler'
|
||||
subviewAttachHandler = jasmine.createSpy 'subviewAttachHandler'
|
||||
view.on 'attach', attachHandler
|
||||
view.subview.on 'attach', subviewAttachHandler
|
||||
|
||||
describe "when attached to an element that is on the DOM", ->
|
||||
it "triggers the 'attach' event on the view", ->
|
||||
it "triggers an 'attach' event on the view and its subviews", ->
|
||||
content = $('#jasmine-content')
|
||||
content.append view
|
||||
expect(attachHandler).toHaveBeenCalled()
|
||||
expect(subviewAttachHandler).toHaveBeenCalled()
|
||||
|
||||
view.detach()
|
||||
content.empty()
|
||||
attachHandler.reset()
|
||||
subviewAttachHandler.reset()
|
||||
|
||||
otherElt = $('<div>')
|
||||
content.append(otherElt)
|
||||
view.insertBefore(otherElt)
|
||||
expect(attachHandler).toHaveBeenCalled()
|
||||
expect(subviewAttachHandler).toHaveBeenCalled()
|
||||
|
||||
describe "when attached to an element that is not on the DOM", ->
|
||||
it "does not trigger an attach event", ->
|
||||
|
||||
@@ -27,7 +27,7 @@ class Template
|
||||
@bindEvents(view)
|
||||
if @viewProperties
|
||||
$.extend(view, @viewProperties)
|
||||
view.data('triggerAttach', true)
|
||||
view.attr('triggerAttachEvents', true)
|
||||
view.initialize?(attributes)
|
||||
view
|
||||
|
||||
@@ -53,21 +53,21 @@ $.fn.view = ->
|
||||
this.data('view')
|
||||
|
||||
# Trigger attach event when views are added to the DOM
|
||||
checkIfAttached = (elt) ->
|
||||
if elt.data?('triggerAttach') and elt.parents('html').length
|
||||
elt.trigger('attach')
|
||||
triggerAttachEvent = (elt) ->
|
||||
if elt.attr?('triggerAttachEvents') and elt.parents('html').length
|
||||
elt.find('[triggerAttachEvents]').add(elt).trigger('attach')
|
||||
|
||||
_.each ['append', 'prepend', 'after', 'before'], (methodName) ->
|
||||
originalMethod = $.fn[methodName]
|
||||
$.fn[methodName] = (args...) ->
|
||||
result = originalMethod.apply(this, args)
|
||||
checkIfAttached(args[0])
|
||||
triggerAttachEvent(args[0])
|
||||
result
|
||||
|
||||
_.each ['prependTo', 'appendTo', 'insertAfter', 'insertBefore'], (methodName) ->
|
||||
originalMethod = $.fn[methodName]
|
||||
$.fn[methodName] = (args...) ->
|
||||
result = originalMethod.apply(this, args)
|
||||
checkIfAttached(this)
|
||||
triggerAttachEvent(this)
|
||||
result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user