@@ -36,7 +36,6 @@ let getPageY = function getPageY(ev){
3636 return pageY ;
3737} ;
3838
39-
4039/**
4140 * Class rapresent a list item with left and right swipe effect.
4241 * It's composed by a swipeable drawer and two actions panels positioned behind
@@ -71,8 +70,8 @@ let getPageY = function getPageY(ev){
7170 * }
7271 * onSelectItem(item, done) {
7372 * if (item) {
74- * // Element clicked, you should check if it is the left, or right, action
75- * // button and ignore the drawer
73+ * // Element clicked, you should check if it is the left, or right,
74+ * // action button and ignore the drawer
7675 * console.log(item.element);
7776 * }
7877 * return done();
@@ -81,6 +80,32 @@ let getPageY = function getPageY(ev){
8180 */
8281export default class SwipeListItemView extends ListItemView {
8382
83+ /**
84+ * Triggered when the user stop dragging the drawer with the left action
85+ * active
86+ * @event SwipeListItemView#swipe:left
87+ * @property {SwipeListItemView } item - Self
88+ */
89+
90+ /**
91+ * Triggered when the user stop dragging the drawer with the right action
92+ * active
93+ * @event SwipeListItemView#swipe:right
94+ * @property {SwipeListItemView } item - Self
95+ */
96+
97+ /**
98+ * Triggered when the user end dragging
99+ * @event SwipeListItemView#dragging:end
100+ * @property {SwipeListItemView } item - Self
101+ */
102+
103+ /**
104+ * Triggered when the user stop dragging
105+ * @event SwipeListItemView#dragging:start
106+ * @property {SwipeListItemView } item - Self
107+ */
108+
84109 constructor ( options ) {
85110 super ( options ) ;
86111
@@ -99,7 +124,7 @@ export default class SwipeListItemView extends ListItemView {
99124 activeClassName : 'action-active'
100125 } ) ;
101126
102- if ( ! this . options . parent ) {
127+ if ( ! this . options . parentList ) {
103128 throw new Error ( 'Parent list view is required for SwipeListItemView' ) ;
104129 }
105130
@@ -122,6 +147,13 @@ export default class SwipeListItemView extends ListItemView {
122147 this . listenTo ( this . parent , 'dragging:start' , this . onListItemDraggingStart ) ;
123148 }
124149
150+ /**
151+ * Render the view
152+ * @version 2.1.0
153+ * @private
154+ * @param {bool } rendered - Indicate if the view was already rendered
155+ * @return {SwipeListItemView } - Self
156+ */
125157 onRender ( rendered ) {
126158 if ( ! rendered ) {
127159 this . cache . $leftAction = $ ( '<div class="ui-swipe-list-item-actions ui-swipe-list-item-actions-left">' ) ;
@@ -142,6 +174,12 @@ export default class SwipeListItemView extends ListItemView {
142174 return this ;
143175 }
144176
177+ /**
178+ * Called when the user touch the view
179+ * @version 2.1.0
180+ * @private
181+ * @param {object } e - jQuery touch event
182+ */
145183 onTouchStart ( e ) {
146184 if ( this . status === STATUS_DRAGGING ) return ;
147185
@@ -164,6 +202,17 @@ export default class SwipeListItemView extends ListItemView {
164202 this . trigger ( 'dragging:start' , this ) ;
165203 }
166204
205+ /**
206+ * Called when the user move the finger on the view for the first time.
207+ * It's used to check if the movement is horizontal or vertical. If it's
208+ * horizontal it attaches a touchmove and touchend event to the document,
209+ * stops the parentList scroll and start move the drawer. If it's vertical
210+ * ignore the event.
211+ * @version 2.1.0
212+ * @private
213+ * @param {[type] } e [description]
214+ * @return {[type] } [description]
215+ */
167216 onCheckDirectionTouchMove ( e ) {
168217 const x = getPageX ( e ) ;
169218 const y = getPageY ( e ) ;
@@ -186,6 +235,14 @@ export default class SwipeListItemView extends ListItemView {
186235 document . removeEventListener ( 'touchmove' , this . onCheckDirectionTouchMove ) ;
187236 }
188237
238+ /**
239+ * Called when the user removes the finger from the screen. It check the
240+ * position of the drawer and react to toggleLeft, toggleRight options.
241+ * It also trigger swipe:left, swipe:right, dragging:end events.
242+ * @version 2.1.0
243+ * @private
244+ * @param {object } e - DOM touch event
245+ */
189246 onTouchEnd ( e ) {
190247 this . parent . resume ( ) ;
191248 document . removeEventListener ( 'touchmove' , this . onTouchMove ) ;
@@ -226,6 +283,13 @@ export default class SwipeListItemView extends ListItemView {
226283 this . trigger ( 'dragging:end' , this ) ;
227284 }
228285
286+ /**
287+ * Called when the user moves a finger on the screen. It handles the
288+ * drawer movement and also adds the options.activeClassName to the view.
289+ * @param {object } e - DOM touch event
290+ * @version 2.1.0
291+ * @private
292+ */
229293 onTouchMove ( e ) {
230294 const x = getPageX ( e ) ;
231295 let deltaX = this . deltaX = x - this . startX ;
@@ -269,6 +333,7 @@ export default class SwipeListItemView extends ListItemView {
269333 this . vibrate ( ) ;
270334 } else if ( deltaX < this . options . leftWidth && this . hasActiveClass ) {
271335 this . removeActiveClass ( ) ;
336+ this . vibrate ( ) ;
272337 }
273338 }
274339
@@ -279,17 +344,32 @@ export default class SwipeListItemView extends ListItemView {
279344 this . vibrate ( ) ;
280345 } else if ( deltaX > - this . options . rightWidth && this . hasActiveClass ) {
281346 this . removeActiveClass ( ) ;
347+ this . vibrate ( ) ;
282348 }
283349 }
284350
285351 translate3d ( this . cache . $drawer , deltaX , 0 , 0 ) ;
286352 }
287353
354+ /**
355+ * Called when another SwipeListItemView start dragging. It closes the
356+ * drawer to prevent multiple drawers opened on the same list.
357+ * NOTE: This method receives his dragging:start event.
358+ * @private
359+ * @version 2.1.0
360+ * @param {SwipeListItemView } item - Item that triggered the event
361+ */
288362 onListItemDraggingStart ( item ) {
289363 if ( item === this ) return ;
290364 this . closeDrawer ( ) ;
291365 }
292366
367+ /**
368+ * Close the drawer
369+ * @public
370+ * @version 2.1.0
371+ * @param {bool } [animated] [true] - Close the drawer with an animation
372+ */
293373 closeDrawer ( animated = true ) {
294374 if ( this . status === STATUS_NORMAL ) return ;
295375 if ( animated ) {
@@ -303,25 +383,46 @@ export default class SwipeListItemView extends ListItemView {
303383 this . status = STATUS_NORMAL ;
304384 }
305385
386+ /**
387+ * Ensure that a model sostitution closes the drawer (without animation)
388+ * @private
389+ * @version 2.1.0
390+ * @param {Model } newModel - The new model
391+ */
306392 setModel ( newModel ) {
307393 this . closeDrawer ( false ) ;
308394 return super . setModel ( newModel ) ;
309395 }
310396
397+ /**
398+ * Helper method used to add the activeClassName only when necessary
399+ * @private
400+ * @version 2.1.0
401+ */
311402 addActiveClass ( ) {
312403 if ( ! this . hasActiveClass ) {
313404 this . $el . addClass ( this . options . activeClassName ) ;
314405 this . hasActiveClass = true ;
315406 }
316407 }
317408
409+ /**
410+ * Helper method used to remove the activeClassName only when necessary
411+ * @private
412+ * @version 2.1.0
413+ */
318414 removeActiveClass ( ) {
319415 if ( this . hasActiveClass ) {
320416 this . $el . removeClass ( this . options . activeClassName ) ;
321417 this . hasActiveClass = false ;
322418 }
323419 }
324420
421+ /**
422+ * Helper method called when it's the time to launch a vibration
423+ * @private
424+ * @version 2.1.0
425+ */
325426 vibrate ( ) {
326427 if ( this . options . vibrateCallback ) {
327428 this . options . vibrateCallback ( ) ;
0 commit comments