start of interface with jQuery for DOM impl

This commit is contained in:
David Greenspan
2013-08-28 13:28:39 -07:00
parent a842d575ce
commit fee94a706d
3 changed files with 45 additions and 2 deletions

43
packages/ui/backend.js Normal file
View File

@@ -0,0 +1,43 @@
UI = {};
if (Meteor.isClient) {
// XXX in the future, make the jQuery adapter a separate
// package and make the choice of back-end library
// configurable. Adapters all expose the DomBackend interface.
if (! Package.jquery)
throw new Error("Meteor UI jQuery adapter: jQuery not found.");
var $ = Package.jquery.jQuery;
var DomBackend = {
parseHTML: function (html) {
// Return an array of nodes.
//
// jQuery does fancy stuff like creating an appropriate
// container element and setting innerHTML on it, as well
// as working around various IE quirks.
return $.parseHTML(html);
},
watchElement: function (elem) {
$(elem).on('meteor_ui_domrange_gc', $.noop);
},
// Called when an element is removed from the DOM using the
// back-end library directly, either by removing it directly
// or by removing a parent.
//
// To use this, override it (set it).
onRemoveElement: function (elem) {}
};
// See http://bugs.jquery.com/ticket/12213#comment:23
$.event.special.meteor_ui_domrange_gc = {
teardown: function() {
DomBackend.onRemoveElement(this);
}
};
UI.DomBackend = DomBackend;
}

View File

@@ -1,4 +1,3 @@
UI = {};
var removeNode = function (n) {
// if (n.nodeType === 1 &&

View File

@@ -11,7 +11,8 @@ Package.on_use(function (api) {
api.use('ordered-dict');
api.use('minimongo'); // for idStringify
api.add_files(['domrange.js']);
api.add_files(['backend.js',
'domrange.js']);
});
Package.on_test(function (api) {