Exemplo n.º 1
0
void WPopupWidget::setHidden(bool hidden, const WAnimation& animation)
{
    if (WWebWidget::canOptimizeUpdates() && hidden == isHidden())
        return;

    WCompositeWidget::setHidden(hidden, animation);

    if (!hidden && anchorWidget_)
        positionAt(anchorWidget_, orientation_);

    if (hidden)
        this->hidden().emit();
    else
        this->shown().emit();

    if (!WWebWidget::canOptimizeUpdates() || isRendered()) {
        if (hidden)
            doJavaScript("var o = jQuery.data(" + jsRef() + ", 'popup');"
                         "if (o) o.hidden();");
        else
            doJavaScript("var o = jQuery.data(" + jsRef() + ", 'popup');"
                         "if (o) o.shown();");
    }

    if (!WWebWidget::canOptimizeUpdates() && hidden && deleteWhenHidden_)
        delete this;
}
Exemplo n.º 2
0
void WStackedWidget::setCurrentIndex(int index, const WAnimation& animation,
				     bool autoReverse)
{
  if (!animation.empty() && 
      WApplication::instance()->environment().supportsCss3Animations() &&
      ((isRendered() && javaScriptDefined_) || !canOptimizeUpdates())) {
    if (canOptimizeUpdates() && index == currentIndex_)
      return;

    loadAnimateJS();

    WWidget *previous = currentWidget();

    doJavaScript("$('#" + id() + "').data('obj').adjustScroll("
		 + widget(currentIndex_)->jsRef() + ");");
    setJavaScriptMember("wtAutoReverse", autoReverse ? "true" : "false");

    if (previous)
      previous->animateHide(animation);
    widget(index)->animateShow(animation);

    currentIndex_ = index;
  } else {
    currentIndex_ = index;

    for (int i = 0; i < count(); ++i)
      if (widget(i)->isHidden() != (currentIndex_ != i))
	widget(i)->setHidden(currentIndex_ != i);

    if (currentIndex_ >= 0 && isRendered() && javaScriptDefined_)
      doJavaScript("$('#" + id() + "').data('obj').setCurrent("
		   + widget(currentIndex_)->jsRef() + ");");
  }
}
Exemplo n.º 3
0
void WStackedWidget::setCurrentIndex(int index, const WAnimation& animation,
				     bool autoReverse)
{
  if (!animation.empty() && loadAnimateJS()
      && (isRendered() || !canOptimizeUpdates())) {
    if (canOptimizeUpdates() && index == currentIndex_)
      return;

    WWidget *previous = currentWidget();

    setJavaScriptMember("wtAutoReverse", autoReverse ? "true" : "false");

    if (previous)
      previous->animateHide(animation);
    widget(index)->animateShow(animation);

    currentIndex_ = index;
  } else {
    currentIndex_ = index;

    for (int i = 0; i < count(); ++i)
      if (widget(i)->isHidden() != (currentIndex_ != i))
	widget(i)->setHidden(currentIndex_ != i);

    if (isRendered())
      doJavaScript("$('#" + id() + "').data('obj').setCurrent("
		   + widget(currentIndex_)->jsRef() + ");");
  }
}
Exemplo n.º 4
0
void WPopupMenu::prepareRender(WApplication *app)
{
  if (app->environment().agentIsIE()) {
    doJavaScript(jsRef() + ".lastChild.style.width="
		 + jsRef() + ".lastChild.offsetWidth + 'px';");
  }

  // FIXME: we should really also prepareRender() of submenus when shown...

  if (!cancel_.isConnected()) {
    LOAD_JAVASCRIPT(app, "js/WPopupMenu.js", "WPopupMenu", wtjs1);

    std::vector<WPopupMenu *> subMenus;
    getSubMenus(subMenus);

    WStringStream s;

    s << "new " WT_CLASS ".WPopupMenu("
      << app->javaScriptClass() << ',' << jsRef() << ','
      << autoHideDelay_ << ",[";

    for (unsigned i = 0; i < subMenus.size(); ++i) {
      if (i != 0)
	s << ',';
      s << WWebWidget::jsStringLiteral(subMenus[i]->id());
    }

    s << "]);";

    setJavaScriptMember(" WPopupMenu", s.str());

    cancel_.connect(this, &WPopupMenu::done);
  }
}
Exemplo n.º 5
0
void WLineEdit::setInputMask(const WT_USTRING &mask,
			     WFlags<InputMaskFlag> flags)
{
  inputMaskFlags_ = flags;

  if (inputMask_ != mask) {
    inputMask_ = mask;
    mask_.clear();
    raw_.clear();
    case_.clear();
    spaceChar_ = ' ';
    WT_USTRING textBefore;
    if (!inputMask_.empty()) {
      textBefore = displayText();
      processInputMask();
      setText(textBefore);
    }

    if (isRendered() && javaScriptDefined_) {
      std::u32string space;
      space += spaceChar_;

      doJavaScript("jQuery.data(" + jsRef() + ", 'lobj')"
        ".setInputMask(" + WWebWidget::jsStringLiteral(mask_) + "," +
			   WWebWidget::jsStringLiteral(raw_) +  "," +
			   WWebWidget::jsStringLiteral(displayContent_) + "," +
			   WWebWidget::jsStringLiteral(case_) + "," +
			   WWebWidget::jsStringLiteral(space) + ", true);");
    } else if (!inputMask_.empty())
      repaint();
  }
}
Exemplo n.º 6
0
 void Popup::doDelayedJavaScript(const Wt::WString & jscode) {
   if (isRendered()) {
     doJavaScript(jscode.toUTF8());
   }
   else {
     additions_.push_back(jscode);
   }
 }
