Skip to content

Commit

Permalink
v0.0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
ben committed Sep 13, 2011
1 parent f4369b3 commit bbfd63f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/zfben_libjs/helpers.rb
@@ -1,7 +1,7 @@
module Zfben_libjs::Helpers
Lib_version = Time.now.strftime('?%s')
def lib *opts
html = ''
html = lib_js 'lib.js'
unless opts.blank?
preload = []
lib_preload = []
Expand All @@ -13,6 +13,7 @@ def lib *opts
lib_preload.push name
end
end

if preload.length > 0
preload.each do |url|
if url.end_with?('.css')
Expand All @@ -22,10 +23,9 @@ def lib *opts
end
end
end

if lib_preload.length > 0
html << lib_js('lib.js') << "<script>lib('#{lib_preload.join(' ')}')</script>"
else
html << '<script>lib()</script>'
html << "<script>lib('#{lib_preload.join(' ')}')</script>"
end
end
return html
Expand Down
11 changes: 9 additions & 2 deletions lib/zfben_libjs/lib.coffee
Expand Up @@ -4,13 +4,20 @@ libs = {}
# save loaded source to `loaded`
loaded = {}

progress_loaded_url = (url)->
url = url.match(/[^?]+/)[0]
local = location.protocol + '//' + location.host
if url.indexOf(local) is 0
url = url.substring(local.length)
return url

for link in document.getElementsByTagName('link')
if link.href && link.href isnt ''
loaded[link.href] = true
loaded[progress_loaded_url(link.href)] = true

for script in document.getElementsByTagName('script')
if script.src && script.src isnt ''
loaded[script.src] = true
loaded[progress_loaded_url(script.src)] = true

# pending
pending_urls = {}
Expand Down
2 changes: 1 addition & 1 deletion zfben_libjs.gemspec
Expand Up @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)

Gem::Specification.new do |s|
s.name = 'zfben_libjs'
s.version = '0.0.18'
s.version = '0.0.19'
s.authors = ["Ben"]
s.email = ["ben@zfben.com"]
s.homepage = "https://github.com/benz303/zfben_libjs"
Expand Down

0 comments on commit bbfd63f

Please sign in to comment.