Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Feb 25, 2012
@metaskills metaskills Fix DOM manipulation bugs for append, prepend, after and before.
  * jQuery argument compatability allows multiple args with arrays.
  * Fix bug where undefined is allowed as an argument too.
abe171a
Commits on Apr 05, 2012
@nathansobo nathansobo Merge pull request #7 from metaskills/bug-attach-args
Fix DOM manipulation bugs for append, prepend, after and before.
e9ea105
Showing with 33 additions and 6 deletions.
  1. +29 −3 space-pen-spec.coffee
  2. +4 −3 space-pen.coffee
View
32 space-pen-spec.coffee
@@ -91,20 +91,25 @@ describe "View", ->
expect(view.subview.header.view()).toBe view.subview
describe "when a view is inserted within another element with jquery", ->
- [attachHandler, subviewAttachHandler] = []
+ [content, attachHandler, subviewAttachHandler] = []
beforeEach ->
attachHandler = jasmine.createSpy 'attachHandler'
subviewAttachHandler = jasmine.createSpy 'subviewAttachHandler'
view.on 'attach', attachHandler
view.subview.on 'attach', subviewAttachHandler
+
+ it "accepts undefined arguments as jQuery does", ->
+ view.append undefined
describe "when attached to an element that is on the DOM", ->
+ beforeEach ->
+ content = $('#jasmine-content')
+
afterEach ->
- $('#jasmine-content').empty()
+ content.empty()
it "triggers an 'attach' event on the view and its subviews", ->
- content = $('#jasmine-content')
content.append view
expect(attachHandler).toHaveBeenCalled()
expect(subviewAttachHandler).toHaveBeenCalled()
@@ -120,6 +125,27 @@ describe "View", ->
expect(attachHandler).toHaveBeenCalled()
expect(subviewAttachHandler).toHaveBeenCalled()
+ describe "with multiple arguments", ->
+ [view2, view3, view2Handler, view3Handler] = []
+
+ beforeEach ->
+ view2Class = class extends View
+ @content: -> @div id: "view2"
+ view3Class = class extends View
+ @content: -> @div id: "view3"
+ view2 = new view2Class
+ view3 = new view3Class
+ view2Handler = jasmine.createSpy 'view2Handler'
+ view3Handler = jasmine.createSpy 'view3Handler'
+ view2.on 'attach', view2Handler
+ view3.on 'attach', view3Handler
+
+ it "triggers an 'attach' event on all args", ->
+ content.append view, [view2, view3]
+ expect(attachHandler).toHaveBeenCalled()
+ expect(view2Handler).toHaveBeenCalled()
+ expect(view3Handler).toHaveBeenCalled()
+
describe "when attached to an element that is not on the DOM", ->
it "does not trigger an attach event", ->
fragment = $('<div>')
View
7 space-pen.coffee
@@ -160,15 +160,16 @@ jQuery.fn.view = -> this.data('view')
# Trigger attach event when views are added to the DOM
triggerAttachEvent = (element) ->
- if element.attr?('triggerAttachEvents') and element.parents('html').length
+ if element?.attr?('triggerAttachEvents') and element.parents('html').length
element.find('[triggerAttachEvents]').add(element).trigger('attach')
for methodName in ['append', 'prepend', 'after', 'before']
do (methodName) ->
originalMethod = $.fn[methodName]
jQuery.fn[methodName] = (args...) ->
- result = originalMethod.apply(this, args)
- triggerAttachEvent(args[0])
+ flatArgs = [].concat args...
+ result = originalMethod.apply(this, flatArgs)
+ triggerAttachEvent arg for arg in flatArgs
result
for methodName in ['prependTo', 'appendTo', 'insertAfter', 'insertBefore']

No commit comments for this range

Something went wrong with that request. Please try again.