Skip to content

Commit

Permalink
Merge branch 'master' into fix.large-dialogs
Browse files Browse the repository at this point in the history
Conflicts with rauchg#153 feature.sign-in-link-in-iframe:
	lib/index.js
	  Added `large` param to splash() call, to which rauchg#153 had added `org`
	lib/splash.js
	  Converted px to rem where rauchg#153 had dedented
  • Loading branch information
laughinghan committed Mar 5, 2016
2 parents 7b9985c + 00aec7e commit 7305f36
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 18 deletions.
5 changes: 4 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ Read more about the [motivations and history](http://rauchg.com/slackin) behind

#### Cloud Foundry

[Follow these instructions.](https://github.com/pivotal-cf/slackin/wiki/Cloud-Foundry)
##### IBM Bluemix
[![Deploy to Bluemix](https://bluemix.net/deploy/button.png)](https://bluemix.net/deploy?repository=https://github.com/rauchg/slackin)

For other CloudFoundry providers, [follow these instructions.](https://github.com/pivotal-cf/slackin/wiki/Cloud-Foundry)

#### Custom

Expand Down
7 changes: 7 additions & 0 deletions lib/assets/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
// ensure it's shown (since first time hidden)
iframe.style.visibility = 'visible';
}

// redirect to URL
var redir = 'slackin-redirect:' + id + ':';
if (redir === e.data.substr(0, redir.length)) {
location.href = e.data.substr(redir.length);
}
});
}

Expand Down Expand Up @@ -126,6 +132,7 @@
ni.style.borderWidth = 0;
ni.src = iframe.src.replace('iframe', 'iframe/dialog');
ni.onload = function(){
setup(ni);
window.addEventListener('scroll', dposition);
window.addEventListener('resize', dposition);
position();
Expand Down
33 changes: 32 additions & 1 deletion lib/assets/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function invite(channel, coc, email, fn){
if (res.body.redirectUrl) {
var err = new Error(res.body.msg || 'Server error');
window.setTimeout(function() {
location.href = res.body.redirectUrl;
topLevelRedirect(res.body.redirectUrl);
}, 1500);
}
if (res.error) {
Expand Down Expand Up @@ -83,3 +83,34 @@ function anim(el, c){
el.anim = null;
}, 150);
}


// redirect, using "RPC" to parent if necessary
function topLevelRedirect(url) {
if (window === top) location.href = url;
else parent.postMessage('slackin-redirect:' + id + ':' + url, '*');
// Q: Why can't we just `top.location.href = url;`?
// A: Ah, the halcyon days, when scripts in iframes could just arbitrarily
// fuck with parent windows' globals. I'm afraid that in this day and
// age of [sandboxes][] and [Content Security Policies][CSP], it's all
// too common for meddling idiots to try to stop us from doing whatever
// we please with their globals---how dare they trample on our rights.
// I mean we're still allowed to do almost anything to their globals,
// the only global we're not allowed to change now is the location URL
// (seriously). I momentarily hoped that explicit permission from the
// parent of the iframe could ensure this privilege that we deserve of
// redirecting the parent, but [nope][].
//
// [sandboxing]: http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/
// [CSP]: http://www.html5rocks.com/en/tutorials/security/content-security-policy/
// [nope]: http://output.jsbin.com/popawuk/16
};

// "RPC" channel to parent
var id;
window.addEventListener('message', function onmsg(e){
if (/^slackin:/.test(e.data)) {
id = e.data.replace(/^slackin:/, '');
window.removeEventListener('message', onmsg);
}
});
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default function slackin({
let { name } = slack.org;
let { active, total } = slack.users;
if (!name) return res.send(404);
let dom = splash({ coc, path, name, channels, active, total, large, iframe: true });
let dom = splash({ coc, path, name, org, channels, active, total, large, iframe: true });
res.type('html');
res.send(dom.toHTML());
});
Expand Down
28 changes: 13 additions & 15 deletions lib/splash.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function splash({ path, name, org, coc, logo, active, total, chan
),
dom('button.loading', 'Get my Invite')
),
!iframe && dom('p.signin',
dom('p.signin',
'or ',
dom(`a href=https://${org}.slack.com target=_top`, 'sign in'),
'.'
Expand Down Expand Up @@ -300,22 +300,20 @@ function style({ logo, active, large, iframe } = {}){
});
}

if (!iframe) {
css.add('p.signin', {
'padding': '1rem 0 1rem',
'font-size': '1.1rem'
});
css.add('p.signin', {
'padding': '1rem 0 1rem',
'font-size': '1.1rem'
});

css.add('p.signin a', {
'color': pink,
'text-decoration': 'none'
});
css.add('p.signin a', {
'color': pink,
'text-decoration': 'none'
});

css.add('p.signin a:hover', {
'background-color': '#E01563',
color: '#fff'
});
}
css.add('p.signin a:hover', {
'background-color': '#E01563',
color: '#fff'
});

if (!iframe) {
css.add('footer', {
Expand Down

0 comments on commit 7305f36

Please sign in to comment.