-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add support to embed hasjob iframe on any third party website #455
Conversation
1. JS for adding iframe to third party website and to resize the iframe automatically to match content size 2. iframe endpoint, accessed by passing `?embed=1` to any view URL, plus `&limit=n` where default is 8 when an embed is specified 3. In iframe view, grouping is disabled
hasjob/static/embed.js
Outdated
@@ -0,0 +1,24 @@ | |||
(function() { | |||
var containerDiv = document.getElementById('hasjob'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes there can be only one Hasjob embed per page. Do we want to support multiple? In the case of a Medium article, for instance, there can be multiple. While this code isn't for Medium, we may have a similar use case on our own websites.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
To include multiple hasjob iframes, container div needs to have
data-href
: hasjob url (can contain query parameters)
data-jobpost-limit
: Number of job posts to be displayed
data-iframe-id
: id for the iframe (this is required to set the height of the respective iframe on resize)
Eg:-
<div class="hasjob-embed" data-href="http://hasjob.co/?q=javascript" data-jobpost-limit="16" data-iframe-id="hasjob-js"></div>
<div class="hasjob-embed" data-href="http://hasjob.co/?t=contract&q=android" data-jobpost-limit="16" data-iframe-id="hasjob-android"></div>
<script src="http://hasjob.co/api/1/embed.js"></script>
hasjob/static/embed.js
Outdated
var link = containerDiv.getAttribute('data-href'); | ||
link = link.substr(-1) !== '/' ? link : link.substr(0, link.length-1); | ||
var jobPostLimit = containerDiv.getAttribute('data-jobpost-limit'); | ||
var iframeSrc = link + '/?embed=1&limit=' + jobPostLimit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work if the link already contains query parameters. Have to check for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
hasjob/templates/index.html.jinja2
Outdated
{{ gboard.description|safe }} | ||
{%- if gkiosk and g.peopleflow_url %} | ||
<p>If you find a job worth applying for here, tap your badge on the reader attached to this kiosk and we’ll send an email connecting you with the employer.</p> | ||
{%- if not embed %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the complexity of this template, I'm unable to tell if the if/endif
tags are correctly positioned and have to trust you on this. We should simplify this in a separate PR, composing the template as a collection of calls to macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved stickie-area
rendering to a macro
hasjob/templates/layout.html.jinja2
Outdated
{%- if not embed %} | ||
{{ super() }} | ||
{% endif %} | ||
{% endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this, make an embedlayout.html.jinja2
and in index.html.jinja2
, add an if
condition to decide which template to extend.
hasjob/views/index.py
Outdated
@@ -702,7 +713,7 @@ def sortarchive(order_by): | |||
if reverse is None: | |||
reverse = False | |||
try: | |||
reverse = bool(int(reverse)) | |||
reverse = bool( (reverse)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
hasjob/views/index.py
Outdated
|
||
|
||
@app.route('/embed.js', methods=['GET'], subdomain='<subdomain>') | ||
@app.route('/embed.js', methods=['GET']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be /api/1/embed.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
…ring of stickie-area to a macro.
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en" {% block manifest %}{%- if g.kiosk %} manifest="{{ url_for('kiosk_manifest') }}" {%- endif %}{% endblock %}> <![endif]--> | ||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en" {{ self.manifest() }}> <![endif]--> | ||
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en" {{ self.manifest() }}> <![endif]--> | ||
<!--[if gt IE 8]><!--> <html lang="en" class="no-js {%- if g.user %} userlogin {%- else %} no-userlogin {%- endif %}" {{ self.manifest() }}> <!--<![endif]--> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move this manifest block into baseframe so we don't have to repeat it here.
} | ||
} | ||
</script> | ||
{%- endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is too much replicated from layout.html.jinja2
here. We'll have to find a way to abstract this out. Maybe in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jace I extended layout.html.jinja2
in embedlayout.html.jinja2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better now!
|
||
{%- if embed -%} | ||
{% extends "embedlayout.html.jinja2" %} | ||
{%- elif not request.is_xhr -%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, doesn't this if
condition do the same thing we're trying to achieve with embed? It returns an embeddable version of the page without header or footer, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and that's what I had done earlier. There are other parts of the page that we don't need in the embed like flash
, campaign, footerscripts
, there was more if/endif tags and increasing the complexity of the template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if not request.is_xhr
doesn't include baseframe styling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a clean-up project, can we design templates around these use cases?
- Full page
- iframe (no header and footer, but includes stylesheet and scripts)
- Fragment (just a HTML snippet)
This needs a separate ticket, and should be supported from Baseframe, so the ticket goes there.
} | ||
} | ||
</script> | ||
{%- endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better now!
|
||
{%- if embed -%} | ||
{% extends "embedlayout.html.jinja2" %} | ||
{%- elif not request.is_xhr -%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a clean-up project, can we design templates around these use cases?
- Full page
- iframe (no header and footer, but includes stylesheet and scripts)
- Fragment (just a HTML snippet)
This needs a separate ticket, and should be supported from Baseframe, so the ticket goes there.
automatically to match content size
?embed=1
to any view URL,plus
&limit=n
where default is 8 when an embed is specifiedTo add iframe to a website, include container div and script tag
Fixes #454
Desktop view
Mobile view(on resizing)