| OLD | NEW |
| 1 // Copyright 2006 Google Inc. All rights reserved. | 1 // Copyright 2006 Google Inc. All rights reserved. |
| 2 /** | 2 /** |
| 3 * @fileoverview A simple formatter to project JavaScript data into | 3 * @fileoverview A simple formatter to project JavaScript data into |
| 4 * HTML templates. The template is edited in place. I.e. in order to | 4 * HTML templates. The template is edited in place. I.e. in order to |
| 5 * instantiate a template, clone it from the DOM first, and then | 5 * instantiate a template, clone it from the DOM first, and then |
| 6 * process the cloned template. This allows for updating of templates: | 6 * process the cloned template. This allows for updating of templates: |
| 7 * If the templates is processed again, changed values are merely | 7 * If the templates is processed again, changed values are merely |
| 8 * updated. | 8 * updated. |
| 9 * | 9 * |
| 10 * NOTE: IE DOM doesn't have importNode(). | 10 * NOTE: IE DOM doesn't have importNode(). |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 } | 521 } |
| 522 var label = stringTrim(values[i].substr(0, colon)); | 522 var label = stringTrim(values[i].substr(0, colon)); |
| 523 var value = context.jseval(values[i].substr(colon + 1), template); | 523 var value = context.jseval(values[i].substr(colon + 1), template); |
| 524 | 524 |
| 525 if (label.charAt(0) == '$') { | 525 if (label.charAt(0) == '$') { |
| 526 // A jsvalues entry whose name starts with $ sets a local | 526 // A jsvalues entry whose name starts with $ sets a local |
| 527 // variable. | 527 // variable. |
| 528 context.setVariable(label, value); | 528 context.setVariable(label, value); |
| 529 | 529 |
| 530 } else if (label.charAt(0) == '.') { | 530 } else if (label.charAt(0) == '.') { |
| 531 // A jsvalues entry whose name starts with . sets a property | 531 // A jsvalues entry whose name starts with . sets a property of |
| 532 // of the current template node. | 532 // the current template node. The name may have further dot |
| 533 template[label.substr(1)] = value; | 533 // separated components, which are translated into namespace |
| 534 | 534 // objects. This specifically allows to set properties on .style |
| 535 // using jsvalues. NOTE(mesch): Setting the style attribute has |
| 536 // no effect in IE and hence should not be done anyway. |
| 537 var nameSpaceLabel = label.substr(1).split('.'); |
| 538 var nameSpaceObject = template; |
| 539 var nameSpaceDepth = jsLength(nameSpaceLabel); |
| 540 for (var j = 0, J = nameSpaceDepth - 1; j < J; ++j) { |
| 541 var jLabel = nameSpaceLabel[j]; |
| 542 if (!nameSpaceObject[jLabel]) { |
| 543 nameSpaceObject[jLabel] = {}; |
| 544 } |
| 545 nameSpaceObject = nameSpaceObject[jLabel]; |
| 546 } |
| 547 nameSpaceObject[nameSpaceLabel[nameSpaceDepth - 1]] = value; |
| 535 } else if (label) { | 548 } else if (label) { |
| 536 // Any other jsvalues entry sets an attribute of the current | 549 // Any other jsvalues entry sets an attribute of the current |
| 537 // template node. | 550 // template node. |
| 538 if (typeof value == 'boolean') { | 551 if (typeof value == 'boolean') { |
| 539 // Handle boolean values that are set as attributes specially, | 552 // Handle boolean values that are set as attributes specially, |
| 540 // according to the XML/HTML convention. | 553 // according to the XML/HTML convention. |
| 541 if (value) { | 554 if (value) { |
| 542 domSetAttribute(template, label, label); | 555 domSetAttribute(template, label, label); |
| 543 } else { | 556 } else { |
| 544 domRemoveAttribute(template, label); | 557 domRemoveAttribute(template, label); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 domRemoveAttribute(ret, 'id'); | 608 domRemoveAttribute(ret, 'id'); |
| 596 return ret; | 609 return ret; |
| 597 } else { | 610 } else { |
| 598 return null; | 611 return null; |
| 599 } | 612 } |
| 600 } | 613 } |
| 601 | 614 |
| 602 window['jstGetTemplate'] = jstGetTemplate; | 615 window['jstGetTemplate'] = jstGetTemplate; |
| 603 window['jstProcess'] = jstProcess; | 616 window['jstProcess'] = jstProcess; |
| 604 window['JsExprContext'] = JsExprContext; | 617 window['JsExprContext'] = JsExprContext; |
| OLD | NEW |