I have a question that I’m hoping someone can help me answer.
I have recently begun embedding for more than one site on my instance (pixls.us and digikam.org).
I’m wondering if there’s a way to differentiate which host is being embedded in for styling? One site is white background and the other is dark. I’m trying to set a font color that works for both, but it’s… difficult.
Is there some neat answer I’m missing for setting a CSS style rule that will match one and not the other?
Perhaps adding another parameter to DiscourseEmbed that we can specify, like a discourseEmbedClass that we can then attach to the iframe/embedded tag as a class, so we can target it with the embed CSS?
I was playing around with the embed stuff the other day. You’re interested in public/javascripts/embed.js, and adding an additional query parameter to queryParams based on DE.discourseEmbedClass, which you could then set in the embedded code.
Yes that’s right. But I saw you mentioned about background color particularly. You can style the background color of the outer div of the iframe, which is part of your website not discourse. And your embedded iframe will get that background color. I did that on my site.
Edit: I read your OP too quickly, so it seems you are looking for change the font color of the iframe. I don’t know a easy way for that. But still you may try to change the iframe to some background color that fits both the site style and discourse font color, as a workaround.
At the moment, my idea is to attach the discourseEmbedClass idea as a class to the embedded <html> element (basically, <html class='SOME-CLASS-PARAM'>) so the CSS can target this element w/o hacking at the actual embed code.
Update the embeddable_host table to add a custom class attribute
Update the admin UI to allow input in that field
Update the embed erb template to show that custom value
I have security concerns otherwise with passing the value through on the client side.
It’s a lot more work but I feel strongly it’s the better way to solve this issue. If it’s outside your realm of experience, maybe someone from the community could jump in and help you out?
Sweet merciful goodness I think I have something working.
I have added the necessary column to :embeddable_hosts and updated the admin UI for inputting that field.
(I am not sure what the naming convention for this file should be, I went with 20170505_add_embed_class_name_to_embeddable_hosts.rb).
I just need to add the class_name to the embed erb template, but am not sure how to access it within the template. Any pointers?
Ideally I’d like to add it to the <html> tag of the embed as a class…
Just an update and a request, if anyone might be able to help.
The patch works and merges fine, but @eviltrout wanted me to add a controller spec that checks for class_name in the record being viewed, and assigns the embeddable_css_class variable for embedding in the template.
I am not having any luck getting it to work despite a great pointer to exactly where I should be looking:
I have modified spec/controllers/embed_controller_spec.rb down in the context "with multiple hosts" so the last call to Fabricator should include a class_name:
Following @eviltrout’s guidance, I then added a new test to check, but this is not working.
it "contains custom class name" do
controller.request.stubs(:referer).returns("https://example.com/some-other-path")
get :comments, embed_url: embed_url
expect(assigns(:embeddable_css_class)).to eq('example')
end
I’m apologize if I’m a little dense, but I could really use a hand here figuring out how to get this last bit working.