First wait till some elements are loaded, then initialize and open dynamically added popup.
<br> See <a href="http://demos.jquerymobile.com/1.4.5/popup-dynamic/#&ui-state=dialog&ui-state=dialog&ui-state=dialog">Dynamic popup with images</a>
7496
public void waitInitOpen(String waitForSelector) {
        if (waitForSelector == null || waitForSelector.isEmpty()) {
            initDynamic();
            open();
            return;
        }
        waitInitOpen(waitForSelector, getElement());
    }
757121
function tabView_open() {
    var menuitem = new elementslib.Elem(this._controller.menus['view-menu'].menu_tabview);
    this._controller.click(menuitem);
    this.waitForOpened();

    this._tabView = this.getElement({type: "tabView"});
    this._tabViewDoc = this._tabView.getNode().webNavigation.document;
  }
258348
function(data) {

		var i;

		if(data.isObj === false) { 
			// convert jQuery collection to array to avoid conflicts later
			mfp.items = data.items.toArray();

			mfp.index = 0;
			var items = data.items,
				item;
			for(i = 0; i < items.length; i++) {
				item = items[i];
				if(item.parsed) {
					item = item.el[0];
				}
				if(item === data.el[0]) {
					mfp.index = i;
					break;
				}
			}
		} else {
			mfp.items = $.isArray(data.items) ? data.items : [data.items];
			mfp.index = data.index || 0;
		}

		// if popup is already opened - we just update the content
		if(mfp.isOpen) {
			mfp.updateItemHTML();
			return;
		}
		
		mfp.types = []; 
		_wrapClasses = '';
		if(data.mainEl && data.mainEl.length) {
			mfp.ev = data.mainEl.eq(0);
		} else {
			mfp.ev = _document;
		}

		if(data.key) {
			if(!mfp.popupsCache[data.key]) {
				mfp.popupsCache[data.key] = {};
			}
			mfp.currTemplate = mfp.popupsCache[data.key];
		} else {
			mfp.currTemplate = {};
		}



		mfp.st = $.extend(true, {}, $.magnificPopup.defaults, data ); 
		mfp.fixedContentPos = mfp.st.fixedContentPos === 'auto' ? !mfp.probablyMobile : mfp.st.fixedContentPos;

		if(mfp.st.modal) {
			mfp.st.closeOnContentClick = false;
			mfp.st.closeOnBgClick = false;
			mfp.st.showCloseBtn = false;
			mfp.st.enableEscapeKey = false;
		}
		

		// Building markup
		// main containers are created only once
		if(!mfp.bgOverlay) {

			// Dark overlay
			mfp.bgOverlay = _getEl('bg').on('click'+EVENT_NS, function() {
				mfp.close();
			});

			mfp.wrap = _getEl('wrap').attr('tabindex', -1).on('click'+EVENT_NS, function(e) {
				if(mfp._checkIfClose(e.target)) {
					mfp.close();
				}
			});

			mfp.container = _getEl('container', mfp.wrap);
		}

		mfp.contentContainer = _getEl('content');
		if(mfp.st.preloader) {
			mfp.preloader = _getEl('preloader', mfp.container, mfp.st.tLoading);
		}


		// Initializing modules
		var modules = $.magnificPopup.modules;
		for(i = 0; i < modules.length; i++) {
			var n = modules[i];
			n = n.charAt(0).toUpperCase() + n.slice(1);
			mfp['init'+n].call(mfp);
		}
		_mfpTrigger('BeforeOpen');


		if(mfp.st.showCloseBtn) {
			// Close button
			if(!mfp.st.closeBtnInside) {
				mfp.wrap.append( _getCloseBtn() );
			} else {
				_mfpOn(MARKUP_PARSE_EVENT, function(e, template, values, item) {
					values.close_replaceWith = _getCloseBtn(item.type);
				});
				_wrapClasses += ' mfp-close-btn-in';
			}
		}

		if(mfp.st.alignTop) {
			_wrapClasses += ' mfp-align-top';
		}

	

		if(mfp.fixedContentPos) {
			mfp.wrap.css({
				overflow: mfp.st.overflowY,
				overflowX: 'hidden',
				overflowY: mfp.st.overflowY
			});
		} else {
			mfp.wrap.css({ 
				top: _window.scrollTop(),
				position: 'absolute'
			});
		}
		if( mfp.st.fixedBgPos === false || (mfp.st.fixedBgPos === 'auto' && !mfp.fixedContentPos) ) {
			mfp.bgOverlay.css({
				height: _document.height(),
				position: 'absolute'
			});
		}

		

		if(mfp.st.enableEscapeKey) {
			// Close on ESC key
			_document.on('keyup' + EVENT_NS, function(e) {
				if(e.keyCode === 27) {
					mfp.close();
				}
			});
		}

		_window.on('resize' + EVENT_NS, function() {
			mfp.updateSize();
		});


		if(!mfp.st.closeOnContentClick) {
			_wrapClasses += ' mfp-auto-cursor';
		}
		
		if(_wrapClasses)
			mfp.wrap.addClass(_wrapClasses);


		// this triggers recalculation of layout, so we get it once to not to trigger twice
		var windowHeight = mfp.wH = _window.height();

		
		var windowStyles = {};

		if( mfp.fixedContentPos ) {
            if(mfp._hasScrollBar(windowHeight)){
                var s = mfp._getScrollbarSize();
                if(s) {
                    windowStyles.marginRight = s;
                }
            }
        }

		if(mfp.fixedContentPos) {
			if(!mfp.isIE7) {
				windowStyles.overflow = 'hidden';
			} else {
				// ie7 double-scroll bug
				$('body, html').css('overflow', 'hidden');
			}
		}

		
		
		var classesToadd = mfp.st.mainClass;
		if(mfp.isIE7) {
			classesToadd += ' mfp-ie7';
		}
		if(classesToadd) {
			mfp._addClassToMFP( classesToadd );
		}

		// add content
		mfp.updateItemHTML();

		_mfpTrigger('BuildControls');

		// remove scrollbar, add margin e.t.c
		$('html').css(windowStyles);
		
		// add everything to DOM
		mfp.bgOverlay.add(mfp.wrap).prependTo( mfp.st.prependTo || $(document.body) );

		// Save last focused element
		mfp._lastFocusedEl = document.activeElement;
		
		// Wait for next cycle to allow CSS transition
		setTimeout(function() {
			
			if(mfp.content) {
				mfp._addClassToMFP(READY_CLASS);
				mfp._setFocus();
			} else {
				// if content is not defined (not loaded e.t.c) we add class only for BG
				mfp.bgOverlay.addClass(READY_CLASS);
			}
			
			// Trap the focus in popup
			_document.on('focusin' + EVENT_NS, mfp._onFocusIn);

		}, 16);

		mfp.isOpen = true;
		mfp.updateSize(windowHeight);
		_mfpTrigger(OPEN_EVENT);

		return data;
	}
302650
function(view, config, widget) {

		this.Element$init(view, config, widget);

		var self = this;

		this._IE_click_callback = function() {
			if (self._events['compatible_changed']) {
				Lava.view_manager.dispatchEvent(self._view, 'compatible_changed', null, self._events['compatible_changed']);
			}
		};

	}
706747
public void openPopup() {
        // If the component is disabled, do nothing.
        if (!isEnabled()) {
            return;
        }
        // If the show popup menu button is not shown, do nothing.
        if (settings.getDisplayToggleTimeMenuButton() == false) {
            return;
        }
        // If this function was called programmatically, we may need to change the focus to this
        // popup.
        if (!timeTextField.hasFocus()) {
            timeTextField.requestFocusInWindow();
        }
        // Create a new time menu.
        timeMenuPanel = new TimeMenuPanel(this, settings);

        // Create a new custom popup.
        popup = new CustomPopup(timeMenuPanel, SwingUtilities.getWindowAncestor(this),
                this, settings.borderTimePopup);
        popup.setMinimumSize(new Dimension(
                this.getSize().width + 1, timeMenuPanel.getSize().height));
        // Calculate the default origin for the popup.
        int defaultX = timeTextField.getLocationOnScreen().x;
        int defaultY = timeTextField.getLocationOnScreen().y + timeTextField.getSize().height - 1;
        // Set the popup location. (Shared function.)
        DatePicker.zSetPopupLocation(popup, defaultX, defaultY, this, timeTextField, -1, 1);
        // Show the popup and request focus.
        popup.show();
        timeMenuPanel.requestListFocus();
    }
