1 // ========================================================================== 2 // Project: SproutCore - JavaScript Application Framework 3 // Copyright: ©2006-2011 Strobe Inc. and contributors. 4 // Portions ©2008-2011 Apple Inc. All rights reserved. 5 // License: Licensed under MIT license (see license.js) 6 // ========================================================================== 7 8 9 SC.BaseTheme.imageButtonRenderDelegate = SC.RenderDelegate.create({ 10 className: 'image-button', 11 12 render: function (dataSource, context) { 13 var image = dataSource.get('image'), 14 toolTip = dataSource.get('toolTip'); 15 16 // render controlSize 17 this.addSizeClassName(dataSource, context); 18 19 if (toolTip) { 20 context.setAttr('title', toolTip); 21 context.setAttr('alt', toolTip); 22 } 23 24 if (image) { 25 context.addClass(image); 26 27 // Track the image class used so that we can remove it when it changes. 28 dataSource.renderState._cachedImage = image; 29 } 30 }, 31 32 update: function (dataSource, jqElement) { 33 var image, toolTip; 34 35 this.updateSizeClassName(dataSource, jqElement); 36 37 if (dataSource.didChangeFor('imageButtonRenderDelegate', 'toolTip')) { 38 toolTip = dataSource.get('toolTip'); 39 40 jqElement.attr('title', toolTip); 41 jqElement.attr('alt', toolTip); 42 } 43 44 if (dataSource.didChangeFor('imageButtonRenderDelegate', 'image')) { 45 image = dataSource.get('image'); 46 47 // Remove the last image class 48 if (dataSource.renderState._cachedImage) { 49 jqElement.removeClass(dataSource.renderState._cachedImage); 50 } 51 52 if (image) { 53 jqElement.addClass(image); 54 55 // Track the image class used so that we can remove it when it changes. 56 dataSource.renderState._cachedImage = image; 57 } 58 } 59 } 60 }); 61