jdvp-back-to-top 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 93a0db47300a7a7c57cac30b9c2715de808b58724b393b2f65212f580eeed7b9
4
+ data.tar.gz: 0e5b31b0c7a2676ca169916adaec4b68169949533ebb6d8d25da90f5cb7b00c4
5
+ SHA512:
6
+ metadata.gz: 6e4650698091c2258440ffb859ef5571f1087aa29a49e3b228b08ba0107961306434c3752b66271044d1d5bac53ac98c40c8747881b28004adfd477502527b64
7
+ data.tar.gz: b0d7d04bc84640d568f6fca7cf5377fde3f43e6dcde2b002b0593552c7753674b415fbf552d05e3af04427e543b9e2dd81966bbb4cd25d25d20fb9916d9654e1
@@ -0,0 +1,11 @@
1
+ #jdvp-back-to-top {
2
+ border: 1px solid #e6e6e6;
3
+ border-radius: 0;
4
+ padding: 10px;
5
+ height: auto;
6
+ width: auto;
7
+ display: flex;
8
+ flex-wrap: wrap;
9
+ align-items: center;
10
+ justify-content: center;
11
+ };
@@ -0,0 +1 @@
1
+ "use strict";function addBackToTop(){var o,t,e,n,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=i.backgroundColor,d=void 0===r?"#000":r,a=i.cornerOffset,c=void 0===a?20:a,s=i.diameter,l=void 0===s?56:s,u=i.ease,p=void 0===u?function(o){return.5*(1-Math.cos(Math.PI*o))}:u,m=i.id,h=void 0===m?"jdvp-back-to-top":m,b=i.innerHTML,v=void 0===b?'<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"></path></svg>':b,f=i.onClickScrollTo,x=void 0===f?0:f,w=i.scrollContainer,g=void 0===w?document.body:w,k=i.scrollDuration,y=void 0===k?100:k,T=i.showWhenScrollTopIs,M=void 0===T?1:T,z=i.size,E=void 0===z?l:z,C=i.textColor,L=void 0===C?"#fff":C,N=i.zIndex,I=void 0===N?1:N,A=g===document.body,B=A&&document.documentElement;o=Math.round(.43*E),t=Math.round(.29*E),e="#"+h+"{background:"+d+";-webkit-border-radius:50%;-moz-border-radius:50%;border-radius:50%;bottom:"+c+"px;-webkit-box-shadow:0 2px 5px 0 rgba(0,0,0,.26);-moz-box-shadow:0 2px 5px 0 rgba(0,0,0,.26);box-shadow:0 2px 5px 0 rgba(0,0,0,.26);color:"+L+";cursor:pointer;display:block;height:"+E+"px;opacity:1;outline:0;position:fixed;right:"+c+"px;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none;-webkit-transition:bottom .2s,opacity .2s;-o-transition:bottom .2s,opacity .2s;-moz-transition:bottom .2s,opacity .2s;transition:bottom .2s,opacity .2s;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:"+E+"px;z-index:"+I+"}#"+h+" svg{display:block;fill:currentColor;height:"+o+"px;margin:"+t+"px auto 0;width:"+o+"px}#"+h+".hidden{bottom:-"+E+"px;opacity:0}",(n=document.createElement("style")).appendChild(document.createTextNode(e)),document.head.insertAdjacentElement("afterbegin",n);var D=function(){var o=document.createElement("div");return o.id=h,o.className="hidden",o.innerHTML=v,o.addEventListener("click",function(o){o.preventDefault(),function(){var o="function"==typeof x?x():x,t=window,e=t.performance,n=t.requestAnimationFrame;if(y<=0||void 0===e||void 0===n)return q(o);var i=e.now(),r=j(),d=r-o;n(function o(t){var e=Math.min((t-i)/y,1);q(r-Math.round(p(e)*d)),e<1&&n(o)})}()}),document.body.appendChild(o),o}(),H=!0;function S(){j()>=M?function(){if(!H)return;D.className="",H=!1}():function(){if(H)return;D.className="hidden",H=!0}()}function j(){return g.scrollTop||B&&document.documentElement.scrollTop||0}function q(o){g.scrollTop=o,B&&(document.documentElement.scrollTop=o)}(A?window:g).addEventListener("scroll",S),S()};
@@ -0,0 +1,51 @@
1
+ require "jekyll"
2
+
3
+ #After the site is written, the necessary files this plugin's generateed code needs are also written
4
+ Jekyll::Hooks.register :site, :post_write do |site|
5
+ debug_logging = site&.config&.dig("jdvp_back_to_top", "debug_logging") || false
6
+
7
+ # Copy required CSS file
8
+ css = File.expand_path("../../assets/jdvp-back-to-top.css", __FILE__)
9
+ FileUtils.mkdir_p("#{site.in_dest_dir("assets/")}")
10
+ css_location = site.in_dest_dir("assets/jdvp-back-to-top.css")
11
+ if (debug_logging)
12
+ puts "Copying jdvp-back-to-top CSS to #{css_location}"
13
+ end
14
+ FileUtils.cp(css, "#{css_location}")
15
+
16
+ # Copy required JS file
17
+ js = File.expand_path("../../assets/jdvp-back-to-top.js", __FILE__)
18
+ js_location = site.in_dest_dir("assets/jdvp-back-to-top.js")
19
+ if (debug_logging)
20
+ puts "Copying jdvp-back-to-top JavaScript to #{js_location}"
21
+ end
22
+ FileUtils.cp(js, "#{js_location}")
23
+
24
+ # Determine which pages will get the widget
25
+ page_file_pattern = site&.config&.dig("jdvp_back_to_top", "file_pattern") || "**/*.html"
26
+
27
+ # Generate the actual HTML for pages that will have the widget
28
+ default_options = "{id:\"jdvp-back-to-top\",backgroundColor:\"#FFF\",textColor:\"#000\",innerHTML:\'<svg style=\"margin: 0px;\"><path d=\"M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z\"/></svg>\',cornerOffset:20}"
29
+ back_to_top_options = site&.config&.dig("jdvp_back_to_top", "options") || default_options
30
+ resource_string = "<link rel=\"stylesheet\" href=\"#{site.baseurl}/assets/jdvp-back-to-top.css\"/>" +
31
+ "<script src=\"#{site.baseurl}/assets/jdvp-back-to-top.js\"></script>" +
32
+ "<script>addBackToTop(#{back_to_top_options});</script>"
33
+
34
+ # For every html file in the generated site
35
+ site_directory = "#{site.in_dest_dir("/")}"
36
+ Dir.glob(page_file_pattern, base: site_directory).each do |file_name|
37
+ file_plus_path = "#{site_directory}#{file_name}"
38
+
39
+ if (debug_logging)
40
+ puts "Adding jdvp-back-to-top widget to #{file_plus_path}"
41
+ end
42
+
43
+ # If the file has a body, append to the body
44
+ if (File.foreach(file_plus_path).grep(/<\/body>/).any?)
45
+ File.write(file_plus_path, File.open(file_plus_path, &:read).sub("</body>","#{resource_string}</body>"))
46
+ # If no body exists for some reason, try to just append at the end of the html tag
47
+ elsif (File.foreach(file_plus_path).grep(/<\/html>/).any?)
48
+ File.write(file_plus_path, File.open(file_plus_path, &:read).sub("</html>","#{resource_string}</html>"))
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jdvp-back-to-top
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - JD Porterfield
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ description:
34
+ email: jd.porterfield@alumni.rice.edu
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - assets/jdvp-back-to-top.css
40
+ - assets/jdvp-back-to-top.js
41
+ - lib/jdvp-back-to-top.rb
42
+ homepage: https://github.com/jdvp/jdvp-back-to-top
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.6.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.5.3
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Simple gem used to add a back-to-top widget to my site
65
+ test_files: []