diff --git a/packages/preserve-inputs/labeler.js b/packages/preserve-inputs/labeler.js deleted file mode 100644 index 2fe0217f2c..0000000000 --- a/packages/preserve-inputs/labeler.js +++ /dev/null @@ -1,38 +0,0 @@ -PreserveInputs = {}; - -PreserveInputs.idNameLabeler = function(n) { - var label = null; - - if (n.nodeType === 1) { - if (n.id) { - label = '#' + n.id; - } else if (n.getAttribute("name")) { - label = n.getAttribute("name"); - // Radio button special case: radio buttons - // in a group all have the same name. Their value - // determines their identity. - // Checkboxes with the same name and different - // values are also sometimes used in apps, so - // we treat them similarly. - if (n.nodeName === 'INPUT' && - (n.type === 'radio' || n.type === 'checkbox') && - n.value) - label = label + ':' + n.value; - - // include parent names and IDs up to enclosing ID - // in the label - while (n.parentNode && - n.parentNode.nodeType === 1) { // ELEMENT - n = n.parentNode; - if (n.id) { - label = '#' + n.id + "/" + label; - break; - } else if (n.getAttribute('name')) { - label = n.getAttribute('name') + "/" + label; - } - } - } - } - - return label; -}; diff --git a/packages/preserve-inputs/package.js b/packages/preserve-inputs/package.js index 1cc41f59fe..805cb64e8e 100644 --- a/packages/preserve-inputs/package.js +++ b/packages/preserve-inputs/package.js @@ -4,9 +4,5 @@ Package.describe({ Package.on_use(function (api, where) { api.use(['underscore', 'spark', 'templating']); - api.add_files(["labeler.js", "preserve-inputs.js"], "client"); + api.add_files("preserve-inputs.js", "client"); }); - -/*Package.on_test(function (api) { - api.add_files('labeler.js', 'client'); -});*/ diff --git a/packages/preserve-inputs/preserve-inputs.js b/packages/preserve-inputs/preserve-inputs.js index e44dae3acf..55747ebf3d 100644 --- a/packages/preserve-inputs/preserve-inputs.js +++ b/packages/preserve-inputs/preserve-inputs.js @@ -1,9 +1,51 @@ - (function () { - var inputTags = 'input textarea button select option'.split(' '); - var selector = _.map(inputTags, function (t) { - return t.replace(/^.*$/, '$&[id], $&[name]'); - }).join(', '); - Spark._globalPreserves[selector] = PreserveInputs.idNameLabeler; +PreserveInputs = {}; + +var inputTags = 'input textarea button select option'.split(' '); + +PreserveInputs.selector = _.map(inputTags, function (t) { + return t.replace(/^.*$/, '$&[id], $&[name]'); +}).join(', '); + +PreserveInputs.idNameLabeler = function(n) { + var label = null; + + if (n.nodeType === 1) { + if (n.id) { + label = '#' + n.id; + } else if (n.getAttribute("name")) { + label = n.getAttribute("name"); + // Radio button special case: radio buttons + // in a group all have the same name. Their value + // determines their identity. + // Checkboxes with the same name and different + // values are also sometimes used in apps, so + // we treat them similarly. + if (n.nodeName === 'INPUT' && + (n.type === 'radio' || n.type === 'checkbox') && + n.value) + label = label + ':' + n.value; + + // include parent names and IDs up to enclosing ID + // in the label + while (n.parentNode && + n.parentNode.nodeType === 1) { // ELEMENT + n = n.parentNode; + if (n.id) { + label = '#' + n.id + "/" + label; + break; + } else if (n.getAttribute('name')) { + label = n.getAttribute('name') + "/" + label; + } + } + } + } + + return label; +}; + +Spark._globalPreserves[PreserveInputs.selector] = + PreserveInputs.idNameLabeler; + })(); diff --git a/packages/spark/package.js b/packages/spark/package.js index 2c28577c71..a204eaf269 100644 --- a/packages/spark/package.js +++ b/packages/spark/package.js @@ -13,6 +13,9 @@ Package.on_use(function (api) { Package.on_test(function (api) { api.use('tinytest'); api.use(['spark', 'test-helpers'], 'client'); + // we include preserve inputs just for idNameLabeler; + // we deactivate the default preservation in spark_tests.js + api.use('preserve-inputs', 'client'); api.add_files('test_form_responder.js', 'server'); diff --git a/packages/spark/spark_tests.js b/packages/spark/spark_tests.js index 16ddddbd29..007607e6a1 100644 --- a/packages/spark/spark_tests.js +++ b/packages/spark/spark_tests.js @@ -8,49 +8,17 @@ Spark._checkIECompliance = true; (function () { -var legacyLabels = { - '*[id], *[name]': function(n) { - var label = null; +// deactivate the automatic global preservation we get +// from including the preserve-inputs package +Spark._globalPreserves = {}; - if (n.nodeType === 1) { - if (n.id) { - label = '#' + n.id; - } else if (n.getAttribute("name")) { - label = n.getAttribute("name"); - // Radio button special case: radio buttons - // in a group all have the same name. Their value - // determines their identity. - // Checkboxes with the same name and different - // values are also sometimes used in apps, so - // we treat them similarly. - if (n.nodeName === 'INPUT' && - (n.type === 'radio' || n.type === 'checkbox') && - n.value) - label = label + ':' + n.value; - - // include parent names and IDs up to enclosing ID - // in the label - while (n.parentNode && - n.parentNode.nodeType === 1) { // ELEMENT - n = n.parentNode; - if (n.id) { - label = '#' + n.id + "/" + label; - break; - } else if (n.getAttribute('name')) { - label = n.getAttribute('name') + "/" + label; - } - } - } - } - - return label; - } +var idNameLabels = { + '*[id], *[name]': PreserveInputs.idNameLabeler }; -var renderWithLegacyLabels = function (htmlFunc) { +var renderWithPreservation = function (htmlFunc) { return Meteor.render(function () { - return Spark.createLandmark({ preserve: legacyLabels }, - htmlFunc); + return Spark.createLandmark({ preserve: idNameLabels}, htmlFunc); }); }; @@ -818,7 +786,7 @@ Tinytest.add("spark - tables", function (test) { Meteor.flush(); test.equal(R.numListeners(), 0); - div = OnscreenDiv(renderWithLegacyLabels(function() { + div = OnscreenDiv(renderWithPreservation(function() { return ''+R.get()+'
'; })); Meteor.flush(); @@ -1391,7 +1359,7 @@ Tinytest.add("spark - preserve copies attributes", function(test) { var R1 = ReactiveVar("foo"); var R2 = ReactiveVar("abcd"); - var frag = WrappedFrag(renderWithLegacyLabels(function() { + var frag = WrappedFrag(renderWithPreservation(function() { return '
'; })).hold(); @@ -1415,7 +1383,7 @@ Tinytest.add("spark - preserve copies attributes", function(test) { var R; R = ReactiveVar(false); - frag = WrappedFrag(renderWithLegacyLabels(function() { + frag = WrappedFrag(renderWithPreservation(function() { return ''; })).hold(); var get_checked = function() { return !! frag.node().firstChild.checked; }; @@ -1435,7 +1403,7 @@ Tinytest.add("spark - preserve copies attributes", function(test) { test.equal(get_checked(), true); frag.release(); R = ReactiveVar(true); - frag = WrappedFrag(renderWithLegacyLabels(function() { + frag = WrappedFrag(renderWithPreservation(function() { return ''; })).hold(); test.equal(get_checked(), true); @@ -1450,7 +1418,7 @@ Tinytest.add("spark - preserve copies attributes", function(test) { _.each([false, true], function(with_focus) { R = ReactiveVar("apple"); - var div = OnscreenDiv(renderWithLegacyLabels(function() { + var div = OnscreenDiv(renderWithPreservation(function() { return ''; })); var maybe_focus = function(div) { @@ -1482,7 +1450,7 @@ Tinytest.add("spark - preserve copies attributes", function(test) { test.equal(get_value(), if_blurred("steve", "jerry")); div.kill(); R = ReactiveVar(""); - div = OnscreenDiv(renderWithLegacyLabels(function() { + div = OnscreenDiv(renderWithPreservation(function() { return ''; })); maybe_focus(div); @@ -1504,7 +1472,7 @@ Tinytest.add("spark - bad labels", function(test) { var go = function(html1, html2) { var R = ReactiveVar(true); - var frag = WrappedFrag(renderWithLegacyLabels(function() { + var frag = WrappedFrag(renderWithPreservation(function() { return R.get() ? html1 : html2; })).hold(); @@ -1670,7 +1638,7 @@ Tinytest.add("spark - landmark patching", function(test) { var R = ReactiveVar(false); var structure = randomNodeList(null, 6); var frag = WrappedFrag(Meteor.render(function () { - return Spark.createLandmark({ preserve: legacyLabels }, function () { + return Spark.createLandmark({ preserve: idNameLabels }, function () { return nodeListToHtml(structure, R.get()); }); })).hold(); @@ -1871,7 +1839,7 @@ Tinytest.add("spark - leaderboard", function(test) { var players = new LocalCollection(); var selected_player = ReactiveVar(); - var scores = OnscreenDiv(renderWithLegacyLabels(function() { + var scores = OnscreenDiv(renderWithPreservation(function() { var html = Spark.list( players.find({}, {sort: {score: -1}}), function(player) { @@ -1888,7 +1856,7 @@ Tinytest.add("spark - leaderboard", function(test) { '
' + player.score + '
'; html = Spark.setDataContext(player, html); html = Spark.createLandmark( - {preserve: legacyLabels}, + {preserve: idNameLabels}, function() { return html; }); return html; }); @@ -2034,7 +2002,7 @@ Tinytest.add("spark - list table", function(test) { var html = ""+doc.value + (doc.reactive ? R.get() : '')+ ""; html = Spark.createLandmark( - {preserve: legacyLabels}, + {preserve: idNameLabels}, function() { return html; }); return html; }); @@ -2255,7 +2223,7 @@ Tinytest.add("spark - list event data", function(test) { Tinytest.add("spark - events on preserved nodes", function(test) { var count = ReactiveVar(0); - var demo = OnscreenDiv(renderWithLegacyLabels(function() { + var demo = OnscreenDiv(renderWithPreservation(function() { var html = Spark.isolate(function () { return '
'+ ''+ @@ -2389,7 +2357,7 @@ var make_input_tester = function(render_func, events) { var R = ReactiveVar(0); var div = OnscreenDiv( - renderWithLegacyLabels(function() { + renderWithPreservation(function() { R.get(); // create dependency var html = render_func(); html = Spark.attachEvents(events, html); @@ -2669,7 +2637,7 @@ Tinytest.add("spark - controls", function(test) { var R = ReactiveVar(""); var change_buf = []; - var div = OnscreenDiv(renderWithLegacyLabels(function() { + var div = OnscreenDiv(renderWithPreservation(function() { var buf = []; buf.push("Band: "); _.each(["AM", "FM", "XM"], function(band) { @@ -2742,7 +2710,7 @@ Tinytest.add("spark - controls", function(test) { // Textarea R = ReactiveVar({x:"test"}); - div = OnscreenDiv(renderWithLegacyLabels(function() { + div = OnscreenDiv(renderWithPreservation(function() { return ''; })); @@ -3691,7 +3659,7 @@ Tinytest.add("spark - legacy preserve names", function (test) { var R = ReactiveVar("foo"); var R2 = ReactiveVar("apple"); - var div = OnscreenDiv(renderWithLegacyLabels(function () { + var div = OnscreenDiv(renderWithPreservation(function () { R.get(); // create dependency return ('
' + '
' +