Skip to content

Commit

Permalink
Rename PageFileLink -> FileLink
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Feb 28, 2018
1 parent 859ac99 commit 5a9814e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
#= require comfy/admin/cms/base
#= require comfy/admin/cms/uploader
#= require comfy/admin/cms/files
#= require comfy/admin/cms/page_file
#= require comfy/admin/cms/file_link
#= require comfy/admin/cms/custom
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
(() => {
const isFirefox = /\bFirefox\//.test(navigator.userAgent);

class PageFileLink {
class FileLink {
constructor(link) {
this.link = link;
this.isImage = !!link.dataset.cmsPageFileThumbUrl;
this.isImage = !!link.dataset.cmsFileThumbUrl;

link.addEventListener('dragstart', (evt) => {
evt.dataTransfer.setData('text/plain', this.link.dataset.cmsPageFileLinkTag);
evt.dataTransfer.setData('text/plain', this.link.dataset.cmsFileLinkTag);
});

if (this.isImage) {
new bootstrap.Popover(link, {
trigger: 'hover',
placement: 'top',
content: this.buildPageFileThumbnail(),
content: this.buildFileThumbnail(),
html: true
});

link.addEventListener('dragstart', (evt) => {
evt.dataTransfer.setDragImage(this.buildPageFileThumbnail(), 4, 2);
evt.dataTransfer.setDragImage(this.buildFileThumbnail(), 4, 2);
this.getPopover().hide();
});

this.workAroundFirefoxPopoverGlitch();
}
}

buildPageFileThumbnail() {
buildFileThumbnail() {
const img = new Image();
img.src = this.link.dataset.cmsPageFileThumbUrl;
img.src = this.link.dataset.cmsFileThumbUrl;
return img;
}

Expand Down Expand Up @@ -59,8 +59,8 @@
}

window.CMS.page_files = () => {
for (const link of document.querySelectorAll('[data-cms-page-file-link-tag]')) {
new PageFileLink(link);
for (const link of document.querySelectorAll('[data-cms-file-link-tag]')) {
new FileLink(link);
}
};
})();
11 changes: 5 additions & 6 deletions app/views/comfy/admin/cms/files/_file.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
%li{data: {id: file.id}}
- file_tag = "{{ cms:file_link #{file.id} }}"
:ruby
file_tag = "{{ cms:file_link #{file.id} }}"
thumb_url = url_for(file.attachment.variant(Comfy::Cms::File::VARIANT_SIZE[:thumb])) if file.attachment.image?
.row
.col-md-5.item
.item-controls.d-none.d-lg-block
Expand All @@ -8,11 +10,8 @@
%i.fas.fa-bars
.item-content
.item-title
- thumb_url = url_for(file.attachment.variant(Comfy::Cms::File::VARIANT_SIZE[:thumb])) if file.attachment.image?
= link_to file.attachment, target: "_blank",
data: {cms_page_file_thumb_url: thumb_url, cms_page_file_link_tag: file_tag} do
= file.label

= link_to file.label, file.attachment, target: "_blank",
data: {cms_file_thumb_url: thumb_url, cms_file_link_tag: file_tag}
.item-meta
.content-type
= truncate(file.attachment.content_type)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
.fragment-attachments
- attachments.each do |attachment|
:ruby
if attachment.image?
thumb_url = url_for(attachment.variant(Comfy::Cms::File::VARIANT_SIZE[:thumb]))
end
thumb_url = url_for(attachment.variant(Comfy::Cms::File::VARIANT_SIZE[:thumb])) if attachment.image?
filename = attachment.filename.to_s
truncated_filename = truncate(filename, length: 40, omission: "...#{filename.last(10)}")
link_data = {
cms_page_file_thumb_url: thumb_url,
cms_page_file_link_tag: cms_page_file_link_tag(
fragment_id: fragment_id, attachment: attachment, multiple: multiple),
cms_file_thumb_url: thumb_url,
cms_file_link_tag: cms_page_file_link_tag(fragment_id: fragment_id, attachment: attachment, multiple: multiple),
}
.fragment-attachment.btn-group.btn-group-sm.mb-1
= link_to truncated_filename, attachment, data: link_data,
Expand Down

0 comments on commit 5a9814e

Please sign in to comment.