mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Implement UI.getElementData
Replaces Spark.getDataContext
This commit is contained in:
@@ -13,21 +13,18 @@ UI.body.rendered = function () {
|
||||
|
||||
var newRank;
|
||||
if (!before) { // moving to the top of the list
|
||||
newRank = SimpleRationalRanks.beforeFirst(
|
||||
after.$ui.component.data().rank);
|
||||
newRank = SimpleRationalRanks.beforeFirst(UI.getElementData(after).rank);
|
||||
|
||||
} else if (!after) { // moving to the bottom of the list
|
||||
newRank = SimpleRationalRanks.afterLast(
|
||||
before.$ui.component.data().rank);
|
||||
newRank = SimpleRationalRanks.afterLast(UI.getElementData(before).rank);
|
||||
|
||||
} else {
|
||||
newRank = SimpleRationalRanks.between(
|
||||
before.$ui.component.data().rank,
|
||||
after.$ui.component.data().rank);
|
||||
|
||||
UI.getElementData(before).rank,
|
||||
UI.getElementData(after).rank);
|
||||
}
|
||||
|
||||
Items.update(el.$ui.component.data()._id, {$set: {rank: newRank}});
|
||||
Items.update(UI.getElementData(el)._id, {$set: {rank: newRank}});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -329,3 +329,11 @@ UI.Component.notifyParented = function () {
|
||||
UI.Component.preserve = function () {
|
||||
Meteor._debug("The 'preserve' method on templates is now unnecessary and deprecated.");
|
||||
};
|
||||
|
||||
// Gets the data context of the enclosing component that rendered a
|
||||
// given element
|
||||
UI.getElementData = function (el) {
|
||||
var comp = UI.DomRange.getContainingComponent(el);
|
||||
return comp && getComponentData(comp);
|
||||
};
|
||||
|
||||
|
||||
@@ -1107,4 +1107,4 @@ DomRange.prototype.on = function (events, selector, handler) {
|
||||
};
|
||||
|
||||
|
||||
UI.DomRange = DomRange;
|
||||
UI.DomRange = DomRange;
|
||||
|
||||
@@ -684,3 +684,18 @@ Tinytest.add("ui - UI.render", function (test) {
|
||||
|
||||
document.body.removeChild(div);
|
||||
});
|
||||
|
||||
Tinytest.add("ui - UI.getDataContext", function (test) {
|
||||
var div = document.createElement("DIV");
|
||||
|
||||
var tmpl = UI.Component.extend({
|
||||
render: function () {
|
||||
return SPAN();
|
||||
}
|
||||
});
|
||||
|
||||
UI.insert(UI.renderWithData(tmpl, {foo: "bar"}), div);
|
||||
var span = $(div).children('SPAN')[0];
|
||||
test.isTrue(span);
|
||||
test.equal(UI.getElementData(span), {foo: "bar"});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user