53 | sub: foreach_subscribe, |
53 | sub: foreach_subscribe, |
54 | unsub: foreach_unsubscribe, |
54 | unsub: foreach_unsubscribe, |
55 | apply_cache: foreach_apply_cache, |
55 | apply_cache: foreach_apply_cache, |
56 } |
56 } |
57 |
57 |
|
58 emit "epilogue:foreach" |
|
59 || |
|
60 function foreach_unsubscribe(){ |
|
61 for(let item of this.items){ |
|
62 for(let widget of item) { |
|
63 unsubscribe.call(widget); |
|
64 } |
|
65 } |
|
66 this.offset = 0; |
|
67 } |
|
68 |
|
69 function foreach_widgets_do(new_offset, todo){ |
|
70 this.offset = new_offset; |
|
71 for(let i = 0; i < this.items.length; i++) { |
|
72 let item = this.items[i]; |
|
73 let orig_item_index = this.index_pool[i]; |
|
74 let item_index = this.index_pool[i+this.item_offset]; |
|
75 let item_index_offset = item_index - orig_item_index; |
|
76 for(let widget of item) { |
|
77 todo.call(widget, new_offset + item_index_offset); |
|
78 } |
|
79 } |
|
80 } |
|
81 |
|
82 function foreach_subscribe(new_offset=0){ |
|
83 foreach_widgets_do.call(this, new_offset, subscribe); |
|
84 } |
|
85 |
|
86 function foreach_apply_cache() { |
|
87 foreach_widgets_do.call(this, this.offset, widget_apply_cache); |
|
88 } |
|
89 |
|
90 function foreach_onclick(opstr, evt) { |
|
91 new_item_offset = eval(String(this.item_offset)+opstr) |
|
92 if(new_item_offset + this.items.length > this.index_pool.length) { |
|
93 if(this.item_offset + this.items.length == this.index_pool.length) |
|
94 new_item_offset = 0; |
|
95 else |
|
96 new_item_offset = this.index_pool.length - this.items.length; |
|
97 } else if(new_item_offset < 0) { |
|
98 if(this.item_offset == 0) |
|
99 new_item_offset = this.index_pool.length - this.items.length; |
|
100 else |
|
101 new_item_offset = 0; |
|
102 } |
|
103 this.item_offset = new_item_offset; |
|
104 off = this.offset; |
|
105 foreach_unsubscribe.call(this); |
|
106 foreach_subscribe.call(this,off); |
|
107 update_subscriptions(); |
|
108 need_cache_apply.push(this); |
|
109 jumps_need_update = true; |
|
110 requestHMIAnimation(); |
|
111 } |
|
112 |
|
113 || |