Skip to content
Browse files

Moved segment widths overflow calculation from render delegate to the…

… view itself and removed 'sc-segment-view' css dependency from the caluclation.
  • Loading branch information...
1 parent 8c709f9 commit ed2b421ca51f41837fac4fbfd8f4e6570739b87b @hungle committed Jun 29, 2011
Showing with 58 additions and 58 deletions.
  1. +1 −51 frameworks/desktop/render_delegates/segmented.js
  2. +57 −7 frameworks/desktop/views/segmented.js
View
52 frameworks/desktop/render_delegates/segmented.js
@@ -25,56 +25,6 @@ SC.BaseTheme.segmentedRenderDelegate = SC.RenderDelegate.create({
update: function(dataSource, jquery) {
this.updateSizeClassName(dataSource, jquery);
jquery.css('text-align', dataSource.get('align'));
- },
-
- /**
- Return the widths of the DOM elements of the segments. This will be measured by the view to
- determine which segments should be overflowed.
-
- It ignores the last segment (the overflow segment).
- */
- segmentWidths: function(dataSource) {
- var elements = dataSource.$('.sc-segment-view'),
- el,
- widths = [];
-
- for (var i = 0, length = elements.length; i < length - 1; i++) {
- el = elements[i];
- widths[i] = el.getBoundingClientRect().width;
- }
-
- return widths;
- },
-
- overflowSegmentWidth: function(dataSource) {
- var elements = dataSource.$('.sc-segment-view'),
- el;
-
- el = elements[elements.length - 1];
-
- return el.getBoundingClientRect().width;
- },
-
- indexForClientPosition: function(dataSource, x, y) {
- var segmentLayers = dataSource.$('.sc-segment-view'),
- length, i,
- segmentLayer, rect,
- point;
-
- point = {x: x, y: y};
- for (i = 0, length = segmentLayers.length; i < length; i++) {
- segmentLayer = segmentLayers[i];
- rect = segmentLayer.getBoundingClientRect();
-
- // Convert client rect into standard rect
- // Remake the rect since IE8 won't let us modify the boundingClientRect
- rect = { x: rect.left, y: rect.top, width: (rect.right-rect.left), height: (rect.bottom - rect.top) };
-
- // Return the index early if found
- if (SC.pointInRect(point, rect)) return i;
- }
-
- // Default not found
- return -1;
}
+
});
View
64 frameworks/desktop/views/segmented.js
@@ -501,8 +501,8 @@ SC.SegmentedView = SC.View.extend(SC.Control,
childViews.objectAt(i).set('isVisible', YES);
}
- this.cachedWidths = renderDelegate.segmentWidths(this);
- this.cachedOverflowWidth = renderDelegate.overflowSegmentWidth(this);
+ this.cachedWidths = this.segmentWidths();
+ this.cachedOverflowWidth = this.overflowSegmentWidth();
this.adjustOverflow();
}
@@ -568,6 +568,60 @@ SC.SegmentedView = SC.View.extend(SC.Control,
this.cachedMinimumWidth = curElementsWidth + this.cachedOverflowWidth;
},
+ /**
+ Return the widths of the DOM elements of the segments. This will be measured by the view to
+ determine which segments should be overflowed.
+
+ It ignores the last segment (the overflow segment).
+ */
+ segmentWidths: function() {
+ var cv = this.get('childViews'),
+ v,
+ widths = [];
+
+ for (var i = 0, length = cv.length; i < length - 1; i++) {
+ v = cv[i];
+ widths[i] = v.get('frame').width;
+ }
+
+ return widths;
+ },
+
+ overflowSegmentWidth: function() {
+ var cv = this.get('childViews'),
+ v;
+
+ v = cv.length && cv[cv.length - 1];
+
+ return v ? v.get('frame').width : 0;
+ },
+
+ indexForClientPosition: function(x, y) {
+ var cv = this.get('childViews'),
+ length, i,
+ v, rect,
+ point;
+
+ point = {x: x, y: y};
+ for (i = 0, length = cv.length; i < length; i++) {
+ v = cv[i];
+
+ rect = v.get('layer').getBoundingClientRect();
+ rect = {
+ x: rect.left,
+ y: rect.top,
+ width: (rect.right-rect.left),
+ height: (rect.bottom - rect.top)
+ };
+
+ // Return the index early if found
+ if (SC.pointInRect(point, rect)) return i;
+ }
+
+ // Default not found
+ return -1;
+ },
+
// ..........................................................
// RENDERING/DISPLAY SUPPORT
//
@@ -594,11 +648,7 @@ SC.SegmentedView = SC.View.extend(SC.Control,
event occurred.
*/
displayItemIndexForEvent: function(evt) {
- var renderDelegate = this.get('renderDelegate');
-
- if (renderDelegate && renderDelegate.indexForClientPosition) {
- return renderDelegate.indexForClientPosition(this, evt.clientX, evt.clientY);
- }
+ return this.indexForClientPosition(evt.clientX, evt.clientY);
},
/** @private */

0 comments on commit ed2b421

Please sign in to comment.
Something went wrong with that request. Please try again.