izi_lightup 1.0.8 → 1.0.13

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
  SHA256:
3
- metadata.gz: e07a49f206c6fb345cf0b7bbc5fbc2b97c7eb7ebe6d0a67b40249c0efcb8d3cb
4
- data.tar.gz: c14d54784f732666060f993b8f3dd2c344e9c3cbf4247e836d9a7a92e395b1a0
3
+ metadata.gz: 2a9caf0a357d64fe6ee03a00bfb69fdb37fd2663ffb8473484f6bf00b473e7da
4
+ data.tar.gz: 752bf51570ee50e41e316cd1c901af0e5a5ad0c7600a1e56870e668d98261a59
5
5
  SHA512:
6
- metadata.gz: 45f511555379a877ce6da9caaea827e5fecb924e63ab2ab1410860fdcd484089fe4ca01fd3fe744b2a65691aca3190c0c795a8e8d96eaf9f326f4aa8263086cb
7
- data.tar.gz: 7de673a26083b07cb3c8ad2828c6b6118930aaf71a0baa4e33cc7c0dd4fb57e017c572199b3f9ec8503e84e08f79f8017d1c12a475518c2dea86421083603476
6
+ metadata.gz: 121307a969169c1673f5dc2a1c657ce36a84e3de6a7ab43d40e2f57d300cf82438f0e3e1775cd4cd5254d1e5ccda8eed692ef749fdf6c8ff663d9bc05316955c
7
+ data.tar.gz: 44c7675d48b3ad3fa1296c3486162f12eb6882bd2ffec6de668553b43c4755e97f6ffab5d10e8fb7557596a27d44b2d796810f665dc7b2b2b5249f0650a486f3
@@ -1,6 +1,6 @@
1
1
  ((window, document) -> (
2
2
  EVENT_TYPE = window.__activeEventName || 'Activity'
3
- MAX_TIMEOUT = window.__activeTimeout || 5000
3
+ MAX_TIMEOUT = window.__activeTimeout || 10000
4
4
  TRACK_MARKING = window.__activeMark || '_real_track=true'
5
5
 
6
6
  if custom_mt = /^\?(\d+)$/.exec(window.location.search)
@@ -10,7 +10,7 @@
10
10
 
11
11
  while callbacks.length > 0
12
12
  callback = callbacks.shift()
13
- callback.call(window) if typeof(callback) is 'function'
13
+ callback.call(window, __required[id]) if typeof(callback) is 'function'
14
14
 
15
15
  _buildSubscriptions = (id, node) ->
16
16
  data = __required[id]
@@ -32,6 +32,7 @@
32
32
  data.callbacks.push(callback) if typeof(callback) is 'function'
33
33
 
34
34
  window.miniRequire ||= (key, source_url, callback = undefined) ->
35
+ key ||= Math.random().toString(36).slice(2, 12)
35
36
  id = "source_#{key.replace(/[^a-z0-9_\-]+/ig, '_')}"
36
37
  __required[id] ||= {loaded: false, callbacks: [], started: false}
37
38
 
@@ -50,9 +51,40 @@
50
51
  src.async = true
51
52
  src.defer = true
52
53
  src.src = source_url
54
+ __required[id].node = src
53
55
  _buildSubscriptions(id, src)
54
56
  _subscribe(id, callback)
55
57
 
56
58
  document.body.appendChild(src)
57
59
  true
60
+
61
+ window.miniPreload ||= (params, callback = undefined) ->
62
+ key = params.key || Math.random().toString(36).slice(2, 12)
63
+ callback ||= params.callback
64
+ source_url = params.src
65
+ id = "source_#{key.replace(/[^a-z0-9_\-]+/ig, '_')}"
66
+ __required[id] ||= {loaded: false, callbacks: [], started: false}
67
+
68
+ # subscribe only if no source
69
+ return _subscribe(id, callback) unless source_url?.length > 0
70
+
71
+ # subscribe only if already attached & started
72
+ return _subscribe(id, callback) if __required[id].started
73
+
74
+ # mark as started
75
+ __required[id].started = true
76
+
77
+ # attach script
78
+ src = document.createElement('link')
79
+ src.id = id
80
+ src.rel = 'preload'
81
+ src.href = source_url
82
+ src.as = params.as || 'style'
83
+ __required[id].node = src
84
+ _buildSubscriptions(id, src)
85
+ _subscribe(id, callback)
86
+
87
+ document.head.appendChild(src)
88
+ true
89
+
58
90
  ))(window, document)
@@ -71,6 +71,12 @@ module CriticalHelper
71
71
  end
72
72
 
73
73
  def asset_exist?(name)
74
- Rails.application.assets_manifest.find_sources(name)&.first&.present?
74
+ return manifest.find_sources(name)&.first&.present? if Rails.env.development?
75
+
76
+ manifest.assets.key?(name)
77
+ end
78
+
79
+ def manifest
80
+ @manifest ||= Rails.application.assets_manifest
75
81
  end
76
82
  end
@@ -22,7 +22,9 @@ module IziLightup
22
22
  next unless version&.file&.exists? && version&.url&.present?
23
23
 
24
24
  url = version.url
25
- params.merge!(%i[width height].zip(version.dimensions).to_h)
25
+ dimensions = safe_dimentions(item, version)
26
+ params.merge!(dimensions) if dimensions.present?
27
+
26
28
  return image_tag(url, params) unless block_given?
27
29
 
28
30
  yield(url, params)
@@ -35,6 +37,19 @@ module IziLightup
35
37
 
36
38
  private
37
39
 
40
+ def safe_dimentions(item, version)
41
+ dimensions = nil
42
+ begin
43
+ dimensions = version.dimensions
44
+ rescue MiniMagick::Error => _e
45
+ dimensions = [item&.width, item&.height].compact
46
+ end
47
+
48
+ return {} if dimensions.blank?
49
+
50
+ %i[width height].zip(dimensions).to_h
51
+ end
52
+
38
53
  def fetch_items(object, fields)
39
54
  Array.wrap(fields).map do |name|
40
55
  object.respond_to?(name) ? object.public_send(name) : nil
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IziLightup
4
- VERSION = '1.0.8'
4
+ VERSION = '1.0.13'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: izi_lightup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - IzikAJ
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-09 00:00:00.000000000 Z
11
+ date: 2021-01-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Utils to speed up page load by using critical css &