Sha256: 0f04a63297eb65e0f8e46b0014a760cc97083043a3b94c0db26169a6809aa4c9

Contents?: true

Size: 1.45 KB

Versions: 61

Compression:

Stored size: 1.45 KB

Contents

Spotlight.onLoad(function() {
  $('[data-in-place-edit-target]').spotlightEditInPlace();
});
/*
  Simple plugin add edit-in-place behavior
*/
(function($) {
  $.fn.spotlightEditInPlace = function() {
    var clickElements = this;

    $(clickElements).each(function() {
      $(this).on('click.inplaceedit', function() {
        var $label = $(this).find($(this).data('in-place-edit-target'));
        var $input = $(this).find($(this).data('in-place-edit-field-target'));

        // hide the edit-in-place affordance icon while in edit mode
        $(this).addClass('hide-edit-icon');
        $label.hide();
        $input.val($label.text());
        $input.attr('type', 'text');
        $input.select();
        $input.focus();

        $input.on('keypress', function(e) {
          if(e.which == 13) {
            $input.trigger('blur.inplaceedit');
            return false;
          }
        });

        $input.on('blur.inplaceedit', function() {
          var value = $input.val();

          if ($.trim(value).length == 0) {
            $input.val($label.text());
          } else {
            $label.text(value);
          }

          $label.show();
          $input.attr('type', 'hidden');
          // when leaving edit mode, should no longer hide edit-in-place affordance icon
          $("[data-in-place-edit-target]").removeClass('hide-edit-icon');

          return false;
        });

        return false;
      });
    });

    return this;
  };
})(jQuery);

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
blacklight-spotlight-3.5.0.4 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.5.0.3 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.5.0.2 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.5.0.1 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.5.0 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.4.4.1 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.4.4 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.4.3 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.4.2.2 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.4.2.1 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.4.2 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.4.1 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.4.0 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.3.0 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.2.0 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.1.0 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.0.3 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.0.2 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.0.1 app/assets/javascripts/spotlight/admin/edit_in_place.js
blacklight-spotlight-3.0.0 app/assets/javascripts/spotlight/admin/edit_in_place.js