mtl 1.1.9 → 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1926f390b1ae10fcb4a3d1fe2c278a282a8a22a3
4
- data.tar.gz: 7526363a9aef94b10d58dd72b04e6d84aefad535
3
+ metadata.gz: 5f56f1f9112e8493ee517caf8765768aa52112a9
4
+ data.tar.gz: aee2814c81cc4749b142e0defa84b2a0a896b4b0
5
5
  SHA512:
6
- metadata.gz: 104e6629a4fcd153762019ce41620800d611842b0dc9c8f7a9363182f23e1cdd6cec4fd17c308f1e3499bb137cbd90bea89cb9c209c1832786e483239e983577
7
- data.tar.gz: 17cc28805e8b28c34641ea3ca7e13a06767e233e091838b07f76dd73704973d29fac5f6cc5efb338ab27b33d3e7b73dea7c19b6647ced072004c972bd6d940e7
6
+ metadata.gz: 0fd302425fa76ce00f3d4eb653ddfe5cbfe00fe2b4fc59d2427460bbe87b74ae1b3b18e65e808582a420901ffab6775606ff1509f7780a8f6d6a658fa6952d60
7
+ data.tar.gz: 7175999428aa56c3af6ee95c7c441ed21899709a7a75460bb5789ba57be7a527e81754497140bea1a36e73a3cec0b92da10e6759475f3c5ccaf3eaee2229a6b3
@@ -88,7 +88,7 @@ findOrCreateDocumentModal = ->
88
88
  initDocumentModal = ($fileCard) ->
89
89
  filename = $fileCard.data('mtl-document-name')
90
90
  title = $fileCard.prop('title')
91
- url = $fileCard.prop('href')
91
+ url = $fileCard.data('href')
92
92
  $modal = $(
93
93
  MTL.renderTemplate(
94
94
  'document_modal',
@@ -122,6 +122,22 @@ $(document).on 'click', '[data-mtl-document-modal="open"]', (e) ->
122
122
  when 39 # right
123
123
  findOrCreateDocumentModal().find('.document-modal-next').trigger 'click'
124
124
 
125
+
126
+ $(document).on 'click', '[data-mtl-document-modal="open"] .download-link', (e) ->
127
+ e.stopPropagation()
128
+ $(this).removeAttr('download') if navigator.userAgent.search('Firefox') > -1
129
+ if window.navigator && window.navigator.msSaveOrOpenBlob
130
+ e.preventDefault()
131
+ xhr = new XMLHttpRequest()
132
+ xhr.open('GET', this.href, true)
133
+ xhr.responseType = 'blob'
134
+ xhr.onload = (e) =>
135
+ if (xhr.status == 200)
136
+ blob = new Blob([xhr.response], type: xhr.getResponseHeader('content-type'))
137
+ window.navigator.msSaveOrOpenBlob(blob, this.title)
138
+ xhr.send()
139
+
140
+
125
141
  $(document).on 'click', '[data-mtl-document-modal="close"]', (e) ->
126
142
  e.preventDefault()
127
143
  closeDocumentModal()
@@ -7,6 +7,8 @@ $mtl-collection-file-bg: color('grey', 'lighten-5');
7
7
  $mtl-collection-file-text-primary: color('grey', 'darken-4');
8
8
  $mtl-collection-file-text-secondary: color('grey', 'base');
9
9
 
10
+ $mtl-collection-file-download: color('grey', 'darken-2');
11
+
10
12
  // collection of file cards
11
13
  .collection-files {
12
14
  margin: (-$mtl-collection-files-spacing) 0 0 (-$mtl-collection-files-spacing);
@@ -27,6 +29,7 @@ $mtl-collection-file-text-secondary: color('grey', 'base');
27
29
  background-size: cover;
28
30
  background-position: center;
29
31
  padding: 12px 13px 0;
32
+ cursor: pointer;
30
33
 
31
34
  @media #{$small-and-down} {
32
35
  width: 100%;
@@ -60,6 +63,28 @@ $mtl-collection-file-text-secondary: color('grey', 'base');
60
63
  }
61
64
  }
62
65
 
66
+ // additional direct download link
67
+ .download-link {
68
+ position: absolute;
69
+ right: 0;
70
+ bottom: 0;
71
+ opacity: 0;
72
+ transition-duration: .2s;
73
+ transition-property: opacity;
74
+
75
+ .material-icons {
76
+ display: block;
77
+ width: 30px;
78
+ height: 30px;
79
+ text-align: center;
80
+ line-height: 30px;
81
+ color: $mtl-collection-file-download;
82
+ }
83
+ }
84
+ &:hover .download-link {
85
+ opacity: 1;
86
+ }
87
+
63
88
  // image only panel
64
89
  &.card-panel-image {
65
90
  text-indent: -6000px;
@@ -13,19 +13,22 @@ module Mtl
13
13
 
14
14
  def render(filename, href, params = {})
15
15
  params = params.reverse_merge type: File.extname(filename).delete('.')
16
-
17
- view.link_to render_body(filename, params), href,
18
- title: params[:title] || filename,
19
- target: '_blank',
20
- class: ['card-panel', params[:preview] ? 'card-panel-image' : nil],
21
- data: data(filename, params),
22
- style: if params[:preview]
23
- "background-image: url(#{URI.encode(params[:preview])})"
24
- end
16
+ params[:href] = href
17
+ card_params = { title: params[:title] || filename,
18
+ class: ['card-panel', params[:preview] ? 'card-panel-image' : nil],
19
+ data: data(filename, params),
20
+ style: if params[:preview]
21
+ "background-image: url(#{URI.encode(params[:preview])})"
22
+ end }
23
+ if params[:modal]
24
+ view.content_tag :div, render_body(filename, params), card_params
25
+ else
26
+ view.link_to render_body(filename, params), href, card_params.merge(target: '_blank')
27
+ end
25
28
  end
26
29
 
27
30
  def render_body(filename, params)
28
- view.safe_join [label(filename, params[:title]), infos(params), delete(params)]
31
+ view.safe_join [label(filename, params[:title]), infos(params), delete(params), download(filename, params)]
29
32
  end
30
33
 
31
34
  private
@@ -56,6 +59,14 @@ module Mtl
56
59
  view.mtl_icon :close, class: 'close', data: data.reject { |_, v| v.blank? }
57
60
  end
58
61
 
62
+ def download(filename, params)
63
+ return unless params[:modal]
64
+ view.link_to view.mtl_icon(:file_download), params[:href], title: params[:title] || filename,
65
+ target: '_blank',
66
+ class: 'download-link',
67
+ download: params[:title] || filename
68
+ end
69
+
59
70
  def data(filename, params)
60
71
  data = params[:data] || {}
61
72
  data.merge(modal_data(filename, params))
@@ -63,7 +74,7 @@ module Mtl
63
74
 
64
75
  def modal_data(filename, params)
65
76
  return {} unless params[:modal]
66
- { mtl_document_modal: 'open', mtl_document_name: filename }
77
+ { mtl_document_modal: 'open', mtl_document_name: filename, href: params[:href] }
67
78
  end
68
79
  end
69
80
  end
@@ -1,5 +1,5 @@
1
1
  module Mtl
2
- VERSION = '1.1.9'.freeze
2
+ VERSION = '1.1.10'.freeze
3
3
  MATERIALIZE_VERSION = '0.99.0'.freeze
4
4
  ICONS_VERSION = '2.2.3'.freeze
5
5
  LODASH_VERSION = '4.14.1'.freeze
@@ -14,7 +14,7 @@ RSpec.describe Mtl::Rails::CardFilePresenter, dom: true do
14
14
  context '#render' do
15
15
  it 'renders a basic file card with filename and href' do
16
16
  expect(subject.render('Document Dolorem.jpg', '/path/to/file.jpg')).to match_dom <<-HTML
17
- <a title="Document Dolorem.jpg" target="_blank" class="card-panel " href="/path/to/file.jpg">
17
+ <a title="Document Dolorem.jpg" class="card-panel " target="_blank" href="/path/to/file.jpg">
18
18
  <span class="truncate">Document Dolorem.jpg</span>
19
19
  <span class="secondary">
20
20
  <i class="material-icons red-text">image</i>
@@ -26,7 +26,7 @@ RSpec.describe Mtl::Rails::CardFilePresenter, dom: true do
26
26
 
27
27
  it 'renders a file card with filename, href and a custom title' do
28
28
  expect(subject.render('Document Dolorem.jpg', '/path/to/file.jpg', title: 'foo')).to match_dom <<-HTML
29
- <a title="foo" target="_blank" class="card-panel " href="/path/to/file.jpg">
29
+ <a title="foo" class="card-panel " target="_blank" href="/path/to/file.jpg">
30
30
  <strong class="truncate">foo</strong>
31
31
  <span class="truncate">Document Dolorem.jpg</span>
32
32
  <span class="secondary">
@@ -39,7 +39,7 @@ RSpec.describe Mtl::Rails::CardFilePresenter, dom: true do
39
39
 
40
40
  it 'renders a file card with filename, href and a custom type' do
41
41
  expect(subject.render('Document Dolorem.jpg', '/path/to/file.jpg', type: 'bar')).to match_dom <<-HTML
42
- <a title="Document Dolorem.jpg" target="_blank" class="card-panel " href="/path/to/file.jpg">
42
+ <a title="Document Dolorem.jpg" class="card-panel " target="_blank" href="/path/to/file.jpg">
43
43
  <span class="truncate">Document Dolorem.jpg</span>
44
44
  <span class="secondary">
45
45
  <i class="material-icons blue-text">insert_drive_file</i>
@@ -51,7 +51,7 @@ RSpec.describe Mtl::Rails::CardFilePresenter, dom: true do
51
51
 
52
52
  it 'renders a file card with filename, href and a custom preview' do
53
53
  expect(subject.render('Document Dolorem.jpg', '/path/to/file.jpg', preview: '/path/to/preview.jpg')).to match_dom <<-HTML
54
- <a title="Document Dolorem.jpg" target="_blank" class="card-panel card-panel-image" style="background-image: url(/path/to/preview.jpg)" href="/path/to/file.jpg">
54
+ <a title="Document Dolorem.jpg" class="card-panel card-panel-image" style="background-image: url(/path/to/preview.jpg)" target="_blank" href="/path/to/file.jpg">
55
55
  <span class="truncate">Document Dolorem.jpg</span>
56
56
  <span class="secondary">
57
57
  <i class="material-icons red-text">image</i>
@@ -63,7 +63,7 @@ RSpec.describe Mtl::Rails::CardFilePresenter, dom: true do
63
63
 
64
64
  it 'renders a file card with filename, href and a custom custom delete' do
65
65
  expect(subject.render('Document Dolorem.jpg', '/path/to/file.jpg', delete: '/path/to/delete/the/file')).to match_dom <<-HTML
66
- <a title="Document Dolorem.jpg" target="_blank" class="card-panel " href="/path/to/file.jpg">
66
+ <a title="Document Dolorem.jpg" class="card-panel " target="_blank" href="/path/to/file.jpg">
67
67
  <span class="truncate">Document Dolorem.jpg</span>
68
68
  <span class="secondary">
69
69
  <i class="material-icons red-text">image</i>
@@ -76,7 +76,7 @@ RSpec.describe Mtl::Rails::CardFilePresenter, dom: true do
76
76
 
77
77
  it 'renders a file card with filename, href and a custom custom delete and a confirm' do
78
78
  expect(subject.render('Document Dolorem.jpg', '/path/to/file.jpg', delete: '/path/to/delete/the/file', confirm: 'sure?')).to match_dom <<-HTML
79
- <a title="Document Dolorem.jpg" target="_blank" class="card-panel " href="/path/to/file.jpg">
79
+ <a title="Document Dolorem.jpg" class="card-panel " target="_blank" href="/path/to/file.jpg">
80
80
  <span class="truncate">Document Dolorem.jpg</span>
81
81
  <span class="secondary">
82
82
  <i class="material-icons red-text">image</i>
@@ -89,19 +89,20 @@ RSpec.describe Mtl::Rails::CardFilePresenter, dom: true do
89
89
 
90
90
  it 'renders a file card with filename, href and document modal options' do
91
91
  expect(subject.render('Document Dolorem.jpg', '/path/to/file.jpg', modal: true)).to match_dom <<-HTML
92
- <a title="Document Dolorem.jpg" target="_blank" class="card-panel " data-mtl-document-modal="open" data-mtl-document-name="Document Dolorem.jpg" href="/path/to/file.jpg">
92
+ <div title="Document Dolorem.jpg" class="card-panel " data-mtl-document-modal="open" data-mtl-document-name="Document Dolorem.jpg" data-href="/path/to/file.jpg">
93
93
  <span class="truncate">Document Dolorem.jpg</span>
94
94
  <span class="secondary">
95
95
  <i class="material-icons red-text">image</i>
96
96
  JPG
97
97
  </span>
98
- </a>
98
+ <a title="Document Dolorem.jpg" target="_blank" class="download-link" download="Document Dolorem.jpg" href="/path/to/file.jpg"><i class="material-icons">file_download</i></a>
99
+ </div>
99
100
  HTML
100
101
  end
101
102
 
102
103
  it 'renders a file card with filename, href and custom data attributes' do
103
104
  expect(subject.render('Document Dolorem.jpg', '/path/to/file.jpg', data: { something: '42' })).to match_dom <<-HTML
104
- <a title="Document Dolorem.jpg" target="_blank" class="card-panel " data-something="42" href="/path/to/file.jpg">
105
+ <a title="Document Dolorem.jpg" class="card-panel " data-something="42" target="_blank" href="/path/to/file.jpg">
105
106
  <span class="truncate">Document Dolorem.jpg</span>
106
107
  <span class="secondary">
107
108
  <i class="material-icons red-text">image</i>
@@ -113,13 +114,14 @@ RSpec.describe Mtl::Rails::CardFilePresenter, dom: true do
113
114
 
114
115
  it 'renders a file card with filename, href, document modal options and custom data attributes' do
115
116
  expect(subject.render('Document Dolorem.jpg', '/path/to/file.jpg', modal: true, data: { something: '42' })).to match_dom <<-HTML
116
- <a title="Document Dolorem.jpg" target="_blank" class="card-panel " data-something="42" data-mtl-document-modal="open" data-mtl-document-name="Document Dolorem.jpg" href="/path/to/file.jpg">
117
+ <div title="Document Dolorem.jpg" class="card-panel " data-something="42" data-mtl-document-modal="open" data-mtl-document-name="Document Dolorem.jpg" data-href="/path/to/file.jpg">
117
118
  <span class="truncate">Document Dolorem.jpg</span>
118
119
  <span class="secondary">
119
120
  <i class="material-icons red-text">image</i>
120
121
  JPG
121
122
  </span>
122
- </a>
123
+ <a title="Document Dolorem.jpg" target="_blank" class="download-link" download="Document Dolorem.jpg" href="/path/to/file.jpg"><i class="material-icons">file_download</i></a>
124
+ </div>
123
125
  HTML
124
126
  end
125
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.9
4
+ version: 1.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Plüss
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-09-02 00:00:00.000000000 Z
13
+ date: 2017-09-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties