sproutcore 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +233 -0
- data/Manifest.txt +67 -34
- data/bin/sc-build +12 -1
- data/bin/sc-gen +1 -1
- data/bin/sproutcore +14 -0
- data/clients/sc_docs/controllers/docs.js +38 -8
- data/clients/sc_docs/english.lproj/body.css +80 -127
- data/clients/sc_docs/english.lproj/body.rhtml +43 -23
- data/clients/sc_docs/english.lproj/no_docs.rhtml +2 -1
- data/clients/sc_docs/english.lproj/tabs.rhtml +16 -0
- data/clients/sc_docs/main.js +14 -9
- data/clients/sc_docs/models/doc.js +1 -1
- data/clients/sc_docs/tests/controllers/docs.rhtml +1 -2
- data/clients/sc_docs/tests/models/doc.rhtml +1 -2
- data/clients/sc_docs/tests/views/doc_frame.rhtml +1 -2
- data/clients/sc_docs/tests/views/doc_label_view.rhtml +1 -2
- data/clients/sc_docs/views/doc_frame.js +1 -1
- data/clients/sc_test_runner/controllers/runner.js +31 -8
- data/clients/sc_test_runner/english.lproj/body.css +62 -122
- data/clients/sc_test_runner/english.lproj/body.rhtml +62 -26
- data/clients/sc_test_runner/main.js +1 -6
- data/clients/sc_test_runner/models/test.js +14 -1
- data/clients/sc_test_runner/views/runner_frame.js +4 -2
- data/clients/view_builder/builders/builder.js +339 -0
- data/clients/view_builder/builders/button.js +81 -0
- data/clients/view_builder/controllers/document.js +21 -0
- data/clients/view_builder/core.js +19 -0
- data/clients/view_builder/english.lproj/body.css +77 -0
- data/clients/view_builder/english.lproj/body.rhtml +41 -0
- data/clients/{sc_docs → view_builder}/english.lproj/controls.css +0 -0
- data/clients/view_builder/english.lproj/strings.js +14 -0
- data/clients/view_builder/main.js +38 -0
- data/clients/view_builder/tests/controllers/document.rhtml +20 -0
- data/clients/view_builder/tests/views/builder.rhtml +20 -0
- data/clients/view_builder/views/builder.js +23 -0
- data/frameworks/prototype/prototype.js +1 -1
- data/frameworks/sproutcore/Core.js +32 -7
- data/frameworks/sproutcore/README +1 -1
- data/frameworks/sproutcore/animation/animation.js +411 -0
- data/frameworks/sproutcore/controllers/array.js +17 -9
- data/frameworks/sproutcore/controllers/collection.js +9 -110
- data/frameworks/sproutcore/controllers/controller.js +1 -1
- data/frameworks/sproutcore/controllers/object.js +2 -1
- data/frameworks/sproutcore/drag/drag.js +267 -56
- data/frameworks/sproutcore/drag/drag_data_source.js +24 -16
- data/frameworks/sproutcore/drag/drag_source.js +53 -42
- data/frameworks/sproutcore/drag/drop_target.js +2 -2
- data/frameworks/sproutcore/english.lproj/buttons.css +337 -236
- data/frameworks/sproutcore/english.lproj/core.css +115 -0
- data/frameworks/sproutcore/english.lproj/icons.css +227 -0
- data/{clients/sc_docs → frameworks/sproutcore}/english.lproj/images/indicator.gif +0 -0
- data/frameworks/sproutcore/english.lproj/images/sc-theme-sprite.png +0 -0
- data/frameworks/sproutcore/english.lproj/images/sc-theme-ysprite.png +0 -0
- data/frameworks/sproutcore/english.lproj/images/shared-icons.png +0 -0
- data/frameworks/sproutcore/english.lproj/menu.css +1 -1
- data/frameworks/sproutcore/english.lproj/strings.js +1 -1
- data/frameworks/sproutcore/english.lproj/theme.css +405 -31
- data/frameworks/sproutcore/foundation/application.js +15 -11
- data/frameworks/sproutcore/foundation/benchmark.js +1 -1
- data/frameworks/sproutcore/foundation/binding.js +2 -2
- data/frameworks/sproutcore/foundation/date.js +1 -1
- data/frameworks/sproutcore/foundation/error.js +1 -1
- data/frameworks/sproutcore/foundation/input_manager.js +32 -21
- data/frameworks/sproutcore/foundation/mock.js +1 -1
- data/frameworks/sproutcore/foundation/node_descriptor.js +9 -6
- data/frameworks/sproutcore/foundation/object.js +249 -177
- data/frameworks/sproutcore/foundation/page.js +5 -2
- data/frameworks/sproutcore/foundation/path_module.js +11 -10
- data/frameworks/sproutcore/foundation/responder.js +5 -2
- data/frameworks/sproutcore/foundation/routes.js +17 -13
- data/frameworks/sproutcore/foundation/run_loop.js +249 -11
- data/frameworks/sproutcore/foundation/server.js +1 -1
- data/frameworks/sproutcore/foundation/set.js +3 -3
- data/frameworks/sproutcore/foundation/string.js +5 -3
- data/frameworks/sproutcore/foundation/timer.js +371 -0
- data/frameworks/sproutcore/foundation/undo_manager.js +1 -1
- data/frameworks/sproutcore/foundation/unittest.js +3 -3
- data/frameworks/sproutcore/foundation/utils.js +161 -2
- data/frameworks/sproutcore/globals/panels.js +1 -1
- data/frameworks/sproutcore/globals/popups.js +4 -3
- data/frameworks/sproutcore/globals/window.js +44 -4
- data/frameworks/sproutcore/lib/button_views.rb +328 -0
- data/frameworks/sproutcore/lib/collection_view.rb +80 -0
- data/frameworks/sproutcore/lib/core_views.rb +281 -0
- data/frameworks/sproutcore/lib/form_views.rb +253 -0
- data/frameworks/sproutcore/lib/index.rhtml +2 -0
- data/frameworks/sproutcore/lib/menu_views.rb +88 -0
- data/frameworks/sproutcore/{foundation → mixins}/array.js +60 -29
- data/frameworks/sproutcore/mixins/control.js +265 -0
- data/frameworks/sproutcore/mixins/delegate_support.js +66 -0
- data/frameworks/sproutcore/{foundation → mixins}/observable.js +176 -6
- data/frameworks/sproutcore/mixins/scrollable.js +245 -0
- data/frameworks/sproutcore/mixins/selection_support.js +148 -0
- data/frameworks/sproutcore/mixins/validatable.js +152 -0
- data/frameworks/sproutcore/models/collection.js +5 -5
- data/frameworks/sproutcore/models/record.js +1 -1
- data/frameworks/sproutcore/models/store.js +1 -1
- data/frameworks/sproutcore/panes/dialog.js +1 -1
- data/frameworks/sproutcore/panes/manager.js +1 -1
- data/frameworks/sproutcore/panes/menu.js +1 -1
- data/frameworks/sproutcore/panes/overlay.js +2 -2
- data/frameworks/sproutcore/panes/panel.js +1 -1
- data/frameworks/sproutcore/panes/picker.js +1 -1
- data/frameworks/sproutcore/tests/controllers/array.rhtml +44 -4
- data/frameworks/sproutcore/tests/foundation/timer/invalidate.rhtml +33 -0
- data/frameworks/sproutcore/tests/foundation/timer/invokeLater.rhtml +145 -0
- data/frameworks/sproutcore/tests/foundation/timer/isPaused.rhtml +70 -0
- data/frameworks/sproutcore/tests/foundation/timer/schedule.rhtml +145 -0
- data/frameworks/sproutcore/tests/views/{scroll.rhtml → checkbox.rhtml} +3 -3
- data/frameworks/sproutcore/tests/views/{collection.rhtml → collection/base.rhtml} +33 -32
- data/frameworks/sproutcore/tests/views/collection/incremental_rendering.rhtml +260 -0
- data/frameworks/sproutcore/tests/views/image_cell.rhtml +19 -0
- data/frameworks/sproutcore/tests/views/label_item.rhtml +2 -4
- data/frameworks/sproutcore/tests/views/list.rhtml +2 -3
- data/frameworks/sproutcore/tests/views/list_item.rhtml +20 -0
- data/frameworks/sproutcore/tests/views/slider.rhtml +20 -0
- data/frameworks/sproutcore/tests/views/text_cell.rhtml +19 -0
- data/frameworks/sproutcore/tests/views/view/clippingFrame.rhtml +395 -0
- data/frameworks/sproutcore/tests/views/view/frame.rhtml +353 -0
- data/frameworks/sproutcore/tests/views/view/innerFrame.rhtml +347 -0
- data/frameworks/sproutcore/tests/views/view/isVisibleInWindow.rhtml +148 -0
- data/frameworks/sproutcore/tests/views/view/scrollFrame.rhtml +468 -0
- data/frameworks/sproutcore/validators/credit_card.js +33 -13
- data/frameworks/sproutcore/validators/date.js +26 -6
- data/frameworks/sproutcore/validators/email.js +21 -3
- data/frameworks/sproutcore/validators/not_empty.js +11 -1
- data/frameworks/sproutcore/validators/number.js +18 -4
- data/frameworks/sproutcore/validators/password.js +12 -1
- data/frameworks/sproutcore/validators/validator.js +204 -194
- data/frameworks/sproutcore/views/{button.js → button/button.js} +96 -94
- data/frameworks/sproutcore/views/button/checkbox.js +29 -0
- data/frameworks/sproutcore/views/button/disclosure.js +42 -0
- data/frameworks/sproutcore/views/button/radio.js +29 -0
- data/frameworks/sproutcore/views/{collection.js → collection/collection.js} +1373 -1024
- data/frameworks/sproutcore/views/collection/grid.js +124 -46
- data/frameworks/sproutcore/views/collection/image_cell.js +17 -46
- data/frameworks/sproutcore/views/collection/list.js +45 -35
- data/frameworks/sproutcore/views/collection/source_list.js +386 -0
- data/frameworks/sproutcore/views/collection/table.js +118 -0
- data/frameworks/sproutcore/views/container.js +7 -2
- data/frameworks/sproutcore/views/error_explanation.js +23 -10
- data/frameworks/sproutcore/views/{checkbox_field.js → field/checkbox_field.js} +16 -6
- data/frameworks/sproutcore/views/field/field.js +219 -0
- data/frameworks/sproutcore/views/{radio_field.js → field/radio_field.js} +27 -12
- data/frameworks/sproutcore/views/{select_field.js → field/select_field.js} +116 -90
- data/frameworks/sproutcore/views/{text_field.js → field/text_field.js} +57 -8
- data/frameworks/sproutcore/views/{textarea_field.js → field/textarea_field.js} +13 -3
- data/frameworks/sproutcore/views/filter_button.js +2 -2
- data/frameworks/sproutcore/views/form.js +3 -3
- data/frameworks/sproutcore/views/image.js +128 -21
- data/frameworks/sproutcore/views/inline_text_editor.js +1 -1
- data/frameworks/sproutcore/views/label.js +149 -92
- data/frameworks/sproutcore/views/list_item.js +225 -0
- data/frameworks/sproutcore/views/menu_item.js +10 -4
- data/frameworks/sproutcore/views/pagination.js +11 -4
- data/frameworks/sproutcore/views/popup_button.js +25 -21
- data/frameworks/sproutcore/views/popup_menu.js +10 -4
- data/frameworks/sproutcore/views/progress.js +29 -16
- data/frameworks/sproutcore/views/radio_group.js +1 -1
- data/frameworks/sproutcore/views/scroll.js +60 -20
- data/frameworks/sproutcore/views/segmented.js +1 -1
- data/frameworks/sproutcore/views/slider.js +132 -0
- data/frameworks/sproutcore/views/source_list_group.js +130 -0
- data/frameworks/sproutcore/views/spinner.js +1 -1
- data/frameworks/sproutcore/views/split.js +292 -0
- data/frameworks/sproutcore/views/split_divider.js +109 -0
- data/frameworks/sproutcore/views/tab.js +1 -1
- data/frameworks/sproutcore/views/toolbar.js +1 -1
- data/frameworks/sproutcore/views/view.js +1272 -591
- data/generators/client/templates/english.lproj/body.css +1 -1
- data/generators/controller/controller_generator.rb +1 -1
- data/generators/controller/templates/test.rhtml +2 -1
- data/generators/model/templates/test.rhtml +1 -1
- data/generators/test/templates/test.rhtml +1 -1
- data/generators/view/templates/test.rhtml +1 -1
- data/jsdoc/templates/sproutcore/class.tmpl +241 -338
- data/jsdoc/templates/sproutcore/default.css +105 -155
- data/jsdoc/templates/sproutcore/index.tmpl +43 -8
- data/jsdoc/templates/sproutcore/publish.js +9 -4
- data/lib/sproutcore/build_tools/html_builder.rb +29 -13
- data/lib/sproutcore/build_tools/resource_builder.rb +1 -1
- data/lib/sproutcore/bundle.rb +86 -25
- data/lib/sproutcore/jsdoc.rb +2 -0
- data/lib/sproutcore/version.rb +1 -1
- data/lib/sproutcore/view_helpers.rb +36 -3
- data/tasks/deployment.rake +1 -1
- metadata +69 -36
- data/clients/sc_docs/english.lproj/icons/small/next.png +0 -0
- data/clients/sc_docs/english.lproj/icons/small/reset.png +0 -0
- data/clients/sc_docs/english.lproj/images/gradients.png +0 -0
- data/clients/sc_docs/english.lproj/images/toolbar.png +0 -0
- data/clients/sc_docs/english.lproj/warning.rhtml +0 -6
- data/clients/sc_test_runner/english.lproj/warning.rhtml +0 -6
- data/frameworks/sproutcore/english.lproj/buttons.png +0 -0
- data/frameworks/sproutcore/english.lproj/collections.css +0 -82
- data/frameworks/sproutcore/english.lproj/images/buttons-sprite.png +0 -0
- data/frameworks/sproutcore/views/collection/collection_item.js +0 -36
- data/frameworks/sproutcore/views/collection/text_cell.js +0 -128
- data/frameworks/sproutcore/views/field.js +0 -214
- data/frameworks/sproutcore/views/workspace.js +0 -170
- data/generators/client/templates/english.lproj/controls.css +0 -0
- data/generators/framework/templates/english.lproj/body.css +0 -0
- data/generators/framework/templates/english.lproj/body.rhtml +0 -3
- data/generators/framework/templates/english.lproj/controls.css +0 -0
- data/lib/sproutcore/view_helpers/button_views.rb +0 -302
- data/lib/sproutcore/view_helpers/core_views.rb +0 -292
- data/lib/sproutcore/view_helpers/form_views.rb +0 -258
- data/lib/sproutcore/view_helpers/menu_views.rb +0 -94
@@ -2,8 +2,8 @@
|
|
2
2
|
// SC.GridView
|
3
3
|
// ==========================================================================
|
4
4
|
|
5
|
-
require('views/collection') ;
|
6
|
-
require('views/
|
5
|
+
require('views/collection/collection') ;
|
6
|
+
require('views/label');
|
7
7
|
|
8
8
|
/** @class
|
9
9
|
|
@@ -37,76 +37,150 @@ SC.GridView = SC.CollectionView.extend(
|
|
37
37
|
|
38
38
|
You can override this as you wish.
|
39
39
|
*/
|
40
|
-
exampleView: SC.
|
40
|
+
exampleView: SC.LabelView,
|
41
41
|
|
42
42
|
insertionOrientation: SC.HORIZONTAL_ORIENTATION,
|
43
|
+
|
44
|
+
// computed function for keyboard handling.
|
45
|
+
itemsPerRow: function() {
|
46
|
+
var ret = this._computeItemsPerRow() ;
|
47
|
+
console.log('ret = %@'.fmt(ret)) ;
|
48
|
+
return ret ;
|
49
|
+
}.property(),
|
50
|
+
|
51
|
+
/**
|
52
|
+
Calculates the number of items per row.
|
53
|
+
*/
|
54
|
+
_computeItemsPerRow: function() {
|
55
|
+
var f = this.get('innerFrame') ;
|
56
|
+
var columnWidth = this.get('columnWidth') || 0 ;
|
57
|
+
return (columnWidth <= 0) ? 1 : Math.floor(f.width / columnWidth) ;
|
58
|
+
},
|
59
|
+
|
60
|
+
/** @private
|
61
|
+
Find the contentRange to display in the passed frame. Note that we
|
62
|
+
ignore the width of the frame passed since we need to have a single
|
63
|
+
contiguous range.
|
64
|
+
*/
|
65
|
+
contentRangeInFrame: function(frame) {
|
66
|
+
var rowHeight = this.get('rowHeight') || 48 ;
|
67
|
+
var itemsPerRow = this._computeItemsPerRow() ;
|
68
|
+
|
69
|
+
var min = Math.floor(SC.minY(frame) / rowHeight) * itemsPerRow ;
|
70
|
+
var max = Math.ceil(SC.maxY(frame) / rowHeight) * itemsPerRow ;
|
71
|
+
var ret = { start: min, length: max - min } ;
|
72
|
+
//console.log('contentRangeInFrame(%@) = %@'.fmt($H(frame).inspect(), $H(ret).inspect()));
|
73
|
+
//if (frame.height < 100) debugger ;
|
74
|
+
return ret ;
|
75
|
+
},
|
76
|
+
|
77
|
+
layoutItemView: function(itemView, contentIndex, firstLayout) {
|
78
|
+
if (!itemView) debugger ;
|
79
|
+
SC.Benchmark.start('SC.GridView.layoutItemViewsFor') ;
|
80
|
+
|
81
|
+
var rowHeight = this.get('rowHeight') || 0 ;
|
82
|
+
var parentView = itemView.get('parentView') ;
|
83
|
+
var frameWidth = this.get('innerFrame').width ;
|
84
|
+
var itemsPerRow = this._computeItemsPerRow() ;
|
85
|
+
var columnWidth = Math.floor(frameWidth/itemsPerRow);
|
86
|
+
|
87
|
+
var row = Math.floor(contentIndex / itemsPerRow) ;
|
88
|
+
var col = contentIndex - (itemsPerRow*row) ;
|
89
|
+
var f = {
|
90
|
+
x: col * columnWidth, y: row * rowHeight,
|
91
|
+
height: rowHeight, width: columnWidth
|
92
|
+
};
|
93
|
+
|
94
|
+
if (firstLayout || !SC.rectsEqual(itemView.get('frame'), f)) {
|
95
|
+
itemView.set('frame', f) ;
|
96
|
+
}
|
97
|
+
SC.Benchmark.end('SC.GridView.layoutItemViewsFor') ;
|
98
|
+
},
|
99
|
+
|
100
|
+
computeFrame: function() {
|
101
|
+
var content = this.get('content') ;
|
102
|
+
var rows = (content) ? content.get('length') : 0 ;
|
103
|
+
var rowHeight = this.get('rowHeight') || 20 ;
|
104
|
+
|
105
|
+
var parent = this.get('parentNode') ;
|
106
|
+
var f = (parent) ? parent.get('innerFrame') : { width: 100, height: 100 } ;
|
107
|
+
|
108
|
+
f.x = f.y = 0;
|
109
|
+
f.height = Math.max(f.height, rows * rowHeight) ;
|
110
|
+
// console.log('computeFrame(%@)'.fmt($H(f).inspect())) ;
|
111
|
+
return f ;
|
112
|
+
},
|
43
113
|
|
114
|
+
|
44
115
|
/** @private */
|
45
|
-
|
116
|
+
layoutItemViewsFor: function(parentView, startingView) {
|
117
|
+
SC.Benchmark.start('SC.GridView.layoutItemViewsFor') ;
|
118
|
+
|
46
119
|
var rowHeight = this.get('rowHeight') ;
|
47
120
|
var columnWidth = this.get('columnWidth') ;
|
48
121
|
if ((rowHeight == null) || (columnWidth == null)) return false ;
|
49
122
|
|
50
123
|
// set items per row.
|
51
124
|
parentView = parentView || this ;
|
52
|
-
var f = parentView.get('
|
125
|
+
var f = parentView.get('innerFrame') ;
|
53
126
|
f.x= f.y = 0 ;
|
54
127
|
var itemsPerRow = Math.floor(f.width / (columnWidth || 1)) ;
|
55
128
|
if (this.get('itemsPerRow') != itemsPerRow) this.set('itemsPerRow', itemsPerRow);
|
56
129
|
|
57
130
|
// fix width to evenly match items per row
|
58
|
-
columnWidth = Math.floor(f.width/itemsPerRow) ;
|
131
|
+
columnWidth = Math.floor((f.width-20)/itemsPerRow) ;
|
59
132
|
|
60
|
-
// get the startingView and the starting
|
61
|
-
|
62
|
-
var
|
63
|
-
|
64
|
-
|
65
|
-
x = SC.maxX(prevFrame); y = SC.minY(prevFrame) ;
|
66
|
-
} else { x = f.x; y = f.y; }
|
133
|
+
// get the startingView and the starting row, col
|
134
|
+
var view = startingView || parentView.firstChild;
|
135
|
+
var content = this.get('content') || [] ;
|
136
|
+
var idx = (view) ? content.indexOf(view.get('content')) : 0;
|
137
|
+
|
67
138
|
|
68
|
-
// Now setup the default frame
|
69
|
-
var maxX = SC.maxX(f);
|
70
|
-
var minX = f.x;
|
71
139
|
f = { x: 0, y: 0, height: rowHeight, width: columnWidth } ;
|
72
|
-
|
140
|
+
|
73
141
|
while(view) {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
// save frame
|
81
|
-
view.set('isPositioned', true) ;
|
82
|
-
f.y = y ; f.x = x;
|
142
|
+
|
143
|
+
// calculate position.
|
144
|
+
var row = Math.floor(idx / itemsPerRow) ;
|
145
|
+
var col = idx - (row * itemsPerRow) ;
|
146
|
+
f.x = col * columnWidth; f.y = row * rowHeight ;
|
147
|
+
|
83
148
|
if (!SC.rectsEqual(view.get('frame'), f)) view.set('frame', f) ;
|
84
|
-
|
149
|
+
|
150
|
+
// go to next one
|
85
151
|
view = view.nextSibling ;
|
152
|
+
idx++ ;
|
86
153
|
}
|
154
|
+
|
155
|
+
SC.Benchmark.end('SC.GridView.layoutItemViewsFor') ;
|
156
|
+
|
87
157
|
return true;
|
88
158
|
},
|
89
159
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
160
|
+
computeFrame: function() {
|
161
|
+
var content = this.get('content') ;
|
162
|
+
var count = (content) ? content.get('length') : 0 ;
|
163
|
+
var rowHeight = this.get('rowHeight') || 0 ;
|
164
|
+
var columnWidth = this.get('columnWidth') || 0 ;
|
165
|
+
|
166
|
+
var parent = this.get('parentNode') ;
|
167
|
+
var f = (parent) ? parent.get('innerFrame') : { width: 0, height: 0 };
|
168
|
+
var itemsPerRow = (columnWidth <= 0) ? 1 : (f.width / columnWidth) ;
|
169
|
+
var rows = Math.ceil(count / itemsPerRow) ;
|
170
|
+
|
171
|
+
f.x = f.y = 0;
|
172
|
+
f.height = Math.max(f.height, rows * rowHeight) ;
|
173
|
+
|
174
|
+
return f ;
|
175
|
+
},
|
176
|
+
|
104
177
|
|
105
178
|
insertionPointClass: SC.View.extend({
|
106
179
|
emptyElement: '<div class="grid-insertion-point"><span class="anchor"></span></div>'
|
107
180
|
}),
|
108
181
|
|
109
182
|
showInsertionPointBefore: function(itemView) {
|
183
|
+
|
110
184
|
if (!itemView) return ;
|
111
185
|
|
112
186
|
if (!this._insertionPointView) {
|
@@ -120,6 +194,7 @@ SC.GridView = SC.CollectionView.extend(
|
|
120
194
|
y: itemViewFrame.y + 6,
|
121
195
|
width: 0
|
122
196
|
};
|
197
|
+
|
123
198
|
if (!SC.rectsEqual(insertionPoint.get('frame'), f)) {
|
124
199
|
insertionPoint.set('frame', f) ;
|
125
200
|
}
|
@@ -137,13 +212,16 @@ SC.GridView = SC.CollectionView.extend(
|
|
137
212
|
// // We can do this much faster programatically using the rowHeight
|
138
213
|
insertionIndexForLocation: function(loc) {
|
139
214
|
var f = this.get('frame') ;
|
140
|
-
|
215
|
+
var sf = this.get('scrollFrame') ;
|
141
216
|
|
142
|
-
var itemsPerRow = this.
|
217
|
+
var itemsPerRow = this._computeItemsPerRow();
|
143
218
|
var columnWidth = Math.floor(f.width / itemsPerRow) ;
|
144
|
-
var row = Math.floor((loc.y - f.y) / this.get('rowHeight')
|
145
|
-
var col = Math.floor((loc.x - f.x) / columnWidth + 0.5) ;
|
146
|
-
|
219
|
+
var row = Math.floor((loc.y - f.y - sf.y) / this.get('rowHeight')) ;
|
220
|
+
var col = Math.floor(((loc.x - f.x - sf.x) / columnWidth) + 0.5) ;
|
221
|
+
|
222
|
+
var ret= (row*itemsPerRow) + col ;
|
223
|
+
//console.log("insertionIndexForLocation = %@".fmt(ret)) ;
|
224
|
+
return ret ;
|
147
225
|
}
|
148
226
|
|
149
227
|
}) ;
|
@@ -1,8 +1,9 @@
|
|
1
1
|
// ==========================================================================
|
2
|
-
// SC.
|
2
|
+
// SC.LabelView
|
3
3
|
// ==========================================================================
|
4
4
|
|
5
|
-
require('
|
5
|
+
require('mixins/control') ;
|
6
|
+
require('views/image') ;
|
6
7
|
|
7
8
|
/** @class
|
8
9
|
|
@@ -14,15 +15,15 @@ require('views/collection/collection_item') ;
|
|
14
15
|
@author AuthorName
|
15
16
|
@version 0.1
|
16
17
|
*/
|
17
|
-
SC.ImageCellView = SC.View.extend(SC.
|
18
|
+
SC.ImageCellView = SC.View.extend(SC.Control,
|
18
19
|
/** @scope SC.ImageCellView.prototype */ {
|
19
20
|
|
20
|
-
emptyElement: '<div class="image-cell collection-item"><img src="%@" style="position:relative;" /></div>'.fmt(static_url('blank')),
|
21
|
+
emptyElement: '<div class="image-cell sc-collection-item"><img src="%@" style="position:relative;" /></div>'.fmt(static_url('blank')),
|
21
22
|
|
22
23
|
/**
|
23
|
-
The
|
24
|
+
The image URL you wish to display.
|
24
25
|
*/
|
25
|
-
|
26
|
+
value: null,
|
26
27
|
|
27
28
|
/**
|
28
29
|
The owner view of this cell. The ImageCell relies on this
|
@@ -40,7 +41,7 @@ SC.ImageCellView = SC.View.extend(SC.CollectionItem,
|
|
40
41
|
*/
|
41
42
|
formatter: null,
|
42
43
|
|
43
|
-
|
44
|
+
contentValueKey: null,
|
44
45
|
|
45
46
|
/**
|
46
47
|
This is the required margin you want to appear around the image. Expressed in px
|
@@ -58,6 +59,8 @@ SC.ImageCellView = SC.View.extend(SC.CollectionItem,
|
|
58
59
|
// parent. Automatically triggered when load status changes and
|
59
60
|
// also by owner whenever it is resized.
|
60
61
|
sizeToFit: function() {
|
62
|
+
|
63
|
+
if (this.get('status') != 'loaded') return ;
|
61
64
|
|
62
65
|
// find the best fit.
|
63
66
|
var f= this.owner.get('frame') ;
|
@@ -90,65 +93,33 @@ SC.ImageCellView = SC.View.extend(SC.CollectionItem,
|
|
90
93
|
}
|
91
94
|
},
|
92
95
|
|
93
|
-
// invoked whenever the content object changes.
|
94
|
-
_contentObserver: function() {
|
95
|
-
var content = this.get('content') ;
|
96
|
-
if (this._content == content) return ;
|
97
|
-
var f = this._boundValueDidChange() ;
|
98
|
-
|
99
|
-
// stop observing the old display property, if there is one.
|
100
|
-
if (this._content && this._displayProperty) {
|
101
|
-
this._content.removeObserver(this._displayProperty, f) ;
|
102
|
-
}
|
103
|
-
|
104
|
-
// start observing the new display property, if there is one
|
105
|
-
this._displayProperty = this._getDefault('displayProperty') ;
|
106
|
-
this._content = content ;
|
107
|
-
if (this._content && this._displayProperty) {
|
108
|
-
this._content.addObserver(this._displayProperty, f) ;
|
109
|
-
}
|
110
|
-
|
111
|
-
// notify value did change
|
112
|
-
this._valueDidChange() ;
|
113
|
-
}.observes('content'),
|
114
|
-
|
115
96
|
/**
|
116
97
|
@private
|
117
98
|
|
118
99
|
Invoked whenever the monitored value on the content object
|
119
100
|
changes.
|
120
101
|
|
121
|
-
The value processed is either the
|
102
|
+
The value processed is either the contentValueKey, if set, or
|
122
103
|
it is the content object itself.
|
123
104
|
*/
|
124
105
|
_valueDidChange: function() {
|
125
|
-
var
|
126
|
-
var value = (content && this._displayProperty) ? content.get(this._displayProperty) : content;
|
106
|
+
var value = this.get('value') ;
|
127
107
|
var owner = this.get('owner') ;
|
128
108
|
|
129
109
|
// prepare the value...
|
130
110
|
|
131
111
|
// 1. apply the formatter
|
132
|
-
var formatter = this.
|
112
|
+
var formatter = this.getDelegateProperty(this.displayDelegate, 'formatter') ;
|
133
113
|
if (formatter) {
|
134
114
|
var formattedValue = ($type(formatter) == T_FUNCTION) ? formatter(value, this) : formatter.fieldValueForObject(value, this) ;
|
135
115
|
if (formattedValue != null) value = formattedValue ;
|
136
116
|
}
|
137
117
|
|
138
118
|
// 2. If the returned value is not a string, convert it.
|
139
|
-
if (
|
119
|
+
if (value != null && value.toString) value = value.toString() ;
|
140
120
|
|
141
121
|
// 3. Apply URL to image view.
|
142
|
-
this.outlet('imageView').set('
|
143
|
-
}
|
144
|
-
|
145
|
-
_boundValueDidChange: function() {
|
146
|
-
return this._boundValueDidChange = this._boundValueDidChange || this._valueDidChange.bind(this);
|
147
|
-
},
|
148
|
-
|
149
|
-
// Retrieves the default value from the owner or locally.
|
150
|
-
_getDefault: function(keyName) {
|
151
|
-
var ret = (this.owner) ? this.owner.get(keyName) : null ;
|
152
|
-
return (ret != null) ? ret : this.get(keyName) ;
|
153
|
-
}
|
122
|
+
this.outlet('imageView').set('value', value) ;
|
123
|
+
}.observes('value')
|
124
|
+
|
154
125
|
}) ;
|
@@ -2,8 +2,8 @@
|
|
2
2
|
// SC.ListView
|
3
3
|
// ==========================================================================
|
4
4
|
|
5
|
-
require('views/collection') ;
|
6
|
-
require('views/
|
5
|
+
require('views/collection/collection') ;
|
6
|
+
require('views/label');
|
7
7
|
|
8
8
|
/** @class
|
9
9
|
|
@@ -40,44 +40,54 @@ SC.ListView = SC.CollectionView.extend(
|
|
40
40
|
|
41
41
|
You can override this as you wish.
|
42
42
|
*/
|
43
|
-
exampleView: SC.
|
43
|
+
exampleView: SC.ListItemView,
|
44
44
|
|
45
45
|
insertionOrientation: SC.VERTICAL_ORIENTATION,
|
46
46
|
|
47
|
+
contentRangeInFrame: function(frame) {
|
48
|
+
var rowHeight = this.get('rowHeight') || 0 ;
|
49
|
+
var min = Math.max(0,Math.floor(SC.minY(frame) / rowHeight)-1) ;
|
50
|
+
var max = Math.ceil(SC.maxY(frame) / rowHeight) ;
|
51
|
+
var ret = { start: min, length: max - min } ;
|
52
|
+
// console.log('contentRangeInFrame(%@) = %@'.fmt($H(frame).inspect(), $H(ret).inspect()));
|
53
|
+
//if (frame.height < 100) debugger ;
|
54
|
+
return ret ;
|
55
|
+
},
|
56
|
+
|
47
57
|
/** @private */
|
48
|
-
|
49
|
-
|
50
|
-
|
58
|
+
layoutItemView: function(itemView, contentIndex, firstLayout) {
|
59
|
+
if (!itemView) debugger ;
|
60
|
+
SC.Benchmark.start('SC.ListView.layoutItemViewsFor') ;
|
61
|
+
|
62
|
+
var rowHeight = this.get('rowHeight') || 0 ;
|
63
|
+
var parentView = itemView.get('parentView') ;
|
64
|
+
var f = {
|
65
|
+
x: 0,
|
66
|
+
y: contentIndex*rowHeight,
|
67
|
+
height: rowHeight,
|
68
|
+
width: (parentView || this).get('innerFrame').width
|
69
|
+
} ;
|
51
70
|
|
52
|
-
if (!
|
53
|
-
|
54
|
-
|
55
|
-
f = { x: 0, height: rowHeight } ;
|
56
|
-
var view = startingView || parentView.firstChild;
|
57
|
-
while(view) {
|
58
|
-
view.set('isPositioned', true) ;
|
59
|
-
f.y = y ;
|
60
|
-
if (!SC.rectsEqual(view.get('frame'), f)) view.set('frame', f) ;
|
61
|
-
y += rowHeight;
|
62
|
-
view = view.nextSibling ;
|
71
|
+
if (firstLayout || !SC.rectsEqual(itemView.get('frame'), f)) {
|
72
|
+
itemView.set('frame', f) ;
|
73
|
+
itemView.setStyle({ zIndex: contentIndex.toString() }) ;
|
63
74
|
}
|
64
|
-
|
75
|
+
SC.Benchmark.end('SC.ListView.layoutItemViewsFor') ;
|
65
76
|
},
|
66
77
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
// },
|
78
|
+
computeFrame: function() {
|
79
|
+
var content = this.get('content') ;
|
80
|
+
var rows = (content) ? content.get('length') : 0 ;
|
81
|
+
var rowHeight = this.get('rowHeight') || 20 ;
|
82
|
+
|
83
|
+
var parent = this.get('parentNode') ;
|
84
|
+
var f = (parent) ? parent.get('innerFrame') : { width: 100, height: 100 } ;
|
85
|
+
|
86
|
+
f.x = f.y = 0;
|
87
|
+
f.height = Math.max(f.height, rows * rowHeight) ;
|
88
|
+
// console.log('computeFrame(%@)'.fmt($H(f).inspect())) ;
|
89
|
+
return f ;
|
90
|
+
},
|
81
91
|
|
82
92
|
insertionPointClass: SC.View.extend({
|
83
93
|
emptyElement: '<div class="list-insertion-point"><span class="anchor"></span></div>'
|
@@ -106,9 +116,9 @@ SC.ListView = SC.CollectionView.extend(
|
|
106
116
|
|
107
117
|
// We can do this much faster programatically using the rowHeight
|
108
118
|
insertionIndexForLocation: function(loc) {
|
109
|
-
var f = this.get('
|
110
|
-
|
111
|
-
var ret = Math.floor((loc.y - f.y) / this.get('rowHeight') + 0.
|
119
|
+
var f = this.get('innerFrame') ;
|
120
|
+
var sf = this.get('scrollFrame') ;
|
121
|
+
var ret = Math.floor(((loc.y - f.y - sf.y) / this.get('rowHeight')) + 0.4) ;
|
112
122
|
return ret ;
|
113
123
|
}
|
114
124
|
|