-
-
Save RockinRoel/40ba4fdf96f1318c0b022053cfc1d0da to your computer and use it in GitHub Desktop.
Remove WFormWidget's JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Wt/WFormWidget.C b/src/Wt/WFormWidget.C | |
index 54fd1e583..16a3ed58f 100644 | |
--- a/src/Wt/WFormWidget.C | |
+++ b/src/Wt/WFormWidget.C | |
@@ -13,10 +13,6 @@ | |
#include "DomElement.h" | |
#include "WebUtils.h" | |
-#ifndef WT_DEBUG_JS | |
-#include "js/WFormWidget.min.js" | |
-#endif | |
- | |
namespace Wt { | |
const char *WFormWidget::CHANGE_SIGNAL = "M_change"; | |
@@ -81,69 +77,14 @@ bool WFormWidget::isReadOnly() const | |
void WFormWidget::setPlaceholderText(const WString& placeholderText) | |
{ | |
- emptyText_ = placeholderText; | |
- | |
- WApplication* app = WApplication::instance(); | |
- const WEnvironment& env = app->environment(); | |
- if (!env.agentIsIElt(10) && | |
- (domElementType() == DomElementType::INPUT || domElementType() == DomElementType::TEXTAREA)) { | |
- flags_.set(BIT_PLACEHOLDER_CHANGED); | |
- repaint(); | |
- } else { | |
- if (env.ajax()) { | |
- if (!emptyText_.empty()) { | |
- if (!flags_.test(BIT_JS_OBJECT)) | |
- defineJavaScript(); | |
- else | |
- updateEmptyText(); | |
- | |
- if (!removeEmptyText_) { | |
- removeEmptyText_.reset(new JSlot(this)); | |
- | |
- focussed().connect(*removeEmptyText_); | |
- blurred().connect(*removeEmptyText_); | |
- keyWentDown().connect(*removeEmptyText_); | |
- | |
- std::string jsFunction = | |
- "function(obj, event) {" | |
- """" + jsRef() + ".wtObj.applyEmptyText();" | |
- "}"; | |
- removeEmptyText_->setJavaScript(jsFunction); | |
- } | |
- } else { | |
- removeEmptyText_.reset(); | |
- } | |
- } else { | |
- setToolTip(placeholderText); | |
- } | |
- } | |
-} | |
- | |
-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); | |
- | |
- setJavaScriptMember(" WFormWidget", "new " WT_CLASS ".WFormWidget(" | |
- + app->javaScriptClass() + "," | |
- + jsRef() + "," | |
- + emptyText_.jsStringLiteral() + ");"); | |
- } | |
+ placeholderText_ = placeholderText; | |
+ flags_.set(BIT_PLACEHOLDER_CHANGED); | |
+ repaint(); | |
} | |
void WFormWidget::render(WFlags<RenderFlag> flags) | |
{ | |
if (flags.test(RenderFlag::Full)) { | |
- if (flags_.test(BIT_JS_OBJECT)) | |
- defineJavaScript(true); | |
- | |
if (validator()) { | |
WValidator::Result result = validator()->validate(valueText()); | |
WApplication::instance()->theme() | |
@@ -155,39 +96,14 @@ void WFormWidget::render(WFlags<RenderFlag> flags) | |
WInteractWidget::render(flags); | |
} | |
-void WFormWidget::updateEmptyText() | |
-{ | |
- WApplication *app = WApplication::instance(); | |
- const WEnvironment &env = app->environment(); | |
- if (env.agentIsIElt(10) && isRendered()) | |
- doJavaScript(jsRef() + ".wtObj" | |
- ".setEmptyText(" + emptyText_.jsStringLiteral() + ");"); | |
-} | |
- | |
-void WFormWidget::applyEmptyText() | |
-{ | |
- WApplication *app = WApplication::instance(); | |
- const WEnvironment &env = app->environment(); | |
- if (env.agentIsIElt(10) && isRendered() && !emptyText_.empty()) | |
- doJavaScript(jsRef() + ".wtObj.applyEmptyText();"); | |
-} | |
- | |
void WFormWidget::refresh() | |
{ | |
- if (emptyText_.refresh()) | |
- updateEmptyText(); | |
- | |
- WInteractWidget::refresh(); | |
-} | |
- | |
-void WFormWidget::enableAjax() | |
-{ | |
- if (!emptyText_.empty() && toolTip() == emptyText_) { | |
- setToolTip(""); | |
- setPlaceholderText(emptyText_); | |
+ if (placeholderText_.refresh()) { | |
+ flags_.set(BIT_PLACEHOLDER_CHANGED); | |
+ repaint(); | |
} | |
- WInteractWidget::enableAjax(); | |
+ WInteractWidget::refresh(); | |
} | |
void WFormWidget::validatorChanged() | |
@@ -249,13 +165,6 @@ void WFormWidget::updateDom(DomElement& element, bool all) | |
if (!all || !isEnabled()) | |
element.setProperty(Wt::Property::Disabled, | |
isEnabled() ? "false" : "true"); | |
- | |
- if (!all && isEnabled() && env.agentIsIE()) { | |
- /* | |
- * FIXME: implement a workaround for IE, reenabling a checkbox makes | |
- * the input box loose interactivity. | |
- */ | |
- } | |
flags_.reset(BIT_ENABLED_CHANGED); | |
} | |
@@ -267,8 +176,8 @@ void WFormWidget::updateDom(DomElement& element, bool all) | |
} | |
if (flags_.test(BIT_PLACEHOLDER_CHANGED) || all) { | |
- if (!all || !emptyText_.empty()) | |
- element.setProperty(Wt::Property::Placeholder, emptyText_.toUTF8()); | |
+ if (!all || !placeholderText_.empty()) | |
+ element.setProperty(Wt::Property::Placeholder, placeholderText_.toUTF8()); | |
flags_.reset(BIT_PLACEHOLDER_CHANGED); | |
} | |
diff --git a/src/Wt/WFormWidget.h b/src/Wt/WFormWidget.h | |
index 7f7b03ecb..2ed244443 100644 | |
--- a/src/Wt/WFormWidget.h | |
+++ b/src/Wt/WFormWidget.h | |
@@ -126,7 +126,7 @@ public: | |
* | |
* \sa setPlaceholderText() | |
*/ | |
- const WString& placeholderText() const { return emptyText_; } | |
+ const WString& placeholderText() const { return placeholderText_; } | |
/*! \brief %Signal emitted when the value was changed. | |
* | |
@@ -154,16 +154,12 @@ public: | |
protected: | |
WLabel *label_; | |
std::shared_ptr<WValidator> validator_; | |
- std::unique_ptr<JSlot> validateJs_, filterInput_, removeEmptyText_; | |
- WString emptyText_; | |
+ std::unique_ptr<JSlot> validateJs_, filterInput_; | |
+ WString placeholderText_; | |
// also used in WAbstractToggleButton | |
static const char *CHANGE_SIGNAL; | |
- void applyEmptyText(); | |
- | |
- virtual void enableAjax() override; | |
- | |
/*! \internal | |
* \brief Called whenever the validator is changed | |
* | |
@@ -181,19 +177,15 @@ private: | |
static const int BIT_ENABLED_CHANGED = 0; | |
static const int BIT_READONLY = 1; | |
static const int BIT_READONLY_CHANGED = 2; | |
- static const int BIT_JS_OBJECT = 3; | |
- static const int BIT_VALIDATION_CHANGED = 4; | |
- static const int BIT_PLACEHOLDER_CHANGED = 5; | |
+ static const int BIT_VALIDATION_CHANGED = 3; | |
+ static const int BIT_PLACEHOLDER_CHANGED = 4; | |
- std::bitset<6> flags_; | |
+ std::bitset<5> flags_; | |
Signal<WValidator::Result> validated_; | |
WString validationToolTip_; | |
void setLabel(WLabel *label); | |
- void defineJavaScript(bool force = false); | |
- void updateEmptyText(); | |
- | |
protected: | |
virtual void updateDom(DomElement& element, bool all) override; | |
virtual void propagateRenderOk(bool deep) override; | |
diff --git a/src/Wt/WLineEdit.C b/src/Wt/WLineEdit.C | |
index ed71c1d08..03fb2c0e7 100644 | |
--- a/src/Wt/WLineEdit.C | |
+++ b/src/Wt/WLineEdit.C | |
@@ -70,8 +70,6 @@ void WLineEdit::setText(const WT_USTRING& text) | |
repaint(); | |
validate(); | |
- | |
- applyEmptyText(); | |
} | |
} | |
diff --git a/src/Wt/WTextArea.C b/src/Wt/WTextArea.C | |
index f31ac1e01..43427ec79 100644 | |
--- a/src/Wt/WTextArea.C | |
+++ b/src/Wt/WTextArea.C | |
@@ -43,8 +43,6 @@ void WTextArea::setText(const WT_USTRING& text) | |
repaint(); | |
validate(); | |
- | |
- applyEmptyText(); | |
} | |
void WTextArea::setColumns(int columns) | |
diff --git a/src/js/WFormWidget.js b/src/js/WFormWidget.js | |
deleted file mode 100644 | |
index 33d909d1a..000000000 | |
--- a/src/js/WFormWidget.js | |
+++ /dev/null | |
@@ -1,50 +0,0 @@ | |
-/* | |
- * Copyright (C) 2010 Emweb bv, Herent, Belgium. | |
- * | |
- * See the LICENSE file for terms of use. | |
- */ | |
- | |
-/* Note: this is at the same time valid JavaScript and C++. */ | |
- | |
-WT_DECLARE_WT_MEMBER(1, JavaScriptConstructor, "WFormWidget", function(APP, el, emptyText) { | |
- el.wtObj = this; | |
- | |
- const WT = APP.WT, emptyTextStyle = "Wt-edit-emptyText"; | |
- | |
- this.applyEmptyText = function() { | |
- if (WT.hasFocus(el)) { | |
- if (el.classList.contains(emptyTextStyle)) { | |
- if (!WT.isIE && el.oldtype) { | |
- el.type = el.oldtype; | |
- } | |
- el.classList.remove(emptyTextStyle); | |
- el.value = ""; | |
- } | |
- } else { | |
- if (el.value === "") { | |
- if (el.type === "password") { | |
- if (!WT.isIE) { | |
- el.oldtype = "password"; | |
- el.type = "text"; | |
- } else { | |
- return; | |
- } | |
- } | |
- el.classList.add(emptyTextStyle); | |
- el.value = emptyText; | |
- } else { | |
- el.classList.remove(emptyTextStyle); | |
- } | |
- } | |
- }; | |
- | |
- this.setEmptyText = function(newEmptyText) { | |
- emptyText = newEmptyText; | |
- | |
- if (el.classList.contains(emptyTextStyle)) { | |
- el.value = emptyText; | |
- } | |
- }; | |
- | |
- this.applyEmptyText(); | |
-}); | |
diff --git a/src/js/WFormWidget.min.js b/src/js/WFormWidget.min.js | |
deleted file mode 100644 | |
index 2c88a297d..000000000 | |
--- a/src/js/WFormWidget.min.js | |
+++ /dev/null | |
@@ -1 +0,0 @@ | |
-WT_DECLARE_WT_MEMBER(1,JavaScriptConstructor,"WFormWidget",(function(t,s,e){s.wtObj=this;const i=t.WT,a="Wt-edit-emptyText";this.applyEmptyText=function(){if(i.hasFocus(s)){if(s.classList.contains(a)){!i.isIE&&s.oldtype&&(s.type=s.oldtype);s.classList.remove(a);s.value=""}}else if(""===s.value){if("password"===s.type){if(i.isIE)return;s.oldtype="password";s.type="text"}s.classList.add(a);s.value=e}else s.classList.remove(a)};this.setEmptyText=function(t){e=t;s.classList.contains(a)&&(s.value=e)};this.applyEmptyText()})); | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment