-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add component to specific index #2540
Changes from 12 commits
80d8f26
ba0065a
19cad93
0527665
d763d0e
3b0ba5f
0f02202
5f02d1f
4e91e67
c5442c8
d25a874
579215c
04fef83
6efa25e
ccac3c5
266097a
cb49200
7b7ca3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,5 @@ test/coverage/* | |
.sass-cache | ||
|
||
dist/* | ||
|
||
.idea/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,10 +336,11 @@ class Component { | |
* | ||
* @param {String|Component} child The class name or instance of a child to add | ||
* @param {Object=} options Options, including options to be passed to children of the child. | ||
* @param {Number} index into our children array to attempt to add the child | ||
* @return {Component} The child component (created by this process if a string was used) | ||
* @method addChild | ||
*/ | ||
addChild(child, options={}) { | ||
addChild(child, options={}, index=this.children_.length) { | ||
let component; | ||
let componentName; | ||
|
||
|
@@ -388,7 +389,7 @@ class Component { | |
component = child; | ||
} | ||
|
||
this.children_.push(component); | ||
this.children_.splice(index, 0, component); | ||
|
||
if (typeof component.id === 'function') { | ||
this.childIndex_[component.id()] = component; | ||
|
@@ -405,7 +406,9 @@ class Component { | |
// Add the UI object's element to the container div (box) | ||
// Having an element is not required | ||
if (typeof component.el === 'function' && component.el()) { | ||
this.contentEl().appendChild(component.el()); | ||
var childNodes = this.contentEl().children; | ||
var refNode = childNodes[index] || undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also, it would automatically get the value |
||
this.contentEl().insertBefore(component.el(), refNode); | ||
} | ||
|
||
// Return so it can stored on parent object if desired. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,7 +300,17 @@ class Player extends Component { | |
if (tag.parentNode) { | ||
tag.parentNode.insertBefore(el, tag); | ||
} | ||
Dom.insertElFirst(tag, el); // Breaks iPhone, fixed in HTML5 setup. | ||
|
||
//Dom.insertElFirst(tag, el); // Breaks iPhone, fixed in HTML5 setup. | ||
|
||
// append the DOM el function to make use of our component.addChild method | ||
// to properly be injected into the children Array | ||
tag.el = function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer not to modify the DOM element as much as we can. I would prefer this wasn't changed quite yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, interesting. I'll take a look later today. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the issue is that for some reason if we're using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because Dom.insertElFirst(tag, el); // Breaks iPhone, fixed in HTML5 setup.
this.children_.unshift(tag); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you can make that last change, I think we may be able to pull it in this week. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good. updated the comments there to try and capture the learnings There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should update it to be something like: // insert the tag as the first child of the player element
// then manually add it to the children array so that this.addChild
// will work properly for other components
Dom.insertElFirst(tag, el); // Breaks iPhone, fixed in HTML5 setup.
this.children_.unshift(tag); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh! my bad, I misunderstood. I'll update that straight away. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh, no worries. I realized I wasn't perfectly clear. I'll try and work on that for the future and would love to see more contributions from you as well! |
||
return this; | ||
}; | ||
|
||
// add our tag as the first child | ||
this.addChild(tag, {}, 0); | ||
|
||
this.el_ = el; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change these
var
s tolet
s.