The best decision
The injection method will look like this:
inject: function(element, location) {
var el = Elements.from(this);
if($type(el) === 'array') var el = el.reverse();
return el.inject(element, location);
}
Let me break it into pieces.
1) Elements.from(this)takes everything the method applies to and converts it into elements:
var foo = "<p>Some text</p>";
var el = Elements.from(foo);
var bar = "<div>First div</div><div>Second div</div>";
var el = Elements.from(bar);
2) if($type(el) === 'array')checks if el is an array. If so, then apply .reverse()to el. This is necessary to enter items in the correct order. Otherwise, they will enter, for example, the second div first and the first div second. Obviously, if el is just one element, we do not need to change its order.
3) , el , , , location. el , .
, . implement():
String.implement({
inject: function(element, location) {
var el = Elements.from(this);
if($type(el) === 'array') var el = el.reverse();
return el.inject(element, location);
}
});
, . , domready, .. window.addEvent('domready', function() { ... });
:
var foo = "<p>Some text</p>";
foo.inject($('parentID'), 'top');
p parentID.
"" "" , :
inject: function(element, location) {
var html = element.get('html')
if(location === 'top') return element.set('html', this + html);
else if (location === 'bottom') return element.set('html', html + this);
}
innerHTML , , HTML, HTML , . innerHTML .
, innerHTML , , , , , , . , ( innerHTML), ( , ).
, "" "".