Skip to content
Merged
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
12 changes: 8 additions & 4 deletions assets/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
"root": true,
"extends": "eslint-config-airbnb-base/legacy",
"rules": {
"camelcase": "off",
"camelcase": [
"error",
{
"allow": [
"^gcaptcha_"
]
}
],
"consistent-return": "off",
"eqeqeq": "off",
"func-names": "off",
"guard-for-in": "off",
"max-len": "off",
"no-bitwise": "off",
"no-continue": "off",
"no-multi-assign": "off",
"no-param-reassign": "off",
"no-plusplus": "off",
"no-prototype-builtins": "off",
"no-restricted-syntax": "off",
"no-shadow": "off",
"no-use-before-define": "off",
Expand Down
18 changes: 9 additions & 9 deletions assets/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
parent.removeChild(script)

// setup iframe RPC
iframe.onload = function () {
iframe.addEventListener('load', function () {
setup(iframe)
}
})
}

// setup an "RPC" channel between iframe and us
Expand All @@ -75,8 +75,8 @@

// update width
var wp = 'slackin-width:' + id + ':'
if (wp === e.data.substr(0, wp.length)) {
var width = e.data.substr(wp.length)
if (wp === e.data.slice(0, wp.length)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emedvedev can you confirm the slice changes are OK? I'm going through the diff after 1.1.11

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be the same in this case, yes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant all of the substr to slice changes, just to be safe :)

var width = e.data.slice(wp.length)
iframe.style.width = width + 'px'

// ensure it's shown (since first time hidden)
Expand All @@ -85,8 +85,8 @@

// redirect to URL
var redir = 'slackin-redirect:' + id + ':'
if (redir === e.data.substr(0, redir.length)) {
window.location.href = e.data.substr(redir.length) // lgtm [js/client-side-unvalidated-url-redirection]
if (redir === e.data.slice(0, redir.length)) {
window.location.href = e.data.slice(redir.length) // lgtm [js/client-side-unvalidated-url-redirection]
}
})
}
Expand Down Expand Up @@ -133,12 +133,12 @@
ni.style.height = '15.5em'
ni.style.borderWidth = 0
ni.src = iframe.src.replace('iframe', 'iframe/dialog')
ni.onload = function () {
ni.addEventListener('load', function () {
setup(ni)
window.addEventListener('scroll', dposition)
window.addEventListener('resize', dposition)
position()
}
})

// arrows
var a1 = document.createElement('div')
Expand Down Expand Up @@ -235,7 +235,7 @@
}

function click(ev) {
if (ev.target.className != '__slackin') {
if (ev.target.className !== '__slackin') {
hide()
}
}
Expand Down
12 changes: 8 additions & 4 deletions assets/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ url.href = window.location
// realtime updates
var socket = io({ path: data.path + 'socket.io' })
socket.on('data', function (users) {
for (var i in users) update(i, users[i])
for (var i in users) {
if (Object.prototype.hasOwnProperty.call(users, i)) {
update(i, users[i])
}
}
})
socket.on('total', function (n) { update('total', n) })
socket.on('active', function (n) { update('active', n) })

function update(val, n) {
var el = document.querySelector('.' + val)
if (el && el.textContent != n) {
if (el && el.textContent !== n) {
el.textContent = n
anim(el, val)
}
Expand Down Expand Up @@ -112,8 +116,8 @@ window.addEventListener('message', function onmsg(e) {
}
})

body.onload = function () {
body.addEventListener('load', function () {
if (window.location.hash) {
body.querySelector('select[name=channel]').value = window.location.hash.slice(1)
}
}
})
16 changes: 10 additions & 6 deletions assets/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
id = e.data.replace(/^slackin:/, '')
document.body.addEventListener('click', function (ev) {
var el = ev.target
while (el && el.nodeName != 'A') el = el.parentNode
while (el && el.nodeName !== 'A') el = el.parentNode
if (el && el.target === '_blank') {
ev.preventDefault()
window.parent.postMessage('slackin-click:' + id, '*')
Expand All @@ -36,7 +36,7 @@
var button = document.querySelector('.slack-button')
var lastWidth
function refresh() {
if (window != window.top && window.postMessage) {
if (window !== window.top && window.postMessage) {
var width = Math.ceil(button.getBoundingClientRect().width)
if (lastWidth !== width) {
lastWidth = width
Expand All @@ -48,22 +48,26 @@
// initialize realtime events asynchronously
var script = document.createElement('script')
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.4/socket.io.slim.min.js'
script.onload = function () {
script.addEventListener('load', function () {
// use dom element for better cross browser compatibility
var url = document.createElement('a')
url.href = window.location
var socket = io({ path: data.path + 'socket.io' })
var count = document.querySelector('.slack-count')

socket.on('data', function (users) {
for (var i in users) update(i, users[i])
for (var i in users) {
if (Object.prototype.hasOwnProperty.call(users, i)) {
update(i, users[i])
}
}
})
socket.on('total', function (n) { update('total', n) })
socket.on('active', function (n) { update('active', n) })

var anim
function update(key, n) {
if (data[key] != n) {
if (data[key] !== n) {
data[key] = n
var str = ''
if (data.active) str = data.active + '/'
Expand All @@ -78,6 +82,6 @@
refresh()
}
}
}
})
document.body.appendChild(script)
}())
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function slackin({
let channelsFiltered;
if (channels) {
channelsFiltered = channels.split(',').map((channel) => (
channel.startsWith('#') ? channel.substr(1) : channel
channel.startsWith('#') ? channel.slice(1) : channel
));
}

Expand Down