//----------------------------------------------------------------------------1// Copyright (C) 2013 The IPython Development Team2//3// Distributed under the terms of the BSD License. The full license is in4// the file COPYING, distributed as part of this software.5//----------------------------------------------------------------------------67//============================================================================8// ImageWidget9//============================================================================1011/**12* @module IPython13* @namespace IPython14**/1516define(["widgets/js/widget"], function(WidgetManager){1718var ImageView = IPython.DOMWidgetView.extend({19render : function(){20// Called when view is rendered.21this.setElement($("<img />"));22this.update(); // Set defaults.23},2425update : function(){26// Update the contents of this view27//28// Called when the model is changed. The model may have been29// changed by another view or by a state update from the back-end.30var image_src = 'data:image/' + this.model.get('format') + ';base64,' + this.model.get('_b64value');31this.$el.attr('src', image_src);3233var width = this.model.get('width');34if (width !== undefined && width.length > 0) {35this.$el.attr('width', width);36} else {37this.$el.removeAttr('width');38}3940var height = this.model.get('height');41if (height !== undefined && height.length > 0) {42this.$el.attr('height', height);43} else {44this.$el.removeAttr('height');45}46return ImageView.__super__.update.apply(this);47},48});49WidgetManager.register_widget_view('ImageView', ImageView);50});515253