File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -90,8 +90,12 @@ export default Base.extend({
90
90
// if so, mark both the anchor and the target element
91
91
$target . addClass ( "current" ) ;
92
92
this . $el . addClass ( "current" ) ;
93
+ this . $el . trigger ( "pat-update" , {
94
+ pattern : "scroll" ,
95
+ action : "attribute-changed" ,
96
+ dom : $target [ 0 ] ,
97
+ } ) ;
93
98
}
94
- $ ( this . $el ) . trigger ( "pat-update" , { pattern : "scroll" } ) ;
95
99
}
96
100
}
97
101
}
Original file line number Diff line number Diff line change @@ -220,4 +220,35 @@ describe("pat-scroll", function () {
220
220
pat . options . selector = null ; // Using href target
221
221
expect ( pat . _get_selector_target ( ) ) . toBe ( el_3 ) ;
222
222
} ) ;
223
+
224
+ it ( "triggers pat-update event." , async ( ) => {
225
+ document . body . innerHTML = `
226
+ <a href="#el1" class="pat-scroll">scroll to</a>
227
+ <div id="el1" />
228
+ ` ;
229
+
230
+ const spy = jest
231
+ . spyOn ( utils , "isElementInViewport" )
232
+ . mockImplementation ( ( ) => true ) ;
233
+
234
+ const el = document . querySelector ( ".pat-scroll" ) ;
235
+ const target = document . querySelector ( "#el1" ) ;
236
+
237
+ new pattern ( el ) ;
238
+
239
+ let data = null ;
240
+ $ ( el ) . on ( "pat-update" , ( e , d ) => {
241
+ data = d ;
242
+ } ) ;
243
+
244
+ $ ( window ) . scroll ( ) ;
245
+ await utils . timeout ( 50 ) ; // wait for debounce.
246
+
247
+ expect ( data ) . not . toBeNull ( ) ;
248
+ expect ( data . pattern ) . toBe ( "scroll" ) ;
249
+ expect ( data . action ) . toBe ( "attribute-changed" ) ;
250
+ expect ( data . dom ) . toBe ( target ) ;
251
+
252
+ spy . mockRestore ( ) ;
253
+ } ) ;
223
254
} ) ;
You can’t perform that action at this time.
0 commit comments