Skip to content

Commit

Permalink
Add web2py componentBegin event
Browse files Browse the repository at this point in the history
Like the “w2p:componentComplete” event I added a while back, this is
another event that I use in my website, and I thought it would be
helpful to share it with others.  This way, you can easily catch when a
web2py component starts loading, and write a handler for whatever
reason (in my case, determining when the user is navigating to a new
page through a smooth loading function piggybacking off of the web2py
component system)
  • Loading branch information
queengooborg committed Nov 29, 2016
1 parent 3d2834c commit fc0add6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions applications/admin/static/js/web2py.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
'beforeSend': function (xhr, settings) {
xhr.setRequestHeader('web2py-component-location', document.location);
xhr.setRequestHeader('web2py-component-element', target);
web2py.fire(element, 'w2p:componentBegin', [xhr, settings], target);
return web2py.fire(element, 'ajax:beforeSend', [xhr, settings], target); //test a usecase, should stop here if returns false
},
'success': function (data, status, xhr) {
Expand Down
1 change: 1 addition & 0 deletions applications/examples/static/js/web2py.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
'beforeSend': function (xhr, settings) {
xhr.setRequestHeader('web2py-component-location', document.location);
xhr.setRequestHeader('web2py-component-element', target);
web2py.fire(element, 'w2p:componentBegin', [xhr, settings], target);
return web2py.fire(element, 'ajax:beforeSend', [xhr, settings], target); //test a usecase, should stop here if returns false
},
'success': function (data, status, xhr) {
Expand Down
1 change: 1 addition & 0 deletions applications/welcome/static/js/web2py.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
'beforeSend': function (xhr, settings) {
xhr.setRequestHeader('web2py-component-location', document.location);
xhr.setRequestHeader('web2py-component-element', target);
web2py.fire(element, 'w2p:componentBegin', [xhr, settings], target);
return web2py.fire(element, 'ajax:beforeSend', [xhr, settings], target); //test a usecase, should stop here if returns false
},
'success': function (data, status, xhr) {
Expand Down

0 comments on commit fc0add6

Please sign in to comment.