Sha256: 6000d6aa734582beebeaf116489bbea8348f224f7096fbe5a25e6fae864a5768

Contents?: true

Size: 1.97 KB

Versions: 21

Compression:

Stored size: 1.97 KB

Contents

(function() {
  var activate, onSlide, onStop, parse, template;

  template = function() {
    return $('<div></div>');
  };

  onStop = function(event, ui) {
    var cmsField, content;
    cmsField = $(this).data('cmsField');
    content = ui.value;
    return cmsField.scrivito('save', content).done(function() {
      cmsField.trigger('scrivito_editors:save');
      return cmsField.trigger('scrivito_editors:blur');
    });
  };

  onSlide = function(event, ui) {
    var cmsField, content;
    cmsField = $(this).data('cmsField');
    content = ui.value;
    return cmsField.text(ui.value);
  };

  parse = function(string, fallback) {
    var value;
    value = parseFloat(string);
    if (isNaN(value)) {
      return fallback;
    } else {
      return value;
    }
  };

  activate = function(element) {
    return $(element).on('click', function() {
      var cmsField, content, max, min, step;
      cmsField = $(element);
      if (cmsField.data('scrivito_editors_active')) {
        return;
      }
      cmsField.data('scrivito_editors_active', true);
      content = cmsField.scrivito('content');
      min = cmsField.data('scrivito-editors-min');
      max = cmsField.data('scrivito-editors-max');
      step = cmsField.data('scrivito-editors-step');
      return template().data('cmsField', cmsField).insertAfter(cmsField).slider({
        min: parse(min, 1),
        max: parse(max, 10),
        step: parse(step, 1),
        value: parse(content, 0),
        range: 'min',
        slide: onSlide,
        stop: onStop
      }).find('.ui-slider-handle').focus();
    });
  };

  scrivito.editors.slider_editor = {
    can_edit: function(element) {
      return $(element).is("[data-scrivito-field-type=float],\n[data-scrivito-field-type=integer],\n[data-scrivito-field-type=string]");
    },
    activate: function(element) {
      return activate(element);
    }
  };

  scrivito.on('load', function() {
    return scrivito.define_editor('slider', scrivito.editors.slider_editor);
  });

}).call(this);

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
scrivito_editors-1.6.0.rc1 app/assets/javascripts/scrivito_editors/slider_editor.js