diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 17f0e4e7..10cd2281 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -29,21 +29,6 @@ module ApplicationHelper !@hide_home_link end - JAVASCRIPT_LIBRARIES = { - :addthis => 'http://s7.addthis.com/js/250/addthis_widget.js#username=openneo', - :bitly => 'http://bit.ly/javascript-api.js?version=latest&login=openneo&apiKey=R_4d0438829b7a99860de1d3edf55d8dc8', - :html5 => 'http://html5shim.googlecode.com/svn/trunk/html5.js', - :jquery => 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js', - :jquery_tmpl => 'http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js', - :swfobject => 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js' - } - - def include_javascript_libraries(*library_names) - raw(library_names.inject('') do |html, name| - html + javascript_include_tag(JAVASCRIPT_LIBRARIES[name]) - end) - end - def login_path_with_return_to login_path :return_to => request.fullpath end diff --git a/app/helpers/head_js_helper.rb b/app/helpers/head_js_helper.rb new file mode 100644 index 00000000..63bce0b3 --- /dev/null +++ b/app/helpers/head_js_helper.rb @@ -0,0 +1,51 @@ +module HeadJsHelper + JAVASCRIPT_LIBRARIES = {} + YAML.load_file(Rails.root.join('config', 'javascript_libraries.yml')).each do |name, src| + JAVASCRIPT_LIBRARIES[name.to_sym] = src + end + + def html5 + content_for :html5, "".html_safe + end + + def javascript_chain(*javascripts) + # two-dimensional array: list of chains + @javascript_chains ||= [] + @javascript_chains << javascripts + end + + def javascript_chains + if @javascript_chains + javascript_include_tag('head') + "\n" + javascript_chains_tag(@javascript_chains) + end + end + + def javascript_chain_line(chain) + chain_args = chain.map { + |script_name| javascript_library_path(script_name).inspect + }.join(', ') + "head.js(#{chain_args});" + end + + def javascript_chains_tag(chains) + output_js do |js| + chains.each do |chain| + js << javascript_chain_line(chain) + end + end + end + + private + + def javascript_library_path(script_name) + script_name.is_a?(Symbol) ? JAVASCRIPT_LIBRARIES[script_name] : javascript_path(script_name) + end + + def output_js(&block) + javascript_tag(safe_output(&block)) + end + + def safe_output(&block) + [].tap(&block).join("\n").html_safe + end +end diff --git a/app/views/items/show.html.haml b/app/views/items/show.html.haml index 38fc8bcc..620f9f70 100644 --- a/app/views/items/show.html.haml +++ b/app/views/items/show.html.haml @@ -1,3 +1,4 @@ +- javascript_chain :jquery, :swfobject, 'items/show' %header = image_tag @item.thumbnail_url, :id => 'item-thumbnail' %div @@ -31,10 +32,4 @@ Javascript and Flash are required to preview wearables. Sorry! :javascript - var CURRENT_ITEM_ZONES_RESTRICT = #{@item.zones_restrict.inspect}, - IMPRESS_HOST = #{RemoteImpressHost.inspect}; - -- content_for :javascripts do - = javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', - 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js', - 'items/show' + var CURRENT_ITEM_ZONES_RESTRICT = #{@item.zones_restrict.inspect}; diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 6f4a9497..36364290 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -6,11 +6,13 @@ - if content_for? :title — = yield :title + = yield(:html5) = stylesheet_link_tag "compiled/screen" = csrf_meta_tag = signed_in_meta_tag + - javascript_chain 'analytics' + = javascript_chains %body{:class => body_class} - = javascript_include_tag "analytics" #container - if content_for? :title %h1#title= yield :title @@ -60,4 +62,3 @@ %p Images © 2000-2010 Neopets, Inc. All Rights Reserved. Used With Permission - = yield(:javascripts) diff --git a/app/views/outfits/edit.html.haml b/app/views/outfits/edit.html.haml index 69b511f5..d386f093 100644 --- a/app/views/outfits/edit.html.haml +++ b/app/views/outfits/edit.html.haml @@ -1,3 +1,5 @@ +- html5 +- javascript_chain :jquery, :swfobject, :jquery_tmpl, 'wardrobe', 'outfits/edit' - add_body_class 'fullscreen' %a#home-link{:href => "/"} %span Dress to Impress @@ -105,8 +107,3 @@ \/ %a.outfit-delete-confirmation-no{:href => '#'} no, thanks -- content_for :javascripts do - /[if IE] - = include_javascript_libraries :html5 - = include_javascript_libraries :jquery, :swfobject, :jquery_tmpl - = include_javascripts :edit_outfit_package diff --git a/app/views/outfits/new.html.haml b/app/views/outfits/new.html.haml index c54853ee..df371b9a 100644 --- a/app/views/outfits/new.html.haml +++ b/app/views/outfits/new.html.haml @@ -1,4 +1,5 @@ - hide_home_link +- javascript_chain :jquery, 'wardrobe', 'pet_query', 'outfits/new' #outfit-forms #pet-preview = image_tag 'default_preview.png', :alt => '' @@ -99,6 +100,3 @@ = pet_name_tag %button{:type => "submit"} I pwn! -- content_for :javascripts do - = include_javascript_libraries :jquery - = include_javascripts :new_outfit_package diff --git a/app/views/outfits/show.html.haml b/app/views/outfits/show.html.haml index 1e730f1d..9c462115 100644 --- a/app/views/outfits/show.html.haml +++ b/app/views/outfits/show.html.haml @@ -1,4 +1,5 @@ - title @outfit.name +- javascript_chain :jquery, :swfobject, 'wardrobe', 'outfits/show' %a.button#outfit-wardrobe-link{:href => wardrobe_path(:anchor => @outfit.to_query)} Edit a copy #outfit-user @@ -9,8 +10,5 @@ #preview-wrapper #preview-swf #outfit-items= render @outfit.worn_items -- content_for :javascripts do - :javascript - var INITIAL_OUTFIT_DATA = #{@outfit.to_json}; - = include_javascript_libraries :jquery, :swfobject - = include_javascripts :show_outfit_package +:javascript + var INITIAL_OUTFIT_DATA = #{@outfit.to_json}; diff --git a/app/views/pets/bulk.html.haml b/app/views/pets/bulk.html.haml index 88b69820..45fb2c41 100644 --- a/app/views/pets/bulk.html.haml +++ b/app/views/pets/bulk.html.haml @@ -1,3 +1,4 @@ +- javascript_chain :jquery, 'pet_query', 'pets/bulk' - unless user_signed_in? %p.warning = link_to 'You are not logged in!', login_path(:return_to => bulk_pets_path) @@ -28,6 +29,3 @@ %textarea %button#bulk-pets-form-add{:type => "button"} Add %button#bulk-pets-form-clear{:type => "button"} Clear -- content_for :javascripts do - = include_javascript_libraries :jquery - = include_javascripts :bulk_pets_package diff --git a/config/javascript_libraries.yml b/config/javascript_libraries.yml new file mode 100644 index 00000000..8eb8de17 --- /dev/null +++ b/config/javascript_libraries.yml @@ -0,0 +1,4 @@ +html5: http://html5shim.googlecode.com/svn/trunk/html5.js +jquery: http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js +jquery_tmpl: http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js +swfobject: http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js diff --git a/public/javascripts/head.js b/public/javascripts/head.js new file mode 100644 index 00000000..b71de176 --- /dev/null +++ b/public/javascripts/head.js @@ -0,0 +1 @@ +(function(j){function k(a){var b=g[a.url||a];if(b)return b;if(typeof a=="object")for(var c in a){if(a[c])b={name:c,url:a[c]}}else b={name:a.substring(a.indexOf("/",10)+1,a.indexOf("?")),url:a};return g[b.url]=b}function e(a,b){if(a){if(typeof a=="object")a=[].slice.call(a);for(var c=0;csubmit that pet's name as soon as you " + + "submit that pet's name as soon as you " + "get the chance! Thanks!"; } } @@ -76,7 +72,7 @@ function PetType() { speciesList.filter('.current').removeClass('current'); this.link.addClass('current'); customize_more_el.attr('href', - 'http://impress.openneo.net/wardrobe?species=' + this.species_id + + '/wardrobe#species=' + this.species_id + '&color=' + this.color_id + '&objects[]=' + Item.current.id); if(this.activated) { Preview.enable(); @@ -222,7 +218,7 @@ Preview = new function Preview() { '100%', // width '100%', // height '9', // required version - impressUrl('/assets/js/swfobject/expressInstall.swf'), // express install URL + null, // express install URL {}, // flashvars {'wmode': 'transparent', 'allowscriptaccess': 'always'} // params );