From fee94a706d989af5eff8a0b73ba90836edd79011 Mon Sep 17 00:00:00 2001 From: David Greenspan Date: Wed, 28 Aug 2013 13:28:39 -0700 Subject: [PATCH] start of interface with jQuery for DOM impl --- packages/ui/backend.js | 43 +++++++++++++++++++++++++++++++++++++++++ packages/ui/domrange.js | 1 - packages/ui/package.js | 3 ++- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 packages/ui/backend.js diff --git a/packages/ui/backend.js b/packages/ui/backend.js new file mode 100644 index 0000000000..9df448b4a9 --- /dev/null +++ b/packages/ui/backend.js @@ -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; + +} \ No newline at end of file diff --git a/packages/ui/domrange.js b/packages/ui/domrange.js index 4706db056b..fd89d59cfd 100644 --- a/packages/ui/domrange.js +++ b/packages/ui/domrange.js @@ -1,4 +1,3 @@ -UI = {}; var removeNode = function (n) { // if (n.nodeType === 1 && diff --git a/packages/ui/package.js b/packages/ui/package.js index 749e9c6c74..0caa7f794c 100644 --- a/packages/ui/package.js +++ b/packages/ui/package.js @@ -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) {