Skip to content

Instantly share code, notes, and snippets.

@hussfelt
Last active October 13, 2022 07:03
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hussfelt/a6fe71ebd7cce327df29 to your computer and use it in GitHub Desktop.
Save hussfelt/a6fe71ebd7cce327df29 to your computer and use it in GitHub Desktop.
Dashing widget to display an iframe with specified src

dashing-iframe

IFrame plugin for dashing

Description

Dashing widget to display an iframe with specified src

Installation

Create the folder iframe in the /widgets/ directory. Put the files iframe.coffee, iframe.html and iframe.scss in that folder.

This can also be done by using the gist: https://gist.github.com/hussfelt/a6fe71ebd7cce327df29

dashing install a6fe71ebd7cce327df29

Dashboard configuration

Put the following in your dashboard.erb file to show the iframe:

    <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
      <div data-id="iframeId1" data-view="Iframe"></div>
    </li>

Updating the src

Curl

curl -d '{
	"auth_token": "YOUR_AUTH_TOKEN",
	"src": "http://example.com/"
}' http://0.0.0.0:3030/widgets/iframeId1

Inline

    <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
      <div data-id="iframeId1" data-view="Iframe" data-src="http://example.com/"></div>
    </li>

License

Distributed under the MIT license

class Dashing.Iframe extends Dashing.Widget
ready: ->
$(@node).find(".iframe").attr('src', @get('src'))
onData: (data) ->
$(@node).find(".iframe").attr('src', data.src)
<iframe class="iframe" data-bind-src="src" scrolling="no"></iframe>
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #FFF;
$title-color: #333;
$moreinfo-color: #333;
$iframe-background: darken($background-color, 25%);
// ----------------------------------------------------------------------------
// Widget-iframe styles
// ----------------------------------------------------------------------------
.widget-iframe {
background-color: $background-color;
padding: 0 !important;
margin: 0 !important;
iframe {
width: 100%;
height: 100%;
border: 0;
padding: 0;
margin: 0;
overflow: hidden;
}
}
@snayler0
Copy link

snayler0 commented Sep 7, 2015

This widget doesn't allow me to drag and drop like others.

Has anyone worked out a way around this?

@rcaudill
Copy link

rcaudill commented Sep 9, 2015

@snayler0
I bumped up the .widget-iframe padding (to 10px) in iframe.scss and it gives you something to grab on to when rearranging.

@hussfelt
Copy link
Author

hussfelt commented Nov 5, 2015

Thanks @rcaudill!

Did you do this:

.widget-iframe {

  background-color: $background-color;
  padding: 10px !important;
  margin: 0 !important;
...

Let me know and I'll adjust!

@DeanCording
Copy link

I'm having a problem with the contents of the iframe being truncated in height - see attached image.
dd3

I haven't been able to find where the height of the iframe is set.

This is in Firefox 44.0 on Kubuntu 15.10

@DeanCording
Copy link

Yay, height problem solved. In Firefox, height: 100% only works properly if the parent container has a specified height. To fix this, change the iframe.scss to specify:

.widget-iframe {
  background-color: $background-color;
  padding: 10px !important;
  margin: 0 !important;
  height: 100%;

@Mabdylon
Copy link

Mabdylon commented Nov 3, 2016

For those who try copy/paste inline example without success, here is the small thing to change :

<div data-id="iframeId1" data-view="Iframe" data-src="http://example.com/"></div>

to :

<div data-id="iframeId1" data-view="Iframe" data-url="http://example.com/"></div>

data-url is expected, not data-src.

Thx for this plugin !

@orphee
Copy link

orphee commented Feb 2, 2017

data-url is expected, not data-src.

Thanks Mabdylon !

@matzelkoenig
Copy link

The HTTP API does not work. I am not firm with Ruby, BatmanBinding and all that stuff. Please help!

curl -d '{
	"auth_token": "YOUR_AUTH_TOKEN",
	"src": "http://example.com/"
}' http://0.0.0.0:3030/widgets/iframeId1

@JonnoN
Copy link

JonnoN commented Jan 22, 2018

@matzelkoenig took me a while, but I figured it out:

curl -d '{ "auth_token": "YOUR_AUTH_TOKEN", "url": "http://example.com" }' http://localhost:3030/widgets/iframeId1

@borisv1979
Copy link

Is it possible to pass username and password directly via URL for password protected websites ? http://username:password@websiteurl.com doesn't work.

@E-Kelly2018
Copy link

what auth token is used for this is a git hub or what

@manikandanselva
Copy link

manikandanselva commented May 20, 2019

which file or which place add curl code?

curl -d '{
"auth_token": "YOUR_AUTH_TOKEN",
"src": "http://example.com/"
}' http://0.0.0.0:3030/widgets/iframeId1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment