Commit 656f946f authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] loopEventListener: immediately execute callback when event is triggered

parent 66f92a05
...@@ -107,13 +107,17 @@ ...@@ -107,13 +107,17 @@
"use strict";\n "use strict";\n
\n \n
window.loopEventListener = function (target, type, useCapture, callback,\n window.loopEventListener = function (target, type, useCapture, callback,\n
allowDefault) {\n prevent_default) {\n
//////////////////////////\n //////////////////////////\n
// Infinite event listener (promise is never resolved)\n // Infinite event listener (promise is never resolved)\n
// eventListener is removed when promise is cancelled/rejected\n // eventListener is removed when promise is cancelled/rejected\n
//////////////////////////\n //////////////////////////\n
var handle_event_callback,\n var handle_event_callback,\n
callback_promise;\n callback_promise;\n
\n
if (prevent_default === undefined) {\n
prevent_default = true;\n
}\n
\n \n
function cancelResolver() {\n function cancelResolver() {\n
if ((callback_promise !== undefined) &&\n if ((callback_promise !== undefined) &&\n
...@@ -129,16 +133,25 @@ ...@@ -129,16 +133,25 @@
cancelResolver();\n cancelResolver();\n
}\n }\n
function itsANonResolvableTrap(resolve, reject) {\n function itsANonResolvableTrap(resolve, reject) {\n
\n var result;\n
handle_event_callback = function (evt) {\n handle_event_callback = function (evt) {\n
evt.stopPropagation();\n if (prevent_default) {\n
if (allowDefault !== true) {\n evt.stopPropagation();\n
evt.preventDefault();\n evt.preventDefault();\n
}\n }\n
\n
cancelResolver();\n cancelResolver();\n
callback_promise = new RSVP.Queue()\n \n
try {\n
result = callback(evt);\n
} catch (e) {\n
result = RSVP.reject(e);\n
}\n
\n
callback_promise = result;\n
new RSVP.Queue()\n
.push(function () {\n .push(function () {\n
return callback(evt);\n return result;\n
})\n })\n
.push(undefined, function (error) {\n .push(undefined, function (error) {\n
if (!(error instanceof RSVP.CancellationError)) {\n if (!(error instanceof RSVP.CancellationError)) {\n
...@@ -314,7 +327,7 @@ ...@@ -314,7 +327,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>romain</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -328,7 +341,7 @@ ...@@ -328,7 +341,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>937.42855.7627.63982</string> </value> <value> <string>947.51167.64410.14796</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -346,8 +359,8 @@ ...@@ -346,8 +359,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1411056451.0</float> <float>1450099422.01</float>
<string>GMT</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment