Created
March 31, 2013 13:13
-
-
Save itzaks/5280559 to your computer and use it in GitHub Desktop.
Helper for embedding an iframe right after this script node. Also includes some css and javascript insert methods. Can limit the iframe to specific size.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Embed | |
| embedded: false | |
| width: 250 | |
| height: 250 | |
| name: "something" | |
| baseURL: "//s3-eu-west-1.amazonaws.com/some-bucket" | |
| constructor: (@script) -> | |
| @width = @script.width if @script.width | |
| @height = @script.height if @script.height | |
| @name = @script.id if @script.id | |
| @embed() | |
| embed: (object) -> | |
| @after @iframe() | |
| after: (dom) -> | |
| @script.parentNode.insertBefore dom, @script.nextSibling | |
| iframe: (object) -> | |
| url = [@baseURL, @name, ".html", '#', @width, 'x', @height].join("") | |
| iframe = document.createElement("IFRAME") | |
| iframe["src"] = url | |
| iframe["style"].width = @width + 'px' | |
| iframe["style"].height = @height + 'px' | |
| iframe["frameBorder"] = 0 | |
| iframe | |
| attachScripts: (sources) -> | |
| for plugin in sources | |
| ((source)-> | |
| script = document.createElement("script") | |
| script.setAttribute "src", source | |
| document.getElementsByTagName("body")[0].appendChild script | |
| )(plugin) | |
| attachStyles: (sources) -> | |
| for style in sources | |
| ((source)-> | |
| css = document.createElement("link") | |
| css.setAttribute "href", source | |
| document.getElementsByTagName("head")[0].appendChild css | |
| )(style) | |
| #attach it! | |
| arrScripts = document.getElementsByTagName('script') | |
| scriptTag = arrScripts[arrScripts.length - 1] | |
| new Embed scriptTag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment