Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #212 #219

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 2 additions & 32 deletions lib/lazy_high_charts/layout_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ def request_is_xhr?
defined?(request) && request.respond_to?(:xhr?) && request.xhr?
end

def request_is_referrer?
defined?(request) && request.respond_to?(:headers) && request.headers["X-XHR-Referer"]
end

def request_turbolinks_5_tureferrer?
defined?(request) && request.respond_to?(:headers) && request.headers["Turbolinks-Referrer"]
end

def options_collection_as_string object
options_collection = [generate_json_from_hash(OptionsKeyFilter.filter(object.options))]
options_collection << %|"series": [#{generate_json_from_array(object.series_data)}]|
Expand All @@ -94,34 +86,12 @@ def options_collection_as_string object
def encapsulate_js(core_js)
if request_is_xhr?
js_output = "#{js_start} #{core_js} #{js_end}"
# Turbolinks.version < 5
elsif defined?(Turbolinks) && request_is_referrer?
js_output =<<-EOJS
#{js_start}
var f = function(){
document.removeEventListener('page:load', f, true);
#{core_js}
};
document.addEventListener('page:load', f, true);
#{js_end}
EOJS
# Turbolinks >= 5
elsif defined?(Turbolinks) && request_turbolinks_5_tureferrer?
js_output =<<-EOJS
#{js_start}
document.addEventListener("turbolinks:load", function() {
#{core_js}
});
#{js_end}
EOJS
else
js_output =<<-EOJS
#{js_start}
var onload = window.onload;
window.onload = function(){
if (typeof onload == "function") onload();
$(document).ready(function() {
#{core_js}
};
});
#{js_end}
EOJS
end
Expand Down
8 changes: 2 additions & 6 deletions spec/lazy_high_charts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,8 @@
expect(high_chart(@placeholder, @chart)).to match(/}\)\(\)/)
end

it "should assign to the onload event" do
expect(high_chart(@placeholder, @chart)).to include('window.onload = function(){')
end
it "should call any existing onload function" do
expect(high_chart(@placeholder, @chart)).to match(/onload = window.onload;/)
expect(high_chart(@placeholder, @chart)).to match(/if \(typeof onload == "function"\)\s*onload\(\)/)
it "should assign to the jquery document ready event" do
expect(high_chart(@placeholder, @chart)).to include('$(document).ready(function()')
end
end
describe "initialize HighChart" do
Expand Down