'use strict'; (function () { /* * Display a placeholder for empty CMS attributes. The placeholder can be overwritten by * defining a +data-scrivito-editors-placeholder+ HTML attribute on the DOM element generated * by +scrivito_tag+. * * For example: * scrivito_tag(:div, @obj, :my_attribute, data: { scrivito_editors_placeholder: 'My text' }) */ scrivito.editors.applyPlaceholder = function ($cmsField) { if (!$cmsField.is('[data-scrivito-editors-placeholder]')) { var fieldName = $cmsField.attr('data-scrivito-field-name'); var defaultPlaceholder = 'Click to edit the “' + fieldName + '” attribute ...'; $cmsField.attr('data-scrivito-editors-placeholder', defaultPlaceholder); } applyBrowserWorkarounds($cmsField); }; // Chrome: fixes span element issue: sometimes the focus is set, but the element receives no input // Firefox: in combination with CSS, helps positioning the cursor at the correct position function applyBrowserWorkarounds($cmsField) { $cmsField.on('focus', function () { if ($cmsField.is(':empty')) { $cmsField.text('_'); window.getSelection().selectAllChildren($cmsField.get(0)); $cmsField.text(''); // needed for IE11: make cursor blink window.getSelection().collapseToStart($cmsField.get(0)); } }); } })();