Add js to output, if name is None or optional name is not already in self._jsNames. Otherwise skip export, to avoid JS chunks to double in the output. This is used to avoid doubling JS chunks if multiple elements of the same type are in one page.
(self, js, name=None)
| 358 | self._jsNames = set() # Keep optional js chunck names, so avoid double output. |
| 359 | |
| 360 | def addJs(self, js, name=None): |
| 361 | """Add js to output, if name is None or optional name is not already in self._jsNames. |
| 362 | Otherwise skip export, to avoid JS chunks to double in the output. This is used |
| 363 | to avoid doubling JS chunks if multiple elements of the same type are in one page.""" |
| 364 | assert isinstance(js, str), ('Added Javascript should be of type str "%s"' % js) |
| 365 | if name is None or not name in self._jsNames: |
| 366 | self._jsOut.append(js) |
| 367 | if name is not None: |
| 368 | self._jsNames.add(name) |
| 369 | |
| 370 | def hasJs(self): |
| 371 | return len(self._jsOut) |
no test coverage detected