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 '