Created
February 17, 2012 10:40
-
-
Save joakimk/1852580 to your computer and use it in GitHub Desktop.
Revisions
-
Joakim Kolsjö created this gist
Feb 17, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ class Controller include LazyLoad def show @model = Model.find(...) respond_to do |format| format.html do @html_specific_data = Model.find(...) end render_lazy_load(format) do @lazy_specific_data = Model.find(...) end end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ module Helper def lazy_render(name) content_tag :div, :id => "lazy-loaded-#{name}" do content_tag :div, :class => "spinner" do content_tag(:script) do "if(!window.lazyLoads) { window.lazyLoads = []; }; window.lazyLoads.push('#{name}');".html_safe end end end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ module LazyLoad def render_lazy_load(format, &block) format.js do block.call if block render json: { lazy_load_partial: params[:lazy_load_partial], body: render_to_string(:partial => params[:lazy_load_partial]) } end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ if window.lazyLoads for lazyLoad in window.lazyLoads url = window.location.href + "?format=js&lazy_load_partial=#{lazyLoad}" $.ajax url: url, dataType: "json", success: (data) -> $("#lazy-loaded-#{data.lazy_load_partial}").html(data.body) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ = render 'foobar' becomes = lazy_render 'foobar'