From 3aff088287cbfe96e5ee25775d4d899449f1c148 Mon Sep 17 00:00:00 2001 From: Henri Bergius Date: Thu, 3 Nov 2011 17:07:26 +0200 Subject: [PATCH] Placeholder support, fixes #10 --- deps/hallo.js | 17 +++++++++++++++-- src/jquery.Midgard.midgardEditable.js | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/deps/hallo.js b/deps/hallo.js index f0a0438..b11ccce 100644 --- a/deps/hallo.js +++ b/deps/hallo.js @@ -18,7 +18,8 @@ activated: function() {}, deactivated: function() {}, selected: function() {}, - unselected: function() {} + unselected: function() {}, + placeholder: '' }, _create: function() { var options, plugin, _ref, _results; @@ -57,6 +58,9 @@ enable: function() { var widget; this.element.attr("contentEditable", true); + if (!this.element.html()) { + this.element.html(this.options.placeholder); + } if (!this.bound) { this.element.bind("focus", this, this._activated); this.element.bind("blur", this, this._deactivated); @@ -123,6 +127,9 @@ getContents: function() { return this.element.html(); }, + setContents: function(contents) { + return this.element.html(contents); + }, isModified: function() { return this.originalContent !== this.getContents(); }, @@ -257,7 +264,10 @@ _activated: function(event) { var widget; widget = event.data; - if (widget.toolbar.html() !== "") { + if (widget.getContents() === widget.options.placeholder) { + widget.setContents(''); + } + if (widget.toolbar.html() !== '') { widget.toolbar.css("top", widget.element.offset().top - widget.toolbar.height() + 10); } return widget._trigger("activated", event); @@ -265,6 +275,9 @@ _deactivated: function(event) { var widget; widget = event.data; + if (!widget.getContents()) { + widget.setContents(widget.options.placeholder); + } widget.toolbar.hide(); return widget._trigger("deactivated", event); } diff --git a/src/jquery.Midgard.midgardEditable.js b/src/jquery.Midgard.midgardEditable.js index 580946a..a5ff552 100644 --- a/src/jquery.Midgard.midgardEditable.js +++ b/src/jquery.Midgard.midgardEditable.js @@ -88,7 +88,8 @@ plugins: { halloformat: {} }, - editable: true + editable: true, + placeholder: '[' + propertyName + ']' }); var widget = this;