Module: FastComments::Jekyll::BulkCountWidget
- Defined in:
- lib/fastcomments/jekyll/bulk_count_widget.rb
Overview
Renders the bulk comment-count loader: sets the global config object, then lazy-loads the bulk script once. The script scans the page for elements with class “fast-comments-count” and a data-fast-comments-url-id attribute.
Class Method Summary collapse
Class Method Details
.render(spec, config) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fastcomments/jekyll/bulk_count_widget.rb', line 9 def render(spec, config) clean = Util.sanitize_config(config) region = clean["region"] script_src = "#{Util.get_cdn_base(region)}#{spec[:script_path]}" "<script>" \ "(function(){" \ "window.#{spec[:global_name]}=#{Util.json_for_script(clean)};" \ "var scriptSrc=#{Util.json_for_script(script_src)};" \ "var marker=#{Util.json_for_script(spec[:script_marker_attr])};" \ "if(!document.querySelector('script['+marker+']')){" \ "var s=document.createElement('script');" \ "s.src=scriptSrc;" \ "s.setAttribute(marker,'');" \ "document.head.appendChild(s);" \ "}" \ "})();" \ "</script>" end |