884642
function(apps) {
			jQuery.each(apps, function(i, a) {
				if (_isPlaceholderElement(appConfigs[i].root)) {
					jQuery(appConfigs[i].root)
						.addClass(F2.Constants.Css.APP)
						.append(jQuery(a.html).addClass(F2.Constants.Css.APP_CONTAINER + ' ' + appConfigs[i].appId));
				}
				else if (!_bUsesAppHandlers) {
					// load html and save the root node
					appConfigs[i].root = _afterAppRender(appConfigs[i], _appRender(appConfigs[i], a.html));
				}
				else {
					F2.AppHandlers.__trigger(
						_sAppHandlerToken,
						F2.Constants.AppHandlers.APP_RENDER,
						appConfigs[i], // the app config
						_outerHtml(jQuery(a.html).addClass(F2.Constants.Css.APP_CONTAINER + ' ' + appConfigs[i].appId))
					);

					var appId = appConfigs[i].appId,
						root = appConfigs[i].root;

					if (!root) {
						throw ('Root for ' + appId + ' must be a native DOM element and cannot be null or undefined. Check your AppHandler callbacks to ensure you have set App root to a native DOM element.');
					}

					if (!elementInDocument(root)) {
						throw ('App root for ' + appId + ' was not appended to the DOM. Check your AppHandler callbacks to ensure you have rendered the app root to the DOM.');
					}

					F2.AppHandlers.__trigger(
						_sAppHandlerToken,
						F2.Constants.AppHandlers.APP_RENDER_AFTER,
						appConfigs[i] // the app config
					);

					if (!F2.isNativeDOMNode(root)) {
						throw ('App root for ' + appId + ' must be a native DOM element. Check your AppHandler callbacks to ensure you have set app root to a native DOM element.');
					}
				}

				// init events
				_initAppEvents(appConfigs[i]);
			});
		}
502019
function ()
    {
      // Add key events
      jQuery(document).on('keyup.jBox-Image-' + this.id, function (ev) {
        (ev.keyCode == 37) && this.showImage('prev');
        (ev.keyCode == 39) && this.showImage('next');
      }.bind(this));

      // Load the image from the attached element
      this.showImage('open');
    }
1370287
function WebuiPopover(element, options) {
            this.$element = $(element);
            if (options) {
                if ($.type(options.delay) === 'string' || $.type(options.delay) === 'number') {
                    options.delay = {
                        show: options.delay,
                        hide: options.delay
                    }; // bc break fix
                }
            }
            this.options = $.extend({}, defaults, options);
            this._defaults = defaults;
            this._name = pluginName;
            this._targetclick = false;
            this.init();
            _srcElements.push(this.$element);
            return this;

        }
877163
function () {
            var _safeHandleWindowResize = function ( /* theEvent */) {
                if (this._isOpen && this._ignoreResizeTo === 0) {
                    if ((this._expectResizeEvent() || this._orientationchangeInProgress) &&
                        !this._ui.container.hasClass("ui-popup-hidden")) {
                        // effectively rapid-close the popup while leaving the screen intact
                        //judge user is in input mode or not.
                        if (!($(":focus").is("input") || $(":focus").is("textarea"))) {
                            this._ui.container
                                .addClass("ui-popup-hidden ui-popup-truncate")
                                .removeAttr("style");
                        }
                    }
                }
            };
            var $mobile = $.mobile;
            if ($mobile.widgets && $mobile.widgets.popup) {
                $mobile.widgets.popup.prototype._handleWindowResize = _safeHandleWindowResize;
            }
        }
1354881
function bind(elements) {
      for (var i = 0; i < elements.length; i++) {
        Binder.on('click', elements[i], this.click);
        Binder.on('touchstart', elements[i], this.click, capture);
      }
    }
132322
function () {
                for (var i = this.openedPopups.length - 1; i >= 0; i--) {
                    var popup = this.openedPopups[i];
                    popup.updatePosition();
                }
            }
80156
public static void showPopup() {

        final CmsPopup popup = new CmsPopup(CmsAliasMessages.messageTitleImport());
        popup.setModal(true);
        popup.setGlassEnabled(true);
        CmsImportView importView = new CmsImportView();
        popup.setMainContent(importView);
        popup.setWidth(800);
        popup.addDialogClose(null);
        popup.centerHorizontally(100);
    }
415644
function initializeClickimages() {
    var elements = document.querySelectorAll('[data-pins]');
    for(var i = 0; i < elements.length; i++) {
        /*
        try/catch so it continues with the next element without breaking
        out of the loop, when any syntax error occurs.
        */
        try {
            clickimagePins(elements[i]);
        }
        catch(err) {
            console.error(err);
        }
    }
}
806733
function bindPopup (element, img) {
  // 图片点击时展现图片
  img.addEventListener('click', function (event) {
    event.stopPropagation()
    // 图片未加载则不弹层
    /* istanbul ignore if */
    if (img.width + img.naturalWidth === 0) {
      return
    }

    // Show page mask
    window.MIP.viewer.page.togglePageMask(true, {
      skipTransition: true,
      extraClass: 'black'
    })
    let popup = createPopup(element, img)
    let popupBg = popup.querySelector('.mip-img-popUp-bg')
    let mipCarousel = popup.querySelector('mip-carousel')
    let popupImg = new Image()
    popupImg.setAttribute('src', img.src)
    popup.appendChild(popupImg)

    let imgOffset = getImgOffset(img)

    popup.addEventListener('click', imagePop, false)

    function imagePop () {
      // Hide page mask
      window.MIP.viewer.page.togglePageMask(false, {
        skipTransition: true,
        extraClass: 'black'
      })

      let mipCarouselWrapper = popup.querySelector('.mip-carousel-wrapper')
      /* istanbul ignore if */
      if (mipCarouselWrapper == null) return

      // 找出当前视口下的图片
      let currentImg = getCurrentImg(mipCarouselWrapper, mipCarousel)
      popupImg.setAttribute('src', currentImg.getAttribute('data-src'))
      let previousPos = getImgOffset(img)
      // 获取弹出图片滑动的距离，根据前面的设定，top大于0就不是长图，小于0才是滑动的距离。
      let currentImgPos = getImgOffset(currentImg)
      currentImgPos.top < 0 && (previousPos.top -= currentImgPos.top)
      currentImgPos.left < 0 && (previousPos.left -= currentImgPos.left)
      css(popupImg, getPopupImgPos(popupImg.naturalWidth, popupImg.naturalHeight))
      css(popupImg, 'display', 'block')
      css(mipCarousel, 'display', 'none')
      naboo.animate(popupBg, {
        opacity: 0
      }).start()

      naboo.animate(popup, {'display': 'none'})
      naboo.animate(popupImg, previousPos).start(() => {
        css(img, 'visibility', 'visible')
        css(popup, 'display', 'none')
        popup.removeEventListener('click', imagePop, false)
        popup.remove()
      })
    }

    let onResize = function () {
      imgOffset = getImgOffset(img)
      css(popupImg, imgOffset)
      naboo.animate(popupImg, getPopupImgPos(img.naturalWidth, img.naturalHeight)).start()
    }
    window.addEventListener('resize', onResize)

    css(popupImg, imgOffset)
    css(mipCarousel, 'visibility', 'hidden')
    css(popupBg, 'opacity', 1)

    naboo.animate(popupImg, getPopupImgPos(img.naturalWidth, img.naturalHeight)).start(() => {
      css(popupImg, 'display', 'none')
      css(mipCarousel, 'visibility', 'visible')
    })
    css(img, 'visibility', 'hidden')
    css(img.parentNode, 'zIndex', 'inherit')
  }, false)
}
884877
function () {
            if (!this._popup || !this._popup.isOpen || this._draggable) {
                // maybe the popup was closed while loading aria.utils.dragdrop.Drag,
                // or it was closed and re-opened very quickly (and we should avoid
                // creating the _draggable object twice)
                return;
            }
            this._draggable = new aria.utils.dragdrop.Drag(this._domElt, {
                handle : this._titleBarDomElt,
                cursor : "move",
                proxy : this._cfg.movableProxy,
                constrainTo : this._popupContainer.getContainerRef(),
                dragOverIFrame : true
            });
            this._draggable.$on({
                "dragstart" : {
                    fn : this._onDragStart,
                    scope : this
                },
                "move" : {
                    fn : this._onDragMove,
                    scope : this
                },
                "dragend" : {
                    fn : this._onDragEnd,
                    scope : this
                }
            });
        }
767708
private void openNextElementView() {

        List<CmsElementViewInfo> views = getData().getElementViews();
        if (views.size() > 1) {
            CmsUUID current = m_elementView.getRootViewId();

            // look for the current view index
            int currentIndex = -1;
            for (int i = 0; i < views.size(); i++) {
                CmsElementViewInfo view = views.get(i);
                if (view.isRoot() && current.equals(view.getElementViewId())) {
                    currentIndex = i;
                    break;
                }
            }
            if (currentIndex != -1) {
                CmsElementViewInfo target = null;
                // look for the next root view
                for (int i = currentIndex + 1; i < views.size(); i++) {
                    CmsElementViewInfo view = views.get(i);
                    if (view.isRoot()) {
                        target = view;
                        break;
                    }
                }
                if (target == null) {
                    // start at the beginning
                    for (int i = 0; i < currentIndex; i++) {
                        CmsElementViewInfo view = views.get(i);
                        if (view.isRoot()) {
                            target = view;
                            break;
                        }
                    }
                }
                if (target != null) {
                    final String viewName = target.getTitle();
                    Runnable action = new Runnable() {

                        public void run() {

                            CmsNotification.get().send(
                                Type.NORMAL,
                                Messages.get().key(Messages.GUI_SWITCH_ELEMENT_VIEW_NOTIFICATION_1, viewName));
                        }
                    };
                    setElementView(target, action);
                }
            }
        }
    }
886911
function () {
            this.$Element.initWidget.call(this);
            this._classList = new ariaUtilsClassList(this._domElt);
            var classType = (this._isLink) ? this.LINK_CLASS : this.BUTTON_CLASS;
            this._classList.add(classType);
        }