Sha256: 4ebdcc86ddb2ec7ff5328a5d518fe646c1c22d59bc7fade1383e5d971246f4c3

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

'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));
      }
    });
  }
})();

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scrivito_editors-1.16.0 app/assets/javascripts/scrivito_editors/placeholder.js
scrivito_editors-1.16.0.rc2 app/assets/javascripts/scrivito_editors/placeholder.js
scrivito_editors-1.16.0.rc1 app/assets/javascripts/scrivito_editors/placeholder.js
scrivito_editors-1.15.0 app/assets/javascripts/scrivito_editors/placeholder.js
scrivito_editors-1.15.0.rc2 app/assets/javascripts/scrivito_editors/placeholder.js
scrivito_editors-1.15.0.rc1 app/assets/javascripts/scrivito_editors/placeholder.js