| OLD | NEW |
| 1 // Copyright 2006 Google Inc. | 1 // Copyright 2006 Google Inc. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 * element in the array, with the array element being the context | 545 * element in the array, with the array element being the context |
| 546 * object. If the array is empty, or the value is undefined, then the | 546 * object. If the array is empty, or the value is undefined, then the |
| 547 * current template node is dropped. If the value is not an array, | 547 * current template node is dropped. If the value is not an array, |
| 548 * then it is just made the context object. | 548 * then it is just made the context object. |
| 549 * | 549 * |
| 550 * @param {JsEvalContext} context The current evaluation context. | 550 * @param {JsEvalContext} context The current evaluation context. |
| 551 * | 551 * |
| 552 * @param {Element} template The currently processed node of the template. | 552 * @param {Element} template The currently processed node of the template. |
| 553 * | 553 * |
| 554 * @param {Function} select The javascript expression to evaluate. | 554 * @param {Function} select The javascript expression to evaluate. |
| 555 * | |
| 556 * @notypecheck FIXME(hmitchell): See OCL6434950. instance and value need | |
| 557 * type checks. | |
| 558 */ | 555 */ |
| 559 JstProcessor.prototype.jstSelect_ = function(context, template, select) { | 556 JstProcessor.prototype.jstSelect_ = function(context, template, select) { |
| 560 var me = this; | 557 var me = this; |
| 561 | 558 |
| 562 var value = context.jsexec(select, template); | 559 var value = context.jsexec(select, template); |
| 563 | 560 |
| 564 // Enable reprocessing: if this template is reprocessed, then only | 561 // Enable reprocessing: if this template is reprocessed, then only |
| 565 // fill the section instance here. Otherwise do the cardinal | 562 // fill the section instance here. Otherwise do the cardinal |
| 566 // processing of a new template. | 563 // processing of a new template. |
| 567 var instance = domGetAttribute(template, ATT_instance); | 564 var instance = domGetAttribute(template, ATT_instance); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 579 // The expression value instanceof Array is occasionally false for | 576 // The expression value instanceof Array is occasionally false for |
| 580 // arrays, seen in Firefox. Thus we recognize an array as an object | 577 // arrays, seen in Firefox. Thus we recognize an array as an object |
| 581 // which is not null that has a length property. Notice that this | 578 // which is not null that has a length property. Notice that this |
| 582 // also matches input data with a length property, so this property | 579 // also matches input data with a length property, so this property |
| 583 // name should be avoided in input data. | 580 // name should be avoided in input data. |
| 584 var multiple = isArray(value); | 581 var multiple = isArray(value); |
| 585 var count = multiple ? jsLength(value) : 1; | 582 var count = multiple ? jsLength(value) : 1; |
| 586 var multipleEmpty = (multiple && count == 0); | 583 var multipleEmpty = (multiple && count == 0); |
| 587 | 584 |
| 588 if (multiple) { | 585 if (multiple) { |
| 586 value = /** @type Array */(value); |
| 589 if (multipleEmpty) { | 587 if (multipleEmpty) { |
| 590 // For an empty array, keep the first template instance and mark | 588 // For an empty array, keep the first template instance and mark |
| 591 // it last. Remove all other template instances. | 589 // it last. Remove all other template instances. |
| 592 if (!instance) { | 590 if (!instance) { |
| 593 domSetAttribute(template, ATT_instance, STRING_asteriskzero); | 591 domSetAttribute(template, ATT_instance, STRING_asteriskzero); |
| 594 displayNone(template); | 592 displayNone(template); |
| 595 } else { | 593 } else { |
| 596 domRemoveNode(template); | 594 domRemoveNode(template); |
| 597 } | 595 } |
| 598 | 596 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 | 929 |
| 932 /** | 930 /** |
| 933 * Sets the jsinstance attribute on a node according to its context. | 931 * Sets the jsinstance attribute on a node according to its context. |
| 934 * | 932 * |
| 935 * @param {Element} template The template DOM node to set the instance | 933 * @param {Element} template The template DOM node to set the instance |
| 936 * attribute on. | 934 * attribute on. |
| 937 * | 935 * |
| 938 * @param {Array} values The current input context, the array of | 936 * @param {Array} values The current input context, the array of |
| 939 * values of which the template node will render one instance. | 937 * values of which the template node will render one instance. |
| 940 * | 938 * |
| 941 * @param {number} index The index of this template node in values. | 939 * @param {number|string} index The index of this template node in values. |
| 942 */ | 940 */ |
| 943 function jstSetInstance(template, values, index) { | 941 function jstSetInstance(template, values, index) { |
| 944 if (index == jsLength(values) - 1) { | 942 if (index == jsLength(values) - 1) { |
| 945 domSetAttribute(template, ATT_instance, CHAR_asterisk + index); | 943 domSetAttribute(template, ATT_instance, CHAR_asterisk + index); |
| 946 } else { | 944 } else { |
| 947 domSetAttribute(template, ATT_instance, STRING_empty + index); | 945 domSetAttribute(template, ATT_instance, STRING_empty + index); |
| 948 } | 946 } |
| 949 } | 947 } |
| 950 | 948 |
| 951 | 949 |
| 952 /** | 950 /** |
| 953 * Log the current state. | 951 * Log the current state. |
| 954 * @param {string} caller An identifier for the caller of .log_. | 952 * @param {string} caller An identifier for the caller of .log_. |
| 955 * @param {Element} template The template node being processed. | 953 * @param {Element} template The template node being processed. |
| 956 * @param {Object} jstAttributeValues The jst attributes of the template node. | 954 * @param {Object} jstAttributeValues The jst attributes of the template node. |
| 957 */ | 955 */ |
| 958 JstProcessor.prototype.logState_ = function( | 956 JstProcessor.prototype.logState_ = function( |
| 959 caller, template, jstAttributeValues) { | 957 caller, template, jstAttributeValues) { |
| 960 }; | 958 }; |
| OLD | NEW |