void WImage::updateDom(DomElement& element, bool all) { DomElement *img = &element; if (all && element.type() == DomElement_SPAN) { DomElement *map = map_->createSDomElement(WApplication::instance()); element.addChild(map); img = DomElement::createNew(DomElement_IMG); img->setId("i" + id()); } if (flags_.test(BIT_IMAGE_LINK_CHANGED) || all) { if (!imageLink_.isNull()) { std::string url = resolveRelativeUrl(imageLink_.url()); WApplication *app = WApplication::instance(); url = app->encodeUntrustedUrl(url); img->setProperty(Wt::PropertySrc, url); } else img->setProperty(Wt::PropertySrc, "#"); flags_.reset(BIT_IMAGE_LINK_CHANGED); } if (flags_.test(BIT_ALT_TEXT_CHANGED) || all) { img->setAttribute("alt", altText_.toUTF8()); flags_.reset(BIT_ALT_TEXT_CHANGED); } if (flags_.test(BIT_MAP_CREATED) || (all && map_)) { img->setAttribute("usemap", '#' + map_->id()); flags_.reset(BIT_MAP_CREATED); } WInteractWidget::updateDom(*img, all); if (&element != img) element.addChild(img); }
void WAnchor::updateDom(DomElement& element, bool all) { if (element.type() != DomElement_A) { WContainerWidget::updateDom(element, all); return; } if (flags_.test(BIT_CHANGE_TAG)) { if (!all) element.callJavaScript(WT_CLASS ".changeTag(" + jsRef() + ",'a');"); flags_.reset(BIT_CHANGE_TAG); } bool needsUrlResolution = false; if (flags_.test(BIT_LINK_CHANGED) || all) { WApplication *app = WApplication::instance(); std::string url = link_.resolveUrl(app); /* * From 但浩亮: setRefInternalPath() and setTarget(TargetNewWindow) * does not work without the check below: */ if (target_ == TargetSelf) changeInternalPathJS_ = link_.manageInternalPathChange(app, this, changeInternalPathJS_); else { delete changeInternalPathJS_; changeInternalPathJS_ = 0; } url = app->encodeUntrustedUrl(url); std::string href = resolveRelativeUrl(url); element.setAttribute("href", href); needsUrlResolution = !app->environment().hashInternalPaths() && href.find("://") == std::string::npos && href[0] != '/'; flags_.reset(BIT_LINK_CHANGED); } if (flags_.test(BIT_TARGET_CHANGED) || all) { switch (target_) { case TargetSelf: if (!all) element.setProperty(PropertyTarget, "_self"); break; case TargetThisWindow: element.setProperty(PropertyTarget, "_top"); break; case TargetNewWindow: element.setProperty(PropertyTarget, "_blank"); } flags_.reset(BIT_TARGET_CHANGED); } WContainerWidget::updateDom(element, all); if (needsUrlResolution) { if (all) element.setProperty(PropertyClass, Utils::addWord(styleClass().toUTF8(), "Wt-rr")); else element.callJavaScript("$('#" + id() + "').addClass('Wt-rr');"); } }