Exemplo n.º 7
0
void WPopupMenu::setHidden(bool hidden, const WAnimation& animation)
{
  WCompositeWidget::setHidden(hidden, animation);

  if (cancel_.isConnected() ||
      WApplication::instance()->session()->renderer().preLearning())
    doJavaScript("jQuery.data(" + jsRef() + ", 'obj').setHidden("
		 + (hidden ? "1" : "0") + ");");
}
Exemplo n.º 8
0
void WSuggestionPopup::doFilter(std::string input)
{
  filtering_ = true;
  filterModel_.emit(WT_USTRING::fromUTF8(input));
  filtering_ = false;

  doJavaScript("jQuery.data(" + jsRef() + ", 'obj').filtered("
	       + WWebWidget::jsStringLiteral(input) + ");");
}
Exemplo n.º 9
0
void Recaptcha::update_impl() {
    if (!implementation()) {
        setImplementation(new WContainerWidget());
    }
    get_impl()->clear();
    WText* title = new WText("reCAPTCHA", get_impl());
    title->addStyleClass("wc_recaptcha_title");
    if (js()) {
        WContainerWidget* image = new WContainerWidget(get_impl());
        image->setId("recaptcha_image");
        response_field_ = input_ ? input_ : new WLineEdit(get_impl());
        challenge_field_ = new WLineEdit(get_impl());
        // not challenge_field_->hide() to get its .text()
        doJavaScript("$(" + challenge_field_->jsRef() + ").hide();");
        response_field_->setId("recaptcha_response_field");
        doJavaScript("Recaptcha.create('" + public_key_  + "', '',"
                     "{theme: 'custom'});");
        if (buttons_enabled_) {
            add_buttons();
        }
        doJavaScript("clearTimeout($(" + jsRef() + ").data('timer'));");
        doJavaScript("$(" + jsRef() + ").data('timer',"
                     "setInterval(function() {"
                     "$(" + challenge_field_->jsRef() + ")"
                     ".val(Recaptcha.get_challenge());"
                     "}, 200));");
    } else {
        WTemplate* iframe = new WTemplate(get_impl());
        iframe->setTemplateText("<iframe src='https://www.google.com/recaptcha/"
                                "api/noscript?k=" + public_key_ +
                                "' height='300' width='500' frameborder='0'>"
                                "</iframe>", XHTMLUnsafeText);
        if (input_) {
            challenge_field_ = input_;
        } else {
            WTextArea* ta = new WTextArea(get_impl());
            ta->setColumns(40);
            ta->setRows(3);
            challenge_field_ = ta;
        }
        response_field_ = new WLineEdit("manual_challenge", get_impl());
        response_field_->hide();
    }
}
Exemplo n.º 10
0
void WAbstractSpinBox::refresh()
{
  doJavaScript
    ("jQuery.data(" + jsRef() + ", 'obj')"
     ".setLocale(" 
     + jsStringLiteral(WLocale::currentLocale().decimalPoint()) + ","
     + jsStringLiteral(WLocale::currentLocale().groupSeparator()) + ");");

  WLineEdit::refresh();
}
Exemplo n.º 11
0
void WPopupMenu::popup(WWidget *location, Orientation orientation)
{
  location_ = location;

  popupImpl();
  doJavaScript("jQuery.data(" + jsRef() + ", 'obj').popupAt("
	       + location->jsRef() + ");");

  positionAt(location, orientation);
}
Exemplo n.º 12
0
void WPopupWidget::setTransient(bool isTransient, int autoHideDelay)
{
    transient_ = isTransient;
    autoHideDelay_ = autoHideDelay;
    if (isRendered()) {
        WStringStream ss;
        ss << "jQuery.data(" << jsRef() << ", 'popup').setTransient("
           << transient_ << ',' << autoHideDelay_ << ");";
        doJavaScript(ss.str());
    }
}
Exemplo n.º 13
0
void WSuggestionPopup::setDefaultIndex(int row)
{
  if (defaultValue_ != row) {
    defaultValue_ = row;

    if (isRendered())
      doJavaScript("jQuery.data(" + jsRef() + ", 'obj').defaultValue = "
		   + boost::lexical_cast<std::string>(defaultValue_)
		   + ';');      
  }
}
Exemplo n.º 14
0
Arquivo: WImage.C Projeto: LifeGo/wt
void WImage::defineJavaScript()
{
  WApplication *app = WApplication::instance();

  LOAD_JAVASCRIPT(app, "js/WImage.js", "WImage", wtjs1);

  WStringStream ss;
  ss << "new " WT_CLASS ".WImage("
     << app->javaScriptClass() << "," << jsRef() << "," << targetJS_ << ");";
  doJavaScript(ss.str());
}
Exemplo n.º 15
0
void WTextEdit::updateDom(DomElement& element, bool all)
{
  WTextArea::updateDom(element, all);

  if (element.type() == DomElement_TEXTAREA)
    element.removeProperty(PropertyStyleDisplay);

  // we are creating the actual element
  if (all && element.type() == DomElement_TEXTAREA) {
    std::stringstream config;
    config << "{";

    bool first = true;

    for (SettingsMapType::const_iterator it = configurationSettings_.begin();
	 it != configurationSettings_.end(); ++it) {
      if (it->first == "plugins")
	continue;

      if (!first)
	config << ',';

      first = false;

      config << it->first << ": "
	     << Impl::asJSLiteral(it->second, XHTMLUnsafeText);
    }

    if (!first)
      config << ',';

    config << "plugins: '" << plugins() << "'";

    config <<
      ",init_instance_callback: obj.init"
      "}";

    DomElement dummy(DomElement::ModeUpdate, DomElement_TABLE);
    updateDom(dummy, true);

    doJavaScript("(function() { "
		 """var obj = $('#" + id() + "').data('obj');"
		 """obj.render(" + config.str() + ","
		 + jsStringLiteral(dummy.cssStyle())
		 + ");})();");

    contentChanged_ = false;
  }

  if (!all && contentChanged_) {
    element.callJavaScript(jsRef() + ".ed.load();");
    contentChanged_ = false;
  }
}
Exemplo n.º 16
0
void WMediaPlayer::play()
{
  if (isRendered()) {
    /*
     * play is being delayed so that other changes (e.g. addSource() are
     * reflected first, see #2819
     */
    doJavaScript("setTimeout(function(){" + jsPlayerRef() 
		 + ".jPlayer('play'); }, 0);");
  } else
    playerDo("play");
}
Exemplo n.º 17
0
void WPopupMenu::popup(const WPoint& p)
{
  popupImpl();

  // make sure we are not confused by client-side being positioned properly
  setOffsets(42, Left | Top);
  setOffsets(-10000, Left | Top);

  doJavaScript(WT_CLASS ".positionXY('" + id() + "',"
	       + boost::lexical_cast<std::string>(p.x()) + ","
	       + boost::lexical_cast<std::string>(p.y()) + ");");
}
Exemplo n.º 18
0
Arquivo: WWidget.C Projeto: DTidd/wt
void WWidget::positionAt(const WWidget *widget, Orientation orientation)
{
  if (isHidden())
    show();

  std::string side = (orientation == Horizontal ? ".Horizontal" : ".Vertical");

  doJavaScript(WT_CLASS ".positionAtWidget('"
	       + id() + "','"
	       + widget->id() + "',"
	       WT_CLASS + side + ");");
}
Exemplo n.º 19
0
void WSuggestionPopup::defineJavaScript()
{
  WApplication *app = WApplication::instance();

  const char *THIS_JS = "js/WSuggestionPopup.js";
  LOAD_JAVASCRIPT(app, THIS_JS, "WSuggestionPopup", wtjs1);
  LOAD_JAVASCRIPT(app, THIS_JS, "WSuggestionPopupStdMatcher", wtjs2);

  doJavaScript("new " WT_CLASS ".WSuggestionPopup("
	       + app->javaScriptClass() + "," + jsRef() + ","
	       + replacerJS_ + "," + matcherJS_ + ","
	       + boost::lexical_cast<std::string>(filterLength_) + ","
	       + boost::lexical_cast<std::string>(defaultValue_) + ","
	       + (global_ ? "true" : "false") + ");");
}
Exemplo n.º 20
0
void WPopupMenu::setHidden(bool hidden, const WAnimation& animation)
{
  if (!WApplication::instance()->session()->renderer().preLearning()
      && (animation.empty() && hidden == isHidden()))
    return;

  WCompositeWidget::setHidden(hidden, animation);

  if (autoHideDelay_ >= 0 && cancel_.isConnected())
    doJavaScript("jQuery.data(" + jsRef() + ", 'obj').setHidden("
		 + (hidden ? "1" : "0") + ");");

  if (hidden)
    renderOutAll();
}
Exemplo n.º 21
0
void WMediaPlayer::playerDoRaw(const std::string& jqueryMethod)
{
  WStringStream ss;

  if (isRendered())
    ss << jsPlayerRef();

  ss << jqueryMethod;

  if (isRendered())
    ss << ';';

  if (isRendered())
    doJavaScript(ss.str());
  else 
    initialJs_ += ss.str();
}
Exemplo n.º 22
0
void WFormWidget::defineJavaScript(bool force)
{
  if (force || !flags_.test(BIT_JS_OBJECT)) {
    flags_.set(BIT_JS_OBJECT);

    if (!isRendered())
      return;

    WApplication *app = WApplication::instance();

    LOAD_JAVASCRIPT(app, "js/WFormWidget.js", "WFormWidget", wtjs1);

    doJavaScript("new " WT_CLASS ".WFormWidget("
		 + app->javaScriptClass() + "," 
		 + jsRef() + ","
		 + emptyText_.jsStringLiteral() + ");");
  }
}
Exemplo n.º 23
0
void WDialog::setHidden(bool hidden, const WAnimation& animation)
{
  if (isHidden() != hidden) {
    if (modal_) {
      WApplication *app = WApplication::instance();
      WContainerWidget *cover = app->dialogCover();

      if (!cover)
	return; // when application is being destroyed

      if (!hidden) {
	saveCoverState(app, cover);

	if (cover->isHidden()) {
	  if (!animation.empty()) {
	    cover->animateShow(WAnimation(WAnimation::Fade, WAnimation::Linear,
					  animation.duration() * 4));
	  } else
	    cover->show();
	}

	cover->setZIndex(impl_->zIndex() - 1);
	app->pushExposedConstraint(this);

	// FIXME: this should only blur if the active element is outside
	// of the dialog
	doJavaScript
	  ("try {"
           """var ae=document.activeElement;"
           // On IE when a dialog is shown on startup, activeElement is the
           // body. Bluring the body sends the window to the background if
           // it is the only tab.
           // http://redmine.emweb.be/boards/2/topics/6415
	   """if (ae && ae.blur && ae.nodeName != 'BODY') {"
	   ""  "document.activeElement.blur();"
           "}"
	   "} catch (e) { }");
      } else
	restoreCoverState(app, cover);
    }
  }

  WPopupWidget::setHidden(hidden, animation);
}
Exemplo n.º 24
0
void WDialog::render(WFlags<RenderFlag> flags)
{
  if (flags & RenderFull) {
    WApplication *app = WApplication::instance();

    bool centerX = offset(Left).isAuto() && offset(Right).isAuto(),
      centerY = offset(Top).isAuto() && offset(Bottom).isAuto();

    /*
     * Make sure layout adjusts to contents preferred width, especially
     * important for IE workaround which uses static position scheme
     */
    if (app->environment().ajax())
      if (width().isAuto())
	if (maximumWidth().unit() == WLength::Percentage ||
	    maximumWidth().toPixels() == 0)
	  impl_->resolveWidget("layout")->setMaximumSize(999999, maximumHeight());

    doJavaScript("new " WT_CLASS ".WDialog("
		 + app->javaScriptClass() + "," + jsRef()
		 + "," + titleBar_->jsRef()
		 + "," + (centerX ? "1" : "0")
		 + "," + (centerY ? "1" : "0") + ");");

    /*
     * When a dialog is shown immediately for a new session, the recentering
     * logic comes too late and causes a glitch. Thus we include directly in
     * the HTML a JavaScript block to mitigate that
     */
    if (!app->environment().agentIsIElt(9)) {
      std::string js = WString::tr("Wt.WDialog.CenterJS").toUTF8();
      Utils::replace(js, "$el", "'" + id() + "'");
      Utils::replace(js, "$centerX", centerX ? "1" : "0");
      Utils::replace(js, "$centerY", centerY ? "1" : "0");

      impl_->bindString
	("center-script", "<script>" + js + "</script>", XHTMLUnsafeText);
    } else
      impl_->bindEmpty("center-script");
  }

  WCompositeWidget::render(flags);
}
Exemplo n.º 25
0
void WAbstractSpinBox::updateDom(DomElement& element, bool all)
{
  if (all || changed_) {
    if (!all) {
      if (!nativeControl())
	doJavaScript("jQuery.data(" + jsRef() + ", 'obj')"
		     ".update(" + jsMinMaxStep() + ","
		     + boost::lexical_cast<std::string>(decimals()) + ");");
      else
	setValidator(createValidator());
    }
  }

  changed_ = false;

  WLineEdit::updateDom(element, all);

  if (all && nativeControl())
    element.setAttribute("type", "number");
}
Exemplo n.º 26
0
void WSpinBox::updateDom(DomElement& element, bool all)
{
    if (all || changed_) {
        if (nativeControl()) {
            element.setAttribute("min", boost::lexical_cast<std::string>(min_));
            element.setAttribute("max", boost::lexical_cast<std::string>(max_));
            element.setAttribute("step", boost::lexical_cast<std::string>(step_));
        } else {
            /* Make sure the JavaScript validator is loaded */
            WIntValidator v;
            v.javaScriptValidate();

            doJavaScript("jQuery.data(" + jsRef() + ", 'obj')"
                         + ".setWrapAroundEnabled("
                         + (wrapAroundEnabled() ? "true" : "false") + ");");
        }
    }

    WAbstractSpinBox::updateDom(element, all);
}
Exemplo n.º 27
0
void WLineEdit::setText(const WT_USTRING& text)
{
  WT_USTRING newDisplayText = inputText(text);
  WT_USTRING newText = removeSpaces(newDisplayText);
  if (maskChanged_ || content_ != newText || 
      displayContent_ != newDisplayText) {
    content_ = newText;
    displayContent_ = newDisplayText;

    if (isRendered() && !inputMask_.empty()) {
      doJavaScript("jQuery.data(" + jsRef() + ", 'lobj')"
	 ".setValue(" + WWebWidget::jsStringLiteral(newDisplayText) + ");");
    }

    flags_.set(BIT_CONTENT_CHANGED);
    repaint();

    validate();

    applyEmptyText();
  }
}
Exemplo n.º 28
0
void WDialog::setHidden(bool hidden, const WAnimation& animation)
{
  if (isHidden() != hidden) {
    if (modal_) {
      WApplication *app = WApplication::instance();
      WContainerWidget *cover = app->dialogCover();

      if (!cover)
	return; // when application is being destroyed

      if (!hidden) {
	saveCoverState(app, cover);

	if (cover->isHidden()) {
	  if (!animation.empty()) {
	    cover->animateShow(WAnimation(WAnimation::Fade, WAnimation::Linear,
					  animation.duration() * 4));
	  } else
	    cover->show();
	}

	cover->setZIndex(impl_->zIndex() - 1);
	app->pushExposedConstraint(this);

	// FIXME: this should only blur if the active element is outside
	// of the dialog
	doJavaScript
	  ("try {"
	   """if (document.activeElement && document.activeElement.blur)"
	   ""  "document.activeElement.blur();"
	   "} catch (e) { }");
      } else
	restoreCoverState(app, cover);
    }
  }

  WCompositeWidget::setHidden(hidden, animation);
}
Exemplo n.º 29
0
void WAbstractSpinBox::updateDom(DomElement& element, bool all)
{
  if (all || changed_) {
    if (!all) {
      if (!nativeControl())
	doJavaScript("jQuery.data(" + jsRef() + ", 'obj')"
		     ".configure("
		     + std::to_string(decimals()) + ","
		     + prefix().jsStringLiteral() + ","
		     + suffix().jsStringLiteral() + ","
		     + jsMinMaxStep() + ");");
      else
	setValidator(std::shared_ptr<WValidator>(createValidator().release()));
    }
  }

  changed_ = false;

  WLineEdit::updateDom(element, all);

  if (all && nativeControl())
    element.setAttribute("type", "number");
}
Exemplo n.º 30
0
void WAbstractSpinBox::render(WFlags<RenderFlag> flags)
{
  /*
   * In theory we are a bit late here to decide what we want to become:
   * somebody could already have asked the domElementType()
   */
  if (!setup_ && flags & RenderFull) {
    setup();
  }

  if (jsValueChanged().needsUpdate(true)) {
    WStringStream function;
    function << "jQuery.data(" + jsRef() + ",'obj').jsValueChanged=";
    if (jsValueChanged().isConnected()) {
      function << "function(oldv, v){"
               << "var o=null;var e=null;" << jsValueChanged().createCall("oldv", "v") << "};";
    } else {
      function << "function() {};";
    }
    doJavaScript(function.str());
  }

  WLineEdit::render(flags);
}