From fc0add67b511c662fa3d2e5c790a34419e8dd9cb Mon Sep 17 00:00:00 2001 From: Vinyl Darkscratch Date: Tue, 29 Nov 2016 14:05:17 -0800 Subject: [PATCH] Add web2py componentBegin event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- applications/admin/static/js/web2py.js | 1 + applications/examples/static/js/web2py.js | 1 + applications/welcome/static/js/web2py.js | 1 + 3 files changed, 3 insertions(+) diff --git a/applications/admin/static/js/web2py.js b/applications/admin/static/js/web2py.js index c8b5e585..1228961c 100644 --- a/applications/admin/static/js/web2py.js +++ b/applications/admin/static/js/web2py.js @@ -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) { diff --git a/applications/examples/static/js/web2py.js b/applications/examples/static/js/web2py.js index c8b5e585..1228961c 100644 --- a/applications/examples/static/js/web2py.js +++ b/applications/examples/static/js/web2py.js @@ -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) { diff --git a/applications/welcome/static/js/web2py.js b/applications/welcome/static/js/web2py.js index c8b5e585..1228961c 100644 --- a/applications/welcome/static/js/web2py.js +++ b/applications/welcome/static/js/web2py.js @@ -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) {