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 /**
 10   Renders and updates the HTML representation of a segment child view within
 11   SC.SegmentedView.
 12 */
 13 SC.BaseTheme.segmentRenderDelegate = SC.RenderDelegate.create({
 14   className: 'segment',
 15 
 16   render: function (dataSource, context) {
 17     var theme = dataSource.get('theme'),
 18         buttonDelegate,
 19         classes;
 20 
 21     // Segment specific additions
 22     classes = {
 23       'sc-first-segment': dataSource.get('isFirstSegment'),
 24       'sc-middle-segment': dataSource.get('isMiddleSegment'),
 25       'sc-last-segment': dataSource.get('isLastSegment'),
 26       'sc-overflow-segment': dataSource.get('isOverflowSegment'),
 27       'vertical': dataSource.get('layoutDirection') !== SC.LAYOUT_HORIZONTAL
 28     };
 29 
 30     if (!SC.none(dataSource.get('index'))) classes['sc-segment-' + dataSource.get('index')] = YES;
 31     context.setClass(classes);
 32 
 33     // Use the SC.ButtonView render delegate for the current theme to render the segment as a button
 34     buttonDelegate = theme.buttonRenderDelegate;
 35     buttonDelegate.render(dataSource, context);
 36   },
 37 
 38   update: function (dataSource, jquery) {
 39     var theme = dataSource.get('theme'),
 40         buttonDelegate,
 41         classes = {};
 42 
 43     // Segment specific additions
 44     classes = {
 45       'sc-first-segment': dataSource.get('isFirstSegment'),
 46       'sc-middle-segment': dataSource.get('isMiddleSegment'),
 47       'sc-last-segment': dataSource.get('isLastSegment'),
 48       'sc-overflow-segment': dataSource.get('isOverflowSegment') || NO,
 49       'vertical': dataSource.get('layoutDirection') !== SC.LAYOUT_HORIZONTAL
 50     };
 51     if (!SC.none(dataSource.get('index'))) classes['sc-segment-' + dataSource.get('index')] = YES;
 52     jquery.setClass(classes);
 53 
 54     // Use the SC.ButtonView render delegate for the current theme to update the segment as a button
 55     buttonDelegate = theme.buttonRenderDelegate;
 56     buttonDelegate.update(dataSource, jquery);
 57   }
 58 
 59 });
 60