2 * Simulate HTML5 placeholder attribute
5 * - div[contentEditable] elements don't support it
6 * - older browsers (such as IE8 and Firefox 3.6) don't support it at all
8 * @param {Object} parent Instance of main wysihtml5.Editor class
9 * @param {Element} view Instance of wysihtml5.views.* class
10 * @param {String} placeholderText
13 * wysihtml.dom.simulatePlaceholder(this, composer, "Foobar");
16 dom.simulatePlaceholder = function(editor, view, placeholderText) {
17 var CLASS_NAME = "placeholder",
19 var composerIsVisible = view.element.offsetWidth > 0 && view.element.offsetHeight > 0;
20 if (view.hasPlaceholderSet()) {
23 if (composerIsVisible ) {
24 setTimeout(function() {
25 var sel = view.selection.getSelection();
26 if (!sel.focusNode || !sel.anchorNode) {
27 view.selection.selectNode(view.element.firstChild || view.element);
32 view.placeholderSet = false;
33 dom.removeClass(view.element, CLASS_NAME);
37 view.placeholderSet = true;
38 view.setValue(placeholderText);
39 dom.addClass(view.element, CLASS_NAME);
44 .on("set_placeholder", set)
45 .on("unset_placeholder", unset)
46 .on("focus:composer", unset)
47 .on("paste:composer", unset)
48 .on("blur:composer", set);