Using the above suggestions, you could replace all of this with:
```
if (PDFView.isOverlayContainer) {
  ...
}
```