lib/assets/badge.js
function setup (iframe){
    var id = Math.random() * (1 << 24) | 0
    iframe.contentWindow.postMessage('slackin:' + id, '*')
    window.addEventListener('message', function (e){
      if (typeof e.data !== 'string') return

      // show dialog upon click
      if ('slackin-click:' + id  === e.data) {
        showDialog(iframe)
      }

      // update width
      var wp = 'slackin-width:' + id + ':'
      if (wp === e.data.substr(0, wp.length)) {
        var width = e.data.substr(wp.length)
        iframe.style.width = width + 'px'

        // 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)
      }
    })
  }
function setup (iframe){
    var id = Math.random() * (1 << 24) | 0
    iframe.contentWindow.postMessage('slackin:' + id, '*')
    window.addEventListener('message', function (e){
      if (typeof e.data !== 'string') return

      // show dialog upon click
      if ('slackin-click:' + id  === e.data) {
        showDialog(iframe)
      }

      // update width
      var wp = 'slackin-width:' + id + ':'
      if (wp === e.data.substr(0, wp.length)) {
        var width = e.data.substr(wp.length)
        iframe.style.width = width + 'px'

        // 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)
      }
    })
  }
function setup ( iframe ) { var id = Math . random ( ) * ( 1 << 24 ) | 0 iframe . contentWindow . postMessage ( 'slackin:' + id , '*' ) window . addEventListener ( 'message' , function ( e ) { if ( typeof e . data !== 'string' ) return // show dialog upon click if ( 'slackin-click:' + id === e . data ) { showDialog ( iframe ) } // update width var wp = 'slackin-width:' + id + ':' if ( wp === e . data . substr ( 0 , wp . length ) ) { var width = e . data . substr ( wp . length ) iframe . style . width = width + 'px' // 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 ) } } ) }
setup an "RPC" channel between iframe and us
setup an RPC channel between iframe and us