class AsyncLoader

Public Instance Methods

async_css(*sources)
Alias for: load_css
async_font(*sources)
Alias for: load_font
async_js(*sources)
Alias for: load_js
async_js_in_order(*sources)
Alias for: load_js_in_order
async_wrap(string) click to toggle source
# File lib/middleman-async-loader.rb, line 32
def async_wrap string
  "(function(){#{string}}());"
end
bootstrap() click to toggle source
# File lib/middleman-async-loader.rb, line 47
def bootstrap
  return "" if @has_loaded == true
  @has_loaded = true
  "window.___asl=function(t,f,wf){var d=document,e=d.createElement(t=='css'?'link':'script');e[t=='css'?'href':'src']=f;e[t=='css'?'rel':'type']=t=='css'?'stylesheet':'text/javascript';if(wf){e.rel='subresource'};d.body.appendChild(e);return e;};"
end
bundle_sources(sources, type, isFont = false) click to toggle source
# File lib/middleman-async-loader.rb, line 41
def bundle_sources(sources, type, isFont = false)
  bootstrap() + async_wrap(sources.map do |source|
    "___asl('#{type.to_s}','#{asset_path(type, source)}'#{',true' if isFont});"
  end.reduce(:+))
end
load_css(*sources) click to toggle source
# File lib/middleman-async-loader.rb, line 5
def load_css(*sources)
  bundle_sources(sources, :css)
end
Also aliased as: async_css
load_font(*sources) click to toggle source
# File lib/middleman-async-loader.rb, line 9
def load_font(*sources)
  bundle_sources(sources, :css, true)
end
Also aliased as: async_font
load_js(*sources) click to toggle source
# File lib/middleman-async-loader.rb, line 13
def load_js(*sources)
  bundle_sources(sources, :js, true)
end
Also aliased as: async_js
load_js_in_order(*sources) click to toggle source
# File lib/middleman-async-loader.rb, line 17
def load_js_in_order(*sources)
 string = ''
 sources.reverse.each do |source|
    string = "___asl('js','#{asset_path(:js, source)}')#{maybe_on_load(string)};"
  end
  bootstrap() + string
end
Also aliased as: async_js_in_order
maybe_on_load(string) click to toggle source
# File lib/middleman-async-loader.rb, line 36
def maybe_on_load string
  return '' if string.empty?
  ".onload=function(){#{string}}"
end