1
- var App = SC . Application . create ( ) ;
1
+ var App = Em . Application . create ( ) ;
2
2
3
3
// Put jQuery UI inside its own namespace
4
4
JQ = { } ;
5
5
6
- // Create a new mixin for jQuery UI widgets using the new SproutCore 2.0
6
+ // Create a new mixin for jQuery UI widgets using the Ember
7
7
// mixin syntax.
8
- JQ . Widget = SC . Mixin . create ( {
9
- // When SproutCore creates the view's DOM element, it will call this
8
+ JQ . Widget = Em . Mixin . create ( {
9
+ // When Ember creates the view's DOM element, it will call this
10
10
// method.
11
- didCreateElement : function ( ) {
11
+ didInsertElement : function ( ) {
12
12
this . _super ( ) ;
13
13
14
- // Make jQuery UI options available as SproutCore properties
14
+ // Make jQuery UI options available as Ember properties
15
15
var options = this . _gatherOptions ( ) ;
16
16
17
17
// Make sure that jQuery UI events trigger methods on this view.
@@ -22,18 +22,18 @@ JQ.Widget = SC.Mixin.create({
22
22
var ui = jQuery . ui [ this . get ( 'uiType' ) ] ( options , this . get ( 'element' ) ) ;
23
23
24
24
// Save off the instance of the jQuery UI widget as the `ui` property
25
- // on this SproutCore view.
25
+ // on this Ember view.
26
26
this . set ( 'ui' , ui ) ;
27
27
} ,
28
28
29
- // When SproutCore tears down the view's DOM element, it will call
29
+ // When Ember tears down the view's DOM element, it will call
30
30
// this method.
31
31
willDestroyElement : function ( ) {
32
32
var ui = this . get ( 'ui' ) ;
33
33
34
34
if ( ui ) {
35
35
// Tear down any observers that were created to make jQuery UI
36
- // options available as SproutCore properties.
36
+ // options available as Ember properties.
37
37
var observers = this . _observers ;
38
38
for ( var prop in observers ) {
39
39
if ( observers . hasOwnProperty ( prop ) ) {
@@ -47,17 +47,17 @@ JQ.Widget = SC.Mixin.create({
47
47
// Each jQuery UI widget has a series of options that can be configured.
48
48
// For instance, to disable a button, you call
49
49
// `button.options('disabled', true)` in jQuery UI. To make this compatible
50
- // with SproutCore bindings, any time the SproutCore property for a
50
+ // with Ember bindings, any time the Ember property for a
51
51
// given jQuery UI option changes, we update the jQuery UI widget.
52
52
_gatherOptions : function ( ) {
53
53
var uiOptions = this . get ( 'uiOptions' ) , options = { } ;
54
54
55
55
// The view can specify a list of jQuery UI options that should be treated
56
- // as SproutCore properties.
56
+ // as Ember properties.
57
57
uiOptions . forEach ( function ( key ) {
58
58
options [ key ] = this . get ( key ) ;
59
59
60
- // Set up an observer on the SproutCore property. When it changes,
60
+ // Set up an observer on the Ember property. When it changes,
61
61
// call jQuery UI's `setOption` method to reflect the property onto
62
62
// the jQuery UI widget.
63
63
var observer = function ( ) {
@@ -78,7 +78,7 @@ JQ.Widget = SC.Mixin.create({
78
78
// Each jQuery UI widget has a number of custom events that they can
79
79
// trigger. For instance, the progressbar widget triggers a `complete`
80
80
// event when the progress bar finishes. Make these events behave like
81
- // normal SproutCore events. For instance, a subclass of JQ.ProgressBar
81
+ // normal Ember events. For instance, a subclass of JQ.ProgressBar
82
82
// could implement the `complete` method to be notified when the jQuery
83
83
// UI widget triggered the event.
84
84
_gatherEvents : function ( options ) {
@@ -97,21 +97,21 @@ JQ.Widget = SC.Mixin.create({
97
97
}
98
98
} ) ;
99
99
100
- // Create a new SproutCore view for the jQuery UI Button widget
101
- JQ . Button = SC . View . extend ( JQ . Widget , {
100
+ // Create a new Ember view for the jQuery UI Button widget
101
+ JQ . Button = Em . View . extend ( JQ . Widget , {
102
102
uiType : 'button' ,
103
103
uiOptions : [ 'label' , 'disabled' ] ,
104
104
105
105
tagName : 'button'
106
106
} ) ;
107
107
108
- // Create a new SproutCore view for the jQuery UI Menu widget (new
108
+ // Create a new Ember view for the jQuery UI Menu widget (new
109
109
// in jQuery UI 1.9). Because it wraps a collection, we extend from
110
- // SproutCore 's CollectionView rather than a normal view.
110
+ // Ember 's CollectionView rather than a normal view.
111
111
//
112
112
// This means that you should use `#collection` in your template to
113
113
// create this view.
114
- JQ . Menu = SC . CollectionView . extend ( JQ . Widget , {
114
+ JQ . Menu = Em . CollectionView . extend ( JQ . Widget , {
115
115
uiType : 'menu' ,
116
116
uiOptions : [ 'disabled' ] ,
117
117
uiEvents : [ 'select' ] ,
@@ -124,20 +124,24 @@ JQ.Menu = SC.CollectionView.extend(JQ.Widget, {
124
124
this . _super ( content , start , removed , added ) ;
125
125
126
126
var ui = this . get ( 'ui' ) ;
127
- if ( ui ) { ui . refresh ( ) ; }
127
+ if ( ui ) {
128
+ Em . run . next ( function ( ) {
129
+ ui . refresh ( ) ;
130
+ } ) ;
131
+ }
128
132
}
129
133
} ) ;
130
134
131
- // Create a new SproutCore view for the jQuery UI Progrress Bar widget
132
- JQ . ProgressBar = SC . View . extend ( JQ . Widget , {
135
+ // Create a new Ember view for the jQuery UI Progress Bar widget
136
+ JQ . ProgressBar = Em . View . extend ( JQ . Widget , {
133
137
uiType : 'progressbar' ,
134
138
uiOptions : [ 'value' , 'max' ] ,
135
139
uiEvents : [ 'change' , 'complete' ]
136
140
} ) ;
137
141
138
142
// Create a simple controller to hold values that will be shared across
139
143
// views.
140
- App . controller = SC . Object . create ( {
144
+ App . controller = Em . Object . create ( {
141
145
progress : 0 ,
142
146
menuDisabled : true
143
147
} ) ;
@@ -174,21 +178,21 @@ App.Button = JQ.Button.extend({
174
178
App . ProgressBar = JQ . ProgressBar . extend ( {
175
179
// When the jQuery UI progress bar reaches 100%, it will invoke the
176
180
// `complete` event. Recall that JQ.Widget registers a callback for
177
- // the `complete` event in `didCreateElement `, which calls the
181
+ // the `complete` event in `didInsertElement `, which calls the
178
182
// `complete` method.
179
183
complete : function ( ) {
180
184
// When the progress bar finishes, update App.controller with the
181
185
// list of people. Because our template binds the JQ.Menu to this
182
186
// value, it will automatically populate with the new people and
183
187
// refresh the menu.
184
188
App . controller . set ( 'people' , [
185
- SC . Object . create ( {
189
+ Em . Object . create ( {
186
190
name : "Tom DAAAAALE"
187
191
} ) ,
188
- SC . Object . create ( {
192
+ Em . Object . create ( {
189
193
name : "Yehuda Katz"
190
194
} ) ,
191
- SC . Object . create ( {
195
+ Em . Object . create ( {
192
196
name : "Majd Potatoes"
193
197
} )
194
198
] ) ;
@@ -212,7 +216,6 @@ Template:
212
216
disabledBinding="App.controller.menuDisabled"}}
213
217
<a href="#">
214
218
{{content.name}}
215
- {{view JQ.Button labelBinding="parentView.content.name"}}
216
219
</a>
217
220
{{else}}
218
221
<a href="#">LIST NOT LOADED</a>
0 commit comments