Skip to content
Snippets Groups Projects
Commit b2e05c11 authored by pabois's avatar pabois
Browse files

fix + summernote paste

parent b11ead30
No related branches found
No related tags found
No related merge requests found
/*global define, module, require */
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = factory(require('jquery'));
} else {
// Browser globals
factory(window.jQuery);
}
}(function ($) {
'use strict';
$.extend($.summernote.options, {
stripTags: ['section', 'div', 'span', 'o', 'xml', 'font', 'style', 'embed', 'param', 'script', 'html', 'body', 'head', 'meta', 'title', 'link', 'iframe', 'abbr', 'acronym', 'address', 'applet', 'area', 'article', 'aside', 'audio', 'noframes', 'noscript', 'form', 'input', 'select', 'option', 'colgroup', 'col', 'std', 'xml:', 'st1:', 'o:', 'w:', 'v:'],
onCleanHtml: function (html) {
var htmlModified = html.replace(/<!\[if !supportLists[\s\S]*?endif\]>/g, '')
.replace(/<!--[\s\S]*?-->/g, '')
.replace(/( class=(")?Mso[a-zA-Z]+(")?)/g, ' ')
.replace(/[\t ]+</g, '<')
.replace(/>[\t ]+</g, '><')
.replace(/>[\t ]+$/g, '>')
.replace(/[\u2018\u2019\u201A]/g, '\'')
.replace(/[\u201C\u201D\u201E]/g, '"')
.replace(/\u2026/g, '...')
.replace(/[\u2013\u2014]/g, '-');
return htmlModified;
}
});
$.extend($.summernote.plugins, {
'striptags': function (context) {
var $note = context.layoutInfo.note,
$options = context.options;
$note.on('summernote.paste', function (e, evt) {
var text = evt.originalEvent.clipboardData.getData('text/plain'),
html = evt.originalEvent.clipboardData.getData('text/html'),
tagStripper = new RegExp('<[ /]*(' + $options.stripTags.join('|') + ')[^>]*>', 'gi'),
attributeStripper = /<(?!a)(\w+)[^>]*>/gi;
evt.preventDefault();
if (html) {
html = html.toString();
html = $options.onCleanHtml(html);
html = html.replace(attributeStripper, '<$1>');
html = html.replace(tagStripper, '');
document.execCommand('insertHTML', false, html);
} else {
document.execCommand('insertHTML', false, text);
}
return false;
});
}
});
}));
......@@ -44,20 +44,6 @@ $(function () {
if (e.keyCode === 8) {
$.summernote.rails.cleanEmptyAttachments($editable);
}
},
// Remove text styles on paste
onPaste: function (event) {
var paragraph;
event.preventDefault();
// Get and trim clipboard content as paragraph
paragraph = document.createElement('p');
paragraph.textContent = ((event.originalEvent || event).clipboardData || window.clipboardData).getData('Text').trim();
// Delete selection if anything is selected (expected behaviour on paste)
if ((window.getSelection !== undefined ? window.getSelection() : document.selection.createRange()).toString().length > 0) {
document.execCommand('delete', false);
}
// Insert trimmed clipboard content as paragraph
document.execCommand('insertHTML', false, paragraph.outerHTML);
}
}
});
......
<%
width, height = @blob.metadata.values_at('width', 'height')
width, height = @about.metadata.values_at('width', 'height')
ratio = width.present? && height.present? ? (width.to_f / height.to_f) : nil
university = University.find_by(id: @blob.university_id)
university = University.find_by(id: @about.university_id)
base_url = university&.url || ""
media_endpoint_path = medium_path(signed_id: @blob.signed_id, filename_with_transformations: @blob.filename)
media_endpoint_path = medium_path(signed_id: @about.signed_id, filename_with_transformations: @about.filename)
%>
<%# TODO: Replace @blob.url with the media endpoint when it's ready %>
<%# TODO: Replace @about.url with the media endpoint when it's ready %>
<%= raw({
"name" => @blob.filename.to_s,
"size" => @blob.byte_size,
"name" => @about.filename.to_s,
"size" => @about.byte_size,
"width" => width,
"height" => height,
"ratio" => ratio,
"url" => "#{base_url}#{media_endpoint_path}",
"direct_url" => @blob.url
"direct_url" => @about.url
}.compact.to_yaml) %>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment