Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit c0bd693

Browse files
author
Gabriel Schulhof
committed
View source: Delegate popup-related events from document
We have to do this because the popup now attaches to the body
1 parent de1b61c commit c0bd693

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

demos/_assets/js/view-source.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,22 +216,12 @@ $( document ).on( "pagebeforecreate", "[data-role='page']", function() {
216216
SyntaxHighlighter.defaults['auto-links'] = false;
217217
});
218218

219-
$( document ).on( "pagecreate", function( e ) {
220-
// prevent page scroll while scrolling source code
221-
$( document ).on( "mousewheel", ".jqm-view-source .ui-collapsible-content", function( event, delta ) {
222-
if ( delta > 0 && $( this ).scrollTop() === 0 ) {
223-
event.preventDefault();
224-
} else if ( delta < 0 && $( this ).scrollTop() === $( this ).get( 0 ).scrollHeight - $( this ).innerHeight() ) {
225-
event.preventDefault();
226-
}
227-
});
228-
219+
$( document )
229220
// reposition when switching between html / js / css
230-
$( e.target ).delegate( ".jqm-view-source .ui-collapsible", "expand", function() {
221+
.on( "collapsibleexpand", ".jqm-view-source .ui-collapsible", function() {
231222
$( this ).parents( ":mobile-popup" ).popup( "reposition", { positionTo: "window" } );
232-
});
233-
234-
$( e.target ).delegate( ".jqm-view-source", "popupbeforeposition", function() {
223+
})
224+
.on( "popupbeforeposition", ".jqm-view-source", function() {
235225
// max height: screen height - tolerance (2*30px) - 42px for each collapsible heading
236226
var x = $( this ).find( ".ui-collapsible" ).length,
237227
maxHeight = $.mobile.getScreenHeight() - 60 - ( x * 42 );
@@ -251,8 +241,17 @@ $( document ).on( "pagecreate", function( e ) {
251241
$( line ).height( height );
252242
}
253243
});
244+
})
245+
.on( "pagecreate", function( e ) {
246+
// prevent page scroll while scrolling source code
247+
$( document ).on( "mousewheel", ".jqm-view-source .ui-collapsible-content", function( event, delta ) {
248+
if ( delta > 0 && $( this ).scrollTop() === 0 ) {
249+
event.preventDefault();
250+
} else if ( delta < 0 && $( this ).scrollTop() === $( this ).get( 0 ).scrollHeight - $( this ).innerHeight() ) {
251+
event.preventDefault();
252+
}
253+
});
254254
});
255-
});
256255

257256
/**
258257
* SyntaxHighlighter

0 commit comments

Comments
 (0)