Sha256: a7cb04c5442cc7262221458aac9ad769f79321c6511151271fcc01f9bc5c8687

Contents?: true

Size: 1.4 KB

Versions: 9

Compression:

Stored size: 1.4 KB

Contents

// Default slice-preview helper. If attachments are present it will emit
// 'n item(s)', otherwise it will simply emit the content of any textarea
// or text input.
//
// This method has been kept purposefully simple to encourage custom
// preview helpers.
//
// Example:
//
//     slices.defaultSlicePreview.call($('.slice-content'))
//
slices.defaultSlicePreview = function() {
  if (this.find('.attachment-list').length) {
    var count = this.find('.attachment-list li').length;
    return count + (count === 1 ? ' item' : ' items');
  } else {
    var html = this.find('textarea, input[type="text"]')
    .map(function() { return $(this).val() })
    .get()
    .join(' ');

    return $('<div />').html(html).text();
  }
}

// Define custom previews for slices using this helper.
//
// In true jQuery style, the context of the method `this` is the slice-content
// element (in this case wrapped in a jQuery object).
//
// If the helper is empty, the default slice preview helper will be used.
//
// Example:
//
//     {{#slicePreview}}
//       return this.find('input').val().toUpperCase();
//     {{/slicePreview}}
//
Handlebars.registerHelper('slicePreview', function(options) {
  try {
    var proc = options.fn && options.fn();
    if (proc.match(/\S/)) window.customSlicePreview = new Function(proc);
  } catch(error) {
    console.error('This slicePreview caused an error:\n' + proc);
    console.error(error);
  }
});

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
slices-2.0.2 app/assets/javascripts/slices/app/helpers/slice_preview.js
slices-2.0.1 app/assets/javascripts/slices/app/helpers/slice_preview.js
slices-2.0.0 app/assets/javascripts/slices/app/helpers/slice_preview.js
slices-1.0.5 app/assets/javascripts/slices/app/helpers/slice_preview.js
slices-1.0.4 app/assets/javascripts/slices/app/helpers/slice_preview.js
slices-1.0.3 app/assets/javascripts/slices/app/helpers/slice_preview.js
slices-1.0.2 app/assets/javascripts/slices/app/helpers/slice_preview.js
slices-1.0.1 app/assets/javascripts/slices/app/helpers/slice_preview.js
slices-1.0.0 app/assets/javascripts/slices/app/helpers/slice_preview.js