You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2013/08/13 11:33:48 UTC
svn commit: r1513406 -
/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-in.js
Author: lofwyr
Date: Tue Aug 13 09:33:47 2013
New Revision: 1513406
URL: http://svn.apache.org/r1513406
Log:
TOBAGO-1283: New attribute "placeholder" for input fields
Modified:
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-in.js
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-in.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-in.js?rev=1513406&r1=1513405&r2=1513406&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-in.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-in.js Tue Aug 13 09:33:47 2013
@@ -141,3 +141,51 @@ Tobago.In.prototype.leaveRequired = func
Tobago.registerListener(Tobago.In.init, Tobago.Phase.DOCUMENT_READY);
Tobago.registerListener(Tobago.In.init, Tobago.Phase.AFTER_UPDATE);
+
+// placeholder --------------------------------------------------------------------------------------------------------
+
+// adding placeholder to the feature detection
+jQuery.support.placeholder = (function(){
+ return 'placeholder' in document.createElement('input');
+})();
+
+Tobago.In.initPlaceholder = function(elements) {
+ if (!jQuery.support.placeholder) {
+ var fields = Tobago.Utils.selectWidthJQuery(elements, "[placeholder]");
+ fields.each(function () {
+ jQuery(this)
+ .on("focus", function () {
+ var input = jQuery(this);
+ var placeholder = input.next(".tobago-in-placeholder");
+ placeholder.hide();
+ })
+ .on("blur", function () {
+ var input = jQuery(this);
+ var placeholder = input.next(".tobago-in-placeholder");
+ if (placeholder.size() == 0) {
+ // lazy init, create a new one
+ placeholder = input.after("<span/>").next();
+ placeholder.addClass("tobago-in-placeholder");
+ placeholder.text(input.attr("placeholder")); // the text
+ placeholder.css(
+ {
+ left: input.css("left"),
+ top: input.css("top")
+ }
+ );
+ placeholder.on("click", function(event) {
+ jQuery(this).prev().focus();
+ });
+ }
+ if (input.val() == "") {
+ // xxx why this doesn't work?
+ // placeholder.show();
+ placeholder.css("display", "block");
+ }
+ }).trigger("blur"); // for initialization
+ });
+ }
+};
+
+Tobago.registerListener(Tobago.In.initPlaceholder, Tobago.Phase.DOCUMENT_READY);
+Tobago.registerListener(Tobago.In.initPlaceholder, Tobago.Phase.AFTER_UPDATE);