Last active
August 29, 2015 14:20
-
-
Save azdle/9baa947268975bf3b855 to your computer and use it in GitHub Desktop.
Base64 Image in a Widget
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
// this is an example of using a base64 image in an exosite portals widget | |
function( container, portal ) | |
{ | |
// this is the actual image, you can generate this string on most | |
// mac/linux computers by using `base64 image.png` from the command line | |
var base64_image = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; | |
// helpful for debugging | |
console.log('widget refresh'); | |
// this just removes all child elements from the widget container to start fresh | |
$(container).empty(); | |
// here we're creating a new image element | |
$('<img/>', { | |
style: 'width:100%; height:100%', // that fills the widget container | |
src: 'data:image/png;base64,' + base64_image, // with the base64 image in png format | |
}).appendTo(container); // and appends it to the widget container | |
// in a real application you would append the image to an element inside your actual widget | |
// such as a table cell or list item | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment